// functions.js checks form data calls alquiler-coche-datos.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 vuelo=document.getElementById('vuelo').value; // OJO
	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 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);
	d = new Date();
	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 = "Oops, maximum rental period is 30 days.\n\n";}
	
	
	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 ((recogida != 31) && (recogida != 70) && (recogida != 80)) {
		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 (dias == 0) {
		msg+="Oops, 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-info2.php?recogida='+recogida+'&devolucion='+devolucion+'&fechainicio='+fechainicio+'&fechafin='+fechafin+'&horainicio='+horainicio+'&horafin='+horafin+'&booster='+booster+'&sillita='+sillita+'&dias='+dias+'&grupo='+grupo+'&vuelo='+vuelo+'&importe='+encodeURIComponent(importe);
	} else { 
		msg+="Thank You.";
		alert(msg);
	}
}
