/* © Master AETOS */

	function ServerConn(){
		var xmlhttp, bComplete = false;
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) { try { xmlhttp = new XMLHttpRequest(); }
		catch (e) { xmlhttp = false; }}}
		if(!xmlhttp){
			alert("Su navegador web no soporta la conexión con el Área de Alumnos. Trate de actualizarlo a una nueva versión o utilice otro navegador para poder tener acceso.");
			gId('buttLk').className = 'buttA';
			return null;
		}
		this.connect = function(sURL, sMethod, sVars, fnDone){
			if(!xmlhttp) return false;
			bComplete = false;
			sMethod = sMethod.toUpperCase();
			try{
				if(sMethod == "GET"){
					xmlhttp.open(sMethod, sURL+"?"+sVars, true);
					sVars = "";
				}else{
					xmlhttp.open(sMethod, sURL, true);
					xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
				xmlhttp.onreadystatechange = function(){
					if(xmlhttp.readyState == 4 && !bComplete){
						bComplete = true;
						fnDone(xmlhttp);
					}
				}
				xmlhttp.send(sVars);
			}
			catch(z) { return false; }
			return true;
		}
		return this;
	}
	
	function inputFocus(cp){
		if(cp == 'us') gId('conUs').style.backgroundPosition = '0 -25px';
		else gId('conPs').style.backgroundPosition = '0 -25px'; 
	}
	
	function inputBlur(cp){
		if(cp == 'us') gId('conUs').style.backgroundPosition = '0 0';
		else gId('conPs').style.backgroundPosition = '0 0';
	}
	
	function userCheck(){
		var user = gId('accUs').value;
		var pass = gId('accPs').value;
		if(user == '' || pass == ''){ showAviso('boc1'); setTimeout("hideAviso()",4000); }
		else{
			gId('buttLk').className = 'buttP';
			var myConn = new ServerConn();
			if(!myConn) alert("9x1 Su navegador web no soporta la conexión con el Área de Alumnos. Trate de actualizarlo a una nueva versión para poder tener acceso.");
			var fnWhenDone = function (oXML){
				response = oXML.responseXML.documentElement;
				if(response.getElementsByTagName('result')[0].firstChild.data == 1) 
					window.location.href = '/formacion';
				else{ 
					showAviso('boc2'); setTimeout("hideAviso()",5000);
				}
				gId('buttLk').className = 'buttA';
			}
			myConn.connect('login.php', 'POST', 'us='+user+'&ps='+pass, fnWhenDone);
		}
	}
	
	function userLost(){ alert('Sistema en proceso de implementación '); }