
$(document).ready(function () {
$("#loginForm").submit(function()
 {



 valorLogin=Trim($("input#txtLogin").val());
 valorSenha=Trim($("input#txtSenha").val());


 if(valorLogin=="" || valorSenha=="")
 {
	
	$("#loginMessage").html("Preencha os campos de login e senha").removeClass().addClass('loginValidationError').show("normal");
	setTimeout("hideLoginErrorMessage()",3000);
	 
	return false;
 }
 	
 $("#imgButtonEnter").attr("disabled","disabled");
 
 	 //remove all the class add the messagebox classes and start fading
        $("#loginMessage").removeClass().addClass('loginValidation').text('Validando....').fadeIn(1000);
        //check the username exists or not from ajax
        $.post("portal/authenticate/dologin",{ login:$('#txtLogin').val(),password:$('#txtSenha').val() } ,function(data)
        {
          if(data=='ok') //if correct login detail
          {
                $("#loginMessage").fadeTo(200,0.1,function()  //start fading the messagebox
                {
                  //add message and change the class of the box and start fading
                  $(this).html('Aguarde...').fadeTo(900,1,
                  function()
                  {
                   document.location='portal/default';
					 
                     
                  });
                });
          }
          else
          {
                $("#loginMessage").fadeTo(200,0.1,function() //start fading the messagebox
                {
				 //$("#loginForm").reset
                  //add message and change the class of the box and start fading
                  $(this).html(data).removeClass().addClass('loginValidationError').fadeTo(900,1);
				  setTimeout("hideLoginErrorMessage()",3000);
                });
          }
          $("#imgButtonEnter").removeAttr("disabled");
       });
        
       return false;//not to post the  form physically

 })
});

 
 function hideLoginErrorMessage()
 {
  $("#loginMessage").fadeOut("normal");
  
  // $('#loginForm')[0].reset();
  $("#txtLogin").focus();
 }