page = {

	/**
	 * default active service
	 * @type {String}
	 * @final
	 * @private
	 */
	activeService: 'htl',

	bind: {
		htlFrm: {
			fromd: { bind:"tod" },
			tod: { bind:"fromd" },
			rooms: { min:1 },
			cty_code: { filter:"htl" }
		},
		chrFrm: {
			fromd: { bind:"tod" },
			tod: { bind:"fromd" },
			dep_cty_air_code: { filter:"chr" },
			arr_cty_air_code: { filter:"chr" },
			ret_cty_air_code: { filter:"chr", empty:"- "+lang.chr.same_as_departure+" -" }
		},
		crrFrm: {
			cty_code: { filter:"crrplace" },
			cars: { min:1 },
			fromd: { bind:"tod" },
			tod: { bind:"fromd" }
		},
		othFrm: {
			fromd_st: { bind:"tod_st" },
			tod_st: { bind:"fromd_st" },
			cty_code: { filter:"oth" }
		},
		trfFrm: {
			trf_date: { bind:"ret_date" },
			ret_date: { bind:"trf_date" }
		}
	},

	/**
	 * Initialize page
	 * @private
	 */
	init: function() {

		// INIT TABBING
		Event.on($$('li', 'tabs'), 'click', this.switchService);
		dom.show(this.activeService+'-quick');
		$('srv-'+this.activeService).className = "selected";

		// Setup Hotels
		var frm = document.forms.htlFrm;
		Event.on(frm.rooms, 'change', this.dstChange);
		if ( $$('select', 'dst-tbl').length/4 != frm.rooms.value ) {
			frm.rooms.value = $$('select', 'dst-tbl').length/4;
		}

		// Setup Charter
		frm = document.forms.chrFrm;
		if ( parseInt(getValue(frm.chr_type), 10) != 1 ) {
			dom.show('chr-rnd');
		}
		Event.on(cssQuery('input[name=chr_type]', frm), 'click', this.dirChange);

		// Setup Transfers
		frm = document.forms.trfFrm;
		if ( frm.rnd.checked ) {
			dom.show('trf-rnd');
		}
		Event.on(frm.rnd, 'click', this.trfToggle);

		frm=null;
	},

	// QUICK TRAVEL FINDER
	switchService: function(e) {
		var srvType = this.id.replace(/srv[-]/, '');

		$('srv-'+page.activeService).className = "";
		dom.hide(page.activeService+'-quick');
		dom.show(srvType+'-quick');
		$('srv-'+srvType).className = "selected";
		page.activeService = srvType;
	},

	// Accommodations
	htlAvl: function(frm) {
		if ( !hasValue(frm.cnt_code) ) { return form.error("Please select at least a country.", frm.cty_label); }
		if ( !hasValue(frm.fromd) ) { return form.error("Please input check-in date.", frm.fromd); }
		if ( app.today.dayDiff(getValue(frm.fromd).toDate()) < 1 ) { return form.error("Please select a date after " + app.today.format()); }
		if ( !hasValue(frm.tod) ) { return form.error("Please input check-out date.", frm.tod); }
		if ( !hasValue(frm.rooms) ) { return form.error("Please input number of rooms.", frm.rooms); }
		return true;
	},
	dstChange: function(e) {
		ajax.queue(page.dstSet, "dstChg");
		ajax.loadXML("htl/dst-tbl.cfm?rooms="+this.value, "dstChg", "Updating persons table.");
	},
	dstSet: function() {
		var response = ajax.getXML('dstChg');
		$('dst-tbl').innerHTML = dom.xmlText(response);
	},

	chrAvl: function(frm) {
		if ( !hasValue(frm.fromd) ) { return form.error("Please input departure date.", frm.fromd); }
		if ( app.today.dayDiff(getValue(frm.fromd).toDate()) < 1 ) { return form.error("Please select a date after " + app.today.format()); }
		if ( parseInt(getValue(frm.chr_type), 10) != 1 && !hasValue(frm.tod) ) { return form.error("Please input return date.", frm.tod); }
		if ( !hasValue(frm.dep_cnt_code) ) { return form.error("Please select at least the country of departure and destination to continue."); }
		if ( !hasValue(frm.arr_cnt_code) ) { return form.error("Please select at least the country of destination."); }
		if ( frm.dep_cnt_code.value == frm.arr_cnt_code.value ) {
			if( !hasValue(frm.dep_cty_code) && !hasValue(frm.arr_cty_code) ) {
				return form.error("Please select at least one city ( destination or departure )");
			}
		}
		if ( parseInt(frm.pax_adult.value, 10) + parseInt(frm.pax_child.value, 10) + parseInt(frm.pax_infant.value, 10) < 1 ) { return form.error("At least one person should exist for availability to continue.", frm.pax_adult); }
		return true;
	},
	dirChange: function(e) {
		dom[parseInt(this.value, 10) == 1 ? "hide" : "show"]('chr-rnd');
	},

	othAvl: function(frm) {
		if ( !hasValue(frm.fromd_st) ) { return form.error("Please input a date.", frm.fromd_st); }
		if ( app.today.dayDiff(getValue(frm.fromd_st).toDate()) < 1 ) { return form.error("Please select a date after " + app.today.format()); }
		return true;
	},

	crrAvl: function(frm) {
		if ( !hasValue(frm.cnt_code) ) { return form.error("Please select at least a country ( Location field )."); }
		if ( !hasValue(frm.fromd) ) { return form.error("Please input delivery date.", frm.fromd); }
		if ( app.today.dayDiff(getValue(frm.fromd).toDate()) < 1 ) { return form.error("Please select a date after " + app.today.format()); }
		if ( !hasValue(frm.tod) ) { return form.error("Please input collection date.", frm.tod); }
		if ( !hasValue(frm.cars) ) { return form.error("Please input number of cars.", frm.cars); }
		return true;
	},

	trfAvl: function(frm) {
		if ( !hasValue(frm.trf_date) ) { return form.error("Please select a date.", frm.trf_date); }
		if ( app.today.dayDiff(getValue(frm.trf_date).toDate()) < 1 ) { return form.error("Please select a date after " + app.today.format()); }
		if ( frm.rnd.checked ) {
			if ( !hasValue(frm.ret_date) ) { return form.error("Please type the departure date.", frm.ret_date); }
		}
		if ( !hasValue(frm.fzone_id) ) { return form.error("Please select a departure zone."); }
		if ( !hasValue(frm.tzone_id) ) { return form.error("Please select a destination zone."); }
		if ( getValue(frm.fzone_id) == getValue(frm.tzone_id) ) { return form.error("Destination zone cannot be the same as departure zone."); }
		if ( parseInt(frm.adults.value, 10) + parseInt(frm.children.value, 10) + parseInt(frm.infants.value, 10) === 0 ) {
			return form.error("At least one passenger must be specified.", frm.adults);
		}
		return true;
	},
	trfToggle: function(e) {
		dom[this.checked ? "show" : "hide"]('trf-rnd');
	}

};