function popup(which) {
    mywindow = window.open(which, "mywindow");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}

function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p, i, x; if (!d) d = document; 
	if(typeof p !== "undefined") {
		if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
			d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
		}
	}
	if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_goToURL() { //v3.0
    var i, args = MM_goToURL.arguments; document.MM_returnValue = false;
    for (i = 0; i < (args.length - 1); i += 2) eval(args[i] + ".location='" + args[i + 1] + "'");
}

function isSecure() {
    return location.protocol == 'https:';

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}


function getElementByID_Master(e) {
    //    alert('ge-' + e.toString());

    var ret = null;

    ret = MM_findObj(e);
    if (ret)
        return ret;

    ret = MM_findObj("ContentPlaceHolder1_" + e);
    if (ret)
        return ret;

    ret = MM_findObj("ContentPlaceHolder1$" + e);
    if (ret)
        return ret;

    //alert('ctl00_ContentPlaceHolder1_' + e.toString());
    ret = MM_findObj("ctl00_ContentPlaceHolder1_" + e);
    if (ret)
        return ret;

    //alert('ctl00$ContentPlaceHolder1$' + e.toString());
    ret = MM_findObj("ctl00$ContentPlaceHolder1$" + e);
    if (ret)
        return ret;



    /*
    //alert('ctl00_ContentPlaceHolder1_' + e.toString());
    ret = document.getElementsByName('ctl00_ContentPlaceHolder1_' + e.toString());
    if (ret != null)
    return ret;

    //alert('ctl00$ContentPlaceHolder1$' + e.toString());
    ret = document.getElementsByName('ctl00$ContentPlaceHolder1$' + e.toString());
    if (ret != null)
    return ret;
    */

    //if (ret)
    //alert(e.toString());

    return ret;
}

function popup_extra(theURL, winName, features) { //v2.0
    var pw;
    pw = window.open(theURL, winName, features);
    pw.focus();
}

function zeropad(i) {
    if (i == 0)
        return 0;

    if (i < 9)
        return "0" + i;

    return i;
}

function popup_win_params(w, p) {
    var pw;
    pw = window.open(w, 'Popup', p);
    pw.focus();
}

function popup_win(w) {
    var pw;
    pw = window.open(w, 'Popup', 'height=275,width=475,toolbar=no,resizable=no,scrollbars=no');
    pw.focus();
}

function popup_fitguide(w, height, width) {
    var pw;
    var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=no";
    pw = window.open(w, 'FitGuide', paramstring);
    pw.focus();
}
function popup_sizechart(w) {
    var pw;
    pw = window.open(w, 'SizeChart', 'height=450,width=620,toolbar=no,resizable=no,scrollbars=yes');
    pw.focus();
}

function popup_sizechart2(w, height, width) {
    var pw;
    var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=yes";
    pw = window.open(w, 'SizeChart', paramstring);
    pw.focus();
}

function popup_cantfindsizeandcolor(w, height, width) {
    var pw;
    var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=yes";
    pw = window.open(w, 'CantFindSizeandColor', paramstring);
    pw.focus();
}

function popup_referafriend(w) {
    var pw;
    var colorid = 0;
    var colorname = "";
    colorid = color_ids[g_color];

    var pc = getElementByID_Master("ProductColors");
    if (pc != null)
        colorname = pc.options[pc.selectedIndex].text.toLowerCase();

    if (colorid != 0 && colorname != "")
        pw = window.open(w + "&colorid=" + colorid + "&colorname=" + colorname, 'ReferAFriend', 'height=425,width=450,toolbar=no,resizable=no,scrollbars=no');
    else
        pw = window.open(w, 'ReferAFriend', 'height=425,width=450,toolbar=no,resizable=no,scrollbars=no');

    pw.focus();
}

function popup_shareproduct(w, height, width) {
    var pw;
    var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=yes";
    pw = window.open(w, 'ShareBookmarkProduct', paramstring);
    pw.focus();
}

function FacebookShare(productid) {
    FacebookShareURL(location.hostname + "/pd/cl/" + color_ids[g_color] + "/p/" + productid + ".html");

}

function FacebookShareURL(url) {
    window.open("http://www.facebook.com/sharer.php?u=" + url);
}

function getElementsByClassName(className, tag, elm) {
    var Class = new RegExp("(^|\\s)" + className + "(\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for (var i = 0; i < length; i++) {
        current = elements[i];
        if (Class.test(current.className)) {
            returnElements.push(current);
        }
    }
    return returnElements;
}

function addCls(elm, className) {
    var currentClass = elm.className;
    if (!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)) {
        elm.className = currentClass + ((currentClass.length > 0) ? " " : "") + className;
    }
    return elm.className;
}

function remCls(elm, className) {
    var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");
    elm.className = elm.className.replace(classToRemove, "").replace(/^\s+|\s+$/g, "");
    return elm.className;
}

function toggleElem(id, show) {
    if (show == "1") {
        if (document.layers) {
            document.layers[id].visibility = "show";
        } else if (document.all) {
            document.all[id].style.visibility = "visible";
        } else if (document.getElementById) {
            getElementByID_Master(id).style.visibility = "visible";
        }
    } else if (show == "0") {
        if (document.layers) {
            document.layers[id].visibility = "hide";
        } else if (document.all) {
            document.all[id].style.visibility = "hidden";
        } else if (document.getElementById) {
            getElementByID_Master(id).style.visibility = "hidden";
        }
    }
}

function setElem(id, val) {
    if (getElementByID_Master(id))
        getElementByID_Master(id).innerHTML = val;
    try { getElementByID_Master(id).className = "" }
    catch (err) { }
}

function reload_sizes() {
    if (size_count == 0)
        return;

    var ps = getElementByID_Master("ProductSizes");
    if (ps == null)
        return;

    //updated to enable quicklook on pdp for huds
    if (ps.options != null) {
        var curr_value = ps.options[ps.selectedIndex].value;
        var curr_index = 0;

        ps.length = 0;
        ps.options[0] = new Option("Select " + g_sizealias, "-1");
        curr_index++;


        for (var i = 1; i <= size_count; i++) {
            if (g_color == 0 || aSCSA[g_color][i] == true || g_showwhenoos == 1) {
                ps.options[curr_index] = new Option(size_names[i], size_ids[i]);
                if (curr_value == size_ids[i])
                    ps.selectedIndex = curr_index;

                curr_index++;
            }
        }
    }
    if (ps.length == 2 && (getElementByID_Master("DisableOneSizeSelection") == null || (getElementByID_Master("DisableOneSizeSelection") != null && getElementByID_Master("DisableOneSizeSelection").value != 1))) {
        ps.selectedIndex = 1;
    }
}

function reload_colors() {
    if (color_count == 0)
        return;

    var ps = getElementByID_Master("ProductColors");
    if (ps == null)
        return;

    var curr_value = ps.options[ps.selectedIndex].value;
    var curr_index = 0;

    ps.length = 0;
    ps.options[0] = new Option("Select Color", "-1");
    curr_index++;

    for (var i = 1; i <= color_count; i++) {
        if (g_size == 0 || aSCSA[i][g_size] == true || g_showwhenoos == 1) {
            ps.options[curr_index] = new Option(color_names[i], color_ids[i]);
            if (curr_value == color_ids[i])
                ps.selectedIndex = curr_index;

            curr_index++;
        }
    }
    if (ps.length == 2) {
        ps.selectedIndex = 1;
    }
}

function change_upc() {
    var upc = getElementByID_Master("upc_text");
    if (upc == null)
        return;

    if (aUPC[g_color] == null) {
        upc.innerHTML = '';
        return;
    }

    var val = aUPC[g_color][g_size];
    if (val == null || val == '') {
        upc.innerHTML = '';
        return;
    }

    upc.innerHTML = 'UPC: ' + val;
}

function HideElem(id) {
    var e = getElementByID_Master(id);
    if (e != null) {
        e.style.display = "none";
    }
}

function ShowElem(id) {
    var e = getElementByID_Master(id);
    if (e != null) {
        e.style.display = "inline";
    }
}

function reset_unitcost(uc, flag) {
    if (g_unitcost == '$0.00' || g_mincost != g_maxcost) {
        if (g_mincost == g_maxcost || flag == 1) {
            if (g_previouscost == '$0.00')
                uc.innerHTML = g_maxcost;
            else if (parseInt(g_size) == 0) {
                var intVal = aSKUUnitCost[g_color][1];
                if (intVal == "") {
                    uc.innerHTML = aSKUUnitCost[g_color][2]
                }
                else {
                    uc.innerHTML = intVal;
                }
            }
            else
                uc.innerHTML = g_unitcost;
        }
        else
            uc.innerHTML = g_mincost + ' - ' + g_maxcost;
    }
    else {
        uc.innerHTML = g_unitcost;
    }
}

function change_costspans() {
    var lpl = getElementByID_Master("legacy_price_layout");
    if (lpl == null)
        return;

    var csr = getElementByID_Master("costspan_regular");
    if (csr == null)
        return;

    var css = getElementByID_Master("costspan_sale");
    if (css == null)
        return;

    var uc = getElementByID_Master("UnitCostSpan");
    if (uc == null)
        return;

    var pc = getElementByID_Master("PreviousCostSpan");
    if (pc == null)
        return;

    var csr_uc = getElementByID_Master("costspan_regular_uc");
    if (csr_uc == null)
        return;

    var css_uc = getElementByID_Master("costspan_sale_uc");
    if (css_uc == null)
        return;

    var css_pc = getElementByID_Master("costspan_sale_pc");
    if (css_pc == null)
        return;

    if (pc.innerHTML == '') {
        csr.style.display = "block";
        css.style.display = "none";
        csr_uc.innerHTML = uc.innerHTML;
    } else {
        csr.style.display = "none";
        css.style.display = "block";
        css_uc.innerHTML = uc.innerHTML;
        css_pc.innerHTML = pc.innerHTML;
    }

    lpl.style.display = "none";
    HideElem("PreviousCost");
    HideElem("PreviousCostCustom");
    HideElem("PreviousCostCustom2");
}

function formatCurrencyZeroDecimal(num) {
    num = num.replace("$", "")
    num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    return parseFloat(num).toFixed(0);
}

function change_unitcost() {
    var uc = getElementByID_Master("UnitCostSpan");
    var uc2 = getElementByID_Master("UnitCostSpan2");
    var ucv2 = getElementByID_Master("RegularPrice2LB");
    var ps = getElementByID_Master("ProductColors");
    var curr_value = 0;
    var nodecimal = getElementByID_Master("NoDecimalEnable");
    var disablesalepricerange = getElementByID_Master("DisableSalePriceRange");

    if (ps != null) {
        curr_value = ps.selectedIndex;
    }

    HideElem("RegularPrice2LB");

    if (uc == null)
        return;

    if (aSKUUnitCost[g_color] == null) {
        reset_unitcost(uc, 0);
        return;
    }

    //out of stock sizes are removed on reload_sizes() if it is a dropdown
    //therefore it needs to change g_size index to get correct index value of aSKUUnitCost.
    //any clients using dropdown as size selector must have "DropDownSizeSelector" hidden type at ProductDetail page
    var ddss = getElementByID_Master("DropDownSizeSelector");
    if (ddss != null) {
        var productsizes = getElementByID_Master("ProductSizes");
        if (productsizes != null && productsizes.getElementsByTagName("option").length > 0) {
            if (productsizes[g_size] != null && productsizes[g_size].innerHTML != null && productsizes[g_size].innerHTML != '') {
                var sizeName = productsizes[g_size].innerHTML;
                if (size_names != null) {
                    for (var i = 0; i < size_names.length; i++) {
                        if (size_names[i] == sizeName) {
                            g_size = i;
                            break;
                        }
                    }
                }
            }
        }
    }

    var skipResetUnitCost = false;
    var itemsOnSale = getElementByID_Master("sizesOnSale");
    if (itemsOnSale != null) {
        var salesPricesOnstock = new Array(0);
        var salesSizNames = new Array(0);
        var indexCount = 0;
        var onStockCount = 0;
        for (var i = 0; i < aSKUUnitCostOnSale[g_color].length; i++) {
            var itemOnStock = aSCSA[g_color][i + 1];
            if (itemOnStock) {
                onStockCount++;
            }
            var saleItem = aSKUUnitCostOnSale[g_color][i + 1];
            if (itemOnStock && saleItem) {
                salesSizNames[indexCount] = size_names[i + 1];
                salesPricesOnstock[indexCount] = parseFloat(aSKUUnitCost[g_color][i + 1].replace("$", ""));
                indexCount++;
            }
        }
        if ((salesSizNames.length > 0 && (onStockCount == indexCount)) || salesSizNames.length == 0) {
            HideElem("sizesOnSale");
            itemsOnSale.innerHTML = "";
            if (ucv2 != null) {
                if (aSKUUnitCost[g_color][g_size] == null || aSKUUnitCost[g_color][g_size] == '') {
                    if (salesPricesOnstock.length > 0) {
                        skipResetUnitCost = true;
                        var maxSalePrice = Math.max.apply(Math, salesPricesOnstock).toFixed(2);
                        var minSalePrice = Math.min.apply(Math, salesPricesOnstock).toFixed(2);
                        var price;
                        if (minSalePrice != maxSalePrice) {
                            if (nodecimal != null) {
                                price = "$" + formatCurrencyZeroDecimal(minSalePrice) + " - $" + formatCurrencyZeroDecimal(maxSalePrice);
                            } else {
                                price = "$" + minSalePrice + " - $" + maxSalePrice;
                            }
                        }
                        else {
                            if (nodecimal != null) {
                                price = "$" + formatCurrencyZeroDecimal(maxSalePrice);
                            }
                            else {
                                price = "$" + maxSalePrice;
                            }
                        }

                    }
                    uc.innerHTML = price;
                    if (uc2 != null)
                        uc2.innerHTML = price;
                } //aSKUUnitCost[g_color][g_size] == null
                ShowElem("RegularPrice2LB");
            } //ucv2 != null
        } else {
            ShowElem("sizesOnSale");
            var listSizeNames = "";
            for (var i = 0; i < salesSizNames.length; i++) {
                listSizeNames += salesSizNames[i] + (i == salesSizNames.length - 1 ? "" : ", ");
            }
            itemsOnSale.innerHTML = "<br/>* " + (salesSizNames.length > 1 ? "sizes" : "size") + " on sale: " + listSizeNames;
        }
    }

    var val = aSKUUnitCost[g_color][g_size];
    if (val == null || val == '') {
        if (!skipResetUnitCost)
            reset_unitcost(uc, 1);
        return;
    }

    if (ucv2 != null) {
        if (val == g_unitcost)
            HideElem("RegularPrice2LB");
        else if (val == aSKUUnitCost[curr_value][0] && aSKUPreviousCost[curr_value][1] == '') {
            HideElem("RegularPrice2LB");
        }
        else {
            if (disablesalepricerange != null) {
                ucv2.innerHTML = aSKUPreviousCost[curr_value][1];
                ShowElem("RegularPrice2LB");
            }
            else {
                ShowElem("RegularPrice2LB");
            }
        }
    }

    if (nodecimal != null)
        uc.innerHTML = "$" + formatCurrencyZeroDecimal(val);
    else
        uc.innerHTML = val;

    if (uc2 != null)
        uc2.innerHTML = val;

    var cscd = getElementByID_Master("CustomSaleColorDisplayHidden");
    if (cscd != null && ucv2 != null && uc != null) {
        var ary = cscd.value.split(",");
        if (ucv2 != null) {
            uc.style.color = ary[0];

            if (ary[2] != null && ucv2 != null) {
                ucv2.className = ary[2];
            }
        }
        if (ucv2.style.display == "none") {
            uc.style.color = ary[1];
        }
    }
}

function reset_unitcost_col(productid, uc) {
    if (eval("g_unitcost_" + productid) == '$0.00') {
        if (eval("g_mincost_" + productid) == eval("g_maxcost_" + productid))
            uc.innerHTML = eval("g_maxcost_" + productid);
        else
            uc.innerHTML = eval("g_mincost_" + productid);
    }
    else {
        uc.innerHTML = eval("g_unitcost_" + productid);
    }
}

function change_unitcost_col(productid, i) {
    //alert(productid + " " + i);
    var uc = getElementByID_Master("UnitCostSpan_" + productid);
    //alert(uc);
    if (uc == null)
        return;

    //alert(eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]"));
    if (eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]") == null) {
        //alert('reset1');
        reset_unitcost_col(productid, uc);
        return;
    }

    var val = eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]");
    if (val == null || val == '') {
        //alert(val + ' :reset2' + " aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]" + ' g_color: ' + eval("g_color_" + productid) + ' g_size: ' + eval("g_size_" + productid));
        reset_unitcost_col(productid, uc);
        return;
    }

    uc.innerHTML = val;
}

function reset_previouscost_col(productid, pc) {
    if (eval("g_previouscost_" + productid) == '$0.00') {

        pc.innerHTML = '';
    }
    else {
        pc.innerHTML = eval("g_previouscost_" + productid);
    }
}

function reset_previouscost(pc) {
    if (g_previouscost == '$0.00') {
        HideElem("PreviousCost");
        HideElem("PreviousCostCustom");
        HideElem("PreviousCostCustom2");

        pc.innerHTML = '';
    }
    else {
        pc.innerHTML = g_previouscost;

        if (g_previouscost == g_unitcost) {
            HideElem("PreviousCostCustom");
            HideElem("PreviousCostCustom2");
        }
        else {
            ShowElem("PreviousCost");
            ShowElem("PreviousCostCustom");
            ShowElem("PreviousCostCustom2");
        }
    }
}

function change_previouscost() {
    var pc = getElementByID_Master("PreviousCostSpan");
    if (pc == null)
        return;

    if (aSKUPreviousCost[g_color] == null) {
        reset_previouscost(pc);
        return;
    }

    var val = aSKUPreviousCost[g_color][g_size];
    if (val == null || val == '') {
        reset_previouscost(pc);
        return;
    }

    ShowElem("PreviousCost");
    ShowElem("PreviousCostCustom");
    ShowElem("PreviousCostCustom2");

    pc.innerHTML = val;
}

function change_previouscost_col(productid, i) {
    //alert(productid + " " + i);
    var pc = getElementByID_Master("PreviousCostSpan_" + productid);
    //alert(uc);
    if (pc == null)
        return;

    //alert(eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]"));
    if (eval("aSKUPreviousCost_" + productid + "[" + "g_color_" + productid + "]") == null) {
        //alert('reset1');
        reset_previouscost_col(productid, pc);
        return;
    }

    var val = eval("aSKUPreviousCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]");
    if (val == null || val == '') {
        //alert(val + ' :reset2' + " aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]" + ' g_color: ' + eval("g_color_" + productid) + ' g_size: ' + eval("g_size_" + productid));
        reset_previouscost_col(productid, pc);
        return;
    }

    pc.innerHTML = val;
}


function zoom_show(width, height) {
    //    alert('zoom_show');
    var rzg = getElementByID_Master("RealZoomGraphic");
    if (rzg != null)
        rzg.style.visibility = "visible";

    //alert(width + " " + height);
    zoom_zoomimagewid = width;
    zoom_zoomimagehei = height;

    Zoom_ReInitialize();
}

function zoom_hide() {
    //    alert('zoom_hide');
    var rzt = getElementByID_Master("realZOOMBG");
    if (rzt != null)
        rzt.style.visibility = "hidden";

    var rzg = getElementByID_Master("RealZoomGraphic");
    if (rzg != null)
        rzg.style.visibility = "hidden";

    zoom_zoomimagewid = 0;
    zoom_zoomimagehei = 0;

    Zoom_DeInitialize();
}

function zoom_show_if_loaded(width, height) {
    if (width > 0)
        zoom_show(width, height);
}

function get_product_image() {
    var x = document.images['ProductImage'];
    if (x == null)
        x = document.images['ProductImage2'];
    if (x == null)
        x = document.images['ContentPlaceHolder1_ProductImage'];
    if (x == null)
        x = document.images['ContentPlaceHolder1_ProductImage2'];
    if (x == null)
        x = document.images['ctl00_ContentPlaceHolder1_ProductImage'];
    if (x == null)
        x = document.images['ctl00_ContentPlaceHolder1_ProductImage2'];

    return x;
}

function change_zoom_realzoom(img, regpath, detailpath) {
	// Get the OnClick text from ProductImageHL
    var pih = getElementByID_Master("ProductImageHL");
    if (pih != null) {
        var f = pih.getAttribute('OnClick').toString();
        if (f.indexOf('anonymous') != -1) {
            f = f.substr(23, f.length - 24);
        }
        zoom_zoomclickfuncs += f;
    }

    zoom_mainimageurl = regpath + img;
    zoom_zoomimageurl = detailpath + img.replace(".jpg", "_z.jpg");

    //    alert(zoom_mainimageurl + " " + zoom_zoomimageurl);
    //    alert(loadzoom);

    //    var zmi = new Image();
    //    zmi.onerror = zoom_image_missing;
    //    zmi.src = zoom_mainimageurl;

    // Temporarily removed "Safari" Agent checker for testing - Richard 05-22-08

    /*
    if (navigator.userAgent.indexOf("Safari") != -1)
    {
    zoom_hide();
    var zzi = new Image();
    zzi.src = zoom_zoomimageurl;
    window.setTimeout("zoom_show_if_loaded(" + zzi.width + ", " + zzi.height + ")", 2000);
    }
    else
    {
    */
    var zzi = new Image();
    zzi.onerror = zoom_hide;
    zzi.onload = function () { zoom_show(zzi.width, zzi.height); };
    zzi.src = zoom_zoomimageurl;
    //   }
}

function change_zoom_magiczoom(img, regpath, detailpath) {
    // Get the OnClick text from ProductImageHL
    var pih = getElementByID_Master("ProductImageHL");
    if (pih == null)
        return;

    MagicZoom_stopZooms();
    pih.href = detailpath + img.replace(".jpg", "_z.jpg");
    setTimeout('MagicZoom_findZooms()', 100);
}

function change_fullZoom() {
    var fZoomExtra = getElementByID_Master("fullZoomExtraMedia");
    var fZoomMainContainer = getElementByID_Master("fullZoomMainContainer");
    if (fZoomExtra && fZoomMainContainer) {
        
        var colorIndex = parseInt(g_color);
        var fZoomExtraContext = "";
        for (var i = 1; i < aExtraGroupColors[colorIndex].length; i++) {
            //<a href="javascript:void(0)" onclick="change_extra3(<%: emi.Index %>)"><img src="<%: emi.Src %>" width="65" height="98" alt="<%= emi.Alt %>" id="DetailModal1_ExtraMediaButton<%= int.Parse(emi.Index) + 1 %>_img" /></a>
            fZoomExtraContext += "<a href=\"javascript:void(0)\" onclick=\"change_extra3(" + (i - 1) + ")\"><img src=\"" + aExtraGroupColors[colorIndex][i] + "\" width=\"65\" height=\"98\" alt=\"\" id=\"DetailModal1_ExtraMediaButton" + (i) + "_img\" /></a>";
        }
        fZoomExtra.innerHTML = fZoomExtraContext;
        //<%--<img id="ContentPlaceHolder1_DetailModal1_ProductZoomImage" src="<%: LargeImageUrl %>" width="714" height="1071" alt="" />--%>
        var imgSRC = "/store/productimages/details/" + aColor[colorIndex].replace(".jpg", "_z.jpg");
        fZoomMainContainer.innerHTML = "<img id=\"ContentPlaceHolder1_DetailModal1_ProductZoomImage\" src=\"" + imgSRC + "\" width=\"714\" height=\"1071\" alt=\"\" />";
    }
}

function change_zoom(img, regpath, detailpath) {
    //zoom_hide();
    var mir = getElementByID_Master("RealZoomH");
    if (mir != null) {
        change_zoom_realzoom(img, regpath, detailpath);
        return;
    }

    var mz = getElementByID_Master("MagicZoomHidden");
    if (mz != null) {
        change_zoom_magiczoom(img, regpath, detailpath);
        return;
    }

    var ppht = getElementByID_Master("PrettyPopupHeight");
    var pp = getElementByID_Master("PrettyPhotoPopup");
    var height = "457";

    if (ppht != null)
        height = ppht.value;

    if (pp != null) {
        if (regpath == null)
            pp.href = "/store/zoom_popup.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=760&height=" + height;
        else
            pp.href = "/store/zoom_popup.aspx?img=" + detailpath + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=760&height=" + height;
    }

    var ppext = getElementByID_Master("PrettyPhotoPopupExtended");
    if (ppext != null) {
        if (regpath == null)
            ppext.href = "/store/zoom_popup_ext.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=795&height=" + height;
        else
            ppext.href = "/store/zoom_popup_ext.aspx?img=" + detailpath + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=795&height=" + height;
    }

    var pphl = getElementByID_Master("PrettyPopupHl");
    if (pphl != null) {
        var img = '';

        if (getElementByID_Master("ExtraMediaButton1") != null) {
            img = aExtraGroupColors[g_color][1];
            getElementByID_Master("ExtraMediaButton1").href = "/store/zoom_popup.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=868&height=" + height;
        }
        if (getElementByID_Master("ExtraMediaButton2") != null) {
            img = aExtraGroupColors[g_color][2];
            getElementByID_Master("ExtraMediaButton2").href = "/store/zoom_popup.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=868&height=" + height;
        }
        if (getElementByID_Master("ExtraMediaButton3") != null) {
            img = aExtraGroupColors[g_color][3];
            getElementByID_Master("ExtraMediaButton3").href = "/store/zoom_popup.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=868&height=" + height;
        }
        if (getElementByID_Master("ExtraMediaButton4") != null) {
            img = aExtraGroupColors[g_color][4];
            getElementByID_Master("ExtraMediaButton4").href = "/store/zoom_popup.aspx?img=" + img.replace(".jpg", "_z.jpg") + "&iframe=true&width=868&height=" + height;
        }
    }


    var zoomImage = getElementByID_Master("ZoomImage");

//    if (zoomImage != null) {
//    	try {
//            var displayiImg = img;
//            if (displayiImg.toUpperCase().indexOf("STORE/PRODUCTIMAGES/DETAILS") > 0) {
//                displayiImg = displayiImg.replace(".jpg", "_z.jpg");
//            }
//           else {
//               	if (getElementByID_Master("ContentPlaceHolder1_s7ProductImage")) {
//               		if (getElementByID_Master("ContentPlaceHolder1_S7ZoomHiddenPath") != null) {
//               			displayiImg = document.getElementById("ContentPlaceHolder1_S7ZoomHiddenPath").value;
//               			getElementByID_Master("ContentPlaceHolder1_ZoomImage").href = displayiImg;
//               		}
//               	} else {
//               		displayiImg = "/store/productimages/details/" + displayiImg.replace(".jpg", "_z.jpg");
//               	}
//               }
//            zoomImage.href = displayiImg;
//        }
//        catch (err) { }
//    }

    var modalzoom = document.getElementById("ContentPlaceHolder1_DetailModal1_ProductZoomImage");
    if (modalzoom != null) {
        try {
            modalzoom.src = "/store/productimages/details/" + img.replace(".jpg", "_z.jpg");
        }
        catch (err) { }
    }

    change_fullZoom();
}

function set_color(i) {
	var s7prImage = getElementByID_Master('ContentPlaceHolder1_s7ProductImage');
	var s7SpinSet = getElementByID_Master('scene7Container');
	var ss;

	g_color = i;

    try {
		//Checking for Scene7 PlaceHolders
    	if (s7prImage != null && s7SpinSet != null) {
    		ss = aColor[i];
    		ss = ss.replace('_l.jpg', '_ss');
    		//Defined at the Product Detail level (see SEVN > scene7view.ascx)
    		if (typeof setScene7 !== "undefined") {
				setScene7(ss);
    		} 
    	} else {
    		get_product_image().src = "/store/productimages/regular/" + aColor[i];
		}


    }
    catch (err) {
    }
    setElem("Message", "");
    if (g_size_priority == 0)
        reload_sizes();
    change_upc();
    change_unitcost();
    change_previouscost();
    change_costspans();
    change_extragroup();
}

function change_color(i) {
    set_color(i);
    change_zoom(aColor[i], "/store/productimages/regular/", "/store/productimages/details/");

    try {
        setElem("AddToCartMessage", "");

        if (g_isvproductid == 1)
            change_vpid_elements(i - 1);
    }
    catch (err) { }
}

function change_vpid_elements(i) {
    var modelname = getElementByID_Master("ModelNameLB");
    var description = getElementByID_Master("TD1_DescriptionLB");
    var mfgsku = getElementByID_Master("MFGSKUL");
    var breadcrumb = getElementByID_Master("modelname");

    if (modelname != null)
        modelname.innerHTML = aModelName[i];

    if (description != null)
        description.innerHTML = aDescription[i];

    if (mfgsku != null)
        mfgsku.innerHTML = aMfgSku[i];

    if (breadcrumb != null)
        breadcrumb.innerHTML = aModelName[i];
}

function change_extrabutton(hyperlinkname, imgname, elementindex) {
     //alert(g_color + " " + hyperlinkname + " " + imgname + " " + elementindex);


    if (g_useextragroup_colors == 0)
    	return;

    var e_img = getElementByID_Master(imgname);
    if (e_img == null)
        return;


    var e_hl = getElementByID_Master(hyperlinkname);
    if (e_hl == null)
    	return;


    try {
        if (aExtraGroupColors[g_color] == null || aExtraGroupColors[g_color][elementindex] == null) {
            e_hl.style.visibility = "hidden";
            e_img.src = '';
            return;
           }

        e_hl.style.visibility = "visible";
        e_img.src = aExtraGroupColors[g_color][elementindex];
    }
    catch (err) {
    }
}

function change_extragroup() {
    change_extrabutton("ExtraMediaButton1", "ExtraMediaButton1_img", 1);
    change_extrabutton("ExtraMediaButton2", "ExtraMediaButton2_img", 2);
    change_extrabutton("ExtraMediaButton3", "ExtraMediaButton3_img", 3);
    change_extrabutton("ExtraMediaButton4", "ExtraMediaButton4_img", 4);
    change_extrabutton("ExtraMediaButton5", "ExtraMediaButton5_img", 5);
    change_extrabutton("ExtraMediaButton6", "ExtraMediaButton6_img", 6);
    change_extrabutton("ExtraMediaButton7", "ExtraMediaButton7_img", 7);
    change_extrabutton("ExtraMediaButton8", "ExtraMediaButton8_img", 8);
    change_extrabutton("ExtraMediaButton9", "ExtraMediaButton9_img", 9);
    change_extrabutton("ExtraMediaButton10", "ExtraMediaButton10_img", 10);
}

function change_stockalert() {
    var stock = getElementByID_Master("Stock");
    var stockLevelAlert = getElementByID_Master("StockLevelAlert");
    var oosalert = getElementByID_Master("OOSAlert");
    if (stockLevelAlert == null)
        return;

    if (aSCSA[g_color][g_size] == false || g_size == 0) {

        if (stock != null)
            stock.style.visibility = "hidden";

        if (oosalert != null && aStockLevels[g_color][g_size] == 0)
            oosalert.style.visibility = "visible";

        stockLevelAlert.style.visibility = "hidden";
        return;
    }

    var stockLevel1 = getElementByID_Master("stockLevel1");
    var stockLevel2OrLess = getElementByID_Master("StockLevel2OrLess");
    var stockLevel3OrLess = getElementByID_Master("StockLevel3OrLess");
    var AdjustLowStockMsg = getElementByID_Master("AdjustLowStockMsg");

    if (stockLevel3OrLess != null && aStockLevels[g_color][g_size] < 4) {
        setElem("StockLevel3OrLess", aStockLevels[g_color][g_size]);
        stockLevelAlert.style.visibility = "visible";
    }
    else if (stockLevel2OrLess != null && aStockLevels[g_color][g_size] < 3) {
        if (oosalert != null)
            oosalert.style.visibility = "hidden";
        setElem("StockLevel2OrLess", aStockLevels[g_color][g_size]);
        stockLevelAlert.style.visibility = "visible";
    }
    else if (AdjustLowStockMsg != null) {
        AdjustLowStockMsg.innerHTML = "";
        checkAdjustableStockLevel(aStockLevels[g_color][g_size]);
    }
    else if (stockLevel1 != null && aStockLevels[g_color][g_size] < 2) {
        setElem("stockLevel1", aStockLevels[g_color][g_size]);
        stockLevelAlert.style.visibility = "visible";
    }
    else {
        if (oosalert != null)
            oosalert.style.visibility = "hidden";
        stockLevelAlert.style.visibility = "hidden";
    }
}

function change_size(i) {
    g_size = i;
    setElem("Message", "");
    if (g_size_priority == 1)
        reload_colors();
    change_upc();
    change_unitcost();
    change_previouscost();
    change_costspans();

    try {
        setElem("AddToCartMessage", "");
    }
    catch (err) { }
}

function change_extra(i) {
    document.images['theimage'].src = aExtra[i];
}

function change_extra2(i) { 
    //    alert('change_extra2(' + i + ')');
    if (color_count > 1) {
        set_color(getElementByID_Master("ProductColors").selectedIndex);
    }
    try {
        if (getElementByID_Master("OverrideChangeExtra2") != null && getElementByID_Master("OverrideChangeExtra2").value == "1")
            return;

        get_product_image().src = aExtra[i];
    }
    catch (err) {
    }
    change_zoom(aExtra[i], "", "");
   }


function change_extra3(i) {

    if (g_useextragroup_colors == 0)
        return;

    if (aExtraGroupColors[g_color] == null || aExtraGroupColors[g_color][i + 1] == null)
        return;

    var img = aExtraGroupColors[g_color][i + 1];
    img = img.replace("_t.jpg", ".jpg");

    try {
    	if (document.getElementById("ContentPlaceHolder1_s7ProductImage") != null) {
    		scene7_proddet_img(document.getElementById("ContentPlaceHolder1_s7ProductImage"), img);
    	}
    	get_product_image().src = img;
    }
    catch (err) {
    }
    change_zoom(img, "", "");

    var educontent = getElementByID_Master("EduHidden");

    if (educontent != null) {
        try {
            $("#ContentPlaceHolder1_ProductImage").removeAttr('width')
            $("#ContentPlaceHolder1_ProductImage").removeAttr('height');
            $('.jcarousel-text').fadeIn('slow', function () {
                $('.jcarousel-text').html(aExtraGroupText[g_color][i + 1]);
            });
        }
        catch (err) { }
    }

       var quicklookzoom = getElementByID_Master("ZoomImage");
       if (quicklookzoom != null) {
    	try {
    		if (getElementByID_Master("ContentPlaceHolder1_s7ProductImage")) {
    			if (getElementByID_Master("ContentPlaceHolder1_S7ZoomHiddenPath") != null) {
    				if (img.indexOf("/store/ProductImages/") == -1) {
    					img = img.substring(0, img.indexOf('?'));
    					img = img + '?wid=600&hei=900';
    					quicklookzoom.href = img;
    				} else {
    					quicklookzoom.href = img.replace(".jpg", "_z.jpg");
    				}
    			}
    		} else {
    			quicklookzoom.href = img.replace(".jpg", "_z.jpg");
    		}

        }
        catch (err) { }
    }

       var modalzoom = document.getElementById("ContentPlaceHolder1_DetailModal1_ProductZoomImage");
    if (modalzoom != null) {
    	try {
    			modalzoom.src = img.replace(".jpg", "_z.jpg");
        }
        catch (err) { }
    }
}

function scene7_proddet_img(img, src) {
	img.src = src;
}

function Contains(s) {
    if (s.indexOf(s) >= 0) {
        return 1;
    }

    return 0;
}

function change_and_select_color(i, cid, qtycid) {
    if (Contains("ProductColors")) {
        var pc = getElementByID_Master("ProductColors");
        if (pc != null) {
            pc.selectedIndex = i;
        }
        change_color(i);
        window.status = '';
    }
    else {
        try {
            getElementByID_Master(cid).selectedIndex = i;
            // 	if(getElementByID_Master(qtycid)!= null && getElementByID_Master(qtycid).value=='')
            //	    getElementByID_Master(qtycid).value = '1'; 
        }
        catch (err) { }
    }
}

function set_selection(id, val) {
    getElementByID_Master(id).selectedIndex = val;
}

function show_color(i) {
    try {
        get_product_image().src = "/store/productimages/regular/" + aColor[i];
    }
    catch (err) {
    }
}

function swatch_mouse_out(i) {
    window.status = '';
    if (g_color != i)
        MM_swapImgRestore();
    show_color(g_color);
    window.status = '';
}

function swatch_mouse_over(i, color_name, over_img_name) {
    window.status = '';
    MM_swapImage(color_name, '', over_img_name, 1);
    show_color(i);
    window.status = color_name;
}

function swatch_click(i, color_name, img_name) {
    window.status = '';
    MM_swapImage(g_swatch_name, '', g_swatch_img, 1);
    change_and_select_color(i);
    g_swatch_name = color_name;
    g_swatch_img = img_name;
    window.status = color_name;
}

function size_swatch_click(i, size_name) {
    window.status = '';
    if (document.getElementById("dvSelectedSize") != null) {
        document.getElementById("dvSelectedSize").innerHTML = size_name;
    }
    set_selection("ProductSizes", i);
    set_size_swatch(i);
    change_size(i);
    window.status = size_name;
}

function set_size_swatch(i) {
    for (var i = 0; i < size_count; i++) {
        var j = i + 1;
        var sw = getElementByID_Master("SizeSwatch_" + j);
        if (sw == null)
            continue;

        if (g_size == j)
            sw.className = "sizebox active";
        else
            sw.className = "sizebox a";
    }
}

function NoChangeAll(nochangename, updatename) {
    var ml = document.forms[0];
    var len = ml.elements.length;

    for (var i = 0; i < len; i++) {
        var e = ml.elements[i];
        if (e.value == nochangename) {
            e.checked = true;
        }
        if (e.value == updatename) {
            e.checked = false;
        }
    }
}

function UpdateAll(nochangename, updatename) {
    var ml = document.forms[0];
    var len = ml.elements.length;

    for (var i = 0; i < len; i++) {
        var e = ml.elements[i];
        if (e.value == nochangename) {
            e.checked = false;
        }
        if (e.value == updatename) {
            e.checked = true;
        }
    }
}

function DefaultButton(btnID, event) {
    btn = getElementByID_Master(btnID);
    
    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancelBubble = true;
            btn.focus();
            btn.click();
        }
    }
    else if (document.getElementById) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancelBubble = true;            
            btn.click();
            btn.focus();
        }
    }
    else if (document.layers) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancelBubble = true;            
            btn.focus();
            btn.click();
        }
    }
}

function findObj(n, d) {
    var p, i, x;

    if (!d)
        d = document;

    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }

    if (!(x = d[n]) && d.all)
        x = d.all[n];

    for (i = 0; !x && i < d.forms.length; i++)
        x = d.forms[i][n];

    for (i = 0; !x && d.layers && i < d.layers.length; i++)
        x = findObj(n, d.layers[i].document);

    if (!x && d.getElementById)
        x = d.getElementById(n);

    return x;
}

function change_img(imgid, img) {
    var i = getElementByID_Master(imgid);
    if (i == null)
        return;

    i.src = eval(img + ".src");
}

function change_master_img(img) {
    change_img("master_img", img);
}

function change_master_text(txt) {
    var i = getElementByID_Master("master_text");
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_text2(txt, txtid) {
    var i = getElementByID_Master(txtid);
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_link(link) {
    var i = getElementByID_Master("master_link");
    if (i == null)
        return;

    i.href = link;
}

function change_master_link2(link, linkid) {
    var i = getElementByID_Master(linkid);
    if (i == null)
        return;

    i.href = link;
}

function change_master_price(txt) {
    var i = getElementByID_Master("master_price");
    if (i == null)
        return;

    /// FOR QL COLOR SPLIT UPDATES ///
    while (txt.toLowerCase().indexOf('<a ') != -1) {
        txt = txt.replace('<a ', '<');
        txt = txt.replace('<A ', '<');
        txt = txt.replace('</a>', '</>');
        txt = txt.replace('</A>', '</>');
    }

    i.innerHTML = txt;
}

function change_master_price2(txt, txtid) {
    var i = getElementByID_Master(txtid);
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_mfgsku(txt) {
    var i = getElementByID_Master("master_mfgsku");
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_morecolors(txt) {
    var i = getElementByID_Master("master_colors");
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_new(txt) {
    var i = getElementByID_Master("master_newtxt");
    if (i == null)
        return;

    i.innerHTML = txt;
}

function lightup(imageobject, opacity) {
    var obj = getElementByID_Master(imageobject);

    if (navigator.userAgent.indexOf("Safari") != -1)
        obj.style.opacity = opacity / 100;
    else if ((navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5))
        obj.style.MozOpacity = opacity / 100;
    else if ((navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4))
        obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
}

function set_master_img(img) {
    var i = getElementByID_Master("master_img");
    if (i == null)
        return;

    i.src = img;
}

function outfit_left() {
    g_outfitindex--;
    if (g_outfitindex <= 0)
        g_outfitindex = g_numoutfits - 1;

    reload_outfits(g_outfitindex);
}

function outfit_right() {
    g_outfitindex++;
    if (g_outfitindex == g_numoutfits)
        g_outfitindex = 1;

    reload_outfits(g_outfitindex);
}

function reload_outfits(current_outfit) {
    var outfit_changer = current_outfit;

    for (var i = 1; i <= g_maxdisplaythumbscollection; i++) {
        var img = getElementByID_Master("OutfitThumbRPT_ctl" + zeropad(i) + "_OutfitNavImage");
        var imghl = getElementByID_Master("OutfitThumbRPT_ctl" + zeropad(i) + "_OutfitNavImageHL");
        if (img != null)
            img.src = "/store/productimages/thumbs/" + aOutfitThumb[outfit_changer];

        if (imghl != null)
            imghl.href = aOutfitThumbHL[outfit_changer];

        outfit_changer++;
        if (outfit_changer == g_numoutfits)
            outfit_changer = 0;
    }
}

function change_color_col_img(imgctlname, productid, i) {
    var img = getElementByID_Master(imgctlname);
    if (img == null)
        return;

    var imgpath = "/store/productimages/regular/" + eval("aColors_" + productid + "[i]");
    img.src = imgpath;
}

function change_color_col(imgctlname, productid, i) {
    this["g_color_" + productid] = i;

    change_color_col_img(imgctlname, productid, i);
    change_unitcost_col(productid, i);
    change_previouscost_col(productid, i);
}

function change_size_col(productid, i, qtycid, sizecid) {
    //    alert(eval("g_color_" + productid));

    this["g_size_" + productid] = i;

    change_unitcost_col(productid, i);
    change_previouscost_col(productid, i);

    if (getElementByID_Master(qtycid) != null && getElementByID_Master(qtycid).value == '')
        getElementByID_Master(qtycid).value = '1';

    var ps = getElementByID_Master(sizecid);

    if (ps == null)
        return;

    var curr_value = ps.options[ps.selectedIndex].value;

    if (curr_value == '-1')
        getElementByID_Master(qtycid).value = '';
}

function GetQueryStringVar(name) {
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var tmpURL = window.location.href;
    var results = regex.exec(tmpURL);
    if (results == null)
        return "";
    else
        return results[1];
}

function toggle_RPTFullDivItem(i) {
    var div = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_RPTFullDiv");
    if (div.style.visibility == "hidden")
        div.style.visibility = "visible";
    else
        div.style.visibility = "hidden";
}

function unset_checkbox(i, j) {
    var rb_ip = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_PM1_PetiteRB");
    var rb_jp = getElementByID_Master("ProductRPTFull_ctl" + zeropad(j) + "_PM1_PetiteRB");

    if (rb_ip.checked == true) {
        rb_jp.checked = true;
    }
    else {
        rb_jp.checked = false;
    }

    var rb_im = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_PM1_MissyRB");
    var rb_jm = getElementByID_Master("ProductRPTFull_ctl" + zeropad(j) + "_PM1_MissyRB");

    if (rb_im.checked == true) {
        rb_jm.checked = true;
    }
    else {
        rb_jm.checked = false;
    }
}

function toggle_RPTFullDiv(rb, i, j) {
    unset_checkbox(i, j);

    toggle_RPTFullDivItem(i);
    toggle_RPTFullDivItem(j);

    return false;
}

function get_DIVVisibilityStates() {
    var s = "";

    for (var i = 0; i < 10; i++) {
        var div = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_RPTFullDiv");
        if (div == null)
            continue;

        if (div.style.visibility == "hidden")
            s += "h";
        else
            s += "v";
    }

    return s;
}


function AttributePoster() {
    var a = "";

    var ProductSizesV = getElementByID_Master("ProductSizesV");
    if (ProductSizesV != null)
        ValidatorEnable(ProductSizesV, false);
    var ProductColorsV = getElementByID_Master("ProductColorsV");
    if (ProductColorsV != null)
        ValidatorEnable(ProductColorsV, false);

    // Get the selected values from the nav and send to the productslist page
    for (var i = 0; i < aAttributes.length; i++) {
        var c = getElementByID_Master(aAttributes[i]);
        if (c == null)
            continue;

        a += c.value;

        if (i + 1 < aAttributes.length)
            a += ",";
    }

    var vals = "";

    if (a.length > 0)
        vals += "&a=" + a;

    // See if there's a size option
    var s = getElementByID_Master(AttributeSizeNameDDL.id);
    if (s != null && s.length > 0)
        vals += "&sn=" + s.value;

    location.href = "/l/" + AttributeSearchCategoryID + vals;
}

// function change image
function chgimg(imgfield, newimg) {
    if (document.images) {
        document[imgfield].src = eval(newimg + ".src")
    }
}

function openWin(url, name, height, width) {
    remote = window.open(url, name, 'height=' + height + ',width=' + width + ',titlebar=0,channelmode=0,screenX=10,left=10,screenY=10,top=10,hotkeys=0,dependent=1,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0');
    remote.focus();
    if (remote.opener == null) remote.opener = window;
    // remote.opener.name = 'opener';
}

function openbranchby_branchnamevar() {
    if (typeof (branchname) != 'undefined') {
        openBranchByName(branchname);
    }
}

function doSort(val) {
    filterorsort("sort", val);
}

function doSizeFilter(val) {
    filterorsort("sizef", val);
}

function doColorFilter(val) {
    filterorsort("colorf", val);
}

function doParentColorFilter(val) {
    filterorsort("fcwpidf", val);
}

function doStyleFilter(val) {
    filterorsort("stylef", val);
}

function doFabricationFilter(val) {
    filterorsort("fabricationf", val);
}

function doFitFilter(val) {
    filterorsort("fitf", val);
}

function doFabricFilter(val) {
    filterorsort("fabricf", val);
}

function doRiseFilter(val) {
    filterorsort("risef", val);
}

function doOccasionFilter(val) {
    filterorsort("occasionf", val);
}

function doStyleFilter(val) {
    filterorsort("stylef", val);
}

function doBrandFilter(val) {
    filterorsort("brandf", val);
}

function doWashFilter(val) {
    filterorsort("washf", val);
}

function doSupportFilter(val) {
    filterorsort("supportf", val);
}

function doSportFilter(val) {
    filterorsort("sportf", val);
}

function doPriceFilter(min, max) {
    filterorsort2("minf", min, "maxf", max);
}

function doPriceFilter2(val) {
    var o = val.split(',');
    if (o.length == 1)
        o[1] = '';
    filterorsort2("minf", o[0], "maxf", o[1]);
}

function addsingleparam(param, value, searchstring, categoryid, parentcolorid, attributeID) {
    var newsearchstring = "";

    if (value == "viewall")
        newsearchstring = categoryid + "?page=0";
    else if (searchstring == "" && (parentcolorid == "" || parentcolorid != "undefined"))
        newsearchstring = categoryid + "?" + param + "=" + (gup(param) == "" ? value : gup(param));
    else if (searchstring == "" && parentcolorid != "")
        newsearchstring = categoryid + "?" + param + "=" + (gup(param) == "" ? value : gup(param)) + "&parentcolorid=" + parentcolorid;
    else {
        if (searchstring.indexOf("?" + param + "=" + gup(param)) == 0)
            newsearchstring = categoryid + searchstring.replace("?" + param + "=" + gup(param), "?" + param + "=" + (gup(param) == "" ? value : gup(param).replace(gup(param), value)));
        else
            newsearchstring = categoryid + searchstring.replace("&" + param + "=" + gup(param), "") + "&" + param + "=" + (gup(param) == "" ? value : gup(param).replace(gup(param), value));
    }

    if (value == "")
        newsearchstring = newsearchstring.replace("&" + param + "=", "")

    if (attributeID > 0)
        newsearchstring += "&a=" + attributeID;

    // don't want categoryid on the new URL since we're using friendlies
    newsearchstring = newsearchstring.replace("?categoryid=" + categoryid + "&", "?");
    newsearchstring = newsearchstring.replace("?categoryid=" + categoryid, "");
    newsearchstring = newsearchstring.replace("&categoryid=" + categoryid, "");
    
    return newsearchstring;
}

function addparam(param, value, base, searchstring, categoryid, parentcolorid) {
    var baseurl = "";
    var newsearchstring = addsingleparam(param, value, searchstring, categoryid, parentcolorid, -1);

    baseurl = base + newsearchstring;

    return baseurl;
}

//overloading method
function addparam(param, value, base, searchstring, categoryid, parentcolorid, attributeID) {
    var baseurl = "";
    var newsearchstring = addsingleparam(param, value, searchstring, categoryid, parentcolorid, attributeID);

    baseurl = base + newsearchstring;

    return baseurl;
}

function getcatname(url) {
	try
	{
		// Get everything after the / before the /l/whatever
		var regex = new RegExp("/([^?>]*)/l([^>]*)");
		var ret = regex.exec(url);

		return ret[1] + "/";
	}
	catch (err) {
		return "";
	}
}

function filterorsort(ctrlname, ctrlvalue) {
    var categoryid = getElementByID_Master("categoryidhidden").value;
    var parentcolorid = 0;
    try {
        parentcolorid = getElementByID_Master("parentcoloridhidden").value;
    }
    catch (err) { }

    var attributeID = 0;
    try {
        attributeID = getElementByID_Master("attributeHidden").value;
    }
    catch (err) { }
    
    var page = window.location.pathname;
    var catname = getcatname(page);
    var base = "";

    if (page.indexOf("productslist2") > 0 || page.indexOf("/l2/") > 0) {
        base = "/" + catname + "l2/";
    } else if (page.indexOf("productslist3") > 0 || page.indexOf("/l3/") > 0) {
        base = "/" + catname + "l3/";
    } else if (page.indexOf("productslist4") > 0 || page.indexOf("/l4/") > 0) {
        base = "/" + catname + "l4/";
    } else {
        base = "/" + catname + "l/";
    }

    var searchstring = window.location.search;
    var baseurl = addparam(ctrlname, ctrlvalue, base, searchstring, categoryid, parentcolorid, attributeID);

    window.location.href = baseurl;
}

function filterorsort2(ctrlname, ctrlvalue, ctrlname2, ctrlvalue2) {
    var categoryid = getElementByID_Master("categoryidhidden").value;
    var base = "/l/";
    var searchstring = window.location.search;
    if (searchstring == "") {
        searchstring = searchstring + "?" + ctrlname + "=" + ctrlvalue;
    }
    else {
        if (searchstring.indexOf(ctrlname) > -1) {
            searchstring = replaceQueryString(searchstring, ctrlname, ctrlvalue);
        }
        else {
            searchstring = searchstring + "&" + ctrlname + "=" + ctrlvalue;
        }
    }
    newsearchstring = searchstring;
    //var newsearchstring = searchstring == "" ? ("?" + ctrlname + "=" + ctrlvalue) : (searchstring + "&" + ctrlname + "=" + ctrlvalue); 
    //addsingleparam(ctrlname, ctrlvalue, searchstring, categoryid, -1);
    var baseurl = addparam(ctrlname2, ctrlvalue2, base, newsearchstring, categoryid);

    window.location.href = baseurl;
}

function replaceQueryString(url, param, value) {
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
    if (url.match(re))
        return url.replace(re, '$1' + param + "=" + value + '$2');
    else
        return url + '&' + param + "=" + value;
}

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

function popup_productemailsignup(w) {
    var pw;
    pw = window.open(w, 'ProductEmailSignup', 'height=508,width=541,toolbar=no,resizable=yes,scrollbars=yes');
    pw.focus();
}

function autoclose_popup(timebeforeclosing) {
    closeMe(timebeforeclosing)
}

function closeMe(timebeforeclosing) {
    t = null;
    t = setTimeout("self.close()", timebeforeclosing);
}

function OutfitListPageLoad() {
    var firstthumb = findObj("OutfitImagesDL_OutfitNavImage");
    if (firstthumb == null)
        firstthumb = findObj("OutfitImagesDL_ctl00_OutfitNavImage");
    if (firstthumb == null)
        return;

    var oc = firstthumb.getAttribute("onmouseover");
    if (oc == null)
        return;

    //    alert(oc);

    var ocs = oc.toString();

    if (ocs.indexOf('anonymous') != -1) {
        ocs = ocs.substr(23, ocs.length - 24);
    }

    //    alert(ocs);

    eval(ocs);
}


function ProductsListPageLoad() {
    var firstthumb = getElementByID_Master("ContentPlaceHolder1_MyList_ThumbnailImage_0");

    if (firstthumb == null)
        firstthumb = getElementByID_Master("MyList_ctl00_ThumbnailImage");

    if (firstthumb == null)
        firstthumb = getElementByID_Master("ContentPlaceHolder1_ProductsListRPTMain_ThumbnailImage_0");

    if (firstthumb == null)
        return;
    var oc = firstthumb.getAttribute("onmouseover");
    if (oc == null)
        return;

    var ocs = oc.toString();

    if (ocs.indexOf('anonymous') != -1) {
        ocs = ocs.substr(23, ocs.length - 24);
    }

    // STRIP EXTRA IE CODE
    if (ocs.indexOf('function onmouseover()') != -1) {
        ocs = ocs.replace('function onmouseover()', '');
    }
    if (ocs.indexOf('{') != -1) {
        ocs = ocs.replace('{', '');
    }
    if (ocs.indexOf('}') != -1) {
        ocs = ocs.replace('}', '');
    }

    eval(ocs);

}

//Start PopOver Swatches
function os_moveemnt(id, x, y) {
    if (document.getElementById) {
        getElementByID_Master(id).style.left = x + 'px';
        getElementByID_Master(id).style.top = y + 'px';
    }
}
function os_showemnt(id) {
    if (document.getElementById) {
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).style.visibility = 'visible';
        }
    }
}
function os_hideemnt(id) {
    if (document.getElementById) {
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).style.visibility = 'hidden';
        }
    }
}
function swhtml(id, html) {
    if (document.getElementById) {
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).innerHTML = html;
        }
    }
}
function os_swmvswh(index, swatchDiv, colorDesc, img) {
    os_strcont = getElementByID_Master("os_swcntr" + index);
    os_strbcont = getElementByID_Master("container");
    os_strconttop = os_strcont.offsetTop + os_strbcont.offsetTop;
    os_strcontleft = os_strcont.offsetLeft + os_strbcont.offsetLeft;
    os_strscontwidth = os_strcont.offsetWidth;
    os_strcontright = os_strcontleft + os_strscontwidth;

    os_strbox = getElementByID_Master("os_swbox");
    os_strboxtop = os_strbox.offsetTop;
    os_strboxleft = os_strbox.offsetLeft;
    os_strboxwidth = os_strbox.offsetWidth;
    os_strsboxheight = os_strbox.offsetHeight;

    os_strboxnewleft = os_strcontleft + (swatchDiv.offsetLeft + (swatchDiv.offsetWidth / 2)) - (os_strboxwidth / 2)
    os_strboxnewright = os_strboxnewleft + (os_strboxwidth)

    if ((os_strboxnewleft) < (os_strcontleft)) {
        sbPosLeft = os_strcontleft;
    } else if ((os_strboxnewright) > (os_strcontright)) {
        sbPosLeft = os_strcontright - os_strboxwidth - 4;
    } else {
        sbPosLeft = os_strboxnewleft;
    }
    imgTag = '<img src="' + img + '">';
    imgURL = '' + img;
    os_showsw(index);
    var IfrRef = getElementByID_Master('dvsh');
    IfrRef.style.width = os_strbox.offsetWidth;
    IfrRef.style.height = os_strbox.offsetHeight;
    IfrRef.style.top = os_strbox.style.top;
    IfrRef.style.left = os_strbox.style.left;
    IfrRef.style.zIndex = 999;

    os_moveemnt('dvsh', sbPosLeft, os_strconttop - os_strsboxheight - 1);
    os_moveemnt('os_swbox', sbPosLeft, os_strconttop - os_strsboxheight - 1);
    swhtml('os_swboxclrdsc', colorDesc);

    swhtml('os_swboximg', imgTag);
}

dispSwatch = false;
function os_swhdswh(index) {
    dispSwatch = false;
    setTimeout('os_dohideswatch()', 100);
}
function os_dohideswatch(index) {
    if (!dispSwatch) {
        var IfrRef = getElementByID_Master('dvsh');
        IfrRef.style.display = "none";
        os_hideemnt('os_swbox');
    }
}
function os_showsw(index) {
    dispSwatch = true;
    var IfrRef = getElementByID_Master('dvsh');
    IfrRef.style.display = "block";
    os_showemnt('os_swbox');
}

{
    document.write("<div class=\"os_swbox\" id=\"os_swbox\">");
    document.write("<div class=\"os_swboximg\" id=\"os_swboximg\"></div>");
    document.write("<div class=\"os_swboxtxt\">");
    document.write("<div class=\"os_swboxclrdsc\" id=\"os_swboxclrdsc\"></div>");
    document.write("<div class=\"os_swboxacn\" id=\"os_swboxacn\"></div>");
    document.write("</div>");
    document.write("</div>");
    document.write("<div class=\"dvsh\" id=\"dvsh\" src=\"javascript:false;\" scrolling=\"no\" style=\"position:absolute; top:0px; left:0px; display:none;\"></div>");
}
//End PopOver Swatches

//PopupHover - Collections Page

function getObj(objectId) {
    if (document.getElementById && getElementByID_Master(objectId)) {
        return getElementByID_Master(objectId).style;
    } else if (document.all && document.all(objectId)) {
        return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
    } else {
        return false;
    }
}

function objvisibilityStatus(objectId, newVisibility) {
    // make sure the object exists
    var styleObject = getObj(objectId);
    if (styleObject) {
        styleObject.visibility = newVisibility;
        return true;
    } else {
        // if we cant find the object change visibility
        return false;
    }
}

function verifyPosition(objectId, x, y) {
    // check if object exists
    var styleObject = getObj(objectId);
    if (styleObject) {
        styleObject.left = x;
        styleObject.top = y;
        return true;
    } else {
        // we couldn't find the object, so we can't very well move it
        return false;
    }
}

// Variables used to determine where the popup opens
var xOffset = 40;
var yOffset = -5;

function openPopup(newObjID, eventObj) {
    if (eventObj) {
        hidePopup();
        eventObj.cancelBubble = true;
        var x = (eventObj.pageX) ? eventObj.pageX + xOffset : eventObj.x + xOffset + ((document.body.scrollLeft) ? document.body.scrollLeft : 0);
        var y = (eventObj.pageY) ? eventObj.pageY + yOffset : eventObj.y + yOffset + ((document.body.scrollTop) ? document.body.scrollTop : 0);
        verifyPosition(newObjID, x, y);
        // and make it visible
        if (objvisibilityStatus(newObjID, 'visible')) {
            // globally-accessible object
            window.currentlyVisiblePopup = newObjID;
            return true;
        } else {
            // popup couldnt be found
            return false;
        }
    } else {
        // no event found
        return false;
    }
}

function hidePopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if (window.currentlyVisiblePopup) {
        objvisibilityStatus(window.currentlyVisiblePopup, 'hidden');
        window.currentlyVisiblePopup = false;
    }
}

// initialize workarounds whenever the page loads
window.onload = initFixes;

// Hide popup if doc is clicked
document.onclick = hidePopup;

function initFixes() {
    if ((navigator.appVersion.indexOf('MSIE 5') != -1)
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getObj('blankDiv')) { }
}


// End PopupHover - Collections Page


//Start Swatches with Selection Enabled


function DisplayDefault(id, DefaultSwatchText, tableName, strlblSwatch) {
    var swatchlabel = getElementByID_Master(strlblSwatch);
    swatchlabel.innerHTML = DefaultSwatchText;
}

function DisplayText(id, SwatchText, currTDValue, tableName, strlblSwatch) {
    var strSwatchText = SwatchText;
    var swatchlabel = getElementByID_Master(strlblSwatch);
    swatchlabel.innerHTML = SwatchText;
    toggleImgColor(id, currTDValue, tableName)
}

function toggleImgColor(id, currentTD, tableName) {
    var tdTag;
    tdTag = getElementByID_Master(tableName).getElementsByTagName('td');

    for (var counter = 0; counter < tdTag.length; counter++) {
        var imgTag = tdTag[counter].getElementsByTagName('img');

        if (imgTag != null) {
            var imgClass = imgTag.item(0).className;

            if (imgClass == 'SelectedImage') {
                imgTag.item(0).className = '';
            }
        }
    }
    if (currentTD == null)
        imgTag.item(0).className = '';
    else
        currentTD.className = 'SelectedImage';
}

function SetImgColor(cid, id, currentTD, tableName, DefaultSwatchText, strlblSwatch) {
    var swatchlabel = getElementByID_Master(strlblSwatch);
    swatchlabel.innerHTML = 'Selected Color: ' + DefaultSwatchText;

    var tdTag;
    tdTag = getElementByID_Master(tableName).getElementsByTagName('td');

    for (var counter = 0; counter < tdTag.length; counter++) {
        var imgTag = tdTag[counter].getElementsByTagName('img');

        if (imgTag != null) {
            var imgClass = imgTag.item(0).className;

            if (imgClass == 'SelectedImage') {
                imgTag.item(0).className = '';
            }
        }
    }
    currentTD.className = 'SelectedImage';

    try {
        getElementByID_Master(cid).selectedIndex = id + 1;
    }
    catch (err) { }
}

// End Swatches with Selection Enabled

function SwapS7Image(VignetteName, ProductID, Scene7RenderServer, ImageID, ProductColor, ImageIndex, CurrTD, tableName, FabricName, strlblSwatch, Scene7VignetteWidth, Scene7VignetteSharpness, Scene7VignetteResolution, SKUPrice) {
    try {
        var swatchlabel = getElementByID_Master(strlblSwatch);
        swatchlabel.innerHTML = 'Now Showing: ' + FabricName + " | Price: " + SKUPrice;
    }
    catch (err) { }
    try {
        getElementByID_Master("MainProductImage").src = Scene7RenderServer + ProductID + '?wid=' + Scene7VignetteWidth + '&obj=body&src=' + VignetteName + '&res=' + Scene7VignetteResolution + '&sharpen=' + Scene7VignetteSharpness + '&cache=off';
    }
    catch (err) { }
    try {
        for (var s = 0; s <= getElementByID_Master("ProductSizes").length; s = s + 1) {
            var ddl1value = getElementByID_Master("ProductSizes").options[s].value;

            if (ddl1value == ImageID) {
                getElementByID_Master("ProductSizes").selectedIndex = s;
                break;
            }
        }

        for (var i = 0; i <= getElementByID_Master("ProductColors").length; i = i + 1) {
            var ddlvalue = getElementByID_Master("ProductColors").options[i].value;

            if (ddlvalue == ProductColor) {
                getElementByID_Master("ProductColors").selectedIndex = i;
                break;
            }
        }
    }
    catch (err) { }
}

function swatch_swap_mouse_over(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl) {
    getElementByID_Master(ImageID).src = ImagePath;
    UnSelectAllSwatches_Iterator(SwatchID);
    getElementByID_Master(SwatchID + "_" + SwatchCount).className = "main-prod-swatch-selected";

    if (getElementByID_Master("EnableListSwatchRolloverDefaultColorHidden") == null) {
        getElementByID_Master(ThumbImageID).href = NavUrl;
    }

    if (ImagePath != null)
        swap_previewimage(ImagePath);
}

function swatch_swap_mouse_out(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl, ProductImageThumb) {

    UnSelectAllSwatches_Iterator(SwatchID);
    getElementByID_Master(ImageID).src = ImagePath;
    getElementByID_Master(SwatchID + "_" + SwatchCount).className = "main-prod-swatch-selected";

    if (getElementByID_Master("EnableListSwatchRolloverDefaultColorHidden") == null) {
        getElementByID_Master(ThumbImageID).href = NavUrl;
    }

    if (ImagePath != null)
        swap_previewimage(ImagePath);

    if (getElementByID_Master("EnableListSwatchRolloverDefaultColorHidden") != null && ProductImageThumb != "") {
        getElementByID_Master(ImageID).src = ProductImageThumb;
    }
}

function isNumeric(value) {
    if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

function swap_mouseover_images(ImagePath, ImageID, NavUrl) {

    var mouseover = getElementByID_Master(ImageID).getAttribute("onmouseover");
    var mouseout = getElementByID_Master(ImageID).getAttribute("onmouseout");
    var cid = NavUrl.indexOf("cl_")!= -1 ? NavUrl.substring(NavUrl.length, (NavUrl.indexOf("cl_") + 3)) : "";

    if (cid != "" && getElementByID_Master(ImageID.replace("ThumbnailImage", "ColorID"))!= null) {
        getElementByID_Master(ImageID.replace("ThumbnailImage", "ColorID")).value = cid;
    }
    
    if (mouseover != null) {
        getElementByID_Master(ImageID).setAttribute("onmouseover", 'this.src="' + ImagePath.replace("_l_thumb.jpg", "_b_thumb.jpg") + '"');
    }

    if (mouseout != null) {
        getElementByID_Master(ImageID).setAttribute("onmouseout", 'this.src="' + ImagePath.replace("_b_thumb.jpg", "_l_thumb.jpg") + '"');
    }
}

function swatch_swap_click(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl) {
    
	if (getElementByID_Master("ContentPlaceHolder1_ProductsListRPTMain_Scene7Image_0") != null) {
		var s7Img = ThumbImageID.replace('ThumbnailImageHL', 'Scene7Image');
		getElementByID_Master(s7Img).src = ImagePath;
	}
    if (isNumeric(ImageID)) {
        document.getElementById(ImageID.toString()).src = ImagePath;
    }
    else if (getElementByID_Master("EnableListSwatchClickHiddenWithQuickView") != null) {
        var imgid = SwatchID.replace('swatches', '');
        getElementByID_Master(imgid).src = ImagePath;
    }
    else {
        getElementByID_Master(ImageID).src = ImagePath;
    }

    getElementByID_Master(ThumbImageID).href = NavUrl;

    if (ImagePath != null) {
        swap_previewimage(ImagePath);
    }

    if (ImagePath != null && ImageID != null && NavUrl != null) {
        swap_mouseover_images(ImagePath, ImageID, NavUrl);
    }

    /// FOR QL COLOR SPLIT UPDATES ///
    if (getElementByID_Master("EnableListSwatchClickHiddenWithQuickView") != null) {
        if (SwatchID.indexOf('-') != -1)
            var imgid = SwatchID.split('-')[0] + 'swatches';
        else
            var imgid = SwatchID;

        if (document.getElementById("ContentPlaceHolder1_disableunselectallswatches") == null) {
            UnSelectAllSwatches_Iterator(ImageID);
        }

        if (getElementByID_Master(ImageID + "_" + SwatchCount) != null)
            getElementByID_Master(ImageID + "_" + SwatchCount).className = "main-prod-swatch-selected";
    }
    else {
        if (getElementByID_Master("disablethumbmousover") != null) {
            getElementByID_Master(ImageID).onmouseover = "undefined";
            getElementByID_Master(ImageID).onmouseout = "undefined";
        }

        if (document.getElementById("ContentPlaceHolder1_disableunselectallswatches") == null) {
            UnSelectAllSwatches_Iterator(ImageID);
        }

        if (getElementByID_Master(ImageID + "_" + SwatchCount) != null)
            getElementByID_Master(ImageID + "_" + SwatchCount).className = "main-prod-swatch-selected";
    }
}

function swap_previewimage(ImagePath) {
    var s = ImagePath;
    var previewimage = getElementByID_Master('main');
    var path = s.replace("thumbs", "regular").replace("_thumb.jpg", ".jpg");

    if (previewimage != null)
        previewimage.src = path;
}

function swap_previewimage_mouseover(ImageID, index) {
    var imagePath = ImageID.substring(ImageID.lastIndexOf('/'));
    var id = imagePath.replace(/[^0-9]/g, '');

    /// FOR QL COLOR SPLIT UPDATES ///
    if (index) {
        id += '-' + index;
    }
    var thumbpath;

    thumbpath = getElementByID_Master(id).src;

    var pathReplace = ImageID.toString().indexOf("detail") > 0 ? "detail" : "regular";
    var path = thumbpath.replace("thumbs", pathReplace).replace("_thumb.jpg", ".jpg");
    var previewimage = getElementByID_Master('main');
    if (previewimage != null) {
        previewimage.src = path;
    }
}


function UnSelectAllSwatches_Iterator(elementId) {
    var i = 0;
    while (!isNull(getElementByID_Master(elementId + "_" + i))) {
        var elem = getElementByID_Master(elementId + "_" + i)
        if (elem.className == "main-prod-swatch-selected") {
            elem.className = "main-prod-swatch-unselected";
        }
        i++;
    }
}

function isNull(elem) {
    if (elem == null) return true;
    return false;
}

function OnRequestStart(ajaxPanel, eventArgs) {
    if (navigator.userAgent.indexOf("Firefox") != -1) {
        DisableControls();
    }
}

function OnResponseEnd(ajaxPanel, eventArgs) {
    if (navigator.userAgent.indexOf("Firefox") != -1) {
        EnableControls();
    }
    try {
        var CartItems;
        var CartTotal;
        var CartItemsHidden;
        var CartTotalHidden;

        HideCartItemsText = getElementByID_Master("ShoppingBag1$HideCartItemsText");
        if (HideCartItemsText == null)
            HideCartItemsText = getElementByID_Master("ctl00$ShoppingBag1$HideCartItemsText");
        CartItems = getElementByID_Master("Top1_ShoppingBag1_CartItemsLB");
        CartTotal = getElementByID_Master("Top1_ShoppingBag1_CartTotalLB");
        CartItemsCount = getElementByID_Master("ShoppingBag1_CartItemsCount");
        if (CartItemsCount == null)
            CartItemsCount = getElementByID_Master("ctl00_ShoppingBag1_CartItemsCount");
        CartItemsHidden = getElementByID_Master("CartItemsHidden");
        CartTotalHidden = getElementByID_Master("CartTotalHidden");
        CartItemsTopNav = getElementByID_Master("TopNav1_ShoppingBag1_CartItemsLB");
        if (CartItemsTopNav == null)
            CartItemsTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsLB");
        CartTotalTopNav = getElementByID_Master("TopNav1_ShoppingBag1_CartTotalLB");
        if (CartTotalTopNav == null)
            CartTotalTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartTotalLB");
        CartItemsCountTopNav = getElementByID_Master("TopNav1_ShoppingBag1_CartItemsCount");
        if (CartItemsCountTopNav == null)
            CartItemsCountTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsCount");
        CartItemsCountTopNav2 = getElementByID_Master("TopNav1_ShoppingBag2_CartItemsCount");
        if (CartItemsCountTopNav2 == null)
            CartItemsCountTopNav2 = getElementByID_Master("ctl00_TopNav1_ShoppingBag2_CartItemsCount");
        CartItemsHidden2 = getElementByID_Master("ContentPlaceHolder1_CartItemsHidden");
        if (CartItemsHidden2 == null)
            CartItemsHidden2 = getElementByID_Master("ctl00_ContentPlaceHolder1_CartItemsHidden");
        CartTotalHidden2 = getElementByID_Master("ContentPlaceHolder1_CartTotalHidden");
        if (CartTotalHidden2 == null)
            CartTotalHidden2 = getElementByID_Master("ctl00_ContentPlaceHolder1_CartTotalHidden");

        //CartItems can remain null for clients like PAIG/SEVN/BTSY whose Top1 is null (line 1842)
        //consequently, bag value gets updated but bag item count does not
        //therefore, we would only want to re-init CartItems IF IT REMAINS NULL so I am changing line 1854 from != to ==
        if (CartItems == null) {
            if (CartItemsTopNav != null)
                CartItems = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsLB");
            else
                CartItems = getElementByID_Master("ctl00_ShoppingBag1_CartItemsLB");

            if (CartItemsTopNav != null) {
                var items = getElementByID_Master("ContentPlaceHolder1_CartItemsHidden").value;
                if (getElementByID_Master("ContentPlaceHolder1_CartItemsHidden") != null && items == "1")
                    CartItemsTopNav.innerHTML = items + " item";
                else
                    CartItemsTopNav.innerHTML = items + " items";
            }
        }

        if (CartItemsCountTopNav2 != null && (CartItemsHidden2.value != ""))
            CartItemsCountTopNav2.innerHTML = CartItemsHidden.value;

        if (CartTotalTopNav != null)
            CartTotal = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartTotalLB");
        else
            CartTotal = getElementByID_Master("ctl00_ShoppingBag1_CartTotalLB");

        if (CartTotal != null)
            CartTotal.innerHTML = CartTotalHidden.value;

        if (CartItemsCount != null)
            CartItemsCount.innerHTML = CartItemsHidden.value;

        if (CartItemsCountTopNav != null)
            CartItemsCountTopNav.innerHTML = CartItemsHidden.value;

        if (CartItemsHidden.value == "1") {
            if (CartItems != null) {
                if (HideCartItemsText != null && HideCartItemsText.value == "1")
                    CartItems.innerHTML = CartItemsHidden.value;
                else
                    CartItems.innerHTML = CartItemsHidden.value + " Item";
            }
        }
        else {
            if (CartItems != null) {
                if (HideCartItemsText != null && HideCartItemsText.value == "1")
                    CartItems.innerHTML = CartItemsHidden.value;
                else
                    CartItems.innerHTML = CartItemsHidden.value + " Items";
            }
        }
        render_cart_header("CartItemsLBGet", "CartTotalLBGet");

        if (getElementByID_Master('ShoppingCartAjaxEnabled') != null) {
            trigger_cartajax();
        }
    }
    catch (err) { }
}
function UpdateContinueShoppingLink() {
    try {
        var continueShippingLink = getFirstElementByClassName("jsHlContinueshopping");
        if (continueShippingLink != null) {
            var hiddenField = getFirstElementByClassName("jsHdnContinueShoppingLink");
            if (hiddenField != null) {
                continueShippingLink.href = hiddenField.value;
            }
        }
    }
    catch (err) { }
}
function DisableControls() {
    for (var i = 0; i < document.forms[0].elements.length; i++) {
        var obj = document.forms[0].elements[i];

        if (document.forms[0].elements[i].name == "__VIEWSTATE")
            obj.disabled = true;
    }
}

function EnableControls() {
    for (var i = 0; i < document.forms[0].elements.length; i++) {
        var obj = document.forms[0].elements[i];
        obj.disabled = false;
    }
}

function addToFavorites(url, title) {
    var ua = navigator.userAgent.toLowerCase();
    var isSafari = ua.indexOf('webkit') != -1;
    var isMac = ua.indexOf('mac') != -1;
    var buttonStr = isMac ? 'Command/Cmd' : 'CTRL';

    if (window.sidebar) // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "")
    else if (window.external) // IE Favorite
        window.external.AddFavorite(url, title)
    else if (isSafari) // Safari
        alert('You need to press ' + buttonStr + ' + D to bookmark this page.');
    else // Others
        alert("Your browser doesn't support this function.");
}

function ToggleCheck(me, group) {
    var checked = me.checked;
    if (checked) for (var i = 1; i < arguments.length; i++) {
        var ck = document.getElementById(arguments[i]);
        if (ck) ck.checked = false;
    }
    me.checked = checked;
}

function TrimString(inputString) {
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") {
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
    }
    return retValue;
}

function SearchBarSetQuery(searchfield, storeUrl, btnId, searchfieldid) {
    if (false == ValidateSearch(searchfieldid)) {
        return false;
    }
    searchfield = TrimString(searchfield.toLowerCase());

    if (false == ValidateSearch(searchfieldid)) {
        return false;
    }
    else {
        document.MM_returnValue = false;
        window.location.href = storeUrl + CallEncode(searchfield);
    }
}

function CallEncode(text) {
    var encoded = encodeURIComponent(text);
    return encoded;
}

function ValidateSearch(textBoxId) {
    var textBox = document.getElementById(textBoxId);
    if (TrimString(textBox.value).length == 0) {
        alert('Please specify a search criteria');
        return false;
    }
    // Check for invalid characters, specifically, "<" and ">".
    if (TrimString(textBox.value).indexOf('<') > -1 || TrimString(textBox.value).indexOf('>') > -1) {
        alert('We\'re sorry, the search value entered is invalid. Please try again.');
        return false;
    }
    return true;
}
//*************Search Functions used on TRUE*************//

function SingleSelectCheckBox(regex, current) {
    re = new RegExp(regex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {

            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

function render_cart_header(items, total) {
    if (getElementByID_Master(total) == null || getElementByID_Master(items) == null)
        return;

    var sc = jQuery;
    sc.ajax({
        url: location.protocol + '//' + document.domain + '/store/os/shoppingcartcost.aspx',
    	cache: false,
    	success: function (html) {
    		var ary = html.split("|");
    		if (ary.length > 1) {
    			getElementByID_Master(total).innerHTML = ary[0];
    			getElementByID_Master(items).innerHTML = ary[1];
    		}
    	},
    	error: function (err) {
    	}
    });

    try {
        getElementByID_Master("CartLiteralSgl").style.display = "none";
        getElementByID_Master("CartLiteralPlural").style.display = "none";
        (getElementByID_Master("CartItemsLBGet").innerHTML == "1") ? getElementByID_Master("CartLiteralSgl").style.display = "inline" : getElementByID_Master("CartLiteralPlural").style.display = "inline";
    }
    catch (e) { }
}

function newXmlHttpObject() {
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function ajaxcall(relativeUrl) {
    //call any file without testing async return
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }

    try {
        if (topdomain) {
            var prot = "http://";
            if (isSecure())
                prot = "https://";
            //alert(prot + topdomain);
            xmlhttp.open("GET", prot + topdomain + relativeUrl, false);
            xmlhttp.send();
            var str = xmlhttp.responseText;
            xmlhttp.close;
            xmlhttp = false;
            return str;
        }
    }
    catch (e) { }
}

function addEvent(obj, evType, fn, useCapture) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    }
}

function addEventToElement(element, evenType, functionToRun) {
    if (element.addEventListener) {
        element.addEventListener(evenType, functionToRun, false);
        EventCache.add(element, evenType, functionToRun);
    }
    else if (element.attachEvent) {
        element["e" + evenType + functionToRun] = functionToRun;
        element[evenType + functionToRun] = function () { element["e" + evenType + functionToRun](window.event); }
        element.attachEvent("on" + evenType, element[evenType + functionToRun]);
        EventCache.add(element, evenType, functionToRun);
    }
    else {
        element["on" + evenType] = element["e" + evenType + functionToRun];
    }
}

var EventCache = function () {
    var listEvents = [];
    return {
        listEvents: listEvents,
        add: function (node, sEventName, fHandler) {
            listEvents.push(arguments);
        },
        flush: function () {
            var i, item;
            for (i = listEvents.length - 1; i >= 0; i = i - 1) {
                item = listEvents[i];
                if (item[0].removeEventListener) {
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if (item[1].substring(0, 2) != "on") {
                    item[1] = "on" + item[1];
                };
                if (item[0].detachEvent) {
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
        }
    };
} ();

function setNumericValuesOnlyOnElements(elementsClassName) {
    var elements = getElementsByClassName(elementsClassName);
    if (elements != null) {
        var numberOfElements = elements.length;
        if (numberOfElements > 0) {
            var element;
            for (var i = 0; i < numberOfElements; i++) {
                setNumericValuesOnlyOnElement(elements[i]);
            }
        }
    }
}

function setNumericValuesOnlyOnElement(element) {
    if (element != null) {
        addEventToElement(element, "keyup",
										function () { removeNoNumericValuesOnElement(element); });
    }
}

function removeNoNumericValuesOnElement(element) {
    if (element != null) {
        element.value = element.value.replace(/[^0-9]/g, "");
    }
}

function getFirstElementByClassName(className) {
    var elements = getElementsByClassName(className);
    if (elements != null) {
        if (elements.length > 0) {
            return elements[0];
        }
    }
    return null;
}
/* CHECKBOX START */
function createOneStopCheckBoxes() {
    var checkBoxes = getElementsByClassName("OneStopCheckBox");
    if (checkBoxes != null) {
        var numberOfCheckBoxes = checkBoxes.length;
        if (numberOfCheckBoxes > 0) {
            for (var i = 0; i < numberOfCheckBoxes; i++) {
                setOneStopCheckBox(checkBoxes[i]);
            }
        }
    }
}
function setOneStopCheckBox(checkbox) {
    if (checkbox.type == "checkbox") {
        var oneStopSpan = createOneStopElementSpan();
        if (checkbox.checked == true) {
            addCls(oneStopSpan, "OneStopCheckBoxChecked");
        }
        oneStopSpan.onclick = function () { changeCheckBoxStatus(checkbox, oneStopSpan); };
        checkbox.parentNode.appendChild(oneStopSpan);
    }
}
function createOneStopElementSpan() {
    var span = document.createElement("span");
    span.className = "OneStopElementSpan";
    return span;
}
function changeCheckBoxStatus(checkbox, span) {
    if (checkbox.checked == true) {
        remCls(span, "OneStopCheckBoxChecked");
        checkbox.checked = false;
    }
    else {
        addCls(span, "OneStopCheckBoxChecked");
        checkbox.checked = true;
    }
    fireCheckBoxChangeEvent(checkbox);
}
function fireCheckBoxChangeEvent(element) {
    if (element.onchange) {
        var fireOnThis = element;
        if (document.createEvent) {
            var evObj = document.createEvent('HTMLEvents');
            evObj.initEvent('change', true, false);
            fireOnThis.dispatchEvent(evObj);
        } else if (document.createEventObject) {
            var evObj = document.createEventObject();
            fireOnThis.fireEvent('change', evObj);
        }
    }
}

/* CHECKBOX END */
var topdomain = document.domain;

function SetOptOutShopper(chk) {
    //change using cookie handler to remove/set cookies due to encrypt/decrypt
    var param;
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
            }
        }
    }
    if (chk.checked == 1) {

        //Delete_Cookie('ShopperBagPersist', '/', '');
        param = 'cmethod=delwd&cname=ShopperBagPersist';

        getElementByID_Master("IsShopperBagUnchecked").value = "0";
    }
    else {

        //Set_Cookie('ShopperBagPersist', '1', '7', '/', '', '');
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + 7);
        param = 'cmethod=set&cname=ShopperBagPersist&cval=1&cdomain=true&cexp=' + exdate.toGMTString();


        getElementByID_Master("IsShopperBagUnchecked").value = "1";

    }

    xmlhttp.open("POST", "/store/os/CookieHandler.ashx?" + param, true);
    xmlhttp.send();
}

function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');

        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Mon, 01-Jan-1900 00:00:01 GMT";
}

function Set_Cookie(name, value, expires, path, domain, secure) {

    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct  
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "") +
	((path) ? ";path=" + path : "") +
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}

function setCookie(name, value, expire, domain) {
    var param = 'cmethod=set&cname=' + name + '&cval=' + value;
    if (expire > 0) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expire);
        param += '&cexp=' + exdate.toGMTString() + "'";
    }
    if (domain) {
        param += '&cdomain=true';
    }
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
            }
        }
    }
    xmlhttp.open("POST", "/store/os/CookieHandler.ashx?" + param, true);
    xmlhttp.send();
};

function getCookie(name) {
    var param = 'cmethod=get&cname=' + name + "'";
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
            }
        }
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            return (xmlhttp.responseText);
        }

    }
    xmlhttp.open("POST", "/store/os/CookieHandler.ashx?" + param, true);
    xmlhttp.send();
};

//adds mutiple window.onload
function addOnloadEvent(fnc) {

    if (typeof window.addEventListener != "undefined") {
        window.addEventListener("load", fnc, false);
    }
    else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onload", fnc);
    }
    else {
        if (window.onload != null) {
            var oldOnload = window.onload;
            window.onload = function (e) {
                oldOnload(e); window[fnc]();
            };
        }
        else window.onload = fnc;
    }
}

