
var one_day=1000*60*60*24
var today = new Date();
var yearTo = today.getFullYear()+1;


function validateDate(inputArray, endDate){
	
	//Validate the date is a true date
	var d = new Date(inputArray.year, inputArray.month - 1, inputArray.day);	
 	if(!(d.getDate() == inputArray.day && d.getMonth() + 1 == inputArray.month && d.getFullYear() == inputArray.year)){
// 		alert('Please enter a valid date.');
		return false;
 	}
 	
 	var checkDate = new Date(inputArray.year, inputArray.month-1, inputArray.day) //Month is 0-11 in JavaScript	
/*	//Check if either date is in july/august, if so, it must be a sat
	if((inputArray.month == 7 || inputArray.month == 8) && checkDate.getDay() != 6){
		alert('During July and August bookings must be made from Saturday to Saturday.  Please amend your dates.');
		return false;
	}*/
	
	var checkDateFrom = new Date(inputArray.year, inputArray.month-1, inputArray.day) //Month is 0-11 in JavaScript						
	//Check that the departure is more than 48 hours from today
	if(Math.ceil((checkDateFrom.getTime()-today.getTime())/(one_day) < 2) && 0){
		alert("Online bookings cannot be made within 48 hours of the desired booking date");	
		return false;
	}	
	
	//Check date does not exceed end date
	if(endDate){
		
		var end = new Date(endDate.year, endDate.month - 1, endDate.day)
		if(checkDate.getTime() > end.getTime()){
			var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dev'];
			var days = ['Sun','Mon','Tues','Wed','Thurs','Fri','Sat'];
			alert('Online bookings can only be made until '+ days[end.getDay()] + ' ' + end.getDate() + ' ' + months[end.getMonth()] + ' ' + end.getFullYear())
			return false;
		}
	}
	return true;
}

function validateDateRange(calObject, dateFrom, dateTo){
		alert('validateDateRange');
	//Check both dates are set
	/*if(!dateFrom || !dateTo){
		alert("Your must select an arrival and departure date");
		return false;
	}*/
	
/*	var checkDateFrom = new Date(dateFrom.year, dateFrom.month-1, dateFrom.day) //Month is 0-11 in JavaScript
	var checkDateTo = new Date(dateTo.year, dateTo.month-1, dateTo.day) //Month is 0-11 in JavaScript
	
	//Check if departure if before arrival
	if(checkDateTo.getTime() <= checkDateFrom.getTime()){
		alert("Your departure date must be after your arrival date");
		return false;
	}
	
	//Check if the booking is for less than 3 nights
	if(Math.ceil((checkDateTo.getTime()-checkDateFrom.getTime())/(one_day)) < 3){
		alert("You must select a minimum of 3 nights.");
		return false;
	}
	
	//Check if the booking is for more than 3 weeks
	if(Math.ceil((checkDateTo.getTime()-checkDateFrom.getTime())/(one_day)) > 21){
		alert("You can not book a property for more than 3 weeks. Please amend your selection or call 01803 855282");			
		return false;
	}
	
	//Creater a temporary date variable to use in isDateWithinValidRange
	var tempDateFrom = new Date();
	tempDateFrom.setFullYear(dateFrom.year,dateFrom.month-1,dateFrom.day);
	
	var tempDateTo = new Date();
	tempDateTo.setFullYear(dateTo.year,dateTo.month-1,dateTo.day);	

	while(Date.parse(tempDateFrom) <= Date.parse(tempDateTo)){
		//Create temporary variables to hold current days date
		var day = tempDateFrom.getDate();
		var month = tempDateFrom.getMonth()+1;
		var year = tempDateFrom.getFullYear();
	
		//Check if current day is invalid		
		if(!calObject.isDateWithinValidRange({year: year, month:month, day: day})){
			alert("You appear to have selected a date range that falls over a period that is already booked. \nPlease change your selection");		
			return false;
		}		
		//Increment Date
		with (tempDateFrom) setDate(getDate()+1);		
	}
	*/
	return true;	
	
}

function unavailable(xhr){
	alert('We appologize we were unable to retrieve the price for this property. \nPlease call us on 01803 855282 so that we may assist with your enquiry.\nError code:'+xhr.status)
	return false;
}