function requisitarLogin(pagina_resultado) {
	
	if(document.getElementById('usuario_sistema_login_formatado')) {
		usuario_sistema_login = document.getElementById('usuario_sistema_login_formatado').value;
		formatado = true;
	} else {
		usuario_sistema_login = document.getElementById('usuario_sistema_login').value;
		formatado = false;
	}
	usuario_sistema_senha = document.getElementById('usuario_sistema_senha').value;
	if(usuario_sistema_login == '' || usuario_sistema_senha == '') {
		alert('Preencha o login e senha.');
		return false;
	}
	// OCULTAR BOTÕES DE OK E CANCELAR:
	if(document.getElementById('cancelar')) {
		document.getElementById('cancelar').style.display = 'none';
	}
	document.getElementById('entrar').style.display = 'none';
	
	// REQUISITAR AJAX:
	modo_debugger_ajax = false;
	url = RAIZ_SITE + "sistema/biblioteca/processamento.php";
	parametros = 'acao=logar&nome_dado=pessoa&usuario_sistema_login' + (formatado ? '_formatado' : '') + '=' + usuario_sistema_login + '&usuario_sistema_senha=' + usuario_sistema_senha
	if(typeof(pagina_resultado) != 'undefined') {
		parametros += '&pagina_resultado=' + pagina_resultado;
	}
	_preloader = (document.getElementById('preloader_login') ? 'preloader_login' : null);
	objetoRequisicaoDados = new requisicaoDados(url, parametros, resultadoLogin, cancelarRequisicaoLogin, _preloader, '');
}

function resultadoLogin() {
	if(resultado_ajax == 'login_aceito') {

		// exibir "redirecionando"
		document.getElementById('redirecionando').style.display = 'block';
		document.getElementById('campos_formulario').style.display = 'none';
		// redirecionar
		if(pagina_resultado) {
			document.location = RAIZ_SITE + pagina_resultado;
		} else {
			document.location.reload();
		}

	} else if(resultado_ajax == 'login_nao_aceito') {

		alert('Nome de usuário ou senha não aceitos.');
		if(document.getElementById('usuario_sistema_login_formatado')) {
			setTimeout("document.getElementById('usuario_sistema_login_formatado').select(); ", 500);
		} else {
			setTimeout("document.getElementById('usuario_sistema_login').select(); ", 500);
		}
		if(document.getElementById('cancelar')) {
			document.getElementById('cancelar').style.display = 'inline';
		}
		document.getElementById('entrar').style.display = 'inline';

	} else {

		alert('Erro interno ao tentar logar. \nTente novamente.');
		document.getElementById('cancelar').style.display = 'inline';
		document.getElementById('enviar').style.display = 'inline';
	}
}


function cancelarRequisicaoLogin() {
	document.getElementById('cancelar').style.display = 'inline';
	document.getElementById('enviar').style.display = 'inline';
	cancelarAjax();
}

window.onload = function() {
	if(typeof(focar_login) != 'undefined' && document.getElementById('usuario_sistema_login')) {
		document.getElementById('usuario_sistema_login').focus();
	}
}



function abrirFormLembrete() {
	document.getElementById('form_login_senha').style.display 	= 'none';
	document.getElementById('form_lembrete').style.display 		= 'block';
	document.getElementById('email').select();
	document.getElementById('email').focus();
}

function fecharFormLembrete() {
	document.getElementById('form_login_senha').style.display 	= 'block';
	document.getElementById('form_lembrete').style.display 		= 'none';
	document.getElementById('sucesso_envio').style.display 		= 'none';
	document.getElementById('usuario_sistema_login').select();
	document.getElementById('usuario_sistema_login').focus();
}

function requisitarLembreteLoginSenha(email) {

	//email = document.getElementById('email').value;
	if(email == '') {
		alert('Preencha o seu e-mail.');
		return
	} else {
		email = email.toLowerCase();
		document.getElementById('email').value = email
	}

	modo_debugger_ajax = false;

	
	url = RAIZ_SITE + "login/processamento.php";
	parametros = "acao=enviar_lembrete_login_senha&email=" + email;
	objetoRequisicaoDados = new requisicaoDados(url, parametros, resultadoLembreteLoginSenha, cancelarAjax, 'preloader_lembrete', '');
}
function resultadoLembreteLoginSenha() {
	if(resultado_envio_lembrete == "sucesso") {
		if(email_enviado == '1') {
			document.getElementById('sucesso_envio').style.display = 'block';
			document.getElementById('form_lembrete').style.display = 'none';
			document.getElementById('email_destinatario_enviado').innerHTML = document.getElementById('email').value;
		} else {
			alert('O e-mail digitado não está cadastrado em nosso sistema.\nVerifique com a secretaria qual e-mail está no seu cadastro.');
			document.getElementById('email').select();
		}
	} else {
		alert('Erro interno ao verificar seu e-mail.\nTente novamente.');
	}
}
