var intervalo = false;

function show_menu(id) {
	intervalo = false;
	
	document.getElementById('sub_cat_1').style.display = "none";
	document.getElementById('sub_cat_2').style.display = "none";
	document.getElementById('sub_cat_3').style.display = "none";
	
	document.getElementById("cntr_sub").style.display = "block";
	document.getElementById(id).style.display = "block";
}

function hide_menu(id) {
	intervalo = true;
	setTimeout(doHide,500,id);
}

function doHide(id) {
	if(intervalo) {
		document.getElementById("cntr_sub").style.display = "none";
		document.getElementById(id).style.display = "none";
	}
}

function clearCampo(id,valor,padrao) {
	if (valor == padrao) {
		document.getElementById(id).value = "";
	}
}

function checkCampo(id,valor,padrao) {
	if (valor == "") {
		document.getElementById(id).value = padrao;
	}
}

function doLogin() {
	
	userIni = $("#user").attr("value");
	usuario = $("#user").attr("value");
	senha = $("#senha").attr("value");
	
	if (usuario == undefined || usuario == "Nome de usuário") {
		alert('Forneça seu nome de usuário');
		$("#user").focus();
		return false;
	}
	
	if (senha == undefined || senha == "Sua senha") {
		alert('Forneça sua senha');
		$("#senha").focus();
		return false;
	}
	
	$("#user").attr("value","Aguarde...");

	$.ajax({
		type: "POST",
		cache: false,
		url: "../includes/doLogin.php",
		data: "u="+usuario+"&s="+senha+"",
		success: function(dados){
			if (dados == 0) {
				$("#user").attr("value",userIni);
				alert('Usuário ou senha incorretos!');
			} else 
				window.location = "/downloads/";
		}
	});
}

