﻿// JScript File

function Logar()
{
    var sucesso = true;
    
    // Define os estilos padrões
    document.getElementById('login_usuario').className = 'txtfield';
    document.getElementById('errologin_usuario').style.display = 'none';
    
    
    document.getElementById('login_senha').className = 'txtfield';
    document.getElementById('errologin_senha').style.display = 'none';
    
    if(EmptyField(document.getElementById('login_usuario')))
    {
        sucesso = false;
        document.getElementById('login_usuario').className = 'error';
        document.getElementById('errologin_usuario').style.display = 'block';
        document.getElementById('errologin_usuario').innerHTML = 'Por favor informe seu login.'  
    }
    
    if(EmptyField(document.getElementById('login_senha')))
    {
        sucesso = false;
        document.getElementById('login_senha').className = 'error pass';
        document.getElementById('errologin_senha').style.display = 'block';
        document.getElementById('errologin_senha').innerHTML = 'Por favor informe sua senha.'  
    }
    
   if (!sucesso) {
       document.getElementById('errologin_usuario').innerHTML = 'Alguns campos não foram preenchidos da forma devida. Por favor verifique os campos em destaque.'; 
	   document.getElementById('errologin_usuario').style.display = 'block';
        return false;
    }
    
    //Verifica Login e senha no servidor.
    if(!includes_include_header.Logar(document.getElementById('login_usuario').value,document.getElementById('login_senha').value).value)
    {
        document.getElementById('errologin_usuario').innerHTML = 'Dados incorretos. Por favor verifique a digitação e tente novamente.'; 
		document.getElementById('errologin_usuario').style.display = 'block';
		document.getElementById('login_usuario').className = 'error';
		document.getElementById('login_senha').className = 'error';
		
        document.getElementById('login_senha').value = '';
        document.getElementById('login_usuario').focus();
        return false;
    }
    else{
        window.location = 'painel.aspx';
    }
}

function Deslogar()
{
    includes_include_header.Deslogar();
    
    window.location = 'default.aspx';            
}
//Função para ao se dá um Enter cair sobre o evento de submit da pagina de contato
//param:evt = Evento do keyPress
//param:botao = Id do botão que dá o submit na página
function EnterLogin(evt,botao)
{
    //Verificando se o que é digitado é somente campos numéricos
    var charCode = (evt.which) ? evt.which : evt.keyCode;
  
    if(charCode==13)
    {
         document.getElementById(botao).onclick();		
         return false;
    }
    return true;
}