/*
Altera a exibição das divs dos campos de login e alterar senha.
*/
function controlarDivModificarSenha(indicador)
{
	var indicador=indicador;
	if (indicador=='1') {
		document.getElementById('divFormularioLogin').style.display='none';
		document.getElementById('divModificarSenha').style.display='';
		document.getElementById('senhaAtual').value=document.getElementById('senha').value;
		document.getElementById('matriculaAtual').value=document.getElementById('matricula').value;
		document.getElementById("matriculaAtual").focus();
	} else if (indicador=='0') {
		document.getElementById('divFormularioLogin').style.display='';
		document.getElementById('divModificarSenha').style.display='none';
		document.getElementById('senha').value=document.getElementById('senhaAtual').value;
		document.getElementById('matricula').value=document.getElementById('matriculaAtual').value;
		document.getElementById("matricula").focus();
	}
}

function limparSessaoIndex()
{
	var url="ajax/ajaxLimparSessao.jsp";
	requisicao=iniciarRequisicao();
	requisicao.onreadystatechange=respostaLimparSessaoIndex;
	requisicao.open("GET",url,false);
	requisicao.send(null);
}

function respostaLimparSessaoIndex()
{
	if (requisicao.readyState==4) 
		if (requisicao.status!=200) 
			alert("Erro interno ao limpar a sessão: "+requisicaoIndex.status);
}

/*TODO:ainda nao temos essa funcionalidade para a nova intranet
function exibirAguarde() 
{
document.getElementById("aguarde").style.visibility="visible";
}
	
function ocultarAguarde()
{
document.getElementById("aguarde").style.visibility="hidden";
}
*/

function setarFoco(componente) 
{
componente.focus();
}

function keyPressSenha(e)
{
var keyCode=e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
if (keyCode==13)
	validaLogin();
}

function validaLogin()
{
if (document.getElementById("matricula").value=="")
	{
	alert("O campo \"Matricula\" não pode estar vazio!");
	document.getElementById("matricula").focus();
	return false;
	}
	
if (document.getElementById("senha").value=="")
	{
	alert("O campo \"Senha\" não pode estar vazio!");
	document.getElementById("senha").focus();
	return false;
	}
	
var matricula=document.getElementById("matricula").value;
var senha=document.getElementById("senha").value;
senha=hex_md5(senha);

document.getElementById("iframeValidaLogin").src="iframeValidaLogins.jsp?matricula="+matricula+"&anh="+senha;
}

function validarAlterarSenha()
{
if (document.getElementById("matriculaAtual").value=="")
	{
	alert("O campo \"Matricula\" não pode estar vazio!");
	document.getElementById("matriculaAtual").focus();
	return false;
	}
	
if (document.getElementById("senhaAtual").value=="")
	{
	alert("O campo \"Senha\" não pode estar vazio!");
	document.getElementById("senhaAtual").focus();
	return false;
	}
	
if (document.getElementById("novaSenha").value=="")
	{
	alert("O campo \"Nova Senha\" não pode estar vazio!");
	document.getElementById("novaSenha").focus();
	return false;
	} else if (document.getElementById("novaSenha").value.lenght<6)
	{
	alert("A nova senha deve conter no mínimo 6 caracteres!");
	document.getElementById("novaSenha").focus();
	return false;
	}
	
if (document.getElementById("novaSenhaConfirmada").value=="")
	{
	alert("O campo \"Confirmar Senha\" não pode estar vazio!");
	document.getElementById("novaSenhaConfirmada").focus();
	return false;
	} else if (document.getElementById("novaSenhaConfirmada").value.lenght<6)
	{
	alert("A nova senha deve conter no mínimo 6 caracteres!");
	document.getElementById("novaSenhaConfirmada").focus();
	return false;
	}
	
if (document.getElementById("novaSenha").value!=document.getElementById("novaSenhaConfirmada").value)
	{
	alert("\"Nova Senha\" e \"Confirmar Senha\" devem ser iguais!");
	return false;
	}
	
return true;
}

function alterarSenha()
{
//exibirAguarde(); //TODO:ainda nao implementado para N.I.(Nova Intranet)
if (validarAlterarSenha())
	{
	var matricula= document.getElementById("matriculaAtual").value;
	var senha=document.getElementById("senhaAtual").value;
	var novaSenha=document.getElementById("novaSenha").value;
	var novaSenhaConfirmada=document.getElementById("novaSenhaConfirmada").value;
	senha=hex_md5(senha);
	novaSenha=hex_md5(novaSenha);
	novaSenhaConfirmada=hex_md5(novaSenhaConfirmada);
	
	document.getElementById("iframeValidaLogin").src="iframeValidaLogins.jsp?matricula="+matricula+"&anh="+senha+"&novaSenha="+novaSenha+"&novaSenhaConfirmada="+novaSenhaConfirmada;
	}
}


