/**
 * Function for creating calendars on the website
 * 
 * @param inputField
 *            the textfield that is used for the date
 * @param trigger
 *            the trigger for opening the calendar (can be a button/img/div etc)
 */
function createCalendar(inputField, trigger) {
	createCalendar(inputField, trigger, "Tl");
}

/**
 * Function for creating calendars on the website
 * 
 * @param inputField
 *            the textfield that is used for the date
 * @param trigger
 *            the trigger for opening the calendar (can be a button/img/div etc)
 * @param align
 *            the alignment of the calendar
 */
function createCalendar(inputField, trigger, align) {

	Calendar.setup( {
		inputField :inputField,
		ifFormat :"%d/%m/%Y",
		button :trigger,
		align :align,
		singleClick :true,
		showOthers :true,
		cache :true,
		dateStatusFunc :isDateDisabled,
		range : [ calendarStartDate.getFullYear(),
				calendarEndDate.getFullYear() + 1 ]
	});

	$(inputField).writeAttribute('autocomplete', value = 'off');

	$(inputField).observe('focus', function(event) {
		if (this.value == 'dd/mm/yyyy') {
			this.value = "";
		}
		$(trigger)['onclick'].call();
	});

	$(inputField).observe('blur', function(event) {
		if (this.value == "") {
			this.value = 'dd/mm/yyyy';
		}
		window.calendar.callCloseHandler();
	});
}

/**
 * Function for creating calendars on the website with drop downs for the dates.
 * 
 * @param inputField
 *            the textfield that is used for the date
 * @param trigger
 *            the trigger for opening the calendar (can be a button/img/div etc)
 */
function createCalendarWithDropDowns(inputField, trigger) {
	createCalendarWithDropDowns(inputField, trigger, "Tl");
}

/**
 * Function for creating calendars on the website with drop downs for the dates.
 * 
 * @param inputField
 *            the textfield that is used for the date
 * @param trigger
 *            the trigger for opening the calendar (can be a button/img/div etc)
 * @param align
 *            the alignment of the calendar
 */
function createCalendarWithDropDowns(inputField, trigger, align) {
	function onUpdate(cal) {
		setDropDownDates(inputField, cal.params.inputField.value);
	};

	Calendar.setup( {
		inputField :inputField,
		ifFormat :"%d/%m/%Y",
		button :trigger,
		align :align,
		singleClick :true,
		showOthers :true,
		cache :true,
		dateStatusFunc :isDateDisabled,
		range : [ calendarStartDate.getFullYear(),
				calendarEndDate.getFullYear() + 1 ],
		onUpdate :onUpdate
	});

	setDropDownDates(inputField, null);
	Event.observe($('departureSelect'), 'change', function(e){setDropDownDates(inputField, $F(inputField))});
	Event.observe($('destinationSelect'), 'change', function(e){setDropDownDates(inputField, $F(inputField))});
}
