/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function login() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = '<img src="loader.gif"/>'; 
//div.innerHTML = "<img src='loader.gif'>"
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var usuario = encodeURI(document.getElementById('usuario').value);
var psw = encodeURI(document.getElementById('psw').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'login.php?usuario='+usuario+'&psw='+psw+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
var url = "login.php?usuario=" + usuario + "&psw=" +psw ;
postRequest(url);
}
function loginReply() {
if(http.readyState == 4){
	
var response = http.responseText;
//response=parseInt(response)

if(response == 0)
{
	parent.top.location = "cerrar.php";
	}else{
    parent.top.location ="perfil/cliente.php?usuario="+response;
	}
	
}
}
