var xmlHttp

//The purpose of the function is to solve the problem of creating different XMLHTTP objects for different browsers.
function GetXmlHttpObject()
{
try
{ // Opera 8.0+, Firefox, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e)
{	// Internet Explorer Browsers
try	{
//IE 6 +
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{	//IE 5.5
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function stateChanged()
{ 
if (xmlHttp.readyState==4)
{ 
//lets get a grip on the ASP-generated XML document using some DOM
var xmlDoc = xmlHttp.responseXML.documentElement;

//check if any car models exist..ie if the XML document returned an <empty> element then we assume no models exist
var empty = xmlDoc.getElementsByTagName('empty');
if (empty.length)
{ 
//get a handle to our areas menu
var our_form = document.searchform.location 

//remove all options by setting the options array's length to 0 
our_form.options.length=0 
our_form.options[0]=new Option("no area selected","",true, false)
}
else
{ 
//get a handle to our area menu
var our_form = document.searchform.location 

//remove all options in the area menu by setting the options array's length to 0 
our_form.options.length=0

//declare some variables
var model_id, model_name 

//how many car models (i.e. XML elements) did our XML document return?
var length = xmlDoc.getElementsByTagName('car_model').length;

// populate the select menu with new options, using the Option() constructor on each option. Loop through based on how many car models we have 
for (var i=0; i < length; i++) {

model_id = xmlDoc.getElementsByTagName("model_id")[i].childNodes[0].nodeValue;
model_name = xmlDoc.getElementsByTagName("model_name")[i].childNodes[0].nodeValue; 
our_form.options[i]=new Option(model_name, model_id, false, false)
} 
}//else 
}//if (xmlHttp.readyState==4) 
}

function get_car_models(car_id)
{
//The user selected an area from the menu, so lets rock with some AJAX!!!
if (car_id == 0) 
{ 
//get a handle to our areas menu
var our_form = document.searchform.location 

//remove all options by setting the options array's length to 0 
our_form.options.length=0 
our_form.options[0]=new Option("no area selected","",true, false) 
}
else
{ 
//create object via function call
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}

//create querystring to our ASP page - pass the 'tenure' of the selected tenure
var url="/include/cleverdropdownScript.asp?tenure=" + car_id;

//make request, specify response function and send request
xmlHttp.open("GET",url,true); 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.send(null);
} 
}