
// ----------------------------------------------------------------------
//  INTELLIGENT FORMS VALIDATION
// ----------------------------------------------------------------------


// -----------------------------------------------------------------------------------------
// CALENDAR
// -----------------------------------------------------------------------------------------

// Variables for the calendar on Step 1
//bank holidays for the year 2010 below
//var bankHolidays = [ [1, 1, 2010, 'bank'], [2, 4, 2010, 'bank'], [5, 4, 2010, 'bank'], [3, 5, 2010, 'bank'], [31, 5, 2010, 'bank'], [30, 8, 2010, 'bank'], [27, 12, 2010, 'bank'], [28, 12, 2010, 'bank'] ];
//bank holidays for the year 2011 below
var bankHolidays = [ [3, 1, 2011, 'bank'], [22, 4, 2011, 'bank'], [25, 4, 2011, 'bank'],[29, 4, 2011, 'bank'], [2, 5, 2011, 'bank'], [30, 5, 2011, 'bank'], [29, 8, 2011, 'bank'], [26, 12, 2011, 'bank'], [27, 12, 2011, 'bank'] ];
var season1Start = new Date();
season1Start.setDate(season1Start.getDate()+1);
var season1End   = new Date(2012,11,31);	//modified as 31 December, 2011 on 17/Jan/2011
var season2Start = new Date(2012,0,1);//new start date for next year i.e. 1/1/2012
//season2Start.setDate(season2Start.getDate()+1);
var season2End   = new Date(2012,11,31);	// modified as 31 December, 2012 on 8/Sep/2011
//alert(season2End);
// -----------------------------------------------------------------------------------------


// set the first possible ARRIVAL date
function arrivalStartDate() {
	var todayDate = new Date();
	if ( todayDate < season1Start ) {
		return season1Start;
	} else {
		//If the time is past 7PM, suggest tommorrow's arrival
		if (todayDate.getHours() > 18) {
			todayDate.setDate(todayDate.getDate()+1);
		}
		return todayDate;
	}
}

// HIGHLIGHT the bank holiday or DISABLE the out-of-season date
function checkThisDay(date) {
		if ( date.getTime() <= season1End.getTime() || date.getTime() >= season2Start.getTime() ) {
		//if ( date.getTime() <= season1End.getTime() ) {
			for (i = 0; i < bankHolidays.length; i++) {
				if (  date.getDate() == bankHolidays[i][0] && date.getMonth() == bankHolidays[i][1] - 1 && date.getFullYear() == bankHolidays[i][2]) {
					return [true, 'datepicker_' + bankHolidays[i][3] + 'Holiday'];
				}
			}
			return [true, ''];
		} else {
			return [false, ''];
		}
}

// CREATE the calendar for step 1
jQuery(function($){

	jQuery(".departureFromText").attachDatepicker({
		minDate: arrivalStartDate(),
		maxDate: season2End, // set this to season2End to cover 2 seasons
		dateFormat: 'dd/mm/yy',
	    	mandatory: true,
		showStatus: true,
		closeAtTop: false,
		firstDay: 1,
		changeFirstDay: false,
		showOn: 'both',
		buttonImage: '/images/NonTridion/icon_calendar.gif',
		buttonText: 'See Calendar',
		buttonImageOnly: true,
		appendText: '',
		beforeShowDay: checkThisDay,
		prevText: '< Prev',
		nextText: 'Next >',
		keyDatesMessage: '<div class="datepicker_keyDates">Bank Holidays are marked in yellow</div>',
		blackoutStart: season1End,
		blackoutEnd: season2Start
	});
	   
	
});
