	var http_request = false;
	var domDoc = false;
	var ModelPageIndex = 1;
	var PartPageIndex = 1;

	String.prototype.trim  =  function()  
	{  
		return this.replace(/(^\s*)|(\s*$)/g,"");  
	}

	function GetNodeValue(obj)
	{
		var str = "";
		if(window.XMLHttpRequest)		//Mozilla
		{
			try
			{
				str = obj.firstChild.nodeValue;
			}
			catch(ex)
			{
				str = "";
			}
		}
		else if(window.ActiveXObject)	//IE
		{
			str = obj.text;
		}
		return str;
	}
	
	function send_request(url) 
	{
		document.getElementById("ModelContainer").innerHTML = "";
		document.getElementById("PartContainer").innerHTML = "";
		document.getElementById("SystemTitleTable").style.display = "none";
		document.getElementById("PartTitleTable").style.display = "none";
		
		http_request = false;
		if(window.XMLHttpRequest)
		{ 
			//Mozilla
			http_request = new XMLHttpRequest();
			try
			{
				domDoc = document.implementation.createDocument("text/xml", "", null);
			
				XMLDocument.prototype.loadXML = function(xmlString)
				{
					var childNodes = this.childNodes;
					for (var i = childNodes.length - 1; i >= 0; i--)
						this.removeChild(childNodes[i]);
	
					var dp = new DOMParser();
					var newDOM = dp.parseFromString(xmlString, "text/xml");
					var newElt = this.importNode(newDOM.documentElement, true);
					this.appendChild(newElt);
				}
					
				XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
				{
					if( !xNode ) { xNode = this; } 
					var oNSResolver = this.createNSResolver(this.documentElement)
					var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
					XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
					var aResult = [];
					for( var i = 0; i < aItems.snapshotLength; i++)
					{
						aResult[i] =  aItems.snapshotItem(i);
					}
					return aResult;
				}
				
				Element.prototype.selectNodes = function(cXPathString)
				{
					if(this.ownerDocument.selectNodes)
					{
						return this.ownerDocument.selectNodes(cXPathString, this);
					}
					else{throw "For XML Elements Only";}
				}
				
				if (http_request.overrideMimeType) 
				{
					http_request.overrideMimeType("text/xml");
				}
			}
			catch(e)
			{
				try
				{
					domDoc = new ActiveXObject("MSXML2.DOMDocument");
				}
				catch(e)
				{
					domDoc = new ActiveXObject("Microsoft.XMLDOM"); 
				}
			}//add by 2007.2.14	
		}
		else if (window.ActiveXObject) 
		{ 
			// IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			    domDoc = new ActiveXObject("MSXML2.DOMDocument");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
					domDoc = new ActiveXObject("Microsoft.XMLDOM");
				} catch (e) {}
			}
		}
		if (!http_request) 
		{ 
			window.alert("Can't create XMLHttpRequest object!");
			return false;
		}
		http_request.onreadystatechange = processRequest;
		
		showProgress();
		
		http_request.open("GET", url, true);
		http_request.send(null);
		
	}
	
    function processRequest() {
        if (http_request.readyState == 4) 
        { 
            if (http_request.status == 200) 
            { 
                var xmlStr = http_request.responseText;
                domDoc.loadXML(xmlStr);
                
                if (domDoc.documentElement != null)
                {
					displayModelData(domDoc,1);
					displayModelPaging(domDoc);
					displayPartData(domDoc,1);
					displayPartPaging(domDoc);
                }
                
				hideProgress();
	
				if(document.getElementById("ModelContainer").innerHTML == "" && document.getElementById("PartContainer").innerHTML == "")
				{
					var noRecordInfo = "<table border=0 width='100%' height='100'>";
					noRecordInfo += "<tr>";
					noRecordInfo += "<td width='5%'>&nbsp;</td>";
					noRecordInfo += "<td valign='bottom'>";
					noRecordInfo += "<p align='center'><b>";
					noRecordInfo += "<span class='navtext6'>Sorry! Your keyword search did not return any results.<br><br><br>";
					noRecordInfo += "Please try your search again. Or click <a href='" + getContentSearchURL() + "'><font color='#005CAB'>here</font></a> to see the content results.";
					noRecordInfo += "</span></b></p>";
					noRecordInfo += "</td>";
					noRecordInfo += "<td width='5%'>&nbsp;</td>";
					noRecordInfo += "<tr>";
					noRecordInfo += "</table>";
					document.getElementById("SystemTitleTable").style.display = "none";
					document.getElementById("ModelPagingContainer_Top").style.display = "none";
					document.getElementById("ModelContainer").style.display = "none";
					document.getElementById("ModelPagingContainer_Bottom").style.display = "none";
					document.getElementById("PartTitleTable").style.display = "none";
					document.getElementById("PartPagingContainer_Top").style.display = "none";
					document.getElementById("PartPagingContainer_Bottom").style.display = "none";
					document.getElementById("PartContainer").innerHTML = noRecordInfo;
					document.getElementById("PartTitleTable").style.display = "";
					document.getElementById("PartTitle").style.display = "none";
				}
				else
				{
					if (document.getElementById("ModelContainer").innerHTML == "")
					{
						document.getElementById("SystemTitleTable").style.display = "none";
						document.getElementById("ModelPagingContainer_Top").style.display = "none";
						document.getElementById("ModelContainer").style.display = "none";
						document.getElementById("ModelPagingContainer_Bottom").style.display = "none";
					}
					else
					{
						document.getElementById("SystemTitleTable").style.display = "";
						document.getElementById("ModelPagingContainer_Top").style.display = "";
						document.getElementById("ModelContainer").style.display = "";
						document.getElementById("ModelPagingContainer_Bottom").style.display = "";
					}
					if (document.getElementById("PartContainer").innerHTML == "")
					{
						document.getElementById("PartTitleTable").style.display = "none";
						document.getElementById("PartPagingContainer_Top").style.display = "none";
						document.getElementById("PartContainer").style.display = "none";
						document.getElementById("PartPagingContainer_Bottom").style.display = "none";
					}
					else
					{
						document.getElementById("PartTitleTable").style.display = "";
						document.getElementById("PartPagingContainer_Top").style.display = "";
						document.getElementById("PartContainer").style.display = "";
						document.getElementById("PartPagingContainer_Bottom").style.display = "";
					}
				}
            } 
			else
			{ 
				hideProgress();
                //alert("Searching aborted,please check the keywords which your inputs.");
					var noRecordInfo = "<table border=0 width='100%' height='100'>";
					noRecordInfo += "<tr>";
					noRecordInfo += "<td width='5%'>&nbsp;</td>";
					noRecordInfo += "<td valign='bottom'>";
					noRecordInfo += "<p align='center'><b>";
					noRecordInfo += "<span class='navtext6'>Sorry! Your keyword search did not return any results.<br><br><br>";
					noRecordInfo += "Please try your search again. Or click <a href='" + getContentSearchURL() + "'><font color='#005CAB'>here</font></a> to see the content results.";
					noRecordInfo += "</span></b></p>";
					noRecordInfo += "</td>";
					noRecordInfo += "<td width='5%'>&nbsp;</td>";
					noRecordInfo += "<tr>";
					noRecordInfo += "</table>";
					document.getElementById("SystemTitleTable").style.display = "none";
					document.getElementById("ModelPagingContainer_Top").style.display = "none";
					document.getElementById("ModelContainer").style.display = "none";
					document.getElementById("ModelPagingContainer_Bottom").style.display = "none";
					document.getElementById("PartTitleTable").style.display = "none";
					document.getElementById("PartPagingContainer_Top").style.display = "none";
					document.getElementById("PartPagingContainer_Bottom").style.display = "none";
					document.getElementById("PartContainer").innerHTML = noRecordInfo;
					document.getElementById("PartTitleTable").style.display = "";
					document.getElementById("PartTitle").style.display = "none";
            }
        }
    }
    
    function displayModelData(domObject,pageindex)
    {
		var displayHTML = "";

		var items = domObject.documentElement.selectNodes("/SearchResults/ModelResults/Model");
		
		var endPoint = pageindex * PageSize;
		var startPoint = endPoint - PageSize;
		if (endPoint > items.length)
		{
			endPoint = items.length;
			startPoint = endPoint - (items.length%PageSize);
		}
		
		for (var i = startPoint;i < endPoint; i++)
		{
			var item = items[i];
		    displayHTML += GetNodeValue(item.getElementsByTagName("Title")[0]);
		}
		document.getElementById("ModelContainer").innerHTML = displayHTML;
    }
    
    function displayPartData(domObject,pageindex)
    {
		var displayHTML = "";
		var items = domObject.documentElement.selectNodes("/SearchResults/PartResults/Item");
		
		var endPoint = pageindex * PageSize;
		var startPoint = endPoint - PageSize;
		if (endPoint > items.length)
		{
			endPoint = items.length;
			startPoint = endPoint - (items.length%PageSize);
		}
		
		for (var i = startPoint; i < endPoint; i++)
		{
			var item = items[i];
			
			displayHTML += "<form name='form1' method='post' action='../app/cartplus.asp'>";
			displayHTML += " <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
			displayHTML += "<tr> ";
            displayHTML += "<td height='63'> <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            displayHTML += "<tr>";
            displayHTML += "<td width='100' valign='top' align='center'>";
            
            if (GetNodeValue(item.getElementsByTagName("ImageName")[0]).toUpperCase().indexOf(item.getAttribute("ItemNumber").toUpperCase()+"-01.GIF") == "-1")
            {
                displayHTML += "<a href=\"JavaScript:openWindowL('ViewItem.asp?itemNumber=";
				displayHTML += item.getAttribute("ItemNumber");
				displayHTML += "&section=1&image="+GetNodeValue(item.getElementsByTagName("ImageName")[0])+"')\"><img src='";
				displayHTML += ComNameImageSite+item.getAttribute("ItemNumber")+".jpg' border='0' ></a>";
            }
            
            displayHTML += "</td>";
            displayHTML += "<td width='500'> <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            displayHTML += "<tr>";
            displayHTML += "<td valign='top'><font face='Verdana, Arial, Helvetica, sans-serif' size='2'>";
            
            var WebDescription = GetNodeValue(item.getElementsByTagName("WebDescription")[0]);
            var BulletDescription = GetNodeValue(item.getElementsByTagName("BulletDescription")[0]);
            var LongDescription = GetNodeValue(item.getElementsByTagName("LongDescription")[0]);
            if (WebDescription != "")
            {
				displayHTML += WebDescription + "<br><br>";
				displayHTML += BulletDescription;
            }
            else
            {
                displayHTML += LongDescription.replace(/<b>/g,"").replace(/<\/b>/g,"").replace(/<B>/g,"").replace(/<\/B>/g,"");
            }
            
            displayHTML += " <font color='#005CAB' size=1>";
            if (GetNodeValue(item.getElementsByTagName("ManufacturerPartsNumber")[0]) != "")
            {
                displayHTML += "<br><br>(Part#:" + GetNodeValue(item.getElementsByTagName("ManufacturerPartsNumber")[0]) + ")";
            }
            
            displayHTML += "<br>(Item#:ABS" + item.getAttribute("ItemNumber").replace(/[-]/g,"") + ")" + getRating(GetNodeValue(item.getElementsByTagName("Rating")[0]));
            
            if (parseInt(GetNodeValue(item.getElementsByTagName("RatingCount")[0])) > 0)
            {
                displayHTML += "<font color='#000000' size=1>avg rating out of "+GetNodeValue(item.getElementsByTagName("RatingCount")[0])+" voters</font>";
            }
            displayHTML += "</font><font size='1'>";
            displayHTML += "<input type='hidden' name='Homepage' value='catalog.asp'>";
            displayHTML += "</font>";
            displayHTML += "<input type='hidden' name='Qty' value='1'>";
            displayHTML += "<input type='hidden' name='TYPE' value='PARTS'>";
            displayHTML += "<input type='hidden' name='ITEM' value='"+item.getAttribute("ItemNumber")+"'>";
            displayHTML += "</font></td>";
            displayHTML += "</tr>";
            displayHTML += "<tr>";
            displayHTML += "<td> <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            displayHTML += "<tr>";
            displayHTML += "<td height='5'><img src='../images/clear_dot.gif' width='1' height='1'></td>";
            displayHTML += "</tr>";
            displayHTML += "<tr>";
            displayHTML += "<td bgcolor='#000000'> <table width='100%' border='0' cellspacing='1' cellpadding='0'>";
            displayHTML += "<tr> ";
            displayHTML += "<td valign='top' width='30%' height='6' bgcolor='#FFFFFF' class='leftbar3'>";
            displayHTML += "<div align='center'><b><font color='#005CAB'>Price:$"+parseFloat(GetNodeValue(item.getElementsByTagName("NewEggUnitPrice")[0]))+"</font></b></div></td>";
            displayHTML += "<td valign='top' width='40%' height='6' bgcolor='#FFFFFF' class='leftbar3'>";
            displayHTML += "<div align='center'><b><font color='005CAB'>";
            
            var shippingCharge = parseFloat(GetNodeValue(item.getElementsByTagName("ShippingCharge")[0]));
            if (shippingCharge > 0.10)
            {
                 displayHTML += "UPS 3 Days Shipping $" + shippingCharge;
            }
            else if (shippingCharge == 0.01)
            {
				displayHTML += "Free UPS 3 Days Shipping";
            }
			else
			{
				displayHTML += "UPS 3 Days Shipping";
			}
			displayHTML += "</font></b></div></td>";
            displayHTML += "<td bgcolor='#FFFFFF' class='leftbar3' width='30%'>";
            displayHTML += "<div align='center'><b><font color='#005CAB'>In";
            displayHTML += "Stock: ";
            if (parseInt(GetNodeValue(item.getElementsByTagName("w_avail")[0])) > 0)
            {
                displayHTML += "Yes";
            }
            else
            {
                displayHTML += "No";
            }
            
            displayHTML += "</font> </b></div></td>";
            displayHTML += "</tr>";
            displayHTML += "</table></td>";
            displayHTML += "</tr>";
            displayHTML += "</table></td>";
            displayHTML += "</tr>";
            displayHTML += "<tr>";
            displayHTML += "<td height='5'><img src='../images/clear_dot.gif' width='1' height='1'></td>";
            displayHTML += "</tr>";
            displayHTML += "<tr>";
            displayHTML += "<td> <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            displayHTML += "<tr>";
            displayHTML += "<td valign='middle' class='rightbar1' width='401'>";
            
            if (GetNodeValue(item.getElementsByTagName("ImageName")[0]) != "")
            {
                displayHTML += "<a href=\"Javascript:openWindowL('ViewItem.asp?ItemNumber="
									+item.getAttribute("ItemNumber")
									+"&section=1&image="+GetNodeValue(item.getElementsByTagName("ImageName")[0])+"')\"><font color='#005CAB'>See It</font></a>";
            }
            
            if(GetNodeValue(item.getElementsByTagName("Hyperlink")[0]) != "")
            {
                var NewLink = GetNodeValue(item.getElementsByTagName("Hyperlink")[0]);
                if (NewLink.substring(NewLink.length-4,NewLink.length).toUpperCase() != "HTTP")
                {
                    NewLink="http://" + GetNodeValue(item.getElementsByTagName("Hyperlink")[0]).replace("http://","");
                }
                displayHTML += "<b>|</b> <a href='"+NewLink+"'  target=_blank><font color='#005CAB'>Manufacturer Link</font></a>";
            }
            
            if (GetNodeValue(item.getElementsByTagName("ReviewSign")[0]) == "Y")
            {
                displayHTML += "<b>|</b> <a href='"+WebSite+"../review/CustratingReview.asp?submit=read&type=item&Code="
									+item.getAttribute("ItemNumber")
									+")'><font color='#005CAB'>Customer Review</font></a>";
            }
            
           displayHTML += "</td>";
           displayHTML += "<td valign='right' width='99' align='right'>";
           displayHTML += "<input type='image' value='ADDPARTS' name='SUBMIT.ADDPARTS' src='"+WebSite+"/graphics/configure/add2cart.gif' border=0 width='95' height='29'>";                                   
           displayHTML += "</td>";
           displayHTML += "</tr>";
           displayHTML += "</table></td>";
           displayHTML += "</tr>";
           displayHTML += "</table></td>";
           displayHTML += "</tr>";
           displayHTML += "</table></td>";
           displayHTML += "</tr>";
		   displayHTML += "<tr>";
		   displayHTML += "<td class='dotline'> <!--hr size=1 width='100%'--> </td>";
		   displayHTML += "</tr>";
		   displayHTML += "</table>";
           displayHTML += "</form>";
		}
		document.getElementById("PartTitle").style.display = "";
		document.getElementById("PartContainer").innerHTML = displayHTML;
    }
	
	function setKeyWord(value)
	{
	    keyWord=value;
	}
	
	function DoRequest()
	{
		var url = SearchSite + "Search.aspx?sp-q="+escape(keyWord);
		send_request(url);
	}
	
	function KeySearch(evt)
	{
		if(window.XMLHttpRequest)		//Mozilla
		{
			if(evt.keyCode == 13)
			{
				if(document.getElementById('sp-q').value.trim()=='' || document.getElementById('sp-q').value.trim().toUpperCase()=='SEARCH')
				{
					alert("Need keywords!");
					return false;
				}
				if(SearchPage)
				{
					DoSearch();
					return false;
				}
				else
				{
					frmSearch.submit();
				}
			}
		}
		else if(window.ActiveXObject)	//IE
		{
			if(event.keyCode == 13)
			{
				if(document.getElementById('sp-q').value.trim()=='' || document.getElementById('sp-q').value.trim().toUpperCase()=='SEARCH')
				{
					alert("Need keywords!");
					return false;
				}
				if(SearchPage)
				{
					DoSearch();
					return false;
				}
				else
				{
					frmSearch.submit();
				}
			}
		}
		return true;
	}
	
	function DoSearch()
	{
		if(SearchPage)
		{
			setKeyWord(document.getElementById("sp-q").value);
	    	DoRequest();
			return false;
		}
		else
		{
			frmSearch.submit();
		}
		return true;
	}
	
    function displayModelPaging(domObject)
    {
		var displayHTML = "";
		
		var items = domObject.documentElement.selectNodes("/SearchResults/ModelResults/Model");
		var recordCount = items.length;
		var pageCount;
		if(recordCount > 0)
		{
			if (recordCount % PageSize == 0)
			{
				PageCount = recordCount/PageSize;
			}
			else
			{
				PageCount = parseInt(recordCount/PageSize) + 1;
			}
			if(recordCount>0 && PageCount>1)
			{
				displayHTML += "Page " + ModelPageIndex + " Of " + PageCount + " : ";
				if (ModelPageIndex > 1)
				{
					displayHTML += "<a href=# onclick='ModelPreviousClicked();'>Previous</a>";
				}
				for(var i = 1;i <= PageCount; i++)
				{
					if (i != ModelPageIndex)
					{
						displayHTML += "[<a href=# onclick='ModelIndexClicked("+i+");'>"+i+"</a>]";
					}
					else
					{
						displayHTML += " <b><font color='red'>" + i + "</font></b> ";
					}
				}
				if (ModelPageIndex < PageCount)
				{
					displayHTML += "<a href=# onclick='ModelNextClicked();'>Next</a>";
				}
			}
			document.getElementById("ModelPagingContainer_Top").innerHTML = displayHTML;
			document.getElementById("ModelPagingContainer_Bottom").innerHTML = displayHTML;
		}
    }
    
    function displayPartPaging(domObject)
    {
		var displayHTML = "";
		
		var items = domObject.documentElement.selectNodes("/SearchResults/PartResults/Item");
		var recordCount = items.length;
		var pageCount;
		if(recordCount > 0)
		{
			if (recordCount % PageSize == 0)
			{
				PageCount = recordCount/PageSize;
			}
			else
			{
				PageCount = parseInt(recordCount/PageSize) + 1;
			}
			
			if(recordCount>0 && PageCount>1)
			{
				displayHTML += "Page " + PartPageIndex + " Of " + PageCount + " : ";
				if (PartPageIndex > 1)
				{
					displayHTML += "<a href=# onclick='PartPreviousClicked();'>Previous</a>";
				}
				for(var i = 1;i <= PageCount; i++)
				{
					if (i != PartPageIndex)
					{
						displayHTML += "[<a href=# onclick='PartIndexClicked("+i+");'>"+i+"</a>]";
					}
					else
					{
						displayHTML += " <b><font color='red'>" + i + "</font></b> ";
					}
				}
				if (PartPageIndex < PageCount)
				{
					displayHTML += "<a href=# onclick='PartNextClicked();'>Next</a>";
				}
			}
			document.getElementById("PartPagingContainer_Top").innerHTML = displayHTML;
			document.getElementById("PartPagingContainer_Bottom").innerHTML = displayHTML;
		}
    }
    
	function ModelPreviousClicked()
	{
		SetModelPageIndex(GetModelPageIndex() - 1);
		displayModelPaging(domDoc);
		displayModelData(domDoc,GetModelPageIndex());
	}
	function ModelNextClicked()
	{
		SetModelPageIndex(GetModelPageIndex() + 1);
		displayModelPaging(domDoc);
		displayModelData(domDoc,GetModelPageIndex());
	}
	function ModelIndexClicked(pageindex)
	{
		SetModelPageIndex(pageindex);
		displayModelPaging(domDoc);
		displayModelData(domDoc,GetModelPageIndex());
	}
	function PartPreviousClicked()
	{
		SetPartPageIndex(GetPartPageIndex() - 1);
		displayPartPaging(domDoc);
		displayPartData(domDoc,GetPartPageIndex());
	}
	function PartNextClicked()
	{
		SetPartPageIndex(GetPartPageIndex() + 1);
		displayPartPaging(domDoc);
		displayPartData(domDoc,GetPartPageIndex());
	}
	function PartIndexClicked(pageindex)
	{
		SetPartPageIndex(pageindex);
		displayPartPaging(domDoc);
		displayPartData(domDoc,GetPartPageIndex());
	}
	
	function SetModelPageIndex(value)
	{
		ModelPageIndex = value;
	}
	function GetModelPageIndex()
	{
		return ModelPageIndex;
	}
	function SetPartPageIndex(value)
	{
		PartPageIndex = value;
	}
	function GetPartPageIndex()
	{
		return PartPageIndex;
	}
	
	function getRating(rating)
	{
		var starImage = "";
		if (rating != null && rating != "")
		{
			switch(parseInt(rating))
			{
				case 1:
					starImage="<img src='../graphics/browse/wave-1.gif' width='145' height='20'>";
					break;
				case 2:
					starImage="<img src='../graphics/browse/wave-2.gif' width='145' height='20'>";
					break;
				case 3:
					starImage="<img src='../graphics/browse/wave-3.gif' width='145' height='20'>";
					break;
				case 4:
					starImage="<img src='../graphics/browse/wave-4.gif' width='145' height='20'>";
					break;
				case 5:
					starImage="<img src='../graphics/browse/wave-5.gif' width='145' height='20'>";
					break;
			}
		}
		return starImage;
	}
	
	function getContentSearchURL()
	{
		return "searchcontent.asp?term=" + keyWord;
	}
	
	function showProgress()
	{
		var obj = document.getElementById("statusPic");
		var screenWidth = screen.availWidth;
		var screenHeight = screen.availHeight;
		var width = obj.lastChild.width;
		var height = obj.lastChild.height;
		
		var top = (screenHeight - height)/2-30;
		var left = (screenWidth - width)/2;
		
		obj.style.display = "";
		obj.style.position = "absolute";
		obj.style.top = top;
		obj.style.left = left;
		obj.style.zIndex = 100;
	}
	
	function hideProgress()
	{
		var obj = document.getElementById("statusPic");
		obj.style.display = "none";
	}