function setCurrentMake() {
	document.getElementById("currentMake").value=(document.getElementById("makes").options[document.getElementById("makes").selectedIndex].text);
}
	
function setCurrentModel() {
	document.getElementById("currentModel").value=(document.getElementById("models").options[document.getElementById("models").selectedIndex].text);
}
	
function populateModel(formEle,compareMakeId,compareMakeDesc, N,U) {

	var tempArrayId = new Array();
	var tempArrayDesc = new Array();
	var anyTxt;
	
	for(x=0;x<MakesModels.length;x++) {
		if (MakesModels[x][4]==N || MakesModels[x][5]==U ) {		  
			if (MakesModels[x][1] == compareMakeDesc) {
				tempArrayId.push(MakesModels[x][2]);
				tempArrayDesc.push(MakesModels[x][3]);
			}
		}
	}
	
	if (compareMakeDesc == "ALL") {
		anyTxt = 'Select Make';
	} else {
		anyTxt = "Any " + compareMakeDesc + " Model...";
	}
	populateDropdown(formEle, tempArrayId, tempArrayDesc, anyTxt);
}

function populateMake(N,U) {

	var tempArrayId = new Array();
	var tempArrayDesc = new Array();
	var saveMM = "";
	var formEle = document.inventory_form_auto;
		
	for(x=0;x<MakesModels.length;x++) {	     
	
		if (MakesModels[x][4]==N || MakesModels[x][5]==U ) {		
		    
			if (tempArrayId.length==0) {
				tempArrayId.push(MakesModels[x][0]);
				tempArrayDesc.push(MakesModels[x][1]);
				saveMM = MakesModels[x][0];
			} else {
				if (MakesModels[x][0] != saveMM) {
					tempArrayId.push(MakesModels[x][0]);
				    tempArrayDesc.push(MakesModels[x][1]);
					saveMM = MakesModels[x][0];
				}
			}
		}
	}
	formEle.makes.selectedIndex = 0;
	populateDropdown(formEle.makes, tempArrayId, tempArrayDesc,  'Select Make...');
}

function populateDropdown(formEle, thisArrayId, thisArrayDesc, anyTxt) {

	formEle.length = thisArrayId.length+1;
	formEle.options[0].text = anyTxt;
	formEle.options[0].value = "";
		
	for (qq = 0;qq < thisArrayId.length;qq++) {
		formEle.options[qq+1].value = thisArrayId[qq];
		formEle.options[qq+1].text = thisArrayDesc[qq];
	}
}

function popModel() { 
   for (var i=0; i < document.inventory_form_auto.NewOrUsed.length; i++) {
       if (document.inventory_form_auto.NewOrUsed[i].checked) {
       	var rad_val = document.inventory_form_auto.NewOrUsed[i].value;
       }
   }

if (rad_val== 1){    //new car        
populateModel(document.inventory_form_auto.models,document.inventory_form_auto.makes.options[document.inventory_form_auto.makes.options.selectedIndex].value,document.inventory_form_auto.makes.options[document.inventory_form_auto.makes.options.selectedIndex].text, 1,0); 
} else {  // used car
populateModel(document.inventory_form_auto.models,document.inventory_form_auto.makes.options[document.inventory_form_auto.makes.options.selectedIndex].value,document.inventory_form_auto.makes.options[document.inventory_form_auto.makes.options.selectedIndex].text, 0,1); 
	}
	
}

function removeModel() { 
	document.inventory_form_auto.models.length = 1;
	document.inventory_form_auto.models.options[0].value = "";
	document.inventory_form_auto.models.options[0].text = "Any Model"	
	document.inventory_form_auto.models.selectedIndex = 0;		
}
 
function setModel() { 
	document.inventory_form_auto.models.selectedIndex = 0;
}

function validateAuto() {
	valid=true;
	if (document.inventory_form_auto.makes.selectedIndex == 0) {
		window.alert("Please enter vehicle make.");
		valid= false;
	} 
	
	if (document.inventory_form_auto.ZipCode.value.length > 0 && document.inventory_form_auto.ZipCode.value.length < 5)
	{
		alert("Zip should only contain 5 digits.");
		valid= false;
	}
	
	if (document.inventory_form_auto.ZipCode.value != "" )
	{
  		var checkOK = "0123456789";
  		var checkStr = document.inventory_form_auto.ZipCode.value;
  		var allValid = true;
  		for (i = 0;  i < checkStr.length;  i++)
  		{
    		ch = checkStr.charAt(i);
    		for (j = 0;  j < checkOK.length;  j++)
      		if (ch == checkOK.charAt(j))
        	break;
    		if (j == checkOK.length)
    		{
      			allValid = false;
      			break;
    		}
		}
  		if (!allValid)
  		{
    		alert("Zip should only contain numbers.");
    		document.inventory_form_auto.ZipCode.focus();
    		valid= false;
  		}
	}
	else
	{
		alert("Please enter a valid zip code.");
		valid=false;
	}
	if(valid==true)
		document.inventory_form_auto.submit();		
}
