var isIE6 = false;
function GoTo(thisURL) {
     self.location = thisURL;
}
function OpenWindow(thisURL) {
     var x = 620;
     var y = 550;
     var gWin = window.open(thisURL,'GraphicWindow',
     'width='+x+',height='+y+',resizable=1,scrollbars=1');
 }
 function ExpandOld(sender,hovering) {
     var img1 = sender.getElementsByTagName("img")[0];
     var img2 = sender.getElementsByTagName("img")[1];
     var span = sender.getElementsByTagName("span")[0];
     var nav = document.getElementById("navigation");
     nav = nav.parentNode;

     var alt = img1.alt;
     var src = img1.src;
     if (alt == "Open" && hovering) {
         sender.title = "Click to close";
         img1.src = src.replace("down", "up");
         img1.alt = "Close";
         img2.src = src.replace("down", "up");
         img2.alt = "Close";
         span.innerHTML = "Close";
         nav.style.height = "auto";
         nav.style.display = "block";
         if (document.getElementById("videoWrapper") != null) {
             HidePlayer();
         }
         document.getElementById("navbottom").onclick = SlideClose;
     }
     else if (!hovering) {
         sender.title = "Click to open";
         img1.src = src.replace("up", "down");
         img1.alt = "Open";
         img2.src = src.replace("up", "down");
         img2.alt = "Open";
         span.innerHTML = "Category";
         nav.style.height = "0px";
         nav.style.display = "none";
         document.getElementById("navbottom").onclick = Expand;
     }
 }
function Expand() {
    var link = document.getElementById("navbottom");
    if (window.getComputedStyle) {
        var style = window.getComputedStyle(link, "")
        if (style.display == 'none') return;
        if (style.visibility == 'hidden') return;
    }
    var style = link.currentStyle
    if (style) {
        if (style['display'] == 'none') return;
        if (style['visibility'] == 'hidden') return;
    }
    var img1 = link.getElementsByTagName("img")[0];
    var img2 = link.getElementsByTagName("img")[1];
    var span = link.getElementsByTagName("span")[0];
    if (isIE6) {
        ExpandOld(link,true);
        return;
    }
    var nav = document.getElementById("navigation");
    nav = nav.parentNode;

    var alt = img1.alt;
    var src = img1.src;
    if (alt == "Open") {
        link.title = "Click to close";
        img1.src = src.replace("down", "up");
        img1.alt = "Close";
        img2.src = src.replace("down", "up");
        img2.alt = "Close";
        span.innerHTML = "Close";
        nav.style.display = "block";
        SlideOpen();
        if (document.getElementById("videoWrapper") != null) {
            HidePlayer();
        }
    }
}
function Collapse() {
    var link = document.getElementById("navbottom");
    var img1 = link.getElementsByTagName("img")[0];
    var img2 = link.getElementsByTagName("img")[1];
    var span = link.getElementsByTagName("span")[0];
    var src = img1.src;
    img1.src = src.replace("up", "down");
    img1.alt = "Open";
    img2.src = src.replace("up", "down");
    img2.alt = "Open";
    span.innerHTML = "Categories";
    link.title = "Click to open";
    document.getElementById("navbottom").onclick = Expand;
        //nav.style.display = "none";
        //SlideClose();
}
function SlideOpen() {
    var input = document.getElementById("navdirection");
    if (input.value != "close") {
        var nav = document.getElementById("navigation");
        nav = nav.parentNode;
        var temp = document.getElementById("navheight");
        if (input.value != "open") {
            temp.value = nav.clientHeight;
            nav.style.height = "0px";
        }
        var height = parseInt(temp.value);
        
        input.value = "open";
        var curHeight = nav.clientHeight;
        if (curHeight < height) {
            if (curHeight + 15 > height) {
                nav.style.height = height + "px";
                input.value = "";
            }
            else {
                nav.style.height = (curHeight + 15) + "px";
                setTimeout('SlideOpen( )', 1);
                return;
            }
        }
        else {
            nav.style.height = height + "px";
            input.value = "";
        }
        document.getElementById("navbottom").onclick = SlideClose;
        //nav.parentNode.style.height = height + "px";
    }
}
function SlideClose() {
    if (isIE6) {
        ExpandOld(document.getElementById("navbottom"),false);
        return;
    }
    var input = document.getElementById("navdirection");
    if (input.value != "open") {
        var nav = document.getElementById("navigation");
        nav = nav.parentNode;
        var temp = document.getElementById("navheight");

        input.value = "close";
        var curHeight = nav.clientHeight;
        if (curHeight > 0) {
            if (curHeight - 15 < 0) {
                input.value = "";
                nav.style.height = temp.value + "px";
                nav.style.display = "none";
                Collapse();
            }
            else {
                nav.style.height = (curHeight - 15) + "px";
                setTimeout('SlideClose( )', 1);
            }
        }
        else {
            input.value = "";
            nav.style.height = temp.value + "px";
            nav.style.display = "none";
            Collapse();
        }
    }
}
function ProcessShipping(element) {
    if (element == null || element.parentNode == null) {
        return;
    }
    var span = element.parentNode.getElementsByTagName("span")[0];
    var newTotal = (parseFloat(element.value) + parseFloat(_subTotal)) + "";
    if (newTotal.lastIndexOf(".") < 0) {
        newTotal = newTotal + ".";
    }
    while (newTotal.lastIndexOf(".") > newTotal.length - 3) {
        newTotal = newTotal + "0";
    }
    while (newTotal.lastIndexOf(".") < newTotal.length - 3) {
        newTotal = newTotal.substr(0,newTotal.length - 1);
    }
    span.innerHTML = "$" + newTotal;
}
function setRRVars(rrObj) {
    var session = setRRCookies("CartGUID");
    var user = setRRCookies("RRUserID");
    if (session != "") {
        if (rrObj != null) {
            rrObj.setSessionId(session);
        }
        else {
            var sessInput = document.getElementById("wcnsid");
            if (sessInput != null) {
                sessInput.value = session;
            }
        }
    }
    if (user != "") {
        if (rrObj != null) {
            rrObj.setUserId(user);
        }
        else {
            var userInput = document.getElementById("wcnuid");
            if (userInput != null) {
                userInput.value = user;
            }
        }
    }
}
function setRRCookies(name) {
    var cookie = getCookie("EpayUser24");
    if (cookie != null && cookie != "") {
        var items = cookie.split("&");
        for (var i = 0; i < items.length; i++) {
            var pair = items[i].split("=");
            if (pair.length = 2) {
                var key = pair[0];
                var value = pair[1];
                if (name == key  && value.length > 0) {
                    return value;
                }
            }
        }
    }
    return "";
}
function WCNTrackingPixel() {
    var path = location.pathname.substring(1);
    var index = path.indexOf("c/");
    if (index > 0) {
        if (!isNaN(parseInt(path))) {
            var catID = path.substring(0, index);
            return (new TrackingPixel("WNDHAET5BY37D86-2", "catid=" + catID));
        }
    }
    if (path.toLowerCase().indexOf("checkoutconfirmation") > 0) {
        var oid = document.getElementById("hidOID");
        var subtotal = document.getElementById("hidSubTotal");
        var shipping = document.getElementById("hidShipping");
        var discount = document.getElementById("hidDiscount");
        var total = document.getElementById("hidTotal");
        if (oid != null && subtotal != null && shipping != null && discount != null && total != null) {
            var dSubtotal = parseFloat(subtotal.value);
            var dShipping = parseFloat(shipping.value);
            var dDiscount = parseFloat(discount.value);
            var dTotal = parseFloat(total.value);
            return (new TrackingPixel("WNDHAET5BY37D86-2", "CSIORDERID=" + oid.value + "|CSIORDERAMT=" + dTotal.toFixed(2) + "|ORDERSUBTOTAL=" + dSubtotal.toFixed(2) + "|ORDERSHIP=" + dShipping.toFixed(2) + "|ORDERDISCOUNT=" + dDiscount.toFixed(2)));
        }
    }
    if (path.toLowerCase().indexOf("checkout/") > -1) {
        var supress = "";
        var inpSupress = document.getElementById("hidSupress");
        if (inpSupress != null) {
            supress = "supress=" + inpSupress.value;
            return (new TrackingPixel('WNDHAET5BY37D86-2',supress));
        }
    }
    return (new TrackingPixel('WNDHAET5BY37D86-2'));
}


function GetPageName(obj) {
    var ret = "";
    var title = document.title;
    var path = location.pathname.substring(1);
    if (path.indexOf("products/") > 0) {
        var input = document.getElementById("productID");
        title = "Product Detail";
        obj.products = ";" + input.value;
        obj.events = "prodView";
    }
    else if (path.indexOf("categories/") > 0) {
        var index = title.indexOf(":");
        ret = title.substr(0, index - 2);
        title = "Category: " + ret;
    }
    else if (path.indexOf("cart.php") > 0) {
        obj.events = "scView"
    }
    obj.pageName = title;
    return obj;
}
function loadScript(url, callback) {

    var script = document.createElement("script")
    script.type = "text/javascript";

    if (callback != null) {
        if (script.readyState) {  //IE
            script.onreadystatechange = function() {
                if (script.readyState == "loaded" ||
                        script.readyState == "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else {  //Others
            script.onload = function() {
                callback();
            };
        }
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}
function openPage(url) {
    var div = document.createElement("div");
    div.id = "popupOverlay";
    document.body.appendChild(div);
    new Ajax.Request(url,
    {
        method: 'get',
        onSuccess: function (response) {
            var win = new Window({
                className: "dialog",
                recenterAuto: "true",
                resizable: "false",
                closable: "false",
                minimizable: "false",
                maximizable: "false",
                draggable: "false",
                height: 500,
                width: 583
            }); 
            var start = "<img src=\"/images/termtop.gif\" alt=\"\" class\"\" />";
            start += "<div class=\"preview terms\">";
            start += "<img onclick=\"CloseWindow( )\" src=\"/images/popupclose.gif\" alt=\"Close\" class=\"close\">";
            start += "<div class=\"container\">";
            var end = "</div></div>";
            end += "<img src=\"/images/termbottom.gif\" alt=\"\" class\"\" />"; 
            win.setDestroyOnClose();
            win.setHTMLContent(start + response.responseText + end);
            win.setZIndex(1500);
            win.showCenter();
        }
    });
}
function openContent(id) {
    var element = document.getElementById(id);
    if (element != null) {
        var div = document.createElement("div");
        div.id = "popupOverlay";
        document.body.appendChild(div);
        var win = new Window({
            className: "dialog",
            recenterAuto: "true",
            resizable: "false",
            closable: "false",
            minimizable: "false",
            maximizable: "false",
            draggable: "false",
            height: 500,
            width: 583
        });
        var start = "<img src=\"/images/termtop.gif\" alt=\"\" class\"\" />";
        start += "<div class=\"preview terms\">";
        start += "<img onclick=\"CloseWindow( )\" src=\"/images/popupclose.gif\" alt=\"Close\" class=\"close\">";
        start += "<div class=\"container\">";
        var end = "</div></div>";
        end += "<img src=\"/images/termbottom.gif\" alt=\"\" class\"\" />";
        win.setDestroyOnClose();
        win.setHTMLContent(start + element.innerHTML + end);
        win.setZIndex(1500);
        win.showCenter();
    }
}
function CloseWindow() {
    var div = document.getElementById("popupOverlay");
    if (div != null) {
        div.parentNode.removeChild(div);
    }
    Windows.closeAll();
}




function getFacebook(url) {
    var fbJSON = new fbInterface(url);
    fbJSON.post();
}
function facebookCallback() {
    var output = "";
    if (fbInterface.data != null && fbInterface.data.likes != "") {
        var likes = parseFloat(fbInterface.data.likes);
        if (likes > 999999) {
            output = roundNumber((likes / 1000), 1) + "M";
        }
        else if (likes > 999) {
            output = roundNumber((likes / 1000), 1) + "K";
        }
    }
    if (output != "") {
        createFBLikes(output);
    }
}
function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
function createFBLikes(likes) {
    var container = document.getElementById("facebook");
    if (container != null) {
        var div = document.createElement("div");
        var img = document.createElement("img");
        var span = document.createElement("span");

        div.className = "fblikes";
        img.src = "/images/fbbubble.png";
        img.alt = "";
        span.innerHTML = likes;

        div.appendChild(img);
        div.appendChild(span);
        container.appendChild(div);
    }
}

function fbInterface(url) {
    this.url = (url == null) ? "" : url;
    this.data = null;
    this.fbInterface = this;
    this.post = function () {
        new Ajax.Request(this.url, {
            method: "get",
            onSuccess: function (e) {
                fbInterface.data = e.responseText.evalJSON(true);
                if (facebookCallback != null) {
                    facebookCallback();
                }
            }
        })
    }
}
