var startDate;
var endDate;


function filterDates1_car(cal) {
		startDate = new Date(cal.date)
		startDate.setHours(0,0,0,0)	// used for compares without TIME
		/* If they haven't chosen an 
		end date before we'll set it to the same date as the start date This
		way if the user scrolls in the start date 5 months forward, they don't
		need to do it again for the end date.
		*/

		if (endDate == null) { 
			Calendar.setup({

			inputField  : "car_second",         // ID of the input field
			button      : "car_trigger_seconf",       // ID of the button
			ifFormat       :    "%b %d, %Y",      // format of the input field: Mar 18, 2005
			 dateStatusFunc    :    disallowDateBefore //the function to call


			});
		}
	}


function filterDates1_flight(cal) {
		startDate = new Date(cal.date)
		startDate.setHours(0,0,0,0)	// used for compares without TIME
		/* If they haven't chosen an 
		end date before we'll set it to the same date as the start date This
		way if the user scrolls in the start date 5 months forward, they don't
		need to do it again for the end date.
		*/

		if (endDate == null) { 
			Calendar.setup({

			inputField  : "flight_second",         // ID of the input field
			button      : "flight_trigger_second",       // ID of the button
			ifFormat       :    "%b %d, %Y",      // format of the input field: Mar 18, 2005
			 dateStatusFunc    :    disallowDateBefore //the function to call


			});
		}
	}



		/* 
		* Check-Out calendar allowed dates
		* Check-Out date can not be BEFORE Check-In date
		* Check-Out date can not be before today
		*/
function disallowDateBefore(dateCheckOut) {
	dateCheckOut.setHours(0,0,0,0)
	if ((startDate != null) && startDate > dateCheckOut)
		// startDate is defined, make sure cal date is NOT before start date
		return true; 
	
	var now = new Date()
	now.setHours(0,0,0,0)
	if (dateCheckOut < now) 
		// check out date can not be befor today if startDate NOT defined
		return true;

	return false;
}



	/* 
		* Check-In date checking
		* Check-In date can not be AFTER Check-Out date
		* Check-In date can not be before today
		*/
		function disallowDateAfter(dateCheckIn) {
			dateCheckIn.setHours(0,0,0,0)
			if ((endDate != null) && dateCheckIn > endDate)
				// endDate defined, calendar date can NOT be after endDate
				return true;

			var now = new Date()
			now.setHours(0,0,0,0)

			if (dateCheckIn < now)
				// endDate NOT defined, calendar date can not be before today
				return true;

			return false;
		}






/* 
* Can't choose days before today or before the
* start date
*/


function disableDates_custom(date) {
	var noLongerValid = new Date();
	noLongerValid.setDate(noLongerValid.getDate()-1+7)

	if (date.getTime() < noLongerValid.getTime())
		return true; // true says "disable"
	else
		return false; // leave other dates enabled

}




/*
car
*/
Calendar.setup({

	inputField  : "car_first",         // ID of the input field
	button      : "car_trigger_first",       // ID of the button
	ifFormat       :    "%b %d, %Y",      // format of the input field: Mar 18, 2005
	dateStatusFunc    :    disallowDateAfter, //the function to call
	//onUpdate       :    filterDates1_car
	dateStatusFunc    :    disableDates_custom

});

Calendar.setup({

	inputField     :    "car_second",
	button         :    "car_trigger_second",  // What will trigger the popup of the calendar
	ifFormat       :    "%b %d, %Y",       // format of the input field: Mar 18, 2005
	//dateStatusFunc    :    disallowDateBefore
	dateStatusFunc    :    disableDates_custom

});


/*
flight
*/

Calendar.setup({

	inputField  : "flight_first",         // ID of the input field
	button      : "flight_trigger_first",       // ID of the button
	ifFormat       :    "%b %d, %Y",      // format of the input field: Mar 18, 2005
	dateStatusFunc    :    disallowDateAfter, //the function to call
	onUpdate       :    filterDates1_flight

	});

Calendar.setup({

	inputField  : "flight_second",         // ID of the input field
	button      : "flight_trigger_second",       // ID of the button
	ifFormat       :    "%b %d, %Y",       // format of the input field: Mar 18, 2005
	dateStatusFunc    :    disallowDateBefore //the function to call

});



/*
custom vacation
*/
Calendar.setup({

	inputField  : "custom_first",         // ID of the input field
	button      : "custom_trigger_first",       // ID of the button
	ifFormat       :    "%b %d, %Y",      // format of the input field: Mar 18, 2005
	dateStatusFunc    :    disableDates_custom

});