function clear(objSelect){

     for (var i = (objSelect.options.length-1); i >= 1; i--){
         objSelect.options[i]=null;
     }
}


function showCustomer()
{
//alert('here');
//alert('here');
 xmlHttp=GetXmlHttpObject();
//alert('here');
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

//alert('here');

//alert('e');	
//alert (document.Form1.Manufacturer.options[document.Form1.Manufacturer.selectedIndex].value);
//alert(Form1.Manufacturer.selectedIndex].value);
var url="/ajaxusedquery.aspx?DealerGroupId=252";
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+"&DealerId=" + document.Form1.DealerId.options[document.Form1.DealerId.selectedIndex].value;
//alert('test');
//alert(url);


if (document.Form1.DealerId.options[document.Form1.DealerId.selectedIndex].value == "-1")
{
	locationSelected = 0;
}

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);
  clear(document.Form1.DealerId);
  //clear(Form1.selboxVersion);

//alert('here');
if(ManufacturerDone ==0)
{

	for(var i=0; i<xmlDoc.getElementsByTagName("Manufacturer").length; i++) {   

	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);
	}


	}

}  




	for(var i=0; i<xmlDoc.getElementsByTagName("Model").length; i++) {   


	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);
	}


	}


for(var i=0; i<xmlDoc.getElementsByTagName("Location").length; i++) {   


	if(trim(xmlDoc.getElementsByTagName("Location")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue) == trim(xmlDoc.getElementsByTagName("LocationSelected")[0].childNodes[0].nodeValue))
	{
	document.Form1.DealerId.options[document.Form1.DealerId.options.length] = new Option(xmlDoc.getElementsByTagName("Location")[i].getElementsByTagName("DealerName")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Location")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue);
	locationSelected = xmlDoc.getElementsByTagName("LocationSelected")[0].childNodes[0].nodeValue;
	}
	else
	{
	document.Form1.DealerId.options[document.Form1.DealerId.options.length] = new Option(xmlDoc.getElementsByTagName("Location")[i].getElementsByTagName("DealerName")[0].childNodes[0].nodeValue,xmlDoc.getElementsByTagName("Location")[i].getElementsByTagName("Id")[0].childNodes[0].nodeValue);
	}


	




}


	


document.getElementById('dvVehicleCount').innerHTML = xmlDoc.getElementsByTagName("VehicleCount")[0].childNodes[0].nodeValue

}

var id245 = false;
var id246 = false;
var id247 = false;
var id249 = false;
var id253 = false;
var id581 = false;
var id343 = false;
var id581 = false;

for(var i=0; i<document.Form1.DealerId.options.length; i++) { 
	if (document.Form1.DealerId.options[i].value == "245") {
		id245 = true;
	}

	if (document.Form1.DealerId.options[i].value == "246") {
		id246 = true;
	}

	if (document.Form1.DealerId.options[i].value == "247") {
		id247 = true;
	}

	if (document.Form1.DealerId.options[i].value == "249") {
		id249 = true;
	}

	if (document.Form1.DealerId.options[i].value == "253") {
		id253 = true;
	}

	if (document.Form1.DealerId.options[i].value == "581") {
		id581 = true;
	}

	if (document.Form1.DealerId.options[i].value == "343") {
		id343 = true;
	}

	if (document.Form1.DealerId.options[i].value == "581") {
		id581 = true;
	}
}

var count = 1;

if (id253 == true) {
	document.Form1.DealerId.options[count].value = "253";
	document.Form1.DealerId.options[count].text = "Swansea (Motorpark)";
	if (locationSelected == "253")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id581 == true) {
	document.Form1.DealerId.options[count].value = "581";
	document.Form1.DealerId.options[count].text = "Swansea (Fiat)";
	if (locationSelected == "581")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id247 == true) {
	document.Form1.DealerId.options[count].value = "247";
	document.Form1.DealerId.options[count].text = "Gorseinon";
	if (locationSelected == "247")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id249 == true) {
	document.Form1.DealerId.options[count].value = "249";
	document.Form1.DealerId.options[count].text = "Neath";
	if (locationSelected == "249")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id246 == true) {
	document.Form1.DealerId.options[count].value = "246";
	document.Form1.DealerId.options[count].text = "Llanelli";
	if (locationSelected == "246")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id245 == true) {
	document.Form1.DealerId.options[count].value = "245";
	document.Form1.DealerId.options[count].text = "Haverfordwest (Ford)";
	if (locationSelected == "245")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

if (id343 == true) {
	document.Form1.DealerId.options[count].value = "343";
	document.Form1.DealerId.options[count].text = "Haverfordwest (Peugeot)";
	if (locationSelected == "343")
	{
		document.Form1.DealerId.options[count].selected = true;
	}
	count++;	
}

	if (locationSelected == "0")
	{
		document.Form1.DealerId.options[0].selected = true;
	}

//alert(locationSelected);


}
		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();
//		}