var doneSelectMake = false;
function initModel(strFormName, boolHeadContained) {
	var i;
	var intModel;
	var objModelSelection;
	i = 0;
	intModel = 0;
	objModelSelection = document.forms[strFormName].add_state;
	if (intModel==0 && objModelSelection.options.length > 1) {
		if (objModelSelection.options[0].value != '') {
			intModel = objModelSelection.options[0].value;
		}
	}
	chooseMake(strFormName, boolHeadContained);
	if (document.forms[strFormName].add_country.selectedIndex > 0) {
		chooseMake(strFormName, boolHeadContained);
		for (i=0; i < document.forms[strFormName].add_state.options.length; i++) {
			if (objModelSelection.options[i].value == intModel) {
				objModelSelection.selectedIndex = i;
				i = document.forms[strFormName].add_state.options.length;
			}
		}
	}
} // initModel

function selectMake(strFormName, boolHeadContained, makeVal) {
	if(!makeVal>0) return;
	var intMake = 0;
	var i;
	var intOffSetForAll;
	if (boolHeadContained)
		intOffsetForAll = 1;
	else
		intOffsetForAll = 0;
	objMakeSelection = document.forms[strFormName].add_country;
	if(!objMakeSelection.selectedIndex>=intOffsetForAll) {
		// IE 5+ and NS 4.x will not enter this block
		// Only Opera 6+ and NS 6+ will enter this block
		for (i=0; i < objMakeSelection.options.length; i++) {
			if (objMakeSelection.options[i].value == makeVal) {
				objMakeSelection.selectedIndex = i;
				break;
			}
		}
	}
	if(objMakeSelection.selectedIndex>=0) doneSelectMake = true;
	chooseMake(strFormName, boolHeadContained);
}

function chooseMake(strFormName, boolHeadContained) {
	var arrModelList;
	var objModelSelection;
	var objMakeSelection;
	var intOffSetForAll;
	var i;
	if (document.forms[strFormName].add_state == null)
		return;
	objModelSelection = document.forms[strFormName].add_state;
	objMakeSelection = document.forms[strFormName].add_country;
	objModelSelection.selectedIndex = 0;
	objModelSelection.options.length = 1;
	if (boolHeadContained)
		intOffsetForAll = 1;
	else
		intOffsetForAll = 0;
	if (objMakeSelection.selectedIndex >= intOffsetForAll) {
		arrModelList = (arrModels[objMakeSelection.selectedIndex + 1 - intOffsetForAll]).split(';');
		if (arrModelList.length > intOffsetForAll) {
			objMakeSelection = document.forms[strFormName].add_state.disabled=false;
			for (i = 0; i < arrModelList.length; i++) {
				objModelSelection.options.length = i+2;
				objModelSelection.options[i+1].value = (arrModelList[i]).split(',')[0];
				if (objModelSelection.options[i+1].value == CurrentState) {
					objModelSelection.options[i+1].selected=true;
				}
				objModelSelection.options[i+1].text = (arrModelList[i]).split(',')[1];
			}
		} else {
			objMakeSelection = document.forms[strFormName].add_state.disabled=true;
		}
	}
} // chooseMake

function selectModel(strFormName, modelVal) {
	if(!modelVal>0)return;
	var objModelSelection = document.forms[strFormName].add_state;;
	for (i=0; i < objModelSelection.options.length; i++) {
		if (objModelSelection.options[i].value == modelVal)
			objModelSelection.selectedIndex = i;
	}
}

function fixMakeModel(strFormName, boolHeadContained, makeVal, modelVal) {
	initModel(strFormName, boolHeadContained);
	selectMake(strFormName, boolHeadContained, makeVal);
	selectModel(strFormName, modelVal);
	//window.alert('Finished preselecting the model');
}

var arrModels = new Array();
