// Define variável global
var xmlhttp;

function __cadastraNews(varForm) {

// Define variáveis
var varNome;
//var varTelefone;
var varEmail;
//var varSite;

var errorMsg = "";

// Atribui valores as variáveis
varNome  = escape(varForm.txtNome.value);
//varTelefone = escape(varForm.txtTelefone.value);
varEmail    = escape(varForm.txtEmail.value);
//varSite  = escape(varForm.txtSite.value);

//verifica os campos
	var ok = true;

    var tamanho = varEmail;
    var BadChars = "*|,\":<>[]{}`/'';()&$#% =+¨!?ª°º§^áéíóúäãü~õôâ´"; 
	
	if (varNome == "Nome" || varNome == ""){
		errorMsg += "\t O Campo Nome é de preenchimento obrigatório \n";
		varForm.txtNome.focus(); 
	}
	
	if (varEmail == "" || varEmail == "E-mail"){
		errorMsg += "\t O E-mail é de preenchimento obrigatório \n";
		varForm.txtEmail.focus(); 
	}
	
	if (varEmail.search("@") == -1) {
		errorMsg += "\t O E-mail deve conter " + "'" + "@" + "'" + "\n";
		varForm.txtEmail.focus(); 
	} else if (varEmail.search("[.*]") == -1) {
		errorMsg += "\t Seu E-mail não contém " + "'" + "." + "'" + "\n";
		varForm.txtEmail.focus(); 
	} else if (tamanho.length < 6) {
		errorMsg += "\t Seu E-mail não contém o mínimo de 6 caracteres - \n";
		varForm.txtEmail.focus(); 
	}
	
	for (var i = 0; i < tamanho.length; i++) { 
    	if (BadChars.indexOf(tamanho.charAt(i)) != -1) {
		   errorMsg += "\t Seu E-mail contém caracteres inválidos " + "'" + (tamanho.charAt(i)) + "'" + "\n";
           varForm.txtEmail.focus(); 
   	    }
    }

	if (errorMsg != ""){
		msg = "Para que este formulário seja enviado, os seguintes dados devem ser preenchidos:\n\n";
		errorMsg += alert(msg + errorMsg + "\n");
		return false;
	}

    // 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", "../Connections/cad_newsletter.asp", true);    

   xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   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 + "&txtTelefone=" + varTelefone + "&txtEmail=" + varEmail + "&txtSite=" + varSite);
   xmlhttp.send("txtNome=" + varNome + "&txtEmail=" + varEmail);
   //xmlhttp.open("POST", "../newsletter/newsletter.asp", true);
}


function processReqChange() {

    document.getElementById("newsletter").innerHTML = "Gravando 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("newsletter").innerHTML = "DADOS CADASTRADOS COM SUCESSO ! ! ! <br><br><br>";
   //window.location.href = "http://www.wmonline.com.br";     Redireciona para uma pagina....
     } else
   document.getElementById("newsletter").innerHTML = xmlhttp.responseText;
       } else {
           alert("Problemas ao carregar o arquivo.");
       }
   }

}