function enter(evt) {
	var r = false;	
	var key_code = evt.keyCode ? evt.keyCode : evt.charCode ? evt.charCode : evt.which ? evt.which : void 0;	
	if (key_code == 13) {
		r = true;
	}
	return r;
}

function Aguarde(sim) {
	var div1 = $('div_aguarde');
	var div2 = $('div_conteudo');
	if (sim) {
		if (div2 != undefined) {Effect.Fade(div2, {to:0.2,duration:0.1});}
		if (div1 != undefined) {div1.style.display = 'block';}
	} else {
		if (div1 != undefined) {div1.style.display = 'none';}
		if (div2 != undefined) {Effect.Appear(div2, {duration:0.1});}
	}
}

function Home() {
	Aguarde(true);
	AjaxInclude('home.php','div_conteudo');
}

function Noticias() {
	Aguarde(true);
	AjaxInclude('noticias.php','div_conteudo');
}

function Interna(tipo, id) {
	Aguarde(true);
	var params = "";
	switch (tipo) {
		case 'M': // menu
			params += "?menu=" + id;
			break;
		case 'N': // noticias
			params += "?noticia=" + id;
			break;
		case 'C': // caixas
			params += "?caixa=" + id;
			break;
	}
	AjaxInclude('conteudo.php'+params, 'div_conteudo');
}

function Login() {
	var dir = "admin/";
	var login = $("txt_login");
	var senha = $("txt_senha");
	var botao = $("bt_ok");
	var aguarde = $("img_aguarde");	
	if (login.value == "") {
		alert("Informe o login.");
		login.focus();
		return;
	}
	if (senha.value == "") {
		alert("Informe a senha.");
		senha.focus();
		return;
	}		
	botao.style.display = 'none';
	aguarde.style.display = 'inline';
	var ajax = new AJAX();
	ajax.url = dir + "login.php";	
	ajax.metodo = "POST";
	ajax.params = "login="+login.value+"&senha="+senha.value;
	ajax.retorno = function(texto) {
		aguarde.style.display = 'none';
		botao.style.display = 'inline';		
		if (texto == "OK"){
			location.href = dir;
		} else {
			alert("ACESSO NEGADO! Login/Senha incorretos.\n\nTente novamente.");
			login.focus();
		}
	}
	ajax.conectar();
}
