var xmlHttp;
function GetXmlHttpObject(){
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function checkInput(theform,username,password,lang) {
	var theforms = document.forms[theform];
	username = theforms.username.value;
	password = hex_md5(theforms.password.value);
	theforms.password.value = "";
	login(theform,username,password,lang);
}

function checkInput2(theform, email, lang) {
	var theform = document.forms[theform];
	email = theform.email.value;
	login(email,'',lang,'resetpass');
}

function login(theform,field1,field2,lang) {
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			var res = xmlHttp.responseText;
			if (res == 'oklogin') { // login con exito
				// window.location="areaprivada_perfil.php";
				window.location="areaprivada_magazine.php";
			} else if (res == 'userpasswrong') { // error login user/pass
				showhidealertlogin('alertnotfound', 1);
			} else if (res == 'statusoff') { // password no reenviado, mail no encontrado
				showhidealertlogin('alertnotfound', 9);
			}
			/*
			 else if (res == 'okpassmail') { // password reenviado
				showhidealertlogin('alertnotfound', 5);
			} else if (res == 'passnomail') { // password no reenviado, mail no encontrado
				showhidealertlogin('alertnotfound', 6);
			}
			*/
		}
	}
	var url = "includes/checklogin.php";
	if (theform=='login') {
		var params = "action="+theform+"&username="+field1+"&password="+field2+"&lang="+lang;
	} else if (theform=='resetpass') {
		var params = "action="+theform+"&email="+field1+"&lang="+lang;
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}

