
function getHTTPObject() {

	  var xmlhttp;

		try {

		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

		  try {

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		  } catch (E) {

			xmlhttp = false;

		  }

		}

	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {

		  xmlhttp = new XMLHttpRequest();

		} catch (e) {

		  xmlhttp = false;

		}

	  }

	  return xmlhttp;

	}
	
	
	function popmodel1(make) {
		
		document.getElementById("model").disabled = true;
		document.getElementById("model").options[0].text = "Loading...";
	
		var urltoget = "http://"+document.domain+"/index.php?option=member&page=generateusedcarmodellist&notemplate=yes&make="+make+"&fr=1";

		  http = new getHTTPObject();
		  if (http) {
			http.open("GET", urltoget, true);
			http.send(null);
			http.onreadystatechange = handleHttpResponse1;

		  }
		
	}
	
	function handleHttpResponse1() {
	  if (http.readyState == 4) {
	 document.getElementById("modeldiv1").innerHTML=http.responseText;
	  }
	}
	
	function popmodel2(make1) {
	
		document.getElementById("model1").disabled = true;
    	document.getElementById("model1").options[0].text = "Loading...";
	
		var urltoget = "http://"+document.domain+"/index.php?option=member&page=generateusedcarmodellist&notemplate=yes&make="+make1+"&fr=2";
		  http = new getHTTPObject();
		  if (http) {
			http.open("GET", urltoget, true);
			http.send(null);
			http.onreadystatechange = handleHttpResponse2;

		  }
	}
	function popmodel3(make2) {
	
		document.getElementById("model2").disabled = true;
		document.getElementById("model2").options[0].text = "Loading...";
	
	var urltoget = "http://"+document.domain+"/index.php?option=member&page=generateusedcarmodellist&notemplate=yes&make="+make2+"&fr=3";
		  http = new getHTTPObject();
		  if (http) {
			http.open("GET", urltoget, true);
			http.send(null);
			http.onreadystatechange = handleHttpResponse3;

		  }
	}
	
	function handleHttpResponse2() {
	  if (http.readyState == 4) {
	 document.getElementById("modeldiv2").innerHTML=http.responseText;
	  }
	}
	
	function handleHttpResponse3() {
	  if (http.readyState == 4) {
	 document.getElementById("modeldiv3").innerHTML=http.responseText;
	  }
	}


function first()
{
	if(document.advancedsearch.make.options[document.advancedsearch.make.selectedIndex].value==0)
	{
		document.advancedsearch.make1.disabled=true;
		document.advancedsearch.model1.disabled=true;
		document.advancedsearch.make2.disabled=true;
		document.advancedsearch.model2.disabled=true;
	}
	else
	{
		document.advancedsearch.make1.disabled=false;
		document.advancedsearch.model1.disabled=false;
		document.advancedsearch.make2.disabled=false;
		document.advancedsearch.model2.disabled=false;
	}
}

function second()
{
	if(document.advancedsearch.make1.options[document.advancedsearch.make1.selectedIndex].value==0)
	{
		document.advancedsearch.make.disabled=true;document.advancedsearch.model.disabled=true;
		document.advancedsearch.make2.disabled=true;document.advancedsearch.model2.disabled=true;
	}
	else
	{
		document.advancedsearch.make.disabled=false;document.advancedsearch.model.disabled=false;
		document.advancedsearch.make2.disabled=false;document.advancedsearch.model2.disabled=false;
	}
}

function third()
{
	if(document.advancedsearch.make2.options[document.advancedsearch.make2.selectedIndex].value==0)
	{
		document.advancedsearch.make.disabled=true;document.advancedsearch.model.disabled=true;
		document.advancedsearch.make1.disabled=true;document.advancedsearch.model1.disabled=true;
	}
	else
	{
		document.advancedsearch.make.disabled=false;document.advancedsearch.model.disabled=false;
		document.advancedsearch.make1.disabled=false;document.advancedsearch.model1.disabled=false;
	}
}

function advsearch_validate()
{
	//alert("min "+document.advancedsearch.yearofmanufacturemax.options[document.advancedsearch.yearofmanufacturemax.selectedIndex].value);
	//alert("max "+document.advancedsearch.yearofmanufacturemin.options[document.advancedsearch.yearofmanufacturemin.selectedIndex].value);
	
	if (parseInt(document.advancedsearch.yearofmanufacturemax.options[document.advancedsearch.yearofmanufacturemax.selectedIndex].text) < parseInt(document.advancedsearch.yearofmanufacturemin.options[document.advancedsearch.yearofmanufacturemin.selectedIndex].text))
	{alert("Invalid range of Year of manufacture");document.advancedsearch.yearofmanufacturemax.focus();return false;}

	if (parseInt(document.advancedsearch.kilometersmax.options[document.advancedsearch.kilometersmax.selectedIndex].value) < parseInt(document.advancedsearch.kilometersmin.options[document.advancedsearch.kilometersmin.selectedIndex].value))
	{alert("Invalid range of kilometers");document.advancedsearch.kilometersmax.focus();return false;}

	if (parseInt(document.advancedsearch.pricemax.options[document.advancedsearch.pricemax.selectedIndex].value) < parseInt(document.advancedsearch.pricemin.options[document.advancedsearch.pricemin.selectedIndex].value))
	{alert("Invalid range of price");document.advancedsearch.pricemax.focus();return false;}

	return true;
}