jQuery(document).ready(function() {
/*start code to populate correct magic zoom attributes */
	var medium_image = jQuery("#Main_Item_Image").attr("src");
	var large_image =  medium_image.replace("250x349", "480x600");
	jQuery(".MagicZoom").attr("href", large_image);
/*end magic zoom code*/
});

function prepImageZoom(a, e, b) {
    var d = a.cloneNode(true);
    d.src = d.src.replace(e, b);
    d.className = d.id = "";
    var c = document.createElement("DIV");
    c.appendChild(document.createTextNode("Click to Enlarge"));
    c.className += " linkZoom";
    a.parentNode.insertBefore(c, a.nextSibling);
    a.className += " linkZoom";
    a.onclick = c.onclick = function () {
        window.open(d.src, "Zoom", "height=625,width=500,menubar=no,location=no,status=no")
    };
    a.className += " zoomOn"
}
function popUpClose() {
    window.Global.accPopUp.className = window.Global.accPopUp.className.replace(/popUpOn/, "");
    window.Global.accPopUp = null
}
function popUpOn(c) {
    var a = c.getElementsByTagName("INPUT")[0].value;
    var b = document.getElementById("Pop_Up_" + a);
    if (b) {
        if (window.Global.accPopUp && window.Global.accPopUp != null) {
            popUpClose()
        } else {
            if (!window.Global.accPopUp) {
                window.Global.accPopUp
            }
        }
        b.className += " popUpOn";
        window.Global.accPopUp = b
    }
}
function cscAccessoryPopUp(c) {
    if (!window.Global) {
        window.Global = new Array
    }
    var d = c.getElementsByTagName("A");
    var b = getElementsByClassName(c, "itemPopUp");
    var a;
    for (i = 0; i < b.length; i++) {
        var e = b[i];
        for (ii = 0; ii == 0; ii) {
            e = e.parentNode;
            if (e.tagName == "TD") {
                ii = 1
            }
        }
        var a = getElementsByClassName(e, "itemID")[0];
        b[i].id = "Pop_Up_" + a.firstChild.nodeValue;
        for (ii = 0; ii == 0; ii) {
            e = e.previousSibling;
            if (e.tagName == "TD") {
                ii = 1
            }
        }
        e.onclick = function () {
            popUpOn(this)
        };
        e.appendChild(document.createTextNode("View Details"))
    }
    c.className += " popUpOn"
}
function cscDetailImageSetup() {
    if (document.getElementById("Main_Item_Image")) {
        prepImageZoom(document.getElementById("Main_Item_Image"), "250x349", "480x600")
    }
    if (document.getElementById("Related_Items")) {
        cscAccessoryPopUp(document.getElementById("Related_Items"))
    }
}
function cscDisableQty(b) {
    var c = b.getElementsByTagName("input");
    for (i = 0; i < c.length && i >= 0; i++) {
        if (c[i].type == "text" && c[i].name == "QTY") {
            c = c[i];
            i = -999
        }
    }
    if (c.nodeName == "INPUT") {
        c.disabled = true;
        c.value = "";
        var a = document.createElement("INPUT");
        a.name = "QTY";
        a.value = "";
        a.type = "hidden";
        b.appendChild(a)
    }
}
function cscQtyBoxControl() {
    var c = document.getElementById("Item_Form");
    var b = document.getElementById("Related_Items");
    var d = getElementsByClassName(c, "price");
    d = getElementsByClassName(d[0], "stockMsg")[0];
    if (d && d.firstChild.nodeValue.indexOf("Out of Stock") != -1) {
        cscDisableQty(c)
    }
    if (b != null) {
        var a = getElementsByClassName(b, "stockMsg");
        for (ia = 0; ia < a.length; ia++) {
            if (a && a[ia].firstChild.nodeValue.indexOf("Out of Stock") != -1) {
                var e = a[ia].parentNode;
                for (iap = 0; a.nodeName != "BODY" && iap != 1; iap) {
                    if (e.nodeName == "TD") {
                        iap = 1
                    } else {
                        e = e.parentNode
                    }
                }
                cscDisableQty(e)
            }
        }
    }
}
addEvent(window, "load", cscDetailImageSetup, false);
addEvent(window, "load", cscQtyBoxControl, false);

function getURLParamter(param) {
    param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+param+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null ) {
        return "";
    } else {
        // Get the value
        var data = results[1];

        // return unescaped value
        return unescape(data);
    }
}
