﻿function TrackSuppliersLinks(supplierLinksNames) {

    var service = new NetMatch.Zoover.Web.Services.Suppliers.SuppliersLinksService();

    service.TrackLinks(supplierLinksNames, OnTrackLinksComplete, OnTrackLinksError);
}

function OnTrackLinksComplete(result) {
}

function OnTrackLinksError(result) {
	// Removed the alert since on FireFox you get an annoying message if the user leaves the page before the 
	// request to the server has executed
	//alert(result.get_message());
}

/* EXPAND-COLLAPSE behaviour for suppliers with pricing info*/
// sid - shader id
// tid - shader text id
function ShowSuppliersShader(sid, tid, msg) {
	var sha = document.getElementById(sid);
	var tex = document.getElementById(tid);
	if (sha) {
		sha.className = "shader-on";
		tex.style.lineHeight = tex.clientHeight + 'px';
		tex.innerHTML = "<span>" + msg + "</span>";
	}
}

// sid - shader id
// tid - shader text id
function HideSuppliersShader(sid, tid) {
	var sha = document.getElementById(sid);
	var tex = document.getElementById(tid);
	if (sha) {
		sha.className = "shader-off";
		tex.innerHTML = "&nbsp;";
	}
}

// sid - shader id
// stid - shader text id
// cid - collapse container id
function ExpandSuppliers(sid, cid, stid, hidden_suppliers_id) {
	//closes supplier links pop-up
	DisableVerticalSupplierLinksWithPublication()

	var sha = document.getElementById(sid);
	var shta = document.getElementById(stid);
	var col = document.getElementById(cid);
	var hidden_suppliers = document.getElementById(hidden_suppliers_id);

	if (sha)
		sha.style.display = "none";
	if (shta)
		shta.style.display = "none";
	if (col)
		col.style.display = "block";
	if (hidden_suppliers)
		hidden_suppliers.style.display = "block"

	// This forces IE 7 to redraw the adlinks panel and position the 3 boxes below the adlinks to the correct position
	sha.parentNode.parentNode.style.display = "none";
	sha.parentNode.parentNode.style.display = "block";
}

// sid - shader id
// stid - shader text id
// cid - collapse container id
function CollapseSuppliers(sid, cid, stid, hidden_suppliers_id) {
	//closes supplier links pop-up
	DisableVerticalSupplierLinksWithPublication()

	var sha = document.getElementById(sid);
	var shta = document.getElementById(stid);
	var col = document.getElementById(cid);
	var hidden_suppliers = document.getElementById(hidden_suppliers_id);

	if (sha)
		sha.style.display = "block";
	if (shta)
		shta.style.display = "block";
	if (col)
		col.style.display = "none";

	if (hidden_suppliers)
		hidden_suppliers.style.display = "none"

	// This forces IE 7 to redraw the adlinks panel and position the 3 boxes below the adlinks to the correct position
	sha.parentNode.parentNode.style.display = "none";
	sha.parentNode.parentNode.style.display = "block";
}

// for IE6 only - as height: 100% does not work on IE6 - we force the shader and the shader text to have it's parent container
function setIE6ShaderHeight(shc, sha, sht) {
	var shcElement = document.getElementById(shc);
	if (shcElement != null) {
		var height = shcElement.offsetHeight;
		var shaElement = document.getElementById(sha);
		var shtElement = document.getElementById(sht);
		if ((shaElement != null) && (shtElement != null)) {
			shaElement.style.height = height;
			shtElement.style.height = height;
		}
	}
}

/*
function PriceInfo(name, price){
	var _Name = name;
	var _Price = price;
	
	this.getName = function() { return _Name; }
	this.getPrice = function() { return _Price; }
}

function PriceInfoToolTip(){
	this.PriceInfoArray = new Array();
}

PriceInfoToolTip.prototype.Length = function(){
	return this.PriceInfoArray.length;
}

PriceInfoToolTip.prototype.InfoAtIndex = function(index){
if (index < this.PriceInfoArray.length) {
	return this.PriceInfoArray[index];
	}
	return null;
}

PriceInfoToolTip.prototype.AddPriceInfo = function(priceInfo) {
	this.PriceInfoArray[this.PriceInfoArray.length] = priceInfo;
}

function HoverTooltips(){
	this.HoverInfo = new Array();
	this.Codes = new Array();
	this.DurationTitle = "";
	this.PriceTitle = "";
	this.HoverTitle = "";
	this.ParentsTitle = "";
}

HoverTooltips.prototype.AddPriceInfo = function(code, name, price) {
	var lExistingInfo = this.GetObjectForCode(code);
	if (lExistingInfo == null) {
		var lPriceInfo = new PriceInfoToolTip();
		lPriceInfo.AddPriceInfo(new PriceInfo(name, price));
		this.HoverInfo[this.HoverInfo.length] = lPriceInfo;
		this.Codes[this.Codes.length] = code;
	}
	else {
		lExistingInfo.AddPriceInfo(new PriceInfo(name, price));
	}
}

// The method that returns the current object for the current code if it exists and null if it doesn't exist

HoverTooltips.prototype.GetObjectForCode = function(code) {
	for (var i = 0; i < this.Codes.length; i++) {
		if (this.Codes[i] == code) {
			return this.HoverInfo[i];
		}
	}
	return null;
}

HoverTooltips.prototype.SetDurationTitle = function(value) {
	this.DurationTitle = value;
}

HoverTooltips.prototype.GetDurationTitle = function() {
	return this.DurationTitle;
}

HoverTooltips.prototype.SetPriceTitle = function(value) {
	this.PriceTitle = value;
}

HoverTooltips.prototype.GetPriceTitle = function() {
	return this.PriceTitle;
}

HoverTooltips.prototype.SetAccommodationTitle = function(value) {
	this.HoverTitle = value;
}

HoverTooltips.prototype.GetAccommodationTitle = function() {
	return this.HoverTitle;
}

HoverTooltips.prototype.SetParentsTitle = function(value) {
	this.ParentsTitle = value;
}

HoverTooltips.prototype.GetParentsTitle = function() {
	return this.ParentsTitle;
}

HoverTooltips.prototype.GetHtmlForCode = function(code, div, containerName, widthOffset) {
	var lInfo = this.GetObjectForCode(code);
	div.style.color = "#4C9EDB";
	var lContainer = document.getElementById(containerName);
	if (lInfo != null && lContainer != null) {
		var lParent = this.GetAccommodationTitle().length + this.GetParentsTitle().length;
		var lRatio = lInfo.Length() > 6 ? 22 : 24;
		if (lInfo.Length() < 3 && lParent < 80) {
			lRatio += 5;
		}
		var lExtra = lParent > 80 ? 40 : 31;
		if (lParent > 80) {
			lRatio += 2;
			if (lInfo.Length() > 6) {
				lRatio -= 2;
			}
		}
		var lHeight = lInfo.Length() * lRatio + (lParent / 50) * lExtra + 22;
		var lTop = div.offsetTop + 19;
		var lLeft = div.offsetLeft + parseInt(widthOffset) + 10;
		if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 || navigator.userAgent.toLowerCase().indexOf('msie 7') != -1) {
			lTop = div.parentNode.offsetTop + 18;
			lLeft += 6;
			if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
				lLeft += 12;
			}
		}

		if (lInfo.Length() < 3 && lParent > 70) {
			lHeight += 30;
		}

		var lStyle = "height:" + lHeight + "px;top:" + lTop + "px;left:" + lLeft + "px";
		var lHtml = "<div class=\"hoverContainer\" style=\"" + lStyle + "\"><div class=\"hoverAccoTitle\">" + this.GetAccommodationTitle()
			+ "<span class=\"parentsTitle\">" + this.ParentsTitle + "</span></div>";
		var lFirstDiv = "<div class=\"durationContainer\"><span class=\"priceTitle\">" + this.GetDurationTitle() + "</span><br/>";
		var lSecondDiv = "<div class=\"priceContainer\"><span class=\"priceTitle\">" + this.GetPriceTitle() + "</span><br/>";
		for (var i = 0; i < lInfo.Length(); i++) {
			var lObj = lInfo.InfoAtIndex(i);
			if (lObj != null) {
				lFirstDiv += "<span>" + lObj.getName() + "</span><br/>";
				lSecondDiv += "<span>" + lObj.getPrice() + "</span><br/>";
			}
		}
		lFirstDiv += "</div>";
		lSecondDiv += "</div>";
		lHtml += lFirstDiv + lSecondDiv + "</div>";
		lContainer.innerHTML = lHtml;
		lContainer.style.display = "block";
	}
}

HoverTooltips.prototype.HideHtmlCode = function(div, containerName) {
	div.style.color = "#FF5D10";
	var lContainer = document.getElementById(containerName);
	if (lContainer != null) {
		lContainer.style.display = "none";
	}
}

var HoverTooltipsAccos = new HoverTooltips();

*/

/* --END-- SUPPLIERS FOR PRICING INFO */


/* initialize some variables */
var calendarstate = 'CLOSED';
var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var dropdownYearMonth;
var dropdownDay;
var updateJS = 0;

// we validate against dates like 30 feb, 31 iun etc
function ValidateDay(monthCtrlId, dayCtrlId, changeDay, uniqueKeyword) {
	//alert(date_validator + " " + typeof (date_validator));
	if (typeof (date_validator) == 'undefined' || date_validator == null)
		return true;

	var lCalendar = new CalendarFlight(uniqueKeyword);

	var lYearIndex;
	if (dayCtrlId == 'depDayFlight_' + uniqueKeyword)
		lYearIndex = lCalendar.GetStartDate().getFullYear();
	else
		lYearIndex = lCalendar.GetEndDate().getFullYear();

	lYearIndex = lYearIndex - (new Date()).getFullYear();

	var dayCtrl = document.getElementById(dayCtrlId);
	var monthCtrl = document.getElementById(monthCtrlId);

	var lSelDay = dayCtrl.options[dayCtrl.selectedIndex].value;

	if (Number(lSelDay) > date_validator[lYearIndex][monthCtrl.options[monthCtrl.selectedIndex].value]) {
		if (changeDay == 1) {
			dayCtrl.selectedIndex = date_validator[lYearIndex][monthCtrl.options[monthCtrl.selectedIndex].value] - 1;
		}
		else {
			return false;
		}
	}
	return true;
}

// make sure that the start date is less than the end date
function ValidateDateChronology(uniqueKeyword) {
	var lCalendar = new CalendarFlight(uniqueKeyword);

	if (lCalendar.GetStartDate() >= lCalendar.GetEndDate())
		return false;

	return true;
}

// make sure the selection is not in the past
function ValidateDateSelection(uniqueKeyword) {
	var lCalendar = new CalendarFlight(uniqueKeyword);
	var lToday = new Date();
	if (lCalendar.GetStartDate() < lToday)
		return false;

	return true;
}

// we set the return date to be always 8 days after the departure date
function ChangeRetDate(uniqueKeyword) {
	var lCalendar = new CalendarFlight(uniqueKeyword);

	var lRetDate = lCalendar.GetStartDate();
	var lEndDate = lCalendar.GetEndDate();
	if (lRetDate <= lEndDate) {
		return;
	}

	lRetDate.setDate(lRetDate.getDate() + 8);

	var lDayCombo = document.getElementById('retDayFlight_'+uniqueKeyword);
	var lMonthCombo = document.getElementById('retMonthFlight_'+uniqueKeyword);

	lDayCombo.options[lRetDate.getDate() - 1].selected = true;

	// Get the return month. Add 1 since the month is zero based in JavaScript.
	var lReturnMonth = (lRetDate.getMonth() + 1).toString();
	if (lReturnMonth.length == 1) {
		lReturnMonth = "0" + lReturnMonth;
	}
	var lReturnMonthYear = lRetDate.getFullYear().toString() + lReturnMonth;
	for (i = 0; i < lMonthCombo.options.length; i++) {
		if (lMonthCombo.options[i].value == lReturnMonthYear) {
			lMonthCombo.options[i].selected = true;
		}
	}
}

function ShowNavigationCalendar(monthSelectId, daySelectId, leftOffsetReturn, topOffsetReturn, uniqueKeyword, monthsCount, changeReturnDate) {
	// Get the year and the month from the current selected value.
	var lSelectedValue = document.getElementById(monthSelectId).value;
	var lYear = lSelectedValue.substr(0, 4);
	// Parse the month and substract one because JavaScript months are zero based.
	// Also, doing so makes the current select month to be on the right side of the calendar, so advancing further when there
	// are no more months in the month select will not be possible.
	var lMonth = lSelectedValue.substr(4);
	lMonth = lMonth - 1;

	showCalendar('', lYear, lMonth, monthSelectId, daySelectId, 1, leftOffsetReturn, topOffsetReturn, 
		uniqueKeyword, monthsCount, changeReturnDate);
}

var CalendarFlight = function(uniqueKeyword) 
{ 
	this.UniqueKeyword = uniqueKeyword 
};

CalendarFlight.prototype.GetStartDate = function() {
	return this.GetDateFromControls('depMonthFlight_', 'depDayFlight_');
}

CalendarFlight.prototype.GetEndDate = function() {
	return this.GetDateFromControls('retMonthFlight_', 'retDayFlight_');
}

CalendarFlight.prototype.GetDateFromControls = function(monthId, dayId) {
	var lDayCombo = document.getElementById((dayId + this.UniqueKeyword));
	var lDay = lDayCombo.options[lDayCombo.selectedIndex].value;

	var lMonthCombo = document.getElementById((monthId + this.UniqueKeyword));
	var lYear = lMonthCombo.options[lMonthCombo.selectedIndex].value.substring(0, 4);
	var lMonth = lMonthCombo.options[lMonthCombo.selectedIndex].value.substring(4);

	// The month is zero based in JavaScript Date.
	lMonth = lMonth - 1;

	var lSelDate = new Date(lYear, lMonth, lDay);
	return lSelDate;
}

// gets the end date in the form 'ddMMyyyy'
CalendarFlight.prototype.GetEndDateString = function() {
	return this.GetDateString(this.GetEndDate());
}

// gets the start date in the form 'ddMMyyyy'
CalendarFlight.prototype.GetStartDateString = function() {
	return this.GetDateString(this.GetStartDate());
}

CalendarFlight.prototype.GetDateString = function(date) {
	var lDay = date.getDate();
	if (lDay < 10)
		lDay = '0' + lDay;

	var lMonth = (date.getMonth() + 1);
	if (lMonth < 10)
		lMonth = '0' + lMonth;

	var lYear = date.getFullYear();

	return '' + lDay + lMonth + lYear;
}

function InitDatesFlights(uniqueKeyword) {
	var lToday = new Date();
	lToday.setDate(lToday.getDate() + 14);
	selectDateFlight(lToday.getDate(), lToday.getMonth() + 1, lToday.getFullYear(), 'depDayFlight_' + uniqueKeyword,
		'depMonthFlight_' + uniqueKeyword, uniqueKeyword);

	lToday.setDate(lToday.getDate() + 14);
	selectDateFlight(lToday.getDate(), lToday.getMonth() + 1, lToday.getFullYear(), 'retDayFlight_' + uniqueKeyword,
		'retMonthFlight_' + uniqueKeyword, uniqueKeyword);
}

function selectDateFlight(selected_day, selected_month, selected_year, day_field, month_field, uniqueKeyword) {

	// show the dropdowns
	document.getElementById(('retDayFlight_' + uniqueKeyword)).style.visibility = 'visible';
	document.getElementById(('retMonthFlight_' + uniqueKeyword)).style.visibility = 'visible';

	if (selected_month > 12) {
		selected_month = 1;
		selected_year += 1;
	}

	if ((day_field == ("depDayFlight_" + uniqueKeyword)) || (month_field == ("depMonthFlight_" + uniqueKeyword))) {
		var mon_element = document.getElementById(("depMonthFlight_" + uniqueKeyword));
		document.getElementById(("depDayFlight_" + uniqueKeyword)).options[selected_day - 1].selected = true;

		for (i = 0; i < mon_element.options.length; i++)
			if (mon_element.options[i].value == createMonthValue(selected_month, selected_year)) {
			mon_element.options[i].selected = true;
		}

		if (typeof (mon_element.onchange) == "function") {
			mon_element.onchange();
		}

	} else if ((day_field == ("retDayFlight_" + uniqueKeyword)) || (month_field == ("retMonthFlight_" + uniqueKeyword))) {
		var mon_element = document.getElementById(("retMonthFlight_" + uniqueKeyword));
		document.getElementById(("retDayFlight_" + uniqueKeyword)).options[selected_day - 1].selected = true;
	
		for (i = 0; i < mon_element.options.length; i++)
			if (mon_element.options[i].value == createMonthValue(selected_month, selected_year))
			mon_element.options[i].selected = true;
	}
}

function createMonthValue(month, year) {
	if (month <= 9) {
		return year + '0' + month;
	}
	return year + '' + month; 
}

/* draw calendar */
function showCalendar(type, y, m, yd, dd, ujs, leftOffset, topOffset, uniqueKeyword, maxMonthCount, changeReturnDate) {
	var lMaxMonthCount = 15;
	if (maxMonthCount != undefined && maxMonthCount != null) {
		lMaxMonthCount = maxMonthCount;
	}
	var lChangeReturnDate = false;
	if (changeReturnDate != undefined && changeReturnDate != null) {
		if (changeReturnDate === true) {
			lChangeReturnDate = true;
		}		 
	}
	var h = '';
	/* set dropdowns if they are set */
	if (yd && dd) {
		dropdownYearMonth = yd;
		dropdownDay = dd;
		updateJS = ujs;
	}

	y = parseInt(y);

	if (type != 'UPDATE') {
		if (type == calendarstate) {
			return closeCalendar();
		} else {
			calendarstate = type;
		}
	}
	if (window.attachEvent) h += '<iframe style="position:absolute; width:447px;height:216px;background-color:#FFFFFF;z-index:10;"></iframe>';
	h += '<table border="0" cellpadding="0" cellspacing="0" class="calheader">';
	/* Print close button, that closes the calendar window */

	h += '<tr>';
	h += '<td width="50%" valign="top">' + drawMonth(1, y, m, uniqueKeyword, yd, dd, leftOffset, topOffset, lMaxMonthCount, lChangeReturnDate) + '</td>';
	h += '<td width="50%" valign="top">' + drawMonth(2, y, m + 1, uniqueKeyword, yd, dd, leftOffset, topOffset, lMaxMonthCount, lChangeReturnDate) + '</td>';
	h += '</tr>';

	/* Print close button, that closes the calendar window */

	h += '</table>';

	var divob = document.getElementById(('calendardiv_' + uniqueKeyword));
	divob.innerHTML = h;
	divob.style.top = topOffset+'px';
	divob.style.left = leftOffset+'px';

	setVisibilityCalendarFC('calendardiv_' + uniqueKeyword, 1);
}

/* close calendar */
function closeCalendar(uniqueKeyword) {
	calendarstate = 'CLOSED';
	setVisibilityCalendarFC('calendardiv_' + uniqueKeyword, 0);
}

/*
* function drawMonth(position, y, m)
*
* - position = This is either 1 (left) or 2 (right). Don't alter.
* - y = Year
* - m = Month
*
*/
function drawMonth(position, y, m, uniqueKeyword, yd, dd, leftOffset, topOffset, maxMonthCount, changeReturnDate) {
	var lMaxMonthCount = 15;
	if (maxMonthCount != undefined && maxMonthCount != null) {
		lMaxMonthCount = maxMonthCount;
	}
	var lChangeReturnDate = false;
	if (changeReturnDate != undefined && changeReturnDate != null) {
		if (changeReturnDate === true) {
			lChangeReturnDate = true;
		}
	}
	var h = '';
	var cells = 0;
	var today_dob = new Date();

	/* Let's do a sanity check. This works nicely if someone enters for example month 13, which would become 1, and year increased by 1 also */
	var dob = new Date(y, m - 1, 1);
	m = dob.getMonth() + 1;
	y = dob.getFullYear();

	/* Start table */
	h = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';

	/* Print the header row with month name */
	h += '<tr class="scalheader1">';

	/* Print the 'previous' button (for left calendar only) */
	if (position == 1) {
		var plink_y = y;
		var plink_m = m;

		if (plink_m == 1) {
			plink_y--;
			plink_m = 12;
		}
		h += '<td>&nbsp;</td>';
		if (dob <= today_dob) {
			h += '<td align="center" class="scalheader1">&nbsp;</td>';
		} else {
		h += '<td align="center" class="scalheader1"><a style="color: black;" href="javascript://" onClick="showCalendar(\'UPDATE\', ' + plink_y + ', ' +
				(plink_m - 1) + ',\'' + yd + '\',\'' + dd + '\',1,' + leftOffset + ',' + topOffset + ',\'' + uniqueKeyword + '\',' + lMaxMonthCount + ',' + lChangeReturnDate + ');"><img src="../shared/images2/datepicker_prev-inactive.png"></a></td>';
		}
	}

	/* Print month name */
	h += '<td colspan="5" align="center" class="scalheader1">' + monthNames[m - 1] + ' ' + y + '</td>';

	/* Print the 'next' button (for right calendar only) */
	if (position == 2) {
		var mdiff = (y * 12 + m) - (today_dob.getFullYear() * 12 + today_dob.getMonth() + 1) + 2;
		/* if the 'next month' is further than 15 months from today.. let's not show it :) */
		if (mdiff > lMaxMonthCount) {
			h += '<td>&nbsp;</td>';
		} else {
			h += '<td align="center" class="scalheader1 scalheader1-next"><a style="color: black;" href="javascript://" onClick="showCalendar(\'UPDATE\', ' + y + ', ' + (m) + ',\'' + yd + '\',\'' + dd + '\',1,' + leftOffset + ',' + topOffset + ',\'' + uniqueKeyword + '\',' + lMaxMonthCount + ',' + lChangeReturnDate + ');"><img src="../shared/images2/datepicker_next-inactive.png"></a></td>';
		}
		/* Always display the close calendar box. */
		h += '<td align="center"><a href="javascript://" onclick="closeCalendar(\'' + uniqueKeyword + '\');" class="closebutton"><img src="../shared/images2/datepicker_close-inactive.png"></a></td>';
	}

	h += '</tr>';

	/* Print day names */
	h += '<tr class="scalheader2">';

	for (var i = 0; i < dayNames.length; i++) {
		h += '<td align="center" width="14%" class="scalheader2">' + dayNames[i] + '</td>';
	}

	h += '</tr>';

	/* Print the calendar */
	h += '<tr class="scalcell">';

	/* Fill empty cells in the beginning of the 'first week of month' if necessary. For example 1st day of a month can be wednesday */
	for (var i = 0; i < getStartDay(dob); i++) {
		h += '<td>&nbsp;</td>';
		cells++;
	}

	/* Check how many days there are in this month. Also checks for leap year */
	var daysInThisMonth = getDaysInThisMonth(y, m);

	/* Print the day numbers of the week */
	for (var i = 1; i <= daysInThisMonth; i++) {
		dob.setDate(i);
		cells++;

		var mStr = m + '';
		if (mStr.length == 1) {
			mStr = '0' + mStr;
		}

		var onClickStr = 'updateCalendar(\'' + y + '\',\'' + mStr + '\',\'' + i + '\',\'' + uniqueKeyword + '\',' + lChangeReturnDate + ');';

		if (dob.getFullYear() == today_dob.getFullYear() && dob.getDate() == today_dob.getDate() && dob.getMonth() == today_dob.getMonth()) {
			/* today */
			h += '<td align="center" style="color: black;"><b>' + i + '</b></td>';
		} else if (dob.getTime() < today_dob.getTime()) {
			/* days before today are not selectable */
			h += '<td align="center" style="color: gray;">' + i + '</td>';
		} else {
			h += '<td align="center"><a href="javascript://" style="color: black;" onClick="' + onClickStr + '">' + i + '</a></td>';
		}

		/* next week row */
		if (!(cells % 7)) {
			h += '</tr><tr class="scalcell">';
		}
	}

	/* Add some empty cells to tidy the table */
	if (cells < 42) {
		var cells2 = 42 - cells;
		for (var i = 0; i < cells2; i++) {
			cells++;
			h += '<td align="center">&nbsp;</td>';

			if (!(cells % 7)) {
				h += '</tr><tr class="scalcell">';
			}
		}
	}

	/* close table */
	h += '</tr></table>';

	return h;
}

function updateCalendar(y, mStr, i, uniqueKeyword, changeReturnDate) {
	document.getElementById(dropdownYearMonth).value = (y + mStr);
	document.getElementById(dropdownDay).value = i;
	closeCalendar(uniqueKeyword);
	if (changeReturnDate === true) {
		ChangeRetDate(uniqueKeyword);
	}
}

/* Get position of the day in a week */
function getStartDay(d) {
	var startDay = d.getDay();

	if (startDay == 0) {
		startDay = 7;
	}

	return startDay - 1;
}

/* Amount of days in a month */
function getDaysInThisMonth(y, m) {
	/* leap year check for february */
	if (m == 2) {
		if (!(y % 400) || (!(y % 4) && y % 100)) {
			return 29;
		} else {
			return 28;
		}
	} else {
		return daysInMonth[m - 1];
	}
}

/* set visibility of an element. */
function setVisibilityCalendarFC(obname, state) {
	var ob = document.getElementById(obname);
	if (ob != null) {
		if (state == 1) {
			ob.style.display = '';
			ob.style.visibility = 'visible';
		} else {
			ob.style.display = 'none';
			ob.style.visibility = 'hidden';
		}
	}
}


Type.registerNamespace('NetMatch.Zoover.Web.Services.Suppliers');
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService = function() {
	NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.initializeBase(this);
	this._timeout = 0;
	this._userContext = null;
	this._succeeded = null;
	this._failed = null;
}
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.prototype = {
	_get_path: function() {
		var p = this.get_path();
		if (p) return p;
		else return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_path();
	},
	GetFlightTicketsUrl: function(children, departureIata, destinationIata, departureDay, departureMonthYear, returnDay, returnMonthYear, adults, from, to, date1, date2, succeededCallback, failedCallback, userContext) {
		return this._invoke(this._get_path(), 'GetFlightTicketsUrl', false, { children: children, departureIata: departureIata, destinationIata: destinationIata, departureDay: departureDay, departureMonthYear: departureMonthYear, returnDay: returnDay, returnMonthYear: returnMonthYear, adults: adults, from: from, to: to, date1: date1, date2: date2 }, succeededCallback, failedCallback, userContext);
	},
	GetCarRentalUrl: function(pickupIata, pickUpDayDay, pickUpMonthYear, pickUpTime, dropOffIata, dropOffDay, dropOffMonthYear, dropOffTime, fromAirport, toAirport, date1, date2, succeededCallback, failedCallback, userContext) {
		return this._invoke(this._get_path(), 'GetCarRentalUrl', false, { pickupIata: pickupIata, pickUpDayDay: pickUpDayDay, pickUpMonthYear: pickUpMonthYear, pickUpTime: pickUpTime, dropOffIata: dropOffIata, dropOffDay: dropOffDay, dropOffMonthYear: dropOffMonthYear, dropOffTime: dropOffTime, fromAirport: fromAirport, toAirport: toAirport, date1: date1, date2: date2 }, succeededCallback, failedCallback, userContext);
	},
	GetDirectFlights: function(fromIataCode, countryId, succeededCallback, failedCallback, userContext) {
		return this._invoke(this._get_path(), 'GetDirectFlights', false, { fromIataCode: fromIataCode, countryId: countryId }, succeededCallback, failedCallback, userContext);
	} 
}
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.registerClass('NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService', Sys.Net.WebServiceProxy);
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance = new NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService();
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_path = function(value) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.set_path(value); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.get_path = function() { return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_path(); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_timeout = function(value) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.set_timeout(value); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.get_timeout = function() { return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_timeout(); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_defaultUserContext = function(value) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.set_defaultUserContext(value); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.get_defaultUserContext = function() { return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_defaultUserContext(); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_defaultSucceededCallback = function(value) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.set_defaultSucceededCallback(value); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.get_defaultSucceededCallback = function() { return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_defaultSucceededCallback(); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_defaultFailedCallback = function(value) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.set_defaultFailedCallback(value); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.get_defaultFailedCallback = function() { return NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.get_defaultFailedCallback(); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.set_path("/Services/Suppliers/FlightTicketsService.asmx");
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetFlightTicketsUrl = function(children, departureIata, destinationIata, departureDay, departureMonthYear, returnDay, returnMonthYear, adults, from, to, date1, date2, onSuccess, onFailed, userContext) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.GetFlightTicketsUrl(children, departureIata, destinationIata, departureDay, departureMonthYear, returnDay, returnMonthYear, adults, from, to, date1, date2, onSuccess, onFailed, userContext); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetCarRentalUrl = function(pickupIata, pickUpDayDay, pickUpMonthYear, pickUpTime, dropOffIata, dropOffDay, dropOffMonthYear, dropOffTime, fromAirport, toAirport, date1, date2, onSuccess, onFailed, userContext) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.GetCarRentalUrl(pickupIata, pickUpDayDay, pickUpMonthYear, pickUpTime, dropOffIata, dropOffDay, dropOffMonthYear, dropOffTime, fromAirport, toAirport, date1, date2, onSuccess, onFailed, userContext); }
NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetDirectFlights = function(fromIataCode, countryId, onSuccess, onFailed, userContext) { NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService._staticInstance.GetDirectFlights(fromIataCode, countryId, onSuccess, onFailed, userContext); }

var SelectFlightTicketsArray = new Array();
var InputFlightTicketsArray = new Array();
var CalendarRowSeparators = new Array();
var SelectedDropDownId = null;
var SelectedDropDownValue = null;
var DirectFlightsCache = new Object();

function InitializeDropDownValues() {
	SelectedDropDownValue = new Array();
	for (var i = 0; i < SelectFlightTicketsArray.length; i++) {
		SelectedDropDownValue[i] = null;
	}
}

function RememberSelection(selectId) {
	if (SelectedDropDownValue == null) {
		InitializeDropDownValues();
	}
	var lContainer = document.getElementById(selectId);
	if (lContainer != null) {
		SelectedDropDownId = selectId;
		var index = GetIndexOfSelect(selectId);
		if (SelectedDropDownValue[index] == null || SelectedDropDownValue[index] == '') {
			SelectedDropDownValue[index] = lContainer.options[1].value;
		}
	}
}

function SetRememberSelections() {
	var index = GetIndexOfSelect(SelectedDropDownId);
	if (SelectedDropDownId != null && SelectedDropDownValue[index] != null) {
		var lSelectElement = document.getElementById(SelectedDropDownId);
		if (lSelectElement.selectedIndex == 0) {
			lSelectElement.value = SelectedDropDownValue[index];
		}
	}
}

function GetIndexOfSelect(selectId) {
	for (var i = 0; i < SelectFlightTicketsArray.length; i++) {
		if (SelectFlightTicketsArray[i] == selectId) {
			return i;
		}
	}
}

var PreviousRowSepHeight = new Array();
function VerifyDestAirport(selectElem, txtBoxId, errId, popUpContainer, closeText, popUpUrl, selectId, calendarRowSep) {
	var lTxtAirOther = document.getElementById(txtBoxId);
	if (selectElem.selectedIndex == 0) {
		CreateFlightTicketsOverlayPopUpWindow(popUpContainer, closeText, popUpUrl, selectId);
	}
	else {
		if (SelectedDropDownValue == null) {
			InitializeDropDownValues();
		}
		if (selectElem.value != '') {
			SelectedDropDownValue[GetIndexOfSelect(selectId)] = selectElem.value;
		}
	}
	if (selectElem.options[selectElem.selectedIndex].value == '') {
		lTxtAirOther.style.display = 'block';
		if (calendarRowSep && calendarRowSep.length > 0) {
			var lSepObj = document.getElementById(CalendarRowSeparators[calendarRowSep][0]);
			if (lSepObj) {
				PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][0]] = lSepObj.clientHeight;
				lSepObj.style.height = (lSepObj.clientHeight + lTxtAirOther.clientHeight + 5) + 'px';
				if (CalendarRowSeparators[calendarRowSep][1] != '') {
					var lSubmitButtonSep = document.getElementById(CalendarRowSeparators[calendarRowSep][1]);
					if (lSubmitButtonSep && lSubmitButtonSep.clientHeight > 0) {
						PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][1]] = lSubmitButtonSep.clientHeight;
						lSubmitButtonSep.style.height = (lSubmitButtonSep.clientHeight + lTxtAirOther.clientHeight + 5) + 'px';
					}
				}
			}
		}
	}
	else {
		if (calendarRowSep && calendarRowSep.length > 0) {
			var lSepObj = document.getElementById(CalendarRowSeparators[calendarRowSep][0]);
			if (lSepObj && PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][0]]) {
				lSepObj.style.height = PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][0]] + 'px';
			}
			if (CalendarRowSeparators[calendarRowSep][1] != '') {
				var lSubmitButtonSep = document.getElementById(CalendarRowSeparators[calendarRowSep][1]);
				if (lSubmitButtonSep && lSubmitButtonSep.clientHeight > 0 && PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][1]]) {
					lSubmitButtonSep.style.height = PreviousRowSepHeight[CalendarRowSeparators[calendarRowSep][1]] + 'px';
				}
			}
		}
		lTxtAirOther.style.display = 'none';
		document.getElementById(errId).style.display = 'none';
	}
}

var CountryId;
var PopulateSelectId;
var PopulateSelectIdSupp;
var UniqueKey;
var UniqueKeySupp;
var AllGroup = new Array();
var OptionsObject = new Array();
var DirectFlights = new Array();
var SelectedValue = null;
var Options = null;
var CurrentKey;

function AddDirectFlights(selectElem, countryId, populateSelectId, uniqueKey, directFlightsEnabled) {
	CountryId = countryId;

	SelectedValue = document.getElementById(populateSelectId).value;
	if (uniqueKey.indexOf("_supp") > 0) {
		UniqueKeySupp = uniqueKey;
		PopulateSelectIdSupp = populateSelectId;
	}
	else {
		UniqueKey = uniqueKey;
		PopulateSelectId = populateSelectId;
	}
	if (typeof (AllGroup[uniqueKey]) == "undefined" || AllGroup[uniqueKey] == null) {
		AllGroup[uniqueKey] = $("#allOptionGroup_" + uniqueKey).clone();
		$("#allOptionGroup_" + uniqueKey).remove();
	}

	if (Options == null) {
		Options = $("#" + populateSelectId + " option").clone();
	}

	if (typeof (OptionsObject[uniqueKey]) == "undefined" || OptionsObject[uniqueKey] == null) {
		OptionsObject[uniqueKey] = $("#" + populateSelectId + " option:not(optgroup > *):not([value='map']):not([value=''])").clone();
		$("#" + populateSelectId + " option:not(optgroup > *):not([value='map']):not([value=''])").remove();
	}

	if (typeof (DirectFlights[uniqueKey]) == "undefined" || DirectFlights[uniqueKey] == null) {
		DirectFlights[uniqueKey] = $("#directOpt_" + uniqueKey).clone();
		$("#directOpt_" + uniqueKey).remove();
	}

	if (directFlightsEnabled != "True") {
		if (uniqueKey.indexOf("_supp") > 0) {
			OnDirectFlightsAvailableSupp(null);
			return;
		}
		OnDirectFlightsAvailable(null);
		return;
	}
	CurrentKey = selectElem.value;
	var lAirports = CheckLocalVariableDirectFlights(selectElem.value);
	if (uniqueKey.indexOf("_supp") > 0) {
		if (lAirports != null) {
			OnDirectFlightsAvailableSupp(lAirports);
			return;
		}
		NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetDirectFlights(selectElem.value, countryId, OnDirectFlightsAvailableSupp, null, null);
		return;
	}
	
	if (lAirports != null) {
		OnDirectFlightsAvailable(lAirports);
		return;
	}
	
	NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetDirectFlights(selectElem.value, countryId, OnDirectFlightsAvailable, null, null);
}

function CheckLocalVariableDirectFlights(selectedValue){
	var lAirports = DirectFlightsCache[selectedValue];
	if (typeof(lAirports) != 'undefined' && lAirports != null){
		return lAirports;
	}
	return null;
}

function OnDirectFlightsAvailableSupp(result) {
	DirectFlightsCache[CurrentKey] = result;
	HandleResults(result, UniqueKeySupp, PopulateSelectIdSupp);
}

function OnDirectFlightsAvailable(result) {
	DirectFlightsCache[CurrentKey] = result;
	HandleResults(result, UniqueKey, PopulateSelectId);
}

function HandleResults(result, uniqueKey, populateSelectId) {
	if (result != null && result.length > 0) {
		var lOptGroup = "";
		for (var i = 0; i < result.length; i++) {
			var lAirportName = GetValueForId(Options, result[i]);
			if (typeof (lAirportName) != "undefined") {
				lOptGroup += "<option value=\"" + result[i] + "\" airportname=\"" + lAirportName.attributes["airportname"].value + "\">"
					+ lAirportName.text + "</option>";
			}
		}

		if (lOptGroup != "") {
			$("#" + populateSelectId + " option[value='map']").after($(DirectFlights[uniqueKey]));
			$("#directOpt_" + uniqueKey).html($(lOptGroup));
			HandleGrouping(true, uniqueKey, populateSelectId);
		}
		else {
			$("#directOpt_" + uniqueKey).remove();
			HandleGrouping(false, uniqueKey, populateSelectId);
		}
	}
	else {
		$("#directOpt_" + uniqueKey).remove();
		HandleGrouping(false, uniqueKey, populateSelectId);
	}
	$("#" + populateSelectId).val(SelectedValue);
}

function HandleGrouping(status, uniqueKey, populateSelectId) {
	if (status) {
		$("#directOpt_" + uniqueKey).after($(AllGroup[uniqueKey]));
	}
	else {
		var lToRemove = $("#allOptionGroup_" + uniqueKey);
		if (lToRemove.length != 0) {
			lToRemove.remove();
		}
	}

	if (status) {
		//We make sure the operation won't be too heavy (for IE especially) - this should be made for destination and accommodation level where 
		//no more than 5 airports aree grouped in no more than 3 groups + the other and the map option - no more than 20 options
		if ($("#" + populateSelectId + " option").length < 20) {
			var lToRemove = $("#" + populateSelectId + " option:not(optgroup > *):not([value='map']):not([value=''])");
			if (lToRemove.length != 0) {
				lToRemove.remove();
			}
		}
	}
	else {
		$("#" + populateSelectId + " option[value='map']").after($(OptionsObject[uniqueKey]));

	}
}

function GetValueForId(options, value) {
	for (var i = 0; i < options.length; i++) {
		if (options[i].value == value) {
			return options[i];
		}
	}
}

function SelectAirportFromIframe(selectId, value, valueName) {
	var lSelectElement = document.getElementById(selectId);
	var lExistsOption = false;
	for (var i = 0; i < lSelectElement.options.length; i++) {
		if (lSelectElement.options[i].value == value) {
			lExistsOption = true;
			break;
		}
	}
	var lCount = -1;
	for (var j = 0; j < SelectFlightTicketsArray.length; j++) {
		if (SelectFlightTicketsArray[j] == selectId) {
			lCount = j;
			break;
		}
	}

	if (lExistsOption) {
		lSelectElement.value = value;
		SelectedDropDownValue[GetIndexOfSelect(selectId)] = value;
		if (lCount >= 0) {
			var lInputText = document.getElementById(InputFlightTicketsArray[lCount]);
			if (lInputText != null) {
				lInputText.style.display = "none";
			}
		}
	}
	else {

		if (lCount >= 0) {
			var lInputText = document.getElementById(InputFlightTicketsArray[lCount]);
			if (lInputText != null) {
				lSelectElement.value = "";
				lInputText.style.display = "block";
				lInputText.value = valueName;
			}
		}
	}
}

function ChangeDestinationSelect(uniqueKeyword) {
	var lDepAirport = document.getElementById(("selCarsFrom_" + uniqueKeyword)).value;
	if (lDepAirport != '' && lDepAirport != 'map') {
		var lDestinationAirport = document.getElementById(("selCarsTo_" + uniqueKeyword));
		lDestinationAirport.value = lDepAirport;
	}
}

function ValidateFlightTicketAndCarData(startIdFrom, startIdTo, uniqueKeyword, select1, select2) {
	var lErrorMessageFrom = document.getElementById(("errorFrom_" + uniqueKeyword));
	var lErrorMessageTo = document.getElementById(("errorTo_" + uniqueKeyword));
	lErrorMessageFrom.style.display = "none";
	lErrorMessageTo.style.display = "none";
	var lReturn = true;

	//Verify that the value of the airport departure is not the map option
	if (select1 != null && select1.value == 'map') {
		lErrorMessageFrom.style.display = "block";
		lReturn = false;
	}

	var lInputText = document.getElementById((startIdFrom + uniqueKeyword));
	if (lInputText.style.display == "block") {
		if (lInputText.value == '') {
			lErrorMessageFrom.style.display = "block";
			lReturn = false;
		}
	}

	//Verify that the value of the airport destination is not the map option
	if (select2 != null && select2.value == 'map') {
		lErrorMessageTo.style.display = "block";
		lReturn = false;
	}

	var lInputTextTo = document.getElementById((startIdTo + uniqueKeyword));
	if (lInputTextTo.style.display == "block") {
		if (lInputTextTo.value == '') {
			lErrorMessageTo.style.display = "block";
			lReturn = false;
		}
	}
	var lDate = ValidateDateFlight(uniqueKeyword);
	lReturn = lReturn && lDate;

	return lReturn;
}

function ValidateDateFlight(uniqueKeyword) {
	var currentDate = new Date();
	currentDate.setDate(currentDate.getDate() + 1);
	var lDepDay = document.getElementById(("depDayFlight_" + uniqueKeyword));
	var lDepMonth = document.getElementById(("depMonthFlight_" + uniqueKeyword));
	var lRetDay = document.getElementById(("retDayFlight_" + uniqueKeyword));
	var lRetMonth = document.getElementById(("retMonthFlight_" + uniqueKeyword));
	var lDepYear = lDepMonth.value.substr(0, 4);
	var lDepMonthValue = lDepMonth.value.substr(4, 2);
	var lRetYear = lRetMonth.value.substr(0, 4);
	var lRetMonthValue = lRetMonth.value.substr(4, 2);

	var lDepDate = new Date();
	lDepDate.setFullYear(lDepYear, trimDateFlight(lDepMonthValue) - 1, lDepDay.value);

	var lRetDate = new Date();
	lRetDate.setFullYear(lRetYear, trimDateFlight(lRetMonthValue) - 1, lRetDay.value);

	var lErrorMessage = document.getElementById(("dateError_" + uniqueKeyword));
	lErrorMessage.style.display = "none";
	var lErrorMessage2 = document.getElementById(("errorInvalidDates_" + uniqueKeyword));
	lErrorMessage2.style.display = "none";
	var lErrorMessage3 = document.getElementById(("errorInvalidPastDates_" + uniqueKeyword));
	lErrorMessage3.style.display = "none";

	if ((lDepDate.getMonth() != trimDateFlight(lDepMonthValue) - 1) || (lRetDate.getMonth() != trimDateFlight(lRetMonthValue) - 1)) {
		lErrorMessage2.style.display = "block";
		return false;
	}

	if (lRetDate < lDepDate) {
		lErrorMessage.style.display = "block";
		return false;
	}

	///If current selected dates are in the past, display error message
	///Current date won't be a valid date
	if (lRetDate < currentDate || lDepDate < currentDate) {
		lErrorMessage3.style.display = "block";
		return false;
	}

	return true;
}

function trimDateFlight(month) {
	if (month[0] == '0') {
		return month[1];
	}
	return month;
}

function InitCarouselFlights(uniqueKeyword) {
	var lDestinationAirportSelect = document.getElementById("selFlightsTo_" + uniqueKeyword);
	if (lDestinationAirportSelect) {
		var lDestinationAirportTxt = document.getElementById("txtFlightTo_" + uniqueKeyword);
		if (lDestinationAirportTxt) {
			if ((lDestinationAirportSelect.options.length <= 0) || (lDestinationAirportSelect.options.length == 1 && lDestinationAirportSelect.options[0].value.length == 0)) {
				lDestinationAirportSelect.style.display = "none";
				lDestinationAirportTxt.style.display = "block";
			}
		}
	}
}

var lFlightWin;
var lCarWin;
function flightRedirect(uniqueKeyword) {
	if (!ValidateFlightTicketAndCarData("txtFlightFrom_", "txtFlightTo_", uniqueKeyword,
		document.getElementById(("selFlightsFrom_" + uniqueKeyword)), document.getElementById(("selFlightsTo_" + uniqueKeyword)))) {
		return;
	}
	var lChildren = document.getElementById(("selbOfChildren_" + uniqueKeyword)) ? document.getElementById(("selbOfChildren_" + uniqueKeyword)).value : 0;
	var lAdults = document.getElementById(("selNbOfAdults_" + uniqueKeyword)) ? document.getElementById(("selNbOfAdults_" + uniqueKeyword)).value : 1;
	var lAirport;
	var lDepatureAirport;
	var lInputText = document.getElementById(("txtFlightTo_" + uniqueKeyword));
	var lDepatureAirportInput = document.getElementById(("txtFlightFrom_" + uniqueKeyword));
	var lDepartureAirportName;
	var lDestinationAirportName;
	if (lDepatureAirportInput.style.display == 'block') {
		lDepatureAirport = lDepatureAirportInput.value;
		lDepartureAirportName = lDepatureAirportInput.value;
	}
	else {
		var lCurrentSelect = document.getElementById(("selFlightsFrom_" + uniqueKeyword));
		lDepatureAirport = lCurrentSelect.value;
		lDepartureAirportName = lCurrentSelect.options[lCurrentSelect.selectedIndex].attributes["airportname"].value;
	}
	if (lInputText.style.display == 'block') {
		lAirport = lInputText.value;
		lDestinationAirportName = lInputText.value;
	}
	else {
		var lCurrentSelectTo = document.getElementById(("selFlightsTo_" + uniqueKeyword));
		lAirport = lCurrentSelectTo.value;
		lDestinationAirportName = lCurrentSelectTo.options[lCurrentSelectTo.selectedIndex].attributes["airportname"].value;
	}
	var lDepartureDay = document.getElementById(("depDayFlight_" + uniqueKeyword)).value;
	var lDepartureYearMonth = document.getElementById(("depMonthFlight_" + uniqueKeyword)).value;
	var lReturnDay = document.getElementById(("retDayFlight_" + uniqueKeyword)).value;
	var lReturnYearMonth = document.getElementById(("retMonthFlight_" + uniqueKeyword)).value;
	var lLink;

	NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetFlightTicketsUrl(lChildren, lDepatureAirport, lAirport, lDepartureDay,
		lDepartureYearMonth, lReturnDay, lReturnYearMonth, lAdults, EscapeSequence(lDepartureAirportName), EscapeSequence(lDestinationAirportName),
		GetDateForQueryString(lDepartureDay, lDepartureYearMonth), GetDateForQueryString(lReturnDay, lReturnYearMonth), OnFlightLinkAvailable,
		OnTimeOut, null);
	lFlightWin = window.open("");
	lFlightWin.opener = this;
	lFlightWin.focus();
}

function OnFlightLinkAvailable(result) {
	lFlightWin.location.href = result;
}

function OnCarLinkAvailable(result) {
	lCarWin.location.href = result;
}

function OnTimeOut() {

}

function EscapeSequence(value) {
	return encodeURIComponent(value); //.replace(' ', '%2B');
}

function GetDateForQueryString(day, yearMonth) {
	return day + EscapeSequence(' ') + monthNames[trimDateFlight(yearMonth.substr(4, 2)) - 1] + EscapeSequence(' ') + yearMonth.substr(0, 4);
}

function InitCarouselCars(uniqueKeyword) {
	var lDepartureAirportSelect = document.getElementById("selCarsFrom_" + uniqueKeyword);
	var lDestinationAirportSelect = document.getElementById("selCarsTo_" + uniqueKeyword);
	if (lDestinationAirportSelect && lDepartureAirportSelect) {
		var lDepartureAirportTxt = document.getElementById("txtCarFrom_" + uniqueKeyword);
		var lDestinationAirportTxt = document.getElementById("txtCarTo_" + uniqueKeyword);
		if (lDestinationAirportTxt && lDepartureAirportSelect) {
			if ((lDestinationAirportSelect.options.length <= 0) || (lDestinationAirportSelect.options.length == 1 && lDestinationAirportSelect.options[0].value.length == 0)) {
				lDestinationAirportSelect.style.display = "none";
				lDestinationAirportTxt.style.display = "block";
				lDepartureAirportSelect.style.display = "none";
				lDepartureAirportTxt.style.display = "block";
			}
		}
	}
}

function carRedirect(uniqueKeyword) {
	if (!ValidateFlightTicketAndCarData("txtCarFrom_", "txtCarTo_", uniqueKeyword, document.getElementById(("selCarsFrom_" + uniqueKeyword)),
		document.getElementById(("selCarsTo_" + uniqueKeyword)))) {
		return;
	}
	var lAirport;
	var lDepatureAirport;
	var lDepartureAirportName;
	var lDestinationAirportName;
	var lInputText = document.getElementById(("txtCarTo_" + uniqueKeyword));
	var lInputFrom = document.getElementById(("txtCarFrom_" + uniqueKeyword));
	if (lInputFrom.style.display == "block") {
		lDepatureAirport = lInputFrom.value;
		lDepartureAirportName = lInputFrom.value;
	}
	else {
		var lCurrentSelect = document.getElementById(("selCarsFrom_" + uniqueKeyword));
		lDepatureAirport = lCurrentSelect.value;
		lDepartureAirportName = lCurrentSelect.options[lCurrentSelect.selectedIndex].attributes["airportname"].value;
	}

	if (lInputText.style.display == 'block') {
		lAirport = lInputText.value;
		lDestinationAirportName = lInputText.value;
	}
	else {
		var lCurrentSelectTo = document.getElementById(("selCarsTo_" + uniqueKeyword));
		lAirport = lCurrentSelectTo.value;
		lDestinationAirportName = lCurrentSelectTo.options[lCurrentSelectTo.selectedIndex].attributes["airportname"].value;
	}
	var lDepartureDay = document.getElementById(("depDayFlight_" + uniqueKeyword)).value;
	var lDepartureYearMonth = document.getElementById(("depMonthFlight_" + uniqueKeyword)).value;
	var lReturnDay = document.getElementById(("retDayFlight_" + uniqueKeyword)).value;
	var lReturnYearMonth = document.getElementById(("retMonthFlight_" + uniqueKeyword)).value;
	var lLink;
	var lPickUpTime = document.getElementById(("depTimeFlight_" + uniqueKeyword)) ? document.getElementById(("depTimeFlight_" + uniqueKeyword)).value : "12:00";
	var lDropOffTime = document.getElementById(("retTimeFlight_" + uniqueKeyword)) ? document.getElementById(("retTimeFlight_" + uniqueKeyword)).value : "12:00";
	NetMatch.Zoover.Web.Services.Suppliers.FlightTicketsService.GetCarRentalUrl(lDepatureAirport, lDepartureDay, lDepartureYearMonth, EscapeSequence(lPickUpTime),
		lAirport, lReturnDay, lReturnYearMonth, EscapeSequence(lDropOffTime), EscapeSequence(lDepartureAirportName), EscapeSequence(lDestinationAirportName),
		EscapeSequence(GetDateForQueryString(lDepartureDay, lDepartureYearMonth)), EscapeSequence(GetDateForQueryString(lReturnDay, lReturnYearMonth)), OnCarLinkAvailable, OnTimeOut, null);
	lCarWin = window.open("");
	lCarWin.opener = this;
	lCarWin.focus();
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();