﻿// JavaScript Document


function validar(inform) {
  
  var v_year=document.frmMain.f_year.value;
  var v_mes=document.frmMain.f_mes.value;
  var v_dia=document.frmMain.f_dia.value;
    
  var fecha= new Date(v_year,v_mes-1,v_dia);

//ADVANCE BOOKING (fecha inicio reserva)

  var v_year_i=document.frmMain.f_year.value;
  var v_mes_i=document.frmMain.f_mes.value;
  var v_dia_i=document.frmMain.f_dia.value;
  var v_hora_i=document.frmMain.f_hora.value;
    
  var fecha_i= new Date(v_year_i,v_mes_i-1,v_dia_i,v_hora_i-2);

//bloquear reservas en domingos
  var fecha_d= new Date(v_year,v_mes-1,v_dia);
//

  var v_year_r=document.frmMain.f_year_r.value;
  var v_mes_r=document.frmMain.f_mes_r.value;
  var v_dia_r=document.frmMain.f_dia_r.value;

  var fecha_r= new Date(v_year_r,v_mes_r-1,v_dia_r);

//bloquear devoluciones en domingos
  var fecha_rd= new Date(v_year_r,v_mes_r-1,v_dia_r);
//

  var now = new Date();
  var v_year_c=now.getFullYear();
  var v_month_c=now.getMonth();
  var v_day_c=now.getDate();	
  var v_hour_c=now.getHours();
  
  var date_c= new Date(v_year_c,v_month_c,v_day_c,v_hour_c);
  
  var v_horariod = ( "Miraflores, Barranco, San Borja & San Isidro locations are closed on Sundays.\n\nPlease choose another date or select an Airport location\nfor your vehicle pick up.\nAirport stations are open 24 hours/day 365 days a year." );
  
  var v_horariodr = ( "Miraflores, Barranco, San Borja & San Isidro locations are closed on Sundays.\n\nPlease choose another date or select an Airport location\nfor your vehicle return.\nAirport stations are open 24 hours/day 365 days a year." );
  
  var v_horariols = ( "Please check Customer Service Hours for your pick up:\n\nSan Isidro, Barranco, San Borja & Miraflores locations opens:\n-Monday through Friday 8:30 to 18:30\n-Saturdays 9:00 to 16:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );
  
  var v_horariolsd = ( "Please check Customer Service Hours for your return:\n\nSan Isidro, Barranco, San Borja & Miraflores locations opens:\n-Monday through Friday 8:30 to 18:30\n-Saturdays 9:00 to 16:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );
  
    var v_horario24 = ( "Please check Customer Service Hours:\n\nOn December 24th, Barranco, San Borja & Miraflores locations\nwill be open from 8:30 to 13:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario25 = ( "Please check Customer Service Hours:\n\nOn December 25th, Barranco, San Borja & Miraflores locations will be closed.\n\nPlease choose a different date or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario31 = ( "Please check Customer Service Hours:\n\nOn December 31th, Barranco, San Borja & Miraflores locations\nwill be open from 8:30 to 13:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario1 = ( "Please check Customer Service Hours:\n\nOn January 1st, Barranco, San Borja & Miraflores locations will be closed.\n\nPlease choose a different date or select an Airport location\nwhich are open 24 hours/day 365 days a year." );
	
	var v_horario31 = ( "Please check Customer Service Hours:\n\nOn July 28th, Barranco, San Borja & Miraflores locations\nwill be open from 8:30 to 13:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario1 = ( "Please check Customer Service Hours:\n\nOn July 29th, Barranco, San Borja & Miraflores locations will be closed.\n\nPlease choose a different date or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario09 = ( "Please check Customer Service Hours:\n\nOn April 9th, Barranco, San Borja & Miraflores locations\nwill be open from 8:30 to 13:00\n\nChoose a different hour or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario10 = ( "Please check Customer Service Hours:\n\nOn April 10th, Barranco, San Borja & Miraflores locations will be closed.\n\nPlease choose a different date or select an Airport location\nwhich are open 24 hours/day 365 days a year." );

    var v_horario296 = ( "Please check Customer Service Hours:\n\nOn June 29th, Barranco, San Borja & Miraflores locations will be closed.\n\nPlease choose a different date or select an Airport location\nwhich are open 24 hours/day 365 days a year." );
	
	var v_horarioBarranco = ( "Barranco location will be available starting November 30." );
	
	var v_horarioSI = ( "San Isidro location will close its operations starting November 30.\n\nWe suggest to change your reservation to San Borja location,\nat just 12 blocks away from San Isidro office." );


// Bloqueo de reservas y devoluciones antes del 30 de noviembre Barranco
	if (document.frmMain.f_agencia.selectedIndex == 4
		&& document.getElementById("f_year").value == "2009"
		&& document.getElementById("f_mes").value == "11"
		&& document.getElementById("f_dia").value <= "28") { 
		alert ( v_horarioBarranco );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex == 4
		&& document.getElementById("f_year_r").value == "2009"
		&& document.getElementById("f_mes_r").value == "11"
		&& document.getElementById("f_dia_r").value <= "28") { 
		alert ( v_horarioBarranco );
		return false; 
		}


// Bloqueo de reservas y devoluciones pasado el 28 de noviembre San Isidro
	if (document.frmMain.f_agencia.selectedIndex == 5
		&& document.getElementById("f_year").value == "2009"
		&& document.getElementById("f_mes").value == "11"
		&& document.getElementById("f_dia").value >= "30") { 
		alert ( v_horarioSI );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex == 5
		&& document.getElementById("f_year").value == "2009"
		&& document.getElementById("f_mes").value == "12") { 
		alert ( v_horarioSI );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex == 5
		&& document.getElementById("f_year").value == "2010") { 
		alert ( v_horarioSI );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex == 5
		&& document.getElementById("f_year_r").value == "2009"
		&& document.getElementById("f_mes_r").value == "11"
		&& document.getElementById("f_dia_r").value >= "30") { 
		alert ( v_horarioSI );
		return false; 
		}
		

//bloquear reservas en domingos para Miraflores, San Isidro y San Borja
	if (document.frmMain.f_agencia.selectedIndex >= 2 &&  fecha_d.getDay() == 0 ){
		alert(v_horariod);
		return false;
		}

//bloquear devoluciones en domingos para Miraflores, San Isidro y San Borja
	if (document.frmMain.f_agencia_r.selectedIndex >= 2 &&  fecha_rd.getDay() == 0 ){
		alert(v_horariodr);
		return false;
		}


//Cliente debe escoger una opción de fecha

	if (document.getElementById("f_dia").value == "0") { 
		alert ("Please select your pick up date.");
		return false; 
		}
		
	if (document.getElementById("f_mes").value == "0") { 
		alert ("Please select your pick up month.");
		return false; 
		}
	
	if (document.getElementById("f_year").value == "") { 
		alert ("Please select your pick up year.");
		return false; 
		}


// Bloqueo de reservas de menos de 1 día o devoluciones antes al recojo
	if (fecha >= fecha_r){
		alert("Return date must be later than pick up date.");
		return false; 
	    }

// Bloqueo de horas de lunes a viernes Miraflores, San Isidro y San Borja recojo y devolución
						
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.frmMain.f_hora.selectedIndex >= 19 || document.frmMain.f_hora.selectedIndex <= 8) ){
		alert ( v_horariols );
        return false;
    	}
		else if
	   (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.frmMain.f_hora_r.selectedIndex >= 19 || document.frmMain.f_hora_r.selectedIndex <= 8) ){
		alert ( v_horariolsd );
        return false;
    	}
		else {}	

// Bloqueo de horas para sábados Miraflores, San Isidro y San Borja recojo y devolución
						
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.frmMain.f_hora.selectedIndex >= 17 || document.frmMain.f_hora.selectedIndex <= 8)
		&& (fecha_d.getDay() == 6 ) ){
		alert ( v_horariols );
        return false;
    	}
		else if
	   (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.frmMain.f_hora_r.selectedIndex >= 17 || document.frmMain.f_hora_r.selectedIndex <= 8)
		&& (fecha_d.getDay() == 6 ) ){
		alert ( v_horariolsd );
        return false;
    	}
		else {}	

// Bloqueo de reservas Navidad, Año Nuevo y Fiestas Patrias

	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.getElementById("f_mes").value == "12"
		&& document.getElementById("f_dia").value == "24")
		&& (document.frmMain.f_hora.selectedIndex <= 8 || document.frmMain.f_hora.selectedIndex >= 13) ) { 
		alert ( v_horario24 );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.getElementById("f_mes").value == "12"
		&& document.getElementById("f_dia").value == "31") 
		&& (document.frmMain.f_hora.selectedIndex <= 8 || document.frmMain.f_hora.selectedIndex >= 13) ) { 
		alert ( v_horario31 );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.getElementById("f_mes").value == "07"
		&& document.getElementById("f_dia").value == "28") 
		&& (document.frmMain.f_hora.selectedIndex <= 8 || document.frmMain.f_hora.selectedIndex >= 13) ) { 
		alert ( v_horario28 );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& document.getElementById("f_mes").value == "12"
		&& document.getElementById("f_dia").value == "25") { 
		alert ( v_horario25 );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& document.getElementById("f_mes").value == "01"
		&& document.getElementById("f_dia").value == "01") { 
		alert ( v_horario1 );
		return false; 
		}
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& document.getElementById("f_mes").value == "07"
		&& document.getElementById("f_dia").value == "29") { 
		alert ( v_horario29 );
		return false; 
		}	


// Bloqueo de devoluciones Navidad, Año Nuevo y Fiestas Patrias

	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.getElementById("f_mes_r").value == "12"
		&& document.getElementById("f_dia_r").value == "24")
		&& (document.frmMain.f_hora_r.selectedIndex <= 8 || document.frmMain.f_hora_r.selectedIndex >= 13) ) { 
		alert ( v_horario24 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.getElementById("f_mes_r").value == "12"
		&& document.getElementById("f_dia_r").value == "31") 
		&& (document.frmMain.f_hora_r.selectedIndex <= 8 || document.frmMain.f_hora_r.selectedIndex >= 13) ) { 
		alert ( v_horario31 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.getElementById("f_mes_r").value == "07"
		&& document.getElementById("f_dia_r").value == "28") 
		&& (document.frmMain.f_hora.selectedIndex <= 8 || document.frmMain.f_hora.selectedIndex >= 13) ) { 
		alert ( v_horario28 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& document.getElementById("f_mes_r").value == "12"
		&& document.getElementById("f_dia_r").value == "25") { 
		alert ( v_horario25 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& document.getElementById("f_mes_r").value == "01"
		&& document.getElementById("f_dia_r").value == "01") { 
		alert ( v_horario1 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& document.getElementById("f_mes_r").value == "07"
		&& document.getElementById("f_dia_r").value == "29") { 
		alert ( v_horario29 );
		return false; 
		}

		
// Bloqueo de reservas y devoluciones Semana Santa 2010
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& (document.getElementById("f_year").value == "2010"
		&& document.getElementById("f_mes").value == "04"
		&& document.getElementById("f_dia").value == "01") 
		&& (document.frmMain.f_hora.selectedIndex <= 8 || document.frmMain.f_hora.selectedIndex >= 13) ) { 
		alert ( v_horario09 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& (document.getElementById("f_year_r").value == "2010"
		&& document.getElementById("f_mes_r").value == "04"
		&& document.getElementById("f_dia_r").value == "01") 
		&& (document.frmMain.f_hora_r.selectedIndex <= 8 || document.frmMain.f_hora_r.selectedIndex >= 13) ) { 
		alert ( v_horario31 );
		return false; 
		}			
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& document.getElementById("f_year").value == "2010"
		&& document.getElementById("f_mes").value == "04"
		&& document.getElementById("f_dia").value == "02") { 
		alert ( v_horario10 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& document.getElementById("f_year_r").value == "2010"
		&& document.getElementById("f_mes_r").value == "04"
		&& document.getElementById("f_dia_r").value == "02") { 
		alert ( v_horario1 );
		return false; 
		}		

// Bloqueo de reservas y devoluciones 29 de junio
	if (document.frmMain.f_agencia.selectedIndex >= 2
		&& document.getElementById("f_mes").value == "06"
		&& document.getElementById("f_dia").value == "29") { 
		alert ( v_horario296 );
		return false; 
		}
	if (document.frmMain.f_agencia_r.selectedIndex >= 2
		&& document.getElementById("f_mes_r").value == "06"
		&& document.getElementById("f_dia_r").value == "29") { 
		alert ( v_horario296 );
		return false; 
		}


		
//Bloqueo de reservas anteriores a la fecha en curso

    if (fecha_i < date_c){
        alert("Your Reservation must be done with at least 1 hour in Advance Booking.");
        return false; 
        }
}
