// JavaScript Document
function fnNewsletter(email, nome, natal){
	//window.alert("Email --> " + email + " | Nome --> " + nome + " | Natal --> " + natal);
	if(fnValidaEmail(email)){

		var req = null; 
	
		if (window.XMLHttpRequest){
		
			req = new XMLHttpRequest();
			if (req.overrideMimeType){
				req.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject){
		
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e){
			
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	
		req.onreadystatechange = function() { 
		
			if(req.readyState == 4)	{
				
				if(req.status == 200) {
					
					var doc = req.responseText;
					//window.alert(doc);
					
					if("ok"==doc){
						window.alert("Cadastro Concluido com Sucesso!");
					} else if("no"==doc){
						window.alert("Desculpe! N"+String.fromCharCode(227)+"o foi poss"+String.fromCharCode(237)+"vel o Cadastro!\nTente novamente mais tarde! Obrigado!");	
					} else if("has"==doc){
						window.alert("Este E-mail j"+String.fromCharCode(225) +" cadastrado! Obrigado!");
					}
				}
			} 
		};
		
		var args = "&email=" + email + "&nome=" + nome + "&natal=" + natal + "&";
		
		req.open("POST", "workers/newsletter_in.php", true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send(args);
		
	} else {
		window.alert("Desculpe! Este não é um email válido!");
	}
}

//Validando Emails
function fnValidaEmail(emailad){
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return false;
	}
	else {
		return true;
	}
}