function VerificaTecla(Tecla) {
   if (Tecla.keyCode == 13) {
      document.Comunidade.Senha.focus();
   }
}

function VerificaTecla2(Tecla) {
   if (Tecla.keyCode == 13) {
      EfetuaLogin();
   }
}

function ajaxInit() {
   var req;
   try {
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e) {
      try {
         req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(ex) {
         try {
            req = new XMLHttpRequest();
         } catch(exc) {
            alert("Esse browser não tem recursos para uso do Ajax");
            req = null;
         }
      }
   }
   return req;
}
   
function EfetuaLogout() {
   document.getElementById("Status").innerHTML = "<div style='float: left; line-height: 29px; text-align: left; font-weight: bold; width: 400px; padding-right: 3px; height: 29px; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 400px;'><tr><td width='120' align='right' valign='middle'><img src='/images06/loading5.gif' width='56' height='21' alt='aguarde, efetuando logout ...' /></td><td width='3'></td><td valign='middle'><font style='font-size: 11px;' color='darkred'>aguarde, efetuando logout ...</font></td></tr></table></div>";
   timerLogout = setTimeout("LogoutFinal()", 3500);
}

function LogoutFinal() {
   location.href = "/logout";
}
   
function EfetuaLogin() {
   CampoLogin = document.Comunidade.Login.value;
   CampoSenha = document.Comunidade.Senha.value;
   if (CampoLogin.length == 0) {
      alert("Informe o seu CDZ-ID ou seu e-Mail!");
      document.Comunidade.Login.focus();
   } else if (CampoSenha.length == 0) {
      alert("Informe a sua Senha!");
      document.Comunidade.Senha.focus();
   } else {
      ajax2 = ajaxInit();
      resultado = "";
      while (CampoLogin.indexOf("/") >= 0) {
          CampoLogin = CampoLogin.replace("/", "[¨traco¨]");
      }
      while (CampoSenha.indexOf("/") >= 0) {
          CampoSenha = CampoSenha.replace("/", "[¨traco¨]");
      }
      document.getElementById("Status").innerHTML = "<div style='line-height: 29px; text-align: left; width: 400px; padding-right: 3px; height: 29px; font-weight: bold; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 400px;'><tr><td width='126' align='right' valign='middle'><img src='/images06/loading5.gif' width='56' height='21' alt='aguarde, efetuando login ...' /></td><td width='3'></td><td align='left'><font style='font-size: 11px;' color='darkred'>aguarde, efetuando login ...</font></td></tr></table></div>";
      if (ajax2) {
         ajax2.open("GET", "/login/" + CampoLogin.toLowerCase() + "/" + CampoSenha.toLowerCase() + "/" + Math.ceil(Math.random() * 100000), true);
         ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         ajax2.onreadystatechange = function() {
             if (ajax2.readyState == 4) {
                 if (ajax2.status == 200) {
                     resultado = ajax2.responseText;
                     if (resultado.indexOf("OK") == 0) {
                         document.getElementById("Status").innerHTML = "<div style='line-height: 29px; text-align: center; font-weight: bold; width: 370px; padding-right: 3px; height: 29px; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 370px;'><tr><td width='96' align='right' valign='middle'><img src='/images10/topo/ok.png' width='16' height='16' alt='' border='0' /></td><td width='3'></td><td align='left'><font style='font-size: 11px;' color='darkgreen'>login efetuado com sucesso ...</font></td></tr></table></div>";
                         //history.go(0);
                         location.href = "/";
                     } else {
                         if (resultado.indexOf("E1") == 0) {
                             document.getElementById("Status").innerHTML = "<form method=\"post\" name=\"Comunidade\" action=\"\"><div id=\"fundologin\"><div style=\"border: 0px solid; width: 70px; height: 20px; float: left; margin-left: 55px; margin-top: 8px;\"><input type=\"text\" onkeydown=\"VerificaTecla(event);\" name=\"Login\" value=\"" + CampoLogin + "\" maxlength=\"255\" class=\"campoTexto2\" style=\"width: 85px; border: 0px solid;\" /></div><div style=\"border: 0px solid; width: 70px; height: 20px; float: left; margin-left: 73px; margin-top: 8px;\"><input onkeydown=\"VerificaTecla2(event);\" type=\"password\" name=\"Senha\" value=\"\" maxlength=\"255\" class=\"campoTexto2\" style=\"width: 66px; border: 0px solid;\" /></div><div style=\"border: 0px solid; width: 70px; text-align: center; height: 20px; float: left; margin-left: 3px; margin-top: 7px;\"><a href=\"javascript:EfetuaLogin();\"><img width=\"51\" height=\"16\" alt=\"Clique aqui para efetuar login na Comunidade Virtual\" src=\"/images06/login.gif\" onmouseout=\"this.src='/images06/login.gif';\" onmouseover=\"this.src='/images06/login2" + Tipo + ".gif';\" border=\"0\" /></a></div></div></form>";
                             alert("Login (CDZ-ID/e-Mail) e/ou Senha Inválidos!");
                         }
                         if (resultado.indexOf("IN") == 0) {
                             document.getElementById("Status").innerHTML = "<div style='line-height: 29px; text-align: center; font-weight: bold; width: 350px; padding-right: 3px; height: 29px; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 350px;'><tr><td width='26' align='right' valign='middle'><img src='/images10/topo/erro.png' width='16' height='16' alt='' border='0' /></td><td width='3'></td><td align='left'><font style='font-size: 11px;' color='darkred'>login inativo no sistema ...</font></td><td align='left'><a href='/enviar_codigo_de_ativacao'><img align='absmiddle' width='136' height='16' alt='Clique aqui para enviar o Código de Ativação da Comunidade Virtual' src='/images06/ativacao.gif' border='0' onmouseout=\"this.src='/images06/ativacao.gif';\" onmouseover=\"this.src='/images06/ativacao" + Tipo + ".gif';\" /></a></td></tr></table></div>";
                             alert("Login Inativo no Sistema. Para utilizá-lo é necessário ativá-lo!");
                         }
                         if (resultado.indexOf("E2") == 0) {
                             document.getElementById("Status").innerHTML = "<div style='line-height: 29px; text-align: center; font-weight: bold; width: 280px; margin-left: 35px; padding-right: 3px; height: 29px; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 280px;'><tr><td width='26' align='right' valign='middle'><img src='/images10/topo/erro.png' width='16' height='16' alt='' border='0' /></td><td width='3'></td><td align='left'><font style='font-size: 11px;' color='darkred'>servidor fora do ar ...</font></td><td align='left'><a href=\"javascript:TentarNovamente('" + CampoLogin + "');\"><img align='absmiddle' width='110' height='16' alt='Clique aqui para tentar efetuar Login novamente na Comunidade Virtual' src='/images06/novamente.gif' border='0' onmouseout=\"this.src='/images06/novamente.gif';\" onmouseover=\"this.src='/images06/novamente" + Tipo + ".gif';\" /></a></td></tr></table></div>";
                             alert("Servidor fora do ar. Tente novamente mais tarde!");
                         }
                     }
                 } else {
                     resultado = ajax2.statusText;
                     document.getElementById("Status").innerHTML = "<div style='line-height: 29px; text-align: center; font-weight: bold; width: 280px; margin-left: 35px; padding-right: 3px; height: 29px; border: 0px solid;'><table cellspacing='1' cellpadding='0' border='0' style='width: 280px;'><tr><td width='26' align='right' valign='middle'><img src='/images10/topo/erro.png' width='16' height='16' alt='' border='0' /></td><td width='3'></td><td align='left'><font style='font-size: 11px;' color='darkred'>servidor fora do ar ...</font></td><td align='left'><a href=\"javascript:TentarNovamente('" + CampoLogin + "');\"><img align='absmiddle' width='110' height='16' alt='Clique aqui para tentar efetuar Login novamente na Comunidade Virtual' src='/images06/novamente.gif' border='0' onmouseout=\"this.src='/images06/novamente.gif';\" onmouseover=\"this.src='/images06/novamente" + Tipo + ".gif';\" /></a></td></tr></table></div>";
                     alert("Servidor fora do ar. Tente novamente mais tarde!");
                 }
             }
         }
         ajax2.send(null);
      }
   }      
}

function TentarNovamente(CampoLogin) {
    document.getElementById("Status").innerHTML = "<form method=\"post\" name=\"Comunidade\" action=\"\"><div id=\"fundologin\"><div style=\"border: 0px solid; width: 70px; height: 20px; float: left; margin-left: 55px; margin-top: 8px;\"><input type=\"text\" onkeydown=\"VerificaTecla(event);\" name=\"Login\" value=\"" + CampoLogin + "\" maxlength=\"255\" class=\"campoTexto2\" style=\"width: 85px; border: 0px solid;\" /></div><div style=\"border: 0px solid; width: 70px; height: 20px; float: left; margin-left: 73px; margin-top: 8px;\"><input onkeydown=\"VerificaTecla2(event);\" type=\"password\" name=\"Senha\" value=\"\" maxlength=\"255\" class=\"campoTexto2\" style=\"width: 66px; border: 0px solid;\" /></div><div style=\"border: 0px solid; width: 70px; text-align: center; height: 20px; float: left; margin-left: 3px; margin-top: 7px;\"><a href=\"javascript:EfetuaLogin();\"><img width=\"51\" height=\"16\" alt=\"Clique aqui para efetuar login na Comunidade Virtual\" src=\"/images06/login.gif\" onmouseout=\"this.src='/images06/login.gif';\" onmouseover=\"this.src='/images06/login2" + Tipo + ".gif';\" border=\"0\" /></a></div></div></form>";
}
