var num_new=0;
var interval_new = null;
var mkIndex_new = 1;

function doLists_motab(make,model,trim){
	num_new++;
	if (num_new < 100)  {
		if (typeof get_makes_motab == 'function' && typeof get_range_motab =='function' && typeof models_motab=='object' && typeof motab_make_value=='object' && typeof motab_make_display=='object')  {
			get_makes_motab(make);

			for(i=0; i<motab_make_value.length; i++)	{
				if (motab_make_value[i] == make){
					mkIndex_new = i;
				}
			}
			//alert(models_motab[mkIndex_new] +","+ model);
			get_range_motab(models_motab[mkIndex_new], model);
			clearInterval(interval_new);
		}
	} else {
		clearInterval(interval_new);
	}
	get_trim_motab(trim);
}


function get_makes_motab(req_make)	{
	var dropDown;
	selectedIndex = 0;

	if (document.newSearch && document.newSearch.make)  {
		dropDown = document.newSearch.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<motab_make_display.length; index++)	{

				dropDown[index] = new Option(motab_make_display[index],motab_make_value[index]);
                if(index != 0){
					dropDown[index].className = "search_optionsel";
				}

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

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

function get_range_motab(ranges,req_model)	{

	selectedIndex = 0;
	var dropDown;

	if (document.newSearch && document.newSearch.model)  {
		dropDown = document.newSearch.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]=="Any"){
				dropDown[index] = new Option(ranges[index],ranges[index].toLowerCase());
			}else{
				dropDown[index] = new Option(ranges[index],ranges[index].toUpperCase());
				dropDown[index].className = "search_optionsel";
			}

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

	get_trim_motab();
}

function select_make_motab(req_make)  {
	var dropDown;

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

	if (document.newSearch && document.newSearch.make)  {
		dropDown = document.newSearch.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 get_trim_motab(trim){
	var selmake = document.forms.newSearch.make.selectedIndex;
	var selmodel = document.forms.newSearch.model.selectedIndex;
	//window.alert(trim_motab[selmake][selmodel]);
	var dropDown = document.newSearch.trim;
	dropDown.length = 0;

	for(index=0;index<trim_motab[selmake][selmodel].length;index++){
		dropDown[index] = new Option(trim_motab[selmake][selmodel][index],trim_motab[selmake][selmodel][index].toLowerCase());
		if(trim_motab[selmake][selmodel][index] != "Any"){
			dropDown[index].className = "search_optionsel";
		}
		if(trim == trim_motab[selmake][selmodel][index].toUpperCase()){
			dropDown.selectedIndex = index;
		}
	}
}