//=== Função para verificar se um e-mail é válido ===
function ValidaEmail(objEmail, strCampo) {
  //Declarar variáveis
  var strEmail   = objEmail.value;

  var strLetras  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var strValidos = strLetras + "0123456789-_.";

  //Verificar tamanho
  if (strEmail.length < 5) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  //Verificar "@"
  intPosicao = strEmail.indexOf("@");

  if (intPosicao < 1) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  strParte1 = strEmail.substring(0             , intPosicao     );
  strParte2 = strEmail.substring(intPosicao + 1, strEmail.length);

  //Verificar "."
  intPosicao = strParte2.indexOf(".");

  if (intPosicao < 1) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }
  
  strParte3 = strParte2.substring(intPosicao + 1, strParte2.length);
  strParte2 = strParte2.substring(0             , intPosicao      );

  //Verificar tamanho das partes
  if (strParte1.length == 0 || strParte2.length == 0 || strParte3.length == 0) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  //Verificar particularidades das partes
  if (strParte1.charAt(0) == "." || strParte3.charAt(0) == ".") {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  if (strLetras.indexOf(strParte1.charAt(0)) == -1) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  if (strLetras.indexOf(strParte2.charAt(0)) == -1) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  if (strLetras.indexOf(strParte3.charAt(0)) == -1) {
    alert("Por favor, preencha o " + strCampo + " de forma correta.");
    objEmail.focus();
    return false;
  }

  //Verificar se existe algum caracter não válido
  for (var i = 1; i <= 3; i++) {
    strParte = eval("strParte" + i);

    for (var j = 0; j < strParte.length; j++) {
      strCaracter = strParte.substring(j, j + 1);

      if (strValidos.indexOf(strCaracter) == -1) {
        alert("Por favor, preencha o " + strCampo + " de forma correta.");
        objEmail.focus();
        return false;
      }
    }
  }

  //Retornar ok
  return true;
}
