
// From /Scripts/PopupWindow.js

	function ShowDiv(divName)
	{
        var div = document.getElementById(divName);
        if (div){
		    div.style.display = "block";
            div.style.visibility = "visible";
        }
	}	
	function ShowInlineDiv(divName)
	{
        var div = document.getElementById(divName);
        if (div){
		    div.style.display = "inline"; 
        }
	}	
	function HideDiv(divName)
	{
        var div = document.getElementById(divName);
        if (div){
		    div.style.display = "none";             
        }
	}
	
function ShowCatalog(vendor,catalog,aLink){ 
    var popupUrl = "/Catalog/" + vendor + "/" + catalog + "/popup.html";
    aLink.name = aLink.id;
    return ClickHandler(popupUrl,350,300,aLink.id,null);
}

// Use this on Stock Popups to enable popups  
// to show a catlog popup add this line to the catalog A tag onclick='return ShowStock("CHD","CH120",this);'
function ShowStock(vendor,catalog,aLink){ 
    var popupUrl = "/Catalog/" + vendor + "/" + catalog + "/stock.html";
    aLink.name = aLink.id;
    return ClickHandler(popupUrl,250,500,aLink.id,null);
}

function HideById(id) {
    var idTag = document.getElementByTagId("input");
    if (idTag) {
        idTag.style.display = "hidden";
    }
}

function ShowById(id) {
    var idTag = document.getElementByTagId("input");
    if (idTag) {
        idTag.style.display = "block";
    }
}

function ToggleById(idHide,idShow) {
    ShowById(idShow);
    HideById(idHide);
}


// Use this on hrefs to open a new window.
function ClickHandler(url,pWidth,pHeight,pAnchor,divName){
    var newin;
    if (divName)
    {
        newin = new PopupWindow(divName);
    }
    else
    {
        newin = new PopupWindow();
    }
    //alert(this.name);
    newin.setSize(pWidth,pHeight);
    newin.setUrl(url);
    newin.showPopup(pAnchor);
    newin.autoHide(); 
    return false;
    }

// Set the position of the popup window based on the anchor
function PopupWindow_getXYPosition(anchorname) {
	var coordinates;
	if (this.type == "WINDOW") {
		coordinates = getAnchorWindowPosition(anchorname);
		}
	else {
		coordinates = getAnchorPosition(anchorname);
		}
	this.x = coordinates.x;
	this.y = coordinates.y;
	}
// Set width/height of DIV/popup window
function PopupWindow_setSize(width,height) {
	this.width = width;
	this.height = height;
	}
// Fill the window with contents
function PopupWindow_populate(contents) {
	this.contents = contents;
	this.populated = false;
	}
// Set the URL to go to
function PopupWindow_setUrl(url) {
	this.url = url;
	}
// Set the window popup properties
function PopupWindow_setWindowProperties(props) {
	this.windowProperties = props;
	}
// Refresh the displayed contents of the popup
function PopupWindow_refresh() {
	if (this.divName != null) {
		// refresh the DIV object
		if (this.use_gebi) {
			document.getElementById(this.divName).innerHTML = this.contents;
			}
		else if (this.use_css) { 
			document.all[this.divName].innerHTML = this.contents;
			}
		else if (this.use_layers) { 
			var d = document.layers[this.divName]; 
			d.document.open();
			d.document.writeln(this.contents);
			d.document.close();
			}
		}
	else {
		if (this.popupWindow != null && !this.popupWindow.closed) {
			if (this.url!="") {
				this.popupWindow.location.href=this.url;
				}
			else {
				this.popupWindow.document.open();
				this.popupWindow.document.writeln(this.contents);
				this.popupWindow.document.close();
			}
			this.popupWindow.focus();
			}
		}
	}
// Position and show the popup, relative to an anchor object
function PopupWindow_showPopup(anchorname) {
	this.getXYPosition(anchorname);
	this.x += this.offsetX;
	this.y += this.offsetY;
	if (!this.populated && (this.contents != "")) {
		this.populated = true;
		this.refresh();
		}
	if (this.divName != null) {
		// Show the DIV object
		if (this.use_gebi) {
            document.getElementById(this.divName).style.position = "absolute";
			document.getElementById(this.divName).style.left = this.x + "px";
			document.getElementById(this.divName).style.top = this.y + "px";
			document.getElementById(this.divName).style.visibility = "visible";
            document.getElementById(this.divName).style.display = "block";
			}
		else if (this.use_css) {
            document.all[this.divName].style.position = "absolute";
			document.all[this.divName].style.left = this.x;
			document.all[this.divName].style.top = this.y;
			document.all[this.divName].style.visibility = "visible";
            document.all[this.divName].style.display = "block";
			}
		else if (this.use_layers) {
            document.layers[this.divName].style.position = "absolute";
			document.layers[this.divName].left = this.x;
			document.layers[this.divName].top = this.y;
			document.layers[this.divName].visibility = "visible";
            document.layers[this.divName].style.display = "block";
			}
		}
	else {
		if (this.popupWindow == null || this.popupWindow.closed) {
			// If the popup window will go off-screen, move it so it doesn't
			if (this.x<0) { this.x=0; }
			if (this.y<0) { this.y=0; }
			if (screen && screen.availHeight) {
				if ((this.y + this.height) > screen.availHeight) {
					this.y = screen.availHeight - this.height;
					}
				}
			if (screen && screen.availWidth) {
				if ((this.x + this.width) > screen.availWidth) {
					this.x = screen.availWidth - this.width;
					}
				}
			var avoidAboutBlank = window.opera || ( document.layers && !navigator.mimeTypes['*'] ) || navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );
			this.popupWindow = window.open(avoidAboutBlank?"":"about:blank","window_"+anchorname,this.windowProperties+",width="+this.width+",height="+this.height+",screenX="+this.x+",left="+this.x+",screenY="+this.y+",scrollbars=yes,top="+this.y+"");
			}
		this.refresh();
		}
	}
// Hide the popup
function PopupWindow_hidePopup() {
	if (this.divName != null) {
		if (this.use_gebi) {
			document.getElementById(this.divName).style.visibility = "hidden";
			}
		else if (this.use_css) {
			document.all[this.divName].style.visibility = "hidden";
			}
		else if (this.use_layers) {
			document.layers[this.divName].visibility = "hidden";
			}
		}
	else {
		if (this.popupWindow && !this.popupWindow.closed) {
			this.popupWindow.close();
			this.popupWindow = null;
			}
		}
	}
// Pass an event and return whether or not it was the popup DIV that was clicked
function PopupWindow_isClicked(e) {
	if (this.divName != null) {
		if (this.use_layers) {
			var clickX = e.pageX;
			var clickY = e.pageY;
			var t = document.layers[this.divName];
			if ((clickX > t.left) && (clickX < t.left+t.clip.width) && (clickY > t.top) && (clickY < t.top+t.clip.height)) {
				return true;
				}
			else { return false; }
			}
		else if (document.all) { // Need to hard-code this to trap IE for error-handling
			var t = window.event.srcElement;
			while (t.parentElement != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentElement;
				}
			return false;
			}
		else if (this.use_gebi && e) {
			var t = e.originalTarget;
			while (t.parentNode != null) {
				if (t.id==this.divName) {
					return true;
					}
				t = t.parentNode;
				}
			return false;
			}
		return false;
		}
	return false;
	}

// Check an onMouseDown event to see if we should hide
function PopupWindow_hideIfNotClicked(e) {
	if (this.autoHideEnabled && !this.isClicked(e)) {
		this.hidePopup();
		}
	}
// Call this to make the DIV disable automatically when mouse is clicked outside it
function PopupWindow_autoHide() {
	this.autoHideEnabled = true;
	}
// This global function checks all PopupWindow objects onmouseup to see if they should be hidden
function PopupWindow_hidePopupWindows(e) {
	for (var i=0; i<popupWindowObjects.length; i++) {
		if (popupWindowObjects[i] != null) {
			var p = popupWindowObjects[i];
			p.hideIfNotClicked(e);
			}
		}
	}
// Run this immediately to attach the event listener
function PopupWindow_attachListener() {
	if (document.layers) {
		document.captureEvents(Event.MOUSEUP);
		}
	window.popupWindowOldEventListener = document.onmouseup;
	if (window.popupWindowOldEventListener != null) {
		document.onmouseup = new Function("window.popupWindowOldEventListener(); PopupWindow_hidePopupWindows();");
		}
	else {
		document.onmouseup = PopupWindow_hidePopupWindows;
		}
	}
// CONSTRUCTOR for the PopupWindow object
// Pass it a DIV name to use a DHTML popup, otherwise will default to window popup
function PopupWindow() {
	if (!window.popupWindowIndex) { window.popupWindowIndex = 0; }
	if (!window.popupWindowObjects) { window.popupWindowObjects = new Array(); }
	if (!window.listenerAttached) {
		window.listenerAttached = true;
		PopupWindow_attachListener();
		}
	this.index = popupWindowIndex++;
	popupWindowObjects[this.index] = this;
	this.divName = null;
	this.popupWindow = null;
	this.width=0;
	this.height=0;
	this.populated = false;
	this.visible = false;
	this.autoHideEnabled = false;
	
	this.contents = "";
	this.url="";
	this.windowProperties="toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable,alwaysRaised,dependent,titlebar=no";
	if (arguments.length>0) {
		this.type="DIV";
		this.divName = arguments[0];
		}
	else {
		this.type="WINDOW";
		}
	this.use_gebi = false;
	this.use_css = false;
	this.use_layers = false;
	if (document.getElementById) { this.use_gebi = true; }
	else if (document.all) { this.use_css = true; }
	else if (document.layers) { this.use_layers = true; }
	else { this.type = "WINDOW"; }
	this.offsetX = 0;
	this.offsetY = 0;
	// Method mappings
	this.getXYPosition = PopupWindow_getXYPosition;
	this.populate = PopupWindow_populate;
	this.setUrl = PopupWindow_setUrl;
	this.setWindowProperties = PopupWindow_setWindowProperties;
	this.refresh = PopupWindow_refresh;
	this.showPopup = PopupWindow_showPopup;
	this.hidePopup = PopupWindow_hidePopup;
	this.setSize = PopupWindow_setSize;
	this.isClicked = PopupWindow_isClicked;
	this.autoHide = PopupWindow_autoHide;
	this.hideIfNotClicked = PopupWindow_hideIfNotClicked;
	}

	
// From /Scripts/AnchorPosition.js

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found===0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
    if (el) {
    	var ol=el.offsetLeft;
	    while ((el=el.offsetParent) !== null) { ol += el.offsetLeft; }
	    return ol;
        }
    else {
        return 100;
        }
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	

function AnchorPosition_getPageOffsetTop (el) {
    if (el) {
	    var ot=el.offsetTop;
	    while((el=el.offsetParent) !== null) { ot += el.offsetTop; }
	    return ot;
        }
    else {
        return 100;    
        }
    }
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

	
// From /Scripts/Cart.js

var divOrder = null;
var divCart = null;
var divCartTotal = null;

function HandleEnter(e,btn){
    if (!e) var e = window.event;
        
    if (e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13)) 
        {
            var btnTag=document.getElementById(btn);
            if (btnTag)
            {
                btnTag.focus();
                btnTag.click();
            }
            return false;
        }
    } 
    else 
    {
        return true;
    }
}

function HandleNextTextBox(e,txt){
    if (!e) var e = window.event;
        
    if (e.which || e.keyCode)
    {
        if ((e.which == 13) || (e.keyCode == 13)) 
        {
            var txtTag=document.getElementById(txt);
            if (txtTag)
            {
                txtTag.focus();
            }
            return false;
        }
    } 
    else 
    {
        return true;
    }
}

function DisableEnter(e)
{
       if (!e) var e = window.event;
        
        if (e.which || e.keyCode)
        {
            if ((e.which == 13) || (e.keyCode == 13)) 
            {
                e.cancelBubble = true;
	            if (e.stopPropagation) e.stopPropagation();
                return false;
            }
        } 
        else 
        {
            return true;
        }
}

function LoadDefaultButtons()
{
    if (document.addEventListener) {
        document.addEventListener("keypress", DisableEnter, true);
    } else if (document.attachEvent) {
        window.attachEvent('onkeydown', DisableEnter);
    } else {
        if (document.onkeydown)
        {
            var oldkeydown = document.onkeydown;
            document.onkeydown = function() { if ( DisableEnter()) { return oldkeydown(); } else { return false; } };
        } else {
            document.onkeydown = DisableEnter;
        }
    }
    
    var x=document.getElementsByTagName('input');
    for (var i=0;i<x.length;i++)
    {
        if (x[i].getAttribute("defaultbutton"))
        {
            x[i].onkeydown = new Function("event","{return HandleEnter(event,'" + x[i].getAttribute("defaultbutton") + "');}");    
            
        }
        if (x[i].getAttribute("nexttextbox"))
        {
            x[i].onkeydown = new Function("event","{return HandleNextTextBox(event,'" + x[i].getAttribute("nexttextbox") + "');}");    
        }
    }
}


function Add2Cart() {
    var inputTags = document.getElementsByTagName("input");
    var cartTag = document.getElementById("CartStore");
    var inputTag;
    var arrayIndex;
    var tagName;
    var strCatalog, strVendor;
    var intPos;
    var postData = new Object();
    var oServer = new ServerRequest();
    var itemCount = 0;
    var btnCart = document.getElementById("btnCart");

    if (btnCart)
    {
        btnCart.oldValue =btnCart.value;
        btnCart.value="Adding Items...";
        btnCart.disabled="disabled";
    }
    
    loadDivVars();
    
    showCartLoading();
    
    // Search through all the input boxes on the page
    for (var arrayIndex=0;arrayIndex<inputTags.length;arrayIndex++) {
        inputTag = inputTags[arrayIndex];
        if (inputTag.getAttribute("type").toLowerCase() == "text"){
            tagName = inputTag.getAttribute("name");
            if (tagName && tagName.substring) {
                if (tagName.substring(0,7).toLowerCase() == "cart--|"){
                    //found tag with name starting with "cart--"
                    var qnty = inputTag.value+0;
                    var intMby = inputTag.getAttribute("multiplyby");
                    var intMof = inputTag.getAttribute("multiplesof");
                    if (intMby)  qnty * intMby;
                    if (intMof && (qnty % intMof) != 0)  
                    {
                        alert("Invalid Quantity");
                        return 
                    }
                    inputTag.getAttribute("name");
                    postData[tagName] = inputTag.value;
                    inputTag.value = "";
                    itemCount += 1;
                }
            }
        }
    }
    
    if (itemCount > 0) {
        postData.ItemCount = itemCount + ' '    // Load Item count for request
        postData.Store = cartTag.value;         // Load hidden store field
        oServer.OnComplete = ChartCallBack;     // set function to handle completed request
        oServer.OnError = ChartCallBackError;   // set function to handle error
        oServer.SendPostRequest("/Checkout/add2Chart.aspx",postData); //Send Request
    }
    return false;
}

function ChartCallBackError(status, statusText, responseText){
    
    loadDivVars();
    deleteTableRows(divCart);
    
    addTableRows(divCart, [["&nbsp;"],["<div class='smallred'>&nbsp;&nbsp;Error Loading Item!</div>"],["&nbsp;"]]  ,0);

    document.close();
    document.write(responseText);
    document.close();
    //window.alert(status + ' ' + statusText + '\n'+ responseText);

}

function ChartCallBack(serverResponse){
    
    var objReturn;
    
    loadDivVars();
    
    objReturn = serverResponse.parseJSON();
    
    deleteTableRows(divCart);
    
    if (objReturn && objReturn.errors)
    {
        alert(objReturn.errors);
    }
    
    //Add rows using array literal
    if (objReturn && objReturn.total && objReturn.items) {
        addTableRows(divCart, objReturn.items , 0);
        for( var rowSub = 0; rowSub < divCart.tBodies[0].rows.length; rowSub++ ) {
            divCart.tBodies[0].rows[rowSub].cells[0].setAttribute("width","30px");
            divCart.tBodies[0].rows[rowSub].cells[0].setAttribute("align","right");
            divCart.tBodies[0].rows[rowSub].cells[0].innerHTML = divCart.tBodies[0].rows[rowSub].cells[0].innerHTML + "&nbsp;";
            divCart.tBodies[0].rows[rowSub].cells[1].innerHTML = "&nbsp;" + divCart.tBodies[0].rows[rowSub].cells[1].innerHTML;
        }
        
        divCartTotal.innerHTML = objReturn.total;
        addTableRows(divCart, [['&nbsp;','<a href="/Checkout/cart.aspx">View All Items</a>']], 0);
    } else {
        addTableRows(divCart, [[serverResponse.Text()]] , 0);
        //addTableRows(divCart, [["&nbsp;"],["<div class='smallred'>&nbsp;&nbsp;Error Loading Cart!</div>"],["&nbsp;"]]  ,0);
    }
    
    var btnCart = document.getElementById("btnCart");
    if (btnCart)
    {
        btnCart.value=btnCart.oldValue;
        btnCart.disabled=null;
    }
}

function loadDivVars(){
    if (isNull(divOrder)){
        divOrder = document.getElementById("order");
        if (isNull(divOrder) && window.parent){
            divOrder = window.opener.document.getElementById("order");
        }
    }
    
    if (isNull(divCart)){
       divCart = document.getElementById("tblCart");
       if (isNull(divCart) && window.parent){
            divCart = window.opener.document.getElementById("tblCart");
        }
    }
    
    if(isNull(divCartTotal)) {
        divCartTotal = document.getElementById("CartTotal");
        if (isNull(divCartTotal) && window.parent){
            divCartTotal = window.opener.document.getElementById("CartTotal");
        }
    }
}

function showCartLoading(){
    divOrder.style.display = "block";
        
    deleteTableRows(divCart);
    
    addTableRows(divCart, [["&nbsp;"],["<div class='instructions'>&nbsp;&nbsp;Loading Items...</div>"],["&nbsp;"]] ,0);
    
    divCartTotal.innerHTML = "?.??";
}

function deleteTableRows(theTable) {
    if (theTable && theTable.tBodies[0]) {
        for( var rowSub = theTable.tBodies[0].rows.length - 1; rowSub >= 0; rowSub-- ) {
            theTable.tBodies[0].deleteRow(rowSub);
	    }
    }
}

//theTable - <table> tag elements
//rows - multi-dem array ie row[0][1] is the first row second column
//tBodiesSub index into theTable.tBodies, usually == 0
function addTableRows(theTable, rows, tBodiesSub) {
    if (rows.length) {
        for( var rowSub = 0; rowSub < rows.length; rowSub++ ) {
            if (rows[rowSub].length) {
                var newRow = theTable.ownerDocument.createElement('tr')
                
                
                for( var colSub = 0; colSub < rows[rowSub].length; colSub++ ) {
                    var newCol = theTable.ownerDocument.createElement('td');
                    newCol.innerHTML = rows[rowSub][colSub];
                    newRow.appendChild(newCol);
                }
                
                if (theTable.tBodies[tBodiesSub]) {
                    theTable.tBodies[tBodiesSub].appendChild(newRow);    
                }else {
                    if (!(theTable.tBodies[0])) {
                        theTable.appendChild(theTable.ownerDocument.createElement("TBODY"));
                    }
                    theTable.tBodies[0].appendChild(newRow);    
                }
            }
        }
    }
}


function isNull(a) {
    return typeof a == 'object' && !a;
}

// From /Scripts/ServerRequest.js



function ServerRequest() {
  this.Init();
}

ServerRequest.prototype.Init = function() {
  this.XmlHttp = this.GetHttpObject();
}

ServerRequest.prototype.TimerID = 0;
ServerRequest.prototype.TimeOutInterval = 20000;

ServerRequest.prototype.GetHttpObject = function() { 
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else @*/
  xmlhttp = false;
  /*@end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

ServerRequest.prototype.AbortCallBack = function() {
    if (this.TimerID != 0 )
	    window.clearTimeout(this.TimerID);
	if( this.XmlHttp )
		this.XmlHttp.abort();
}
 
ServerRequest.prototype.OnLoading = function() {
  // Loading
}
 
ServerRequest.prototype.OnLoaded = function() {
  // Loaded
}
 
ServerRequest.prototype.OnInteractive = function() {
  // Interactive
}
 
ServerRequest.prototype.OnComplete = function(serverResponse) {
  // Complete
}
 
ServerRequest.prototype.OnAbort = function() {
  // Abort
}
 
ServerRequest.prototype.OnError = function(status, statusText, responseText) {
  // Error
}

ServerRequest.prototype.TimeOut = function() {
  return this.OnError(0,"Connection Timed Out","");
}
 
ServerRequest.prototype.ReadyStateChange = function() {
  if( this.XmlHttp.readyState == 1 )
  {
    this.OnLoading();
  }
  else if( this.XmlHttp.readyState == 2 )
  {
    this.OnLoaded();
  }
  else if( this.XmlHttp.readyState == 3 )
  {
    this.OnInteractive();
  }
  else if( this.XmlHttp.readyState == 4 )
  {
    window.clearInterval(this.TimerID);
    if( this.XmlHttp.status == 0 )
      this.OnAbort();
    else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
      this.OnComplete(new ServerResponse(this.XmlHttp));
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
  }
}

ServerRequest.prototype.SendGetRequest = function(theUrl){

    this.AbortCallBack();
	if( this.XmlHttp )
	{		
		if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
		{
			var oThis = this;
			
            this.TimerID = window.setInterval(function(){ oThis.TimeOut(); }, this.TimeOutInterval);	
            
			this.XmlHttp.open('GET', theUrl, true);
			this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
			this.XmlHttp.send(null);
		}
        else
        {
            this.OnError(-2,"Request already in progress","");
        }
	}
    else
    {
        this.OnError(-1,"Not Supported","");
    }

}

ServerRequest.prototype.SendPostRequest = function(url,postData){

    this.AbortCallBack();
	
	if( this.XmlHttp )
	{		
		if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
		{
			var oThis = this;
			var strData = '';
            
            if( isString(postData) )
                strData = postData;
            else {
                var key;
                for (key in postData)
                {
                    strData += '&' + this.EncodePostData(key) + '=' + this.EncodePostData(postData[key]);
                }
                strData = strData.substring(1,strData.length);
            }
            
            this.TimerID = window.setInterval(function(){ oThis.TimeOut(); }, this.TimeOutInterval);	
            
			this.XmlHttp.open('POST', url, true);
			this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
			this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            this.XmlHttp.setRequestHeader('Content-length', strData.length );
			this.XmlHttp.send(strData);
		}
        else
        {
            this.OnError(-2,"Request already in progress","");
        }
	}
    else
    {
        this.OnError(-1,"Not Supported","");
    }
}

ServerRequest.prototype.EncodePostData = function(data)
{
	return data.split("%").join("%25").split("=").join("%3d").split("&").join("%26").split("+").join("%2b");
}


// ServerResponse Object

function ServerResponse(xmlHttp) {
  this.ResponseXML =  xmlHttp.responseXML;
  this.ResponseText =  xmlHttp.responseText;
}

ServerResponse.prototype.Xml = function () {
    return this.ResponseXML;
}

ServerResponse.prototype.Text = function () {
    return this.ResponseText;
}

ServerResponse.prototype.RunScript = function () {
    return eval(this.ResponseText);
}

ServerResponse.prototype.parseJSON = function () {
    /*try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                this.ResponseText.replace(/"(\\.|[^"\\])*"/g, ''))) &&
            eval('(' + this.ResponseText + ')');
    } catch (e) {
        return false;
    }
    */
    try {
        return eval('(' + this.ResponseText + ')');
    }catch (e) {
        return false;
    }
};


function isArray(a) {
    return (a && typeof a == 'object' && a.constructor == Array);
}

function isString(a) {
    return typeof a == 'string';
}



//From /Scripts/cookie.js

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// Orig from head element in master page

function runSearch() {
	$(location).attr('href', '/Catalog/search.aspx?Keyword=' + $("[id*=headerSearchBox]").val());
}

function runGetNewsletter() {
	$(location).attr('href', '/CatalogSignUp.aspx?Email=' + $("[id*=txtNewsletterSignup]").val());
}


// Orig from Stats programs

$(document).ready(function(){
  
  // From google analytics 
  // Ref: http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html
  var _gaq = window["_gaq"] || []; 
  _gaq.push(['_setAccount', 'UA-13049236-1']); 
  _gaq.push(['_setDomainName','.elliottelectric.com']);
  _gaq.push(['_trackPageview']);  
  window["_gaq"] = _gaq;
 
  (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); 
  })(); 
 
  
  //From awstats
  
  (function() { 
    var awstats = document.createElement('script'); awstats.type = 'text/javascript'; awstats.async = true; 
    awstats.src =  '/js/awstats_misc_tracker.js'; 
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(awstats); 
  })(); 
  
});


