function chat(){
ancho=510; alto=400;
var W=window.open('chatonline/client.php','chat',"scrollbars=yes,width="+ancho+",height="+alto);
W.focus();
iz=(screen.width-ancho) / 2;
de=(screen.height-alto) / 2;
W.moveTo(iz,de);
}
function validarReserv(form1)
{

	/*  Datos seleccionados en el formulario  */
	var iNumNoches 		= document.getElementById('numnoches').value; // Num de  Noches
	var iDayLlegada 	= document.getElementById('llegada_dia').value; // dia de llegada
	var iYearLlegada	= document.getElementById('llegada_year').value; // Anio de llegada
	var iMonthLlegada	= document.getElementById('llegada_mes').value;  // mes ""
	
	var iDayF = document.getElementById('diaf').value; 		// Dia de  salida
	var iMonthF = document.getElementById('mesf').value;	// Mes de salida
	var iYearF = document.getElementById('aniof').value; 	// Anio de salida
	
	var iHabitaciones = document.getElementById('num_hab').value; // Numero de habitaciones
	if(comprobarLlegada(iDayLlegada,iMonthLlegada,iYearLlegada) == false)
	{

		alert("La fecha de llegada es invalida, verificala por favor");
		return false;
	}
	if(!comprobarSalida(iDayLlegada,iMonthLlegada,iYearLlegada,iDayF,iMonthF,iYearF))
	{

		alert("La fecha de salida es invalida, verificala por favor");
		return false;
	}

	if((iNumNoches < 1) || (iHabitaciones < 1)) return false; // Comprobamos que el num de habitaciones sea mayor a 1 y las noches como minimo una

	return true;
}
function validarNoches()
{
		
	var iDayLlegada 	= document.getElementById('llegada_dia').value; // dia de llegada
	var iYearLlegada	= document.getElementById('llegada_year').value; // Anio de llegada
	var iMonthLlegada	= document.getElementById('llegada_mes').value;  // mes ""
	
	var iDayF = document.getElementById('diaf').value; 		// Dia de  salida
	var iMonthF = document.getElementById('mesf').value;	// Mes de salida
	var iYearF = document.getElementById('aniof').value; 	// Anio de salida
	var noches = getNoches(iDayLlegada,iMonthLlegada,iYearLlegada,iDayF,iMonthF,iYearF);
	
	if(noches < 0)
	{
		alert("La fecha de salida es invalida.");
			document.getElementById('numnoches').value = 0;
	}
	else
	{
		document.getElementById('numnoches').value = noches;
	}
}
function validarNoches2()
{
		
	var iDayLlegada 	= document.getElementById('llegada_dia').value; // dia de llegada
	var iYearLlegada	= document.getElementById('llegada_year').value; // Anio de llegada
	var iMonthLlegada	= document.getElementById('llegada_mes').value;  // mes ""
	
	var iDayF = document.getElementById('diaf').value; 		// Dia de  salida
	var iMonthF = document.getElementById('mesf').value;	// Mes de salida
	var iYearF = document.getElementById('aniof').value; 	// Anio de salida
	var noches = getNoches(iDayLlegada,iMonthLlegada,iYearLlegada,iDayF,iMonthF,iYearF);
	
	if(noches < 0)
	{
		alert("Invalid number of nights");
			document.getElementById('numnoches').value = 0;
	}
	else
	{
		document.getElementById('numnoches').value = noches;
	}
}

function getNoches(iDayLlegada,iMonthLlegada,iYearLlegada,iDayF,iMonthF,iYearF)
{
		var fecha1 = new Date(iYearLlegada,iMonthLlegada,iDayLlegada);
		var fecha2 = new Date(iYearF,iMonthF,iDayF);
		
		var resta = (fecha2.getTime() - fecha1.getTime()); // restamos la fecha
		var dias = Math.floor(resta / (1000 * 60 * 60 * 24));
		return (dias);
		
}
function comprobarLlegada(iDia,iMes, iAno)
{
	/* fecha del sistema */
	var dFecha = new Date();
	
	//Comprobamos que la fecha de entrada no es menor a la fecha registrada por el sistema (Que debe ser correcta)
	if( (Math.round(iMes) <= (dFecha.getMonth() + 1)) &&  (Math.round(iDia) < dFecha.getDate() )  ) 
	{	
		return false;
	}
	return true;
}
function comprobarSalida(iDiaEntrada,iMesEntrada,iAnoEntrada, iDiaSalida,iMesSalida,iAnoSalida)
{
var dFecha = new Date();

		
	//Comprobamos que la fecha de salida no sea menor a la de entrada
	if( (iDiaSalida < iDiaEntrada) &&((iMesEntrada > iMesSalida) ) )
	{
		return false;
	}
	
	return true;
}





function validarReserv2(form1)
{

	/*  Datos seleccionados en el formulario  */
	var iNumNoches 		= document.getElementById('numnoches').value; // Num de  Noches
	var iDayLlegada 	= document.getElementById('llegada_dia').value; // dia de llegada
	var iYearLlegada	= document.getElementById('llegada_year').value; // Anio de llegada
	var iMonthLlegada	= document.getElementById('llegada_mes').value;  // mes ""
	
	var iDayF = document.getElementById('diaf').value; 		// Dia de llegada
	var iMonthF = document.getElementById('mesf').value;	// Mes de llegada
	var iYearF = document.getElementById('aniof').value; 	// Anio de llegada
	
	var iHabitaciones = document.getElementById('num_hab').value; // Numero de habitaciones
	
	if(comprobarLlegada(iDayLlegada,iMonthLlegada,iYearLlegada) == false)
	{

		alert("La fecha de llegada es invalida, verificala por favor");
		return false;
	}
	if(!comprobarSalida(iDayLlegada,iMonthLlegada,iYearLlegada,iDayF,iMonthF,iYearF))
	{

		alert("La fecha de salida es invalida, verificala por favor");
		return false;
	}

	if((iNumNoches < 1) || (iHabitaciones < 1)) return false; // Comprobamos que el num de habitaciones sea mayor a 1 y las noches como minimo una

	return true;
}

/* Validacion servidor */
function al_inicio(varcaribe)
{
 if (varcaribe==1){
   //window.opener.close();
 }
}

function valida00(theForm1){

  //Traer el dia, mes y año del servidor web
  var YearHoy = theForm1.YearHoy.value;
  var MesHoy = theForm1.MesHoy.value;
  var DiaHoy = theForm1.DiaHoy.value;
  //Concatenarlos en una fecha
  var Fecha_actual = new Date();
  Fecha_actual.setYear( YearHoy );
  Fecha_actual.setMonth( MesHoy);
  Fecha_actual.setDate( DiaHoy );
  //Traer el dia, mes y año de la reservación..
  //el selectedIndex me trae la posición no el valor y se le suma 1 ..
  var chkYear = document.getElementById('llegada_year').value;
  var chkMes  = document.getElementById('llegada_mes').value;
  var chkDia  = document.getElementById('llegada_dia').value;
  // agregado
  var mydateh=new Date()
  var yearh=mydateh.getYear()
  //chkYear = chkYear + 2001;
  chkYear = chkYear;
  chkMes = chkMes;
  chkDia = chkDia;
  //Concatenarlos en una fecha
  var Fecha_reservacion = new Date();
  Fecha_reservacion.setYear( chkYear );
  Fecha_reservacion.setMonth( chkMes);
  Fecha_reservacion.setDate( chkDia );
  //Comparamos las fechas, si la de reservación es menor que la actual
  //impedimos la reservación
  reserva = Fecha_reservacion.valueOf()
  actual = Fecha_actual.valueOf()
  // Asignarle valor a los hidden de la fecha selecionada
  // de la forma de los combos hacia la forma del submit
  var theForm = document.FrontPage_Form1;
  theForm.txtDia_llegada_dia.value = chkDia;
  theForm.txtDia_llegada_mes.value = chkMes;
  theForm.txtDia_llegada_year.value = chkYear;
//Validar fecha
var mes;
var aMes = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
mes = aMes[Math.round(chkMes) - 1];

  var myDateStr = chkDia + ' ' + mes + ' ' + chkYear;
  var myDate = new Date( myDateStr );
  // Convert the date to a string so we can parse it.
  var myDate_string = myDate.toGMTString();
/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */
var myDate_array = myDate_string.split( ' ' );
/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
converts the value to "Mar 3, 1975". Therefore, we compare the month
in the array with the month we entered into the form. If they match,
then the date is valid, otherwise, the date is NOT valid. */
/*if ( myDate_array[2] != mes ) {
  alert( "Fecha inválida.");
  theForm1.llegada_dia.focus();
  return (false);
}
*/
  if (reserva < actual)
  {
	//alert("No puede hacer una reservación para una fecha anterior a la actual.Si entra a la forma.\nY el hoy es: dia " + DiaHoy + "; mes "+ MesHoy +"; año "+ YearHoy +".\n Y el de la escogida es: dia " + chkDia + "; mes "+ chkMes + ";año "+ chkYear +".\nLas fechas concatenadas de actual: " +  actual + " y la de reservacion " + reserva);
	alert('No puede hacer una reservación para una fecha anterior a la actual.');
    theForm1.llegada_dia.focus();
	return (false);
  }

var numnoches = theForm.numnoches.value;
var f_r1_i=new Date();
var f_r1_f=new Date();
var f_r2_i=new Date();
var f_r2_f=new Date();
var f_r3_i=new Date();
var f_r3_f=new Date();

f_r1_i.setFullYear(2010,4,1);
f_r1_f.setFullYear(2010,4,4);

f_r2_i.setFullYear(2010,4,2);
f_r2_f.setFullYear(2010,4,5);

f_r3_i.setFullYear(2010,4,3);
f_r3_f.setFullYear(2010,4,6);


if ((reserva>=f_r1_i) && (reserva <= f_r1_f) && (numnoches < 3))
{
	alert("La estancia mínima es de 3 Noches para esta fecha.");
	return (false);
}

if ((reserva>=f_r2_i) && (reserva <= f_r2_f) && (numnoches < 3))
{
	alert("La estancia mínima es de 3 Noches para esta fecha.");
	return (false);
}

if ((reserva>=f_r3_i) && (reserva <= f_r3_f) && (numnoches < 3))
{
	alert("La estancia mínima es de 3 Noches para esta fecha.");
	return (false);
}

return(true);
}

function valida01(theForm)
{
	var numcuarto = theForm.numcuarto.value;
	var numnoches = theForm.numnoches.value;
	var numadultos = theForm.num_adultos.value;

	var resultado = true;

	if (valida00(document.FrontPage_Form1) == false) return(false);

	//Tiene que haber cuartos indicados para reservar!!!
	if (theForm.numcuarto.value == "")
	{
		alert("Escriba un valor para el campo No. de Habitaciones.");
		theForm.numcuarto.focus();
		resultado = false;
	}



	if (isNaN(parseInt(numcuarto)))
	{
		alert("No. de Habitaciones incorrecto.");
		theForm.numcuarto.focus();
		resultado = false;
	}

	theForm.numcuarto.value=parseInt(numcuarto);
	if (numcuarto <= 0)
	{
		alert('Coloque al menos una habitacion.');
		theForm.numcuarto.focus();
		resultado = false;
	}

	if (numcuarto > 9)
	{
		alert("El No. de Habitaciones hace que esta reservacion se considere de Grupo. No se puede realizar por este medio.");
		theForm.numcuarto.focus();
		resultado = false;
	}

	if ( numnoches <= 0)
	{
		alert("La fecha de llegada no debe ser la misma que la de salida");
		theForm.numnoches.focus();
		resultado = false;
	}

	var sumaninos = parseInt(theForm.rango1.value) + parseInt(theForm.rango2.value) + parseInt(theForm.rango3.value);
	if ((numadultos == 4) && (sumaninos > 0))
	{
		alert("Imposible combinación de adultos y niños. Ver políticas de reservaciones");
		theForm.num_adultos.focus();
		resultado = false;
	}

	if ((numadultos == 3) && (sumaninos > 1))
	{
		alert("Imposible combinación de adultos y niños. Ver políticas de reservaciones");
		theForm.num_adultos.focus();
		resultado = false;
	}
	
	if ((numadultos == 2) && (sumaninos > 2))
	{
		alert("Imposible combinación de adultos y niños. Ver políticas de reservaciones");
		theForm.num_adultos.focus();
		resultado = false;
	}

	if ((numadultos == 1) && (sumaninos > 3))
	{
		alert("Imposible combinación de adultos y niños. Ver políticas de reservaciones");
		theForm.num_adultos.focus();
		resultado = false;
	}
		
		return(resultado);
	

}