
function GetXmlHttpObject(handler)
{
   var objXMLHttp=null
   if (window.XMLHttpRequest)
   {
       objXMLHttp=new XMLHttpRequest()
   }
   else if (window.ActiveXObject)
   {
       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
   }
   return objXMLHttp
}

function stateChanged(divid, hideDiv, showDiv)
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
		var myobj = document.getElementById(divid);
		myobj.innerHTML= xmlHttp.responseText;
		if(xmlHttp.responseText!="" ){ // if query returns empty, show hideDiv and hide ShowDiv
			try{
				document.getElementById(hideDiv).style.visibility = "hidden";
			}
			catch(err){}
			try{
				document.getElementById(showDiv).style.visibility = "visible";
			}
			catch(err){}
		} else {
			try
			{
				document.getElementById(hideDiv).style.visibility = "visible";
			} catch(err){}
			try
			{
				document.getElementById(showDiv).style.visibility = "hidden";
			} catch(err){}
		}
   }
   else {
           //alert(xmlHttp.status);
   }
}

function stateChanged2(divid, hideDiv, showDiv)
{
   if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
   {
		var myobj = document.getElementById(divid);
		myobj.innerHTML= xmlHttp2.responseText;
		if(xmlHttp2.responseText!="" ){ // if query returns empty, show hideDiv and hide ShowDiv
			try{
				document.getElementById(hideDiv).style.visibility = "hidden";
			}
			catch(err){}
			try{
				document.getElementById(showDiv).style.visibility = "visible";
			}
			catch(err){}
		} else {
			try
			{
				document.getElementById(hideDiv).style.visibility = "visible";
			} catch(err){}
			try
			{
				document.getElementById(showDiv).style.visibility = "hidden";
			} catch(err){}
		}
   }
   else {
           //alert(xmlHttp.status);
   }
}

function stateChanged3(divid, hideDiv, showDiv)
{
   if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete")
   {
		var myobj = document.getElementById(divid);
		myobj.innerHTML= xmlHttp3.responseText;
		if(xmlHttp3.responseText!="" ){ // if query returns empty, show hideDiv and hide ShowDiv
			try{
				document.getElementById(hideDiv).style.visibility = "hidden";
			}
			catch(err){}
			try{
				document.getElementById(showDiv).style.visibility = "visible";
			}
			catch(err){}
		} else {
			try
			{
				document.getElementById(hideDiv).style.visibility = "visible";
			} catch(err){}
			try
			{
				document.getElementById(showDiv).style.visibility = "hidden";
			} catch(err){}
		}
   }
   else {
           //alert(xmlHttp.status);
   }
}

// Will populate data based on input
function htmlData(divid, url, qStr, showDiv, hideDiv)
// hideDiv will hide and showDiv will show when a result is returned. The opposite will happen if result set is empty
{
	var tmpStr;
   if (url.length==0)
   {
       document.getElementById(divid).innerHTML="";
       return;
   }

   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
   {
       alert ("Browser does not support HTTP Request");
       return;
   }
	 if (divid=="txtResult4")
	 {
		 var tmpobj;
		 tmpobj = document.getElementById("txtResult4");
		 tmpobj.innerHTML="";
	 }
	 if (divid=="txtResult3")
	 {
		 var tmpobj;
		 tmpobj = document.getElementById("txtResult3");
		 tmpobj.innerHTML="";
		 tmpobj = document.getElementById("txtResult4");
		 tmpobj.innerHTML="";
	 }
	tmpStr=qStr.substring(qStr.length-2);

	if (qStr.substring(qStr.length-2) =="=0") // no selection was made in the drop-down, don't process anything
	{
		return;
	}
	 
   url=url+"?"+qStr;
   url=url+"&sid="+Math.random();
   xmlHttp.onreadystatechange = function () { stateChanged(divid, hideDiv, showDiv); };
   xmlHttp.open("GET",url,true) ;
   xmlHttp.send(null);
}

function changeRanges(prodGrp){
   xmlHttp=GetXmlHttpObject()
	xmlHttp2=GetXmlHttpObject()
	xmlHttp3=GetXmlHttpObject()
   if (xmlHttp==null)
   {
       alert ("Browser does not support HTTP Request");
       return;
   }
   url="/includes/getHP.asp?pg="+prodGrp;
   url=url+"&sid="+Math.random();
   xmlHttp.onreadystatechange = function () { stateChanged('horsepower_range', ' ', ' '); };
   xmlHttp.open("GET",url,true) ;
   xmlHttp.send(null);

   url="/includes/getRPM.asp?pg="+prodGrp;
   url=url+"&sid="+Math.random();
   xmlHttp2.onreadystatechange = function () { stateChanged2('rpm_range', ' ', ' '); };
   xmlHttp2.open("GET",url,true) ;
   xmlHttp2.send(null);

   url="/includes/getFrame.asp?pg="+prodGrp;
   url=url+"&sid="+Math.random();
   xmlHttp3.onreadystatechange = function () { stateChanged3('frame_range', ' ', ' '); };
   xmlHttp3.open("GET",url,true) ;
   xmlHttp3.send(null);

}
