function createXMLHTTP() 
 {
  var ajax;
  try 
  {
   ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) 
  {
   try 
   {
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
    alert(ajax);
   }
   catch(ex) 
   {
    try 
    {
     ajax = new XMLHttpRequest();
    }
    catch(exc) 
    {
      alert("Esse browser não tem recursos para uso do Ajax");
      ajax = null;
    }
   }
   return ajax;
  }
 
 
     var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
           "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
           "Microsoft.XMLHTTP"];
     for (var i=0; i < arrSignatures.length; i++) 
     {
    try 
    {
     var oRequest = new ActiveXObject(arrSignatures[i]);
     return oRequest;
    } 
    catch (oError) 
    {
       }
     }
  
      throw new Error("MSXML is not installed on your system.");
 }
 
function CarregarModelo(campo,destino,funcao){
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", caminho_virtual+"/include/consultas/veiculos.asp", true);
		document.all.div_atualizar.style.display = "block";
		document.getElementById(destino).options.length = 0;
		document.getElementById(destino).options.add(new Option("Escolher...", ""))
     	oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    oHTTPRequest.onreadystatechange=function(){
	    	if (oHTTPRequest.readyState==4)
			{
				if(oHTTPRequest.status == 200 || oHTTPRequest.status == 404 || oHTTPRequest.status == 500){
					rp = oHTTPRequest.responseText;
					rp = rp.replace(/\+/g," ");
					rp = unescape(rp);
					arr = rp.split("|");
					document.getElementById(destino).options.length = 0;
					document.getElementById(destino).options.add(new Option("Escolher...", ""));
					for (i = 0; i < arr.length -1; i++)
					{
						codigo = arr[i++];
						descricao = arr[i];
						document.getElementById(destino).options.add(new Option(descricao,codigo));
					}
					document.all.div_atualizar.style.display = "none";
				} else
					alert("Erro na consulta dos dados. \nErro: "+req.statusText)
			}
		}
		oHTTPRequest.send("funcao=" + funcao + "&valor="+ campo.value);
}
function CarregarAno(campo,destino,funcao){
     var oHTTPRequest = createXMLHTTP(); 
	 var ano_fabricacao = destino+'_fabricacao';
	 var ano_modelo = destino+'_modelo';
     oHTTPRequest.open("post", caminho_virtual+"/include/consultas/veiculos.asp", true);
		document.all.div_atualizar.style.display = "block";
		document.getElementById(ano_fabricacao).options.length = 0;
		document.getElementById(ano_fabricacao).options.add(new Option("Escolher...", ""))
		document.getElementById(ano_modelo).options.length = 0;
		document.getElementById(ano_modelo).options.add(new Option("Escolher...", ""))
     	oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    oHTTPRequest.onreadystatechange=function(){
	    	if (oHTTPRequest.readyState==4)
			{
				if(oHTTPRequest.status == 200 || oHTTPRequest.status == 404 || oHTTPRequest.status == 500){
					rp = oHTTPRequest.responseText;
					arr = rp.split("|");
					document.getElementById(ano_fabricacao).options.length = 0;
					document.getElementById(ano_modelo).options.length = 0;
					document.getElementById(ano_fabricacao).options.add(new Option("Escolha...", ""));
					document.getElementById(ano_modelo).options.add(new Option("Escolha...", ""));
					for (i = 0; i < arr.length -1; i++)
					{
						codigo = arr[i];
						descricao = arr[i];
						document.getElementById(ano_fabricacao).options.add(new Option(descricao,codigo));
						document.getElementById(ano_modelo).options.add(new Option(descricao,codigo));
					}
					//document.getElementById(ano_fabricacao).options.add(new Option(arr[arr.length-2]-1, arr[arr.length-2]-1));
					document.all.div_atualizar.style.display = "none";
				} else
					alert("Erro na consulta dos dados. \nErro: "+req.statusText)
			}
		}
		oHTTPRequest.send("funcao=" + funcao + "&valor="+ campo.value);
}
function ConsultaLoginSenha(funcao,login,senha){
	 if ((login != '') && (senha != '')) {
	    var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", caminho_virtual+"/include/consultas/consulta.asp", true);
	 	document.all.div_contato_login_carregando.style.display = 'block';
		document.all.div_contato_login.style.display = 'none';
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    oHTTPRequest.onreadystatechange=function(){
	    	if (oHTTPRequest.readyState==4){
				if(oHTTPRequest.status == 200 || oHTTPRequest.status == 404 || oHTTPRequest.status == 500){
					resultado = oHTTPRequest.responseText
					document.all.div_contato_login.innerHTML = resultado;
					if (resultado.length > 3140) {
						document.getElementById("proximo").disabled = false;	
					}
			 		document.all.div_contato_login_carregando.style.display = 'none';
					document.all.div_contato_login.style.display = 'block';
				} else
					alert("Erro na consulta dos dados. \nErro: "+req.statusText)
			}
		}
		oHTTPRequest.send("funcao=" + funcao + "&login="+ login +"&senha="+ senha);
	 } else {
		 if (login == ''){
			 document.getElementById('login_contato').className = 'borda_erro';
		 } else {
			 document.getElementById('login_contato').className = 'borda_cadastro';
		 }
		 if (senha == ''){
			 document.getElementById('senha_contato').className = 'borda_erro';
		 } else {
			 document.getElementById('senha_contato').className = 'borda_cadastro';
		 }
	 }
}



