/**

* @author Quang Vinh <janov2k4@yahoo.com>

* @version 280205

* @require automobile.js A javascript file which declares an array of make and model

* 

* In order to use, the following elements (element ID) must exist in the document: model. eg: <span id='model'></span>

* the following variables will be passed back to server when submitted: make, model.

*/



//document.write("<script language='javascript' type='text/javascript' src='./lang/automobile.js'></script>");

/*

function DisplayMake(selectedMake,selectedModel) {

	var make = "<select style='width:150px' name='make' id='make' onChange=\"DisplayModel(this.selectedIndex)\">";

	for (i=0; i < automobile.length; i++)

	{

		if (selectedMake==automobile[i][0]) {

			make += "<option value='"+ automobile[i][0] +"' selected>"+ automobile[i][0] +"</option>";

			DisplayModel(i,selectedModel);

		}

		else make += "<option value='"+ automobile[i][0] +"'>"+ automobile[i][0] +"</option>";

	}

	make += "</select>";

	PutInnerHTML('make',make);

}

*/

function DisplayModel(makeIndex,selectedModel,className) {
	if (className != undefined) className = " class='"+ className + "'";
	else className = "";
	
	var model = "<select style='width:130px' name='model' id='model' "+ className + ">";

	model += "<option value=''></option>";

	for (i=0; i < automobile[makeIndex].length; i++)

	{

		if (selectedModel==automobile[makeIndex][i]) model += "<option value='"+automobile[makeIndex][i]+"' selected>"+ automobile[makeIndex][i] +"</option>";

		else model += "<option value='"+automobile[makeIndex][i]+"'>"+ automobile[makeIndex][i] +"</option>";

	}

	model += "</select>";

	PutInnerHTML('model',model);

}
//Long add for use at "Lien He Ban Xe" page
function DisplayModel2(makeIndex,selectedModel,className) {
	if (className != undefined) className = " class='"+ className + "'";
	else className = "";

	var model = "<select style='width:130px' name='model' id='model2' "+ className + ">";

	model += "<option value=''></option>";

	for (i=0; i < automobile[makeIndex].length; i++)

	{

		if (selectedModel==automobile[makeIndex][i]) model += "<option value='"+automobile[makeIndex][i]+"' selected>"+ automobile[makeIndex][i] +"</option>";

		else model += "<option value='"+automobile[makeIndex][i]+"'>"+ automobile[makeIndex][i] +"</option>";

	}

	model += "</select>";

	PutInnerHTML('model2',model);

}



function PutInnerHTML(idname,html) {

	cur_node = document.getElementById(idname);

	parent_node = cur_node.parentNode;

	new_node = document.createElement('div');

	new_node.innerHTML = html;

	new_node.setAttribute('id',idname);

	parent_node.replaceChild(new_node,cur_node);

}