try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

atual=0
function abrirPag(n){

    //Exibe o texto carregando no div conteúdo
    var conteudo=document.getElementById("conteudo")
    conteudo.innerHTML='<div class="carregando">carregando...</div>'

    //Guarda a página escolhida na variável atual
    atual=n

    //Abre a url
    xmlhttp.open("GET", n,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText

            //Desfaz o urlencode
            texto=texto.replace(/\+/g," ")
            texto=unescape(texto)

            //Exibe o texto no div conteúdo
            var conteudo=document.getElementById("conteudo")
            conteudo.innerHTML=texto

 

            //Limpa as classes do menu
            
        }
    }
    xmlhttp.send(null)
}

function Contato_enviar() {
  var nome = document.getElementById('nome');
  var email = document.getElementById('email');
  var telefone = document.getElementById('telefone');
  var comentario = document.getElementById('textareacomentario');
  
  // validar os dados preenchidos
  nome.value = nome.value.replace(/^\s+|\s+$/g,'');// um espaço ou mais no início ou no final da linha: removemos.
  if (nome.value == "") {
    alert('Informe o seu nome');
    return false;
  }

  email.value = email.value.replace(/\s+/g,'');// qualquer espaço: removemos.
  if (email.value == "") {
    alert('Informe o seu email para contato');
    return false;
  }
  
  if (!/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test( email.value )) {
    alert('O endereco de email nao e valido');
    return false;
  }

  if (telefone.value == "") {
    alert('Informe o seu telefone para contato');
    return false;
  }
  
  var url = "./ws/contato.php?N=" + nome.value 
            + "&E=" + email.value
            + "&F=" + telefone.value
            + "&C=" + comentario.value
            + "&UID=" + new Date().getTime();
  xmlhttp.open("GET", url,true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4){
    var msg = ( xmlhttp.responseText || 'Nenhuma informacao sobre a remessa do contato.\nPor favor, tente novamente mais tarde.' );
    alert(msg.replace(/<br>/g, "\n"));
    }
  }
  xmlhttp.send(null)
    
}

