//Inicio do Form de Contato

// Tabela de Idiomas
// 1 - Português
// 2 - Inglês
// 3 - Alemão
// 4 - Espanhol
// 5 - Frances
// 6 - Italiano

// Define variável global

var xmlhttp;
var Cod_Idioma;

function _email(varForm, varIdioma) {

// Define variáveis

var varNome;
var varEmail;
var varAssunto;
var varMensagem;

Cod_Idioma = varIdioma;

// Atribui valores as variáveis

varNome  = escape(varForm.formNome.value);
varEmail  = escape(varForm.formEmail.value);
varAssunto  = escape(varForm.formAssunto.value);
varMensagem  = escape(varForm.formMensagem.value);

if (varNome == "") {
  if (Cod_Idioma == "1"){ document.getElementById("resposta_contato").innerHTML = "Informar Nome Completo"; }
  if (Cod_Idioma == "2"){ document.getElementById("resposta_contato").innerHTML = "Inform your full name"; }
  if (Cod_Idioma == "3"){ document.getElementById("resposta_contato").innerHTML = "Vollständigen Namen eingeben"; }
  if (Cod_Idioma == "4"){ document.getElementById("resposta_contato").innerHTML = "Informe su nombre completo"; }
  if (Cod_Idioma == "5"){ document.getElementById("resposta_contato").innerHTML = "Introduire Nom complet"; }
  //if (Cod_Idioma == "6"){ document.getElementById("resposta_contato").innerHTML = ""; }
  document.frmcontato.formNome.focus();
  setTimeout("limpa_resposta()",8000);
  return false
}
if (varEmail == "") {
  if (Cod_Idioma == "1"){ document.getElementById("resposta_contato").innerHTML = "Informar E-mail"; }
  if (Cod_Idioma == "2"){ document.getElementById("resposta_contato").innerHTML = "Inform E-mail"; }
  if (Cod_Idioma == "3"){ document.getElementById("resposta_contato").innerHTML = "E-Mail eingeben"; }
  if (Cod_Idioma == "4"){ document.getElementById("resposta_contato").innerHTML = "Informe su E-mail"; }
  if (Cod_Idioma == "5"){ document.getElementById("resposta_contato").innerHTML = "Introduire E-mail"; }
  //if (Cod_Idioma == "6"){ document.getElementById("resposta_contato").innerHTML = ""; }
  document.frmcontato.formEmail.focus();
  setTimeout("limpa_resposta()",8000);
  return false
}
if (varEmail.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
  if (Cod_Idioma == "1"){ document.getElementById("resposta_contato").innerHTML = "E-mail inválido..."; }
  if (Cod_Idioma == "2"){ document.getElementById("resposta_contato").innerHTML = "Invalid E-mail..."; }
  if (Cod_Idioma == "3"){ document.getElementById("resposta_contato").innerHTML = "Ungültige Angaben..."; }
  if (Cod_Idioma == "4"){ document.getElementById("resposta_contato").innerHTML = "E-mail inválido..."; }
  if (Cod_Idioma == "5"){ document.getElementById("resposta_contato").innerHTML = "Données non valables..."; }
  //if (Cod_Idioma == "6"){ document.getElementById("resposta_contato").innerHTML = ""; }
  document.frmcontato.formEmail.focus();
  setTimeout("limpa_resposta()",8000);
  return false
}
if (varAssunto == "") {
  if (Cod_Idioma == "1"){ document.getElementById("resposta_contato").innerHTML = "Informar Assunto"; }
  if (Cod_Idioma == "2"){ document.getElementById("resposta_contato").innerHTML = "Inform Subject"; }
  if (Cod_Idioma == "3"){ document.getElementById("resposta_contato").innerHTML = "Betrifft eingeben"; }
  if (Cod_Idioma == "4"){ document.getElementById("resposta_contato").innerHTML = "Informe su Assunto"; }
  if (Cod_Idioma == "5"){ document.getElementById("resposta_contato").innerHTML = "Introduire Sujet"; }
  //if (Cod_Idioma == "6"){ document.getElementById("resposta_contato").innerHTML = ""; }
  document.frmcontato.formAssunto.focus();
  setTimeout("limpa_resposta()",8000);
  return false
}
if (varMensagem == "") {
  if (Cod_Idioma == "1"){ document.getElementById("resposta_contato").innerHTML = "Informar Mensagem"; }
  if (Cod_Idioma == "2"){ document.getElementById("resposta_contato").innerHTML = "Inform Message"; }
  if (Cod_Idioma == "3"){ document.getElementById("resposta_contato").innerHTML = "Nachricht eingeben"; }
  if (Cod_Idioma == "4"){ document.getElementById("resposta_contato").innerHTML = "Informe su Mensage"; }
  if (Cod_Idioma == "5"){ document.getElementById("resposta_contato").innerHTML = "Introduire Message"; }
  //if (Cod_Idioma == "6"){ document.getElementById("resposta_contato").innerHTML = ""; }
  document.frmcontato.formMensagem.focus();
  setTimeout("limpa_resposta()",8000);
  return false
}


   // Instancia o objeto, dependendo do navagador
    if (window.XMLHttpRequest) {
 	xmlhttp = new XMLHttpRequest();  
    } else if (window.ActiveXObject) {
  	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
    } else {
 	alert("Seu navegador n&atilde;o suporta XMLHttpRequest.");
 	return;
    }

   xmlhttp.open("POST", "envia_email.php", true);    

   xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
   xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
   xmlhttp.setRequestHeader("Pragma", "no-cache");
   
    xmlhttp.onreadystatechange = processReqChange;

   xmlhttp.send("formNome=" + varNome + "&formEmail=" + varEmail + "&formAssunto=" + varAssunto + "&formMensagem=" + varMensagem);
}


function processReqChange() {

   document.getElementById("resposta_contato").innerHTML = "<img src='loading_login.gif' />";
   if (xmlhttp.readyState == 4) {    
            if (xmlhttp.status == 200) {
            // xmlhttp.responseText, recebe o valor da variavel $msg de envia_email.php
            if(xmlhttp.responseText == 1) {
              document.getElementById("resposta_contato").innerHTML = "Enviado com Sucesso!";
              document.frmcontato.formNome.value="";
              document.frmcontato.formEmail.value="";
              document.frmcontato.formAssunto.value="";
              document.frmcontato.formMensagem.value="";
              document.frmcontato.formNome.focus();
              setTimeout("limpa_resposta()",8000);
            } else
              document.getElementById("resposta_contato").innerHTML = xmlhttp.responseText;
           } else {
             document.getElementById("resposta_contato").innerHTML = "Problemas ao carregar o arquivo.";
           }
   }
}

function limpa_resposta() {

 document.getElementById("resposta_contato").innerHTML = "";

}


