// functions.js checks form data calls car-hire-info.php
function ActionDetermina(){
	var recogida=document.getElementById('select').value;
	var devolucion=document.getElementById('select2').value;
	var fechainicio=document.getElementById('datBegin').value;
	var fechafin=document.getElementById('datEnd').value;
	var horainicio=document.getElementById('horainicio').value;
	var horafin=document.getElementById('horafin').value;
	var booster=document.getElementById('booster').value;
	var sillita=document.getElementById('sillita').value;
	var dias=document.getElementById('hdias').value;
	var grupo=document.getElementById('hgrupo').value;
	var importe=document.getElementById('hprecio').value;	
	var dday   = (document.getElementById('datBegin').value).substr(0,2);
	var dmonth = (document.getElementById('datBegin').value).substr(3,2) - 1;
	var dyear  = (document.getElementById('datBegin').value).substr(6,4);
	var desde  = new Date(dyear,dmonth,dday);
	var dday   = (document.getElementById('datEnd').value).substr(0,2);
	var dmonth = (document.getElementById('datEnd').value).substr(3,2) - 1;
	var dyear  = (document.getElementById('datEnd').value).substr(6,4);
	var hasta  = new Date(dyear,dmonth,dday);
	var in23 = new Date(2009,11,23); // Ojo, el mes - 1
	var in26 = new Date(2009,11,26);
	var in2  = new Date(2010,0,2);
	var in30 = new Date(2009,11,30);		
	var inicio_temporada = new Date(2010,2,1);
	var day0   = (document.getElementById('datBegin').value).substr(0,2);
	var month0 = (document.getElementById('datBegin').value).substr(3,2) - 1;
	var year0  = (document.getElementById('datBegin').value).substr(6,4);
	msg='';
	//Set the two dates
	var today=new Date(year0,month0,day0);
	var christmas=new Date(dyear, dmonth, dday);
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24
	//Calculate difference btw the two dates, and convert to days
	if ( (Math.ceil((christmas.getTime()-today.getTime())/(one_day))) > 30) { msg = "Ooops, maximum rental period is 30 days.\n\n";}
	
	
	d = new Date();
	
	if ((year0 < d.getFullYear()) || (year0 == d.getFullYear() && month0 < d.getMonth()) || (year0 == d.getFullYear() && month0 == d.getMonth() && day0 <= d.getDate())) { 
		msg+="You are trying to start the rental period earlier than today’s date. Please, revise the rental start date and try again.\n\n";
	}
	else if (year0 == d.getFullYear() && month0 == d.getMonth() && day0 <= d.getDate()+ 1) {
		var x0 = 1;
		x0 =  horainicio.substr(0,2);
			
		if ((eval(d.getHours() - x0) > 11) && (x0 < 12) && (d.getHours() > 12)) { 
			msg+="Our Reservation department needs at least 24 hours before the pick-up hour to process the booking.\n\n";
		}
	} 
	
	if ((desde < inicio_temporada) && (recogida != 31) && (recogida != 80) && (recogida != 82) && (recogida != 32) && (recogida != 61)) {
		msg+="Sorry we have no service for the selected office before March 1st.\n\n";
	} else if ((recogida != 80) && (recogida != 31) && (recogida != 82)) { // Horario de oficinas que no sean aeropuertos
		if (recogida == 61 ) {
			if (((horainicio < '08:30') || (horainicio > '20:00')  ) || ((horafin < '08:30') || (horafin > '20:00') )) {
					msg+="Opening hours in Formentera from 8:30 to 20:00.\n\n";	
				} 
			}
		else 
		if (((horainicio < '08:30') || (horainicio > '20:00') || ((horainicio > '13:00' ) && (horainicio < '16:30') ) ) || ((horafin < '08:30') || (horafin > '20:00') || ((horafin > '13:00' ) && (horafin < '16:30') ) )) {
			msg+="Opening hours for selected location are 8:30 to 13:00 & from 16:30 to 20:00.\n\n";	
		} 
	} 
		
	if  (((desde > in23) && (desde < in26)) || ((desde > in30) && (desde < in2))) {
		msg+="Sorry we have no pick up - drop off service for December 24,25 and 31 and January 1st.\n\n"; 	
	}
	
	if (dias == 0) {
		msg+="Please check the dates.\n\n"; 
	} 
	if (importe == 0) {
		msg+="Please check the selection data.\n\n"; 
	} 
	if (document.getElementById('clausulas').checked == false) {
		msg+="Please check our terms & conditions.\n\n"; 
	}
	if (msg=='') {
	document.location = '../../car-hire-info.php?recogida='+recogida+'&devolucion='+devolucion+'&fechainicio='+fechainicio+'&fechafin='+fechafin+'&horainicio='+horainicio+'&horafin='+horafin+'&booster='+booster+'&sillita='+sillita+'&dias='+dias+'&grupo='+grupo+'&importe='+encodeURIComponent(importe);
	} else { 
		msg+="Thank you.";
		alert(msg);
	}
}

