function exibe_marcas(campo,valor){
	if(campo == "tipo"){
		url = "inc/ajax_site/chama_marcas.php?id_tipo_veiculo="+valor;
		Dados_exibe_marcas(url);
	}
}

function Dados_exibe_marcas(valor) {
	//verifica se o browser tem suporte a ajax
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}

	//se tiver suporte ajax
	if(ajax) {

		ajax.open("GET", valor, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function() {
			
			idloading_ajax = document.getElementById("opt_1_marca");
			
			//enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
				
				idloading_ajax.innerHTML = "Carregando...";
				
			}else { 
				
				idloading_ajax.innerHTML = "Selecione a marca";
				
			}
			
			//após ser processado - chama função processXML que vai varrer os dados
	      if(ajax.readyState == 4 ) {
	      	
			   if(ajax.responseXML) {
			   	
			      processXML_exibe_marcas(ajax.responseXML);
			      
			   }else {
			   	
//			   	alert("parou no else ajax.responseXML");
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idloading_ajax.value = "Selecione a Marca (erro xml)";
				   
			   }
	      }

	   }

		ajax.send(null);

	} // Fecha function Ajax

} // Fecha function Dados
   
function processXML_exibe_marcas(obj){
	
//	alert("entrou na processXML...");
	
   // pega a tag erro
   var dataArrays = obj.getElementsByTagName("resultado");
   
   document.getElementById("seleciona-marca").options.length = 1;
		
  // total de elementos contidos na tag resultado
	if(dataArrays.length > 0) {
		
     // percorre o arquivo XML para extrair os dados
		for(var i = 0 ; i < dataArrays.length ; i++) {
			
			var item = dataArrays[i];

			var marca = item.getElementsByTagName("marca")[0].firstChild.nodeValue;
			var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;
			
			option = document.createElement("option");
			option.setAttribute("value",id);
			option.appendChild(document.createTextNode(marca));
			
			document.getElementById('seleciona-marca').appendChild(option);

		}

  }else{
  	
  			document.getElementById("seleciona-marca").options.length = 1;

  }
}

/*###################################################################################
#####################################################################################
######################### FUNÇÃO PARA CHAMAR OS MODELOS #############################
#####################################################################################
###################################################################################*/

function exibe_modelos(valor){
	
	var tipo_veiculo = document.getElementById("seleciona-veiculo").value;

	url = "inc/ajax_site/chama_modelos.php?id_marca_veiculo="+valor+"&id_tipo="+tipo_veiculo;
	Dados_exibe_modelos(url);

}

function Dados_exibe_modelos(valor) {
	//verifica se o browser tem suporte a ajax
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}

	//se tiver suporte ajax
	if(ajax) {

		ajax.open("GET", valor, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function() {
			
			idloading_ajax = document.getElementById("opt_1_modelo");
			
			//enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
				
				idloading_ajax.innerHTML = "Carregando...";
				
			}else { 
				
				idloading_ajax.innerHTML = "Selecione o modelo";
				
			}
			
			//após ser processado - chama função processXML que vai varrer os dados
	      if(ajax.readyState == 4 ) {
	      	
			   if(ajax.responseXML) {
			   	
			      processXML_exibe_modelos(ajax.responseXML);
			      
			   }else {
			   	
//			   	alert("parou no else ajax.responseXML");
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idloading_ajax.value = "Selecione a Marca (erro xml)";
				   
			   }
	      }

	   }

		ajax.send(null);

	} // Fecha function Ajax

} // Fecha function Dados
   
function processXML_exibe_modelos(obj){
	
//	alert("entrou na processXML...");
	
   // pega a tag erro
   var dataArrays = obj.getElementsByTagName("resultado");
   
   document.getElementById("seleciona-modelo").options.length = 1;
		
  // total de elementos contidos na tag resultado
	if(dataArrays.length > 0) {
		
     // percorre o arquivo XML para extrair os dados
		for(var i = 0 ; i < dataArrays.length ; i++) {
			
			var item = dataArrays[i];

			var modelo = item.getElementsByTagName("modelo")[0].firstChild.nodeValue;
			var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;
			
			option = document.createElement("option");
			option.setAttribute("value",id);
			option.appendChild(document.createTextNode(modelo));
			
			document.getElementById('seleciona-modelo').appendChild(option);

		}

  }else{
  	
  			document.getElementById("seleciona-modelo").options.length = 1;

  }
}

function verifica_veiculos () {
	
	var tipo_veiculo = document.getElementById("seleciona-veiculo").value;
	//var marca_veiculo = document.getElementById("seleciona-marca").value;
	
	var arrayDados = new Array();
	
	arrayDados[0] = tipo_veiculo;
	//arrayDados[1] = marca_veiculo;

	var erro = 0;
	for (vkk = 0 ; vkk < arrayDados.length ; vkk++){
		if (arrayDados[vkk] == ""){
			erro++;
		}
	}
	
	if (erro > 0){
		alert("Selecione ao menos o tipo e a marca do veículo");
	} else {
		document.getElementById("form_busca_home").submit();
	}
	
}

function usados_sel (id_pai,funct,id_prox){
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	if(ajax) {
		ajax.open("GET", "inc/ajax_site/avalie_home.php?funcao="+funct+"&id_pai="+id_pai, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
		    if(ajax.readyState == 4 ) {
		    	if(ajax.responseXML) {
					var obj = ajax.responseXML;
					var dataArrays = obj.getElementsByTagName("resultado");
					if(dataArrays.length > 0) {
						
						document.getElementById(id_prox).options.length = 1;
						
						for(var i = 0 ; i < dataArrays.length ; i++) {
							var item = dataArrays[i];
							
							var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;
							var valor = item.getElementsByTagName("valor")[0].firstChild.nodeValue;
							
							if(id != 0 && valor != 0){
								option = document.createElement("option");
								option.setAttribute("value",id);
								option.appendChild(document.createTextNode(valor));
								
								document.getElementById(id_prox).appendChild(option);
							}
						}
					}
		    	}
		    }
		}
		ajax.send(null);
	}
}