﻿var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);

function ShowStatus(obj, hide, msg) {
    document.getElementById("Status_help").innerHTML = msg;
    ShowHelp(obj, 'Status', hide);
}

function ShowHelp(obj, field, hide) {
    //Get help object
    var helpObj;
    if (document.all) {
        helpObj = document.all[field + "_help"];
    } else if (document.getElementById) {
        helpObj = document.getElementById(field + "_help");
    }
    if (helpObj) {
        //if help object is shown, hide it ; if object hidden, show it
        if (hide) {
            helpObj.style.display = "none";
        }
        else {
            helpObj.style.display = "";
        }

        //Get location of mouseover object, move help object to the left if will display off-screen
        var divWidth = 300;
        var offsetLeft = getOffsetLeft(obj);
        var screenWidth = (window.innerWidth) ? window.innerWidth - 25 : document.body.clientWidth;
        if ((offsetLeft + divWidth) > screenWidth) offsetLeft = screenWidth - divWidth;
        newX = offsetLeft;

        //Get location of mouseover object, move help object on top if will display off-screen
        var divHeight = helpObj.offsetHeight;
        var offsetTop = getOffsetTop(obj) + obj.offsetHeight + 5;
        var screenHeight = (window.innerHeight) ? window.innerHeight - 25 : document.body.clientHeight;
        if (moveOnScreen) {
            if ((offsetTop + divHeight) > screenHeight + getScrollY()) offsetTop = getOffsetTop(obj) - divHeight;
        }
        newY = offsetTop;

        helpObj.style.top = newY + "px";
        helpObj.style.left = newX + "px";

        if (!hide) {
            qh_hideElement("select", helpObj);
            qh_hideElement("object", helpObj);
            qh_hideElement("embed", helpObj);
        } else {
            qh_showElement("select");
            qh_showElement("object");
            qh_showElement("embed");
        }
    }
}

function getOffsetTop(elm) {
    var mOffsetTop = elm.offsetTop;
    var mOffsetParent = elm.offsetParent;
    while (mOffsetParent) {
        mOffsetTop += mOffsetParent.offsetTop;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    return mOffsetTop;
}

function getOffsetLeft(elm) {
    var mOffsetLeft = elm.offsetLeft;
    var mOffsetParent = elm.offsetParent;
    while (mOffsetParent) {
        mOffsetLeft += mOffsetParent.offsetLeft;
        mOffsetParent = mOffsetParent.offsetParent;
    }
    return mOffsetLeft;
}

function getScrollY() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape
        scrOfY = window.pageYOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM
        scrOfY = document.body.scrollTop;
    }
    else if (document.documentElement &&
      (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}

function qh_hideElement(elmID, overDiv) {
    if (document.all) {
        for (i = 0; i < document.all.tags(elmID).length; i++) {
            obj = document.all.tags(elmID)[i];
            if (!obj || !obj.offsetParent) continue;

            // Find the element's offsetTop and offsetLeft relative to the BODY tag.
            objLeft = obj.offsetLeft;
            objTop = obj.offsetTop;
            objParent = obj.offsetParent;

            while (objParent.tagName.toUpperCase() != 'BODY') {
                objLeft += objParent.offsetLeft;
                objTop += objParent.offsetTop;
                objParent = objParent.offsetParent;
            }

            objHeight = obj.offsetHeight;
            objWidth = obj.offsetWidth;

            if ((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
            else if ((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
            else if (overDiv.offsetTop >= (objTop + objHeight));
            else if (overDiv.offsetLeft >= (objLeft + objWidth));
            else {
                obj.style.visibility = 'hidden';
            }
        }
    }
}
function qh_showElement(elmID) {
    if (document.all) {
        for (i = 0; i < document.all.tags(elmID).length; i++) {
            obj = document.all.tags(elmID)[i];
            if (!obj || !obj.offsetParent) continue;
            obj.style.visibility = '';
        }
    }
}
var moveOnScreen = true;


// The swapImage function is used for rollover images
// Example: onmouseover="swapImage('go','images/novo_go_d.gif')" onmouseout="swapImage('go','images/novo_go_u.gif')"
function swapImage(imageId, newImagePath) {
    document.getElementById(imageId).src = newImagePath;
}

var slideRunning = 0;
var slideMinimum = 4; /* slowest speed to let it move, lower = slower */
var slideDivisor = 2; /* higher number = slower */
var slideTimer = 30;
var slideTarget = 0;
var slideTop = 0;

/* 
IE's timer is 10ms 'slower' than everyone else. The following conditional
corrects for that
@cc_on
@if (@_jscript_version>=4)
slideTimer-=10;
@end
@*/

function slideLoop() {
    slideRunning = 0;
    moveAmount = slideMinimum + Math.ceil((slideTarget.clientHeight - slideTop) / 10);
    switch (slideTarget.className) {
        case 'slideOut':
            slideTop += moveAmount;
            if (slideTop > slideTarget.clientHeight) {
                slideTop = slideTarget.clientHeight;
            } else {
                slideRunning++;
            }

            break;
        case 'slideIn':
            slideTop -= moveAmount;
            if (slideTop < 0) {
                slideTop = 0;
            } else {
                slideRunning++;
            }

            break;
    }
    slideTarget.style.top = -slideTop + 'px';
    if (slideRunning > 0) setTimeout(slideLoop, slideTimer);
}

function slide(targetID) {
    slideTarget = document.getElementById(targetID);
    switch (slideTarget.className) {
        case 'slideMe':
            slideTop = slideTarget.clientHeight;
        case 'slideOut':
            slideTarget.className = 'slideIn';
            break;
        case 'slideIn':
            slideTarget.className = 'slideOut';
            break;
    }
    if (slideRunning == 0) slideLoop();
}

// this function determines how and what is displayed when the user hovers over the five dollar icon
function MyTip(arg) {
    switch (arg) {
        case "FiveDollar":
            return Tip('Products marked &quot;Yes&quot; qualify for a flat <b>$5.00 shipping and handling charge</b><br />per order when shipped standard delivery from our warehouse to anywhere in the<br /> contiguous lower 48 states. No calculating, no guessing, no hassle!<br /><br />', BALLOON, true, ABOVE, true, JUMPHORZ, true, OFFSETX, -17, FADEIN, 400, FADEOUT, 0);


    }
}

// Function used to determine the X coordinate for the shopping cart hover
function CalcFixX() {
    if (parseInt(navigator.appVersion) > 3) {
        if (navigator.appName == "Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft") != -1) {
            winW = document.body.offsetWidth;
            winH = document.body.offsetHeight;
        }
    }

    if (winW > document.width) {
        winW = document.width;
    }

    var UserWidth = winW;
    var shoppingWidth = document.getElementById('shopping').offsetWidth;

    var cartTotalWidth = document.getElementById('headerCartTotal').offsetWidth;
    var quickShopWidth = document.getElementById('headerQuickShop').offsetWidth;
    var cartCheckout = document.getElementById('headerCheckout').offsetWidth;

    if (UserWidth > 960) {
        var padding = UserWidth - 960;
        padding = padding / 2 + 4;

        newWidth = UserWidth - cartTotalWidth - quickShopWidth - cartCheckout - padding;
        return newWidth;
    }
    else {
        newWidth = UserWidth - shoppingWidth;
        return newWidth;
    }

}

// Function used to determine the Y coordinate for the shopping cart hover
function CalcFixY() {
    var headerHeight = document.getElementById('header').offsetHeight;
    return headerHeight;
}

// Function used to determine the Y coordinate for the shopping cart hover when in the corp store
function CorpCalcFixY() {
    // the corporate header has a padding of 8 that needs to be subtracted to line up under the header

    var headerHeight = document.getElementById('header').offsetHeight - 8;
    return headerHeight;
}

// Function used to determine the width of the hover box dynamically
function determineHoverBoxWidth() {
    var cartTotalWidth = document.getElementById('headerCartTotal').offsetWidth;
    var cartCheckoutWidth = document.getElementById('headerCheckout').offsetWidth;

    var boxWidth = cartTotalWidth + cartCheckoutWidth - 9;
    return boxWidth;
}

function divSize() {
    var browserToolBarHeight = 230;
    var header = document.getElementById('header').offsetHeight;
    var footer = document.getElementById('footer').offsetHeight;

    var sidNav = document.getElementById('sideNavColumn').offsetHeight;
    var container = 0;

    if (document.getElementById('MainProductContainer')) {
        container = document.getElementById('MainProductContainer').offsetHeight;
    }

    var container2 = 0;

    if (document.getElementById('pagingTopContainer')) {
        container2 = document.getElementById('pagingTopContainer').offsetHeight;
    }


    var crumbTrail = 0;

    if (document.getElementById('categoryDisplayCrumb')) {
        crumbTrail = document.getElementById('categoryDisplayCrumb').offsetHeight;
    }

    var noResults = 0;

    if (document.getElementById('noResults')) {
        noResults = document.getElementById('noResults').offsetHeight;
    }

    var sidebarPromoSpan = 0;

    if (document.getElementById('sidebarPromoSpan')) {
        sidebarPromoSpan = 80;
    }

    var promoImage = 0;
    var sPath = window.location.pathname;

    if (document.getElementById('promo') && sPath.indexOf("TopCategory") > -1) {
        promoImage = document.getElementById('promo').offsetHeight - 100;
    }

    var footerDetails = 0;
    if (document.getElementById('footerDetails')) {
        footerDetails = document.getElementById('footerDetails').offsetHeight;
    }

    var contentH = ((container + container2 + browserToolBarHeight + noResults + promoImage + sidebarPromoSpan) - (header + crumbTrail + (footer - footerDetails)));

    return contentH;
}

function resetDotNetScrollPosition() {
    var scrollX = document.getElementById('__SCROLLPOSITIONX');
    var scrollY = document.getElementById('__SCROLLPOSITIONY');

    if (scrollX != null && scrollY != null) {
        scrollX.value = 0;
        scrollY.value = 0;
    }
}

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 ((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]; }
}
