function clear(objSelect)
{
    for (var i = (objSelect.options.length-1); i >= 1; i--)
	{
        objSelect.options[i]=null;
        }
}

function Reset()
{
  	clear(document.Form1.Manufacturer);
  	clear(document.Form1.Model);
  	clear(document.Form1.Version);
  	clear(document.Form1.Doors);
  	clear(document.Form1.FuelType);
  	clear(document.Form1.TransmissionType);
	document.Form1.DropdownPriceFrom.selectedIndex = 0;
	document.Form1.DropdownPriceTo.selectedIndex = 0;
	
	showCustomer();
}


function showCustomer()
{
//alert('here');

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

//alert('here');


//alert (document.Form1.Manufacturer.options[document.Form1.Manufacturer.selectedIndex].value);
//alert(Form1.Manufacturer.selectedIndex].value);
var url="/ajaxusedquery.aspx?DealerId=193";
url=url+"&Manufacturer=" + document.Form1.Manufacturer.options[document.Form1.Manufacturer.selectedIndex].value;
url=url+"&Model=" + document.Form1.Model.options[document.Form1.Model.selectedIndex].value;
url=url+"&PriceFrom=" + document.Form1.DropdownPriceFrom.options[document.Form1.DropdownPriceFrom.selectedIndex].value;
url=url+"&PriceTo=" + document.Form1.DropdownPriceTo.options[document.Form1.DropdownPriceTo.selectedIndex].value;

//alert(url);

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}

var ManufacturerDone = 0;


var iSelected = 0;

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function stateChanged() 
{ 

  if (xmlHttp.readyState==4)
  {
  var xmlDoc=xmlHttp.responseXML.documentElement;

  var i;
  var t;
  var a;

  a = '';

  clear(document.Form1.Manufacturer);
  clear(document.Form1.Model);



if(ManufacturerDone ==0)
{

	for(var i=0; i<xmlDoc.getElementsByTagName("Manufacturer").length; i++) {   

		try {

		if(xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue == 						xmlDoc.getElementsByTagName("ManufacturerSelected")[0].childNodes[0].nodeValue)
		{
			document.Form1.Manufacturer.options[document.Form1.Manufacturer.options.length] = new Option(xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue,false,true);
		ManufacturerSelected = xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue;
		}
		else
		{
			document.Form1.Manufacturer.options[document.Form1.Manufacturer.options.length] = new Option(xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Manufacturer")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue);
		}

		}
		catch(err)
		{
			//Handle errors here
		}
      	}


	for(var i=0; i<xmlDoc.getElementsByTagName("Model").length; i++) {   


		try {

		if(trim(xmlDoc.getElementsByTagName("Model")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue) == 			xmlDoc.getElementsByTagName("ModelSelected")[0].childNodes[0].nodeValue)
		{
			document.Form1.Model.options[document.Form1.Model.options.length] = new Option(xmlDoc.getElementsByTagName("Model")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Model")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue,false,true);
		}
		else
		{
			document.Form1.Model.options[document.Form1.Model.options.length] = new Option(xmlDoc.getElementsByTagName("Model")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Model")[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue);
		}


		}
		catch(err)
		{
			//Handle errors here
		}
	}



document.getElementById('dvVehicleCount').innerHTML = '<span class="stockvehicles">' + xmlDoc.getElementsByTagName("VehicleCount")[0].childNodes[0].nodeValue + '</span> vehicles match your search criteria.'

}
}
}

		function SubmitForm() {

			//Form1.action="/UsedList.aspx";			
//alert(Form1.action);
if (Form1.Submit) {
    Form1.Submit();
}
else {
    Form1.submit();
}

			Form1.submit();

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



		//window.onload = function() 
//		{						
//		showCustomer();
//		}