﻿//Added on 26/12/11 to remove MISC file from local folder.
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) {
        $(".sizeSelect").parents('.jquery-selectbox').unselectbox();

        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++;
            }
        }
        $(".sizeSelect").selectbox();
    }
    if (ps.length == 2 && (getElementByID_Master("DisableOneSizeSelection") == null || (getElementByID_Master("DisableOneSizeSelection") != null && getElementByID_Master("DisableOneSizeSelection").value != 1))) {
        ps.selectedIndex = 1;
    }
}

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;
            try {
                $(".zoomWrapperImage").find("img").attr("src", displayiImg);
            }
            catch (err) { }
        }
        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) {
    g_color = i;
    try {
        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 filterorsort2(ctrlname, ctrlvalue, ctrlname2, ctrlvalue2) {
    var categoryid = getElementByID_Master("categoryidhidden").value;
    var base = "/l/";
    var searchstring = window.location.search;
    var newsearchstring = addsingleparam(ctrlname, ctrlvalue, searchstring, categoryid, -1);
    var baseurl = addparam(ctrlname2, ctrlvalue2, base, newsearchstring, categoryid);

    window.location.href = baseurl;
}

