var url = "login.php";
var redirectOK = "consultas.php";

function CheckLogin()
{
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	var onSuccessExec = "LoginStatus(ajax.responseText)";
	sendData('POST', url, true,"username="+username+"&password="+password,onSuccessExec);
	document.getElementById("divMsg").innerHTML = "Validando...";
	//document.getElementById("divMsg").style.visibility = "visible";
	//document.getElementById("divMsg").visible = false;
}

function LoginStatus(Status)
{
	if(Status == 1)
		//document.getElementById("divMsg").innerHTML = "OK!";
		redirect(redirectOK);
	else if (Status == 2 || Status == 4)
		redirect("consultascood.php");
	else if (Status == 3)
		redirect("consultascentro.php");
	else
		//alert("Usuario o contraseña incorrecta!");
		document.getElementById("divMsg").innerHTML = "Usuario o contraseña incorrecta!";
}


/*
function createXMLHttp()//this, create a object XMLHTTPREQUEST
{	var obj; 
	if(window.XMLHttpRequest) // object native, not IE 
	{	obj = new XMLHttpRequest(); 
	} 
	else // for IE
	{  	try 
		{	obj = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e) 
		{ 	try
			{	obj = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e) 
			{	alert('El navegador utilizado no está soportado'); 
			}
		} 
	} 
	return obj; 
}  

function sendData(method, url, sync, data)//method, url,sync,data
{	ajax = createXMLHttp();
	ajax.open(method, url, sync);
	ajax.onreadystatechange = verifyState;
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajax.send(data);
}

function verifyState() 
{	// if state is "loaded"(4)
    if (ajax.readyState == 4) 
	{   // if status "OK"
        if (ajax.status == 200) 
		{	//LoginStatus(ajax.responseText);
			eval(onSuccess);//eval(onSuccess);
			//ajax.abort();
        } 
		else 
		{	alert('Hubo un problema retrayendo datos XML: ' + ajax.responseText);
        }
    }
}

function redirect(redirect)
{	document.location = redirect;
}
*/
