/**********************************************************************************/
/***     CRIA UM OBJETO [XHR], PARA FUNCIONAR EM TODOS 					        ***/
/***     OS NAVEGADORES DA MESMA FORMA									        ***/
/**********************************************************************************/
/***	 UI:																	***/
/***	 var req = new 	XMLHTTPRequest()										***/
/***     PROPRIEDADES E METODOS:												***/
/***	 req.open (string : TIPO DE CGI, string : URL, boolean : true)			***/
/***	 req.send(null)															***/
/***	 req.readyState (vai de 1 a 4, sendo 1 = "conectando" e 4 = "recebido")	***/
/***	 req.responseText (valor retornado pelo endereco)						***/
/**********************************************************************************/
function XMLHTTPRequest() {
  try {
        return new XMLHttpRequest(); // FF, Safari, Konqueror, Opera, ...
  } catch(ee) {
        try {
          return new ActiveXObject("Msxml2.XMLHTTP"); // activeX (IE5.5+/MSXML2+)
        } catch(e) {
          try {
                return new ActiveXObject("Microsoft.XMLHTTP"); // activeX (IE5+/MSXML1)
          } catch(E) {
                return false; // doesn't support
          }
        }
  }
}

var ajaxNews = function () {
	
	var forme = document.getElementById('forme');
	var input_mail = document.getElementById('mail').value == '' ? null : document.getElementById('mail').value;
	var input_nome = document.getElementById('nome').value == '' ? null : document.getElementById('nome').value;
	if (input_mail && input_nome) {
		var url = 'inc/fnews.php?mail='+input_mail+'&nome='+input_nome;
		xhr = new XMLHTTPRequest();
		var conteiner = document.getElementById('retorno');
		xhr.open( 'get', url, true);
		xhr.onreadystatechange = function () {
			if ( xhr.readyState == 1) {

				conteiner.innerHTML = 'Aguarde...'; 
			}
			if (xhr.readyState == 4) { 
				if (xhr.responseText != 'Sucesso') {

					conteiner.innerHTML = 'Problemas na execu&ccedil;&atilde;o.';
				}
				else {
					conteiner.innerHTML = 'Obrigado! Seu e-mail foi adicionado com sucesso em nossa base de dados.';
				}
			}
		};
		xhr.send (null);
		return false;
	} else {
		return false;
	}
	
}


