
var intPais = 0; 
var intDestino = 0; 
var intHotel = 0; 
var intIndiceDias, intIndiceMes, intDigDias, intDigMes, strSeparador;

//--------Funciones que implementan la relacion entre los combos
//Cargar todos los combos
function Control_onload()
{
	RecargarCombo(document.getElementById("ddlPais"), arrPais, "0", "0");
	intPais = 0;
	RecargarCombo(document.getElementById("ddlDestino"), arrDestino, "0", "0");
	intDestino = 0;
	RecargarCombo(document.getElementById("ddlHotel"), arrHotel, "0", "0");	
	intHotel = 0;
	
}

function Pais_onchange(_objCombo_Pais)
{	
	//si el pais seleccionado es 0 y diferente a variable global, guardar valor y recargar combos
	var strPais_Seleccionado = _objCombo_Pais.options[_objCombo_Pais.selectedIndex].value.split("#")[1];
	if ((strPais_Seleccionado== "0")&&(intPais!=0))
	{
		intPais=0;
		Control_onload();
	}
	//si no
	else
	{
		//si el pais seleccionado no es el mismo 
		//que ya habia en la variable global
		if (strPais_Seleccionado!=intPais.toString())
		{
			//guardamos el pais seleccionado en la variable global
			intPais = parseInt(strPais_Seleccionado); 
			//recargar el combo de destino
			RecargarCombo(document.getElementById("ddlDestino"), arrDestino, "2", strPais_Seleccionado );
			//recargar el combo de hotel
			RecargarCombo(document.getElementById("ddlHotel"), arrHotel, "2", strPais_Seleccionado );
		}
	}
	
}
function Destino_onchange(_objCombo_Destino)
{
	
	//si el destino seleccionado es 0 y diferente a variable global, guardar valor y recargar combos
	var strDestino_Seleccionado = _objCombo_Destino.options[_objCombo_Destino.selectedIndex].value.split("#")[1];
	if ((strDestino_Seleccionado == "0")&&(intDestino!=0))
	{
		intDestino=0;
		Control_onload();
	}
	//si no
	else
	{		
		//si el destino seleccionado no es el mismo 
		//que ya habia en la variable global 
		if (strDestino_Seleccionado!=intDestino.toString())
		{			
			//guardamos el destino seleccionado en su variable global
			intDestino = parseInt(strDestino_Seleccionado); 
			//recargar el combo de hotel
			RecargarCombo(document.getElementById("ddlHotel"), arrHotel, "3", strDestino_Seleccionado);
			//actualizar el combo de pais
			CambiarComboSuperior(_objCombo_Destino, arrPais, "intPais" , intPais, "ddlPais" , 2);
			
		}
	}				
}
function Hotel_onchange(_objCombo_Hotel)
{
	//guardar valor de hotel
	var strHotel_Seleccionado = _objCombo_Hotel.options[_objCombo_Hotel.selectedIndex].value.split("#")[1];
	//si el hotel seleccionado es 0 y diferente a variable global, recargar combos
	if ((strHotel_Seleccionado   == "0")&&(intHotel!=0))
	{
		intHotel=0;
		Control_onload();
	}
	//si no 
	else
	{	
		//guardamos el hotel seleccionado en su variable global
		intHotel = parseInt(strHotel_Seleccionado);  
		//actualizar el combo de pais
		CambiarComboSuperior(_objCombo_Hotel, arrPais, "intPais" , intPais, "ddlPais" , 2);
		//actualizar el combo de destino
		CambiarComboSuperior(_objCombo_Hotel, arrDestino, "intDestino" , intDestino, "ddlDestino", 3);			
	 }
}

function CambiarComboSuperior(_objcombo_actual, _array_superior, _strnombre_variable_global, _intvalor_variable_global, 
								_strnombre_combo_superior, _intposicion_busqueda_seleccion)
{
	//si el combo superior no es el mismo que habia
	var strSuperior_Seleccionado = _objcombo_actual.options[_objcombo_actual.selectedIndex].value.split("#")[0];
	strSuperior_Seleccionado  = strSuperior_Seleccionado.split("|")[_intposicion_busqueda_seleccion];
		
	if (_intvalor_variable_global!=parseInt(strSuperior_Seleccionado))
	{
			//guardar variable de combo superior en variable global correspondiente
			eval(_strnombre_variable_global + "=parseInt(strSuperior_Seleccionado)");
			//seleccionar el combo superior
			for(var x=0;x<_array_superior.length-1;x++)
			{	
				objElementoCombo = document.getElementById(_strnombre_combo_superior).options[x];
				//si existe el elemento
				if (objElementoCombo)
				{
					if (objElementoCombo.value.split("#")[1] == strSuperior_Seleccionado)
					{
						objElementoCombo.selected = true;
					}
		
				}
			}		
	}
}
								
function RecargarCombo(_combo, _array, _strPosicionSeleccion, _strValorSeleccion)
{
	var x;
	var strElemento_Seleccion;
	var strTexto;
	var strValor;
	var arrayAux = new Array();
	var i = 0;
	//limpiar combo llamando a la funcion LimpiarCombo
	LimpiarCombo(_combo);
	//hacer un array a partir del array original
	for(var x=1;x<_array.length;x++)
	{	
		//si existe el elemento
		if (_array[x])
		{
			strTexto = _array[x].split("|")[0];
			//el valor de cada elemento del combo será
			//el que se pone por c# concatenado con su codigo
			strValor = _array[x] +"#" + x.toString();
			arrayAux[i] = strValor;
			i = i + 1;
		}
	}
	arrayAux = arrayAux.sort(compare);
	strValor = _array[0];
	arrauAux = arrayAux.unshift(strValor + "#0");  
	
	//ordenar el nuevo array
	//para cada elemento del array
	for(var x=0;x<arrayAux.length;x++)
	{	
		//si existe el elemento
		if (arrayAux[x])
		{
			//si cumple filtro o si el filtro es 0 o si el elemento es 0
			strElemento_Seleccion = arrayAux[x].split("|")[parseInt(_strPosicionSeleccion)];
			strElemento_Seleccion = strElemento_Seleccion.split("#")[0]; 
			
			//strElemento_Seleccion=="0" (caso de 1er elemento)
			//_strValorSeleccion=="0" ) caso en el que se quieren cargar todos
			if(strElemento_Seleccion==_strValorSeleccion || strElemento_Seleccion=="0" 
													|| _strValorSeleccion=="0" ) 
			{
			   	//añadir a los elementos del combo con la funcion AnyadirOpcion
			   	strTexto = arrayAux[x].split("|")[0];
			   	strValor = arrayAux[x];
			   	AnyadirOpcion(strValor, strTexto, _combo);
			}
		}
	}  
	//reiniciar valor de la variable del combo y seleccionar el valor 0 en el combo
	_combo.selectedIndex = 0;
	
}
//MNG 20061016 Cambios FireFox
function AnyadirOpcion(_value, _text, _control)
{
	var where = (document.all) ? -1 : null;
	var NewOption = document.createElement("OPTION");
	NewOption.value = _value;
	NewOption.text = _text;
	_control.add(NewOption, where);
	NewOption = null;
}

function LimpiarCombo(_Combo)
{
	for ( var i = _Combo.length; i > 0; i-- )
	{
		_Combo.remove(0);
	}
}
//FIN funciones que implementan la relacion entre los combos


//recuperar estados previos: desde c# se informan las intVariable_previo
function Estado_Previo()
{
	Estado_Combos();
	//Estado_Calendarios(); 
}

function Estado_Combos()
{	
	InformarValoresPrevios();
	
	if (intPais_previo != 0)
	{ 
		SeleccionarValoresCombos(arrPais, "ddlPais", intPais_previo);
		Pais_onchange(document.getElementById("ddlPais"));
	}
	if (intDestino_previo != 0)
	{ 
		SeleccionarValoresCombos(arrDestino, "ddlDestino", intDestino_previo);
		Destino_onchange(document.getElementById("ddlDestino"));
	}
	
	if (intHotel_previo != 0)
	{
		SeleccionarValoresCombos(arrHotel, "ddlHotel", intHotel_previo);
		Hotel_onchange(document.getElementById("ddlHotel"));
	}
}

function SeleccionarValoresCombos( _array, _strnombre_combo, _id_seleccionado)	
{	
	for(var x=0;x<_array.length-1;x++)
	{	
		objElementoCombo = document.getElementById(_strnombre_combo).options[x];
		//si existe el elemento
		if (objElementoCombo)
		{
			if (objElementoCombo.value.split("#")[1] == _id_seleccionado)
			{
				objElementoCombo.selected = true;
			}
		}
	}		
}

function Estado_Calendarios()
{
	document.getElementById("dtpFechaEntrada_Fecha").onfocus();
	document.getElementById("dtpFechaEntrada_Fecha").onblur(); 
}
//FIN recuperar estados previos: desde c# se informan las intVariable_previo

//Validaciones

function Localizador_PerderFoco()
{
	var n;
	var x;
	n = (document.getElementById("txtLocalizador").value);
	x = n/2;
	if ((!x)&&(x!="0"))
	{
		//Si no es número se borra el campo
		document.getElementById("txtLocalizador").value = "";
	}
	//MNG 20060410 Si localizador == 0, borramos el campo para que no 
	//devuelva todas las reservas al buscar.
	if (x==0)
	{
		document.getElementById("txtLocalizador").value = "";
	}	
}

function Validar(_mensaje_Min1Campo, _mensaje_LocalizYHotelOblig, _mensaje_InfoCamposUsuarioReg, _EsUsuarioRegistrado)
{ 
	//MNG 20061011 Problema con navegadores distintos a explorer 5.5 o 6
	/*if(!document.all)
	{
		return false;
	}*/
	//Fin MNG
	strMensaje = "";
	objCombo_Destino = document.getElementById("ddlDestino");
	objCombo_Pais = document.getElementById("ddlPais");
	objCombo_Hotel = document.getElementById("ddlHotel");
	objLocalizador = document.getElementById("txtLocalizador");
	
	var strDestino_Seleccionado = objCombo_Destino.options[objCombo_Destino.selectedIndex].value.split("#")[1];
	var strPais_Seleccionado = objCombo_Pais.options[objCombo_Pais.selectedIndex].value.split("#")[1];
	var strHotel_Seleccionado = objCombo_Hotel.options[objCombo_Hotel.selectedIndex].value.split("#")[1];
	var strLocalizador = objLocalizador.value;
	var bolMinUnaFecha = MinimoUnaFecha();
	var bolParesFechas = true;
	var bolHayError = false;
			
	//Validaciones para Usuario Registrado			
	if (_EsUsuarioRegistrado == "True")
	{	
		if  (strLocalizador == "")
		{//CAMPO LOCALIZADOR NO INFORMADO
			if (strHotel_Seleccionado != "0") 
			{
				
				if (bolMinUnaFecha)
				{
					strMensaje = "";				
				}
				else
				{
					strMensaje = _mensaje_InfoCamposUsuarioReg;		
					bolHayError = true;		
				}
			}
			else
			{
				strMensaje = _mensaje_InfoCamposUsuarioReg;		
				bolHayError = true;								
			}	

			//bolParesFechas = ValidacionParesFechas();
			//if (!bolParesFechas)
			//{
			//	bolHayError = true;								
			//}
			bolParesFechas = ValidacionParesFechas();
		}
		else 
		{//CAMPO LOCALIZADOR INFORMADO	
			bolParesFechas = ValidacionParesFechas();
			
			if( (bolParesFechas) && (strHotel_Seleccionado != "0") )
			{
				strMensaje = "";
			}
			if (!bolParesFechas)
			{
				bolHayError = true;
			}
			//else
			//{
			//	strMensaje = _mensaje_InfoCamposUsuarioReg;	
		//		bolHayError = true;								
			//}			
		}	
	}	
	else
	{//Validaciones para Usuario NO Registrado
		if ( (strHotel_Seleccionado == "0") || (strLocalizador == "") )
		{  
			//Mensaje de que los 2 campos deben estar informados.
			strMensaje = _mensaje_LocalizYHotelOblig;		
			bolHayError = true;				
		}	
	}
		
	if ( (bolHayError)&&(bolParesFechas) )
	{
		window.alert(strMensaje);
		Page_BlockSubmit = true;	
		return false;
	}	
	else if ( (!bolHayError)&&(bolParesFechas) )
	{
		Page_BlockSubmit = false;	
		return true;
	}
	else if (bolParesFechas == false)
	{
		return false;
	}
}

function MinimoUnaFecha()
{
	InformarDateSelectorsValue();

	if (	(document.getElementById("dtpFechaEntradaDesde_DateSelector").value !="" && document.getElementById("dtpFechaEntradaDesde_DateSelector").value != null )||
			(document.getElementById("dtpFechaSalidaDesde_DateSelector").value !="" && document.getElementById("dtpFechaSalidaDesde_DateSelector").value != null)|| 
			(document.getElementById("dtpFechaReservaDesde_DateSelector").value !="" && document.getElementById("dtpFechaReservaDesde_DateSelector").value != null)||
			(document.getElementById("dtpFechaEntradaHasta_DateSelector").value !="" && document.getElementById("dtpFechaEntradaHasta_DateSelector").value != null)||
			(document.getElementById("dtpFechaSalidaHasta_DateSelector").value !="" && document.getElementById("dtpFechaSalidaHasta_DateSelector").value != null )|| 
			(document.getElementById("dtpFechaReservaHasta_DateSelector").value !="" && document.getElementById("dtpFechaReservaHasta_DateSelector").value != null ))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

function InformarDateSelectorsValue()
{
	var arrDtpSelectors = new Array ("dtpFechaEntradaDesde", "dtpFechaEntradaHasta", "dtpFechaSalidaDesde", "dtpFechaSalidaHasta", "dtpFechaReservaDesde", "dtpFechaReservaHasta");
	var controlDia;
	var controlMes;
	var diaSeleccionado;
	var mesSeleccionado;
	var anyoSeleccionado;
	
	for (i=0; i<arrDtpSelectors.length; i++)
	{
		controlDia = document.getElementById(arrDtpSelectors[i] + "_Days");
		controlMes = document.getElementById(arrDtpSelectors[i] + "_Months");
		if (controlDia.selectedIndex != 0 && controlMes.selectedIndex != 0 )
		{
			diaSeleccionado = controlDia.value;
			mesSeleccionado = controlMes.value.split("|")[1];
			anyoSeleccionado = controlMes.value.split("|")[2];
			
			document.getElementById(arrDtpSelectors[i] + "_DateSelector").value = ConvierteFechaConSeparadorSegunCultura(diaSeleccionado, mesSeleccionado, anyoSeleccionado);
		}
		else
		{
			document.getElementById(arrDtpSelectors[i] + "_DateSelector").value = "";
		}
	}
}

function ValidacionParesFechas()
{
	var bolValidador = true;
	var validarFechaEntrada = false;
	var validarFechaSalida = false;
	var validarFechaReserva = false;
	
	if ( ( document.getElementById("dtpFechaEntradaDesde_DateSelector").value !="" && document.getElementById("dtpFechaEntradaDesde_DateSelector").value != null ) &&
	     ( document.getElementById("dtpFechaEntradaHasta_DateSelector").value !="" && document.getElementById("dtpFechaEntradaHasta_DateSelector").value != null ))
	{
		if (document.all)
		{
			document.getElementById("cvFechasEntrada").enabled = true;
		}
		validarFechaEntrada = true;
	} 
	if ( ( document.getElementById("dtpFechaSalidaDesde_DateSelector").value !="" && document.getElementById("dtpFechaSalidaDesde_DateSelector").value != null ) &&
	     ( document.getElementById("dtpFechaSalidaHasta_DateSelector").value !="" && document.getElementById("dtpFechaSalidaHasta_DateSelector").value != null ))
	{
		if (document.all)
		{
			document.getElementById("cvFechasSalida").enabled = true;	
		}
		validarFechaSalida = true;
	} 	
	if ( (document.getElementById("dtpFechaReservaDesde_DateSelector").value !="" && document.getElementById("dtpFechaReservaDesde_DateSelector").value != null )&&
	     (document.getElementById("dtpFechaReservaHasta_DateSelector").value !="" && document.getElementById("dtpFechaReservaHasta_DateSelector").value != null ))
	{
		if (document.all)
		{
			document.getElementById("cvFechasReserva").enabled = true;
		}
		validarFechaReserva = true;	
	} 	

	if (document.all)
	{
		bolValidador = Page_ClientValidate();
		document.getElementById("cvFechasEntrada").enabled = false;
		document.getElementById("cvFechasSalida").enabled = false;
		document.getElementById("cvFechasReserva").enabled = false;
	}
	else
	{
		var strError = "";
		if (validarFechaEntrada)
		{
			if (ComparaFechas(document.getElementById("dtpFechaEntradaDesde_DateSelector").value, document.getElementById("dtpFechaEntradaHasta_DateSelector").value) == false)
			{
				strError = "- " + document.getElementById("hdErrorFechaEntrada").value;
				bolValidador = false;
			}
		}
		if (validarFechaSalida)
		{
			if (ComparaFechas(document.getElementById("dtpFechaSalidaDesde_DateSelector").value, document.getElementById("dtpFechaSalidaHasta_DateSelector").value) == false)
			{
				if(strError != "")
				{
					strError += "\n";
				}
				strError += "- " + document.getElementById("hdErrorFechaSalida").value;
				bolValidador = false;
			}
		}
		if (validarFechaReserva)
		{
			if (ComparaFechas(document.getElementById("dtpFechaReservaDesde_DateSelector").value, document.getElementById("dtpFechaReservaHasta_DateSelector").value) == false)
			{
				if(strError != "")
				{
					strError += "\n";
				}
				strError += "- " + document.getElementById("hdErrorFechaReserva").value
				bolValidador = false;
			}
		}
		
		if (strError != "")
		{
			alert(strError);
		}
	}
	
	//Se añade bolParesFechas, para indicar que se ha pasado por la función
	//ValidacionParesFechas, el Page_BlockSubmit es controlado por ésta al hacer
	//Page_ClientValidate(). Si no se pone, la funcion Validar siempre lanzaría la búsqueda.  
	//bolParesFechas = false;
	
	return bolValidador;
}

function ComparaFechas(strFechaInicial, strFechaFinal)
{
	var tempFechaInicial = ConvierteFecha(strFechaInicial);
	var tempFechaFinal = ConvierteFecha(strFechaFinal);
	
	if ( parseInt(tempFechaFinal) <= parseInt(tempFechaInicial))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ConvierteFecha(strFecha)
{
	var strPatron = document.getElementById("hdPatron").value;
	var strSeparador = document.getElementById("hdSeparador").value; 
	
	IdentificarGR(strPatron, strSeparador);
	
	var arrDate = strFecha.split(strSeparador); 
    
    var intDia = arrDate[intIndiceDias];
    var intMes = arrDate[intIndiceMes];
    var intAnyo = arrDate[2];

    var strFechaOut = intAnyo + intMes + intDia;
	return strFechaOut;
	
}

function ConvierteFechaConSeparadorSegunCultura(strDia, strMes, strYear)
{
	var strPatron = parent.document.getElementById("hdPatron").value;
	var strSeparador = parent.document.getElementById("hdSeparador").value; 
	
	IdentificarGR(strPatron, strSeparador);
	
	var strFechaOut;

	if ( intIndiceDias < intIndiceMes )
	{
		strFechaOut = strDia + strSeparador + strMes + strSeparador + strYear;
	}
	else
	{
		strFechaOut = strMes + strSeparador + strDia + strSeparador + strYear;
	}
	
    
	return strFechaOut;
	
}

//function check(_chkID, _ClientID, _blnEsUsuarioReg, _strEstadoReserva, _IDdelCheck)
function check(_chkID, _ClientID, _blnEsUsuarioReg, _strEstadoReserva, _IDdelCheck, _strNumReserva, _strFechaCheckIn, _strCodHotel)
{
	document.getElementById("hdNumReserva").value = _strNumReserva;
	document.getElementById("hdFechaCheckIn").value = _strFechaCheckIn;
	document.getElementById("hdCodHotel").value = _strCodHotel; 
	
    var dtFechaHoy = new Date();
    var strFechaHoy = Formatear_Fechas(dtFechaHoy);
    var bolFechaModificable;
    

    if (_strFechaCheckIn <= strFechaHoy)
    {
		bolFechaModificable = false;
    }
    else
    {
		bolFechaModificable = true;
    }
    
	var ListaChecks = document.getElementById("hdChecks").value;
	var arrChecks = ListaChecks.split('#');
	var checkID;
	
	//_chkID = _ClientID + "_" + _chkID;
	_chkID =_IDdelCheck;
	
	//Deshabilitar botones
	document.getElementById("ibtModificar").style.display = "none";
	document.getElementById("ibtAnular").style.display = "none";
	document.getElementById("ibtConsultar").style.display = "none";	

	if (_blnEsUsuarioReg == "True")
	{
		// Activa/Desactiva botones de Usuario Registrado
		if (document.getElementById(_chkID).checked == false)
		{
			//Deshabilitar botones
			document.getElementById("ibtModificar").style.display = "none";
			document.getElementById("ibtAnular").style.display = "none";
			document.getElementById("ibtConsultar").style.display = "none";	
		}		
		else
		{
			//Habilitar botones
			
			if (_strEstadoReserva == "FIR")
			{
				//Si es Reserva en Firme: habilitar botón Consultar:
				document.getElementById("ibtConsultar").style.display = "inline";			
				
				//Si además la Fecha Entrada es posterior a hoy => activa el resto de botones
				if (bolFechaModificable)
				{
					document.getElementById("ibtModificar").style.display = "inline";
					document.getElementById("ibtAnular").style.display = "inline";
				}
			}
			else
			{
				//Si NO es Reserva en Firme: habilitar solo botón Consultar:
				document.getElementById("ibtConsultar").style.display = "inline";					
			}
		}		
	}
	
	else 
	{
		// Activa/Desactiva botones de Usuario NO-Registrado
		if (document.getElementById(_chkID).checked == false)
		{
			//Deshabilitar botones
			document.getElementById("ibtAnular").style.display = "none";	
		}		
		else
		{
			//Para reservas en estado FIRME y fecha Modificable: Habilitar Cancelar
			if ( (_strEstadoReserva == "FIR") && (bolFechaModificable) )
			{
				
				document.getElementById("ibtAnular").style.display = "inline";
			}
		}
	}
		
	for (i=0; i<arrChecks.length -1; i++)
	{	
		checkID = arrChecks[i];

		if  (_chkID.lastIndexOf("chkBox")!= -1)
		{
			//"chkBox" está en checkID
			_chkID = new String(_chkID.replace("chkBox","chk_"));				
		}

		if (checkID != _chkID)
		{
			if (document.getElementById(checkID) != null)
			{
				document.getElementById(checkID).checked = false;
			}
			else
			{
				newID = new String(checkID.replace("chk_", "chkBox"));	
				document.getElementById(newID).checked = false;
			}			
		}
		
	}			
}

function IdentificarGR(_strFormato, _strSeparador)
{
	strSeparador = _strSeparador;
	var strFormato = _strFormato.split(_strSeparador);
	
	if ( strFormato[0].substr(0, 1).toUpperCase() == "D" )
	{
		intIndiceDias = 0;
		intIndiceMes = 1;
		intDigDias = strFormato[0].length;
		intDigMes = strFormato[1].length;
	}
	else
	{
		intIndiceDias = 1;
		intIndiceMes = 0;
		intDigDias = strFormato[1].length;
		intDigMes = strFormato[0].length;
	}
}

function ComprobarEsFechaGR(_IdControl, _strFormato, _strSeparador)
{ 
   IdentificarGR(_strFormato, _strSeparador);

    var strTextoControl = document.getElementById(_IdControl).value;
    var arrDate = strTextoControl.split(strSeparador); 
    
    
    var intDia = arrDate[intIndiceDias];
    var intMes = arrDate[intIndiceMes];
    var intAnyo = arrDate[2];
		
    var Mensaje = document.getElementById("hdErrorMsg").value;    
        
    var dtHoy = new Date();    
    var intAnyoActual = dtHoy.getFullYear();    
    var tempFecha = new Date(intAnyo, (intMes-1), intDia); 
    
    if ( strTextoControl != "" )
	{	
		if ( isNaN(tempFecha) || UltimoDiaMes(intDia, (intMes - 1), intAnyo)== "ATPC" || intAnyo.length<4 || intMes.length<intDigMes || intDia.length<intDigDias )
 		{
 			alert (Mensaje);
 			document.getElementById(_IdControl).value = "";
 			return false;
 		}
 		else
		{
			return true;
		}
    }
	
}

function UltimoDiaMes(strDia, strMes, strAnyo)
{
	var strUltimo = "N";
	if ( ( strMes == 0 || strMes == 2 || strMes == 4 || strMes == 6 || strMes == 7 || strMes == 9 || strMes == 11 ) && strDia >= 31 )
	{
		strUltimo = "Y";
	    if (strDia > 31)
		{
			strUltimo = "ERROR";
		}
	}
	if ( ( strMes == 3 || strMes == 5 || strMes == 8 || strMes == 10 ) && strDia >= 30 )
	{
		strUltimo = "Y";
	    if (strDia > 30)
		{
			strUltimo = "ERROR";
		}
	}
	if ( strMes == 1 )
	{
		if (strDia > 29) 
		{
			strUltimo="ERROR";
		}
		
		var strAnyoBisiesto = AnyoBisiesto(strAnyo);
		if ( strAnyoBisiesto && strDia == 29 )
		{
			strUltimo = "Y";
		}
		if ( !strAnyoBisiesto && strDia >= 28 )
		{
		
			strUltimo = "Y";
			if (strDia > 28)
			{
				strUltimo = "ERROR";
			}
		}
	}
	if ( strUltimo == "Y" )
	{
		return true;
	}
	if ( strUltimo == "N" )
	{
		return false;
	}
	if ( strUltimo == "ERROR" )
	{
		return "ATPC"
	}
}


function AnyoBisiesto(strAnyo)
{
	var strAnyoBisiesto = "N";
	if ( (strAnyo % 4) == 0 )
	{
		strAnyoBisiesto = "Y";
		if ( (strAnyo % 100) == 0 )
		{
			if ( (strAnyo % 400) !=0 )
			{
				strAnyoBisiesto = "N";
			}
		}
	}
	if ( strAnyoBisiesto == "Y" )
	{
		return true;
	}
	if ( strAnyoBisiesto == "N" )
	{
		return false;
	}
}

function CancelReservation(_Hoy, _Mensaje)
{
	//alert(_Mensaje);
	var retVal = false;
	var Result = Confirmacion(_Mensaje);

	//MNG Pet A1137 20061113 
	if (document.all)
	{
		Page_BlockSubmit = !Result;	
	}
	else
	{
		return Result;
	}
	
	//Si Acepta anular se ejecuta el código de servidor del botón Anular.
}

//20050206 JAB funciones para comparar independientemente de los acentos
function compare(a, b) {
if (EliminaTilde(a) < EliminaTilde(b))
{
return -1;
}
if (EliminaTilde(a) > EliminaTilde(b))
{
return 1;
}

return 0;
}


function EliminaTilde(str){
 ret=str.replace(String.fromCharCode(225),"a");
 ret=ret.replace(String.fromCharCode(233),"e");
 ret=ret.replace(String.fromCharCode(237),"i");
 ret=ret.replace(String.fromCharCode(243),"o");
 ret=ret.replace(String.fromCharCode(250),"u");
 ret=ret.replace(String.fromCharCode(224),"a");
 ret=ret.replace(String.fromCharCode(232),"e");
 ret=ret.replace(String.fromCharCode(236),"i");
 ret=ret.replace(String.fromCharCode(242),"o");
 ret=ret.replace(String.fromCharCode(249),"u");
 return ret;
}