var http_request = false;
var http_request2 = false;

   function catRequest(unittype, make, typee, model, year, engine, mfg, autopop, count, reqtype) {
    url = 'cat.asp?UnitType=' + unittype + '&make=' + make + '&type=' + typee + '&model=' + model + '&year=' + year + '&engine=' + engine + '&mfg=' + mfg + '&ReqType=' + reqtype;

	  http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
          http_request.overrideMimeType('text/xml');
       }
      } else if (window.ActiveXObject) { // IE
       try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
       }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	
      http_request.onreadystatechange = function(){ catContents(unittype, make, typee, model, year, engine, mfg, autopop, count, reqtype) };

            document.getElementById(reqtype).innerHTML = "Refreshing...";
			
     http_request.open('GET', url, true);
     http_request.send(null);
   }

   function catContents(unittype, make, typee, model, year, engine, mfg, autopop, count, reqtype) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById(reqtype).innerHTML = result;
			
//			if (autopop == 1) {
//			autopopRequest(unittype, make, model, year, engine, mfg, autopop);

//				if (make == "Make") {
//				alert("Reseting results. Click OK and select a new Make.");
//				}
				
//			}
			
         } else {
            alert('There was a problem with the request -- catContents.');
         }
		
		if (count < 5) {
		catPopulate(unittype, make, typee, model, year, engine, mfg, autopop, count, reqtype)
		}
     }
	 
   }

   function catPopulate(unittype, make, typee, model, year, engine, mfg, autopop, count, reqtype) {
         
	if (reqtype == "Make") {
		if (!typee) { 
		document.getElementById('Type').innerHTML = "<img src=\"empty.gif\" width=\"0px\" onLoad=\"catRequest('"+unittype+"', '"+make+"', '"+typee+"', '"+model+"', '"+year+"', '"+engine+"', '"+mfg+"', 0, "+count+", 'Type');\" />";
		}
	}
		 
	else if (count == 1) {
	count+=1;

		if (count > 4) { }
		else {
		document.getElementById('Year').innerHTML = "<img src=\"empty.gif\" width=\"0px\" onLoad=\"catRequest('"+unittype+"', '"+make+"', '"+typee+"', '"+model+"', '"+year+"', '"+engine+"', '"+mfg+"', 0, "+count+", 'Year');\" />";
		}
	
	}

	else if (count == 2) {
	count+=1;

		if (count > 4) { }
		else {
		document.getElementById('Engine').innerHTML = "<img src=\"empty.gif\" width=\"0px\" onLoad=\"catRequest('"+unittype+"', '"+make+"', '"+typee+"', '"+model+"', '"+year+"', '"+engine+"', '"+mfg+"', 0, "+count+", 'Engine');\" />";
		}
	
	}

	else if (count == 3) {
	count+=1;

		if (count > 4) { }
		else {
		document.getElementById('Mfg').innerHTML = "<img src=\"empty.gif\" width=\"0px\" onLoad=\"catRequest('"+unittype+"', '"+make+"', '"+typee+"', '"+model+"', '"+year+"', '"+engine+"', '"+mfg+"', 0, "+count+", 'Mfg');\" />";
		}
	
	}

	else { 
	count+=1;
	
		if (!model) { 
		document.getElementById('Model').innerHTML = "<img src=\"empty.gif\" width=\"0px\" onLoad=\"catRequest('"+unittype+"', '"+make+"', '"+typee+"', '"+model+"', '"+year+"', '"+engine+"', '"+mfg+"', 0, "+count+", 'Model');\" />";
		}
	}
	
   }

   
////////////////

   function autopopRequest(unittype, make, typee, model, year, engine, mfg, autopop, limit) {
   document.getElementById('Sub').innerHTML = "Refreshing . . .";
   auto_url = 'cat_autopop.asp?AutoPop=' + autopop + '&UnitType=' + unittype + '&make=' + make + '&type=' + typee + '&model=' + model + '&year=' + year + '&engine=' + engine + '&mfg=' + mfg + '&r=' + limit;

	  http_request2 = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request2 = new XMLHttpRequest();
       if (http_request2.overrideMimeType) {
          http_request2.overrideMimeType('text/xml');
       }
      } else if (window.ActiveXObject) { // IE
       try {
          http_request2 = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             http_request2 = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {}
       }
      }
      if (!http_request2) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	
      http_request2.onreadystatechange = function(){ autopopContents(unittype, make, typee, model, year, engine, mfg) ; }
      document.getElementById('Result').innerHTML = "<h1 style=\"text-align: center;\">Loading...</h1>"; 

     http_request2.open('GET', auto_url, true);
     http_request2.send(null);
   }

   function autopopContents(unittype, make, typee, model, year, engine, mfg) {
      if (http_request2.readyState == 4) {
         if (http_request2.status == 200) {
            result = http_request2.responseText;

            document.getElementById('Result').innerHTML = result;
            document.getElementById('Sub').innerHTML = "<input type=\"submit\" value=\"Submit\" onClick=\"gatherRequest();\"  style=\"margin-top: 4px;\">";
			
         } else {
            alert('There was a problem with the request -- autopopContents.');
         }
      }
   }
   
////////////////

function refreshIndex(boxName, UnitType) {
 if (boxName.checked) {
 window.location = "index.asp?UnitType=" + UnitType;
 }
 else {
 document.getElementById(FieldType).innerHTML = "";
 }
}