function ValidarDatosLogin()
{
	document.getElementById("rqdUsuario").enabled = true;
	document.getElementById("rqdContrasenya").enabled = true;
	
	Page_ClientValidate();
	
	document.getElementById("rqdUsuario").enabled = false;
	document.getElementById("rqdContrasenya").enabled = false;

}
function ValidarDatosRegistro(_MasDatos)
{
	//Borramos espacios en blanco en el campo CODIGO USUARIO
	
	var boolValidator;
	
	if (document.getElementById("txt_CodigoUsuario") != null)
	{
		document.getElementById("txt_CodigoUsuario").value = Trim(document.getElementById("txt_CodigoUsuario").value);
	}
		
	/*if (!_MasDatos )
	{
		document.getElementById("dtpFechaNacimiento").disabled = true;	
	}
	else
	{
		document.getElementById("dtpFechaNacimiento").disabled = false;	
	}*/
	
	if (window.opera)
	{
		RecuperarCampos();
	}
	else
	{
		PonerRequiredsDatosRegistro(true,_MasDatos);	
		
		boolValidator = Page_ClientValidate();
		
		PonerRequiredsDatosRegistro(false,_MasDatos);
		
		if ( boolValidator == true )
		{
			RecuperarCampos();
		}
	}
	
	//document.getElementById("dtpFechaNacimiento").disabled = false;
}

function PonerRequiredsDatosRegistro(_estado,_MasDatos)
{
	document.getElementById("rqdNombre").enabled = _estado;
	document.getElementById("rqdApellidos").enabled = _estado;
	document.getElementById("rqdEmail").enabled = _estado;	
	document.getElementById("rglFVMail").enabled = _estado;
	document.getElementById("rqdIdiomaCont").enabled = _estado;
	document.getElementById("rqdPais").enabled = _estado;	
	if (document.getElementById("txt_CodigoUsuario") != null)
	{
		document.getElementById("rqdCodigoUsuario").enabled = _estado;
		document.getElementById("rglCodigoUsuario").enabled = _estado;
	}	
	if (document.getElementById("lblPassword") != null)
	{
		document.getElementById("rqdPassword").enabled = _estado;
		document.getElementById("rglPassword").enabled = _estado;
	}
	
	document.getElementById("rqdPreguntaControl").enabled = _estado;	
	document.getElementById("rqdRespuestaControl").enabled = _estado;
	
	if(_MasDatos==true)
	{
		document.getElementById("rqdDireccion").enabled = _estado;
		document.getElementById("rqdCodigoPostal").enabled = _estado;
		document.getElementById("rqdCiudad").enabled = _estado;
		
		if ( (document.getElementById("ddl_Pais").value == "CA") || (document.getElementById("ddl_Pais").value == "US") )
		{
			document.getElementById("rqdEstado").enabled = _estado;
		}
		else
		{
			document.getElementById("rqdProvincia").enabled = _estado;
		}
		
		document.getElementById("rngNochesHoteltrabajo").enabled = _estado;
		document.getElementById("rngNochesHotelOcio").enabled = _estado;
						
	}	
}

function ValidarMasDatosRegistro()
{
	var MasDatos = true;
	ValidarDatosRegistro(MasDatos);
	MasDatos = false;

}

// Funcion que guarda en Hiddens los campos Otras Motivaciones y Otros Destinos
// Posteriormente, se enviara a la BBDD
function RecuperarCampos()
{	
	document.getElementById("hOtrasMot").value = DatosListBox("lst_OtrasMotivaciones");		
	document.getElementById("hOtrosDest").value = DatosListBox("lst_OtrosDestinos");	
	
	if ( document.getElementById("hOtrasMot").value == "||" )
	{
		document.getElementById("hOtrasMot").value = "";
	}
	
	if ( document.getElementById("hOtrosDest").value == "||" )
	{
		document.getElementById("hOtrosDest").value = "";	
	}

}

// A falta de pan...
function Trim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;

}

//Funcion que rellena un string con los codigos de los items seleccionados en un ListBox
function DatosListBox(sNombrelst)
{
	var sListBox = "";
	
	for ( i=0 ; i < document.getElementById(sNombrelst).length ; i++)
	{
		if ( document.getElementById(sNombrelst)[i].selected == true )
		{
			sListBox += document.getElementById(sNombrelst)[i].value + "|";		
		}
	}
	
	sListBox += "|";
	
	return sListBox;
	
}

function PaisOnChange()
{
	var Pais = document.getElementById("ddl_Pais").value;
	
	ControlaDropEstados(Pais);
	
	if ((Pais == "CA")||(Pais == "US"))
	{
		var stateList = document.getElementById("hdEstados").value;
		var combo = document.getElementById("ddl_Estado");
		ClearCombo(combo);
		var splits = stateList.split("#");
		var i = 0;
		var comparer = splits[i];
		// Se deja la posibilidad de no rellenar
		var where = (document.all) ? -1 : null;
		optNueva=document.createElement("OPTION");
		optNueva.value="";
		optNueva.text="";
		combo.add(optNueva, where);
		// Se rellena con los estados del país
		while (comparer != "")
		{
			var state = comparer.split("|");
			if (state[0] == Pais)
			{
				optNueva=document.createElement("OPTION");
				optNueva.value=state[1];
				optNueva.text=state[2];
				combo.add(optNueva,where);
			}
			i += 1;
			comparer = splits[i];
		}
	}
}

function ControlaDropEstados(_Pais)
{
	if ((_Pais == "CA")||(_Pais == "US"))
	{
		document.getElementById("ddl_Estado").style.display = "inline";	
		document.getElementById("lblEstado").style.display = "inline";
		document.getElementById("txt_Provincia").style.display = "none";
		document.getElementById("lblProvincia").style.display = "none";			
		
		
	}
	else
	{
		document.getElementById("ddl_Estado").style.display = "none";
		document.getElementById("lblEstado").style.display = "none";	
		document.getElementById("txt_Provincia").style.display = "inline";
		document.getElementById("lblProvincia").style.display = "inline";		
		
	}
}

function ClearCombo(_combo)
{
	for(x=_combo.length;x>0;x--)
	{
		_combo.remove(0);
	}
}