var newwindow = '';

function popUp(url) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','toolbar=no,scrollbars=1,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=571,height=470,left = 100,top = 100');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}

function Reservas_valid(theForm)
{

    var Fecha= theForm.diaingreso.value + '-' + theForm.mesingreso.value + '-' + theForm.anoingreso.value

    // Cadena Año  
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))  
    // Cadena Mes  
    var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))  
    // Cadena Día  
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))  
  
    // Valido el año  
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
        alert('Anio de Fecha de Ingreso invalido')  
		theForm.anoingreso.focus();
        return false  
    }  
    // Valido el Mes  
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
        alert('Mes de Fecha de Ingreso invalido')  
		theForm.mesingreso.focus();
        return false  
    }  
    // Valido el Dia  
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
        alert('Dia de Fecha de Ingreso invalido')  
		theForm.diaingreso.focus();
        return false  
    }  
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
        if (Mes==2 && Dia > 28 || Dia>30) {  
            alert('Dia de Fecha de Ingreso invalido')  
			theForm.diaingreso.focus();
            return false  
        }  
    }  

    Fecha= theForm.diasalida.value + '-' + theForm.messalida.value + '-' + theForm.anosalida.value

    // Cadena Año  
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))  
    // Cadena Mes  
    var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))  
    // Cadena Día  
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))  
  
    // Valido el año  
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
            alert('Anio de Fecha de Salida invalido')  
			theForm.anosalida.focus();
        return false  
    }  
    // Valido el Mes  
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
        alert('Mes de Fecha de Salida invalido')  
		theForm.messalida.focus();
        return false  
    }  
    // Valido el Dia  
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
        alert('Dia de Fecha de Salida invalido')  
		theForm.diasalida.focus();
        return false  
    }  
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
        if (Mes==2 && Dia > 28 || Dia>30) {  
            alert('Dia de Fecha de Salida invalido')  
			theForm.diasalida.focus();
            return false  
        }  
    }  

	var mydate=new Date();
	var year=mydate.getYear();
	var FechaActual;
	
	if (year < 1000)
	year+=1900;

	var day=mydate.getDay();

	var month=mydate.getMonth()+1;
	if (month<10)
		month="0"+month;
	var daym=mydate.getDate();
	if (daym<10)
		daym="0"+daym;

	var myear = year.toString();
	var mmonth = month.toString();
	var mday = daym.toString();

	FechaActual = myear + mmonth + mday
	FechaIngreso = theForm.anoingreso.value + theForm.mesingreso.value + theForm.diaingreso.value
    FechaSalida = theForm.anosalida.value + theForm.messalida.value + theForm.diasalida.value

	parseInt(FechaActual)
	parseInt(FechaIngreso)
	parseInt(FechaSalida)

	if (FechaIngreso < FechaActual)
	{
		alert("La Fecha de Ingreso no puede ser menor a la Fecha Actual.");
		theForm.diaingreso.focus();
		return (false);
	}

	if (FechaSalida < FechaIngreso)
	{
		alert("La Fecha de Salida no puede ser menor a la Fecha de Ingreso.");
		theForm.diasalida.focus();
		return (false);
	}
	
	if (theForm.personas.value == "")
	{
		alert("Ingrese el Numero de Personas.");
		theForm.personas.focus();
		return (false);
	}

	if (!(theForm.habsimple.checked) && !(theForm.habdoble.checked) && !(theForm.habmatrimonial.checked) && !(theForm.habtriple.checked) && !(theForm.habsuite.checked))
	{
		alert("Seleccione el Tipo de Habitacion");
		theForm.habsimple.focus();
		return (false);
	}
	
	if (theForm.habsimple.checked)
	{
		if (theForm.nrosimple.value == "")
		{
			alert("Ingrese el Numero de Habitaciones Simples.");
			theForm.nrosimple.focus();
			return (false);
		}
	}

	if (theForm.habdoble.checked)
	{
		if (theForm.nrodoble.value == "")
		{
			alert("Ingrese el Numero de Habitaciones Dobles.");
			theForm.nrodoble.focus();
			return (false);
		}
	}

	if (theForm.habmatrimonial.checked)
	{
		if (theForm.nromatrimonial.value == "")
		{
			alert("Ingrese el Numero de Habitaciones Matrimoniales.");
			theForm.nromatrimonial.focus();
			return (false);
		}
	}

	if (theForm.habtriple.checked)
	{
		if (theForm.nrotriple.value == "")
		{
			alert("Ingrese el Numero de Habitaciones Triples.");
			theForm.nrotriple.focus();
			return (false);
		}
	}

	if (theForm.habsuite.checked)
	{
		if (theForm.nrosuite.value == "")
		{
			alert("Ingrese el Numero de Suites.");
			theForm.nrosuite.focus();
			return (false);
		}
	}

	return (true);
}