// JavaScript Document
function login(){
	var correo = document.loginForm.email.value;
	var password = document.loginForm.password.value;
	
	if(correo == ""){
		alert("Indica tu dirección de correo electrónico");
		document.loginForm.email.focus();
		return;
	}
	if(password == ""){
		alert("Indica tu password");
		document.loginForm.password.focus();
		return;
	}
	
	document.getElementById("login_form").innerHTML = getLoadingArea();
	
	var url = "sistema/getLogin.php";
	var params = "correo=" + correo + "&password=" + password;
	var req = new AJAX.request(url, confirmaLogin, null, AJAX.POST, params, "");
}

function confirmaLogin(){
	var res = this.req.responseText;
	if(res == "FAIL"){
		alert("correo o password incorrecto");
		document.getElementById("login_form").innerHTML = getFormArea();
		return;
	}
	if(res == "INACTIVO"){
		alert("Su cuenta de usuario esta inactiva");
		document.getElementById("login_form").innerHTML = getFormArea();
		return;
	}
	
	location.href="sistema/login.php" + res;
}

function getLoadingArea(){
	var html = "<table width='100%' cellpadding='5' cellspacing='0'>";
	html += "<tr>";
	html += "<td align='center' valign='middle'><img src='images/indicadores/loading.gif'></td>";
	html += "</tr>";
	html += "</table>";
	
	return html;
}

function getFormArea(){
	var html = "<table width='100%' cellpadding='2' cellspacing='0'>";
	html += "<tr><td colspan='3'><center>Ingreso al Sistema</center></td></tr>";
	html += "<tr><td><input type='text' name='email' value='email' size='15' tabindex='1' onfocus='this.value=\"\"'/></td>";
	html += "<td><input type='password' name='password' value='password' size='15' tabindex='2' onfocus='this.value=\"\"'/></td>";
	html += "<td><input type='button' name='button' value='Entrar' onclick='login()' tabindex='3' /></td>";
	html += "</tr><tr><td colspan='3'><center><a href='olvido/'>Recuperar Password</a></center></td></tr>";
	html += "</table>";
	
	return html;
}

