function clearlistbox(oBox){
  for (var i=oBox.options.length-1; i>=0; i--){
    oBox.options[i] = null;
  }
  oBox.selectedIndex = -1;
}

function loadlistbox(oBox,aArray){
  for (var i = 0; i < aArray.length; i++){
    if (i==0) {
		oBox.options[oBox.options.length]=new Option(aArray[0],'');
	}
	else {
		oBox.options[oBox.options.length]=new Option(aArray[i],aArray[i]);
	}
  }
}

function loadlistbox2(oBox,aArray1,aArray2){
// Load list box with separate display and value elements
// Note: Array1 = Display Name
//       Array2 = Option Value
  for (var i = 0; i < aArray1.length; i++){
  	if (i==0) {
		oBox.options[oBox.options.length]=new Option(aArray1[0],'');
	}
	else {
		 oBox.options[oBox.options.length]=new Option(aArray1[i],aArray2[i]);
	}
   
  }
}

function loadModelList(theForm) {
	clearlistbox(theForm.fldModel);
	clearlistbox(theForm.fldYear);
	tmpMake=theForm.fldMake.options[theForm.fldMake.selectedIndex].value;
	if (tmpMake=="") {
		theForm.fldModel.disabled=true;
		theForm.fldYear.disabled=true;
	}
	else {
		theForm.fldModel.disabled=false;
		theForm.fldModel.options[theForm.fldModel.options.length]=new Option(ModelList[0],'');
		for (var i = 0; i < ModelMakeList.length; i++){
			if (ModelMakeList[i]==tmpMake) {
			    theForm.fldModel.options[theForm.fldModel.options.length]=new Option(ModelList[i],ModelList[i]);
			}
		}
	}
}

function loadYearList(theForm) {
	clearlistbox(theForm.fldYear);
	tmpMake=theForm.fldMake.options[theForm.fldMake.selectedIndex].value;
	tmpModel=theForm.fldModel.options[theForm.fldModel.selectedIndex].value;
	if (tmpMake=="" || tmpModel=="") {
		theForm.fldYear.disabled=true;
	}
	else {
		theForm.fldYear.disabled=false;
		theForm.fldYear.options[theForm.fldYear.options.length]=new Option(YearList[0],'');
		for (var i = 0; i < YearModelMakeList.length; i++){
			if (YearModelMakeList[i]==tmpMake + '|' + tmpModel) {
			    theForm.fldYear.options[theForm.fldYear.options.length]=new Option(YearList[i],YearList[i]);
			}
		}
	}
}


function autoSubmitForm(tmpFormName) {
   setTimeout('document.' + tmpFormName + '.submit()', 1);
}

function submitMatchForm(tmpFormName,argResetField,argResetValue) {
   argResetField.value=argResetValue;
   //alert(argResetValue)
   setTimeout('document.' + tmpFormName + '.submit()', 1);
}

function doCompare(argMaxNumModels,argHdrColWidth,argDtlColWidth) {
	var allFields=document.getElementsByTagName('input');
	var tmpNumModels=0;
	var tmpSelModelStr="";
	for (var i = 0; i < allFields.length; i++) {
		tmpField=allFields[i];
		if (tmpField.name=='fldModel') {
			if (tmpField.checked==true) {
				tmpNumModels=tmpNumModels+1;
				if (tmpSelModelStr!="") {
					tmpSelModelStr=tmpSelModelStr + ','
				}
				tmpSelModelStr=tmpSelModelStr + tmpField.value;
			}
		}
	}
	if (tmpNumModels<2) {
		alert('You must select two or more models to compare!');
	}
	else if (tmpNumModels>argMaxNumModels){
		alert('You may not select more than ' + argMaxNumModels + ' models.');
	}
	else {
		tmpwidth=(argHdrColWidth + (tmpNumModels*argDtlColWidth))
		window.open('configspecs.asp?models=' + tmpSelModelStr,'ModelCompare','resizable=no,width=' + tmpwidth + ',height=270,scrollbars=0,location=0');
	}	
}

function doCompare_cv(argMaxNumModels,argHdrColWidth,argDtlColWidth) {
	var allFields=document.getElementsByTagName('input');
	var tmpNumModels=0;
	var tmpSelModelStr="";
	for (var i = 0; i < allFields.length; i++) {
		tmpField=allFields[i];
		if (tmpField.name=='fldModel') {
			if (tmpField.checked==true) {
				tmpNumModels=tmpNumModels+1;
				if (tmpSelModelStr!="") {
					tmpSelModelStr=tmpSelModelStr + ','
				}
				tmpSelModelStr=tmpSelModelStr + tmpField.value;
			}
		}
	}
	if (tmpNumModels<2) {
		alert('You must select two or more models to compare!');
	}
	else if (tmpNumModels>argMaxNumModels){
		alert('You may not select more than ' + argMaxNumModels + ' models.');
	}
	else {
		tmpwidth=(argHdrColWidth + (tmpNumModels*argDtlColWidth))
		window.open('configspecs_cv.asp?models=' + tmpSelModelStr,'ModelCompare','resizable=no,width=' + tmpwidth + ',height=270,scrollbars=0,location=0');
	}	
}
