var newskiesValidation = Class.create(
{
	cutoverDate: Array(),
	dateFrom: null,
	dateTo: null,

	travelsOnCutover: false,


	/**
		* Class initialisation function
		* sets travel dates etc and checks if they coincide with the planned new skies cutover
		* dates expected in the format of yyyymmdd
		*/
	initialize: function (travelStart, travelEnd, cutoverDate) {
		this.dateFrom = travelStart;
		this.dateTo   = travelEnd;

		if ( (typeof(cutoverDate) != 'undefined') && cutoverDate ) {
			if (typeof(cutoverDate) == 'array' || typeof(cutoverDate) == 'object') {
				this.cutoverDate = cutoverDate;
			}
			else {
				this.cutoverDate = Array(cutoverDate);
			}
		}
		else {
			this.cutoverDate = Array("20100613"); // use default dates for cutover if none was specified
		}
		this.travelsOnCutover = this.checkCutoverDay();
	},


	/**
		* compares start and end travel dates to the cutover date, in the format of yyyymmdd
		*/
	checkCutoverDay: function () {
		for (iloop = 0; iloop < this.cutoverDate.length; iloop ++) {
			cutoverDate = this.cutoverDate[iloop];
			if ( (this.dateFrom == cutoverDate) || (this.dateTo == cutoverDate) ) {
				return true;
			}
		}
		return false;
	},


	/**
		* compares start and end travel dates to the cutover date, using date objects
		* Arguments:
		*		dateFrom (string)   : in the format of dd/mm/yyyy
		*		dateTo   (string)   : in the format of dd/mm/yyyy
		*/
	checkCutoverDate: function (dateFrom, dateTo) {
		var cutoverDate = new Date(2010, 05, 10);

		// convert dateFrom string to a date object for comparison
		var dateComponents = dateFrom.split("/");
		var travelStart = new Date(dateComponents[2], dateComponents[1], dateComponents[0]);

		// convert dateTo string to a date object for comparison
		dateComponents = dateTo.split("/");
		var travelEnd = new Date(dateComponents[2], dateComponents[1], dateComponents[0]);

		if ( (travelStart == cutoverDate) || (travelEnd == cutoverDate) ) {
			return true;
		}
		return false;
	},


	checkForPopup: function () {
		if (this.travelsOnCutover) {
			this.showPopup();
			return true;
		}
		return false;
	},


	showPopup: function () {
		var path = '/apps/booking_panel/';

		if (typeof(bp_path) != 'undefined') {
			path = bp_path;
		}

		var mURL = path + 'newskies_message.php'
		this.newskiesMessagePanel = new AjaxMessagePanel('newskies-message', mURL);
		this.newskiesMessagePanel.show();
	}
});


