
// convert all characters to lowercase to simplify testing
var agt = navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
            && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
                        (agt.indexOf("; nav") != -1)));
var is_nav6 = (is_nav && (is_major == 5)); var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);

var is_mac = (agt.indexOf("mac") != -1);

var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5") == -1));
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1));
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);

// Scroll Mode (crawl or jump)
var ScrollMode = new Object();
ScrollMode.CRAWL = 'crawl';
ScrollMode.JUMP = 'jump';

function showDisplayBox(id) {
    if (!id) { return; }
    var divs = document.getElementsByTagName("div");
    for (var i = 0; i <= divs.length; i++) {
        if (divs[i]) {
            if (divs[i].className == "DisplayBox") {
                divs[i].className = "hide";
                if (divs[i].style && divs[i].style.visibility) {
                    divs[i].style.visibility = "hidden";
                }
            }
        }
    }
    var showBox = document.getElementById(id);
    if (showBox) {
        showBox.className = "DisplayBox";
        if (showBox.style && showBox.style.visibility) {
            showBox.style.visibility = "visible";
        }
    }
    return false;
}

function showElement(id) {
    if (!id) { return; }
    var elem = d(id);

    if (elem) {
        elem.className = "show";
        if (elem.style && elem.style.visibility) {
            elem.style.visibility = "visible";
        }
    }
}

function hideElement(id) {
    if (!id) { return; }
    var elem = d(id);

    if (elem) {
        elem.className = "hide";
        if (elem.style && elem.style.visibility) {
            elem.style.visibility = "hidden";
        }
    }
}

function clickButton(id) {
    var button = document.getElementById(id);
    if (button) {
        if (is_gecko && button.href.indexOf("javascript") == 0) { eval(button.href); }
        else { button.click(); }
    }
    else {
        alert('Button not found: ' + id);
    }
}

// shortcut method
function d(id) {
    return document.getElementById(id);
}

// selected value
function sv(id) {
    var element = d(id);
    var options, i;
    if (element) {
        options = element.getElementsByTagName("option");
        for (i = 0; i < options.length; i++) {
            var option = element.getElementsByTagName("option")[i];
            if (option.selected) {
                return option.value;
            }
        }
    }
    return null;
}

// set html
function sh(id, content) {
    if (d(id)) { d(id).innerHTML = content; }
    //else { alert(id + ' not found'); }
}

function loadWindow() {
    if (d("ProductMoreInfoContent")) {
        jumpToHash();
    }
}

function jumpToHash() {
    setTimeout('doJumpToHash()', 30);
}

function doJumpToHash() {
    if (window.location.href.indexOf('#') != -1) {
        var hash = window.location.href.substring(window.location.href.indexOf('#'));
        var anchorName = hash.substring(1);
        showDisplayBox(anchorName + 'Box');
        if (!is_mac && !is_ie5up) {
            window.location.href = hash;
        }
        //scrollToElement(anchorName + 'Box', ScrollMode.JUMP);
    }
}

function scrollToElement(id, mode) {
    if (ScrollMode.CRAWL == mode) {
        crawlToElement(id);
    }
    else if (ScrollMode.JUMP == mode) {
        jumpToElement(id)
    }
    else {
        // default to jump
        jumpToElement(id)
    }
}

function jumpToElement(id) {
    var xPos = 0;
    var yPos = findYPos(d(id));
    window.scrollTo(xPos, yPos);
}

var lastYPos = -50;
function crawlToElement(id) {
    var xPos = 0;
    var yPos = findYPos(d(id));
    var distance = Math.abs(yPos - getCurrentYPos());
    var moveDistance = 10;
    if (distance > moveDistance) {
        if (yPos < getCurrentYPos()) {
            yPos = getCurrentYPos() - moveDistance;
        }
        else {
            yPos = getCurrentYPos() + moveDistance;
            window.scrollTo(xPos, yPos);
            if (lastYPos != getCurrentYPos()) {
                setTimeout("crawlToElement('" + id + "');", 10);
            }
            lastYPos = getCurrentYPos();
            return;
        }
    }
    window.scrollTo(xPos, yPos);
}

function scrollToPosition(xPos, yPos) {
    window.scrollTo(xPos, yPos);
}

function findXPos(obj) {
    if (!obj) { return 0; }
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findYPos(obj) {
    if (!obj) { return 0; }
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function getCurrentYPos() {
    if (document.body && document.body.scrollTop)
        return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    if (window.pageYOffset)
        return window.pageYOffset;
    return 0;
}

function PopupWinLg(strURL) {
    win = window.open(strURL, 'popupwinlg', 'toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=670,height=640,top=0,left=0');
    win.focus();
}

function PopupWinXtraLg(strURL) {
    win = window.open(strURL, 'popupwinlg', 'toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=825,height=650,top=20,left=20');
    win.focus();
}

function PopupWinMed(strURL) {
    win = window.open(strURL, 'popupmed', 'toolbar=no,menubar=no,location=yes,status=no,scrollbars=yes,resizable=yes,width=600,height=400');
    win.focus();
}

function PopupWinSmall(strURL) {
    win = window.open(strURL, 'popupmed', 'toolbar=no,menubar=no,location=yes,status=no,scrollbars=yes,resizable=yes,width=400,height=300');
    win.focus();
}
function PopupWinLong(strURL) {
    win = window.open(strURL, 'popuplong', 'toolbar=no,menubar=no,location=yes,status=no,scrollbars=yes,resizable=yes,width=550,height=750');
    win.focus();
}
function PopupWinWithTools(strURL) {
    win = window.open(strURL, 'popupwinlg', 'toolbar=yes,menubar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=825,height=650,top=20,left=20');
    win.focus();
}

function PopupWinSuperLg(strURL) {
    win = window.open(strURL, 'popupwinlg', 'toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=1000,height=750,top=20,left=20');
    win.focus();
}

//try this for popup
function showPopUp(el, fr) {
    var cvr = document.getElementById("cover")
    var dlg = document.getElementById(el)
    var frm = document.getElementById(fr)
    cvr.style.display = "block"
    dlg.style.display = "block"
    frm.style.display = "block"
    if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
        var pageWidth = document.body.scrollWidth + 'px';
        var pageHeight = document.body.scrollHeight + 'px';
    }
    else if (document.body.offsetWidth) {
        var pageWidth = document.body.offsetWidth + 'px';
        var pageHeight = document.body.offsetHeight + 'px';
    }
    else {
        var pageWidth = '100%';
        var pageHeight = '100%';
    }
    cvr.style.width = pageWidth;
    cvr.style.height = pageHeight;
}
function closePopUp(el, fr) {
    var cvr = document.getElementById("cover")
    var dlg = document.getElementById(el)
    var frm = document.getElementById(fr)
    cvr.style.display = "none"
    dlg.style.display = "none"
    frm.style.display = "none"
    document.body.style.overflowY = "scroll"
}
function CallInternalSearch() {
    s = s_gi(s_account);
    s.linkTrackVars = "events";
    s.linkTrackEvents = "event3";
    s.events = "event3";
    s.tl(this, 'o', 'Internal Search');
}
function CallCrossSell() {
    s = s_gi(s_account);
    s.linkTrackVars = "events";
    s.linkTrackEvents = "event14";
    s.events = "event14";
    s.tl(this, 'o', 'Cross Sell');
}

function CallMailingList() {
    s = s_gi(s_account);
    s.linkTrackVars = "events";
    s.linkTrackEvents = "event25";
    s.events = "event25";
    s.tl(this, 'o', 'Mailing List');
}


function ClearTextBox(textbox, initialvalue) {
    if (textbox.value == initialvalue) {
        textbox.value = '';
    }
}

function changePic(img_name, img_src) {
    document[img_name].src = img_src;
}
function changeLinkColor(linkName, color) {
    document[linkName].style.color = color;
}
function resizePopup(el, fr, height) {
    var dlg = document.getElementById(el);
    var frm = document.getElementById(fr);
    dlg.style.height = height;
    frm.style.height = height;
}

window.onload = loadWindow

function BadCharStrip(str) {
    NewStr = "";
    NewChar = "";

    for (i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) == 32) {
            //Do nothing (space)
            NewChar = str.charAt(i);
        } else if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
            //Do nothing (1 - 9)
            NewChar = str.charAt(i);
        } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
            //Do nothing (a - z)
            NewChar = str.charAt(i);
        } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
            //Do nothing (A - Z)
            NewChar = str.charAt(i);
        } else {
            //Convert to web safe ASCII code
            NewChar = "&#" + str.charCodeAt(i) + ";";
        }

        NewStr = NewStr + NewChar;
    }

    return (NewStr);
}



