
function criaXMLHttpRequest() {
  var oXMLhttp = null;
 
 try 
  {
   oXMLhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) 
  {
   try 
   {
    oXMLhttp = new ActiveXObject("Msxml2.XMLHTTP");
    alert(oXMLhttp);
   }
   catch(ex) 
   {
    try 
    {
     oXMLhttp = new XMLHttpRequest();
    }
    catch(exc) 
    {
      alert("Esse browser não tem recursos para uso do Ajax");
      oXMLhttp = null;
    }
   }
   return oXMLhttp;
  }
     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 oXMLhttp = new ActiveXObject(arrSignatures[i]);
     return oXMLhttp;
    } 
    catch (oError) 
    {
       }
     }
 
      throw new oError("MSXML is not installed on your system.");
 }
																																																																																																	 

 
var oAjax = criaXMLHttpRequest();
function escrevemensagem(sMsg) {
document.getElementById('respostafinal').innerHTML = sMsg;
}

function EnviaPedido() {
var Nome = document.getElementById('nome');
var Telefone = document.getElementById('telefone');
var Email = document.getElementById('email');
var sURL = "envia_pedido.asp?nome=" + Nome.value + "&telefone=" + Telefone.value + "&email=" + Email.value + "";
oAjax.open("GET", sURL, true);
oAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oAjax.onreadystatechange = trataHttpResponse;
oAjax.send(null);
}

function trataHttpResponse() {

var exibeResultado = document.getElementById('respostafinal');
exibeResultado.style.display='';

if(oAjax.readyState == 2 || oAjax.readyState == 3 || oAjax.readyState == 1) {
                                exibeResultado.innerHTML = "<div id='carregando'><img src='ajax-loader.gif' alt='Carregando' />Enviando...</div>";
} else {

if(oAjax.readyState == 4) {
                                if(oAjax.status == 200) {
                                        var resultado = oAjax.responseText;
                                        exibeResultado.innerHTML = '<div style="background-color:#FFFFCC; color:#000000; ">'+ resultado+ '</div>';
                                } else {
                                        exibeResultado.innerHTML = "CEP incorreto";
                                }
                         } 
						 }
}



function BuscaCEP() {
var CEP = document.getElementById('cep');

var sURL = "busca_cep_endereco.asp?cep=" + CEP.value  + "";

oAjax.open("GET", sURL, true);
oAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oAjax.onreadystatechange = trataHttpResponse;
oAjax.send(null);
}

function trataHttpResponse() {

var exibeResultado = document.getElementById('respostafinalcep');
var exibeEndereco = document.getElementById('endereco');
var exibeBairro= document.getElementById('bairro');
exibeResultado.style.display='';

if(oAjax.readyState == 2 || oAjax.readyState == 3 || oAjax.readyState == 1) {
                                exibeResultado.innerHTML = "<div id='carregando'><img src='ajax-loader.gif' alt='Carregando' />Pesquisando...</div>";
} else {

if(oAjax.readyState == 4) {
                                if(oAjax.status == 200) {
                                        var resultado = oAjax.responseText.split(",");
                                        exibeEndereco.value = resultado[0];
										exibeBairro.value = resultado[1];
										exibeResultado.innerHTML = "<div style='display:inline'><img src='icn_ok.gif'></div>";
										var CursorNum= document.getElementById('endereco_num');
										CursorNum.focus()
                                } else {
                                        exibeResultado.innerHTML = "CEP incorreto";
                                }
                         } 
						 }
}


 // Envio email
 
 //Valida Visitas
function valida_solicitar_retirada() {

	if (document.getElementById('nome').value.length == 0) {
		alert('Informe seu nome');
		document.getElementById('nome').focus();
		return false;
	}
	
	if (document.getElementById('email').value.length == 0) {
        alert('Informe o seu e-mail');
        document.getElementById('email').focus();
        return false;
    }
	
	if (document.getElementById('email').value.indexOf('@', 0) == -1 || document.getElementById('email').value.indexOf('.', 0) == -1) {
		alert('E-mail incorreto'); 
        document.getElementById('email').focus();
        return false;
    }

    if (document.getElementById('telefone').value.length == 0) {
        alert('Informe seu telefone');
        document.getElementById('telefone').focus();
        return false;
    }
	
     if (document.getElementById('endereco').value.length == 0) {
		alert('Informe o seu endereco');
		document.getElementById('endereco').focus();
		return false;
	}

     if (document.getElementById('endereco_num').value.length == 0) {
		alert('Informe o numero do endereco');
		document.getElementById('endereco_num').focus();
		return false;
	}

	if (document.getElementById('bairro').value.length == 0) {
		alert('Informe o bairro');
		document.getElementById('bairro').focus();
		return false;
	}
	
	return true;
}


