 var selectedType;//,selectedKey2,selectedKey3;
//------------------------------------
	function setMake(type){
		var arr;
		var showY=true;
		selectedType=type;//save it for future use
		if(type=='ALL'){
			arr=combineDistinctArray(_search.getKey('USED').getKey('no').getAllKeysNames(),_search.getKey('USED').getKey('yes').getAllKeysNames());
			arr=combineDistinctArray(arr,_search.getKey('NEW').getKey('no').getAllKeysNames());
		}else	if(type=='New'){
				arr=_search.getKey('NEW').getKey('no').getAllKeysNames();
				showY=false;//for new cars do not show years
		}else if(type=='Used'){
				arr=combineDistinctArray(_search.getKey('USED').getKey('no').getAllKeysNames(),_search.getKey('USED').getKey('yes').getAllKeysNames());
		}else if(type=='used_certified'){
				arr=_search.getKey('USED').getKey('yes').getAllKeysNames();
		}
		var q=setOptions('make',arr,'Makes');
		setNoResult(q);
		if(q>0){
			setOptions('model',0,'Models');
			displayTrimColorSelector(false);
			displayYearsSelector(showY);
		}
		setSearchHeader();
	}
	function setNoResult(q){
		if(q==0){
			document.getElementById(search_box_id).style.display="none";
			document.getElementById("emptyresultsbox").style.display="block";
		}else{
			document.getElementById(search_box_id).style.display="block";
			document.getElementById("emptyresultsbox").style.display="none";
		}
	}
//-------------------------------------
	function setModel(make){
		var arr;
		if(selectedType=='ALL'){
			arr=combineDistinctArray(_search.getKey('USED').getKey('no').getKey(make).getAllKeysNames(),_search.getKey('USED').getKey('yes').getKey(make).getAllKeysNames());
			arr=combineDistinctArray(_search.getKey('NEW').getKey('no').getKey(make).getAllKeysNames(),arr);
		}else if(selectedType=='New'){
			arr=_search.getKey('NEW').getKey('no').getKey(make).getAllKeysNames();
		}else if(selectedType=='Used'){
			arr=combineDistinctArray(_search.getKey('USED').getKey('no').getKey(make).getAllKeysNames(),_search.getKey('USED').getKey('yes').getKey(make).getAllKeysNames());
		}else if(selectedType=='used_certified'){
			arr=_search.getKey('USED').getKey('yes').getKey(make).getAllKeysNames();
		}	
		setOptions('model',arr,'Models');
		displayTrimColorSelector(false);
	}
	//--------------------------------------
	function setTrimColor(model){
		if(selectedType=="New"){ //for new models only
			var make=document.getElementById("make").value;
			var selectedModel=_search.getKey('NEW').getKey('no').getKey(make).getKey(model);
			var arrTrims=selectedModel.getAllKeysNames();
			//--lets get all color
			var kqty=selectedModel.getKeyQty();//get all trims qty
 			var arrColors=Array();//prepare array for colors
 			arrColors=selectedModel.getVals();//if there was no trim we saved colors in model as value, so take them out
 			for(var i=0;i<kqty;i++){
 				arrColors=combineDistinctArray(arrColors,selectedModel.getKeyByNum(i).getVals());//get colors from trim's vals
 			}
			setOptions('trim',arrTrims,'Trims');
			setOptions('color',arrColors,'Colors');
			displayTrimColorSelector(true);
		}
	}
	//--------------------------------------
	function setColor(trim){
		if(selectedType=="New"){ //for new models only
			var make=document.getElementById("make").value;
			var model=document.getElementById("model").value;
			if(trim=="ALL"){
				var selectedModel=_search.getKey('NEW').getKey('no').getKey(make).getKey(model);
				//--lets get all color
				var kqty=selectedModel.getKeyQty();//get all trims qty
				var arrColors=Array();//prepare array for colors
 				arrColors=selectedModel.getVals();//if there was no trim we saved colors in model as value, so take them out
 				for(var i=0;i<kqty;i++){
 					arrColors=combineDistinctArray(arrColors,selectedModel.getKeyByNum(i).getVals());//get colors from trim's vals
 				}
 				setOptions('color',arrColors,'Colors');
 			}else
				setOptions('color',_search.getKey('NEW').getKey('no').getKey(make).getKey(model).getKey(trim).getVals(),'Colors');
		}
	}
	//--------------------------------------
	function displayTrimColorSelector(show){
		if(show)
			document.getElementById("trimcolor_selector").style.display="inline";
		else document.getElementById("trimcolor_selector").style.display="none";
	}
	//--------------------------------------
	function displayYearsSelector(show){
		if(show)
			document.getElementById("year_selector").style.display="block";
		else document.getElementById("year_selector").style.display="none";
	}
	//--------------------------------------
	function setSearchHeader(){
		var text;
		switch(selectedType){
			case "ALL": text="Search Our Entire Inventory";
			break;
			case "New": text="Search For a New Vehicle";
			break;
			case "Used": text="Search For a Used Vehicle";
			break;
			case "used_certified": text="Search Certified Pre-Owned Vehicles";
		}
		if(document.all)
    	document.getElementById("search_header").innerText=text;
		else
    	document.getElementById("search_header").textContent=text;
	}
//--------------------------------------