﻿//List of javascript files to include
//function include(filename) { var head = document.getElementsByTagName('head')[0]; script = document.createElement('script'); script.src = filename; script.type = 'text/javascript'; head.appendChild(script) }
//no longer using this include function because it doesn't load the files reliably

// JQuery Document Ready Event
$(document).ready(function() {
    //Wire-Up product quick view.
    $('#ProductQV').dialog({ width: 502, resizable: false, autoOpen: false });


    //Wire-Up all dialogs with default settings.
    //$('.phe-ui-dialog').dialog({ autoOpen: false });

    $('.phe-ui-dialog').each(function() {

        var $this = $(this);
        var position = $this.position();
        var myOptions = {};
        var pheDialogOptions = $this.attr('pheDialogOptions')
        if (pheDialogOptions) {
            pheDialogOptions = ", " + pheDialogOptions;
        }
        var metaData = "{ autoOpen: false, position: [" + position.left + ", " + position.top + "]" + pheDialogOptions + " }";
        if (metaData) {
            eval("myOptions = " + metaData + ";");
        }
        if (myOptions) {
            $this.dialog(myOptions);
        }
        else {
            //$this.dialog();
        }
    });

});
//Jquery Functions
//Jquery Functions
function ShowDialog(ID, URL, Title) {
    var $this = $('div#' + ID);
    var scrolltop = $(window).scrollTop();
    var position = $('a[rel = ' + ID + ']').position();
    var positionArray = [];
    if (position) {
        positionArray[0] = position.left;
        positionArray[1] = position.top - scrolltop;
        $this.load(URL).dialog('option', 'position', positionArray).dialog('option', 'title', Title).dialog('open');
    }
    else {
        $this.load(URL).dialog('open');
    }
    
}
//Jquery quick view
function ShowProductQV(ProductID, QSParams, HeaderText, leftcoord, topcoord) {
    $('div#ProductQV iframe').attr('src', 'qv.aspx?pid=' + ProductID + QSParams).load(function() {
        $('div#ProductQV').dialog('option', 'title', HeaderText).dialog('open');
    });

}

//**************************************************************************
//include("/jscripts/Gomez/ActualXF.js"); //8k
//moved to the head of the page because it was not working in the include file

//**************************************************************************
//include("/jscripts/PHE_RPC.js"); //1k
var xmlRequester = null;
var READY_STATE_SUCCESS = 4;

function callAsyncRPC(rpcPath, sXML, callBackFunc) {
    try {
        xmlRequester.open("POST", rpcPath, true);
        if (trim(sXML) == "")
            sXML = "<XML></XML>";
        xmlRequester.onreadystatechange = callBackFunc;
        xmlRequester.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlRequester.send("XML=" + escape(sXML.replace(/\+/g, "%2B")));
    }
    catch (ex) {
        alert(ex.message);
    }
}

function InitRPC() {
    if (window.XMLHttpRequest) {
        xmlRequester = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        xmlRequester = new ActiveXObject("Microsoft.XMLHTTP");
    }
}


//**************************************************************************
//include("/jscripts/Ajax.js"); //8k
// MULTIPLE XMLHttpRequest FrameWork [BEGIN]
var maxCon = 10; // maximum connection
var tailCon = 1; // initial tail
var HTTPCon = new Array; // array of connection

// init connection array
for (i = 1; i <= maxCon; i++) {
    HTTPCon[i] = false;
}

// function to find one available connection
// either find used empty or create new if available
function fine1Con() {
    var i;

    // try to find 1 used empty (completed)
    for (i = 1; i < tailCon; i++) {
        if (HTTPCon[i]) {
            if (HTTPCon[i].readyState == 0 || HTTPCon[i].readyState == 4)
                return i; // return empty one
        }
    }

    // if can not 1 used empty, pick 1 new
    if (tailCon <= maxCon) {

        // crate new object
        if (window.XMLHttpRequest) {
            HTTPCon[tailCon] = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            HTTPCon[tailCon] = new ActiveXObject("Microsoft.XMLHTTP");
        }

        // if new object was created successfully
        if (HTTPCon[tailCon]) {
            i = tailCon;
            tailCon = tailCon + 1;
            return i; // increase the tail of stack and exit
        } else {
            return false; // new object was failed (browser may not be ajax anable)
        }
    } else {
        return false; // maximum connection reached
    }

}

function getXMLData(dataSource, divID, HTMLOnly) {
    // find me one available Connection
    var gotOne = fine1Con();
    if (gotOne) {
        if (HTTPCon[gotOne]) {
            var obj = document.getElementById(divID);
            HTTPCon[gotOne].open("GET", dataSource);
            HTTPCon[gotOne].onreadystatechange = function() {
                if (HTTPCon[gotOne].readyState == 4 && HTTPCon[gotOne].status == 200) {
                    var result = HTTPCon[gotOne].responseText;
                    var tabnumber = 0
                    if (HTMLOnly > 0) {
                        // make sure that this is the correct format   
                        t1 = result.indexOf('">');
                        t2 = result.indexOf('</string>');
                        if ((t1 > 0) && (t2 > 0) && (t2 > t1)) {
                            result = cleanGTLT(result.substring(t1 + 2, t2));
                            t1 = result.indexOf('#A#');
                            t2 = result.indexOf('#B#');
                            if ((t1 > 0) && (t2 > 0) && (t2 > t1)) {
                                tabnumber = result.substring(t1 + 3, t2);
                                result = result.substring(0, t1);
                            }
                        }
                    }
                    if (obj) { obj.innerHTML = result; }
                    if (aftergetXMLData) {
                        aftergetXMLData(tabnumber, result); // if there is aftergetXMLData function, call it
                    }
                }
            }
            HTTPCon[gotOne].send(null);
        }
    } else {
        // All Connection full 
        alert('Connection Full');
    }
}

function postXMLData(dataSource, divID, dataPost, HTMLOnly) {
    // find me one available Connection
    var gotOne = fine1Con();
    if (gotOne) {
        if (HTTPCon[gotOne]) {
            var obj = document.getElementById(divID);
            HTTPCon[gotOne].open('POST', dataSource);
            // need this content type
            HTTPCon[gotOne].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            HTTPCon[gotOne].onreadystatechange = function() {
                if (HTTPCon[gotOne].readyState == 4 && HTTPCon[gotOne].status == 200) {
                    var result = HTTPCon[gotOne].responseText;
                    if (HTMLOnly > 0) {
                        // make sure that this is the correct format   
                        t1 = result.indexOf('">');
                        t2 = result.indexOf('</string>');
                        if ((t1 > 0) && (t2 > 0) && (t2 > t1)) {
                            result = cleanGTLT(result.substring(t1 + 2, t2));
                        }
                    }
                    obj.innerHTML = result;
                    if (afterpostXMLData) {
                        afterpostXMLData(); // if there is aftergetXMLData function, call it
                    }
                }
            }
            HTTPCon[gotOne].send(dataPost);
        }
    } else {
        // All Connection full 
        alert('Connection Full');
    }
}

function cleanGTLT(s) {
    while (s.indexOf('&gt;') > -1) {
        s = s.replace('&gt;', '>');
    }
    while (s.indexOf('&lt;') > -1) {
        s = s.replace('&lt;', '<');
    }
    return s;
}

function updateHelpfulness(ratingID, isHelpful) {
    if (isHelpful == true) {
        alert('Thank you for letting us know you found this review helpful. We\'ll be sure to let our other customers know.');
    }
    else {
        alert('Thank you for letting us know that you did not find this review helpful. We\'ll be sure to let our other customers know.');
    }
    rating_ajax_update(ratingID, isHelpful);
}

function rating_ajax_update(ratingID, isHelpful) {

    var qs = 'rid=' + ratingID + '&isHelpful=' + isHelpful
    var dataSource = '/redwood/controls/product/AjaxUpdateRating.aspx?' + qs;
    var gotOne = fine1Con();
    if (gotOne) {
        if (HTTPCon[gotOne]) {
            HTTPCon[gotOne].open("GET", dataSource);
            HTTPCon[gotOne].onreadystatechange = function() {
                if (HTTPCon[gotOne].readyState == 4 && HTTPCon[gotOne].status == 200) {
                    //at this point we have a result and want to pull out the real debug code
                    //obj.innerHTML = HTTPCon[gotOne].responseText.split('|')[0]    //<-- no need to set div since it's hidden anyway
                    if (qs != null && qs.indexOf("ajaxdebug") != -1) {
                        alert(qs);
                        alert('debug code=' + HTTPCon[gotOne].responseText.split('|')[1]);
                    }
                }
            }
            HTTPCon[gotOne].send(null);
        }
    }
}

function loadPage(url, containerid) {
    var loadedobjects = ""
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false
    page_request.onreadystatechange = function() {
        loadpage(page_request, containerid)
    }
    page_request.open('GET', url, true)
    page_request.send(null)
}

function loadpage(page_request, containerid) {
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1))
        document.getElementById(containerid).innerHTML = page_request.responseText
}

function loadobjs() {
    if (!document.getElementById)
        return
    for (i = 0; i < arguments.length; i++) {
        var file = arguments[i]
        var fileref = ""
        if (loadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding
            if (file.indexOf(".js") != -1) { //If object is a js file
                fileref = document.createElement('script')
                fileref.setAttribute("type", "text/javascript");
                fileref.setAttribute("src", file);
            }
            else if (file.indexOf(".css") != -1) { //If object is a css file
                fileref = document.createElement("link")
                fileref.setAttribute("rel", "stylesheet");
                fileref.setAttribute("type", "text/css");
                fileref.setAttribute("href", file);
            }
        }
        if (fileref != "") {
            document.getElementsByTagName("head").item(0).appendChild(fileref)
            loadedobjects += file + " " //Remember this object as being already added to page
        }
    }
}

function openQV(findControl, qvURL, leftcoord, topcoord) {
    var oWnd = $find(findControl);
    oWnd.setUrl(qvURL);
    oWnd.moveTo(leftcoord, topcoord);
    oWnd.show();
}
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}


//**************************************************************************
//include("/jscripts/internationalsites.js"); //1k
function change_url(form, strFormTitle) {
    var new_window = window.open();
    new_window.location.href = document.InternationalSitesForm.InternationalSites.options[document.InternationalSitesForm.InternationalSites.selectedIndex].value;
}


//**************************************************************************
//include("/jscripts/PHE_Utility.js"); //4k
function trim(sBuf) {
    if (!sBuf)
        return "";
    var iNum = parseInt(sBuf);
    if (!isNaN(iNum))
        return iNum.toString();
    while (sBuf.lastIndexOf(" ") == sBuf.length - 1) {
        sBuf = sBuf.substring(0, sBuf.lastIndexOf(" "));
        if (sBuf == "")
            return sBuf;
    }
    while (sBuf.indexOf(" ") == 0) {
        sBuf = sBuf.substring(1, sBuf.length);
    }
    return sBuf;
}

function getBetweenText(sBuffer, sStartText, sEndText) {
    if ((sBuffer.indexOf(sStartText) > -1) && (sBuffer.indexOf(sEndText) > -1)) {
        return (sBuffer.substring(sBuffer.indexOf(sStartText) + sStartText.length, sBuffer.indexOf(sEndText)));
    }
    else {
        return (null);
    }
}

function appendOptionToSelect(theVal, theText, selectName) {
    var elOptNew = document.createElement('option');
    elOptNew.text = theText;
    elOptNew.value = theVal;
    var elSel = document.getElementById(selectName);

    try {
        elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
    }
    catch (ex) {
        elSel.add(elOptNew); // IE only
    }
}

function clearDropDown(selectName) {
    document.getElementById(selectName).options.length = 0;
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}
function SetCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue)
        + ";expires=" + expire.toGMTString();
}
function DisableEnableLinks(xHow) {
    objLinks = document.links;
    for (i = 0; i < objLinks.length; i++) {
        objLinks[i].disabled = xHow;
        //link with onclick
        if (objLinks[i].onclick && xHow) {
            objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
        }
        //link without onclick
        else if (xHow) {
            objLinks[i].onclick = function() { return false; }
        }
        //remove return false with link without onclick
        else if (!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1) {
            objLinks[i].onclick = null;
        }
        //remove return false link with onclick
        else if (!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1) {
            strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;", "")
            objLinks[i].onclick = new Function(strClick);
        }
    }
}

String.prototype.getFuncBody = function() {
    var str = this.toString();
    str = str.replace(/[^{]+{/, "");
    str = str.substring(0, str.length - 1);
    str = str.replace(/\n/gi, "");
    if (!str.match(/\(.*\)/gi)) str += ")";
    return str;
}

// Merged in from PopUp.js
function OpenBrWindow(theURL, winName, features) {
    //v2.0
    var new_window = window.open(theURL, winName, features);
    new_window.focus();
}
function searchSubmit(sform) {
    //disable form after submit so that it can't be submitted multiple times
    sform.onsubmit = 'javascript:void(0);';
    sform.btnGO.onclick = 'javascript:void(0);';
    var saction = sform.action;

    if (saction.indexOf('?') != -1) { saction = saction + '&'; }
    else { saction = saction + '?'; }
    sform.action = saction + 'st=' + escape(sform.SearchTerm.value);
    sform.submit();
}
function moreButtonClicked(objectID) {
    var object = document.getElementById('menu' + objectID);
    object.style.display = 'block';
    object = document.getElementById('more' + objectID);
    object.style.display = 'none';

    for (x = 1; x <= 100; x++) {
        if (x.toString() != objectID) {
            var obj2 = document.getElementById('menu' + x.toString());

            if (obj2 != null) {
                obj2.style.display = 'none';
                obj2 = document.getElementById('more' + x.toString());
                obj2.style.display = 'block';
            }
        }
    }
    return;
}


//**************************************************************************
//include("/jscripts/nav.js");
var cssdropdown = {
    disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
    disablemenuclick: false, //when user clicks on a menu item with a drop down menu, disable menu item's link?
    enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no
    enableiframeshim: 1, //enable "iframe shim" technique to get drop down menus to correctly appear on top of controls such as form objects in IE5.5/IE6? 1 for yes, 0 for no

    //NO NEED TO EDIT BELOW. SEE OPTIONS ABOVE BEFORE CHANGING THE CODE BELOW////////////////////////
    dropmenuobj: null, ie: document.all, firefox: document.getElementById && !document.all, swipetimer: undefined, bottomclip: 0,
    getposOffset: function(what, offsettype) {
        var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
        var parentEl = what.offsetParent;
        while (parentEl != null) {
            totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop; parentEl = parentEl.offsetParent;
        } return totaloffset;
    },
    swipeeffect: function() {
        if (this.bottomclip < parseInt(this.dropmenuobj.offsetHeight)) {
            this.bottomclip += 10 + (this.bottomclip / 10)
            this.dropmenuobj.style.clip = "rect(0 auto " + this.bottomclip + "px 0)"
        }
        else
            return
        this.swipetimer = setTimeout("cssdropdown.swipeeffect()", 10)
    },
    showhide: function(obj, e) {
        if (this.ie || this.firefox)
            this.dropmenuobj.style.left = this.dropmenuobj.style.top = "-500px"
        if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover") {
            if (this.enableswipe == 1) {
                if (typeof this.swipetimer != "undefined")
                    clearTimeout(this.swipetimer)
                obj.clip = "rect(0 auto 0 0)"
                this.bottomclip = 0
                this.swipeeffect()
            }
            obj.visibility = "visible"
        }
        else if (e.type == "click")
            obj.visibility = "hidden"
    },
    iecompattest: function() {
        return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
    },
    clearbrowseredge: function(obj, whichedge) {
        var edgeoffset = 0
        if (whichedge == "rightedge") {
            var windowedge = this.ie && !window.opera ? this.iecompattest().scrollLeft + this.iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
            this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetWidth
            if (windowedge - this.dropmenuobj.x < this.dropmenuobj.contentmeasure)
                edgeoffset = this.dropmenuobj.contentmeasure - obj.offsetWidth
        }
        else {
            var topedge = this.ie && !window.opera ? this.iecompattest().scrollTop : window.pageYOffset
            var windowedge = this.ie && !window.opera ? this.iecompattest().scrollTop + this.iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
            this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetHeight
            if (windowedge - this.dropmenuobj.y < this.dropmenuobj.contentmeasure) {
                edgeoffset = this.dropmenuobj.contentmeasure + obj.offsetHeight
                if ((this.dropmenuobj.y - topedge) < this.dropmenuobj.contentmeasure)
                    edgeoffset = this.dropmenuobj.y + obj.offsetHeight - topedge
            }
        }
        return edgeoffset
    },
    dropit: function(obj, e, dropmenuID) {
        if (this.dropmenuobj != null)
            this.dropmenuobj.style.visibility = "hidden"
        this.clearhidemenu()
        if (this.ie || this.firefox) {
            obj.onmouseout = function() { cssdropdown.delayhidemenu() }
            obj.onclick = function() { return !cssdropdown.disablemenuclick }
            this.dropmenuobj = document.getElementById(dropmenuID)
            this.dropmenuobj.onmouseover = function() { cssdropdown.clearhidemenu() }
            this.dropmenuobj.onmouseout = function(e) { cssdropdown.dynamichide(e) }
            this.dropmenuobj.onclick = function() { cssdropdown.delayhidemenu() }
            this.showhide(this.dropmenuobj.style, e)
            this.dropmenuobj.x = this.getposOffset(obj, "left")
            this.dropmenuobj.y = this.getposOffset(obj, "top")
            this.dropmenuobj.style.left = this.dropmenuobj.x - this.clearbrowseredge(obj, "rightedge") + "px"
            this.dropmenuobj.style.top = this.dropmenuobj.y - this.clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + 1 + "px"
            this.positionshim()
        }
    },
    positionshim: function() {
        if (this.enableiframeshim && typeof this.shimobject != "undefined") {
            if (this.dropmenuobj.style.visibility == "visible") {
                this.shimobject.style.width = this.dropmenuobj.offsetWidth + "px"
                this.shimobject.style.height = this.dropmenuobj.offsetHeight + "px"
                this.shimobject.style.left = this.dropmenuobj.style.left
                this.shimobject.style.top = this.dropmenuobj.style.top
            }
            this.shimobject.style.display = (this.dropmenuobj.style.visibility == "visible") ? "block" : "none"
        }
    },
    hideshim: function() {
        if (this.enableiframeshim && typeof this.shimobject != "undefined")
            this.shimobject.style.display = 'none'
    },
    contains_firefox: function(a, b) {
        while (b.parentNode)
            if ((b = b.parentNode) == a)
            return true;
        return false;
    },
    dynamichide: function(e) {
        var evtobj = window.event ? window.event : e
        if (this.ie && !this.dropmenuobj.contains(evtobj.toElement))
            this.delayhidemenu()
        else if (this.firefox && e.currentTarget != evtobj.relatedTarget && !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
            this.delayhidemenu()
    },
    delayhidemenu: function() {
        this.delayhide = setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; cssdropdown.hideshim()", this.disappeardelay)
    },
    clearhidemenu: function() {
        if (this.delayhide != "undefined")
            clearTimeout(this.delayhide)
    },
    startchrome: function() {
        for (var ids = 0; ids < arguments.length; ids++) {
            var menuitems = document.getElementById(arguments[ids]).getElementsByTagName("a")
            for (var i = 0; i < menuitems.length; i++) {
                if (menuitems[i].getAttribute("rel")) {
                    var relvalue = menuitems[i].getAttribute("rel")
                    menuitems[i].onmouseover = function(e) {
                        var event = typeof e != "undefined" ? e : window.event
                        cssdropdown.dropit(this, event, this.getAttribute("rel"))
                    }
                }
            }
        }
        if (window.createPopup && !window.XmlHttpRequest) {
            document.write('<IFRAME id="iframeshim"  src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"></IFRAME>')
            this.shimobject = document.getElementById("iframeshim")
        }
    }
}
function turnTabOn(tabOnName, tabOffName, DivName) {
    if (document.getElementById(tabOnName).style.display == 'none' && document.getElementById(tabOffName).style.display == 'none') {
    } else { document.getElementById(tabOnName).style.display = 'block'; document.getElementById(tabOffName).style.display = 'none'; document.getElementById(DivName).style.display = 'block'; }
}
function turnTabOff(tabOnName, tabOffName, DivName) {
    if (document.getElementById(tabOnName).style.display == 'none' && document.getElementById(tabOffName).style.display == 'none') {
    } else { document.getElementById(tabOnName).style.display = 'none'; document.getElementById(tabOffName).style.display = 'block'; document.getElementById(DivName).style.display = 'none'; }
}


//**************************************************************************
//include("/jscripts/CompareChecks.js"); //4k
var xmlHttp;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5") != -1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6") != -1) || (navigator.userAgent.indexOf("Opera/6") != -1)) ? 1 : 0;
//netscape, safari, mozilla behave the same???  
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
var theCheckedProds = "";

function LogCompareClick(chk, productid, catID, custID) {
    var theBegin = "/";
    var Url = theBegin + "CompareList.aspx?CustomerID=" + custID + "&ProductID=" + productid + "&CategoryID=" + catID + "&Action=";
    if (chk.checked) {
        Url = Url + 'Add';
        theCheckedProds = theCheckedProds + "~" + productid + "~";
    }
    else {
        Url = Url + 'Remove';
        theCheckedProds = theCheckedProds.replace("~" + productid + "~", "");
    }
    xmlHttp = GetXmlHttpObject(stateChangeHandler);
    xmlHttp_Get(xmlHttp, Url);
    return true;
}
function stateChangeHandler() { if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') { } }

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) {
    xmlhttp.open('GET', url, true);
    xmlhttp.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
    xmlhttp.setRequestHeader('Pragma', 'no-cache');
    xmlhttp.send(null);
}

function GetXmlHttpObject(handler) {
    var objXmlHttp = null;

    if (is_ie) {
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
        try {
            objXmlHttp = new ActiveXObject(strObjName);
            objXmlHttp.onreadystatechange = handler;
        }
        catch (e) {
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
            return;
        }
    }
    else if (is_opera) {
        alert('Opera detected. The page may not behave as expected.');
        return;
    }
    else {
        objXmlHttp = new XMLHttpRequest();
        objXmlHttp.onload = handler;
        objXmlHttp.onerror = handler;
    }
    return objXmlHttp;
}
function ClearChecks() {
    theCheckedProds = theCheckedProds.replace("~~", "~");
    var splitArray = theCheckedProds.split("~");
    for (var x = 0; x < splitArray.length; x++) {
        if (x == 0 || x == (splitArray.length - 1))
            var nothing_here = "";
        else {
            if (splitArray[x].length > 0)
                document.getElementById("Compare_" + splitArray[x]).checked = false;
        }
    }
    theCheckedProds = "";
}

function GetCheckedProds() {
    var theReturn = "";
    var f = document.forms.length;
    for (var x = 0; x < f; x++) {
        var theForm = document.forms[x];
        var AllElements = theForm.elements;
        var l = AllElements.length;
        for (var i = 0; i < l; i++) {
            var element = AllElements[i];
            if (element.type == 'checkbox' && element.name.indexOf('Compare_') > -1) {
                if (element.checked) {
                    var theProdID = element.name.substring(8);

                    if (theReturn == "")
                        theReturn = theProdID;
                    else
                        theReturn = theReturn + "+" + theProdID;
                }
            }
        }
    }

    return theReturn;
}


//**************************************************************************
//include("/jscripts/scroller.js"); //12k
var jsEvent = {
    add: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
        else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
    },
    remove: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
        else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
    },
    DOMit: function(e) {
        e = e ? e : window.event; // e IS passed when using attachEvent though ...
        if (!e.target) e.target = e.srcElement;
        if (!e.preventDefault) e.preventDefault = function() { e.returnValue = false; return false; }
        if (!e.stopPropagation) e.stopPropagation = function() { e.cancelBubble = true; }
        return e;
    },
    getTarget: function(e) {
        e = jsEvent.DOMit(e); var tgt = e.target;
        if (tgt.nodeType != 1) tgt = tgt.parentNode;
        return tgt;
    }
}
function addLoadEvent(func) {
    var oldQueue = window.onload ? window.onload : function() { };
    window.onload = function() {
        oldQueue();
        func();
    }
}
function jsscrollObj(wndoId, lyrId, horizId) {
    var wn = document.getElementById(wndoId);
    this.id = wndoId; jsscrollObj.col[this.id] = this;
    this.animString = "jsscrollObj.col." + this.id;
    this.load(lyrId, horizId);

    if (wn.addEventListener) {
        wn.addEventListener('DOMMouseScroll', jsscrollObj.doOnMouseWheel, false);
    }
    wn.onmousewheel = jsscrollObj.doOnMouseWheel;
}
jsscrollObj.isSupported = function() {
    if (document.getElementById && document.getElementsByTagName
         && document.addEventListener || document.attachEvent) {
        return true;
    }
    return false;
}
jsscrollObj.col = {}; // collect instances
jsscrollObj.defaultSpeed = jsscrollObj.prototype.speed = 180; // default for mouseover or mousedown scrolling
jsscrollObj.defaultSlideDur = jsscrollObj.prototype.slideDur = 500; // default duration of glide onclick
// pseudo events 
jsscrollObj.prototype.on_load = function() { } // when jsscrollObj initialized or new layer loaded
jsscrollObj.prototype.on_scroll = function() { }
jsscrollObj.prototype.on_scroll_start = function() { }
jsscrollObj.prototype.on_scroll_stop = function() { } // when scrolling has ceased (mouseout/up)
jsscrollObj.prototype.on_scroll_end = function() { } // reached end
jsscrollObj.prototype.on_update = function() { } // called in updateDims
jsscrollObj.prototype.on_glidescroll = function() { }
jsscrollObj.prototype.on_glidescroll_start = function() { }
jsscrollObj.prototype.on_glidescroll_stop = function() { } // destination (to/by) reached
jsscrollObj.prototype.on_glidescroll_end = function() { } // reached end
jsscrollObj.prototype.load = function(lyrId, horizId) {
    var wndo, lyr;
    if (this.lyrId) { // layer currently loaded?
        lyr = document.getElementById(this.lyrId);
        lyr.style.visibility = "hidden";
    }
    this.lyr = lyr = document.getElementById(lyrId); // hold this.lyr?
    this.lyr.style.position = 'absolute';
    this.lyrId = lyrId; // hold id of currently visible layer
    this.horizId = horizId || null; // hold horizId for update fn
    wndo = document.getElementById(this.id);
    this.y = 0; this.x = 0; this.shiftTo(0, 0);
    this.getDims(wndo, lyr);
    lyr.style.visibility = "visible";
    this.ready = true; this.on_load();
}
jsscrollObj.prototype.shiftTo = function(x, y) {
    if (this.lyr) {
        this.lyr.style.left = (this.x = x) + "px";
        this.lyr.style.top = (this.y = y) + "px";
    }
}
jsscrollObj.prototype.getX = function() { return this.x; }
jsscrollObj.prototype.getY = function() { return this.y; }
jsscrollObj.prototype.getDims = function(wndo, lyr) {
    this.wd = this.horizId ? document.getElementById(this.horizId).offsetWidth : lyr.offsetWidth;
    this.maxX = (this.wd - wndo.offsetWidth > 0) ? this.wd - wndo.offsetWidth : 0;
    this.maxY = (lyr.offsetHeight - wndo.offsetHeight > 0) ? lyr.offsetHeight - wndo.offsetHeight : 0;
}
jsscrollObj.prototype.updateDims = function() {
    var wndo = document.getElementById(this.id);
    var lyr = document.getElementById(this.lyrId);
    this.getDims(wndo, lyr);
    this.on_update();
}
// for mouseover/mousedown scrolling
jsscrollObj.prototype.initScrollVals = function(deg, speed) {
    if (!this.ready) return;
    if (this.timerId) {
        clearInterval(this.timerId); this.timerId = 0;
    }
    this.speed = speed || jsscrollObj.defaultSpeed;
    this.fx = (deg == 0) ? -1 : (deg == 180) ? 1 : 0;
    this.fy = (deg == 90) ? 1 : (deg == 270) ? -1 : 0;
    this.endX = (deg == 90 || deg == 270) ? this.x : (deg == 0) ? -this.maxX : 0;
    this.endY = (deg == 0 || deg == 180) ? this.y : (deg == 90) ? 0 : -this.maxY;
    this.lyr = document.getElementById(this.lyrId);
    this.lastTime = new Date().getTime();
    this.on_scroll_start(this.x, this.y);
    this.timerId = setInterval(this.animString + ".scroll()", 10);
}
jsscrollObj.prototype.scroll = function() {
    var now = new Date().getTime();
    var d = (now - this.lastTime) / 1000 * this.speed;
    if (d > 0) {
        var x = this.x + Math.round(this.fx * d); var y = this.y + Math.round(this.fy * d);
        if ((this.fx == -1 && x > -this.maxX) || (this.fx == 1 && x < 0) ||
                (this.fy == -1 && y > -this.maxY) || (this.fy == 1 && y < 0)) {
            this.lastTime = now;
            this.shiftTo(x, y);
            this.on_scroll(x, y);
        } else {
            clearInterval(this.timerId); this.timerId = 0;
            this.shiftTo(this.endX, this.endY);
            this.on_scroll(this.endX, this.endY);
            this.on_scroll_end(this.endX, this.endY);
        }
    }
}
// when scrolling has ceased (mouseout/up)
jsscrollObj.prototype.ceaseScroll = function() {
    if (!this.ready) return;
    if (this.timerId) {
        clearInterval(this.timerId); this.timerId = 0;
    }
    this.on_scroll_stop(this.x, this.y);
}
jsscrollObj.handleMouseWheel = function(id, delta) {
    var wndo = jsscrollObj.col[id];
    var x = wndo.x;
    var y = wndo.y;
    wndo.on_scroll_start(x, y);
    var ny;
    ny = 12 * delta + y
    ny = (ny < 0 && ny >= -wndo.maxY) ? ny : (ny < -wndo.maxY) ? -wndo.maxY : 0;
    wndo.shiftTo(x, ny);
    wndo.on_scroll(x, ny);
}
jsscrollObj.doOnMouseWheel = function(e) {
    var delta = 0;
    if (!e) e = window.event;
    if (e.wheelDelta) { /* IE/Opera. */
        delta = e.wheelDelta / 120;
        if (window.opera) delta = -delta;
    } else if (e.detail) { // Mozilla 
        delta = -e.detail / 3;
    }
    if (delta) { // > 0 up, < 0 down
        jsscrollObj.handleMouseWheel(this.id, delta);
    }
    if (e.preventDefault) e.preventDefault();
    e.returnValue = false;
}
function jsgetLayerOffset(el, oCont, sOff) {
    var off = "offset" + sOff.charAt(0).toUpperCase() + sOff.slice(1);
    var val = el[off];
    while ((el = el.offsetParent) != oCont)
        val += el[off];
    var clientOff = off.replace("offset", "client");
    if (el[clientOff]) val += el[clientOff];
    return val;
}
jsscrollObj.prototype.setUpScrollControls = function(controlsId, autoHide, axis) {
    var wndoId = this.id; var el = document.getElementById(controlsId);
    if (autoHide && axis == 'v' || axis == 'h') {
        jsscrollObj.handleControlVis(controlsId, wndoId, axis);
        jsScrollbar_Co.addEvent(this, 'on_load', function() { jsscrollObj.handleControlVis(controlsId, wndoId, axis); });
        jsScrollbar_Co.addEvent(this, 'on_update', function() { jsscrollObj.handleControlVis(controlsId, wndoId, axis); });
    }
    var links = el.getElementsByTagName('a'), cls, eType;
    for (var i = 0; links[i]; i++) {
        cls = jsscrollObj.get_DelimitedClass(links[i].className);
        eType = jsscrollObj.getEv_FnType(cls.slice(0, cls.indexOf('_')));
        switch (eType) {
            case 'mouseover':
            case 'mousedown':
                jsscrollObj.handleMouseOverDownLinks(links[i], wndoId, cls);
                break;
            case 'scrollToId':
                jsscrollObj.handleScrollToId(links[i], wndoId, cls);
                break;
            case 'scrollTo':
            case 'scrollBy':
            case 'click':
                jsscrollObj.handleClick(links[i], wndoId, cls);
                break;
        }
    }
}
jsscrollObj.handleMouseOverDownLinks = function(linkEl, wndoId, cls) {
    var parts = cls.split('_'); var eType = parts[0];
    var re = /^(mouseover|mousedown)_(up|down|left|right)(_[\d]+)?$/;

    if (re.test(cls)) {
        var eAlt = (eType == 'mouseover') ? 'mouseout' : 'mouseup';
        var dir = parts[1]; var speed = parts[2] || null;
        var deg = (dir == 'up') ? 90 : (dir == 'down') ? 270 : (dir == 'left') ? 180 : 0;

        jsEvent.add(linkEl, eType, function(e) { jsscrollObj.col[wndoId].initScrollVals(deg, speed); });
        jsEvent.add(linkEl, eAlt, function(e) { jsscrollObj.col[wndoId].ceaseScroll(); });

        if (eType == 'mouseover') {
            jsEvent.add(linkEl, 'mousedown', function(e) { jsscrollObj.col[wndoId].speed *= 3; });
            jsEvent.add(linkEl, 'mouseup', function(e) {
                jsscrollObj.col[wndoId].speed = jsscrollObj.prototype.speed;
            });
        }
        jsEvent.add(linkEl, 'click', function(e) { if (e && e.preventDefault) e.preventDefault(); return false; });
    }
}
// scrollToId_smile, scrollToId_smile_100, scrollToId_smile_lyr1_100    
jsscrollObj.handleScrollToId = function(linkEl, wndoId, cls) {
    var parts = cls.split('_'); var id = parts[1], lyrId, dur;
    if (parts[2]) {
        if (isNaN(parseInt(parts[2]))) {
            lyrId = parts[2];
            dur = (parts[3] && !isNaN(parseInt(parts[3]))) ? parseInt(parts[3]) : null;
        } else {
            dur = parseInt(parts[2]);
        }
    }
    jsEvent.add(linkEl, 'click', function(e) {
        jsscrollObj.scrollToId(wndoId, id, lyrId, dur);
        if (e && e.preventDefault) e.preventDefault();
        return false;
    });
}
// doesn't checks if lyrId in wndo, el in lyrId
jsscrollObj.scrollToId = function(wndoId, id, lyrId, dur) {
    var wndo = jsscrollObj.col[wndoId];
    var el = document.getElementById(id);
    if (el) {
        if (lyrId) {
            if (document.getElementById(lyrId) && wndo.lyrId != lyrId) {
                wndo.load(lyrId);
            }
        }
        var lyr = document.getElementById(wndo.lyrId);
        var x = jsgetLayerOffset(el, lyr, 'left');
        var y = jsgetLayerOffset(el, lyr, 'top');
        wndo.initScrollToVals(x, y, dur);
    }
}
jsscrollObj.getEv_FnType = function(str) {
    var re = /^(mouseover|mousedown|scrollBy|scrollTo|scrollToId|click)$/;
    if (re.test(str)) {
        return str;
    }
    return '';
}

// return class name with underscores in it 
jsscrollObj.get_DelimitedClass = function(cls) {
    if (cls.indexOf('_') == -1) {
        return '';
    }
    var whitespace = /\s+/;
    if (!whitespace.test(cls)) {
        return cls;
    } else {
        var classes = cls.split(whitespace);
        for (var i = 0; classes[i]; i++) {
            if (classes[i].indexOf('_') != -1) {
                return classes[i];
            }
        }
    }
}
jsscrollObj.handleControlVis = function(controlsId, wndoId, axis) {
    var wndo = jsscrollObj.col[wndoId];
    var el = document.getElementById(controlsId);
    if ((axis == 'v' && wndo.maxY > 0) || (axis == 'h' && wndo.maxX > 0)) {
        el.style.visibility = 'visible';
    } else {
        el.style.visibility = 'hidden';
    }
}
function navTo(goLocationLeft, goLocationRight, find, replace) {
    //add back in http and .aspx so it is a proper link
    temp = 'http:' + goLocationLeft + '.aspx' + goLocationRight;

    //replace chars
    while (temp.indexOf(find) > -1) {
        pos = temp.indexOf(find);
        temp = "" + (temp.substring(0, pos) + replace +
                    temp.substring((pos + find.length), temp.length));
    }
    window.location.href = (temp);
}


//**************************************************************************
//

function setCoremetricsItem(iPID, iCategoryID, iItemType, anchor) {
    var href = $(anchor).attr("href");
    var data = "{ productID:" + iPID + ", itemType:" + iItemType + ", categoryID:" + iCategoryID + " }"
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/ws/Ajax/Coremetrics.asmx/CoremetricsAddCartItem",
        data: data,
        dataType: "json",
        success: function(msg) {

            //FIRST REMOVE ONCLICK BEFORE RE-CLICKING THE ANCHOR
            $(anchor).removeAttr("onclick");

            if (navigator.appName == 'Microsoft Internet Explorer') {
                //WORKS IN IE ONLY  
                anchor.click();
            }
            else {
                ////CAUSES US TO LOSE REFERRER IN IE ONLY WHICH IS NEEDED FOR BREADCRUMBS ON PRODUCT PAGE
                window.location = $(anchor).attr("href");           
            }

            ////TRIGGERS AN ONCLICK EVENT NOT A MOUSE CLICK EVENT
            //var evt = this.ownerDocument.createEvent('MouseEvents');
            //evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
            //this.dispatchEvent(evt);

            //TRIGGERS AN ONCLICK EVENT NOT A MOUSE CLICK EVENT
            //$("[href=" + $(anchor).attr("href") + "]").trigger('click');


        }
    });
}
