/**
 * @author 2XT
 */

function verificaLoginAutomatico(){
	form = document.getElementById("frmLogin");
    if(document.getElementById("loginAutomatico").value){
	document.getElementById("login").value = document.getElementById("loginAutomatico").value;
	document.getElementById("senha").value = document.getElementById("senhaAutomatico").value;
	autenticarUsuario(form);
	}
}
 
function autenticarUsuario(form)
{ 
	/**
	@sumary: 
	@param formu: Formul�rio HTML, com os dados da pesquisa;
	@type formu: Object Html (Formul�rio);
	@author: Roberto Brasileiro
	*/
	var login = document.getElementById('login')
	var senha = document.getElementById('senha')
	with(form)
	{
		if(login.value != "" && senha.value != "" || form == 'visitante')
		{
			var handler = new XMLHandler();
			var xmlreq = new XMLClient('../modulos/cliente/autenticarUsuario/');
			if (form == 'visitante')
			{
			xmlreq.addParam('login', 'visitante');
			xmlreq.addParam('senha', 'visitante');
			}
			else
			{
			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 == 'visitante')
				{
				document.getElementById('frmLogin').submit();
				}
				else
				{
				if(resultado == 'logou')
				{
					form.submit();
				}
				else
				{
					document.getElementById("falha").innerHTML = String(resultado);
					document.getElementById("erro").style.display = "";
					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("falha").innerHTML = String(resultado);
			document.getElementById("erro").style.display = "";
			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.")
		}
               }
	  }
