﻿var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');



function BlurTextFilter(thebox) {
    if (thebox.value == '') {
        thebox.value = 'Type Keywords';
        return true;
    }else{
        return true;
    }
}
 
function BuildMainAccordion(populateList) {
        var arrCatIDs = new Array("1542", "1543", "1544", "1545", "1546", "1547", "1548", "1549", "1550", "1551", "1552", "1553", "1630", "1554", "1555", "1557", "1558", "3159", "3158", "1556");
        var arrCatNames = new Array("Women's Fashion", "Men's Fashion", "Jewelry", "Watches", "Lingerie", "Handbags, Shoes &amp; Accessories", "Sports, Beauty &amp; Wellness", "Lifestyle &amp; Gifts", "Electronics &amp; Telecommunications", "Celebrity Chefs", "Restaurants", "Bars &amp; Nightclubs", "Concierge", "Food Court", "Cafés", "General", "Banks", "Department Store", "Children's Fashion &amp; Maternity", "Gourmet & Specialty Food");
        var arrPos = -1;
        var thisLetter = "";
        var thisReqString = "/ShopList.ashx";
        var outString = "";
        var firstrun = true;
        var j = 1;
        $.ajax({ type: "GET", url: thisReqString, dataType: "xml", success: function (xml) {
            for (a = 0; a < arrCatIDs.length; a++) {
                var thisCatID = arrCatIDs[a];
                var thisCategoryOutput = "<a class='bellow' href='#' onclick='chgBtnStateTitle(event, \"" + j + "\"); return false;'>";
                thisCategoryOutput += arrCatNames[a];
                thisCategoryOutput += "<img name='" + j + "' class='accordionimage' alt='Expand' src='/images/uparrow.png' /></a>";
                thisCategoryOutput += "<div class='innerAccordionShop' id='accord" + j + "' style='display: none'><ul>";
                var thisCategoryCount = 0;
                $(xml).find('shop').each(function () {
                    var shopTitle = $(this).find('title').text();
                    var shopUrl = $(this).find('alias').text();
                    var shopCats = $(this).find('categories').text();
                    var catsSplit = shopCats.split(' ');
                    if (firstrun && populateList) {
                        var opttext = shopTitle.replace("&amp;", "&");
                        opttext = opttext.replace("&#39;", "'");
                        var opt = document.createElement("option");
                        document.getElementById("namelist").options.add(opt);
                        opt.text = opttext;
                        opt.value = "/" + shopUrl;
                    }
                    if (shopCats.indexOf(thisCatID) > -1) {
                        thisCategoryCount += 1;
                        thisCategoryOutput += "<li><a href='/" + shopUrl + "'>" + shopTitle + "</a><li>";
                    }
                });
                thisCategoryOutput += "</ul></div><div class='bellowborder'></div>";
                if (thisCategoryCount > 0) {
                    outString += thisCategoryOutput;
                    j += 1;
                }
                firstrun = false;
            }

            document.getElementById("accordions").innerHTML = outString;
        }
        });


}

    function BuildMainList() {
        var arrPos = -1;
        var thisLetter = "";
        var thisReqString = "/ShopList.ashx";
        var outString = "";
        $.ajax({ type: "GET", url: thisReqString, dataType: "xml", success: function (xml) {
            $(xml).find('shop').each(function () {
                var shopTitle = $(this).find('title').text();
                var shopUrl = $(this).find('alias').text();
                var shopTitleLower = shopTitle.toUpperCase();
                var firstChar = shopTitleLower.charAt(0);
                var opt = document.createElement("option");
                var opttext = shopTitle.replace("&amp;", "&");
                opttext = opttext.replace("&#39;", "'");
                var opt = document.createElement("option");
                document.getElementById("namelist").options.add(opt);
                opt.text = opttext;
                opt.value = "/" + shopUrl;
                if (arrPos < 0) {
                    outString = '<ul>';
                    arrPos = 0;
                }
                if (shop_isNumber(firstChar)) {
                    outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                } else {
                    var thisPos = $.inArray(firstChar, alphabet);
                    if (thisPos > arrPos) {
                        outString += "</ul><div class='alpha_top'><a href='#top'>Top</a></div>";
                        arrPos = thisPos;
                        if (arrPos < 26) {
                            outString += "<a id='" + alphabet[arrPos] + "'></a><ul>";
                            outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                        }
                    } else {
                        outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                    }
                }
            });
            outString += "</ul><div class='alpha_top'><a href='#top'>Top</a></div>";
            document.getElementById("listtop").innerHTML = outString;
        }
    });
}

function FilterAccordion(sellist, filtertype) {
    var selvalue = sellist[sellist.selectedIndex].value;
    if (selvalue != "0") {
        var arrCatIDs = new Array("1542", "1543", "1544", "1545", "1546", "1547", "1548", "1549", "1550", "1551", "1552", "1553", "1630", "1554", "1555", "1557", "1558", "3159", "3158", "1556");
        var arrCatNames = new Array("Women's Fashion", "Men's Fashion", "Jewelry", "Watches", "Lingerie", "Handbags, Shoes &amp; Accessories", "Sports, Beauty &amp; Wellness", "Lifestyle &amp; Gifts", "Electronics &amp; Telecommunications", "Celebrity Chefs", "Restaurants", "Bars &amp; Nightclubs", "Concierge", "Food Court", "Cafés", "General", "Banks", "Department Store", "Children's Fashion &amp; Maternity", "Gourmet & Specialty Food");
        var j = 1;
        var arrPos = -1;
        var thisLetter = "";
        var thisReqString = "/ShopList.ashx?f=1&t=" + filtertype + "&v=" + selvalue;
        var outString = "";
        $.ajax({ type: "GET", url: thisReqString, dataType: "xml", success: function (xml) {
            for (a = 0; a < arrCatIDs.length; a++) {
                var thisCatID = arrCatIDs[a];
                if (sellist.id == 'categoryselect') {
                    if (thisCatID != selvalue) {
                        continue;
                    }
                }
                var thisCategoryOutput = "<a class='bellow' href='#' onclick='chgBtnStateTitle(event, \"" + j + "\"); return false;'>";
                thisCategoryOutput += arrCatNames[a];
                thisCategoryOutput += "<img name='" + j + "' class='accordionimage' alt='Expand' src='/images/uparrow.png' /></a>";
                thisCategoryOutput += "<div class='innerAccordionShop' id='accord" + j + "' style='display: none'><ul>";
                var thisCategoryCount = 0;
                $(xml).find('shop').each(function () {
                    var shopTitle = $(this).find('title').text();
                    var shopUrl = $(this).find('alias').text();
                    var shopCats = $(this).find('categories').text();
                    var catsSplit = shopCats.split(' ');
                    if (shopCats.indexOf(thisCatID) > -1) {
                        thisCategoryCount += 1;
                        thisCategoryOutput += "<li><a href='/" + shopUrl + "'>" + shopTitle + "</a><li>";
                    }
                });
                thisCategoryOutput += "</ul></div><div class='bellowborder'></div>";
                if (thisCategoryCount > 0) {
                    outString += thisCategoryOutput;
                    j += 1;
                }
            }

            document.getElementById("accordions").innerHTML = outString;
        }
        });
} else {

        BuildMainAccordion(false);
    }
}

function FilterList(sellist, filtertype) {
    var selvalue = sellist[sellist.selectedIndex].value;
    if (selvalue != "0") {
        var arrPos = -1;
        var thisLetter = "";
        var thisReqString = "/ShopList.ashx?f=1&t=" + filtertype + "&v=" + selvalue;
        var outString = "";
        $.ajax({ type: "GET", url: thisReqString, dataType: "xml", success: function (xml) {
            $(xml).find('shop').each(function () {
                var shopTitle = $(this).find('title').text();
                var shopUrl = $(this).find('alias').text();
                var shopTitleLower = shopTitle.toUpperCase();
                var firstChar = shopTitleLower.charAt(0);
                if (arrPos < 0) {
                    outString = '<ul>';
                    arrPos = 0;
                }
                if (shop_isNumber(firstChar)) {
                    outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                } else {
                    var thisPos = $.inArray(firstChar, alphabet);
                    if (thisPos > arrPos) {
                        outString += "</ul><div class='alpha_top'><a href='#top'>Top</a></div>";
                        arrPos = thisPos;
                        if (arrPos < 26) {
                            outString += "<a id='" + alphabet[arrPos] + "'></a><ul>";
                            outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                        }
                    } else {
                        outString += "<li><a title='" + shopTitle + "' href='/" + shopUrl + "'>" + shopTitle + "</a></li>";
                    }
                }
            });
            outString += "</ul><div class='alpha_top'><a href='#top'>Top</a></div>";
            document.getElementById("listtop").innerHTML = outString;
        }
        });
    }
}

    function GoToShop(droplist) {
        var dropval = droplist[droplist.selectedIndex].value;
        if (dropval != '') {
            window.location = dropval;
        }
    }

    function shop_isNumber(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }
