//Parte AJAX da coisa! 
//AGCORP - Abdenego 2008-2010


//------funcao para trocar o TAB pelo Enter no formulario trabalhe
//use assim no form: <input type="text" name="campo1" size="45" onFocus="nextfield = 'trabalhe.campo2';"> 
//evento: onFocus chamando o prox. campo


netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
   netscape = (ver.charAt(iln+1).toUpperCase() != "C");
   
   function keyDown(DnEvents) {
      // ve quando e o netscape ou IE
      k = (netscape) ? DnEvents.which : window.event.keyCode;
      if (k == 13) { // pressiona tecla enter
      if (nextfield == 'trabalhe.done') {
         return true; // envia quando termina os campos
      }
	  if (nextfield == 'cotacao.done') {
         return true; // envia quando termina os campos
      }
	  if (nextfield == 'contato1.done' || nextfield == 'contato2.done' || nextfield == 'contato3.done') {
         return true; // envia quando termina os campos
      }
	  else {
         // se existem mais campos vai para o proximo
         eval('document.' + nextfield + '.focus()');
         return false;
      }
   }
}

document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);                

function confirmaExclusao(aURL) {
	if(confirm('Voce tem certeza que deseja excluir este registro?')) {
	location.href = aURL;
	}
}


function limpaCache(url)
{
   if (url.indexOf("?") >=0 ) return url + "&rand=" + encodeURI(Math.random());
   		else return url + "?randon=" + encodeURI(Math.random());
}


function mostraCompras( prod, desc, quan, acao, pp, metodo )
{
  //acao = inserir, excluir
  if (acao == "") acao = "inserir";
  
  pagina = limpaCache("montacompras.php?prod=" + prod + "&desc=" + desc + "&quan=" + quan + "&acao=" + acao + "&pp=" + pp + "&metodo=" + metodo);
  http.open("GET", pagina, true);
  mostra_div("espera");
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);	
}


function finalizaCompras()
{
	
d = document.cotacao;
		 //validar nome
		 if (d.nome.value == "" || d.nome.value == "NOME"){
                   //alert("O campo Nome deve ser preenchido!");
                     d.nome.focus();
                     return false;
		 }
		 //validar email
         if (d.email.value == ""  || d.email.value == "EMAIL"){
                   //alert("O campo Email deve ser preenchido!");
                   d.email.focus();
                   return false;

         }
         //validar email(verificacao de endereco eletrônico)
         parte1 = d.email.value.indexOf("@");
         parte2 = d.email.value.indexOf(".");
         parte3 = d.email.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                   //alert ("O campo Email deve conter um endereco eletronico!");
                   d.email.focus();
                   return false;
         }
		 //validar telefone
		 if (d.tel.value == "" || d.tel.value == "TELEFONE"){
                   //alert("O campo Telefone deve ser preenchido!");
                     d.tel.focus();
                     return false;
		 }

  
 // pagina = limpaCache("enviar_cotacao.php?nome="+d.nome.value+"&email="+d.email.value+"&tel="+d.tel.value+"&vendedor="+d.vendedor.value);
  pagina = limpaCache("enviar_cotacao.php?nome="+d.nome.value+"&email="+d.email.value+"&tel="+d.tel.value);
  http.open("GET", pagina, true);
  mostra_div("espera");
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function excluiItem( id, pp, metodo )
{
  //acao = inserir, atualizar, excluir
  acao = "excluir";
  
  pagina = limpaCache("montacompras.php?id=" + id + "&acao=" + acao + "&pp=" + pp + "&metodo=" + metodo);
  http.open("GET", pagina, true);
  mostra_div("espera");
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function loginAdm( usuario,senha )
{
	
  http.open("GET", "testaloginAdmin.php?login="+usuario+"&senha="+senha, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function loginUser( usuario,senha )
{
	
  http.open("GET", "testaloginUser.php?login="+usuario+"&senha="+senha, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}


function paginaAdm( subpagina,ordem,pagin,fatura,de,ate,pagto,servico )
{
  pagina = limpaCache( "subgerenciamento.php?pagina="+subpagina+"&ordem="+ordem+"&pp="+pagin+"&fatura="+fatura+"&de="+de+"&ate="+ate+"&pagto="+pagto+"&servico="+servico);
  http.open("GET", pagina, true);
  mostra_div("espera");
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function enviarFeedback()
{
	
	   d = document.feedback;
		 //validar nome
		  if (d.nomefeed.value == ""){
                     d.nomefeed.focus();
                     return false;
		  }
		 //validar email
         if (d.emailfeed.value == ""){
                  // alert("O campo Email deve ser preenchido!");
                   d.emailfeed.focus();
                   return false;
         }
         //validar email(verificacao de endereco eletrônico)
         parte1 = d.emailfeed.value.indexOf("@");
         parte2 = d.emailfeed.value.indexOf(".");
         parte3 = d.emailfeed.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                  // alert ("O campo Email deve conter um endereco eletronico!");
                   d.emailfeed.focus();
                   return false;
         }
		//validar msg
         if (d.msgfeed.value == ""){
                  // alert("O campo CPF deve ser preenchido!");
                   d.msgfeed.focus();
                   return false;
         }
	
  mostra_div("esperafeed");	
  pagina = limpaCache( "enviar_feedback.php?nome="+d.nomefeed.value+"&email="+d.emailfeed.value+"&msg="+d.msgfeed.value);
  http.open("GET", pagina, true);
  http.onreadystatechange = retornoFormfeedback;
  http.send(null);
}

function editaBoleto(numdoc,valor,dtvenc,selectstatus,dtpagto)
{
	//for (i=0; i<selectstatus.length; i++)
	//	if (selectstatus[i].selected) stpagto = selectstatus[i].value;
  mostra_div("espera");
  http.open("GET", "editar_boleto.php?numdoc="+numdoc+"&valor="+valor+"&dtvenc="+dtvenc+"&stpagto="+selectstatus+"&dtpagto="+dtpagto, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function editaContato(cod,nome,razao,cnpj,cpf,contato,end,num,bairro,comp,cep,cidade,uf,tel1,tel2,mail1,mail2,elog,epas)
{
	//for (i=0; i<selectstatus.length; i++)
	//	if (selectstatus[i].selected) stpagto = selectstatus[i].value;
  mostra_div("espera");
  http.open("GET", "editar_contato.php?cod="+cod+"&nome="+nome+"&razao="+razao+"&cnpj="+cnpj+"&cpf="+cpf+"&contato="+contato+"&end="+end+"&num="+num+"&bairro="+bairro+"&comp="+comp+"&cep="+cep+"&cidade="+cidade+"&uf="+uf+"&tel1="+tel1+"&tel2="+tel2+"&mail1="+mail1+"&mail2="+mail2+"&elog="+elog+"&epas="+epas, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function salvaContato(tipo,nome,razao,cnpj,cpf,contato,end,num,bairro,comp,cep,cidade,uf,tel1,tel2,mail1,mail2,elog,epas)
{
	//for (i=0; i<selectstatus.length; i++)
	//	if (selectstatus[i].selected) stpagto = selectstatus[i].value;
  mostra_div("espera");
  http.open("GET", "salvar_contato.php?tipo="+tipo+"&nome="+nome+"&razao="+razao+"&cnpj="+cnpj+"&cpf="+cpf+"&contato="+contato+"&end="+end+"&num="+num+"&bairro="+bairro+"&comp="+comp+"&cep="+cep+"&cidade="+cidade+"&uf="+uf+"&tel1="+tel1+"&tel2="+tel2+"&mail1="+mail1+"&mail2="+mail2+"&elog="+elog+"&epas="+epas, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}


function editaServico(cod,servico,data,valor,ativo,juros)
{
	if (ativo.checked) ativov = 1; else ativov = 0;
	if (juros.checked) semjurosv = 0; else semjurosv = 1;
	
  mostra_div("espera");
  http.open("GET", "editar_servico.php?cod="+cod+"&servico="+servico+"&data="+data+"&valor="+valor+"&ativo="+ativov+"&semjuros="+semjurosv, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}

function salvaServico(contato,servico,data,valor,ativo,juros)
{
	if (ativo.checked) ativov = 1; else ativov = 0;
	if (juros.checked) semjurosv = 0; else semjurosv = 1;
	
  mostra_div("espera");
  http.open("GET", "salvar_servico.php?contato="+contato+"&servico="+servico+"&data="+data+"&valor="+valor+"&ativo="+ativov+"&semjuros="+semjurosv, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}



function enviarContato( nome,cidade,email,telefone,mensagem,formulario)
{
  mostra_div("esperacontato");	
  pagina = limpaCache( "enviar_contato.php?nome="+nome+"&cidade="+cidade+"&email="+email+"&telefone="+telefone+"&mensagem="+mensagem+"&formulario="+formulario);
  http.open("GET", pagina, true);
  http.onreadystatechange = retornoContato;
  http.send(null);
}


function retornoContato()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
		  esconde_div("esperacontato");
			var Retorno = http.responseText.split("|");
			var div = document.getElementById(Retorno[1]);
				div.innerHTML = Retorno[0];
	  }
	  else	
	  {
		var div = document.getElementById("esperacontato");
			div.innerHTML = "<div id='msg'>Houve um erro. Tente mais tarde.</div>";
	  }
  }
}

function retornoFormfeedback()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("msgfeedback");
				div.innerHTML = Retorno[0];
				esconde_div("esperafeed");
	  }
	  else	
	  {
		var div = document.getElementById("msgfeedback");
			div.innerHTML = "<p style='margin-left: 25px; padding: 0 30px 5px 5px;'>Houve um erro temporario no site. Tente novamente mais tarde.</p>";
			esconde_div("esperafeed");
	  }
  }
}


function retornoTrabalhe()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
		  esconde_div("esperatrabalhe");
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("retorno_trabalhe");
				div.innerHTML = Retorno[0];
				esconde_div("esperatrabalhe");
	  }
	  else	
	  {
		var div = document.getElementById("retorno_trabalhe");
			div.innerHTML = "<div id='msg'>Houve um erro. Tente mais tarde.</div>";
			esconde_div("esperatrabalhe");
	  }
  }
}


function handleHttpResponse()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("mensagemlogin");
				div.innerHTML = Retorno[0];
				esconde_div("espera");
	  }
	  else	
	  {
		var div = document.getElementById("mensagemlogin");
			div.innerHTML = "<div id='msg'>Houve um erro na solicitaçao. Tente mais tarde.</div>";
			esconde_div("espera");
	  }
  }
}

function handleHttpResponse2()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("lista_prod");
				div.innerHTML = Retorno[0];
				esconde_div("espera");	
				
	  }
	  else	
	  {
		var div = document.getElementById("lista_prod");
			div.innerHTML = "<div id='msg'>Houve um erro na solicitaçao. Tente mais tarde.</div>";
			esconde_div("espera");
	  }
  }
}




function getHTTPObject() {
var req;

try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();

  if (req.readyState == null) {
   req.readyState = 1;
   req.addEventListener("load", function () {
   req.readyState = 4;

   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }

  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];

  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};
  }
 }
} catch (ex) {}

alert("XmlHttp Objects not supported by client browser");
}
var http = getHTTPObject();



//funcoes de timer


var segs
var timerID = null
var tempoAndando = false
var delay = 1000

function ContarSegEexibirMens(n,mensagem,qualdiv)
{
    segs = n
    PareContagem()
	InicieContagem(mensagem,qualdiv)
}

function PareContagem()
{
    if(tempoAndando)
        clearTimeout(timerID)
    tempoAndando = false
}

function InicieContagem(mensagem,qualdiv)
{
    if (segs==0)
    {
        PareContagem()
		MensagemFinal(mensagem,qualdiv)	

    }
    else
    {
        self.status = segs
        segs = segs - 1
        tempoAndando = true
        timerID = self.setTimeout("InicieContagem('"+mensagem+"','"+qualdiv+"')", delay)
    }
	

}

function MensagemFinal(qualmensagem,qualdiv)
{
		div = document.getElementById(qualdiv);
        div.innerHTML = qualmensagem;
}

function mostra_div(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';  
		}  
		else {    
			if (document.layers) { // Netscape 4      
			document.id.display = 'block';
			}    
			else { // IE 4      
				 document.all.id.style.display = 'block';    
				 }  
		}
	}
	
function esconde_div(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
		}
		else {
			if (document.layers) { // Netscape 4
			document.id.display = 'none';    
			}    
			else { // IE 4      
			document.all.id.style.display = 'none';    
			}  
		}
	}

function trabalheForm(){
           d = document.trabalhe;
		 //validar nome
		  if (d.nome.value == "" || d.nome.value == "NOME COMPLETO"){
                  // alert("O campo Nome deve ser preenchido!");
                     d.nome.focus();
                     return false;
		  }
		  
		 //validar cpf
         if (d.cpfi.value == ""  || d.cpfi.value == "CPF"){
                  // alert("O campo CPF deve ser preenchido!");
                   d.cpfi.focus();
                   return false;
         }
		 
		 //validar email
         if (d.email.value == ""  || d.email.value == "EMAIL"){
                  // alert("O campo Email deve ser preenchido!");
                   d.email.focus();
                   return false;

         }
         //validar email(verificacao de endereco eletrônico)
         parte1 = d.email.value.indexOf("@");
         parte2 = d.email.value.indexOf(".");
         parte3 = d.email.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                  // alert ("O campo Email deve conter um endereco eletronico!");
                   d.email.focus();
                   return false;
         }
		
		 //validar endereco
         if (d.endereco.value == ""  || d.endereco.value == "ENDEREÇO"){
                  // alert("O campo Endereço deve ser preenchido!");
                   d.endereco.focus();
                   return false;
         }
		 
		 
		  //validar bairro
         if (d.bairro.value == ""  || d.bairro.value == "BAIRRO"){
                  // alert("O campo Bairro deve ser preenchido!");
                   d.bairro.focus();
                   return false;
         }
		 
		 
		  //validar cep
         if (d.cepi.value == ""  || d.cepi.value == "CEP"){
                  // alert("O campo CEP deve ser preenchido!");
                   d.cepi.focus();
                   return false;
         }
		 
		 		
		 //validar cidade
         if (d.cidade.value == ""  || d.cidade.value == "CIDADE"){
                  // alert("O campo Cidade deve ser preenchido!");
                   d.cidade.focus();
                   return false;
         }
		 
		 
		 //validar estado
         if (d.estado.value == ""  || d.estado.value == "UF"){
                 //  alert("O campo Estado deve ser preenchido!");
                   d.estado.focus();
                   return false;
         }
       
		 
		  //validar nascimento
         if (d.nascimento.value == ""  || d.nascimento.value == "DT. NASCIMENTO"){
                  // alert("O campo Nascimento deve ser preenchido!");
                   d.nascimento.focus();
                   return false;

         }
		 
		//validar celular
         if (d.celular.value == ""  || d.celular.value == "CELULAR"){
                  // alert("O campo Telefone Celular deve ser preenchido!");
                   d.celular.focus();
                   return false;
         }
		 
		 //validar escolaridade
         if (d.escolaridade.value == ""  || d.escolaridade.value == "ESCOLARIDADE"){
                 //  alert("O campo Escolaridade deve ser preenchido!");
                   d.escolaridade.focus();
                   return false;
         }
		 //validar atividade profissional
         if (d.atividade.value == ""  || d.atividade.value == "PROFISSÃO"){
                  // alert("O campo Profissão deve ser preenchido!");
                   d.atividade.focus();
                   return false;
         }
		
		lingua = "";
		if (d.radIngles.checked == true) lingua = " Fala Ingles, "; else lingua = " Nao fala Ingles, ";
		if (d.radEspanhol.checked == true) lingua = lingua+" Fala Espanhol, "; else lingua = lingua + " Nao fala Espanhol, ";
		if (d.radOutros.checked == true) lingua = lingua+" Fala outros Linguas. "; else lingua = lingua +" Nao fala outras linguas. ";
 
  pagina = limpaCache("enviar_trabalhe.php?nome="+d.nome.value+"&cpf="+d.cpfi.value+"&email="+d.email.value+"&end="+d.endereco.value+"&bairro="+d.bairro.value+"&cep="+d.cepi.value+"&cidade="+d.cidade.value+"&uf="+d.estado.value+"&nasc="+d.nascimento.value+"&estcivil="+d.estcivil.value+"&sexo="+d.sexo.value+"&cel="+d.celular.value+"&fone="+d.residencial.value+"&escol="+d.escolaridade.value+"&linguas="+lingua+"&ativ="+d.atividade.value+"&curso="+d.curso.value+"&exp1="+d.experiencia1.value+"&exp2="+d.experiencia2.value+"&exp3="+d.experiencia3.value+"&chaves="+d.palavras.value+"&obs="+d.complementares.value);
  
  http.open("GET", pagina, true);
  mostra_div("esperatrabalhe");
  http.onreadystatechange = retornoTrabalhe;
  http.send(null);
 }



function ValidaSubmeteContato(tipo,acao){
	
           d = document.formContato;
		   
		  if (d.nome.value == ""){
                   alert("Preencha o nome do contato");
                     d.nome.focus();
                     return false;
		  }
		  
		  if (d.razao.value == "" && tipo == 1){
                   alert("Preencha a Razao Social");
                     d.razao.focus();
                     return false;
		  }
		  
		  if (d.cnpj.value == "" && tipo == 1){
                   alert("Preencha o CNPJ");
                     d.cnpj.focus();
                     return false;
		  }
		  
		  if (d.contato.value == "" && tipo == 1){
                   alert("Preencha o Contato");
                     d.contato.focus();
                     return false;
		  }
		  
		  if (d.cpf.value == "" && tipo ==0){
                   alert("Preencha o CPF");
                     d.cpf.focus();
                     return false;
		  }
		  
		  if (d.endereco.value == ""){
                   alert("Preencha o endereco");
                     d.endereco.focus();
                     return false;
		  }
		  
		  if (d.num.value == ""){
                   alert("Preencha o numero do endereco");
                     d.num.focus();
                     return false;
		  }
		  
		  if (d.bairro.value == ""){
                   alert("Preencha o Bairro");
                     d.bairro.focus();
                     return false;
		  }
		  
		  if (d.cep.value == ""){
                   alert("Preencha o CEP");
                     d.cep.focus();
                     return false;
		  }
		  
		  if (d.cidade.value == ""){
                   alert("Preencha a Cidade");
                     d.cidade.focus();
                     return false;
		  }
		  
		  if (d.uf.value == ""){
                   alert("Preencha o Estado (UF) ");
                     d.uf.focus();
                     return false;
		  }
		  
		  if (d.tel1.value == ""){
                   alert("O campo telefone1 deve ser preenchido!");
                     d.tel1.focus();
                     return false;
		  }
		  
		  if (d.mail.value == ""){
                   alert("Preencha o Email de Cobranca");
                     d.mail.focus();
                     return false;
		  }
		  
		  if (d.elog.value == ""){
                   alert("Preencha o LOGIN do contato");
                     d.elog.focus();
                     return false;
		  }
		  
		  if (d.epas.value == ""){
                   alert("Preencha a SENHA do contato");
                     d.epas.focus();
                     return false;
		  }
		  
		  if (acao == "editar") {
	       		 editaContato(tipo,d.nome.value,d.razao.value,d.cnpj.value,d.cpf.value,d.contato.value,d.endereco.value,d.num.value,d.bairro.value,d.comp.value,d.cep.value,d.cidade.value,d.uf.value,d.tel1.value,d.tel2.value,d.mail.value,d.mail2.value,d.elog.value,d.epas.value);
		  }
		  if (acao == "salvar") {
	       		 salvaContato(tipo,d.nome.value,d.razao.value,d.cnpj.value,d.cpf.value,d.contato.value,d.endereco.value,d.num.value,d.bairro.value,d.comp.value,d.cep.value,d.cidade.value,d.uf.value,d.tel1.value,d.tel2.value,d.mail.value,d.mail2.value,d.elog.value,d.epas.value);
		  }
		  
				return true;
 }
 
 
function validaformContato(d, nomeform){

		 //validar nome
		  if (d.nome.value == ""){
                  // alert("O campo Nome deve ser preenchido!");
                     d.nome.focus();
                     return false;
		  }
		  
		 //validar cidade
         if (d.cidade.value == ""){
                   //alert("O campo Cidade deve ser preenchido!");
                   d.cidade.focus();
                   return false;
         }


        //validar email
         if (d.email.value == ""){
                   //alert("O campo Email deve ser preenchido!");
                   d.email.focus();
                   return false;

         }
         //validar email(verificao de endereco eletrônico)
         parte1 = d.email.value.indexOf("@");
         parte2 = d.email.value.indexOf(".");
         parte3 = d.email.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                   //alert ("O campo Email deve conter um endereco eletronico!");
                   d.email.focus();
                   return false;
         }
		 
		//validar telefone
         if (d.tel.value == ""){
                   //alert("O campo Telefone deve ser preenchido!");
                   d.tel.focus();
                   return false;
         }
		 
         //validar mensagem
         if (d.msg.value == ""){
                   //alert("O campo Mensagem deve ser preenchido!");
                   d.msg.focus();
                   return false;
			    }
				
				
		enviarContato(d.nome.value,d.cidade.value,d.email.value,d.tel.value,d.msg.value,nomeform);		
		return true;
 }
 
 
 
 
 
 

/*

	AGCORP Network 2011 - Copyright Agcorp Servicos de Informatica Ltda
	Scripts desenvolvidos por Abdenego Santos
	
	//Funçoes para Carregar Conteudo em Ajax
	//AGCORP - Abdenego 2008/2010

*/

function cadastraEmail()
{
           d = document.FormNews;
		 //validar nome
		  if (d.news_nome.value == "" || d.news_nome.value=="NOME"){
                   alert("O campo Nome deve ser preenchido!");
                     d.news_nome.focus();
                     return false;
		  }
		  
		 //validar email
         if (d.news_email.value == "" || d.news_email.value=="EMAIL"){
                   alert("O campo Email deve ser preenchido!");
                   d.news_email.focus();
                   return false;
         }

  pagina = limpaCache( "mailling.php?nome="+d.news_nome.value+"&email="+d.news_email.value);
  http.open("GET", pagina, true);
  mostra_div("espera2");
  http.onreadystatechange = retorno_cadastraEmail;
  http.send(null);
}


function retorno_cadastraEmail()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("imprimeretorno");
				div.innerHTML = Retorno[0];
				esconde_div("espera2");
	  }
	  else	
	  {
		var div = document.getElementById("imprimeretorno");
			div.innerHTML = "ERRO";
			esconde_div("espera2");
	  }
  }
}


function retorno_cadastraEmail()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("imprimeretorno");
				div.innerHTML = Retorno[0];
				esconde_div("espera2");
	  }
	  else	
	  {
		var div = document.getElementById("imprimeretorno");
			div.innerHTML = "ERRO";
			esconde_div("espera2");
	  }
  }
}


function CadFormNews(  )
{
	
  pagina = limpaCache( "cad-email.php");
  http.open("GET", pagina, true);
  mostra_div("espera2");
  http.onreadystatechange = retorno_CadForm;
  http.send(null);
}

function retorno_CadForm()
{
  if (http.readyState == 4) {
	
	  if (http.status == 200) {
			var Retorno = http.responseText.split("|");
			var div = document.getElementById("imprimeretorno");
				div.innerHTML = Retorno[0];
				esconde_div("espera2");
	  }
	  else	
	  {
		var div = document.getElementById("imprimeretorno");
			div.innerHTML = "ERRO";
			esconde_div("espera2");
	  }
  }
}



function limpaCache(url)
{
   if (url.indexOf("?") >=0 ) return url + "&rand=" + encodeURI(Math.random());
   		else return url + "?randon=" + encodeURI(Math.random());
}


function getHTTPObject() {
var req;

try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();

  if (req.readyState == null) {
   req.readyState = 1;
   req.addEventListener("load", function () {
   req.readyState = 4;

   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }

  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];

  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};
  }
 }
} catch (ex) {}

alert("XmlHttp Objects not supported by client browser");
}
var http = getHTTPObject();





function MensagemFinal(qualmensagem,qualdiv)
{
		div = document.getElementById(qualdiv);
        div.innerHTML = qualmensagem;
}


function mostra_div(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';  
		}  
		else {    
			if (document.layers) { // Netscape 4      
			document.id.display = 'block';
			}    
			else { // IE 4      
				 document.all.id.style.display = 'block';    
				 }  
		}
	}
	
function esconde_div(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
		}
		else {
			if (document.layers) { // Netscape 4
			document.id.display = 'none';    
			}    
			else { // IE 4      
			document.all.id.style.display = 'none';    
			}  
		}
	}



