// Define variável global
var xmlhttp;

function __cadastraCliente(varForm) {

// Define variáveis
var varNome;
var varEmail;
var varNomeInd;
var varEmailInd;

// Atribui valores as variáveis
varNome  = escape(varForm.txtNome.value);
varEmail = escape(varForm.txtEmail.value);
varNomeInd  = escape(varForm.txtNomeInd.value);
varEmailInd = escape(varForm.txtEmailInd.value);

    // Instancia o objeto, dependendo do navagador
    if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();  
    } else if (window.ActiveXObject) {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
    } else {
  alert("Seu navegador n&atilde;o suporta XMLHttpRequest.");
  return;
    }

    xmlhttp.open("POST", "recomenda-site.php", true);    

    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
    xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
    xmlhttp.setRequestHeader("Pragma", "no-cache");
    
    xmlhttp.onreadystatechange = processReqChange;

    xmlhttp.send("txtNome=" + varNome + "&txtEmail=" + varEmail + "&txtNomeInd=" + varNomeInd + "&txtEmailInd=" + varEmailInd);
}


function processReqChange() {

    document.getElementById("resposta").innerHTML = "Processando dados...";
    if (xmlhttp.readyState == 4) {    
  if (xmlhttp.status == 200) {
      // xmlhttp.responseText, recebe o valor da variavel $msg de cadastro.php
      if(xmlhttp.responseText == 1) {
    document.getElementById("resposta").innerHTML = "<br /><span style=\"color:green;\">Envio efetuado com sucesso!</span><br />";
    //window.location.href = "http://localhost:8080/perfil/";    // Redireciona para uma pagina....
      } else
    document.getElementById("resposta").innerHTML = xmlhttp.responseText;
      
        } else {
            alert("Houve um erro ao indicar este site.");
        }
    }

}

