var xmlhttp;

function enviaNews(str)
{
xmlhttp=GetXmlHttpObject();

document.getElementById("loader").style.display = "block";
document.getElementById("email").style.display = "none";
						
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }  
  /*inicia aqui*/
  var url = "cadastra_news.php";
  //Variaveis aqui especificadas por ID
  
  var params = "&email=" + encodeURI(document.getElementById("email").value );
  xmlhttp.open("POST", url, true);			   
  
  //Send the proper header information along with the request
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");
  
  xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
	  if(xmlhttp.readyState == 4) {
		  //alert(xmlhttp.responseText);
		  //Resetando os valores padrões do formulario
		  document.getElementById("loader").style.display = "none";
		  document.getElementById("email").style.display = "block";
		  
		  if(xmlhttp.responseText){
			  document.getElementById("email").value = xmlhttp.responseText;
		  }else{
		  	document.getElementById("email").value = "E-mail cadastrado com sucesso";
		  }
		  
	  }
  }
  xmlhttp.send(params);
  /*termina aqui*/
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
