var POSITIVE_INFINITY = Math.pow(2, 32);
var MAX_CITY_PAIRS = 1;
var MAX_DEPARTURES = 2;
var MULTI_DESTINATION = false;
var FLIGHT_PAGE = false;
var MAX_FLIGHT_SELECTION_MONTH = 12;

function WDSWaitingImage () {
this.IMG_ID = "moveimageID";
this.DIV_ID = "inpageFlightsWaitPage";
this.pleaseWait      = WDSWaitingImage_pleaseWait;
}
var WDSWaitingImage = new WDSWaitingImage();

function WDSWaitingImage_pleaseWait (waitingImg) {
var waitingImageDiv = document.getElementById(WDSWaitingImage.DIV_ID);
var container = document.getElementById("inpageSearchPage");
var wiSrc = "/shared/images/common/";
wiSrc += waitingImg + ".gif";

if (document.getElementById(WDSWaitingImage.IMG_ID)) {
document.getElementById(WDSWaitingImage.IMG_ID).src = wiSrc;
} else {
WDSTrace.dump("WDSWaitingImage_pleaseWait : element id = WDSWaitingImage.IMG_ID NOT FOUND and MANDATORY");
}

waitingImageDiv.style.display    = "block";
waitingImageDiv.style.visibility = "visible";
container.style.display   = "none";
self.scrollTo(0,0);

}

function getFieldInfo(name) {
	fieldInfo = new Array();

	underscoreIndex = name.indexOf("_");
	if (underscoreIndex > -1) {
		fieldInfo[0] = name.substring(0, underscoreIndex);
		fieldInfo[1] = name.substring(underscoreIndex + 1);
	}

	return fieldInfo;
}

function popSelectionData(optName,value) {
	var i;
	for (i =0; i < optName.length; i++) {	   	      
		if (optName.options[i].value == value) {
			optName.selectedIndex = i;
			break;
		}
	} 
}

function checkCityCountry(city) {
	res = findMatch(city);
	if (matchAmbiArray) {
		return new Array("","","","");
	}
	if (res) {
		
		if (res[0]) {	  
			return new Array("","","","");
		} else {
			airportCode = res[1][0];
			for (i=0; i<Countries.length; i++) {
				if (airportCode.toUpperCase() == Countries[i][0].toUpperCase()) {
					return Countries[i];
				}
			}
			return new Array("","","","");
		}
	}
}

function checkFlightSegmentType(depCity, arrCity) {
	var depAirportCountryCity = checkCityCountry(depCity);
	var arrAirportCountryCity = checkCityCountry(arrCity);
	return checkforIntnl(depAirportCountryCity[1],arrAirportCountryCity[1]);
}

function checkforIntnl(depCountry, arrCountry) {
	if (depCountry == "" || arrCountry == "")
		return "";
	else if (depCountry == "CA" && arrCountry == "CA")
		return "Domestic";
	else if ((depCountry == "CA" && arrCountry == "US") || (depCountry == "US" && arrCountry == "CA") || (depCountry == "US" && arrCountry == "US"))
		return "Transborder";
	else
		return "International";
} 

function checkforFareDriven(depCity, arrCity) {
	var depAirportCountryCity = checkCityCountry(depCity);
	var arrAirportCountryCity = checkCityCountry(arrCity);
	var aFlightType = checkforIntnl(depAirportCountryCity[1],arrAirportCountryCity[1]);
	if (aFlightType == "Domestic" || aFlightType == "Transborder")
		return depAirportCountryCity[3] && arrAirportCountryCity[3];
	else
		return true;
}

function execShowWarning() {
	return document.getElementById("ip-depdate2") && document.getElementById("ip-depdate1within") && document.getElementById("ip-depdate2within") && document.getElementById("ip-passenger") && document.getElementById("ip-infants") && document.getElementById("ip-residence");
}

function showWarning(formSubmit) {
  	var checkNeeded = MULTI_DESTINATION || (document.flights.tripType[0] && document.flights.tripType[0].checked);
	var inpageErrorFlag = false;
	var anyNewError = false;
	var i;
	var within;

	if (!isWithin353Days(document.flights.departMonthYear1,document.flights.departDay1)) {
		if (!(document.getElementById("ip-depdate1within").style.display == 'block' && document.getElementById("DepartError1").style.display == 'block')) {
			document.getElementById("ip-depdate1within").style.display='block';
			document.getElementById("DepartError1").style.display='block';
			anyNewError = true;
		}
		inpageErrorFlag = true;
	} else {
		document.getElementById("ip-depdate1within").style.display='none';	
		document.getElementById("DepartError1").style.display='none';
	}

	if ( checkNeeded ) { 
		for (i = MAX_DEPARTURES; i > 1; i--) {
			if (!MULTI_DESTINATION || (eval("document.flights.org" + i + ".value") != "" || eval("document.flights.dest" + i + ".value") != "")) {
				tmpFlag = false;
				for (j=i-1; j >= 1; j--) {
					if ( getDateNumber(j) > getDateNumber(i) ) {
						if (!(document.getElementById("ip-depdate"+i).style.display == 'block' && document.getElementById("DepartError"+i).style.display == 'block')) {
							document.getElementById("ip-depdate"+i).style.display='block';
							document.getElementById("DepartError"+i).style.display='block';
							anyNewError = true;
						}
						tmpFlag = true;
						inpageErrorFlag = true;
						break;
					} else if ( getDateNumber(j) == getDateNumber(i) ) {
						departTimeOfModifiedFlight = eval("document.flights.departTime" + i + ";");
						departTimeOfPreviousFlight = eval("document.flights.departTime" + (j) + ";");
						if (departTimeOfPreviousFlight.options[departTimeOfPreviousFlight.selectedIndex].value > departTimeOfModifiedFlight.options[departTimeOfModifiedFlight.selectedIndex].value) {
							if (!(document.getElementById("ip-depdate"+i).style.display == 'block' && document.getElementById("DepartError"+i).style.display == 'block')) {
								document.getElementById("ip-depdate"+i).style.display='block';
								document.getElementById("DepartError"+i).style.display='block';
								anyNewError = true;
							}
							tmpFlag = true;
							inpageErrorFlag = true;
							break;
						}
					}
				}
				within = eval("isWithin353Days(document.flights.departMonthYear" + i + ",document.flights.departDay" + i + ")");
				if (!within) {
					if (!(document.getElementById("ip-depdate"+i+"within").style.display == 'block' && document.getElementById("DepartError"+i).style.display == 'block')) {
						document.getElementById("ip-depdate"+i+"within").style.display='block';		
						document.getElementById("DepartError"+i).style.display='block';
						anyNewError = true;
					}
					inpageErrorFlag = true;
				} else {
					document.getElementById("ip-depdate"+i+"within").style.display='none';	
				}
				if (!tmpFlag) {
					document.getElementById("ip-depdate"+i).style.display='none';
					if (within)
						document.getElementById("DepartError"+i).style.display='none';
				}
			}
		}
	}
	
  	if ( (Number(document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value) + Number(document.flights.numberOfChildren.options[document.flights.numberOfChildren.selectedIndex].value)) > 9 ) {
		if (!(document.getElementById("ip-passenger").style.display == 'block' && document.getElementById("AdultError").style.display == 'block' && document.getElementById("ChildError").style.display == 'block')) {
		 	document.getElementById("ip-passenger").style.display='block';
			document.getElementById("AdultError").style.display='block';
			document.getElementById("ChildError").style.display='block';
			anyNewError = true;
		}
	 	document.flights.numberOfChildren.selectedIndex = 9 - document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value;
	 	inpageErrorFlag = true;
    } else {
		document.getElementById("ip-passenger").style.display='none';
		document.getElementById("AdultError").style.display='none';
		document.getElementById("ChildError").style.display='none';
	} 
	
	if (document.getElementById("Infant").style.display != 'none' && Number(document.flights.numberOfInfants.options[document.flights.numberOfInfants.selectedIndex].value) > Number(document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value)) {			
		if (!(document.getElementById("ip-infants").style.display == 'block' && document.getElementById("InfantError").style.display == 'block')) {
			document.getElementById("ip-infants").style.display='block';
			document.getElementById("InfantError").style.display='block';
			anyNewError = true;
		}
		document.flights.numberOfInfants.selectedIndex = document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value;
		inpageErrorFlag = true;
	} else {
		document.getElementById("ip-infants").style.display='none';
		document.getElementById("InfantError").style.display='none';
	}
	
	if ((formSubmit || (document.getElementById("ip-residence").style.display == 'block' && document.getElementById("residenceError").style.display == 'block')) && document.getElementById("ResidenceBar").style.display != 'none' && document.flights.countryOfResidence.selectedIndex == 0){
		if (!(document.getElementById("ip-residence").style.display == 'block' && document.getElementById("residenceError").style.display == 'block')) {
			document.getElementById("ip-residence").style.display='block';
			document.getElementById("residenceError").style.display='block';
			anyNewError = true;
		}
		inpageErrorFlag = true;
	} else {
		document.getElementById("ip-residence").style.display='none';
		document.getElementById("residenceError").style.display='none';
	}

	if (inpageErrorFlag && anyNewError) {
		document.getElementById("inpage").style.display='block';
		document.getElementById("inpageUser").style.display='block';
		window.scroll(1,1);
	} else if (!inpageErrorFlag) {
		document.getElementById("inpage").style.display='none';
		document.getElementById("inpageUser").style.display='none';
	}
	
	return inpageErrorFlag;
}

function showAndHide(formSubmit,fromFacade) {
	var hasDomestic = false;
	var hasTransborder = false;
	var hasInternational = false;
	var allFaredriven = true;
	var i;
	var tempFlightType;
	for (i = 1; i <= MAX_CITY_PAIRS; i++) {
		depCity = eval("document.flights.org" + i + ".value");
		arrCity = eval("document.flights.dest" + i + ".value");
		
		if (depCity != "" && arrCity != "") {
			tempFlightType = checkFlightSegmentType(depCity, arrCity);
			if (tempFlightType == "Domestic")
				hasDomestic = true;
			else if (tempFlightType == "Transborder")
				hasTransborder = true;
			else if (tempFlightType == "International")
				hasInternational = true;
			if (!checkforFareDriven(depCity, arrCity))
				allFaredriven = false;
			
		document.getElementById('FlightType').value = tempFlightType;
				
		checkFlightType(hasDomestic,hasTransborder,hasInternational,allFaredriven);
		if (!fromFacade && execShowWarning())
		showWarning(formSubmit);
		
		}
		
	}
	
	
}

function checkFlightType(domestic,transborder,international,faredriven) {
	if (document.flights.fromHomePage != null){
		if(international){
			document.getElementById('InfantText').style.display='block';
			document.getElementById('SeniorText').style.display='none';
		}else{
			document.getElementById('InfantText').style.display='none';
			document.getElementById('SeniorText').style.display='block';
		}
	}
	
	if (!MULTI_DESTINATION && (international || !faredriven)) {
		document.getElementById('Shop').style.display='block';
	} else {
		document.getElementById('Shop').style.display='none';
	}
	if (international) {
		document.getElementById('Infant').style.display='none';
	} else {
		document.getElementById('Infant').style.display='block';
	}
	if (international || !faredriven) {
	   	if ((!MULTI_DESTINATION && document.flights.searchType[1].checked) || (MULTI_DESTINATION && international))
			document.getElementById('Flexible').style.display='none';
		else
			document.getElementById('Flexible').style.display='block';
	} else {
		document.getElementById('Flexible').style.display='none';
	}
	if (!MULTI_DESTINATION && ((international || !faredriven) && document.flights.searchType[0].checked)) {
		document.getElementById('Class').style.display='none';
	} else {
		document.getElementById('Class').style.display='block';
	}
	if (transborder) {
	} else {
	}
	if (transborder && !(document.flightsPlanitgo.PRIVATE_LABEL.value != "AGENT" && getCookie("AC-Signon-Cookie") && getCookie("AC-Session-Cookie"))) {
		document.getElementById('ResidenceBar').style.display='block';
	} else {
		document.getElementById('ResidenceBar').style.display='none';
	}
	
	if (document.getElementById('Direct')) {
		var aBookingFlowVal = checkBookingFlow();
		if (aBookingFlowVal.indexOf("SCHEDULE") != -1 || aBookingFlowVal == "COMPLEX" || aBookingFlowVal == "AGENT_COMPLEX") {
			document.getElementById('Direct').style.display='block';
		} else
			document.getElementById('Direct').style.display='none';
	}
}

function checkBookingFlow() {
	var hasDomestic = false;
	var hasTransborder = false;
	var hasInternational = false;
	var allFaredriven = true;
	var i;
	var tempFlightType;
	for (i = 1; i <= MAX_CITY_PAIRS; i++) {
		depCity = eval("document.flights.org" + i + ".value");
		arrCity = eval("document.flights.dest" + i + ".value");	
		if (depCity != "" && arrCity != "") {
			tempFlightType = checkFlightSegmentType(depCity, arrCity);
			if (tempFlightType == "Domestic")
				hasDomestic = true;
			else if (tempFlightType == "Transborder")
				hasTransborder = true;
			else if (tempFlightType == "International")
				hasInternational = true;
			if ((tempFlightType == "Domestic" || tempFlightType == "Transborder") && !checkforFareDriven(depCity, arrCity))
				allFaredriven = false;
		}
	}
	if (!MULTI_DESTINATION) {
		if ((hasDomestic || hasTransborder) && allFaredriven) {
			if (document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT")
				return "AGENT_DOMTRANSB";
			else
				return "DOMTRANSB";
		} else if ((hasDomestic || hasTransborder) || hasInternational) {
			if (document.flights.searchType[0].checked) {
				if (document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT")
					return "AGENT_INTERNATIONAL";
				else
					return "INTERNATIONAL";
			} else {
				if (document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT")
					return "AGENT_SCHEDULE";
				else
					return "SCHEDULE";
			}
		}
	} else if (hasInternational || !allFaredriven) {
		if (document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT")
			return "AGENT_COMPLEX";
		else
			return "COMPLEX";
	} else {
		if (document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT")
			return "AGENT_COMPLEX_DOMTRANSB";
		else
			return "COMPLEX_DOMTRANSB";
	}
	return "";
}

function checkEmbeddedTransaction(bookingFlow) {
	if (bookingFlow.indexOf("COMPLEX_DOMTRANSB") != -1) {
		return "FlexPricerComplexItineraryAvailabilityServlet";
	} else if (bookingFlow.indexOf("DOMTRANSB") != -1 || bookingFlow.indexOf("INTERNATIONAL") != -1) {
		return "FlexPricerAvailabilityServlet";
	} else if (bookingFlow.indexOf("SCHEDULE") != -1) {
		return "AirAvailabilityServlet";
	} else {
		return "AirComplexAvailabilityServlet";
	}
}

function setFormFields() {
	var aBookingFlowVal = checkBookingFlow();
	document.flightsPlanitgo.BOOKING_FLOW.value = aBookingFlowVal;
	if (aBookingFlowVal.indexOf("DOMTRANSB") != -1) {
		if (document.flights.classType.selectedIndex <= 1) {
			document.flightsPlanitgo.COMMERCIAL_FARE_FAMILY_1.value = "YOUNGFUNUS";
			document.flightsPlanitgo.COMMERCIAL_FARE_FAMILY_2.value = "EXCLUSIVE";
		} else{
			document.flightsPlanitgo.COMMERCIAL_FARE_FAMILY_1.value = "EXCLUSIVE";
			document.flightsPlanitgo.COMMERCIAL_FARE_FAMILY_2.value = "";
		}
		document.flightsPlanitgo.PRICING_TYPE.value = "C";
		document.flightsPlanitgo.DISPLAY_TYPE.value = "2";
		document.flightsPlanitgo.CORPORATE_NUMBER_1.value = "URIGET";
		document.flightsPlanitgo.CORPORATE_NUMBER_2.value = "BHVQLN";
		document.flightsPlanitgo.TYPE_OF_CORPORATE_FARE.value = "2";
		if (!MULTI_DESTINATION) {
			document.flightsPlanitgo.DATE_RANGE_QUALIFIER_1.value = "C";
			document.flightsPlanitgo.DATE_RANGE_VALUE_1.value = "3";
			if (document.flights.tripType[0].checked) {
				document.flightsPlanitgo.DATE_RANGE_QUALIFIER_2.value = "C";
				document.flightsPlanitgo.DATE_RANGE_VALUE_2.value = "3";
			}
		} else {
			for (i=1; i<=MAX_CITY_PAIRS; i++) {
				if (eval("document.flights.origin" + i + ".value") != "" && eval("document.flights.destination" + i + ".value") != "") {
					eval("document.flightsPlanitgo.DATE_RANGE_QUALIFIER_" + i + ".value = \"C\";");
					eval("document.flightsPlanitgo.DATE_RANGE_VALUE_" + i + ".value = \"3\";");
					
				}
			}
		}
	} else if (aBookingFlowVal.indexOf("INTERNATIONAL") != -1) {
		document.flightsPlanitgo.COMMERCIAL_FARE_FAMILY_1.value = "WORLTRAVEL";
		document.flightsPlanitgo.PRICING_TYPE.value = "I";
		if (!document.flights.Flexible.checked) {
			document.flightsPlanitgo.DATE_RANGE_QUALIFIER_1.value = "C";
			document.flightsPlanitgo.DATE_RANGE_VALUE_1.value = "0";
			document.flightsPlanitgo.DATE_RANGE_VALUE_2.value = "0";
			if (document.flights.tripType[0].checked) {
				document.flightsPlanitgo.DISPLAY_TYPE.value = "1";
				document.flightsPlanitgo.DATE_RANGE_QUALIFIER_2.value = "C";
			} else {
				document.flightsPlanitgo.DISPLAY_TYPE.value = "2";
			}
		} else if (document.flights.tripType[1].checked) {
			document.flightsPlanitgo.DISPLAY_TYPE.value = "2";
			document.flightsPlanitgo.DATE_RANGE_QUALIFIER_1.value = "C";
			document.flightsPlanitgo.DATE_RANGE_VALUE_1.value = "3";
			document.flightsPlanitgo.DATE_RANGE_VALUE_2.value = "3";
		} else {
			document.flightsPlanitgo.DISPLAY_TYPE.value = "1";
			document.flightsPlanitgo.DATE_RANGE_QUALIFIER_1.value = "C";
			document.flightsPlanitgo.DATE_RANGE_VALUE_1.value = "3";
			document.flightsPlanitgo.DATE_RANGE_QUALIFIER_2.value = "C";
			document.flightsPlanitgo.DATE_RANGE_VALUE_2.value = "3";
		}
	}
	
	var country;
	if (document.flightsPlanitgo.PRIVATE_LABEL.value != "AGENT") {
		var signOnCookie = getCookie("AC-Signon-Cookie");
		var sessionCookie = getCookie("AC-Session-Cookie");
		if (signOnCookie && sessionCookie) {
			var signOnCookieValue = signOnCookie.split('^');
			var sessionCookieValue = sessionCookie.split('^');
			document.flightsPlanitgo.USERID.value = signOnCookieValue[0];
			document.flightsPlanitgo.TITLE.value = signOnCookieValue[1];
			document.flightsPlanitgo.LNAME.value = signOnCookieValue[4];
			document.flightsPlanitgo.MNAME.value = signOnCookieValue[3];
			document.flightsPlanitgo.FNAME.value = signOnCookieValue[2];
			document.flightsPlanitgo.FFMILES.value = signOnCookieValue[5];
			country = signOnCookieValue[6];
			document.flightsPlanitgo.EXTERNAL_ID.value = sessionCookieValue[0];
		} else {
			document.flightsPlanitgo.USERID.value = "GUEST";
			document.flightsPlanitgo.EXTERNAL_ID.value = "GUEST";
			
			if (document.getElementById("ResidenceBar").style.display != 'none') {
				country = document.flights.countryOfResidence.options[document.flights.countryOfResidence.selectedIndex].value;
			}
		}
	} else if (document.getElementById("ResidenceBar").style.display != 'none') {
		country = document.flights.countryOfResidence.options[document.flights.countryOfResidence.selectedIndex].value;
	}

	if (MULTI_DESTINATION)
		document.flightsPlanitgo.TRIP_TYPE.value = document.flights.tripType.value;
	
	else if (document.flights.tripType[0].checked)
		
		document.flightsPlanitgo.TRIP_TYPE.value = document.flights.tripType[0].value;
	else if (document.flights.tripType[1].checked)
		
		document.flightsPlanitgo.TRIP_TYPE.value = document.flights.tripType[1].value;
		
	for (i=1; i<=MAX_CITY_PAIRS; i++) {
		eval("document.flightsPlanitgo.B_LOCATION_" + i + ".value = document.flights.origin" + i + ".value;");
		eval("document.flightsPlanitgo.E_LOCATION_" + i + ".value = document.flights.destination" + i + ".value;");
	}
	if (aBookingFlowVal == "DOMTRANSB" || aBookingFlowVal == "AGENT_DOMTRANSB" || aBookingFlowVal.indexOf("INTERNATIONAL") != -1) {
		if (document.flights.tripType[0].checked) {
			document.flightsPlanitgo.B_LOCATION_2.value = document.flightsPlanitgo.E_LOCATION_1.value;
			document.flightsPlanitgo.E_LOCATION_2.value = document.flightsPlanitgo.B_LOCATION_1.value;
		}
	}
	var selectedTimeOption, submitfield;
	for (i=1; i<=MAX_DEPARTURES; i++) {
		if (!MULTI_DESTINATION)
			submitfield = true;
		else if (MULTI_DESTINATION && eval("document.flights.origin" + i + ".value") != "" && eval("document.flights.destination" + i + ".value") != "")
			submitfield = true;
		else
			submitfield = false;
		if (submitfield) {
			if (!MULTI_DESTINATION && i==2 && document.flights.tripType[1] && document.flights.tripType[1].checked) {
				eval("document.flightsPlanitgo.B_DATE_" + i + ".value = getDateNumber(1)+document.flights.departTime1.options[document.flights.departTime1.selectedIndex].value;");
				selectedTimeOption = eval("document.flights.departTime1.options[document.flights.departTime1.selectedIndex].value");
			} else {
				eval("document.flightsPlanitgo.B_DATE_" + i + ".value = getDateNumber(" + i + ")+document.flights.departTime" + i + ".options[document.flights.departTime" + i + ".selectedIndex].value;");
				selectedTimeOption = eval("document.flights.departTime" + i + ".options[document.flights.departTime" + i + ".selectedIndex].value");
			}
			if (selectedTimeOption == "0000")
				eval("document.flightsPlanitgo.B_ANY_TIME_" + i + ".value = \"TRUE\";");
			else
				eval("document.flightsPlanitgo.B_ANY_TIME_" + i + ".value = \"FALSE\";");
		} else {
			eval("document.flightsPlanitgo.B_DATE_" + i + ".value = \"\";");
			eval("document.flightsPlanitgo.B_ANY_TIME_" + i + ".value = \"\";");
		}
	}

	totadults = Number(document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value);
	totpassengers = Number(document.flights.numberOfAdults.options[document.flights.numberOfAdults.selectedIndex].value) + Number(document.flights.numberOfChildren.options[document.flights.numberOfChildren.selectedIndex].value);
	adult = "ADT";
	child = "CHD";
	for (i = 1; i <= totadults; i++)
		eval('document.flightsPlanitgo.TRAVELLER_TYPE_' + i + '.value = adult;');
	for (j = i; j <= totpassengers; j++)
		eval('document.flightsPlanitgo.TRAVELLER_TYPE_' + j + '.value = child;');
	for (k = j; k <= 9; k++)
		eval('document.flightsPlanitgo.TRAVELLER_TYPE_' + k + '.value = "";');
	if (document.getElementById("Infant").style.display != 'none') {
		totinfants = Number(document.flights.numberOfInfants.options[document.flights.numberOfInfants.selectedIndex].value);
		for (i = 1; i <= totinfants; i++)
			eval('document.flightsPlanitgo.HAS_INFANT_' + i + '.value = "TRUE";');
		for (j = i; j <= totpassengers; j++)
			eval('document.flightsPlanitgo.HAS_INFANT_' + j + '.value = "FALSE";');
	} else {
		for (i = 1; i <= 9; i++)
			eval('document.flightsPlanitgo.HAS_INFANT_' + i + '.value = "";');
	}

	var soSiteVal = "";
	if (checkforCuba()) {
		soSiteVal = "YWG";
	} else {
		if (country == "CA") {
			soSiteVal = "YOW";
		} else if (country == "US") {
			soSiteVal = "WAS";
		}
	}
	if (document.flightsPlanitgo.action.indexOf("jsessionid") != -1 && soSiteVal == document.flightsPlanitgo.SO_SITE_POINT_OF_SALE.value) {
		var controllerIndex = document.flightsPlanitgo.action.lastIndexOf("OverrideServlet");
		document.flightsPlanitgo.action = document.flightsPlanitgo.action.substr(0,controllerIndex)+checkEmbeddedTransaction(aBookingFlowVal)+document.flightsPlanitgo.action.substr(controllerIndex+15);
		document.flightsPlanitgo.SO_SITE_POINT_OF_SALE.value = "SAO";
		document.flightsPlanitgo.SO_SITE_POINT_OF_TICKETING.value = "SAO";
		
	} else {
		document.flightsPlanitgo.EMBEDDED_TRANSACTION.value = checkEmbeddedTransaction(aBookingFlowVal);
		document.flightsPlanitgo.SO_SITE_POINT_OF_SALE.value = "SAO";
		document.flightsPlanitgo.SO_SITE_POINT_OF_TICKETING.value = "SAO";
	}

	if (document.getElementById('Direct') && document.getElementById('Direct').style.display != 'none' && document.flights.directFlight && document.flights.directFlight.checked)
		document.flightsPlanitgo.DIRECT_NON_STOP.value = "TRUE";
    else
		document.flightsPlanitgo.DIRECT_NON_STOP.value = "FALSE"

	if (document.getElementById("Flexible").style.display != 'none') {
		if (document.flights.Flexible.checked == true)
			document.flightsPlanitgo.SEVEN_DAY_SEARCH.value = "TRUE";
	    else
			document.flightsPlanitgo.SEVEN_DAY_SEARCH.value = "FALSE"
	} else {
		document.flightsPlanitgo.SEVEN_DAY_SEARCH.value = "";
	}
	if (aBookingFlowVal.indexOf("INTERNATIONAL") == -1) {
		if (document.flights.classType.selectedIndex == 0) {
			document.flightsPlanitgo.CABIN.value = "R";
		} else if (document.flights.classType.selectedIndex == 1) {
			document.flightsPlanitgo.CABIN.value = "E";
		} else if (document.flights.classType.selectedIndex == 2) {
			document.flightsPlanitgo.CABIN.value = "N";
		} else if (document.flights.classType.selectedIndex == 3) {
			document.flightsPlanitgo.CABIN.value = "B";
		}		
	}
	
	document.flightsPlanitgo.COUNTRY.value = "BR";
	document.flightsPlanitgo.MARKET.value = "BR";
}

function submitFlightSearch() {

		setFormFields();
		document.flightsPlanitgo.submit();
}


function init() {
	loaded = true;
	
	for (i = 1; i <= MAX_DEPARTURES; i++) {	 
		eval("popMonth(document.flights.departMonthYear" + i + ", 0, " + getCurrentMonth() + ", " + getCurrentFullYear() + ", POSITIVE_INFINITY, POSITIVE_INFINITY);");
		eval("setDays(document.flights.departDay" + i + ");");
	}

	if (!FLIGHT_PAGE) {
		if (!MULTI_DESTINATION) {
			document.flights.tripType[0].checked = true;
		}
		for (i = 1; i <= MAX_CITY_PAIRS; i++) {
			eval('document.flights.org' + i + '.value = "";');
			eval('document.flights.dest' + i + '.value = "";');
			eval('document.flights.origin' + i + '.value = "";');
			eval('document.flights.destination' + i + '.value = "";');
		}
	}
//SR97501543
	if (!(document.flightsPlanitgo.PRIVATE_LABEL.value == "AGENT" || MULTI_DESTINATION))
	{// For non-AGENT site display depatrue date as today+7days and reurn date as today+14days
		document.flights.departTime1.selectedIndex = 0;
		document.flights.departTime2.selectedIndex = 0;

		var adjustedDates = adjustDates();

		if (parseInt(getCurrentMonth()) != (adjustedDates.depDate.getMonth()+1))
			document.flights.departMonthYear1.selectedIndex = 1;
		else
			document.flights.departMonthYear1.selectedIndex = 0;

		if (parseInt(getCurrentMonth()) != (adjustedDates.retDate.getMonth()+1))
			document.flights.departMonthYear2.selectedIndex = 1;
		else
			document.flights.departMonthYear2.selectedIndex = 0;

		day = document.flights.departDay1;
		for (j = 0; j < day.length; j++) {
			if (parseInt(day.options[j].value) == parseInt(adjustedDates.depDate.getDate())) {
				day.selectedIndex = j;
				break;
			}
		}

		day = document.flights.departDay2;
		for (j = 0; j < day.length; j++) {
			if (parseInt(day.options[j].value) == parseInt(adjustedDates.retDate.getDate())) {
				day.selectedIndex = j;
				break;
			}
		}
	}
	//SR97501543
	else
	{// original behavior i.e. pre SR97501543 implementation
		// reset to today's date
		for (i = 1; i <= MAX_DEPARTURES; i++) {
			eval('document.flights.departMonthYear' + i + '.selectedIndex = 0;');
			day = eval('document.flights.departDay' + i + ';');
			for (j = 0; j < day.length; j++) {
				if (parseInt(day.options[j].value) == parseInt(getCurrentDate())) {
					day.selectedIndex = j;
					break;
				}
			}
			eval('document.flights.departTime' + i + '.selectedIndex = 0;');
		} // end set date
	}
	document.flights.numberOfAdults.selectedIndex = 0;
	document.flights.numberOfChildren.selectedIndex = 0;
	document.flights.numberOfInfants.selectedIndex = 0;
	document.flights.countryOfResidence.selectedIndex = 0;
	document.flights.Flexible.checked = false;
	document.flights.classType.selectedIndex = 0;
	if (!MULTI_DESTINATION && document.flights.searchType[0])
		document.flights.searchType[0].checked = true;
	if (FLIGHT_PAGE || MULTI_DESTINATION)
		document.flights.directFlight.checked = false;
}

function initFlightSearch() {
	
	init();

}

matchAmbiArray = false;

function findMatch(text) {
	matchAmbiArray = false;
	keyWordsArray = new Array("Charleston","Chicago","Cleveland","Dallas","Kingston","London","Manchester","Moscow","New York","Sydney","Tokyo","Toronto","Washington");

	rEtext = text;
	eval("rExp = /^" + rEtext.replace(/\//g, "\\\/").replace(/\(/g, " ").replace(/\)/g, " ") + "/i");

	if (text.length == 3) {
		for (i=0; i<Countries.length; i++) {
			if (Countries[i][0].match(rExp)) {
				return new Array(false, Countries[i]);
			}
		}
	}
	found = false;
	ambiguous = false;
	if (text.length >= 3) {
		for (j = 0; j < keyWordsArray.length; j ++) {
			if ( keyWordsArray[j].toUpperCase() == text.toUpperCase() ) {
				matchAmbiArray = true;
				return new Array(true, new Array("???", text));
			}
		}
		for (i=0; i<Countries.length; i++) {
			if (Countries[i][2].replace(/\(/g, "\ ").replace(/\)/g, "\ ").match(rExp)) {
				if (found) {
					ambiguous = true;
					break;
				} else {
					found = Countries[i];
				}
			}
		}
	}
	if (found) {
		return new Array(ambiguous, found);
	} else {
		return new Array(true, new Array("???", text));
	}
}

function checkCity(cityField, hiddenField) {
	if (cityField.value.length < 3) {
		return false;
	} else {
		res = findMatch(cityField.value);
		if (matchAmbiArray) {
			return false;
    	}
		if (res) {	
			if (res[0]) {
				return false;
			} else {
				hiddenField.value = res[1][0];
				cityField.value = res[1][2];
				return true;
			}
		}
	}
	return false;
}

function getDateNumber( index ) {
	if (index == "Dep")
		index = 1;
	else if (index == "Ret")
		index = 2;
	depDay = eval("document.flights.departDay" + index);
	depMonthYear = eval("document.flights.departMonthYear" + index);

	inputDepDay = depDay.options[depDay.selectedIndex].text;
	inputDepMonth = getMonth(depMonthYear.options[depMonthYear.selectedIndex].value);
	inputDepYear = getYear(depMonthYear.options[depMonthYear.selectedIndex].value,depDay);

	depDateString = inputDepYear + getMonthOfYear( inputDepMonth ) + inputDepDay;
	return depDateString;
}

function getZeroPadded(input, len) {
	retString = new String(input);
	while (retString.length < len)
		retString = "0" + retString;
	return retString;
}

function getFullYearFromOpt(monthYearOpt,dayOpt) {
	var yr = Number(getCurrentFullYear());
	var mo = Number(getMonthFromOpt(monthYearOpt));
	var day = Number(getDayFromOpt(dayOpt));
	if (mo == getCurrentMonth() && day < getCurrentDate()) {
		yr++;
		return yr.toString();
	} else {
		return monthYearOpt.options[monthYearOpt.selectedIndex].value.substring(3,7);
	}
}

function getMonthFromOpt(monthYearOpt) {
	return getMonthOfYear(monthYearOpt.options[monthYearOpt.selectedIndex].value.substring(0,3));
}

function getDayFromOpt(dayOpt) {
	return dayOpt.options[dayOpt.selectedIndex].value;
}

function isWithin353Days(monthYearOpt,dayOpt) {
	var today = new Date();
	var yr = Number(getFullYearFromOpt(monthYearOpt,dayOpt));
	var mo = Number(getMonthFromOpt(monthYearOpt))-1;
	var day = Number(getDayFromOpt(dayOpt));
	var selectedDate = new Date(yr,mo,day);
	var diff = new Date(selectedDate.getTime() - today.getTime());
	var daysDiff = Math.ceil(diff.getTime() / (1000 * 60 * 60 * 24));
	if (daysDiff > 353)
		return false;
	else
		return true;
}

function getCurrentDateAsNumber() {
	var mo = Number(getCurrentMonth()).toString();
	var day = Number(getCurrentDate()).toString();
	return getCurrentFullYear() + getZeroPadded(mo,2) + getZeroPadded(day,2);	
}

function getMonth(monthYear) {
	return monthYear.substring( 0, 3 );
}

function getYear(monthYear,dayOpt) {
	if (dayOpt) {
		var yr = Number(getCurrentFullYear());
		var mo = Number(getMonthOfYear(monthYear.substring(0,3)));
		var day = Number(getDayFromOpt(dayOpt));
		if (mo == getCurrentMonth() && day < getCurrentDate()) {
			yr++;
			return yr.toString();
		} else {
			return monthYear.substring(3,7);
		}
	} else {
		return monthYear.substring(3,7);
	}
}

function leapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0)
			return true;
	} else {
		if ((intYear % 4) == 0)
			return true;
	}
	return false;
}

function getDaysInMonth(month,year) {
	daysOfMonth = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
	daysOfMonth["Jan"] = "31";
	daysOfMonth["Feb"] = eval("leapYear("+year+")?\"29\":\"28\"");
	daysOfMonth["Mar"] = "31";
	daysOfMonth["Apr"] = "30";
	daysOfMonth["May"] = "31";
	daysOfMonth["Jun"] = "30";
	daysOfMonth["Jul"] = "31";
	daysOfMonth["Aug"] = "31";
	daysOfMonth["Sep"] = "30";
	daysOfMonth["Oct"] = "31";
	daysOfMonth["Nov"] = "30";
	daysOfMonth["Dec"] = "31";

	return daysOfMonth[month];
}

function getMonthOfYear(month) { 
	monthOfYear = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
	monthOfYear["Jan"] = "01";
	monthOfYear["Feb"] = "02";
	monthOfYear["Mar"] = "03";
	monthOfYear["Apr"] = "04";
	monthOfYear["May"] = "05";
	monthOfYear["Jun"] = "06";
	monthOfYear["Jul"] = "07";
	monthOfYear["Aug"] = "08";
	monthOfYear["Sep"] = "09";
	monthOfYear["Oct"] = "10";
	monthOfYear["Nov"] = "11";
	monthOfYear["Dec"] = "12";

	return monthOfYear[month];
}

function getCurrentFullYear() {
   var today = new Date();
   return today.getFullYear();
}

function getCurrentMonth() {
   var today = new Date();
   return (today.getMonth()+1);
}

function getCurrentDate() {
   var today = new Date();
   return (today.getDate());
}

function adjustDates()
{
	var dep = new Date();
	var ret = new Date();

	dep.setDate(dep.getDate()+7);
	ret.setDate(ret.getDate()+14);

	var o = new Object();
	o.depDate = dep;
	o.retDate = ret;
	return o;
}

//------------------------------------------------------------------------------
function popMonth(monthYearList, listIndex, startMonth, startYear, endMonth, endYear) {

	var month = new Number(startMonth);
	var year = new Number(startYear);

	if ((month.toString() == "NaN") || (year.toString() == "NaN")
		|| (endMonth.toString() == "NaN") || (endYear.toString() == "NaN")
		|| (endYear < year) || (endYear == year && endMonth < month) ) {
		return;
	}
	else {
		monthYearList.selectedIndex = listIndex;
		for (; listIndex < monthYearList.length; listIndex ++) {
			if (year < endYear || ((year == endYear) && (month <= endMonth))) {
				monthYearList.options[listIndex].text = months[month - 1][0] ;
				monthYearList.options[listIndex].value = months[month - 1][1] + year;
			}
			else {
				monthYearList.options[listIndex].text = "";
				monthYearList.options[listIndex].value = ""; 
			}

			if (++month > 12) {
				month = 1;
				year ++;
			}
		}
	}
}


function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
  var today = new Date()
  var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
  if (cookie_value != null && cookie_value != ""){
    var cookie_string =cookie_name + "=" + escape(cookie_value)
    if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
    if(cookie_path){ cookie_string += "; path=" + cookie_path}
 	document.cookie = cookie_string
  }
} 

function getCookie(name) {
  var index = document.cookie.indexOf(name + "=")
  if (index == -1) { return null}
  index = document.cookie.indexOf("=", index) + 1
  var end_string = document.cookie.indexOf(";", index)
  if (end_string == -1) { end_string = document.cookie.length }
  return unescape(document.cookie.substring(index, end_string))
} 

function cookieEnable(){
	var testout = "";
	var cookie_enable = false;
	setCookie('cookietest', 'yes', '1', '/');
	testout = getCookie('cookietest');
	if (testout != null ) {
	  cookie_enable = true;	
	}
  return cookie_enable 
} 

function classType_onChange() {
	if (document.flights.searchType && document.getElementById('Shop').style.display!='none') {
		if (document.flights.classType.selectedIndex > 0)
			document.flights.searchType[1].checked = true;
		else
			document.flights.searchType[0].checked = true;
		searchType_onChange();
	}
}

function searchType_onChange() {
	var searchTyp = '';
	searchTyp = document.flights.searchType[0].value;
	if (document.flights.searchType[1].checked){
		searchTyp = document.flights.searchType[1].value;
	}

	var aFlightSegmentType = checkFlightSegmentType(document.flights.org1.value,document.flights.dest1.value);
	var fareDriven = checkforFareDriven(document.flights.org1.value,document.flights.dest1.value);
    if (searchTyp == "F") {
        document.flights.searchType[0].checked = true;
        document.getElementById('Flexible').style.display='block';
        if (aFlightSegmentType == "International" || !fareDriven) {
			document.getElementById('Class').style.display='none';
		} else {
			document.getElementById('Class').style.display='block';
		}
		if (document.getElementById('Direct'))
			document.getElementById('Direct').style.display='none';
    } else if(searchTyp == "S") {
        document.flights.searchType[1].checked = true;
        document.getElementById('Flexible').style.display='none';
		document.getElementById('Class').style.display='block';
		if (document.getElementById('Direct'))
			document.getElementById('Direct').style.display='block';
    } else {
        document.flights.tripType[0].checked = true;
	}
}

function checkforTyrolean() {
	var tyroleanFlightSegment = false;
	var airportOrgCode;
	var airportDestCode;
	var i;
	for (i=1; i<=MAX_CITY_PAIRS; i++) {
		airportOrgCode = eval("document.flights.origin" + i + ".value");
		airportDestCode = eval("document.flights.destination" + i + ".value");
		if (airportOrgCode=="GRZ" || airportOrgCode=="INN" || airportOrgCode=="KLU" || airportOrgCode=="LNZ" || airportOrgCode=="SZG" || airportDestCode=="GRZ" || airportDestCode=="INN" || airportDestCode=="KLU" || airportDestCode=="LNZ" || airportDestCode=="SZG") {
			tyroleanFlightSegment = true;
		}
	}
	if (tyroleanFlightSegment) {
		displayTyroleanPopup();
	}
}

var tyrolean_window = null;
function displayTyroleanPopup() {
	if (tyrolean_window == null) {
		if (Language == "french") {
			tyrolean_window = window.open('/shared/includes/fr/common/city/pop_tyrolean.html', 'Error', 'scrollbars=yes,width=300,height=200,resizeable=yes');
		} else {
			tyrolean_window = window.open('/shared/includes/en/common/city/pop_tyrolean.html', 'Error', 'scrollbars=yes,width=300,height=200,resizeable=yes');
		}
	}
}

function setDays(day,month) {
	var monthval, yearval;
	if (month && month.options) {
		monthval = month.options[month.selectedIndex].value;
		yearval = getYear(monthval);
		monthval = getMonth(monthval);
		monthval = Number(getMonthOfYear(monthval));
		yearval = Number(yearval);
	}
	else {
		monthval = getCurrentMonth();
		yearval = getCurrentFullYear();
	}
	if (monthval == 1 || monthval == 3 || monthval == 5 || monthval == 7 || monthval == 8 || monthval == 10 || monthval == 12) {
		if (day.length == 28) {
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if (day.length == 29) {
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if (day.length == 30) {
			opt = new Option(31,31);
			day.options[30] = opt;
		}
	} else if (monthval == 2) {	
		if (day.length == 31) {			
			day.removeChild(day.options[30]);
		}
		if (day.length == 30) {				
			day.removeChild(day.options[29]);
		}	
		if ((day.length == 29) && !leapYear(yearval)) {
			day.removeChild(day.options[28]);
		}
	} else if (monthval == 4 || monthval == 6 || monthval == 9 || monthval == 11) {
		if (day.length == 28) {
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if (day.length == 29) {
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if (day.length == 31){		
			day.removeChild(day.options[30]);
		}
	}
} 

function doNothing() {}

function _openWindow(dependant, FileName, windowName, width, height) {
	wh = window.open(FileName, windowName, 'dependant=' + (dependant ? 'yes' : 'no') + ',resizable=yes'  + ',width=' + width + ',height=' + height);
	wh.topwin = self;
	wh.focus();
}


  mouseDown = new Array();
  
  function setMouseDown(e, target) {	  
    mouseDown[target.name] = true;  	
  }
  function clearMouseDown(e, target) {
    mouseDown[target.name] = false;
  }
  function checkMouseDown(e, target) {
    if (mouseDown[target.name]) {
      mouseDown[target.name] = false;      
      return true;
    }
    else {
      return false;
    }
  }

function openWindow(event, target, FileName, windowName, width, height) {
	if (!(width && height)) {
		width = 800;
		height = 600;		
	}

	if (checkMouseDown(event, target)) {		
		_openWindow(false, FileName, windowName, width, height);
	}

}

function checkTripType(RoundTrip) {
	if (RoundTrip=="O")
		document.getElementById('ReturnTextbar').style.display="none";
	else
		document.getElementById('ReturnTextbar').style.display="block";
}

var Language = 'english'
function MM_openCalWindow(theURL,winName,calendarType,features) {
	if (window.calendar && window.calendar.open && !window.calendar.closed)
	{ window.calendar.close();
	}	
  features="width=282,height=230,screenX=320,screenY=200";
  if(Language == 'english')
 	 lang = '0';
  else
     lang ='1';

 if (calendarType == '')
  { 
  	i=winName.indexOf('_',10);
  	formname= winName.substr(10,i-10);
	datefield = winName.substr(i+1,winName.lastIndexOf('_')-i-1);
	monthfield = winName.substr(winName.lastIndexOf('_')+1,winName.length);
	
	day=eval("document."+formname+"."+datefield);
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
	  	}
	
	calendar = window.open(theURL+"?month_el='"+monthfield+"'%26date_el='"+datefield+"'%26month_wl=''%26date_wl=''%26date_year=''%26date_year1=''%26way=''%26language='"+lang+"'%26formName='"+formname+"'",winName,features);
    return;
 }	

 if (calendarType == 'pu' || calendarType == 'do')
  {
   if (calendarType == 'pu'){  
	  	day=document.cars.departDay1;
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
	  	}
	}
	day=document.cars.departDay2;
	if(day.length == 28){		
		opt = new Option(29,29);
		day.options[28] = opt;
	}
	if(day.length == 29){
		opt = new Option(30,30);
		day.options[29] = opt;
	}
	if(day.length == 30){
		opt = new Option(31,31);
		day.options[30] = opt;
	}
	  calendar = window.open(theURL+"?month_el='departMonthYear1'%26date_el='departDay1'%26month_wl='departMonthYear2'%26date_wl='departDay2'%26date_year=''%26date_year1=''%26way='"+calendarType+"'%26language='"+lang+"'%26formName='cars'",winName,features);
 	return;
  }
 
 var tripType="" ;
 if(calendarType == '1' || calendarType == '2' ||calendarType == '3' ||calendarType == '4' ||calendarType == '5' ||calendarType == '6' )
  {	  tripType="M"; }

else if(calendarType == 'd' || calendarType == 'r')
{	 
  if (document.flights.tripType[0].checked)
  	tripType="R";
  else
    tripType="O"
}      

if (tripType =="R")
{
	if(calendarType == 'd' )
	{
		day=document.flights.departDay1;
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
	  	}
		day=document.flights.departDay2;
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
		}
	    calendar = window.open(theURL+"?month_el='departMonthYear1'%26date_el='departDay1'%26month_wl='departMonthYear2'%26date_wl='departDay2'%26date_year=''%26date_year1=''%26way='d'%26language='"+lang+"'%26formName='flights'",winName,features);
	}	
	if(calendarType == 'r')
	{
		day=document.flights.departDay2;
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
		}
       calendar = window.open(theURL+"?month_el='departMonthYear1'%26date_el='departDay1'%26month_wl='departMonthYear2'%26date_wl='departDay2'%26date_year=''%26date_year1=''%26way='r'%26language='"+lang+"'%26formName='flights'",winName,features);
	}  
}
else if (tripType == "O")
{
	if(calendarType == 'd' )
	{
		day=document.flights.departDay1;
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
		}
		calendar = window.open(theURL+"?month_el='departMonthYear1'%26date_el='departDay1'%26month_wl=''%26date_wl=''%26date_year=''%26date_year1=''%26way='d'%26language='"+lang+"'%26formName='flights'",winName,features);
	}
}
else if (tripType == "M")
{
	for(i=1;i<=6;i++){
		day=eval("document.flights.departDay"+i);
		if(day.length == 28){		
			opt = new Option(29,29);
			day.options[28] = opt;
		}
		if(day.length == 29){
			opt = new Option(30,30);
			day.options[29] = opt;
		}
		if(day.length == 30){
			opt = new Option(31,31);
			day.options[30] = opt;
		}
	}
	calendar = window.open(theURL+"?month_el='departMonthYear"+calendarType+"'%26date_el='departDay"+calendarType+"'%26month_wl=''%26date_wl=''%26date_year=''%26date_year1=''%26way='m'%26language='"+lang+"'%26formName='flights'",winName,features);
}
   
}

function getCountry(airportCode) {
  	for (i=0; i<Countries.length; i++) {
 		if (Countries[i][0] == airportCode.toUpperCase()) {
			return Countries[i][1].toUpperCase();
 		}
 	}
}

function getCityName(airportCode) {
  	for (i=0; i<Countries.length; i++) {
 		if (Countries[i][0] == airportCode.toUpperCase()) {
			return Countries[i][2];
 		}
 	}
 	return "";
}

function checkforCuba() {
	var airportOrgCode;
	var airportDestCode;
	var countryOrgCode;
	var countryDestCode;
	var i;
	for (i=1; i<=MAX_CITY_PAIRS; i++) {
		airportOrgCode = eval("document.flights.origin" + i + ".value");
		airportDestCode = eval("document.flights.destination" + i + ".value");
		countryOrgCode = airportOrgCode==""?"":getCountry(airportOrgCode);
		countryDestCode = airportDestCode==""?"":getCountry(airportDestCode);
		if (countryOrgCode == "CU" || countryDestCode == "CU") {
			return true;
		}
	}
	return false;
}



