var win = null;
var PageRedirect = true;

var clickmessage = "Sorry, cannot download images";

function disableBtn(btnID, newText) {

    var btn = document.getElementById(btnID);
    btn.disabled = true;
    btn.value = newText;
}

function writeDocument(s) { document.write(s); }

function disableclick(e) {
    if (document.all) {
        if (event.button == 2 || event.button == 3) {
            if (event.srcElement.tagName == "IMG") {
                alert(clickmessage);
                return false;
            }
        }
    }
    else if (document.layers) {
        if (e.which == 3) {
            alert(clickmessage);
            return false;
        }
    }
    else if (document.getElementById) {
        if (e.which == 3 && e.target.tagName == "IMG") {
            alert(clickmessage)
            return false
        }
    }
}

function associateimages() {
    for (i = 0; i < document.images.length; i++)
        document.images[i].onmousedown = disableclick;
}

function stoprightclick() {
    if (document.all)
        document.onmousedown = disableclick
    else if (document.getElementById)
        document.onmouseup = disableclick
    else if (document.layers)
        associateimages()
}

function bookmark(url, title) {
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(url, title);
    } else if (navigator.appName == "Netscape") {
        window.sidebar.addPanel(title, url, "");
    } else {
        alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
    }
}

function NewWindow(mypage, myname, w, h, scroll, resize) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable=' + resize
    if (win && !win.closed) win.close()
    win = window.open(mypage, myname, settings)
    if (win.window.focus) { win.window.focus(); }
}

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_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_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_findObj(n, d) { //v4.01
    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 = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_displayStatusMsg(msgStr) { //v1.0
    status = msgStr;
    document.MM_returnValue = true;
}

function CheckRedirect() {
    PageRedirect = false;
    return true;
}


function Hilite(name, over) {
    if (window.document.images) {
        if (over)
            window.document.images[name].src = "css/" + name + "_over.gif";
        else
            window.document.images[name].src = "css/" + name + ".gif";
    }
}

function clickButton(e, buttonid) {
    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

function switchText(object, baseText, eventName) {
    if (eventName == "blur") {
        if (object.value == "") {
            object.value = baseText;
        }
    }
    else {
        if (object.value == baseText) {
            object.value = "";
        }
    }
}

function toggle(a, b) {
    if (!document.getElementById) return true;
    //alert(document.getElementById('faq'));
    a = document.getElementById(a);
    a.style.display = (a.style.display == 'block') ? 'none' : 'block';
    return false;
}

function changetext(div_id, val) {
    var elm = document.getElementById(div_id);
    if (elm != null) elm.innerHTML = val;
    return false;
}

function ToNewPage(newURL) {
    document.location.href = newURL;
}

function MM_nbGroup(event, grpName) { //v6.0
    var i, img, nbArr, args = MM_nbGroup.arguments;
    if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
            img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
            if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
            nbArr[nbArr.length] = img;
            for (i = 4; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
                if (!img.MM_up) img.MM_up = img.src;
                img.src = img.MM_dn = args[i + 1];
                nbArr[nbArr.length] = img;
            }
        }
    } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i = 1; i < args.length - 1; i += 3) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = (img.MM_dn && args[i + 2]) ? args[i + 2] : ((args[i + 1]) ? args[i + 1] : img.MM_up);
            nbArr[nbArr.length] = img;
        }
    } else if (event == "out") {
        for (i = 0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
    } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr) for (i = 0; i < nbArr.length; i++) { img = nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i = 2; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = img.MM_dn = (args[i + 1]) ? args[i + 1] : img.MM_up;
            nbArr[nbArr.length] = img;
        }
    }
}

onerror = handleError;

function handleError(msg, url, l) {
    txt = "There was an error on this page.\n\n";
    txt += "Error: " + msg + "\n";
    txt += "URL: " + url + "\n";
    txt += "Line: " + l + "\n\n";
    txt += "Click OK to continue.\n\n";
    //alert(txt);
    return true;
}

function openWindow(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("Popup");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}

function openWindow2(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("PopupNonModal");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}
function openWindowLarge(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("PopupLarge");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}

function openCSVWindow(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("PopupSmall");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}

function openOutOfStockWindow(url, title) {
    try {
        var menu = window.parent.$find("header_Dropnav1_navlinks1_rmDropDownCart");
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("PopupOutOfStock");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}

function openMissUltimo(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("MissUltimo");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}
function openIcon(url, title) {
    try {
        var oWnd = window.parent.$find("RadWindowManager1").GetWindowByName("Icon");
        oWnd.SetUrl(url);
        oWnd.SetTitle(title);
        oWnd.Show();
    }
    catch (Error) {
    }
}

function openVideo(url, title) {
    try {
        var oWndMan = window.parent.$find("RadWindowManager1");
        var oWnd = oWndMan.GetWindowByName("PopupVideo");
        if (oWnd != null) {
            oWnd.SetUrl(url);
            oWnd.SetTitle(title);
            oWnd.Show();
        }
        else {
            var oNew = oWndMan.Open(url, title);
            oNew.SetSize(428, 349);
            oNew.SetModal(true);
            oWnd.Show();
        }
    }
    catch (Error) {
    }
}
function ShowDropDownCart() {
    var menu = window.parent.$find("header_Dropnav1_navlinks1_rmDropDownCart");
    if (menu != null) {
        menu.findItemByValue("shoppingbag").open();
        setTimeout("window.parent.$find('header_Dropnav1_navlinks1_rmDropDownCart').findItemByValue('shoppingbag').close()", 5000);
    }
}
function SlideToggle(oObjectID) {
    try {
        $(oObjectID).slideToggle();
    }
    catch (Error) {
        alert(Error.description);
    }
}
function BeforeWindowClose(sender, eventArgs) {
    try {
        sender.SetUrl("");
        eventArgs.set_cancel(false);
    }
    catch (Error) {
    }
}
