

var tipo_usuario = "";

function CompruebaLogin(){
	var id = document.getElementById("envioID").value;
	var pwd = document.getElementById("envioPWD").value;

	if (id.length == 0){
	 alert ("El nombre de usuario está vacio");
	 return;
	 }

	else if (pwd.length == 0){
	 alert ("La contraseña está vacia");
	 return;
	 }

		//prepare URL for XHR request:
	if (isIE())
		var sUrl = "../PHP/servidorIE.php?" + getSessionIDParam() + "&rs=ComprobarLogin&id=" + id + "&pwd=" + sha1Hash(pwd) + "&tipo_usuario=" + tipo_usuario + "&idioma=es";
	else
		var sUrl = "../PHP/servidor.php?" + getSessionIDParam() + "&rs=ComprobarLogin&id=" + id + "&pwd=" + sha1Hash(pwd) + "&tipo_usuario=" + tipo_usuario + "&idioma=es";
	var callback = {
  		success: function(oResponse) {
			//get the object from the server response

			var selectObj = "";
			try {
				selectObj = YAHOO.lang.JSON.parse(oResponse.responseText);
			} catch(e) {
				//exit
				oResponse.argument.fnLoadComplete();
			}

			//the execution is going ok

		//draw the new data in a new drop down list
		var arrayRecibido = selectObj.info;

//		alert(arrayRecibido[0]);
//		alert(arrayRecibido[1]);

		tipo_usuario = arrayRecibido[2];


		 /*if (tipo_usuario == "Administrador"){
			myWindow=window.open('principal.php','_self','','');
			myWindow.focus();
		}
		else*/ if (tipo_usuario == "Experto"){

		//document.getElementById("Enviar Plantilla").innerHTML = "<a href='index_eng.php'>English</a>";
			myWindow=window.open('principal_experto.php','_self','','');
			myWindow.focus();
		}
		else if (tipo_usuario == "Invitado"){
			myWindow=window.open('principal_inv.php','_self','','');
			myWindow.focus();
		}
		else if (tipo_usuario == "ErrorEs"){
		 alert("ERROR: Nombre de usuario o contraseña incorrecto");
		}
		else if (tipo_usuario == "ErrorEn"){
		 alert("ERROR: Incorrect user name or password");
		}
		else{
		 alert("ERROR: Sólo pueden entrar los invitados y los expertos");
		 }
		return true;




	/*
  			alert(oResponse.responseText);
  	*/
  		//nuevaListaRSint(nuevoArray);
  		},
		failure: function(oResponse) {
			alert("Error");      /////////PARECE QUE DA ERROR AQUI
		},

		//our handlers for the XHR response will need the same
		//argument information we got to loadNodeData, so
		//we'll pass those along:
		//timeout -- if more than 7 seconds go by, we'll abort
		//the transaction and assume there are no children:
		timeout: 7000
  	};
  	YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);



}
