/**
 * @author 2XT
 */

function procuraEnterLogin(evt)
   {
      evt = (evt) ? evt : event;
      var c = (evt.which) ? evt.which : evt.keyCode;
      if (c == 13) {
         document.getElementById('login').submit();
         return false;
      }
      return true;
   };

function autenticarUsuario(form)
{ 
	/**
	@sumary: 
	@param formu: Formulário HTML, com os dados da pesquisa;
	@type formu: Object Html (Formulário);
	@author: Roberto Brasileiro
	*/
	with(form)
	{
		if(login.value != "" && senha.value != "")
		{
			var handler = new XMLHandler();
			var xmlreq = new XMLClient('../modulos/cliente/autenticarUsuario/');
			xmlreq.addParam('login', login.value);
			xmlreq.addParam('senha', senha.value);
			handler.onError = function (e) {alert(e)}
			handler.onProgress = function () {}
			handler.onInit = function () {}
			handler.onLoad = function(resultado) 
			{
				if(resultado == 'logou')
				{
					form.submit();
				}
				else
				{
					document.getElementById("naoencontrado").style.display = "none";
                    			document.getElementById("sucesso").style.display = "none";
                    			var id = document.getElementById("falha");
					id.style.display = 'block';
				}	
			}
			xmlreq.query(handler);
		}
		else
		{
			document.getElementById("naoencontrado").style.display = "none";
                    	document.getElementById("sucesso").style.display = "none";
			document.getElementById("falha").style.display = "block";
		}
	}
}

function verificarEmail(form)
{
	/**
	@sumary: 
	@param formu: Formulário HTML, com os dados da pesquisa;
	@type formu: Object Html (Formulário);
	@author: Roberto Brasileiro
	*/
        if( !validaEmail2(document.getElementById('email').value) ){
          alert('Formato de E-mail inválido! Favor consertar.');
          return;
        }
	with(form)
	{
		if(email.value != "")
		{
			var handler = new XMLHandler();
			var xmlreq = new XMLClient('../modulos/cliente/esqueceuEmail/');
			xmlreq.addParam('email', email.value);
                        xmlreq.addParam('nomeagencia', nomeagencia.value);
			handler.onError = function (e) {alert(e)}
			handler.onProgress = function () {}
			handler.onInit = function () {}
			handler.onLoad = function(resultado) 
			{
				if(resultado == 'enviado')
				{
                    alert("Email enviado com sucesso!")
				}
				else
				{
                    alert("Email nao encontrado na base de dados.")
				}	
			}
			xmlreq.query(handler);
			toggle();
			email.value = ""
		}
		else
		{
            alert("Digite o email pra continuar.")
		}
               }
	  }
