/* 
Función que se encarga de comprobar la obligatoriedad de los campos correspondientes al código de usuario y al
password. En caso que esta validación sea correcta, llamamos en protocolo seguro a una página encargada 
de autentificar al usuario. Como paso previo cambiamos el nombre de los campos correspondientes al código y al
password del usuario, de esta forma siempre que lleguen a la página de autentificación se llamarán de la
misma forma, independientemente de cómo se llame el control que los contiene.
*/	
			
function AutentificarUsuario(_strIdValidadorUsuario,
							_strIdValidadorPassword,
							_strCampoCodigoDeUsuario,
							_strCampoPassword,
							_strUsuarioObligatorio,
							_strPasswordObligatorio,
							_strTarget,
							ClickMapOmniture)
{
	var bolEsInfoOK = false;

	if (document.all)
	{
		document.getElementById(_strIdValidadorUsuario).enabled = true;
		document.getElementById(_strIdValidadorPassword).enabled = true;

		bolEsInfoOK = Page_ClientValidate();

		document.getElementById(_strIdValidadorUsuario).enabled = false;
		document.getElementById(_strIdValidadorPassword).enabled = false;	
	}
	else
	{
		var UserKO = false;
		var PassKO = false;

		//MNG Pet A1137 - Firefox
		//Realizamos la validacion manual para firefox.

		if (document.getElementsByName(_strCampoCodigoDeUsuario)[0].value == "")
			UserKO = true;

		if (document.getElementsByName(_strCampoPassword)[0].value == "")
			PassKO = true;
		
		if (UserKO == true && PassKO == true)
		{
			alert("- " + _strUsuarioObligatorio + "\n" + "- " + _strPasswordObligatorio);
		}
		else
		{
			if (UserKO == true)
			{
				alert("- " + _strUsuarioObligatorio);
			}
			else
			{
				if (PassKO == true)
					alert("- " + _strPasswordObligatorio);
				else
					bolEsInfoOK = true;
			}
		}
	}
	
	if ( bolEsInfoOK == true )
	{
		if (document.all)
		{
		
			document.forms(0).__VIEWSTATE.name = "__ORIGINALVIEWSTATE";
			document.getElementById(_strCampoCodigoDeUsuario).name = "__CodigoDeUsuario";
			document.getElementById(_strCampoPassword).name = "__PasswordUsuario";
			document.forms(0).action = "https://" + window.document.domain +
				"/BarceloHotels/Authentication/Autentificacion?Target=" + _strTarget;
			document.forms(0).submit();		
			
			//Caso IE
			s_objectID = ClickMapOmniture;			
		}
		else
		{
			document.forms[0].__VIEWSTATE.name = "__ORIGINALVIEWSTATE";
			
			document.getElementsByName(_strCampoCodigoDeUsuario)[0].name = "__CodigoDeUsuario";
			document.getElementsByName(_strCampoPassword)[0].name = "__PasswordUsuario";
			document.forms[0].action = "https://" + window.document.domain +
				"/BarceloHotels/Authentication/Autentificacion?Target=" + _strTarget;
			document.forms[0].submit();
			
			//Caso Firefox
			s_objectID = ClickMapOmniture;			
		}
	}
}

//Función que abre en una nueva pantalla el posting de redirección al portal b2b.
function AbrirAlertaB2B(_strHost, _strCultura)
{
	//MNG Pet A1137 Firefox
	/*window.showModalDialog("http://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/AvisoB2B"
							, "","dialogHeight:200px;dialogWidth:400px;scroll:no;resizable:no;status:no" );*/
	xShowModalDialog("http://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/AvisoB2B"
							, "","dialogHeight=200px;dialogWidth=400px;scrollbars=no;resizable=no;status=no" );
}

//Función que abre en una nueva pantalla el posting de "Usuario incorrecto".
function AbrirAlertaUsuarioErroneo(_strHost, _strCultura)
{
	//MNG Pet A1137 Firefox
	/*window.showModalDialog("http://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/UsuarioIncorrecto"
							, "","dialogHeight:200px;dialogWidth:400px;scroll:no;resizable:no;status:no" );*/
	xShowModalDialog("http://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/UsuarioIncorrecto"
							, "","dialogHeight=240px;dialogWidth=450px;scrollbars=no;resizable=no;status=no" );					
}

//Función que abre una nueva pantalla que permite acceder a la pregunta secreta y recordar el password
function AbrirPasswordErroneo(_strHost, _strCultura, _strUsuario)
{
	//MNG Pet A1137 Firefox
	/*window.showModalDialog("https://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/PasswordIncorrecto?Usuario="+_strUsuario
							, "","dialogHeight:200px;dialogWidth:400px;scroll:no;resizable:no;status:no" );*/
		xShowModalDialog("https://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/PasswordIncorrecto?Usuario="+_strUsuario
							, "","dialogHeight=240px;dialogWidth=450px;scrollbars=no;resizable=no;status=no" );
}

function AbrirRecordarPassword(_strHost, _strCultura)
{	
	xShowModalDialog("http://" + _strHost + "/barcelohotels/" + _strCultura + "/UserRegistration/RecordarContrasena", 
					"", "dialogHeight=240px;dialogWidth=450px;scrollbars=no;resizable=no;status=no"); 
}

function ClickLogin(event, _strNombreBoton)
{
	if (event.keyCode == 13)
	{
		document.getElementById(_strNombreBoton).click();
		event.returnValue = false;
	}
}
