function showModelos(idMarca) { 
	if(document.getElementById("marca").value!="-1") {
 		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null) {
 			alert ("Browser does not support HTTP Request");
 			return;
 		}
		var url="public/pages/getModelos.jsp";
		url=url+"?idMarca="+idMarca;

		xmlHttp.onreadystatechange=stateChanged; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

	}else{
		var selectModelos = document.getElementById("modelo");
		//Remove todas as opções
		if (selectModelos.hasChildNodes()) {
			while(selectModelos.childNodes.length >= 1) {
				selectModelos.removeChild(selectModelos.firstChild);
			}
		}
	}
}

function stateChanged() { 	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
  		var showdata = xmlHttp.responseText; 
    	var dados = showdata.split(":");
    	
    	var selectModelos = document.getElementById("modelo");
    	
		//Remove todas as opções
		if (selectModelos.hasChildNodes()) {
			while(selectModelos.childNodes.length >= 1) {
				selectModelos.removeChild(selectModelos.firstChild);
			}
		}
		
		//Insere a primeira opção: "Selecione um modelo"
		var firstOptionTxt = document.createTextNode('Selecione um modelo');
		var firstOption = document.createElement('option');
		firstOption.appendChild(firstOptionTxt);
		firstOption.setAttribute('value', '');
		selectModelos.appendChild(firstOption);
	
	 	if(dados.length >= 1) {		 															
			//Insere as novas opções
			for (i=1; i<dados.length; i++) {				
				var optionTxt = document.createTextNode(dados[i]);
				var option = document.createElement('option');
				option.appendChild(optionTxt);
				option.setAttribute('value',dados[i]);
				selectModelos.appendChild(option);
			}
	 	}	
 	} 	
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
 	}catch(e) {
 		//Internet Explorer
 		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}catch(e) {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}
