// Content: js eBT7 calendar
/* calendar functions */
var type = '';
var days = ['週一', '週二', '週三', '週四', '週五', '週六', '週日'];

function showCalendar(depret, txt) {
	top.type = depret;
	var container = document.getElementById('calendarcontainer');
	var header = document.getElementById('calendartop');
	header.innerHTML = txt; 
	if (document.all) {
		var entries = document.getElementsByTagName('select');
		for (var i = 0; i < entries.length; i++) {
			if (entries[i].className == 'cal_hide') {
				entries[i].style.display = 'none';
			}
		}
	}
	var today = new Date();
	var index = document.getElementById(depret + '_month').options.selectedIndex;
	document.getElementById('calendarmonth').options.selectedIndex = index;
	updateMonth(today.getFullYear() + "" + (today.getMonth()+1+index), index);
	container.style.display = 'block';
                document.getElementById('calendarmonth').focus();
}

function showCalendar_other(depret, txt) {
	top.type = depret;
	var container = document.getElementById('calendarcontainer_other');
	var header = document.getElementById('calendartop_other');
	header.innerHTML = txt;
	if (document.all) {
		var entries = document.getElementsByTagName('select');
		for (var i = 0; i < entries.length; i++) {
			if (entries[i].className == 'cal_hide') {
				entries[i].style.display = 'none';
			}
		}
	}
	var today = new Date();
	var index = document.getElementById(depret + '_month_other').options.selectedIndex;
	document.getElementById('calendarmonth_other').options.selectedIndex = index;
	updateMonth_other(today.getFullYear() + "" + (today.getMonth()+1+index), index);
	container.style.display = 'block';
  document.getElementById('calendarmonth_other').focus();
}

function fill(type, day, month) {
	closeCalendar();
	document.getElementById(type + '_day').options.selectedIndex = day;
	document.getElementById(type + '_month').options.selectedIndex = month;
	syncDate(document.getElementById(type + '_month'));
	if (type=='dep'){document.getElementById('ret_day').focus();}
	if (type=='ret') {document.getElementById('on').focus();}
}

function fillother(type, day, month) {
	closeCalendar_other();
	document.getElementById(type + '_day_other').options.selectedIndex = day;
	document.getElementById(type + '_month_other').options.selectedIndex = month;
	syncDate_other(document.getElementById(type + '_month_other'));
	if (type=='dep'){document.getElementById('ret_day_other').focus();}
	if (type=='ret') {document.getElementById('default').focus();}	
}

function closeCalendar () {
	var container = document.getElementById('calendarcontainer');
	if (document.all) {
		var entries = document.getElementsByTagName('select');
		for (var i = 0; i < entries.length; i++) {
			if (entries[i].className == 'cal_hide') {
				entries[i].style.display = 'block';
			}
		}
	}
	container.style.display = 'none';
}

function closeCalendar_other () {
	var container = document.getElementById('calendarcontainer_other');
		
	if (document.all) {
		var entries = document.getElementsByTagName('select');
		for (var i = 0; i < entries.length; i++) {
			if (entries[i].className == 'cal_hide') {
				entries[i].style.display = 'block';
			}
		}
	}
	container.style.display = 'none';
}

function updateMonth(monthyear, selection) {
	var month = monthyear.substr(4,2);
	var year = monthyear.substr(0,4);
	var noOfDays = getNumberOfDays(month, year);
	var firstDay = getFirstDay(month, year);
	fillMonth(month, firstDay, noOfDays, selection);
}

function updateMonth_other(monthyear, selection) {
	var month = monthyear.substr(4,2);
	var year = monthyear.substr(0,4);
	var noOfDays = getNumberOfDays(month, year);
	var firstDay = getFirstDay(month, year);
	fillMonth_other(month, firstDay, noOfDays, selection);
}
function getNumberOfDays(m, y) {
	var days = 31;
	switch (parseInt(m, 10)) {
		case 4: case 6: case 9: case 11:
			days = 30;
			break;
		case 2:
		  if ((y % 4 == 0) ^ (y % 100 == 0) ^ (y % 400 == 0))
			days = 29;
		  else
			days = 28;
		  break;
	}
	return days;
}
function getFirstDay(m, y) {
	d = new Date(y, m-1, 1);
	d.setHours(12);
	return (d.getDay() - 1 >= 0 ? d.getDay() - 1 : d.getDay() + 6);
}
function fillMonth(month, firstDay, noOfDays, monthIndex) {
	var firstSet = false;
	var dayCounter = 1;
	var today = new Date();
	dateToday = today.getDate();
	monthToday = today.getMonth() + 1;
	var sHTML = '<table cellspacing="0"><tr class="head">'
	for (var i = 0; i < days.length; i ++) {
		sHTML += '<td>' + days[i] + '</td>\n';
	}
	sHTML += '</tr>';
	while (dayCounter <= noOfDays) {
		sHTML += '<tr>';
		for (i = 0; i < 7; i++) {
			if (!firstSet && i < firstDay) {
				sHTML += '<td>&nbsp;</td>\n';
			} else {
				firstSet = true;
				if (dayCounter <= noOfDays) {
					if ((monthToday == month) && (dayCounter < dateToday)) {
						sHTML += '<td>' + dayCounter + '</td>\n';
					} else {
						sHTML += '<td><a href="javascript:fill(top.type, ' + (dayCounter - 1) + ' , ' + monthIndex + ');">' + dayCounter + '</a></td>\n';
					}

				} else {
					sHTML += '<td>&nbsp;</td>\n';
				}
				dayCounter++;
			}
		}
		sHTML += '</tr>'
	}
	sHTML += '</table>';
	document.getElementById('monthtable').innerHTML = sHTML;
}

function fillMonth_other(month, firstDay, noOfDays, monthIndex) {
	var firstSet = false;
	var dayCounter = 1;
	var today = new Date();
	dateToday = today.getDate();
	monthToday = today.getMonth() + 1;
	var sHTML = '<table cellspacing="0"><tr class="head">'
	for (var i = 0; i < days.length; i ++) {
		sHTML += '<td>' + days[i] + '</td>\n';
	}
	sHTML += '</tr>';
	while (dayCounter <= noOfDays) {
		sHTML += '<tr>';
		for (i = 0; i < 7; i++) {
			if (!firstSet && i < firstDay) {
				sHTML += '<td>&nbsp;</td>\n';
			} else {
				firstSet = true;
				if (dayCounter <= noOfDays) {
					if ((monthToday == month) && (dayCounter < dateToday)) {
						sHTML += '<td>' + dayCounter + '</td>\n';
					} else {
						sHTML += '<td><a href="javascript:fillother(top.type, ' + (dayCounter - 1) + ' , ' + monthIndex + ');" tabindex=301>' + dayCounter + '</a></td>\n';
					}

				} else {
					sHTML += '<td>&nbsp;</td>\n';
				}
				dayCounter++;
			}
		}
		sHTML += '</tr>'
	}
	sHTML += '</table>';
	document.getElementById('monthtable_other').innerHTML = sHTML;
}

function RecalcCalendar(id,days) { //,matchdates) {
	this.calendar = document.getElementById(id);
	this.days = days||new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
	/*this.minMatch = false;
	this.maxMatch = false;
	if (matchdates!=null) {
		if (matchdates.minMatch!=null) {
			this.minMatch = true;
			this.matchCalendar = document.getElementById(matchdates.minMatch);
		} else if(matchdates.maxMatch!=null) {
			this.maxMatch = true;
			this.matchCalendar = document.getElementById(matchdates.maxMatch);
		}
	}*/
	var self = this;
	addEventHandler(this.calendar, "click", function(e) {
		return self.clickHandler(e);
	});
}

RecalcCalendar.prototype = {
	aRE:/a/i,
	relRE:/date/i,
	divRE:/div/i,
	dateRE:/\b[0-9]{1,2}\b/,
	dayRE:/^[^ ]*/,
	clickHandler:function(e) {
		var e = e||event;
		var target = e.target||e.srcElement;
		var eventResult = true;

		while (target.nodeType>1)target = target.parentNode; //Safari targets textnodes.

		if (this.aRE.test(target.nodeName) && this.relRE.test(target.getAttribute("rel"))) {//It's a date link
			//de-select current date
			var selSpans = getElementsByClassName(this.calendar, "span", "sel");
			removeClass(selSpans[0], "sel");

			//select current date
			var span = target.parentNode;
			addClass(span, "sel");

			//change date-string
			var div = target;
			while (div.parentNode && !this.divRE.test(div.nodeName)) div = div.parentNode;
			if (this.divRE.test(div.nodeName)) {
				var strong = div.getElementsByTagName("strong").item(0);
				var sDate = strong.firstChild.nodeValue;
				sDate = sDate.replace(this.dateRE, target.firstChild.nodeValue);

				//count how many-eth day this is
				var td = target.parentNode.parentNode;
				var day = this.days[td.cellIndex];
				sDate = sDate.replace(this.dayRE, day);
				strong.replaceChild(document.createTextNode(sDate),strong.firstChild);
			} else alert("Could not find a div");

			//set variable on button-action
			var button = document.getElementById("recalcon"), buttonlink = button.getElementsByTagName("a").item(0), buttonhref = buttonlink.getAttribute("href"), href="";
			var re = new RegExp("([\\?&]" + this.calendar.id + "=)[^&]*");
			if (re.test(buttonhref)) {
				href = buttonhref.replace(re, "$1" + target.firstChild.nodeValue);
			} else {
				href = buttonhref + (buttonhref.indexOf("?")>0?"&":"?") + this.calendar.id + "=" + target.firstChild.nodeValue;
			}
			buttonlink.setAttribute("href",href);

			//enable recalcButton
			addClass(button, "enable");
			//cancel original event
			eventResult = cancelEvent(e);
		}
		return eventResult;
	}
}
// Content: js eBT7 DBFlightSearch
// --------------------------------------------------------------------------------------------
//
// DBFlightSearch component
//
// --------------------------------------------------------------------------------------------
function DBFlightSearch (container, inputSearchCriteriaJSON, ebtPage, cabinClassURL, cityCode, closeText) {
	this.ebtPage = ebtPage;
	this.cabinClassURL = cabinClassURL;
	this.container = YAHOO.util.Dom.get(container);
	this.destFinder = new FindDestinationBox(this);
	this.closeText = closeText;
	this.getInputSearchCriteria(inputSearchCriteriaJSON);
	this.cityCode = cityCode;
	this.acSelectionMade = false;
}
DBFlightSearch.prototype.getInputSearchCriteria = function (JSONData) {
	var callback = { 
		success: this.parseInputSearchCriteria, 
		failure: this.handleFailure,
		scope: this
	};
	YAHOO.util.Connect.asyncRequest('GET', JSONData, callback, null);
}
DBFlightSearch.prototype.parseInputSearchCriteria = function (o) {
	if (o.responseText == '')
		alert('A backend error occurred. Contact the system administrator.');
	else
	{
		this.inputSearchCriteria = eval('(' + o.responseText + ')');
		this.init();
		if (this.cityCode!=undefined)
			this.initCity();
	}
}
DBFlightSearch.prototype.handleFailure = function (o) {
}

DBFlightSearch.prototype.initCity = function () {
	if (YAHOO.util.Dom.get('ebt-destination-place'))
	{
	
		var airports = this.inputSearchCriteria.allowedDestinations;
	
		for (var i = 0; i < airports.length; i++) {
			if (airports[i].code==this.cityCode)
			{
				YAHOO.util.Dom.get('ebt-destination-place').value = airports[i].content;
				YAHOO.util.Dom.get('ebt-airportcode').value = airports[i].code;
				YAHOO.util.Dom.get('ebt-outbound-destination-location-type').value = "city";
				//YAHOO.util.Dom.get('ebt-destination-container').value = 
			}
		}
	}	
}


DBFlightSearch.prototype.init = function () {
	this.waitingPageActive = false;
	this.ebtRoundTrip = YAHOO.util.Dom.get('ebt-round-trip');
	YAHOO.util.Event.addListener(this.ebtRoundTrip, 'click', this.showReturnDates, this, true);
	this.ebtOneWay = YAHOO.util.Dom.get('ebt-one-way');
	YAHOO.util.Event.addListener(this.ebtOneWay, 'click', this.hideReturnDates, this, true);
	this.submitButton = YAHOO.util.Dom.get('ebt-flightsearch-submit');
	YAHOO.util.Event.addListener(this.submitButton, 'click', this.doSubmitData, this, true);
	this.openJawButton = YAHOO.util.Dom.get('ebt-open-jaw-opt-link');
	YAHOO.util.Event.addListener(this.openJawButton, 'click', this.doSubmitData2, this, true);
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-departure-place'), 'change', this.updateOriginType, this, true);
	this.initDefaultSearch(this.inputSearchCriteria.defaultSearchByPeriod);
	this.initAdults(this.inputSearchCriteria.minimumNumberOfAdults, this.inputSearchCriteria.maximumSeats);
	this.initBestPriceGuarantee(this.inputSearchCriteria.bestPriceGuarantee);
	this.initCabinClass(this.inputSearchCriteria.brandedCabinClasses);
	this.getInitialCabinClasses();
	this.initOrigins(this.inputSearchCriteria.allowedOrigins, this.inputSearchCriteria.defaultOrigin);
	this.flightDater = new FlightDater(this, this.inputSearchCriteria.dateFormat, this.inputSearchCriteria.defaultDaysDeparture, this.inputSearchCriteria.defaultDaysAfterDeparture, this.inputSearchCriteria.maximumAdvancePurchase, this.inputSearchCriteria.months, this.inputSearchCriteria.shortWeekDays, this.closeText);
	this.childrensBox = new ChildrensBox(this, this.inputSearchCriteria.shortMonths);
	// subscribe childrensBox to listen to dateChange event to update children's types
	this.flightDater.depDateChange.subscribe(this.childrensBox.updateChildrensData, this.childrensBox);

	if (YAHOO.util.Dom.get('ebt-destination-place') && YAHOO.util.Dom.get('ebt-destination-container')) 
		this.autoCompleteTo = new AutoComplete(this, this.inputSearchCriteria.allowedDestinations, 'ebt-destination-place', 'ebt-airportcode', 'ebt-outbound-destination-location-type', 'ebt-destination-container', false);
	// recent searches popup
	if (YAHOO.util.Dom.get('ebt-recent-search-link')) {
		this.recentSearches = new RecentSearch(this);
	}
	// tooltips for Hotels and Cars, Best-price and Local Shop
	
	if (YAHOO.util.Dom.get('ebt-local-shop-box')) {
		this.tooltipLocalshop = new ToolTip('ebt-local-shop-box');
		this.tooltipLocalshoplLink = YAHOO.util.Dom.get('ebt-local-shop');
		YAHOO.util.Event.addListener(this.tooltipLocalshoplLink, 'mouseover', this.tooltipLocalshop.show, this.tooltipLocalshop, true);
		YAHOO.util.Event.addListener(this.tooltipLocalshoplLink, 'mouseout', this.tooltipLocalshop.hide, this.tooltipLocalshop, true);
	}
	if (YAHOO.util.Dom.get('ebt-hotel-box')) {
		this.tooltipHotel = new ToolTip('ebt-hotel-box');
		this.tooltipHotelLink = YAHOO.util.Dom.get('ebt-hotel-link');
                                YAHOO.util.Event.addListener(this.tooltipHotelLink, 'mouseover', this.showCompleteYourTrip, [this, this.tooltipHotel], true);
                                YAHOO.util.Event.addListener(this.tooltipHotelLink, 'mouseout', this.hideCompleteYourTrip, [this, this.tooltipHotel], true);
	}
	if (YAHOO.util.Dom.getElementsByClassName('shopping-cart') && YAHOO.util.Dom.getElementsByClassName('shopping-cart')[0]) {
		YAHOO.util.Dom.getElementsByClassName('shopping-cart')[0].onclick = function () {
			if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "ShoppingCartLink", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1"});
		}
	}

	if (YAHOO.util.Dom.get('ebt-best-price-box')) {
		this.tooltipBestPrice = new ToolTip('ebt-best-price-box');
		this.tooltipBestPriceLink = YAHOO.util.Dom.get('ebt-best-price-link');
		YAHOO.util.Event.addListener(this.tooltipBestPriceLink, 'mouseover', this.tooltipBestPrice.show, this.tooltipBestPrice, true);
		YAHOO.util.Event.addListener(this.tooltipBestPriceLink, 'mouseout', this.tooltipBestPrice.hide, this.tooltipBestPrice, true);
	}

                if (YAHOO.util.Dom.get('ebt-multiple-city-box')) {
		this.tooltipMultiCity = new ToolTip('ebt-multiple-city-box');
		this.tooltipMultiCityLink = YAHOO.util.Dom.get('ebt-multiple-city-link');
		YAHOO.util.Event.addListener(this.tooltipMultiCityLink, 'mouseover', this.tooltipMultiCity.show, this.tooltipMultiCity, true);
		YAHOO.util.Event.addListener(this.tooltipMultiCityLink, 'mouseout', this.tooltipMultiCity.hide, this.tooltipMultiCity, true);
	}


	this.initShoppingCartLink();
}
DBFlightSearch.prototype.initAdults = function (minNum, maxNum) {
	var adultBox = YAHOO.util.Dom.get('ebt-number-adults');
	var option;
	if (adultBox) {
		for (var i = minNum; i <= maxNum; i++) {
			option = new HTMLNode(document, 'option', {value:i.toString()}, i.toString());
			adultBox.appendChild(option);
		}
	}
}
DBFlightSearch.prototype.initBestPriceGuarantee = function (show) {
	if (show) {
		YAHOO.util.Dom.getElementsByClassName('best-price')[0].style.display = 'block';
	}
}
DBFlightSearch.prototype.initCabinClass = function (ccData) {
	this.cabinClassBox = YAHOO.util.Dom.get('ebt-cabin-class');
	var option;
	for (var i = 0; i < ccData.length; i++) {
		option = new HTMLNode(document, 'option', {value:ccData[i].brandedCabinClassCode}, ccData[i].name);
		this.cabinClassBox.appendChild(option);
	}
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-departure-place'), 'blur', this.getCabinClasses, this, true);
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-destination-place'), 'blur', this.getCabinClasses, this, true);
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-destination-place-oj'), 'blur', this.getCabinClasses, this, true);
}
DBFlightSearch.prototype.initDefaultSearch = function (defaultPeriod) {
	if (defaultPeriod) {
		YAHOO.util.Dom.get('ebt-flexible-dates').checked = 'checked';
	} else {
		YAHOO.util.Dom.get('ebt-fixed-dates').checked = 'checked';
	}
}
DBFlightSearch.prototype.initOrigins = function (origins, defaultOrigin) {
	this.origins = origins;
	this.originBox = YAHOO.util.Dom.get('ebt-departure-place');
	this.originBox.options.length = 0; // CB 20090730 Added line to remove previous origins because of a second call to inputSearchCriteria.ajax
	var option;
                YAHOO.util.Dom.addClass(this.originBox, "waiting");
                this.originBox.disabled="disabled";
	for (var i = 0; i < origins.length; i++) {
		option = new HTMLNode(document, 'option', {value:origins[i].code}, origins[i].content);
		if (origins[i].code == defaultOrigin) option.selected = 'selected';
		this.originBox.appendChild(option);
	}
                this.originBox.disabled="";
                YAHOO.util.Dom.removeClass(this.originBox, "waiting");


}
DBFlightSearch.prototype.showCompleteYourTrip = function (e, args) {
	if (args[0].showCompleteYourTripFired) return;
	if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "complete_your_trip", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1"});
	args[1].show();
	args[0].showCompleteYourTripFired = true;
}
DBFlightSearch.prototype.hideCompleteYourTrip = function (e, args) {
	args[0].showCompleteYourTripFired = false;
	args[1].hide();
}
DBFlightSearch.prototype.fillChildInfo = function () {
	var objForm = YAHOO.util.Dom.get('ebt-flight-searchform');
	var objChildren = YAHOO.util.Dom.get('ebt-children-formdata');
	var strChildId;
	var objChildDay, objChildMonth, objChildYear, objChildIsInfant, objChildIsChild;
	var strChildId, strInfantId;
	var objChild, objInfant;
	var chdQty = 0;
	var infQty = 0;
	for ( var ii = 0; ii < 9; ii++ ) {
		strChildId = 'child[' + ii + ']';
		objChildDay = YAHOO.util.Dom.get(strChildId + '.day');
		objChildMonth = YAHOO.util.Dom.get(strChildId + '.month');
		objChildYear = YAHOO.util.Dom.get(strChildId + '.year');
		objChildIsInfant = YAHOO.util.Dom.get(strChildId + '.isInfant');
		objChildIsChild = YAHOO.util.Dom.get(strChildId + '.isChild');
		if ( objChildYear ) {
			if ( objChildIsChild.value.toLowerCase() == "true" ) {
				strChildId = 'chds[' + chdQty + '].dateOfBirth';
				objChild = new HTMLNode(document, 'input', {id:strChildId, name:strChildId, type:'hidden'}, null, strChildId);
				objChild.value =	objChildYear.value + '-' +
				   					this.getValueString(objChildMonth.value) + '-' +
									this.getValueString(objChildDay.value);
				objForm.appendChild(objChild);
				chdQty++;
			}
			else if ( objChildIsInfant.value.toLowerCase() == "true" ) {
				strInfantId = 'infs[' + infQty + '].dateOfBirth';
				objInfant = new HTMLNode(document, 'input', {id:strInfantId, name:strInfantId, type:'hidden'}, null, strInfantId);
				objInfant.value =	objChildYear.value + '-' +
				   					this.getValueString(objChildMonth.value) + '-' +
									this.getValueString(objChildDay.value);
				objForm.appendChild(objInfant);
				infQty++;
			}
		}
	}
	var objChdQty = new HTMLNode(document, 'input', {id:'chdQty', name:'chdQty', type:'hidden'}, null, 'chdQty');
	var objInfQty = new HTMLNode(document, 'input', {id:'infQty', name:'infQty', type:'hidden'}, null, 'infQty');
	objChdQty.value = chdQty;
	objInfQty.value = infQty;
	objForm.appendChild(objChdQty);
	objForm.appendChild(objInfQty);
}

DBFlightSearch.prototype.getValueString = function(strValue) {
	var strReturnValue = strValue;
	if ( strValue < 10 ) {
		strReturnValue = "0" + strValue;
	}
	return strReturnValue;
}
DBFlightSearch.prototype.doSubmitData2 = function (e) {
	if(YAHOO.util.Dom.hasClass(this.openJawButton, 'disabled')) return;
	YAHOO.util.Dom.get('goToPage').value = "home_openjaw";
	this.doSubmitDataRoot(e);
}
DBFlightSearch.prototype.doSubmitData = function (e) {
	YAHOO.util.Dom.get('goToPage').value = "";
	this.doSubmitDataRoot(e);
}
DBFlightSearch.prototype.doSubmitDataRoot = function (e) {
	this.setCabinClassParameter();
	this.fillChildInfo();
	YAHOO.util.Event.preventDefault(e);
	try {top.document.documentElement.scrollTop = 0} catch (e) {};
	document.body.className = 'waiting';
	this.waitingPageActive = true;
	if (!this.acSelectionMade) {
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "autocomplete_no_selection_from_list", "z_ebt_eventplace" : this.ebtPage.wtEventPlace, "z_ebt_event" : "1"});
	}
	if (this.recentSearches && YAHOO.util.Dom.getElementsByClassName('error').length < 1) this.recentSearches.add();
	this.formatDataBeforeSubmit();
	document.forms['ebt-flight-searchform'].submit();
}
DBFlightSearch.prototype.setCabinClassParameter = function () {
	var cabinClass = YAHOO.util.Dom.get('ebt-cabin-class');
	var ccIndex = cabinClass.selectedIndex;
	var ccValue = cabinClass.options[cabinClass.selectedIndex].value;
	var cffccValue = "ECONOMY";
	if (ccValue.indexOf( "BUS") > -1)
	{
		cffccValue = "BUSINESS";
	}
	YAHOO.util.Dom.get('cffcc').value = cffccValue;
}
DBFlightSearch.prototype.showErrors = function (e) {
	var errorContainer = YAHOO.util.Dom.get('ebt-home-error-messages');
	var errorDisplayContainer = YAHOO.util.Dom.get('error-message-home-container');
	if (errorContainer && errorDisplayContainer && errorContainer.innerHTML != '') {
		errorDisplayContainer.innerHTML = errorContainer.innerHTML;
		errorDisplayContainer.id = 'error-message-home-container-show';
	}
}
DBFlightSearch.prototype.hideReturnDates = function () {
	YAHOO.util.Dom.addClass(YAHOO.util.Dom.get('ebt-return-label'), 'disabled');
	YAHOO.util.Dom.get('ebt-return-label').disabled = 'disabled';
                YAHOO.util.Dom.get('ebt-return-date').disabled = 'disabled';
                YAHOO.util.Dom.get('ebt-fixed-dates').click();
                YAHOO.util.Dom.get('ebt-flexible-dates').disabled = 'disabled';
                if (YAHOO.util.Dom.get('ebt-open-jaw-opt')) YAHOO.util.Dom.get('ebt-open-jaw-opt').disabled = 'disabled';
                var ojLink = YAHOO.util.Dom.get('ebt-open-jaw-opt-link');
                if (ojLink) {
                        YAHOO.util.Dom.addClass(ojLink, 'disabled');
               }
                if (YAHOO.util.Dom.get('ebt-return-date-icon') && (YAHOO.util.Dom.get('ebt-return-date-icon').childNodes[0])) {
                        YAHOO.util.Dom.get('ebt-return-date-icon').style.cursor = 'default';
                        YAHOO.util.Dom.get('ebt-return-date-icon').style.backgroundPosition = '0 -50px';
                }
}
DBFlightSearch.prototype.showReturnDates = function () {
                YAHOO.util.Dom.get('ebt-return-label').disabled = '';
                YAHOO.util.Dom.get('ebt-return-date').disabled = '';
                YAHOO.util.Dom.get('ebt-flexible-dates').disabled = '';
                if (YAHOO.util.Dom.get('ebt-return-label')) YAHOO.util.Dom.removeClass(YAHOO.util.Dom.get('ebt-return-label'), 'disabled');
                if (YAHOO.util.Dom.get('ebt-open-jaw-opt')) YAHOO.util.Dom.get('ebt-open-jaw-opt').disabled = '';
                var ojLink = YAHOO.util.Dom.get('ebt-open-jaw-opt-link');
                if (ojLink) {
                        YAHOO.util.Dom.removeClass(ojLink, 'disabled');
                }
                if (YAHOO.util.Dom.get('ebt-return-date-icon') && (YAHOO.util.Dom.get('ebt-return-date-icon').childNodes[0])) {
                        YAHOO.util.Dom.get('ebt-return-date-icon').style.cursor = 'pointer';
                        YAHOO.util.Dom.get('ebt-return-date-icon').style.cursor = 'hand';
                        YAHOO.util.Dom.get('ebt-return-date-icon').style.backgroundPosition = '0 0';
                }
}

DBFlightSearch.prototype.getInitialCabinClasses = function () {
	var callback = { 
		success: this.parseCabinClasses, 
		scope: this
	};

	var url = this.cabinClassURL
	YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}
DBFlightSearch.prototype.getCabinClasses = function (e) {
	var callback = { 
		success: this.parseCabinClasses, 
		scope: this
	};
	var orgBox = YAHOO.util.Dom.get('ebt-departure-place');
	if (orgBox) var org = orgBox.options[orgBox.selectedIndex].value;
	var dest = YAHOO.util.Dom.get('ebt-airportcode').value;

	var url = this.cabinClassURL + '&origin=' + org + '&destination=' + dest;
	YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}
DBFlightSearch.prototype.parseCabinClasses = function (o) {
	if (this.waitingPageActive) return;
	var currentSelected = this.cabinClassBox.selectedIndex;
	var ccOptions = (eval('(' + o.responseText + ')'));
	var newOption;
	while (this.cabinClassBox.childNodes[0]) this.cabinClassBox.removeChild(this.cabinClassBox.childNodes[0]);
	for (var i =0; i < ccOptions.options.length; i+=2) {
		newOption = new HTMLNode(document, 'option', {}, ccOptions.options[i]);
		newOption.value = ccOptions.options[i+1];
		this.cabinClassBox.appendChild(newOption);
	}
	if (currentSelected == 2 && this.cabinClassBox.options.length == 2) currentSelected = 1;
	try {this.cabinClassBox.selectedIndex = currentSelected} catch (e) {}
	
}
DBFlightSearch.prototype.initShoppingCartLink	= function () {
	var scLink = YAHOO.util.Dom.get('ebt-shoppingcart-link');
	var cookie = getCookie(this.ebtPage.pos + "_ShoppingCartCookie");
	var today = new Date();
	
	if (scLink && cookie) {
		
		var date, y, m, d;
		var scItems = eval(cookie.split('+')[1]);
		var total = scItems.length;
		
		for (var i = 0; i < scItems.length; i++) {
			y = scItems[i].split('-')[0];
			m = scItems[i].split('-')[1];
			d = scItems[i].split('-')[2];
			date = new Date(parseInt(y, 10), parseInt((m - 1), 10), parseInt((d), 10) + 1);
			if (today.getTime() > date.getTime()) {
				total--;
			}
		}
		if (total=='undefined') total=0;
		scLink.innerHTML = total;
		
		if (total > 0) {
			scLink.parentNode.parentNode.style.visibility = 'visible';
		}
		return;
	}
}
DBFlightSearch.prototype.formatDataBeforeSubmit = function () {
	var depDate = YAHOO.util.Dom.get('ebt-departure-date').value.split('/');
	if (depDate[this.flightDater.yPos] && depDate[this.flightDater.yPos].length == 2) {
		depDate[this.flightDater.yPos] = '20' + depDate[this.flightDater.yPos];
	}
	if (depDate[this.flightDater.mPos] && depDate[this.flightDater.mPos].length == 1) {
		depDate[this.flightDater.mPos] = '0' + depDate[this.flightDater.mPos];
	}
	if (depDate[this.flightDater.dPos] && depDate[this.flightDater.dPos].length == 1) {
		depDate[this.flightDater.dPos] = '0' + depDate[this.flightDater.dPos];
	}
	YAHOO.util.Dom.get('ebt-departure-date').value = depDate[this.flightDater.yPos] + '-' + depDate[this.flightDater.mPos] + '-' + depDate[this.flightDater.dPos];
	
	var retDate = YAHOO.util.Dom.get('ebt-return-date').value.split('/');
	if (retDate[this.flightDater.yPos] && retDate[this.flightDater.yPos].length == 2) {
		retDate[this.flightDater.yPos] = '20' + retDate[this.flightDater.yPos];
	}
	if (retDate[this.flightDater.mPos] && retDate[this.flightDater.mPos].length == 1) {
		retDate[this.flightDater.mPos] = '0' + retDate[this.flightDater.mPos];
	}
	if (retDate[this.flightDater.dPos] && retDate[this.flightDater.dPos].length == 1) {
		retDate[this.flightDater.dPos] = '0' + retDate[this.flightDater.dPos];
	}
	
	YAHOO.util.Dom.get('ebt-return-date').value = retDate[this.flightDater.yPos] + '-' + retDate[this.flightDater.mPos] + '-' + retDate[this.flightDater.dPos];
	
	YAHOO.util.Dom.get('ebt-inboundOrigin').value = YAHOO.util.Dom.get('ebt-airportcode').value;
	YAHOO.util.Dom.get('ebt-inboundOrigin-location-type').value = YAHOO.util.Dom.get('ebt-outbound-destination-location-type').value;
	YAHOO.util.Dom.get('ebt-inboundDestination').value = YAHOO.util.Dom.get('ebt-departure-place').options[YAHOO.util.Dom.get('ebt-departure-place').selectedIndex].value;
}
DBFlightSearch.prototype.updateOriginType = function (e) {
    var orgBox = YAHOO.util.Dom.get('ebt-departure-place');
    var orgLocType = YAHOO.util.Dom.get('ebt-outbound-origin-location-type');
    if (this.origins[orgBox.selectedIndex].group == "true" || this.origins[orgBox.selectedIndex].group == true) {
        orgLocType.value = "city";
    } else {
        orgLocType.value = "airport";
    }
}

// --------------------------------------------------------------------------------------------
//
// FlightDater component
//
// --------------------------------------------------------------------------------------------
function FlightDater (bookingTool, dateFormat, depDate, retDate, maxDate, months, days, closeText) {
	this.bookingTool = bookingTool;
	this.initDateFormat(dateFormat);
	var today = new Date();
	this.depDate = this.formatDate(dateFormat, (today.getTime() + (depDate * 1000 * 60 * 60 * 24)));
	this.retDate = this.formatDate(dateFormat, (today.getTime() + ((depDate + retDate) * 1000 * 60 * 60 * 24)));
	this.minDate = this.formatDate('mm/dd/yyyy', today);
	this.maxDate = this.formatDate('mm/dd/yyyy', (today.getTime() + (maxDate * 1000 * 60 * 60 * 24)));
	
	// init departuredate
	this.depDateIcon = YAHOO.util.Dom.get('ebt-departure-date-icon');
	this.depCalendar = new EBTCalendar (null, YAHOO.util.Dom.get('ebt-departure-date'), dateFormat, this.depDate, this.minDate, this.maxDate, months, days, closeText);
	YAHOO.util.Event.addListener(this.depDateIcon, "click", this.depCalendar.show, [this.depCalendar, YAHOO.util.Dom.get('ebt-departure-date'), true], true); 
	
	// init returndate
	this.retDateIcon = YAHOO.util.Dom.get('ebt-return-date-icon');
	this.retCalendar = new EBTCalendar (null, YAHOO.util.Dom.get('ebt-return-date'), dateFormat, this.retDate, this.minDate, this.maxDate, months, days, closeText);
	YAHOO.util.Event.addListener(this.retDateIcon, "click", this.retCalendar.show, [this.retCalendar, YAHOO.util.Dom.get('ebt-return-date'), true], true); 
	this.depCalendar.cal.selectEvent.subscribe(this.selectdepDate, this, true);
	this.depDateChange = new YAHOO.util.CustomEvent("dateChange", this);
	this.selectdepDate();
}
FlightDater.prototype.formatDate = function (format, d) {
	var date = new Date(d);
	var dPos, mPos, yPos;
	var sDate = format.split('/');
	
	// determine format;
	sDate[0] == 'mm' ? mPos = 0 : (sDate[1] == 'mm' ? mPos = 1 : mPos = 2);
	sDate[0] == 'dd' ? dPos = 0 : (sDate[1] == 'dd' ? dPos = 1 : dPos = 2);
	sDate[0].indexOf('yy') != -1 ? yPos = 0 : (sDate[1].indexOf('yy') != -1 ? yPos = 1 : yPos = 2);

	// format new date in array
	var aFormattedDate = new Array();
	aFormattedDate[dPos] = date.getDate();
	aFormattedDate[mPos] = date.getMonth() + 1;
	aFormattedDate[yPos] = date.getFullYear();
	
	// make string from array
	var s = aFormattedDate[0] + '/' + aFormattedDate[1] + '/' + aFormattedDate[2];
	
	return s;
}
FlightDater.prototype.initDateFormat = function (format) {
	var sDate = format.split('/');
	
	// determine format;
	sDate[0] == 'mm' ? this.mPos = 0 : (sDate[1] == 'mm' ? this.mPos = 1 : this.mPos = 2);
	sDate[0] == 'dd' ? this.dPos = 0 : (sDate[1] == 'dd' ? this.dPos = 1 : this.dPos = 2);
	sDate[0].indexOf('yy') != -1 ? this.yPos = 0 : (sDate[1].indexOf('yy') != -1 ? this.yPos = 1 : this.yPos = 2);
    this.longYear = sDate[this.yPos].length > 2 ? true : false;
}
FlightDater.prototype.selectdepDate = function (e) {
	// update Return calendar
	var selectedDepDate = this.depCalendar.getSelectedDates()[0];
	this.retCalendar.cal.cfg.setProperty("mindate", selectedDepDate); 
	if ((selectedDepDate > this.retCalendar.getSelectedDates()[0])) {
		this.retCalendar.cal.select(selectedDepDate);
	}
	this.depDateChange.fire(selectedDepDate);
}
// --------------------------------------------------------------------------------------------
//
// ChildrensBox component
//
// --------------------------------------------------------------------------------------------
function ChildrensBox (bookingTool, months) {
	this.bookingTool = bookingTool;
	this.months = months;
	this.createChildrensBoxDOM();
	this.cbTooltipElement = new ToolTip('ebt-children-tooltip');
	this.cbTooltipLink = YAHOO.util.Dom.get('ebt-children-tooltiplink');
	this.cbTooltipLinkText = this.cbTooltipLink.innerHTML;
	this.childrenList = YAHOO.util.Dom.get('ebt-children-listed');
	this.childrenFormdata = YAHOO.util.Dom.get('ebt-children-formdata');
	this.cbCheckBox = YAHOO.util.Dom.get('ebt-with-children');
		
	// init language dependent texts for children's box
	this.infantText = YAHOO.util.Dom.get('ebt-cb-infant-text').innerHTML;
	this.childText = YAHOO.util.Dom.get('ebt-cb-child-text').innerHTML;
	this.youngadultText = YAHOO.util.Dom.get('ebt-cb-youngadult-text').innerHTML;
	this.adultText = YAHOO.util.Dom.get('ebt-cb-adult-text').innerHTML;
	this.removeText = YAHOO.util.Dom.get('ebt-cb-remove-text').innerHTML;
	this.errorText = YAHOO.util.Dom.get('ebt-cb-error-text').innerHTML;
	
	this.nrOfChildren = 0;
	this.maxChildren = 9;
	this.children = new Array();
	this.childrenAdmin = new Array();
	this.years = new Array();
	var today = new Date();
	var thisYear = today.getFullYear();
	var yearIndex = 0;
	for (var i = thisYear - 14; i <= thisYear; i++) {
		this.years[yearIndex] = i;
		yearIndex++;
	}
	var currentChildren = this.childrenFormdata.getElementsByTagName('input');
	if (currentChildren.length > 0) {
		this.init(currentChildren);
	} else {
		// add first child (by default);
		// this.clickAddChild();
	}

	// init click event to open popup
	YAHOO.util.Event.addListener(this.cbCheckBox, 'click', this.open, [this, this.cbCheckBox] , true);

	// init click event to close popup and cancel
	YAHOO.util.Event.addListener(this.cbCloseBut, 'click', this.cancelAndclose, this, true);

	// init button to add Child
	YAHOO.util.Event.addListener(this.addChildBut, 'click', this.clickAddChild, this, true);

	// init click event to save entered data
	YAHOO.util.Event.addListener(this.cbSubmitForm, 'click', this.saveAndClose, this, true);
}
ChildrensBox.prototype.createChildrensBoxDOM = function () {
	var targetDocument = this.bookingTool.ebtPage.targetDoc;
	this.cbPopupElement = new HTMLNode(targetDocument, 'div', {id:'ebt-children-box'}, '<h3>' + YAHOO.util.Dom.get('ebt-cb-title').innerHTML + '</h3>');

	this.cbCloseBut = new HTMLNode(targetDocument, 'a', {href:'javascript:;'}, null, 'close-overlay');
	this.cbPopupElement.appendChild(this.cbCloseBut);

	var cbContent = new HTMLNode(targetDocument, 'div', {}, '', 'content');
	var myLink =  YAHOO.util.Dom.get('ebt-cb-helplink') ? YAHOO.util.Dom.get('ebt-cb-helplink').innerHTML : '/';
	var helpLink = new HTMLNode(targetDocument, 'a', {id:'tt-help-children', href:myLink, target:'_blank'}, YAHOO.util.Dom.get('ebt-cb-helptext').innerHTML, 'help-overlay');
	cbContent.appendChild(helpLink);
	
	var myh4 = new HTMLNode(targetDocument, 'h4', {}, YAHOO.util.Dom.get('ebt-cb-subtitle').innerHTML);
	cbContent.appendChild(myh4);
	
	var mybr = new HTMLNode(targetDocument, 'br', {clear: 'all'});
	cbContent.appendChild(mybr);
	
	var cbInnerContent = new HTMLNode(targetDocument, 'div', {}, '<p>' + YAHOO.util.Dom.get('ebt-cb-introtext').innerHTML + '</p>', 'inner-content');
	this.childrenContainer = new HTMLNode(targetDocument, 'div', {id:'ebt-child-form'}, null, 'form-container');
	cbInnerContent.appendChild(this.childrenContainer);
	
	this.maxChildrenError = new HTMLNode(targetDocument, 'div', {id:'ebt-maxchildren-error'}, '<p class="date-warning">' + YAHOO.util.Dom.get('ebt-cb-max-error').innerHTML + '</p>');
	cbInnerContent.appendChild(this.maxChildrenError);
	cbContent.appendChild(cbInnerContent);
	this.cbPopupElement.appendChild(cbContent);

	var footer = new HTMLNode(targetDocument, 'div', {}, null, 'footer');
	var span1 = new HTMLNode(targetDocument, 'span', {}, null, 'add-child');
	this.addChildBut = new HTMLNode(targetDocument, 'a', {id:'ebt-add-child', href:'javascript:;'}, YAHOO.util.Dom.get('ebt-cb-add-text').innerHTML);
	span1.appendChild(this.addChildBut);
	footer.appendChild(span1);

	this.cbSubmitForm = new HTMLNode(targetDocument, 'a', {id:'ebt-children-submit', href:'javascript:;'});
	var span2 = new HTMLNode(targetDocument, 'span', {}, YAHOO.util.Dom.get('ebt-cb-save-text').innerHTML, 'save-button');
	this.cbSubmitForm.appendChild(span2);
	footer.appendChild(this.cbSubmitForm);

	this.cbPopupElement.appendChild(footer);
	targetDocument.body.appendChild(this.cbPopupElement);
}
ChildrensBox.prototype.open = function (e, args) {
	var base = args[0];
	var checkBox = args[1];
	
	if (checkBox.checked && base.childrenAdmin) {
		while(base.nrOfChildren > 0) base.children[base.nrOfChildren-1].remove();
		if (base.childrenAdmin.length == 0) 
			base.clickAddChild();
		else {
			for (var i = 0; i < base.childrenAdmin.length; i++) {
				base.addChild(base.childrenAdmin[i]);
			}
		}
		base.maxChildrenError.style.display = 'none';
		if (base.bookingTool.ebtPage.lightBox) base.bookingTool.ebtPage.lightBox.show();
		base.animateOpen();
	} else {
		while(base.nrOfChildren > 0) base.children[base.nrOfChildren-1].remove();
		base.childrenAdmin = [];
		base.returnFormElements();
		base.cbTooltipLink.innerHTML = base.cbTooltipLinkText;
		base.cbTooltipLink.className = '';
		base.cbCheckBox.checked = false;
		YAHOO.util.Event.removeListener(base.cbTooltipLink, 'mouseover', base.cbTooltipElement.show);
	}
}
ChildrensBox.prototype.animateOpen = function () {
	if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "open"});
	this.cbPopupElement.style.display = 'block';
	var attributes = {
		opacity: { to: 1 }
	}
	anim = new YAHOO.util.Motion(this.cbPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.animate();
}
ChildrensBox.prototype.cancelAndclose = function () {
	this.maxChildrenError.style.display = 'none';
	if (this.childrenAdmin.length == 0) {
		this.cbCheckBox.checked = false;
	}
	this.close();
}
ChildrensBox.prototype.saveAndClose = function () {
	if (this.nrOfChildren > 0) {
		// ignore saveclick if date error(s)
		for (var i = 0; i < this.nrOfChildren; i++) {
			if (this.children[i].hasError) return;
		}
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "save all"});
		this.cbTooltipLink.className = 'ebt-children-tooltiplink';
		this.cbTooltipLink.innerHTML = this.nrOfChildren + '&nbsp;'  + this.cbTooltipLinkText;
		while (this.childrenList.childNodes.length > 0) {
			this.childrenList.removeChild (this.childrenList.firstChild);
		}
		var newChild;
		this.childrenAdmin = [];
		for (var i = 0; i < this.nrOfChildren; i++) {
			newChild = document.createElement('li');
			newChild.innerHTML = this.children[i].day + '-' + this.months[this.children[i].month -1] + '-' + this.children[i].year + ' (' + this.children[i].ageGroupText + ')';
			this.childrenList.appendChild(newChild);
            this.childrenAdmin[i] = [this.children[i].selectedDayIndex, this.children[i].selectedMonthIndex, this.children[i].selectedYearIndex, this.children[i].isInfant, this.children[i].isChild];
		}
		YAHOO.util.Event.removeListener(this.cbTooltipLink, 'mouseover', this.cbTooltipElement.show);
		YAHOO.util.Event.addListener(this.cbTooltipLink, 'mouseover', this.cbTooltipElement.show, this.cbTooltipElement, true);
		YAHOO.util.Event.removeListener(this.cbTooltipLink, 'mouseout', this.cbTooltipElement.hide);
		YAHOO.util.Event.addListener(this.cbTooltipLink, 'mouseout', this.cbTooltipElement.hide, this.cbTooltipElement, true);
		YAHOO.util.Event.removeListener(this.cbTooltipLink, 'click', this.open);
		YAHOO.util.Event.addListener(this.cbTooltipLink, 'click', this.open, [this, this.cbCheckBox], true);
	} else {
		while(this.nrOfChildren > 0) this.children[base.nrOfChildren-1].remove();
		this.childrenAdmin = [];
		this.cbTooltipLink.innerHTML = this.cbTooltipLinkText;
		this.cbTooltipLink.className = '';
		this.cbCheckBox.checked = false;
		YAHOO.util.Event.removeListener(this.cbTooltipLink, 'mouseover', this.cbTooltipElement.show);
	}
	this.returnFormElements();
	this.close();
}
ChildrensBox.prototype.returnFormElements = function () {
	while (this.childrenFormdata.childNodes.length > 0) this.childrenFormdata.removeChild(this.childrenFormdata.firstChild);
	if (this.childrenAdmin) {
		for (var i = 0; i < this.childrenAdmin.length; i++) {
			var inputEl = document.createElement('input');
			inputEl.type = 'hidden';
			inputEl.id = 'child[' + i + '].day';
			inputEl.name = 'child[' + i + '].day';
			inputEl.value = this.children[i].day;
			this.childrenFormdata.appendChild(inputEl);
			
			inputEl = document.createElement('input');
			inputEl.type = 'hidden';
			inputEl.id = 'child[' + i + '].month';
			inputEl.name = 'child[' + i + '].month';
			inputEl.value = this.children[i].month;
			this.childrenFormdata.appendChild(inputEl);
			
			inputEl = document.createElement('input');
			inputEl.type = 'hidden';
			inputEl.id = 'child[' + i + '].year';
			inputEl.name = 'child[' + i + '].year';
			inputEl.value = this.children[i].year;
			this.childrenFormdata.appendChild(inputEl);
			
			inputEl = document.createElement('input');
			inputEl.type = 'hidden';
			inputEl.id = 'child[' + i + '].isInfant';
			inputEl.name = 'child[' + i + '].infant';
			inputEl.value = this.children[i].isInfant;
			this.childrenFormdata.appendChild(inputEl);
			
			inputEl = document.createElement('input');
			inputEl.type = 'hidden';
			inputEl.id = 'child[' + i + '].isChild';
			inputEl.name = 'child[' + i + '].child';
			inputEl.value = this.children[i].isChild;
			this.childrenFormdata.appendChild(inputEl);
		}
	}
}
ChildrensBox.prototype.close = function () {
	var attributes = {
		opacity: { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.cbPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.cb = this;
	anim.onComplete.subscribe(this.finishClose);
	anim.animate();
	if (this.bookingTool.ebtPage.lightBox) this.bookingTool.ebtPage.lightBox.hide();
}
ChildrensBox.prototype.finishClose = function () {
	this.cb.cbPopupElement.style.display = 'none';
}
ChildrensBox.prototype.init = function (inputFields) {
	this.cbCheckBox.checked = true;
	var yearIndex;
	for (var i=0; i < inputFields.length; i+=5) {
		yearIndex = 0;
		while ((yearIndex < this.years.length) && (this.years[yearIndex] != inputFields[i+2].value)) yearIndex++;
		this.addChild([(inputFields[i].value - 1), (inputFields[i+1].value - 1), yearIndex]);
	}
	this.saveAndClose();
}
ChildrensBox.prototype.addChild = function (initValues) {
	if (this.nrOfChildren < this.maxChildren) {
		this.nrOfChildren++;
		this.children[this.nrOfChildren-1] = new Child(this, this.nrOfChildren, initValues);
	} else {
		this.maxChildrenError.style.display = 'block';
	}
}
ChildrensBox.prototype.clickAddChild = function () {
	if (this.nrOfChildren < this.maxChildren) {
		this.nrOfChildren++;
		this.children[this.nrOfChildren-1] = new Child(this, this.nrOfChildren, null);
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "add child"});
	} else {
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "more_then_9"});
		this.maxChildrenError.style.display = 'block';
	}
}
ChildrensBox.prototype.updateChildOrder = function (num) {
	this.maxChildrenError.style.display = 'none';
	for (var i = num; i < this.nrOfChildren; i++) {
		this.children[i-1] = this.children[i];
		this.children[i-1].updateOrderNr(i);
	}
	this.children[this.nrOfChildren - 1] = null;
	this.nrOfChildren--;
}
ChildrensBox.prototype.updateChildrensData = function (type, args, base) {
    for (var i = 0; i < base.nrOfChildren; i++) {
        base.children[i].checkDate();
    }
    while (base.childrenList.childNodes.length > 0) base.childrenList.removeChild (base.childrenList.firstChild);
    var newChild;
    for (var i = 0; i < base.nrOfChildren; i++) {
        newChild = document.createElement('li');
        newChild.innerHTML = base.children[i].day + '-' + base.months[base.children[i].month -1] + '-' + base.children[i].year + ' (' + base.children[i].ageGroupText + ')';
        base.childrenList.appendChild(newChild);
    }
}

// --------------------------------------------------------------------------------------------
//
// Child component
//
// --------------------------------------------------------------------------------------------
function Child (cb, num, selectedValues) {
	this.childrenBox = cb;
	this.targetDocument = this.childrenBox.bookingTool.ebtPage.targetDoc;
	this.container = this.targetDocument.createElement('fieldset');
	this.num = num;
	this.saved = false;
	this.generateChildsHTML();
	// ranking for child
	YAHOO.util.Event.addListener(this.removeBut, 'click', this.remove, this,  true);
	// referrer to errortext
	YAHOO.util.Event.addListener(this.dayBox, 'change', this.checkDate, this, true);
	YAHOO.util.Event.addListener(this.monthBox, 'change', this.checkDate, this, true);
	YAHOO.util.Event.addListener(this.yearBox, 'change', this.checkDate, this, true);
	if (selectedValues && selectedValues.length >= 3) {
		this.dayBox.selectedIndex = selectedValues[0];
		this.monthBox.selectedIndex = selectedValues[1];
		this.yearBox.selectedIndex = selectedValues[2];
	}
	// init default date set
	this.checkDate();
}
Child.prototype.generateChildsHTML = function () {
	var days = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];
	
	this.rankingText = new HTMLNode(this.targetDocument, 'span', {id:"ebt-ranking-" + this.num}, this.num, 'ranking');
	this.container.appendChild(this.rankingText);

	this.dayBox = new HTMLNode(this.targetDocument, 'select', {id:"ebt-child-day-" + this.num}, '');
	
	var o;
	for (var i = 0; i < days.length; i++) {
			o = new HTMLNode(this.targetDocument, 'option', {value:days[i]}, days[i]);
			this.dayBox.appendChild(o);
	}
	this.container.appendChild(this.dayBox);

	this.monthBox = new HTMLNode(this.targetDocument, 'select', {id:"ebt-child-month-" + this.num}, '');
	for (i = 0; i < this.childrenBox.months.length; i++) {
			o = new HTMLNode(this.targetDocument, 'option', {value:i+1}, this.childrenBox.months[i]);
			this.monthBox.appendChild(o);
	}
	this.container.appendChild(this.monthBox);

	this.yearBox = new HTMLNode(this.targetDocument, 'select', {id:"ebt-child-year-" + this.num}, '');
	var today = new Date();
	var thisYear = today.getFullYear();
	var yearIndex = 0;
	for (i = thisYear - 14; i <= thisYear; i++) {
		o = new HTMLNode(this.targetDocument, 'option', {value:i}, i);
		this.yearBox.appendChild(o);
		this.childrenBox.years[yearIndex] = i;
		yearIndex++;
	}
	this.container.appendChild(this.yearBox);

	this.ageGroup = new HTMLNode(this.targetDocument, 'span', {id:"ebt-child-agegroup-" + this.num}, this.childrenBox.youngadultText, 'classification');
	this.container.appendChild(this.ageGroup);

	this.removeBut = new HTMLNode(this.targetDocument, 'span', {id:"ebt-child-remove-" + this.num}, '<a href="javascript:;" id="ebt-child-remove-' + this.num + '">' + this.childrenBox.removeText + '</a>', 'remove-record');
	this.container.appendChild(this.removeBut);

	this.errorP = new HTMLNode(this.targetDocument, 'p', {id:"ebt-child-error-" + this.num}, this.childrenBox.errorText, 'date-warning');
	this.container.appendChild(this.errorP);
	this.childrenBox.childrenContainer.appendChild(this.container);
}
Child.prototype.generateYears = function () {
	var today = new Date();
	var thisYear = today.getFullYear();
	var sHTML = '';
	var yearIndex = 0;
	for (var i = thisYear - 14; i <= thisYear; i++) {
		sHTML += '<option value="' + i + '">' + i + '</option>';
		this.childrenBox.years[yearIndex] = i;
		yearIndex++;
	}
	
	return sHTML;
}
Child.prototype.checkDate = function () {
	this.selectedDayIndex = this.dayBox.options.selectedIndex;
	this.day = parseInt(this.dayBox.options[this.selectedDayIndex].value, 10);
	this.selectedMonthIndex = this.monthBox.options.selectedIndex;
	this.month = parseInt(this.monthBox.options[this.selectedMonthIndex].value, 10);
	this.selectedYearIndex = this.yearBox.options.selectedIndex;
	this.year = parseInt(this.yearBox.options[this.selectedYearIndex].value, 10);
	this.isInfant = this.isChild = this.isYoungAdult = false;
	var date = new Date(this.year, this.month-1, this.day);
	var today = new Date();
	if ((date.getMonth() + 1) == this.month && date < today) {
		this.errorP.style.display = 'none';
		this.hasError = false;
	} else {
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_event" : "1", "z_ebt_eventvalue" : "wrong_dob"});
		this.errorP.style.display = 'block';
		this.hasError = true;
		this.ageGroup.innerHTML = '';
		return;
	}
	// check age group for entered birthdate
	if (this.childrenBox.bookingTool.flightDater && this.childrenBox.bookingTool.flightDater.depCalendar) {
		var refDate = this.childrenBox.bookingTool.flightDater.depCalendar.getSelectedDates()[0];
	} else {
		var refDate = new Date();
	}
	refDate.setDate(refDate.getDate());
	// check if Infant
	refDate.setFullYear(refDate.getFullYear() - 2);
	if (refDate < date) {
		this.ageGroup.innerHTML = this.ageGroupText = this.childrenBox.infantText;
		this.isInfant = true;
		return;
	}
	// check if Child
	refDate.setFullYear(refDate.getFullYear() - 10);
	if (refDate < date) {
		this.ageGroup.innerHTML = this.ageGroupText = this.childrenBox.childText;
		this.isChild = true;
		return;
	}

                //young adult
	refDate.setFullYear(refDate.getFullYear() - 2);
	if (refDate < date) {
		this.ageGroup.innerHTML = this.ageGroupText = this.childrenBox.youngadultText;
		return;
	}

	this.ageGroup.innerHTML = this.ageGroupText = this.childrenBox.adultText;
}
Child.prototype.remove = function () {
	if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "children_box", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "remove child"});
	this.container.parentNode.removeChild(this.container);
	this.childrenBox.updateChildOrder(this.num);
}
Child.prototype.updateOrderNr = function (newNr) {
	this.num = newNr;
	if (newNr % 2 == 0) 
		this.container.className = 'fieldset-even';
	else
		this.container.className = '';
	this.rankingText.id = 'ebt-ranking-' + newNr;
	this.rankingText.innerHTML = newNr;
	this.ageGroup.id = 'ebt-child-agegroup-' + newNr;
	this.removeBut.id = 'ebt-child-remove-' + newNr;
	this.errorP.id = 'ebt-child-error-' + newNr;
	this.dayBox.id = this.dayBox.name = 'ebt-child-day-' + newNr;
	this.monthBox.id = this.monthBox.name = 'ebt-child-month-' + newNr;
	this.yearBox.id = this.yearBox.name = 'ebt-child-year-' + newNr;
}
// --------------------------------------------------------------------------------------------
//
// AutoComplete component
//
// --------------------------------------------------------------------------------------------
var airportToData = new Array();
var airportFromData = new Array();
function AutoComplete (bookTool, JSONData, inputField, airportCodeInputField, locationTypeInputField, dataContainer, from) {
	this.dataReady = new YAHOO.util.CustomEvent("dataReady", this);
	this.bookingTool = bookTool;
	this.from = from;
	this.airportCodeInputField = YAHOO.util.Dom.get(airportCodeInputField);
	this.locationTypeInputField = YAHOO.util.Dom.get(locationTypeInputField);
	this.inputField = YAHOO.util.Dom.get(inputField);
	YAHOO.util.Event.addListener(this.inputField, "focus", function () {if (YAHOO.util.Dom.hasClass(this, 'entered')) {this.select()} else {this.value = ''}});
	YAHOO.util.Event.addListener(this.inputField, "focus", this.autoHelptip, this, true); 
	YAHOO.util.Event.addListener(this.inputField, "keydown", function () {this.style.color = '#023167'; YAHOO.util.Dom.addClass(this, 'entered')});
	YAHOO.util.Event.addListener(this.inputField, "keyup", this.updateHiddenField, this, true);
	YAHOO.util.Event.addListener(this.inputField, "blur", function (e) {YAHOO.util.Dom.removeClass('ebt-autosuggest-helptip', 'on')});
	if (this.airportCodeInputField.value != '') {this.inputField.style.color = '#023167'; YAHOO.util.Dom.addClass(this.inputField, 'entered')}
	YAHOO.util.Dom.addClass(this.inputField, "waiting");
	this.inputField.disabled = "disabled";
	this.parseAirportData(JSONData);
	this.from ? this.ACDS = new YAHOO.widget.DS_JSFunction(this.getFromMatches) : this.ACDS = new YAHOO.widget.DS_JSFunction(this.getToMatches);
	this.autoComplete = new YAHOO.widget.AutoComplete(inputField, dataContainer, this.ACDS);
	this.autoComplete.queryDelay = 0; 
	this.autoComplete.maxResultsDisplayed = 100;
	this.autoComplete.obj = this;
	if (this.bookingTool.ebtPage.browser == 'ie55' || this.bookingTool.ebtPage.browser == 'ie6') this.autoComplete.useIFrame = true;
	this.autoComplete.autoHighlight = false; 

	this.autoComplete.itemSelectEvent.subscribe(this.selectAirport);
	this.autoComplete.dataReturnEvent.subscribe(this.onDataReturn);
	// formats the autocomplete suggestions; highlight the searchquery by making it bold
	this.autoComplete.formatResult = function(oResultItem, sQuery) {
		var city = oResultItem[0];
		var state = oResultItem[1];
		var country = oResultItem[2];
		var airport = oResultItem[3];
		var airportCode = oResultItem[4];
		var cityGroup = oResultItem[5];
		var numberOf = oResultItem[6];
		
		sQuery = unescape(sQuery);		
		// highlight (<strong>) searchquery in resultlist
		var regExp = new RegExp("(^)(" + sQuery + ")(.*)", "i");
		city = city.replace(regExp, '$1<strong>$2</strong>$3');
		if (state) state = state.replace(regExp, '$1<strong>$2</strong>$3');
		country = country.replace(regExp, '$1<strong>$2</strong>$3');
		airport = airport.replace(regExp, '$1<strong>$2</strong>$3');
		airportCode = airportCode.replace(regExp, '$1<strong>$2</strong>$3');
		if (cityGroup) {
			airportCode = numberOf;
		}
		// return markup for ac-suggestions
		var sMarkup = '';
		sMarkup += city + ' - ' + airport + ' (' + airportCode + ')';
		// add state if available
		sMarkup += state ? ", " + state + ", " : ", ";
		sMarkup += country;
		// if airportgroup, make italic;
		if (cityGroup) sMarkup = '<i>' + sMarkup + '</i>';
		
		return (sMarkup);
	}

	// replace _sResultKey in autocomplete Object to display full text on selectEvent
	this.autoComplete.doBeforeExpandContainer = function (oTextbox, oContainer, sQuery, aResults) {
		var resultList = oContainer.getElementsByTagName('li');
		// delete <strong> tags
		var regExp = new RegExp("<strong>(.*?)</strong>", "ig");
		for (var i = 0; i < resultList.length; i++) {
			// add ranking for WebTrends measurement
			resultList[i].ranking = i + 1;
			if (resultList[i].innerHTML != '') {
				resultList[i]._sResultKey = resultList[i].innerHTML.replace(regExp, '$1')
			} 
		}
		// delete <i> tags, if present
		regExp = new RegExp("<i>(.*?)</i>", "ig");
		for (var i = 0; i < resultList.length; i++) {
			if (resultList[i].innerHTML != '') {
				resultList[i]._sResultKey = resultList[i]._sResultKey.replace(regExp, '$1')
			} 
		}
		return true;
	}
}

// activate the helptip on the autocomplete inputbox
AutoComplete.prototype.autoHelptip = function (e) {

       if (YAHOO.util.Dom.get('ebt-autosuggest-helptip') != null)
       {
	YAHOO.util.Dom.addClass('ebt-autosuggest-helptip', 'on'); 
	var parentXY;
	
	if (YAHOO.util.Dom.get('klm-ebt') != null)
		parentXY = YAHOO.util.Dom.getXY(YAHOO.util.Dom.get('klm-ebt'));
	else if (YAHOO.util.Dom.get('mini-ebt') != null)
		parentXY = YAHOO.util.Dom.getXY(YAHOO.util.Dom.get('mini-ebt'));

	var helptip = YAHOO.util.Dom.get('ebt-autosuggest-helptip');
	YAHOO.util.Dom.setStyle(helptip, 'left', (YAHOO.util.Dom.getX(this.inputField) - parentXY[0]) - 6 + 'px');
	YAHOO.util.Dom.setStyle(helptip, 'top', (YAHOO.util.Dom.getY(this.inputField) - parentXY[1] + parseInt(this.inputField.offsetHeight, 10) - 1) + 'px');

                 var helptipLink = YAHOO.util.Dom.getElementsByClassName("helptip-link", "a", helptip)[0];
                 switch(YAHOO.util.Event.getTarget(e).id) {
                                  case "ebt-destination-place": helptipLink.id = "autoHelptip-od-link";
                                                                            break;
                                  case "ebt-from-place-oj": helptipLink.id = "autoHelptip-io-link";
                                                                            break;
                                  case "ebt-destination-place-oj": helptipLink.id = "autoHelptip-id-link"; 
                 }
       }

}
AutoComplete.prototype.onDataReturn = function (e, args) {
	var autoComplete = args[0];
	var query = args[1];
	var results = args[2];
	var error = YAHOO.util.Dom.get('ebt-destination-place-error');


	if (results.length == 0 && query.length > 2)  {
		YAHOO.util.Dom.addClass(autoComplete._oTextbox, 'error');
                                if (error != null)
                                {
			YAHOO.util.Dom.addClass('ebt-autosuggest-helptip', 'error');
			YAHOO.util.Dom.addClass('ebt-autosuggest-helptip', 'on');
			error.style.display = 'block';
		}
		return;
	}
	YAHOO.util.Dom.removeClass(autoComplete._oTextbox, 'error');
                if (error != null)
                {
		YAHOO.util.Dom.removeClass('ebt-autosuggest-helptip', 'error');
		error.style.display = 'none';

		if (results.length > 0 && query.length > 2)  {
			YAHOO.util.Dom.removeClass('ebt-autosuggest-helptip', 'on');
			error.style.display = 'none';
		}
		else {
			YAHOO.util.Dom.addClass('ebt-autosuggest-helptip', 'on');
		}
	}

}
AutoComplete.prototype.selectAirport = function (e, args) {
	var base = args[0];
	var airportCode = args[2][4];
	var group = args[2][5];
	
	base.obj.bookingTool.acSelectionMade = true;
	if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "autocomplete_selection_from_list", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : args[1].ranking});
	if (group) {
		base.obj.locationTypeInputField.value = "city";
	} else {
		base.obj.locationTypeInputField.value = "airport";
	}
	base.obj.airportCodeInputField.value = airportCode;
	base.obj.inputField.select();
	base.obj.inputField.blur();
}
AutoComplete.prototype.updateHiddenField = function (e) {
	if (e.keyCode != 13) this.airportCodeInputField.value = this.inputField.value;
}
AutoComplete.prototype.getAirportData = function (xmlFile) {
	var callback = { 
		success: this.parseAirportData, 
		failure: this.handleFailure,
		scope: this
	};
	this.airportXMLData = YAHOO.util.Connect.asyncRequest('GET', xmlFile, callback, null);
}
AutoComplete.prototype.parseAirportData = function (airports) {
	var airportRecord;

	for (var i = 0; i < airports.length; i++) {
		airportRecord = new Array();
		airportRecord[0] = airports[i].city; // City
		airportRecord[1] = airports[i].state; // State
		airportRecord[2] = airports[i].country; // Country
		airportRecord[3] = airports[i].name; // Airportname
		airportRecord[4] = airports[i].code; // AirportCode
		airportRecord[5] = airports[i].group; // grouping name
		if (airportRecord[5]) {
			airportRecord[6] = airports[i].numberof; // Number of airports in this group
		}
		airportToData[i] = airportRecord;
	}
	airportToData.sort(initialSortFunc);
	this.bookingTool.destFinder.parseData(null, null, this.bookingTool.destFinder); 
	YAHOO.util.Dom.removeClass(this.inputField, "waiting");
	this.inputField.disabled="";
}
AutoComplete.prototype.handleFailure = function () {
}
AutoComplete.prototype.getToMatches = function (sQuery) {
	sQuery = unescape(decodeURIComponent(sQuery));
	var aResults = [];
	if (sQuery.length < 3) return aResults;
	
	// priority array; defines order to show results: city, airportcode, airportname, country, state
	var priority = [0, 4, 3, 2, 1, 5];
	var regExp = new RegExp("^" + sQuery, "i");
	
	for (var i = 0; i < airportToData.length; i++) {
		for (var j = 0; j < airportToData[i].length; j++) {
			if (regExp.test(airportToData[i][priority[j]])) {
				aResults.push(airportToData[i]);
				aResults[aResults.length - 1][7] = j;
				break;
			}
		}
	}
	
	aResults.sort(acSortFunc);
	return (sortSecLevelAlphabetic(aResults));
}
function sortSecLevelAlphabetic (results) {
	var arSorted = new Array();
	var arSub = new Array();
	if (results[0])	var group = results[0][7];

	for (var i = 0; i < results.length; i++) {
		if (results[i][7] == group) {
			arSub[arSub.length] = results[i]
		} else {
			arSub.sort(initialSortFunc);
			arSorted = arSorted.concat(arSub);
			arSub = new Array();
			arSub[arSub.length] = results[i]
			group = results[i][7];
		}
	}
	arSub.sort(initialSortFunc);
	arSorted = arSorted.concat(arSub);
	
	return arSorted;
}
function acSortFunc (a, b) {
	if (parseInt(a[7], 10) >= parseInt(b[7], 10)) return 1;
	if (parseInt(a[7], 10) < parseInt(b[7], 10)) return -1;
	return 0;
}
function initialSortFunc (a, b) {
	if (a[0] == b[0] && a[5]) return -1;
	if (a[0] >= b[0]) return 1;
	return -1;
}
// --------------------------------------------------------------------------------------------
//
// RecentSearch component
//
// --------------------------------------------------------------------------------------------
function RecentSearch (bookingTool) {
	this.bookingTool = bookingTool;
	var c = getCookie('klm-ebt-searches');
	if (c) {
		this.searches = eval('(' + c + ')').searches;
		if (this.searches[0].p != this.bookingTool.ebtPage.pos) {
			this.searches = new Array();
		}
	} else {
		this.searches = new Array();
	}
	
	this.createDOM();
	this.rsLink = YAHOO.util.Dom.get('ebt-recent-search-link');
	this.rsPopupElement = YAHOO.util.Dom.get('ebt-rs-box');

	// init click event to open popup
	YAHOO.util.Event.addListener(this.rsLink, 'click', this.open, this, true);

	// init click event to close popup
	YAHOO.util.Event.addListener(this.rsCloseBut, 'click', this.close, this, true);
	YAHOO.util.Event.addListener(this.cbBack, 'click', this.close, this, true);
}
RecentSearch.prototype.createDOM = function () {
	var targetDocument = this.bookingTool.ebtPage.targetDoc;
	this.rsPopupElement = new HTMLNode(targetDocument, 'div', {id:'ebt-rs-box'}, '<h3>' + YAHOO.util.Dom.get('ebt-rs-title').innerHTML + '</h3>');

	this.rsCloseBut = new HTMLNode(targetDocument, 'a', {id:'ebt-rs-close', href:'javascript:;'}, null, 'close-overlay');
	this.rsPopupElement.appendChild(this.rsCloseBut);

	var rsContent = new HTMLNode(targetDocument, 'div', {}, '<p>' + YAHOO.util.Dom.get('ebt-rs-intro').innerHTML + '</p>', 'content');
	
	var s, a, t, p, d, pHTML;
	for (var i = 0; i < this.searches.length; i++) {
		s =  new HTMLNode(targetDocument, 'div', {}, null, 'ebt-rs');
		a = new HTMLNode(targetDocument, 'a', {href:'javascript:;'}, '<span>' + YAHOO.util.Dom.get('ebt-rs-selecttext').innerHTML + '</span>', 'ebt-button-special');
		YAHOO.util.Event.addListener(a, 'click', this.selectSearch, [this, i], true);
		s.appendChild(a);
		
		t = new HTMLNode(targetDocument, 'table', {cellspacing:'0'});
		var tbody = new HTMLNode(targetDocument, 'tbody', {});
		var tr = new HTMLNode(targetDocument, 'tr');
		var td = new HTMLNode(targetDocument, 'td', {width:'59'}, YAHOO.util.Dom.get('ebt-rs-fromtext').innerHTML);
		tr.appendChild(td);
		if (this.searches[i].oos) {
			td = new HTMLNode(targetDocument, 'td', {width:'370'}, '<strong>' + this.searches[i].oos + '</strong>'); 
		} else {
			td = new HTMLNode(targetDocument, 'td', {width:'370'}, '<strong>' + '' + '</strong>');
		}
		tr.appendChild(td);
		td = new HTMLNode(targetDocument, 'td', {width:'70'}, YAHOO.util.Dom.get('ebt-rs-deptext').innerHTML);
		tr.appendChild(td);
		td = new HTMLNode(targetDocument, 'td', {width:'80'}, '<strong>' + this.searches[i].od + '</strong>');
		tr.appendChild(td);
		tbody.appendChild(tr);
		
		tr = new HTMLNode(targetDocument, 'tr');
		td = new HTMLNode(targetDocument, 'td', {width:'59'}, YAHOO.util.Dom.get('ebt-rs-totext').innerHTML);
		tr.appendChild(td);
		td = new HTMLNode(targetDocument, 'td', {width:'370'}, '<strong>' + this.searches[i].ois + '</strong>');
		tr.appendChild(td);
		if (this.searches[i].i == '1' ) {
			td = new HTMLNode(targetDocument, 'td', {width:'70'}, YAHOO.util.Dom.get('ebt-rs-rettext').innerHTML);
			tr.appendChild(td);
			td = new HTMLNode(targetDocument, 'td', {width:'80'}, '<strong>' + this.searches[i].id + '</strong>');
			tr.appendChild(td);
		}
		tbody.appendChild(tr);
		
		if (this.searches[i].i == '2') {
			tr = new HTMLNode(targetDocument, 'tr');
			td = new HTMLNode(targetDocument, 'td', {width:'59'}, YAHOO.util.Dom.get('ebt-rs-fromtext').innerHTML);
			tr.appendChild(td);
			td = new HTMLNode(targetDocument, 'td', {width:'370'}, '<strong>' + this.searches[i].dos + '</strong>');
			tr.appendChild(td);
			td = new HTMLNode(targetDocument, 'td', {width:'70'}, YAHOO.util.Dom.get('ebt-rs-rettext').innerHTML);
			tr.appendChild(td);
			td = new HTMLNode(targetDocument, 'td', {width:'80'}, '<strong>' + this.searches[i].id + '</strong>');
			tr.appendChild(td);
			tbody.appendChild(tr);
			tr = new HTMLNode(targetDocument, 'tr');
			td = new HTMLNode(targetDocument, 'td', {width:'59'}, YAHOO.util.Dom.get('ebt-rs-totext').innerHTML);
			tr.appendChild(td);
			td = new HTMLNode(targetDocument, 'td', {width:'370'}, '<strong>' + this.searches[i].dis + '</strong>');
			tr.appendChild(td);
			tbody.appendChild(tr);
		}
		
		t.appendChild(tbody);
		s.appendChild(t);
		
		pHTML = this.searches[i].cct + ', ' + YAHOO.util.Dom.get('ebt-number-adults')[this.searches[i].a].value + ' ' + YAHOO.util.Dom.get('ebt-rs-adulttext').innerHTML;
		if (this.searches[i].c.length > 0) {
			pHTML += ', ' + this.searches[i].noc + ' ' + YAHOO.util.Dom.get('ebt-rs-childrentext').innerHTML;
		}
		if (this.searches[i].hotel == "true") {
			pHTML += ', ' + YAHOO.util.Dom.get('ebt-rs-hoteltext').innerHTML;
		}
		p = new HTMLNode(targetDocument, 'p', {}, pHTML);
		s.appendChild(p);
		
		d =  new HTMLNode(targetDocument, 'div', {}, null, 'ebt-rs-bot');
		s.appendChild(d);
		
		rsContent.appendChild(s);
	}

	this.rsPopupElement.appendChild(rsContent);

	var footer = new HTMLNode(targetDocument, 'div', {}, null, 'footer');
	this.cbBack = new HTMLNode(targetDocument, 'a', {href:'javascript:;'}, '<span>' + YAHOO.util.Dom.get('ebt-rs-backtext').innerHTML + '</span>', 'ebt-button-back');
	
	footer.appendChild(this.cbBack);
	this.rsPopupElement.appendChild(footer);

	targetDocument.body.appendChild(this.rsPopupElement);
}
RecentSearch.prototype.open = function (e, args) {
    YAHOO.util.Event.preventDefault(e);
	this.rsPopupElement.style.display = 'block';
	var attributes = {
		opacity: { to: 1 }
	}
	anim = new YAHOO.util.Motion(this.rsPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.animate();
	if (this.bookingTool.ebtPage.lightBox) this.bookingTool.ebtPage.lightBox.show();
}
RecentSearch.prototype.close = function () {
	var attributes = {
		opacity: { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.rsPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.rs = this;
	anim.onComplete.subscribe(this.finishClose);
	anim.animate();
	if (this.bookingTool.ebtPage.lightBox) this.bookingTool.ebtPage.lightBox.hide();
}
RecentSearch.prototype.finishClose = function () {
	this.rs.rsPopupElement.style.display = 'none';
}
RecentSearch.prototype.add = function () {
	var s = new Object();
	s.p = this.bookingTool.ebtPage.pos;
	
	var orgOut = YAHOO.util.Dom.get('ebt-departure-place');
	s.oov = orgOut[orgOut.selectedIndex].value;
	s.oos = orgOut[orgOut.selectedIndex].text;
	s.oic = YAHOO.util.Dom.get('ebt-airportcode').value;
	var input1 = YAHOO.util.Dom.get('ebt-destination-place');
	if ((input1.value == '') || (!YAHOO.util.Dom.hasClass(input1, 'entered'))) return;
	s.ois = YAHOO.util.Dom.get('ebt-destination-place').value;
	if (YAHOO.util.Dom.get('ebt-outbound-origin-location-type')) s.oolt = YAHOO.util.Dom.get('ebt-outbound-origin-location-type').value;
	s.odlt = YAHOO.util.Dom.get('ebt-outbound-destination-location-type').value;
	
	if (YAHOO.util.Dom.get('ebt-airportcode-from-oj')) {
		s.doc = YAHOO.util.Dom.get('ebt-airportcode-from-oj').value;
		s.dos = YAHOO.util.Dom.get('ebt-from-place-oj').value;
		s.dic = YAHOO.util.Dom.get('ebt-airportcode-dest-oj').value;
		s.dis = YAHOO.util.Dom.get('ebt-destination-place-oj').value;
		s.iolt = YAHOO.util.Dom.get('ebt-inbound-origin-location-type').value;
		s.idlt = YAHOO.util.Dom.get('ebt-inbound-destination-location-type').value;
	}
	
	s.i = this.getItinerary();
	s.fs = YAHOO.util.Dom.get('ebt-flexible-dates').checked;
	var cabinClass = YAHOO.util.Dom.get('ebt-cabin-class');
	s.cc = cabinClass.selectedIndex;
	s.cct = cabinClass.options[cabinClass.selectedIndex].text;
	s.od = YAHOO.util.Dom.get('ebt-departure-date').value;
	s.id = YAHOO.util.Dom.get('ebt-return-date').value;
	s.a = YAHOO.util.Dom.get('ebt-number-adults').selectedIndex;
	s.noc = this.bookingTool.childrensBox.childrenAdmin.length;
	s.c = this.getChildren();
	
	this.findMatch(s);
	this.searches.unshift(s);
	this.storeCookies();
}
RecentSearch.prototype.findMatch = function (s) {
	var matchFound = false;
	if (this.searches.length == 0) return;
	for (var i = 0; i < this.searches.length; i++) {
		matchFound = this.searchesEqual(s, this.searches[i]);
		if (matchFound) {
			this.searches.splice(i, 1)
			return;
		}
	}
}
RecentSearch.prototype.searchesEqual = function (s, storedS) {
	if (s.oov != storedS.oov) return false;
	if (s.oos != storedS.oos) return false;
	if (s.oic != storedS.oic) return false;
	if (s.doc != storedS.doc) return false;
	if (s.dic != storedS.dic) return false;
	if (s.oolt != storedS.oolt) return false;
	if (s.odlt != storedS.odlt) return false;
	if (s.iolt != storedS.iolt) return false;
	if (s.idlt != storedS.idlt) return false;
	if (s.i != storedS.i) return false;
	if ((s.fs && storedS.fs == 'false') || (!s.fs && storedS.fs == 'true')) return false;
	if (s.cc != storedS.cc) return false;
	if (s.cct != storedS.cct) return false;
	if (s.od != storedS.od) return false;
	if (s.id != storedS.id) return false;
	if (s.a != storedS.a) return false;
	if (this.childrenUnique(s.c, storedS.c)) return false;

	return true;
}
RecentSearch.prototype.childrenUnique = function (newC, C) {
	// counter added because C is stored as one-dimensional array and newC as 2-dimensional
	var counter = 0;
	for (var i = 0; i < newC.length; i++) {
		for (var j = 0; j < newC[i].length; j++) {
			if (parseInt(newC[i][j], 10) != parseInt(C[counter], 10)) {return true;}
			counter++;
		}
	}
	return false;
}

RecentSearch.prototype.storeCookies = function () {
	var cookieVal = '{"searches":[';
	for (var i = 0; i < 5; i++) {
		if (this.searches[i]) {
			cookieVal += "{";
			for (var prop in this.searches[i]) {
				if (prop == "c") {
					cookieVal += '"' + prop + '": [' + this.searches[i][prop] + '],';
				} else {
					cookieVal += '"' + prop + '":"' + this.searches[i][prop] + '",';
				}
			}
			// remove last ","
			cookieVal = cookieVal.substr(0, cookieVal.length - 1);
			cookieVal += "}";
			if (this.searches[i+1] && i < 5) cookieVal += ",";
		}
	}
	cookieVal += "]}";
	if (escape(cookieVal).length > 3000) {
		this.searches.pop();
		this.storeCookies();
	} else {
		setEscapedCookie('klm-ebt-searches', cookieVal, 30);
	}
}
RecentSearch.prototype.selectSearch = function (e, args) {
	var base = args[0];
	var index = args[1];
	var s = base.searches[index];
	base.close();
	
	if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "recent_search", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1"});
    if (s.i == 2) {
        base.deepLinkToOpenJaw(s);
        return;
    }
	var dep = YAHOO.util.Dom.get('ebt-departure-place');
	for (var i = 0; i < dep.options.length; i++) {
		if (dep.options[i].value == s.oov) {
			dep.selectedIndex = i;
			break;
		}
	}
	YAHOO.util.Dom.get('ebt-airportcode').value = s.oic;
	YAHOO.util.Dom.get('ebt-destination-place').value = s.ois;
	YAHOO.util.Dom.get('ebt-destination-place').style.color = '#023167';
	if (YAHOO.util.Dom.get('ebt-outbound-origin-location-type')) YAHOO.util.Dom.get('ebt-outbound-origin-location-type').value = s.oolt;
	YAHOO.util.Dom.get('ebt-outbound-destination-location-type').value = s.odlt;
	if (YAHOO.util.Dom.get('ebt-airportcode-from-oj')) {
		YAHOO.util.Dom.get('ebt-airportcode-from-oj').value = s.doc;
		YAHOO.util.Dom.get('ebt-from-place-oj').value = s.dos;
		YAHOO.util.Dom.get('ebt-from-place-oj').style.color = '#023167';
		YAHOO.util.Dom.get('ebt-airportcode-dest-oj').value = s.dic;
		YAHOO.util.Dom.get('ebt-destination-place-oj').value = s.dis;
		YAHOO.util.Dom.get('ebt-destination-place-oj').style.color = '#023167';
		YAHOO.util.Dom.get('ebt-inbound-origin-location-type').value = s.iolt;
		YAHOO.util.Dom.get('ebt-inbound-destination-location-type').value = s.idlt;
	}
	
	if (s.fs == 'true') {
		var ebtFlex = YAHOO.util.Dom.get('ebt-flexible-dates');
		var ebtFix = YAHOO.util.Dom.get('ebt-fixed-dates');
		if ( ebtFlex ) {
			ebtFlex.checked = true;
		}
		if ( ebtFix ) {
			ebtFix.checked = false;
		}
	} else {
		var ebtFlex = YAHOO.util.Dom.get('ebt-flexible-dates');
		var ebtFix = YAHOO.util.Dom.get('ebt-fixed-dates');
		if ( ebtFlex ) {
			ebtFlex.checked = false;
		}
		if ( ebtFix ) {
			ebtFix.checked = true;
		}
	}
	YAHOO.util.Dom.get('ebt-number-adults').selectedIndex = s.a;
	if (new Date(s.od).getTime() + (24 * 60 * 60 * 1000) >= new Date().getTime()) {
		base.bookingTool.flightDater.depCalendar.cal.select(s.od);
	} else {
		base.bookingTool.flightDater.depCalendar.cal.select(base.bookingTool.flightDater.depCalendar.defaultDate);
	}
	base.bookingTool.flightDater.retCalendar.cal.select(s.id);
	// set Children
	if (s.c.length > 0) {
		while(base.bookingTool.childrensBox.nrOfChildren > 0) base.bookingTool.childrensBox.children[base.bookingTool.childrensBox.nrOfChildren-1].remove();
		base.bookingTool.childrensBox.childrenAdmin = [];
		base.bookingTool.childrensBox.cbCheckBox.checked = true;
		for (var i = 0; i < base.searches[index].c.length; i+=5) {
			base.bookingTool.childrensBox.addChild([s.c[i], s.c[i+1], s.c[i+2]]);
		}
		base.bookingTool.childrensBox.saveAndClose();
	} else {
		while(base.bookingTool.childrensBox.nrOfChildren > 0) base.bookingTool.childrensBox.children[base.bookingTool.childrensBox.nrOfChildren-1].remove();
		base.bookingTool.childrensBox.childrenAdmin = [];
		base.bookingTool.childrensBox.cbCheckBox.checked = false;
		base.bookingTool.childrensBox.saveAndClose();
	}
	base.setItinerary(s.i);
	if (s.cc == 2) s.cc = 1;
	YAHOO.util.Dom.get('ebt-cabin-class').selectedIndex = s.cc;
	base.bookingTool.getCabinClasses();

}
RecentSearch.prototype.getChildren = function () {
	return this.bookingTool.childrensBox.childrenAdmin;
}
RecentSearch.prototype.getItinerary = function () {
	if (YAHOO.util.Dom.get('ebt-open-jaw-opt') && YAHOO.util.Dom.get('ebt-open-jaw-opt').checked) {
		return 2;	// Open Jaw
	} else if (YAHOO.util.Dom.get('ebt-round-trip').checked) {
		return 1;	// Retour ticket
	} else {
		return 0;	// One way
	}
}
RecentSearch.prototype.setItinerary = function (itinerary) {
	if (itinerary == 2) {
		if (YAHOO.util.Dom.get('ebt-open-jaw-opt')) YAHOO.util.Dom.get('ebt-open-jaw-opt').checked = 'checked';
		YAHOO.util.Dom.addClass(document.body, 'open-jaw');
		YAHOO.util.Dom.get('ebt-round-trip').click();
		return;
	} else {
		if (YAHOO.util.Dom.get('ebt-open-jaw-opt')) YAHOO.util.Dom.get('ebt-open-jaw-opt').checked = '';
		YAHOO.util.Dom.removeClass(document.body, 'open-jaw');
	}
	if (itinerary == 1) {
		YAHOO.util.Dom.get('ebt-round-trip').click();
	} else {
		var ebtOneWay = YAHOO.util.Dom.get('ebt-one-way');
		if ( ebtOneWay ) {
			ebtOneWay.click();
		}
	}
}



RecentSearch.prototype.deepLinkToOpenJaw = function (s) {
        var searchString = '?';
       
        searchString += 'pos=' + this.bookingTool.ebtPage.pos;
        searchString += '&lang=' + YAHOO.util.Dom.get('ebt-language').value;
        searchString += '&goToPage=home_openjaw';
        searchString += '&c[0].os=' + s.oov;
        searchString += '&c[0].ost=' + s.oolt.toUpperCase();
        searchString += '&c[0].ds=' + s.oic;
        searchString += '&c[0].dst=' + s.odlt.toUpperCase();
        searchString += '&c[0].dd=' + this.formatDateForDeepLink(s.od);
        searchString += '&c[1].os=' + s.doc;
        searchString += '&c[1].ost=' + s.iolt.toUpperCase();
        searchString += '&c[1].ds=' + s.dic;
        searchString += '&c[1].dst=' + s.idlt.toUpperCase();
        searchString += '&c[1].dd=' + this.formatDateForDeepLink(s.id);
        searchString += '&cffcc=' + (s.cc == "0" ? 'ECONOMY' : 'BUSINESS');
        searchString += '&flex=' + s.fs;
        searchString += '&adtQty=' + this.getNrOfAdults(s);
        searchString += '&chdQty=' + this.getNrOfChildren(s);
        searchString += this.getBirthDates(s, 'chds', 4); // get childrens birthdates (4th in array)
        searchString += '&infQty=' + this.getNrOfInfants(s);
        searchString += this.getBirthDates(s, 'infs', 3); // get infants birthdates (3rd in array)

        var submitURL = YAHOO.util.Dom.get('ebt-flight-searchform').action;
       
        document.location.href = submitURL + searchString;
}
RecentSearch.prototype.formatDateForDeepLink = function (d, longYear) {
    var s = '';
    var splitted = d.split('/');
    s = splitted[this.bookingTool.flightDater.yPos] + '-' + this.addLeadingZero(splitted[this.bookingTool.flightDater.mPos]) + '-' + this.addLeadingZero(splitted[this.bookingTool.flightDater.dPos]);
    if (longYear) return s;
    
    if (!this.bookingTool.flightDater.longYear) {
        s = '20' + s;
    }
    return s;
}
RecentSearch.prototype.getNrOfAdults = function (s) {
    var total = 0;
    
    total += parseInt(YAHOO.util.Dom.get('ebt-number-adults').options[s.a].value, 10);
    for(var i = 0; i < s.c.length; i+=5) {
            if (!s.c[i+3] && !s.c[i+4]) total++;
    }
    return total;
}
RecentSearch.prototype.getNrOfChildren = function (s) {
    var total = 0;
    
    for(var i = 0; i < s.c.length; i+=5) {
            if (s.c[i+4]) total++;
    }
    return total;
}
RecentSearch.prototype.getNrOfInfants = function (s) {
    var total = 0;
    
    for(var i = 0; i < s.c.length; i+=5) {
            if (s.c[i+3]) total++;
    }
    return total;
}
RecentSearch.prototype.getBirthDates = function (s, name, idx) {
    var result = '';
    var counter = 0;
    
    for(var i = 0; i < s.c.length; i+=5) {
            if (s.c[i+idx]) {
                result += '&' + name + '[' + counter + '].dateOfBirth=' + this.formatDateForDeepLink(this.bookingTool.childrensBox.years[s.c[i+2]] + '/' + parseInt(s.c[i+1] + 1, 10) + '/' + parseInt(s.c[i] + 1, 10), true);
                counter++;
            }
    }
    return result;
}
RecentSearch.prototype.addLeadingZero = function (num) {
    return (num > 9 ? num : '0' + num);
}
// --------------------------------------------------------------------------------------------
//
// Find destination component
//
// --------------------------------------------------------------------------------------------
function FindDestinationBox (bookingTool) {
	this.bookingTool = bookingTool;
	// init language dependent texts for find destination box
if ( YAHOO.util.Dom.get('ebt-fd-title') != null )
{
	this.titleText = YAHOO.util.Dom.get('ebt-fd-title').innerHTML;
	this.introText = YAHOO.util.Dom.get('ebt-fd-intro').innerHTML;
	this.buttonText = YAHOO.util.Dom.get('ebt-fd-buttontext').innerHTML;
	this.chooseCountryText = YAHOO.util.Dom.get('ebt-fd-choosecountry').innerHTML;
	this.chooseAirportText = YAHOO.util.Dom.get('ebt-fd-chooseairport').innerHTML;

	this.createFindDestinationBoxDOM();

	this.airportBox.disabled='disabled';
	
	YAHOO.util.Dom.addClass(YAHOO.util.Dom.get('ebt-finddest-submit'), 'disabled');
	YAHOO.util.Event.addListener(this.countryBox, 'change', this.changeCountry, this, true);
	YAHOO.util.Event.addListener(this.airportBox, 'change', this.changeAirport, this, true);

	// init click events to open popup
	// for outbound destination:
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-od-find-destination-link'), 'click', this.open, [this, YAHOO.util.Dom.get('ebt-od-find-destination-link')], true);
	// for outbound destination:
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-io-find-destination-link'), 'click', this.open, [this, YAHOO.util.Dom.get('ebt-io-find-destination-link')], true);
	// for outbound destination:
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-id-find-destination-link'), 'click', this.open, [this, YAHOO.util.Dom.get('ebt-id-find-destination-link')], true);

	var helptipLink = YAHOO.util.Dom.getElementsByClassName("helptip-link", "a", "ebt-autosuggest-helptip")[0];
	YAHOO.util.Event.addListener(helptipLink, 'mousedown', this.findHelptipLink, this, true);


	var helptipLink = YAHOO.util.Dom.getElementsByClassName("helptip-link", "a", "ebt-autosuggest-helptip")[0];
	YAHOO.util.Event.addListener(helptipLink, 'mousedown', this.findHelptipLink, this, true);


	YAHOO.util.Event.addListener(this.fdCloseBut, 'click', this.close, this, true);
	YAHOO.util.Event.addListener(this.submitBut, 'click', this.saveAndClose, this, true);

}
}

FindDestinationBox.prototype.createFindDestinationBoxDOM = function () {
	var targetDocument = this.bookingTool.ebtPage.targetDoc;
	this.fdPopupElement = new HTMLNode(targetDocument, 'div', {id:'ebt-finddestination-box'}, '<h3>' + this.titleText + '</h3>');

	this.fdCloseBut = new HTMLNode(targetDocument, 'a', {href:'javascript:;'}, null, 'close-overlay');
	this.fdPopupElement.appendChild(this.fdCloseBut);

	var fdContent = new HTMLNode(targetDocument, 'div', {}, '', 'content');
	
	var mybr = new HTMLNode(targetDocument, 'br', {clear: 'all'});
	fdContent.appendChild(mybr);

	var fdInnerContent = new HTMLNode(targetDocument, 'div', {}, '<p>' + this.introText + '</p>', 'inner-content');
	
	var destForm = new HTMLNode(targetDocument, 'div', {id:'ebt-finddestination-form'}, null, 'form-container');
	var fieldset = new HTMLNode(targetDocument, 'fieldset', null, null);
		
	this.countryBox = new HTMLNode(targetDocument, 'select', null);
	var firstOption = new HTMLNode(targetDocument, 'option', {value:null}, this.chooseCountryText);
	this.countryBox.appendChild(firstOption);
	
	fieldset.appendChild(this.countryBox);  
	
	this.airportBox = new HTMLNode(targetDocument, 'select', null);
	var firstOption = new HTMLNode(targetDocument, 'option', {value:null}, this.chooseAirportText);
	this.airportBox.appendChild(firstOption);

	fieldset.appendChild(this.airportBox);  

	destForm.appendChild(fieldset);
	fdInnerContent.appendChild(destForm);
	fdContent.appendChild(fdInnerContent);
	this.fdPopupElement.appendChild(fdContent);

	var footer = new HTMLNode(targetDocument, 'div', {}, null, 'footer');
	this.submitBut = new HTMLNode(targetDocument, 'a', {id:'ebt-finddest-submit', href:'javascript:;'});
	var span = new HTMLNode(targetDocument, 'span', {},  this.buttonText, 'save-button');
	this.submitBut.appendChild(span);
	footer.appendChild(this.submitBut);

	this.fdPopupElement.appendChild(footer);
	targetDocument.body.appendChild(this.fdPopupElement);
}
FindDestinationBox.prototype.parseData = function (type, args, base) {
if ( base.countryBox != null )
{
	base.countryBox.style.display = 'none';
	var countries = new Array();
	var countriesandcities = new Array();
	for(i=0; i<airportToData.length; i++) {
		var country = airportToData[i][2];
		var city = airportToData[i][0];
		var airportname = airportToData[i][3];
		countriesandcities[i] = new Array(3);
		countriesandcities[i][0] = country;
		countriesandcities[i][1] = city;
		countriesandcities[i][2] = airportname;
		var doublecheck=false;
		for(j=0; j<countries.length; j++) {
			if(country == countries[j]){doublecheck=true;break;}
		}
		if(!doublecheck) {
			countries.push(country);
		}
	}
	countries.sort();
	for(i=0; i<countries.length; i++) {
		var newoption = document.createElement('option');
		newoption.innerHTML = countries[i];
		newoption.value = countries[i];
		base.countryBox.appendChild(newoption);
	}
}
}
FindDestinationBox.prototype.findHelptipLink = function(e, args) {
	var helptipLink = YAHOO.util.Dom.getElementsByClassName("helptip-link", "a", YAHOO.util.Dom.get("ebt-autosuggest-helptip"))[0];
	var el = YAHOO.util.Dom.get('ebt-od-find-destination-link');    
	if(helptipLink.id.search("-io-") > -1)
		el = YAHOO.util.Dom.get('ebt-io-find-destination-link') 
	else if(helptipLink.id.search("-id-") > -1) 
		el = YAHOO.util.Dom.get('ebt-id-find-destination-link');    
	 this.open(e, [this, el]);
}
FindDestinationBox.prototype.open = function (e, args) {
	var base = args[0];
	var link = args[1];
	base.countryBox.style.display = 'block';
	base.target = link.id;
	if (base.bookingTool.ebtPage.lightBox) base.bookingTool.ebtPage.lightBox.show();
	base.animateOpen();
}
FindDestinationBox.prototype.animateOpen = function () {
	this.fdPopupElement.style.display = 'block';
	var attributes = {
		opacity: { to: 1 }
	}
	anim = new YAHOO.util.Motion(this.fdPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.animate();
}
FindDestinationBox.prototype.saveAndClose = function () {
	if (YAHOO.util.Dom.hasClass(YAHOO.util.Dom.get('ebt-finddest-submit'), 'disabled')) return;
	this.returnFormElements();
	this.close();
}
FindDestinationBox.prototype.returnFormElements = function () {
	var inputField;
	var hiddenTypeField;
	var hiddenCodeField;
	if (this.target.search('-od-') != -1) {
		inputField = YAHOO.util.Dom.get('ebt-destination-place');
		hiddenTypeField = YAHOO.util.Dom.get('ebt-outbound-destination-location-type'); 
		hiddenCodeField = YAHOO.util.Dom.get('ebt-airportcode');
	}
	if (this.target.search('-io-') != -1) {
		inputField = YAHOO.util.Dom.get('ebt-from-place-oj');
		hiddenTypeField = YAHOO.util.Dom.get('ebt-inbound-origin-location-type');   
		hiddenCodeField = YAHOO.util.Dom.get('ebt-airportcode-from-oj');
	}
	if (this.target.search('-id-') != -1) {
		inputField = YAHOO.util.Dom.get('ebt-destination-place-oj');
		hiddenTypeField = YAHOO.util.Dom.get('ebt-inbound-destination-location-type');  
		hiddenCodeField = YAHOO.util.Dom.get('ebt-airportcode-dest-oj');
	}
	var selectedIndex = this.airportBox.childNodes[this.airportBox.selectedIndex].className;
	var selectedAirport = airportToData[selectedIndex];
	var city = selectedAirport[0];
	var state = selectedAirport[1];
	var country = selectedAirport[2];
	var airport = selectedAirport[3];
	var code = selectedAirport[4];
	var citygroup = selectedAirport[5];
	var sMarkup = "";
	sMarkup += city + ' - ' + airport + ' (' + code + ')';
	// add state if available
	sMarkup += state ? ", " + state + ", " : ", "; 
	sMarkup += country; 
	inputField.value = sMarkup;
	YAHOO.util.Dom.addClass(inputField, 'entered');
	inputField.style.color = '#023167';
	YAHOO.util.Dom.removeClass(inputField, 'error');
	if(YAHOO.util.Dom.get(inputField.id + '-error')) YAHOO.util.Dom.get(inputField.id + '-error').style.display = 'none';
	if (citygroup) {hiddenTypeField.value = 'city'} else {hiddenTypeField.value = 'airport';}
	hiddenCodeField.value = code;
}
FindDestinationBox.prototype.close = function () {
	var attributes = {
		opacity: { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.fdPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.fd = this;
	anim.onComplete.subscribe(this.finishClose);
	anim.animate();
	if (this.bookingTool.ebtPage.lightBox) this.bookingTool.ebtPage.lightBox.hide();
	YAHOO.util.Dom.addClass(YAHOO.util.Dom.get('ebt-finddest-submit'), 'disabled');
	this.countryBox.selectedIndex = 0;
	this.airportBox.selectedIndex = 0;
	this.airportBox.disabled = 'disabled';
}
FindDestinationBox.prototype.finishClose = function () {
	this.fd.fdPopupElement.style.display = 'none';
}
FindDestinationBox.prototype.changeCountry = function (type, args, base) { 
	var fdairportbox = this.airportBox;
	var fdcountrybox = this.countryBox;
	fdairportbox.selectedIndex = 0;
	if(fdcountrybox.selectedIndex < 1) {fdairportbox.disabled='disabled';}
	else {
		fdairportbox.disabled=false;
		while (this.airportBox.childNodes[1]) {
			this.airportBox.removeChild(this.airportBox.childNodes[1]);
		}

		for(i=0; i<airportToData.length; i++) {
			if(airportToData[i][2] == fdcountrybox.value) {
				var newoption = document.createElement('option');
				newoption.innerHTML = airportToData[i][0] + ' - ' + airportToData[i][3] + '(' + airportToData[i][4] + ')';
				newoption.className = i;
				this.airportBox.appendChild(newoption);
			}
		}

	}
	YAHOO.util.Dom.addClass(YAHOO.util.Dom.get('ebt-finddest-submit'), 'disabled');
}
FindDestinationBox.prototype.changeAirport = function (type, args, base) { 
	YAHOO.util.Dom.removeClass(YAHOO.util.Dom.get('ebt-finddest-submit'), 'disabled');
}


// Content: js eBT7 elements
// --------------------------------------------------------------------------------------------
//
// Lightbox component
//
// --------------------------------------------------------------------------------------------
function Lightbox (ebtPage) {
	this.ebtPage = ebtPage;
	this.lbElement = parent.document.createElement('div');
	this.lbElement.className = 'lightbox';
	parent.document.body.appendChild(this.lbElement);
	if (this.ebtPage.browser == 'ie6' || this.ebtPage.browser == 'ie55') this.selects = document.getElementById(this.ebtPage.container.id).getElementsByTagName('select');
}
Lightbox.prototype.show = function () {
	if (this.ebtPage.browser == 'ie6' || this.ebtPage.browser == 'ie55') this.hideSelectBoxes();
	this.lbElement.style.display = 'block';
	var attributes = {
		opacity: { to: .8 }
	}
	anim = new YAHOO.util.Motion(this.lbElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.animate();
}
Lightbox.prototype.hide = function () {
	var attributes = {
		opacity: { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.lbElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.lb = this;
	anim.onComplete.subscribe(this.finishHide);
	anim.animate();
}
Lightbox.prototype.finishHide = function () {
	if (this.lb.ebtPage.browser == 'ie6' || this.lb.ebtPage.browser == 'ie55') this.lb.showSelectBoxes();
	this.lb.lbElement.style.display = 'none';
}
Lightbox.prototype.hideSelectBoxes = function () {
	for (var i = 0; i < this.selects.length; i++) {
		this.selects[i].style.visibility = 'hidden';
	}
}
Lightbox.prototype.showSelectBoxes = function () {
	for (var i = 0; i < this.selects.length; i++) {
		this.selects[i].style.visibility = 'visible';
	}
}
// --------------------------------------------------------------------------------------------
//
// ToolTip component
//
// --------------------------------------------------------------------------------------------
function ToolTip (container, link, deltaX, deltaY) {
	this.container = container.tagName ? container : YAHOO.util.Dom.get(container);
	this.link = link;
	this.deltaX = deltaX;
	this.deltaY = deltaY;
 	if (document.all) {
		this.iframe = document.createElement('iframe');
		this.iframe.className = 'tooltip-iframe';
		// src added to make sure there is no problem with secure/non-secure items
		this.iframe.src = 'javascript:false;';
		this.iframe.frameBorder = 0;
		this.container.appendChild(this.iframe);
	}
}
ToolTip.prototype.show = function () {
	if (!isNaN(this.deltaX) && !isNaN(this.deltaX)) {
		this.container.style.left = calculateLeft(this.link) + this.deltaX + "px";
		this.container.style.top = calculateTop(this.link) + this.deltaY + "px";
		this.container.style.bottom = "auto";
	}
	this.toShow = setTimeout(createContextFunction(this, "doShow"), 300);
}
ToolTip.prototype.showPos = function (e, args) {
	var ieFix = document.all ? 120 : 30; 
	var leftCorr =  YAHOO.util.Dom.hasClass(args[0].container, 'goleft') ? -300 : 0;
	args[0].container.style.left = (args[1].offsetLeft + ieFix + leftCorr) + "px";
	args[0].container.parentNode.style.zIndex = 200;
	args[0].toShow = setTimeout(createContextFunction(args[0], "doShow"), 300);
}
ToolTip.prototype.hide = function () {
	clearTimeout(this.toShow);
	this.toShow = -1;
	this.container.style.display = 'none';
}
ToolTip.prototype.doShow = function () {
	this.container.style.display = 'block';
	if (document.all) {
		this.iframe.style.width = (this.container.offsetWidth)+ 'px';
		this.iframe.style.height = (this.container.offsetHeight) + 'px';
	}
}
// --------------------------------------------------------------------------------------------
//
// HoverToolTip component
//
// --------------------------------------------------------------------------------------------
function HoverToolTip (container) {
	this.container = container.tagName ? container : YAHOO.util.Dom.get(container);
}
HoverToolTip.prototype.show = function (e, args) {
	args.followMouse(e, args);
	if (args.container) args.container.style.display = 'block';
}
HoverToolTip.prototype.hide = function (e, args) {
	args.priceset = false;
	if (args.container) args.container.style.display = 'none';
}
HoverToolTip.prototype.followMouse = function (e, args) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	YAHOO.util.Dom.setX(args.container, posx);
	YAHOO.util.Dom.setY(args.container, posy + 34);
}
// --------------------------------------------------------------------------------------------
//
// ClickToolTip component
//
// --------------------------------------------------------------------------------------------
function ClickToolTip (cont, myLink, deltaX, deltaY) {
	this.container = cont;
	this.deltaX = deltaX;
	this.deltaY = deltaY;
	YAHOO.util.Event.addListener(myLink, 'click', this.show, [this, myLink], true);
	YAHOO.util.Event.addListener(myLink, 'blur', this.hide, this, true);
}
ClickToolTip.prototype.show = function (e, args) {
	YAHOO.util.Event.preventDefault(e);
	var base = args[0];
	var myLink = args[1];
	base.container.style.left = ((YAHOO.util.Dom.getX(myLink) + base.deltaX) - YAHOO.util.Dom.getX(YAHOO.util.Dom.get('ebt-main-container'))) + "px";
	base.container.style.top = (YAHOO.util.Dom.getY(myLink) + base.deltaY) + "px";
	base.container.style.display = 'block';
}
ClickToolTip.prototype.hide = function (e) {
	this.container.style.display = 'none';
}
// --------------------------------------------------------------------------------------------
//
// HTMLNode component
//
// --------------------------------------------------------------------------------------------
function HTMLNode(target, type, attributes, innerHtml, className, hrefText) {
	var newNode = target.createElement(type);
	for (var prop in attributes) {
		newNode.setAttribute(prop, attributes[prop]);
	}
	if (type = 'a' && hrefText) newNode.href = hrefText;
	if (className) newNode.className = className;
	if (innerHtml) newNode.innerHTML = innerHtml;
	return newNode;
}
// --------------------------------------------------------------------------------------------
//
// PriceBreakdown component
//
// --------------------------------------------------------------------------------------------
function PriceBreakdown (hideText) {
	this.toggleLink = YAHOO.util.Dom.get('ebt-show-price-breakdown');
	this.hideText = hideText;
	if (this.toggleLink) this.showText = this.toggleLink.innerHTML;
	this.extendedData = YAHOO.util.Dom.get('ebt-price-breakdown');
	this.opened = false;
	YAHOO.util.Event.addListener(this.toggleLink, 'click', this.toggle, this, true);
	
	this.totalAdultPrice = YAHOO.util.Dom.get('ebt-total-adult-price');
	this.totalPriceTop = YAHOO.util.Dom.get('ebt-total-price-top');
	this.totalPriceBot = YAHOO.util.Dom.get('ebt-total-price-bot');
	this.adultPrice = YAHOO.util.Dom.get('ebt-adult-price');
	this.childPrice = YAHOO.util.Dom.get('ebt-child-price');
	this.infantPrice = YAHOO.util.Dom.get('ebt-infant-price');
	this.adultTax = YAHOO.util.Dom.get('ebt-adult-tax');
	this.childTax = YAHOO.util.Dom.get('ebt-child-tax');
	this.infantTax = YAHOO.util.Dom.get('ebt-infant-tax');
	this.adultFee = YAHOO.util.Dom.get('ebt-adult-fee');
	this.childFee = YAHOO.util.Dom.get('ebt-child-fee');
	this.infantFee = YAHOO.util.Dom.get('ebt-infant-fee');
	this.adultTotal = YAHOO.util.Dom.get('ebt-adult-total');
	this.childTotal = YAHOO.util.Dom.get('ebt-child-total');
	this.infantTotal = YAHOO.util.Dom.get('ebt-infant-total');
	this.departPrice = YAHOO.util.Dom.get('ebt-depart-price');
	this.returnPrice = YAHOO.util.Dom.get('ebt-return-price');
	if (YAHOO.util.Dom.get('ebt-best-price-pb-link')) {
		this.tooltipBestPrice = new ToolTip('ebt-best-price-box');
		this.tooltipBestPriceLink = YAHOO.util.Dom.get('ebt-best-price-pb-link');
		YAHOO.util.Event.addListener(this.tooltipBestPriceLink, 'mouseover', this.tooltipBestPrice.show, this.tooltipBestPrice, true);
		YAHOO.util.Event.addListener(this.tooltipBestPriceLink, 'mouseout', this.tooltipBestPrice.hide, this.tooltipBestPrice, true);
	}
}
PriceBreakdown.prototype.toggle = function (e) {
	YAHOO.util.Event.preventDefault(e);
	if (this.opened) {
		this.opened = false;
		this.toggleLink.innerHTML = this.showText;
		YAHOO.util.Dom.removeClass(this.toggleLink, 'hide-price-breakdown');
		this.extendedData.style.display = 'none';
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "price_details", "z_ebt_eventplace" : "customize", "z_ebt_event" : "1", "z_ebt_eventvalue" : "close"});
	} else {
		this.opened = true;
		this.toggleLink.innerHTML = this.hideText;
		YAHOO.util.Dom.addClass(this.toggleLink, 'hide-price-breakdown');
		this.extendedData.style.display = 'block';
		if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "price_details", "z_ebt_eventplace" : "customize", "z_ebt_event" : "1", "z_ebt_eventvalue" : "open"});
	}
}
PriceBreakdown.prototype.update = function (prices) {
	if (!prices || prices.length == 0) {
		prices = null;
	}
	if (this.adultPrice) this.adultPrice.innerHTML = prices ? prices[0] : '-';
	if (this.adultTax) this.adultTax.innerHTML = prices ? prices[1] : '-';
	if (this.adultFee) this.adultFee.innerHTML = prices ? prices[2] : '-';
	
	if (this.childPrice) this.childPrice.innerHTML = prices ? prices[3] : '-';
	if (this.childTax) this.childTax.innerHTML = prices ? prices[4] : '-';
	if (this.childFee) this.childFee.innerHTML = prices ? prices[5] : '-';

	if (this.infantPrice) this.infantPrice.innerHTML = prices ? prices[6] : '-';
	if (this.infantTax) this.infantTax.innerHTML = prices ? prices[7] : '-';
	if (this.infantFee) this.infantFee.innerHTML = prices ? prices[8] : '-';
	
	if (this.totalAdultPrice) this.totalAdultPrice.innerHTML = prices ? prices[9] : '-';
	if (this.adultTotal) this.adultTotal.innerHTML = prices ? prices[10] : '-';
	if (this.childTotal) this.childTotal.innerHTML = prices ? prices[11] : '-';
	if (this.infantTotal) this.infantTotal.innerHTML = prices ? prices[12] : '-';
	if (this.totalPriceTop) this.totalPriceTop.innerHTML = prices ? prices[13] : '-';
	if (this.totalPriceBot) this.totalPriceBot.innerHTML = prices ? prices[13] : '-';
	if (this.departPrice) this.departPrice.innerHTML = prices ? prices[14] : '-';
	if (this.returnPrice) this.returnPrice.innerHTML = prices ? prices[15] : '-';
}
// --------------------------------------------------------------------------------------------
//
// PriceBumbMessage component
//
// --------------------------------------------------------------------------------------------
function PriceBumbMessage(page) {
	this.ebtPage = page;
	this.pbText = YAHOO.util.Dom.get('ebt-pb-text').innerHTML;
	this.createPBMDOM();
}
PriceBumbMessage.prototype.createPBMDOM = function () {
	var targetDocument = this.ebtPage.targetDoc;
	this.pbPopupElement = new HTMLNode(targetDocument, 'div', {id:'ebt-pricebumb-message'}, '<div id="ebt-pricebumb-top">&nbsp;</div><p>' + this.pbText + '</p>');
	targetDocument.body.appendChild(this.pbPopupElement);
}
PriceBumbMessage.prototype.show = function () {
	if (this.ebtPage.lightBox) this.ebtPage.lightBox.show();
	var dd = document.documentElement ? document.documentElement : document.body;
	this.pbPopupElement.style.top = (dd.scrollTop + 200) + 'px';
	this.pbPopupElement.style.display = 'block';
	var attributes = {
		opacity: { to: 1 }
	}
	anim = new YAHOO.util.Motion(this.pbPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.animate();
	this.timeOut = setTimeout(createContextFunction(this, "close"), 1100);
}
PriceBumbMessage.prototype.close = function () {
	clearTimeout(this.timeOut);
	this.timeOut = -1;
	var attributes = {
		opacity: { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.pbPopupElement, attributes,.5, YAHOO.util.Easing.easeOut);
	anim.pb = this;
	anim.onComplete.subscribe(this.finishClose);
	anim.animate();
	if (this.ebtPage.lightBox) this.ebtPage.lightBox.hide();
}
PriceBumbMessage.prototype.finishClose = function () {
	this.pb.pbPopupElement.style.display = 'none';
}
// --------------------------------------------------------------------------------------------
//
// general functions
//
// --------------------------------------------------------------------------------------------
function createContextFunction(context, method, method2) {
	return (function(x){
		method = (method == "post") ? method2 : method;
		eval("context."+method+"(x)");
		return false;
	});
}
// compare function to compare Arrays
Array.prototype.compare = function(testArr) {
    if (this.length != testArr.length) return false;
    for (var i = 0; i < testArr.length; i++) {
        if (this[i].compare) { 
            if (!this[i].compare(testArr[i])) return false;
        }
        if (this[i] !== testArr[i]) return false;
    }
    return true;
}
/* get, set, and delete cookies */
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setEscapedCookie( name, value, expires, path, domain, secure ) {
	path = '/';
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// --------------------------------------------------------------------------------------------
//
// checkoutpage 4 -- confirmation
//
// --------------------------------------------------------------------------------------------
function showConditions () {
	var showConditionsLinks = YAHOO.util.Dom.getElementsByClassName('ebt-show-conditions', 'a', 'left-check-out');
	var showConditionsHTML = YAHOO.util.Dom.getElementsByClassName('cond-popup', 'div', 'left-check-out');
	for (var i = 0; i < showConditionsLinks.length; i++) {
		new ClickToolTip(showConditionsHTML[i], showConditionsLinks[i], 0, -85);
	}
}

// --------------------------------------------------------------------------------------------
//
// Open Jaw
//
// --------------------------------------------------------------------------------------------

function Openjaw (fs) {
	this.flightSearch = fs;
	this.docBody = document.getElementsByTagName('body');
	this.ojCheck = document.getElementById('ebt-open-jaw-opt');
	this.init();
}

Openjaw.prototype.init = function () {
	YAHOO.util.Event.addListener(this.ojCheck, 'click', this.toggleOpenJaw, [this, this.ojCheck], true);
	YAHOO.util.Event.addListener(YAHOO.util.Dom.get('ebt-departure-place'), 'blur', this.prefillFields, [this, this.ojCheck], true);
	
	if (this.ojCheck && this.ojCheck.checked) {
		YAHOO.util.Dom.addClass(document.body, 'open-jaw');
		// prefill fields
		if (YAHOO.util.Dom.get('ebt-airportcode-from-oj').value) YAHOO.util.Dom.get('ebt-from-place-oj').style.color = '#023167';
	}
}
Openjaw.prototype.toggleOpenJaw = function (e, args) {
	var base = args[0];
	var check = args[1];
	
	if(check && check.checked) {
		YAHOO.util.Dom.addClass(document.body, 'open-jaw');
		// prefill fields
		YAHOO.util.Dom.get('ebt-from-place-oj').value = YAHOO.util.Dom.get('ebt-destination-place').value;
		YAHOO.util.Dom.get('ebt-airportcode-from-oj').value = YAHOO.util.Dom.get('ebt-airportcode').value;
		if (YAHOO.util.Dom.get('ebt-airportcode-from-oj').value) YAHOO.util.Dom.get('ebt-from-place-oj').style.color = '#023167';

		YAHOO.util.Dom.get('ebt-airportcode-dest-oj').value = YAHOO.util.Dom.get('ebt-departure-place').options[YAHOO.util.Dom.get('ebt-departure-place').selectedIndex].value;		
		YAHOO.util.Dom.get('ebt-destination-place-oj').value = YAHOO.util.Dom.get('ebt-departure-place').options[YAHOO.util.Dom.get('ebt-departure-place').selectedIndex].text;
		YAHOO.util.Dom.get('ebt-destination-place-oj').style.color = '#023167';
	} else {
		YAHOO.util.Dom.removeClass(document.body, 'open-jaw');
	}
}
function calculateTop(object) {if (object) return object.offsetTop + calculateTop(object.offsetParent); else return 0;}
function calculateLeft(object) {if (object) return object.offsetLeft + calculateLeft(object.offsetParent); else return 0;}
function isChild(ancestor, candidate) {
	while (candidate && candidate != ancestor.parentNode) {
		if (candidate == ancestor) return true;
		candidate = candidate.parentNode;
	}
	return false;
}

// --------------------------------------------------------------------------------------------
//
// EBTCalendar component
//
// --------------------------------------------------------------------------------------------
function EBTCalendar (container, inputBox, dateFormat, defaultDate, minDate, maxDate, months, days, closeText) {
	if (!container) {
		this.container = new HTMLNode(document, 'div', null, '', 'ebt-calendar');
		document.body.appendChild(this.container);
	} else {
		this.container = container;
	}
	this.homepage = true;
	this.closeText = closeText ? closeText : 'close';
	this.closeBut = new HTMLNode(document, 'a', {href:'javascript:;'}, this.closeText, 'close-calendar');
	this.container.appendChild(this.closeBut);
	this.tableContainer = new HTMLNode(document, 'div', {id:'cal' + Math.random()});
	this.container.appendChild(this.tableContainer);
	this.cal = new YAHOO.widget.Calendar('myCal', this.tableContainer.id, {mindate:minDate, maxdate:maxDate});
	this.inputBox = inputBox;
	this.dateFormat = dateFormat;
	this.minDate = minDate;
	this.maxDate = maxDate;
	this.months = months;
	this.days = days;
	this.mover = false;
	this.configDateFormat();
	this.initEvents();
	this.defaultDate = defaultDate;
	if (defaultDate) this.cal.select(this.defaultDate);
}
EBTCalendar.prototype.configDateFormat = function () {
	this.cal.cfg.setProperty("WEEKDAYS_SHORT", this.days);
	this.cal.cfg.setProperty("MONTHS_LONG", this.months);
	var sDate = this.dateFormat.split('/');
	sDate[0] == 'mm' ? this.mPos = 1 : (sDate[1] == 'mm' ? this.mPos = 2 : this.mPos = 3);
	sDate[0] == 'dd' ? this.dPos = 1 : (sDate[1] == 'dd' ? this.dPos = 2 : this.dPos = 3);
	sDate[0].indexOf('yy') != -1 ? this.yPos = 1 : (sDate[1].indexOf('yy') != -1 ? this.yPos = 2 : this.yPos = 3);
	this.cal.cfg.setProperty("MDY_MONTH_POSITION", this.mPos);
	this.cal.cfg.setProperty("MDY_DAY_POSITION", this.dPos);
	this.cal.cfg.setProperty("MDY_YEAR_POSITION", this.yPos);
	this.cal.cfg.setProperty("START_WEEKDAY", 1);
	this.yearShort = sDate[this.yPos-1].length > 2 ? false : true;
}
EBTCalendar.prototype.initEvents = function () {
	YAHOO.util.Event.addListener(this.container, "mouseover", this.overCal, this, true); 
	YAHOO.util.Event.addListener(this.container, "mouseout", this.outCal, this, true); 
	YAHOO.util.Event.addListener(this.inputBox, "focus", this.show, [this, this.inputBox], true); 
	YAHOO.util.Event.addListener(this.closeBut, "click", this.close, this, true); 
	YAHOO.util.Event.addListener(this.inputBox, "keydown", this.close, this, true); 
	YAHOO.util.Event.addListener(this.inputBox, "blur", this.checkEnteredDate, this, true); 
	this.cal.selectEvent.subscribe(this.selectDate, this, true);
	this.cal.renderEvent.subscribe(this.updateCalNavigation, this, true);

	this.dateInputError = new YAHOO.util.CustomEvent("dateError", this);
	this.dateNoError = new YAHOO.util.CustomEvent("dateNoError", this);
}
EBTCalendar.prototype.overCal = function (e) {
	this.mover = true;
}
EBTCalendar.prototype.outCal = function (e) {
	try {if (isChild(this.container, YAHOO.util.Event.resolveTextNode(YAHOO.util.Event.getRelatedTarget(e)))) return} catch(e) {}
	this.mover = false;
}
EBTCalendar.prototype.show = function (e, args) {
	var base = args[0];
	var inputBox = args[1];
	
	if (inputBox.disabled) return;
	if (base.homepage) {
		if (inputBox.id.indexOf('depart') > -1) {
			if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "calendar_departure", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1"});
		} else {
			if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "calendar_return", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1"});
		}
	}
	if (inputBox) inputBox.select();
	if (base.cal.getSelectedDates().length > 0) {
		base.cal.cfg.setProperty("pagedate", (base.cal.getSelectedDates()[0].getMonth() + 1) + '/' + base.cal.getSelectedDates()[0].getFullYear());
	}
	base.cal.render();
	base.container.style.display = 'block';
	YAHOO.util.Dom.setXY(base.container, [calculateLeft(inputBox) - 3, calculateTop(inputBox) + 16]);
}
EBTCalendar.prototype.close = function (e) {
	this.mover = false;
	this.container.style.display = 'none';
}
EBTCalendar.prototype.selectDate = function (e, args) {
	var selectedRetDate = args[0][0];
	var selDay = selectedRetDate[2];
	var selMonth = selectedRetDate[1];
	var selYear = selectedRetDate[0];

	selectedDate = selDay + '/' + selMonth + '/' + selYear;
	this.close();
	this.inputBox.value = this.formatDate(selectedDate);
	YAHOO.util.Dom.removeClass(this.inputBox, 'error');
	this.dateNoError.fire(this.inputBox); 
}
EBTCalendar.prototype.formatDate = function (date) {
	var aDate = date.split('/');
	var aFormattedDate = new Array();
	
	aFormattedDate[this.dPos-1] = aDate[0];
	aFormattedDate[this.mPos-1] = aDate[1];
	aFormattedDate[this.yPos-1] = aDate[2];
	if (this.yearShort) aFormattedDate[this.yPos-1] = aFormattedDate[this.yPos-1].substr(2, 2); // show only last 2 characters of year
	var s = aFormattedDate[0] + '/' + aFormattedDate[1] + '/' + aFormattedDate[2];
	
	return s;
}
EBTCalendar.prototype.checkEnteredDate = function (e) {
	if (this.mover) return;
	this.close();
	var dateValues = this.inputBox.value.split('/');
	var day = parseInt(dateValues[this.dPos-1], 10);
	var month = parseInt(dateValues[this.mPos-1], 10);
	var year = parseInt(dateValues[this.yPos-1], 10);
	if (this.yearShort) year += 2000;
	var date = new Date(year, month-1, day);
	if ((date.getMonth() + 1) != month) {
		this.dateInputError.fire(this.inputBox); 
		YAHOO.util.Dom.addClass(this.inputBox, 'error');
		if (this.homepage) {
			if (this.inputBox.id.indexOf('depart') > -1) 
				if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "departure_date_validation", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "nonvalid"});
			else 
				if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "return_date_validation", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "nonvalid"});
		}
		return false;
	} else {
		this.dateNoError.fire(this.inputBox);
		YAHOO.util.Dom.removeClass(this.inputBox, 'error');
		this.cal.select(date);
		if (this.homepage) {
			if (this.inputBox.id.indexOf('depart') > -1) 
				if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "departure_date_validation", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "valid"});
			else 
				if (_metron2) _metron2.measureVariablesAndCommit({"z_ebt_eventtype" : "return_date_validation", "z_ebt_eventplace" : "homepage", "z_ebt_event" : "1", "z_ebt_eventvalue" : "valid"});
		}
		return true;
	}
}
EBTCalendar.prototype.getSelectedDates = function () {
	return this.cal.getSelectedDates();
}
EBTCalendar.prototype.updateCalNavigation = function (e) {
	var mindate = new Date(this.cal.cfg.getProperty("minDate"));
	var maxdate = new Date(this.cal.cfg.getProperty("maxDate"));
	maxdate.setMonth(maxdate.getMonth() - 1);
	if (this.cal.cfg.getProperty("pagedate").getTime() <= mindate.getTime()) {
		YAHOO.util.Dom.getElementsByClassName('calnavleft', 'a', this.cal.oDomContainer)[0].style.display = 'none';
	};
	if (this.cal.cfg.getProperty("pagedate").getTime() > maxdate.getTime()) {
		YAHOO.util.Dom.getElementsByClassName('calnavright', 'a', this.cal.oDomContainer)[0].style.display = 'none';
	};
}
// Content: js EBT7 layover
// use for new ebt7 dashboard 
//if (this.canScriptDomain) this.lightBox = new LayOver(document.body, "lightbox", .4, .5);
function LayOver(container, className, animationSpeed, maxOpacity, useReplacementBoxes) {
	this.speed = animationSpeed;
	this.opacity = maxOpacity;
	// Get parentregion
	var parentRegion = YAHOO.util.Dom.getRegion(container);
	// make sure you fill out the whole page
	var height = YAHOO.util.Dom.getViewportHeight() > document.body.offsetHeight ? YAHOO.util.Dom.getViewportHeight() : document.body.offsetHeight;
	// Create the layover
	this.layOver = document.createElement("div");
	this.layOver.className = className;
	container.appendChild(this.layOver);

	// Settings for the layover
	// The layover is put in the parentobject of the application that uses the layover
	// Because else ie has problems with z-index
	this.layOver.style.height = height + "px";
	this.layOver.style.width = YAHOO.util.Dom.getViewportWidth() + "px";
	// Set negative margin to align the layover with the screen
	this.layOver.style.marginLeft = - parentRegion.left + "px";
	this.layOver.style.marginTop = - parentRegion.top + "px";
	
	if (is_ie6) {
		this.selectBoxes = document.getElementsByTagName("select");
		if (useReplacementBoxes) this.replacements = createReplacementSelectBoxes(this.selectBoxes);
//		alert(this.replacements.length)
	}
}
LayOver.prototype.hide = function() {
	var attributes = {
		opacity : { to: 0 }
	}
	anim = new YAHOO.util.Motion(this.layOver, attributes, this.speed, YAHOO.util.Easing.easeOut);
	anim.lo = this;
	anim.onComplete.subscribe(this.finishHide);
	anim.animate();
}
LayOver.prototype.finishHide = function() {
	if (this.lo.selectBoxes) this.lo.showSelectBoxes();
	this.lo.layOver.style.display = "none";
}
LayOver.prototype.show = function() {
	if (this.selectBoxes) this.hideSelectBoxes();
	this.layOver.style.display = "block";
	var attributes = {
		opacity : { to: this.opacity }
	}
	anim = new YAHOO.util.Motion(this.layOver, attributes, this.speed, YAHOO.util.Easing.easeOut);
	anim.animate();
}
LayOver.prototype.hideSelectBoxes = function() {
	for (var i = 0; i < this.selectBoxes.length; i++) {
		this.selectBoxes[i].style.visibility = "hidden";
		if (this.replacements) this.replacements[i].style.visibility = "visible";
	}
}
LayOver.prototype.showSelectBoxes = function() {
	for (var i = 0; i < this.selectBoxes.length; i++) {
		this.selectBoxes[i].style.visibility = "visible";
		if (this.replacements) this.replacements[i].style.visibility = "hidden";
	}
}

function createReplacementSelectBoxes(selectBoxes) {
	var replacements = new Array();
	for (var i = 0; i < selectBoxes.length; i++) {
		var div = document.createElement("div");
		div.style.position = "absolute";
		div.style.visibility = "hidden";
		
		var input = document.createElement("input");
		input.type = "text";
//		input.value = selectBoxes[i].value;
		input.style.width = (selectBoxes[i].offsetWidth - 4) + "px";
		input.style.height = (selectBoxes[i].offsetHeight - 4) + "px";
		
		// Get the location of the selectbox on the screen
		var region = YAHOO.util.Dom.getRegion(selectBoxes[i]);
		div.style.left = (region.left - 2) + "px";
		div.style.top = (region.top - 3) + "px";
		div.appendChild(input);
		
		var img = document.createElement("img");
		img.src = "images/ie6-selectbox-arrow.gif";
		img.className = "replacement-image";
		img.style.position = "absolute";
		img.style.right = 1 + "px";
		img.style.top = 3 + "px";
		div.appendChild(img);
		
//		selectBoxes[i].parentNode.appendChild(div);
		document.body.appendChild(div);
		
		replacements[i] = div;
	}
	return replacements;
}
// Content: js eBT7 Page
if (top.location != document.location){
	document.domain = 'klm.com';
}
var _metron2;

// --------------------------------------------------------------------------------------------
//
// EBTPage component
//
// --------------------------------------------------------------------------------------------
function EBTPage (container) {
	try {
		_metron2 = new Metron();
	} catch (e) {}
	this.container = YAHOO.util.Dom.get(container);
	this.canScriptDomain = this.checkScriptingPoss();
	this.browser = this.getBrowser();
	this.addStylesheets();
	if (this.browser == 'safari') this.attachCSS('static/css/safari.css', document);
	if (this.canScriptDomain) this.lightBox = new Lightbox(this);
	//the following gives an error in ie6+ , have to ask Cor about this
	//if (this.canScriptDomain) this.lightBox = new LayOver(document.body, "lightbox", .4, .5);
	
}
EBTPage.prototype.addStylesheets = function () {
	var host = document.location.protocol+'//'+document.domain+(document.location.port ? ':'+document.location.port : '');
	var publication = 'hk_hk';
	var aCssURLs = [
		host+'/travel/'+publication+'/static/css/ebt-elements.css'
		];
		
	if ( is_ie6 )
	{
		aCssURLs[aCssURLs.length] = host+'/travel/'+publication+'/static/css/ebt-elements-ie6.css';
	}
	else if ( is_ie7 )
	{
		aCssURLs[aCssURLs.length] = host+'/travel/'+publication+'/static/css/ebt-elements-ie7.css';
	}
	else if ( is_ie8 )
	{
		aCssURLs[aCssURLs.length] = host+'/travel/'+publication+'/static/css/ebt-elements-ie8.css';
	}
	YAHOO.util.Get.css(aCssURLs);
}
EBTPage.prototype.checkScriptingPoss = function () {
	try {
		var o = parent.document.body.offsetHeight;
		this.targetDoc = parent.document;
		
		return true;
	} catch (e) {
		this.targetDoc = document;
		
		return false;
	}
}
EBTPage.prototype.getBrowser = function () {
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof)
		return 'opera';
	} else if (ua.indexOf('msie 7')!=-1) { // IE7
		return 'ie7';
	} else if (ua.indexOf('msie 6') !=-1) { // IE6
		return 'ie6';
	} else if (ua.indexOf('msie') !=-1) { // IE5.5
		return 'ie55';
	} else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko")
		return 'safari';
	} else if (ua.indexOf('gecko') != -1) { // Gecko
		return 'gecko';
	} else {
		return false;
	}
}
EBTPage.prototype.attachCSS = function (css, target) {
	if (target) {
		var headID = target.getElementsByTagName("head")[0];
		var cssNode = target.createElement('link');
	} else {
		var headID = this.targetDoc.getElementsByTagName("head")[0];
		var cssNode = this.targetDoc.createElement('link');
	}
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = '/travel/hk_hk/' + css;
	cssNode.media = 'screen, print';
	headID.appendChild(cssNode);
}