function check_book_dates(formfrom,formto) 
{
var form = document.forms['quickbooking']
	var one_day=1000*60*60*24;
	var from = formfrom.value;
	var to = formto.value;
	var checkdate = parseDate(from, 'd/M/y');
	var todate = parseDate(to, 'd/M/y');
 	if ((isDate(to,'d/M/y')==true) && (isDate(from,'d/M/y')==true) ) {
		form.action = 'car.php?q=book';
		form.submit();
 	}
 	else {
 		alert ("Please enter a pick-up and drop-off date for your car hire!");
 	} 
}


function calculate_price(formcar,formfrom,formfromhrs,formto,formtohrs,formprice,formpricegbp) 
{
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24;
	var from = formfrom.value;
	var to = formto.value;
	var car = formcar.value;
	var tohrs = formtohrs.value;
	var fromhrs = formfromhrs.value;
	var fromtohrsdif = tohrs - fromhrs;
	var fromdate = parseDate(from, 'd/M/y');
	var checkdate = parseDate(from, 'd/M/y');
	var todate = parseDate(to, 'd/M/y');
	var lowseasonbookingdays = 0;
	var midseasonbookingdays = 0;
	var highseasonbookingdays = 0;
	var price =0;
	
	
	// check if from date contains a date
	// check if to date contains a date 
	// check if starting date is before ending date
	// check if car is selected

 	if ((isDate(to,'d/M/y')==true) && (isDate(from,'d/M/y')==true) && (fromdate < todate) && (car != 'pickbyprice')) { 

		// since days are ok then find how many days is the booking
		var days = Math.ceil((todate.getTime()-fromdate.getTime())/(one_day)); 
		// select the correct rate to charge the customer		
		if (days <= 2) {
			var rate=0;
		}
		else if ((days >= 3) && (days <= 7)) {
			var rate=1;
		}		
		else if (days >= 8) {
			var rate=2;
		}
		// if the hours diference is more than 5 then add another day
		if (fromtohrsdif >= 5){
			//alert ("from "+fromhrs+" to "+tohrs+" dif "+fromtohrsdif); 
			//alert ("extra day added"); 
			todate.setDate(todate.getDate()+1);
			
		}
		
		
		while(checkdate<todate)	{
			

			var period1 = new Date(checkdate.getFullYear(),00,01);
			
			var period2 = new Date(checkdate.getFullYear(),00,11);
			
			var period3 = new Date(checkdate.getFullYear(),03,01);			

			var period4 = new Date(checkdate.getFullYear(),06,01);

			var period5 = new Date(checkdate.getFullYear(),10,01);						
			
			var period6 = new Date(checkdate.getFullYear(),11,20);			
			
			var period7 = new Date(checkdate.getFullYear(),11,31);

			if ((checkdate >= period1) && (checkdate < period2)) {
				midseasonbookingdays++;
			}
			if ((checkdate >= period2) && (checkdate < period3)) {
				lowseasonbookingdays++;
			}
			if ((checkdate >= period3) && (checkdate < period4)) {
				midseasonbookingdays++;
			}
			if ((checkdate >= period4) && (checkdate < period5)) {
				highseasonbookingdays++;
			}
			if ((checkdate >= period5) && (checkdate < period6)) {
				lowseasonbookingdays++;
			}
			if ((checkdate >= period6) && (checkdate < period7)) {
				midseasonbookingdays++;
			}
			
									
			//increment the day we are checking
			checkdate.setDate(checkdate.getDate()+1);
			
		} 
		price = (lowseasonbookingdays * carrate[car][rate]) + (midseasonbookingdays * carrate[car][rate+3]) + (highseasonbookingdays * carrate[car][rate+6]);  
 
		//alert (" Car Hire Pricing Breakdown " 
		//+ "\n From "+ formfrom.value + " to " + formto.value
		//+ "\n ----------------------------------------------------"
		//+ "\n Low Season for "+ lowseasonbookingdays 
		//+ "\n Mid Season for "+ midseasonbookingdays
		//+ "\n high Season  for "+ highseasonbookingdays
		//+ "\n Car "+car  
		//+ "\n ----------------------------------------------------");		
				
		formprice.value = "EUR €"+price;
		formpricegbp.value = "GBP £"+Math.round(price*currrate);
		
	}	
}

function pcheck_book_dates(formfrom,formto) 
{
	var form = document.forms['pquickbooking']
	var one_day=1000*60*60*24;
	var from = formfrom.value;
	var to = formto.value;
	var checkdate = parseDate(from, 'd/M/y');
	var todate = parseDate(to, 'd/M/y');
 	if ((isDate(to,'d/M/y')==true) && (isDate(from,'d/M/y')==true) ) {
		form.action = 'car.php?q=bookparking';
		form.submit();
 	}
 	else {
 		alert ("Please enter arrival and departure dates for your airport parking!");
 	} 
}

function pcalculate_price(formfrom,formfromhrs,formto,formtohrs,formprice,formpricegbp) 
{

	//Set 1 day in milliseconds
	var one_day=1000*60*60*24;
	var from = formfrom.value;
	var to = formto.value;
	var tohrs = formtohrs.value;
	var fromhrs = formfromhrs.value;
	var fromtohrsdif = tohrs - fromhrs;
	var fromdate = parseDate(from, 'd/M/y');
	var checkdate = parseDate(from, 'd/M/y');
	var todate = parseDate(to, 'd/M/y');
	var bookingdays = 0;
	var price =0;
	var priceperday =3;
	var price1stweek =40;
	
	
	// check if from date contains a date
	// check if to date contains a date 
	// check if starting date is before ending date
	// check if car is selected

 	if ((isDate(to,'d/M/y')==true) && (isDate(from,'d/M/y')==true) && (fromdate < todate)) { 

		// since days are ok then find how many days is the booking
		var bookingdays = Math.ceil((todate.getTime()-fromdate.getTime())/(one_day)); 
		// select the correct rate to charge the customer		
		
		// if the hours diference is more than 8 then add another day
		if (fromtohrsdif >= 8){
		bookingdays = bookingdays + 1;
		}
		
		
		if ( bookingdays > 7 )
		{
		price = ((bookingdays - 7) * priceperday) + price1stweek ;  
		} else {
		price = price1stweek;
		}
 		
				
		formprice.value = "EUR €"+price;
		formpricegbp.value = "GBP £"+Math.round(price*currrate);
		
	}	
}