var num=0;
var interval = null;
var mkIndex=0;

function doLists(make,model,make_value_array,make_display_array,models_array,nomodel)  {

	num++;
	if (num < 100)  {
		if (typeof get_makes == 'function' && typeof get_range =='function' && typeof models_array=='object' && typeof make_value_array=='object' && typeof make_display_array=='object')  {
			get_makes(make,make_value_array,make_display_array);

			if(nomodel != 1){
				for(i=0; i<make_value_array.length; i++)	{
					if (make_value_array[i] == make){
						mkIndex = i;
				 	}
				}
				get_range(models_array[mkIndex], model);
				clearInterval(interval);
			}else{
				get_range(models_array[0], model);
			}
		}
	} else {
		clearInterval(interval);
	}
}


function get_makes(req_make,make_value_array,make_display_array)	{
	var dropDown;
	selectedIndex = 0;

	if (document.quicksearch && document.quicksearch.make)  {
		dropDown = document.quicksearch.make;
	}
	else if(document.search && document.search.make)  {
		dropDown=document.search.make;
	}
	else if (document.forms[0] && document.forms[0].make)  {
		dropDown = document.forms[0].make;
	}

	if (dropDown)  {
		dropDown.length = 0;

		for(index=0; index<make_display_array.length; index++)	{

			dropDown[index] = new Option(make_display_array[index],make_value_array[index]);

			if(make_value_array[index].toUpperCase() == req_make){
				selectedIndex = index;

			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
	select_make(req_make);
}

function get_range(ranges,req_model)	{

	selectedIndex = 0;
	var dropDown;

	if (document.quicksearch && document.quicksearch.model)  {
		dropDown = document.quicksearch.model;
	}
	else if(document.search && document.search.model)  {
		dropDown=document.search.model;
	}
	else if (document.forms[0] && document.forms[0].model)  {
		dropDown = document.forms[0].model;
	}

	if (dropDown)  {

		dropDown.length = 0;

		for(index=0; index<ranges.length; index++)	{

			if(ranges[index]=="Model"){
				dropDown[index] = new Option(ranges[index],"any");
			}else{
				dropDown[index] = new Option(ranges[index],ranges[index].toUpperCase());
			}

			if(ranges[index].toUpperCase() == req_model){
				selectedIndex = index;
			}
			else if (ranges[index].toUpperCase() == "MODEL")  {
				selectedIndex = index;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}

function select_make(req_make)  {
	var dropDown;

	if (req_make == null)  {
		req_make="";
	}

	if (document.quicksearch && document.quicksearch.make)  {
		dropDown = document.quicksearch.make;
	}
	else if(document.search && document.search.make)  {
		dropDown=document.search.make;
	}
	else if (document.forms[0] && document.forms[0].make)  {
		dropDown = document.forms[0].make;
	}

	if (dropDown)  {
		for (x=0; x<dropDown.length; x++)  {
			mk=dropDown.options[x].value;
			if ( mk.toUpperCase()==req_make)  {
				if (dropDown.options[x].selected==false)   {
					dropDown.options[x].selected=true;
				}
			}
		}
	}
}

function searchGetBodystyle(array_type,req_style){
	var dropDown = document.forms.quicksearch.bodystyle;
	var selectedIndex = 0;

    if(dropDown){
		dropDown.length = 0;
	    for(var i=0; i<bodystyle_display[array_type].length; i++)	{
			dropDown[i] = new Option(bodystyle_display[array_type][i],bodystyle_value[array_type][i]);

			if(bodystyle_value[array_type][i].toLowerCase() == req_style){
				selectedIndex = i;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}

function searchGetFueltype(array_type,req_fuel){
	var dropDown = document.forms.quicksearch.fuel;
	var selectedIndex = 0;

    if(dropDown){
		dropDown.length = 0;
	    for(var i=0; i<fuel_display[array_type].length; i++)	{
			dropDown[i] = new Option(fuel_display[array_type][i],fuel_value[array_type][i]);

			if(fuel_value[array_type][i].toLowerCase() == req_fuel){
				selectedIndex = i;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}

function searchGetGearbox(array_type,req_gearbox){
	var dropDown = document.forms.quicksearch.gearbox;
	var selectedIndex = 0;

    if(dropDown){
		dropDown.length = 0;
	    for(var i=0; i<gearbox_display[array_type].length; i++)	{
			dropDown[i] = new Option(gearbox_display[array_type][i],gearbox_value[array_type][i]);

			if(gearbox_value[array_type][i].toLowerCase() == req_gearbox){
				selectedIndex = i;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}