
//== Validation messages:
var msgEnterValidOutboundDate	= "Please enter a valid date for the outgoing journey";
var msgEnterValidReturnDate		= "Please enter a valid date for the return journey";
var msgOutboundBeforeReturn		= "Your return journey cannot be before your outward journey";
var msgEnterDifferentDest		= "Please enter a different destination to the airport you wish to depart from";
var msgIncludeLiverpool 		= "Your journey must start from, or fly to Liverpool";
var msgTooManyPeople			= "You can only make a booking for up to 9 seats online. Please phone 1111 111 1111 if you wish to make a booking for 10 or more passengers. Please view our CONTACT US page if dialling from outside the UK.";
var msgTooManyInfants			= "There can only be up to one infant per adult for the booking. Please check and try again";
var msgInvalidTitle				= "Please enter a valid title";
var msgInvalidAge				= "Please enter an age for the infant";
var msgAcceptTerms				= "Please tick the box to indicate that you have accepted the terms and conditions for the booking";
var msgInvalidExpiryDate		= "Please enter a valid expiry date";

var msgGenericInvalidStart		= "Please enter a valid ";
var	msgGenericInvalidEnd		= "";

var msgGenericLongStart			= "Please enter a shorter ";
var	msgGenericLongEnd			= "";

//== for browser differences
var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

var regExMac = /Macintosh/;
var strVersion = navigator.appVersion;
if (strVersion.search(regExMac) == -1)
{
	var isMac = false;
}
else 
{
	var isMac = true;
}

//== Field name variables (do not translate name variables):

//==	Search form & Booking Page 1
var glbOriginAirportName		= "from";
var glbDestinationAirportName	= "to";

var glbOutboundDayName			= "outbound_day";
var glbOutboundMonthYearName	= "outbound_month_and_year";
var glbReturnDayName			= "return_day";
var glbReturnMonthYearName		= "return_month_and_year";

var glbAdultsName				= "adults";
var glbChildrenName				= "children";
var glbInfantsName				= "infants";

//==	Booking Page 2
var glbOutboundJourneyName		= "outbound_journey";
var glbReturnJourneyName		= "return_journey";

//==	Booking Page 4
var glbTitlePrefixName			= "title_p";
var glbForenamePrefixName		= "forename_p";
var glbSurnamePrefixName		= "surname_p";

var glbContactPhoneHome			= "contact_phone_home";
var glbContactPhoneAway			= "contact_phone_away";
var glbContactEmail				= "contact_email";

//==	Booking Page 5
var glbPaymentRadio			= "PURCHASE2";
var glbTotalPaymentName			= "total_payment";
var glbTotalPaymentDisplayName		= "total_payment_display";
var glbCardTypeName			= "card_type";

var glbCardNameName			= "card_name";
var glbCardNumberName			= "card_number";
var glbCardExpiryMonthName		= "card_expiry_month";
var glbCardExpiryYearName		= "card_expiry_year";
var glbCardIssueNumberName		= "card_issue_number";

var glbBillHouseName			= "bill_house";
//var glbBillStreetName			= "bill_street";
var glbBillTownName				= "bill_town";
var glbBillPostcodeName			= "bill_postcode";
var glbBillCountryName			= "bill_country";
var glbBillEmailName			= "bill_email";
var glbBillTermsName			= "bill_terms";

//== Currency settings:

var glbCCChargeOnServer			= true;				//==	Set this to true if the server will create the credit card drop down 
													//==	with the credit card charges

var glbCurrency					= "GBP";
var glbCurrencySymbol			= "�";
var glbCreditCardCharge			= 3;

var constEUROCurrency			= "EUR";
var constEUROSymbol				= "�";
var constEUROCCCharge			= 5;

var constGBPCurrency			= "GBP";
var constGBPSymbol				= "�";
var constGBPCCCharge			= 3;

var constMaxFieldLength			= 100;				//==	Default maximum field length for all fields

var constMaxNumberPassengers	= 9;				//==	Maximum number of total Adults and children for the booking
var constMaxNumberParty			= 18;				//==	Theoretical maximum number in party (max Adults + max Infants)

var constLiverpool	= "LPL";
var constIsleOfMan				= "IOM";
var constCreditCardChargeIdentifier = "charge";		//==	String to search for in the option value that
													//==	specifies the card adds a charge


window.onload = loader;		//== Set the onload event handler



//==	Event handler - window.onload: loader()
//
//==		fires when the page loads. assigns event handlers.
//==		also sets the global currency type, and populates credit
//==		card charge details

function loader() {
	var objReturnDay			= glbGetElementById(glbReturnDayName);
	var objReturnMonthYear		= glbGetElementById(glbReturnMonthYearName);
	var objTotalPayment			= glbGetElementById(glbTotalPaymentName);
	var objTotalPaymentDisplay	= glbGetElementById(glbTotalPaymentDisplayName);
	var objCreditCardType		= glbGetElementById(glbCardTypeName);
	
	var strTotalPaymentValue	= getFieldValue(objTotalPayment);
	/*
	if (objReturnDay) {
		objReturnDay.onchange = dateReturnChange;
	}
	
	if (objReturnMonthYear) {
		objReturnMonthYear.onchange = dateReturnChange;
	}
	*/
	if (objTotalPayment && objTotalPaymentDisplay) {										//== The payment fields are on the page
		if (strTotalPaymentValue.substr(0,1) == constEUROSymbol) {							//==	Look at the figure to determine currency type
			glbCurrency = constEUROCurrency;												//==	and set global values
			glbCurrencySymbol = constEUROSymbol;
			glbCreditCardCharge = constEUROCCCharge;
		} else {
			glbCurrency = constGBPCurrency;
			glbCurrencySymbol = constGBPSymbol;
			glbCreditCardCharge = constGBPCCCharge;			
		}
		objTotalPaymentDisplay.value = strTotalPaymentValue;
	}
	

// commented out because of conflict with onChange event handler defined elsewhere
//
//	if (objCreditCardType) {																//== The credit card type field is on the page:
//		objCreditCardType.onchange = creditCardTypeChange;									//==	Assign the onchange handler
//		if (!glbCCChargeOnServer) {
//			for (var intItem = 0; intItem < objCreditCardType.options.length; intItem++) {		//==	For each item that contains the Credit Card charge identifier
//				var strOptionText = objCreditCardType.options[intItem].text;					//==	add details of the charge based on the currency settings
//				if (strOptionText.indexOf(constCreditCardChargeIdentifier) > -1) {
//					objCreditCardType.options[intItem].text += " " + glbCurrencySymbol + glbCreditCardCharge;
//				}
//			}
//		}
//	}
}



//==	Event handler - select.onchange: creditCardTypeChange()
//
//==		fires when the credit card type field changes. adds credit card
//==		charges if the card requires it. 

function creditCardTypeChange() {
	var objTotalPayment			= glbGetElementById(glbTotalPaymentName);
	var objTotalPaymentDisplay	= glbGetElementById(glbTotalPaymentDisplayName);
	var objCreditCardType		= glbGetElementById(glbCardTypeName);
	
	var strTotalPaymentValue			= getFieldValue(objTotalPayment);

	var strTotalCreditCardTypeText		= "";
	var decCreditCardCharge				= glbCreditCardCharge; 
	
	if (objCreditCardType.selectedIndex > -1) {
		strTotalCreditCardTypeText = objCreditCardType.options[objCreditCardType.options.selectedIndex].text;
	}
	
	if (strTotalPaymentValue.substr(0,1) == glbCurrencySymbol) {
		if (glbCCChargeOnServer) { //== Override the credit card charges with those generated on the server
			var intCurSymbolPosn = strTotalCreditCardTypeText.indexOf(glbCurrencySymbol)
			if (intCurSymbolPosn > 0) {
				decCreditCardCharge = parseFloat(strTotalCreditCardTypeText.substr(intCurSymbolPosn + glbCurrencySymbol.length, strTotalCreditCardTypeText.length - (intCurSymbolPosn + glbCurrencySymbol.length)));	//== Get the value of the total payment
			}				
		}	
		var decTotalPayment = parseFloat(strTotalPaymentValue.substr(1, strTotalPaymentValue.length - 1));	//== Get the value of the total payment
	} else {
		return;  //==  Total price doesn't have the correct currecy symbol on the front
	}
	
	if (strTotalCreditCardTypeText.indexOf(constCreditCardChargeIdentifier) > -1) {							//== Card adds a charge
		decTotalPayment = decTotalPayment + decCreditCardCharge;											//== Add charge to the total
	}
	
	objTotalPaymentDisplay.value = glbCurrencySymbol + formatCurrency(decTotalPayment);
}



//==	Event handler - select.onchange: dateReturnChange()
//
//==		fires when the return date fields change to reset the fields
//==		to the value "no just one way" if either of the fields are set to 
//==		their part of the value

function dateReturnChange() {
	var objReturnDay			= glbGetElementById(glbReturnDayName);
	var objReturnMonthYear		= glbGetElementById(glbReturnMonthYearName);
	var strReturnDayValue		= "";
	var strReturnMonthYearValue = "";
	
	strReturnDayValue = getFieldValue(objReturnDay);
	strReturnMonthYearValue = getFieldValue(objReturnMonthYear);

	if (this == objReturnDay) {						//==	Day object change event fired
		if (strReturnDayValue == -1) {				//==	Day is set to "no"
			objReturnMonthYear.selectedIndex = 0;	//==	Set month to "just one way"
		} else { 
			if (strReturnMonthYearValue == -1) {
				objReturnMonthYear.selectedIndex = 1;
			}
		}
	} else {										//==	Month object change event fired
		if (strReturnMonthYearValue == -1) {		//==	Month is set to "just one way"
			objReturnDay.selectedIndex = 0;			//==	Set day to "no"
		} else { 
			if (strReturnDayValue == -1) {
				objReturnDay.selectedIndex = 1;
			}
		}
	}
}



//==	object glbGetElementById (string strName)
//
//==		returns the element object contained in the document where the name is equal 
//==		to string strName. designed to be cross-browser compatible.

function glbGetElementById (strName) {
	var objRetVal;
	var blnUseForm = false;
	if (document.getElementById) {					//==	Check for getElementById method
		objRetVal = document.getElementById(strName);
	} else {
		if (document.all) {							//==	Check for the document.all collection
			objRetVal = document.all[strName];
		} else {									//==	Search document forms for element
			blnUseForm = true;
		}
	}
	
	if (objRetVal) {
		if (objRetVal.type) {								//==	If object is a radio button we need to access it using
			if (objRetVal.type.toLowerCase() == "radio") {	//==	the document.formname.elementname notation to retrive the radioset array
				eval ("objRetVal = document." + objRetVal.form.name + "." + strName);
			}
		}
	}

	if (blnUseForm) {
		for (var lngFormCounter=0; !objRetVal && lngFormCounter < document.forms.length; lngFormCounter++) {
			for (var lngElementCounter=0; !objRetVal && lngElementCounter < document.forms[lngFormCounter].elements.length; lngElementCounter++) {
				var objElement = document.forms[lngFormCounter].elements[lngElementCounter];
				if (objElement.name == strName) {			//==	Found element 
					objRetVal = document.forms[lngFormCounter].elements[strName];
				}
			}
		}			
	}
	return objRetVal;
}



//==	string getFieldValue (object objField) 
//
//==		returns the value of the select element object passed in to
//==		the function. returns an empty string if the object is null, 
//==		not a select or	does not have a value selected.

function getFieldValue(objField) {
	if (objField) {
		if (objField.type) {
			if (objField.type.toLowerCase() == "select-one") {			//==	Field is a select drop-down. Get the selected option value
				if (objField.selectedIndex > -1) {
					return objField.options[objField.options.selectedIndex].value;
				}
			}
			if (objField.type.toLowerCase() == "radio") {				//==	Field is a radio box, but not checked so don't return a value
				if (!objField.checked) {
					return "";
				}
			}
		}
		if (objField.length && objField[0]) {							//==	Field is an radioset array. Find radio button that is checked
			for (var intOption = 0; intOption < objField.length; intOption++) {	
				if (objField[intOption].checked) {
					return objField[intOption].value;
				}
			}
		}
		if (objField.value) {											//==	Standard field. Use the value property
			return objField.value;
		}
	}
	return "";
}



//==	string formatCurrency (decimal decCurrency) 
//
//==		returns a string formating the decimal decCurrency to two decimal
//==		places.

function formatCurrency(decCurrency) {
	var strCurrency = decCurrency.toString();
	var intDecPosn = strCurrency.indexOf(".");
	if (intDecPosn == -1) {								//==	No decimal point in number. Add the two decimal places.
		strCurrency = strCurrency + ".00";	
	} else {
		if ((strCurrency.length - intDecPosn) < 3) {	//==	Decimal point exists, but not to two decimal places. Pad to correct length
			strCurrency = rightPad(strCurrency, intDecPosn + 3, "0");
		}
	}
	return strCurrency;
}



//==	string leftPad (string str, integer len, string chr)
//
//==		returns the string str left-padded to length len with 
//==		the character chr.

function leftPad(str, len, chr) {
	while (str.length < len) str = chr + str;
	return str;
}



//==	string rightPad (string str, integer len, string chr)
//
//==		returns the string str right-padded to length len with 
//==		the character chr.

function rightPad(str, len, chr) {
	while (str.length < len) str = str + chr;
	return str;
}



//==	string getDateValue(object objDay, object objMonthYear)
// 
//==		if either of objDay, or objMonthYear are set to the "no, just one way" value, 
//== 		it returns a blank string and sets both fields to the "no, just one way" value.
//==		otherwise, it returns the date value provided by the fields in the following 
//==		format: 
//==			dd mmm yyyy
//==		use isValidDate to validate the date value.

function getDateValue(objDay, objMonthYear) {
	var strDayValue = "";
	var strMonthYearValue = "";
	
	strDayValue = getFieldValue(objDay);
	strMonthYearValue = getFieldValue(objMonthYear);

	if (strDayValue == -1 || strMonthYearValue == -1) {	//==	Day field set to "no" or
														//==	Month Year field set to "just one way"

		objDay.selectedIndex		= 0;				//==	Set to "no"
		objMonthYear.selectedIndex	= 0;				//==	Set to "just one way"
		return "";
	}
	return leftPad(strDayValue, 2, "0") + " " + strMonthYearValue.substr(0,3) + " " + strMonthYearValue.substr(3,4);
}



//==	bool isValidDate (string strDate)
// 
//==		strDate should be the following format: dd mmm yyyy
//==		if strDate is empty, or contains a valid date value, returns true.
//== 		otherwise returns false.

function isValidDate(strDate) {
	if (strDate == "") return true;
	var strDay = strDate.substr(0,2);					//==	Take the first two characters from the date
	if (strDay.substr(0,1) == "0")						//==	Remove padded zero	
		strDay = strDay.substr(1,1);
	var intDay = parseInt(strDay);
	var dteDate = new Date(strDate);
	
	if (dteDate.getDate() != intDay) {					//==	The day value of the date has changed,
														//==	the date must be invalid
		return false;
	}
	
	return true;
}



//==	bool isValidNumber (string strNumber)
// 
//==		returns true if is string strNumber is a valid number 
//== 		(contains 0-9 . + - ( or )). otherwise returns false.

function isValidNumber(strNumber) {
	var numInput = "+-0123456789(). ";					//==	String containing valid characters
	
	if (strNumber == "") return false;
	
	for(var k = 0; k < strNumber.length; k++) {
		if(numInput.indexOf(strNumber.charAt(k)) == -1)	{
			return false;
		}
	}
	return true;
}



//==	bool isValidPostcode (string strPostcode)
// 
//==		returns true if is string strPostcode is a valid postcode.
//== 		otherwise returns false.

function isValidPostcode(strPostcode) {
	var regExPC = /^[a-zA-Z]{1,2}[0-9]{1,2}[a-zA-Z]? ?[0-9][a-zA-Z]{2}$/
	return regExPC.test(strPostcode);
}



//==	bool isValidEmail (string strEmail)
// 
//==		returns true if is string strEmail is a valid email address.
//== 		otherwise returns false.

function isValidEmail(strEmail) {
	if (isMac)
	{
		if (strEmail == null || strEmail == "" || strEmail.length < 5 || strEmail.search("@") == -1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		var regExEmail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
		return regExEmail.test(strEmail);
	//== above code doesn't work on Macs
	}
}



//==	string monthName (integer intMonth)
// 
//==		returns the abbreviated name of the month corresponding to the integer intMonth supplied.


function monthName (intMonth) {
	var aryMonths = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	
	if ((intMonth > 0) && (intMonth < 13)) {
		return aryMonths[intMonth - 1];
	}
	
	return "";
}



//==	integer daysInMonth (integer intMonth, integer intYear)
// 
//==		returns the numbers of days in the month for the month and year supplied

function daysInMonth (intMonth, intYear) {
	if (intMonth < 1 || intMonth > 12) {
		return 0;
	}
	if (intMonth == 12) return 31;
	
	var dteDate = new Date ("1 " + monthName (intMonth + 1) + " " + intYear)
	
	if (dteDate) {
		dteDate.setDate(0);
		return dteDate.getDate();
	}
	
	return 0;
}


//==	bool checkRequiredField (object objField, string strTitle, bool blnRequired, optional string strType)
//
//==		returns true if the field value passes the validation tests based on whether it is required, 
//==		the type of the field. if it fails validation, a generic message is displayed using the 
//==		the supplied title. focus is given to the object, and false is returned.

function checkRequiredField (objField, strTitle, blnRequired, strType) {
	var strValue = getFieldValue(objField);

	if (objField) {
		if (objField.length && objField[0]) {		//==	Field is an array - likely radioset
			objField = objField[0];			//==	Set field to first item so we can apply focus
		}
	}
	
	if (blnRequired || strValue != "") {			//==	Field is required, or value has been entered so check format
		if (strType == "postcode" && blnRequired) {	//==	Apply postcode validation only if required
			if (!isValidPostcode(strValue)) {
				alert (msgGenericInvalidStart + strTitle + msgGenericInvalidEnd);
				objField.focus();
				return false;
			}
		}
		if (strType == "number") {
			if (!isValidNumber(strValue)) {			//==	Apply number validation
				alert (msgGenericInvalidStart + strTitle + msgGenericInvalidEnd);
				objField.focus();
				return false;
			}
		}
		if (strType == "email") {
			if (!isValidEmail(strValue)) {			//==	Apply email validation 
				alert (msgGenericInvalidStart + strTitle + msgGenericInvalidEnd);
				objField.focus();
				return false;
			}
		}

        // to make sure it contains more than spaces
        var regexp = / /g;
        strCheck = strValue.replace(regexp, "");

	//	if (strValue == "" || strValue == -1) {		//==	Value is required but no value present
        if (strCheck == "" || strValue == -1) {     //==    Value is required but no value present
			alert (msgGenericInvalidStart + strTitle + msgGenericInvalidEnd);
			//objField.focus();
			return false;
		}
	}
	
	if (strValue.length > constMaxFieldLength) {	//==	Length of field is greater than max length
		alert (msgGenericLongStart + strTitle + msgGenericLongEnd);
		objField.focus();
		return false;
	}
	
	return true;									//==	Check successful
}



//==	bool checkFormPage1() 
//
//==		returns true if the following tests are passed:
//==			Origin Airport and Distination Airport are not the same
//==			Leeds Bradford is the start or destination Airport
//==			Outgoing date is valid
//==			Return date is valid (or no date set)
//==			Return date is same or after Outgoing date
//==			The number in the party is 9 or less
//==			The number of infants is equal to less to the number of adults
//==		if any check fails, the relevant field is focused and the function
//==		returns false.

function checkFormPage1() {
	var objOriginAirport			= glbGetElementById(glbOriginAirportName);
	var objDestinationAirport		= glbGetElementById(glbDestinationAirportName);
	var objOutboundDay				= glbGetElementById(glbOutboundDayName);
	var objOutboundMonthYear		= glbGetElementById(glbOutboundMonthYearName);
	var objReturnDay				= glbGetElementById(glbReturnDayName);
	var objReturnMonthYear			= glbGetElementById(glbReturnMonthYearName);
	var objAdults					= glbGetElementById(glbAdultsName);
	var objChildren					= glbGetElementById(glbChildrenName);
	var objInfants					= glbGetElementById(glbInfantsName);
	
	var strOriginAirportValue		= getFieldValue(objOriginAirport);
	var strDestinationAirportValue	= getFieldValue(objDestinationAirport);
	var strOutboundDateValue		= getDateValue(objOutboundDay, objOutboundMonthYear);
	var strReturnDateValue			= getDateValue(objReturnDay, objReturnMonthYear);
	var strAdultsValue				= getFieldValue(objAdults);
	var strChildrenValue			= getFieldValue(objChildren);
	var strInfantsValue				= getFieldValue(objInfants);

	if (strOriginAirportValue == strDestinationAirportValue) {						//==	Origin and Destination the same
		alert(msgEnterDifferentDest);
		objDestinationAirport.focus();
		return false;
	}
	
	if (!isValidDate(strOutboundDateValue)) {										//==	Outbound date not a valid date
		alert (msgEnterValidOutboundDate);
		objOutboundDay.focus();
		return false;
	}
	
	if (!isValidDate(strReturnDateValue)) {											//==	Return date not a valid date
		alert (msgEnterValidReturnDate);
		objReturnDay.focus();
		return false;
	}
	
	if (strReturnDateValue != "") {													//==	Return date set
		var dteOutbound = new Date (strOutboundDateValue);
		var dteReturn	= new Date (strReturnDateValue);
		if (dteOutbound > dteReturn) {												//==	Outbound date not before Return date
			alert (msgOutboundBeforeReturn);
			objOutboundDay.focus();
			return false;
		}
	}
	
	var intTotalParty = parseInt(strAdultsValue) 
					  + parseInt(strChildrenValue);
					  //-- + parseInt(strInfantsValue);								//==	Add up total party 

	if (intTotalParty > constMaxNumberPassengers) {									//==	Number in party more than Max number set
		alert(msgTooManyPeople);
		objAdults.focus();
		return false;
	}
	
	if (parseInt(strAdultsValue) < parseInt(strInfantsValue)) {						//==	More infants than adults
		alert(msgTooManyInfants);
		objInfants.focus();
		return false;
	}
	
	toBox = document.getElementById("to");
	fromBox = document.getElementById("from");
	fromVal = fromBox.value
	toVal = toBox.value;
	setCookie("last_from",fromVal,3);
	setCookie("last_to",toVal,3);
	
	return true;	// Checks passed sucessfully
} 



//==	bool checkFormPage2() 
//
//==		returns true if the following tests are passed:
//==			Outbound journey selected
//==			Return journey selected
//==		if any check fails, the relevant field is focused and the function
//==		returns false.

//function checkFormPage2() {
//	var objOutboundJourney			= glbGetElementById(glbOutboundJourneyName);
//	var objReturnJourney			= glbGetElementById(glbReturnJourneyName);
//
//	if (!checkRequiredField(objOutboundJourney, "Outbound journey", true, "")) return false;
//	if (objReturnJourney) { //== Only check for return journey if the return_journey radio set exists
//		if (!checkRequiredField(objReturnJourney, "Return journey", true, "")) return false;
//	}
//	
//	return true;
//} 

function getElById(id)
{
	if (isIE4)
	{
		return document.all(id);
	}
	else
	{
		return document.getElementById(id);
	}
}
function checkFormPage2IE4()
{
	var col = document.all.tags("INPUT");
	var i;
	var bSelect1 = false;
	var bSelect2 = false;

	for (i = 0;i < col.length;i++)
	{
	  if (col[i].name == "SELECT_LINE")
	  {
		if (col[i].checked)
		{
			bSelect1 = true;
		}
	  }
	  if (col[i].name == "SELECT_LINE2")
	  {
		if (col[i].checked)
		{
			bSelect2 = true;
		}
	  }
	}

	if (!(bSelect1 && bSelect2))
	{
		alert("Please select your flight(s)");
		return false;
	}

	return true;
}
function checkFormPage2()
{
	if (isIE4)
	{
		return checkFormPage2IE4();
	}
	
	var col = document.getElementsByName("SELECT_LINE");
	var col2 = document.getElementsByName("SELECT_LINE2");
	var i = 0;
	var bGroup1,bGroup2;
	
	bGroup1 = bGroup2 = false;
	
	for (i = 0;i < col.length;i++)
	{
		if (col[i].checked)
		{
			bGroup1 = true;
			break;
		}
	}
	
	for (i = 0;i < col2.length;i++)
	{
		if (col2[i].checked)
		{
			bGroup2 = true;
			break;
		}
	}
	
	// if there is no group 2
	if (col2.length == 0) 
	{ 
		bGroup2 = true; 
	}
	
	if (!(bGroup1 && bGroup2)) 
	{ 
		alert("Please select your flight(s)"); 
		return false 
	}
	
	return true;
}	



//==	bool checkFormPage3() 
//
//==		returns true. no checks required.

function checkFormPage3() {
	//== Validation for Insurance
	var insRad = document.names.radiobutton;
	
	if(insRad){	
			var radioChecked = "false";
				if (insRad.length) {
					for (p = 0; p < insRad.length; p++) {
						if (insRad[p].checked == true) {
							radioChecked = "true";
						}
					}
				}
				else {
					if (insRad.checked == true) {
						radioChecked = "true";
					}
				}
				if(radioChecked == "false"){
					alert("Please select if you would like to have travel insurance or not for your trip.")
					return false;
				}
		if ((document.names.radiobutton[1].checked == false) && (document.names.radiobutton[4].checked == false)) {
			if (document.getElementById("terms").checked == false) {
				alert("Please check the box confirming that you have read the Terms and Conditions in order to continue.");
				return false;
			}
		}
	}


	return true;	
} 



//==	bool checkFormPage4() 
//
//==		returns true if the following tests are passed:
//==			Each passenger has:
//==				a valid title (or age for infants)
//==				a valid forename
//==				a valid surname
//==			Home phone number entered
//==			Email address valid if entered
//==			No field longer than 100 characters
//==		if any check fails, the relevant field is focused and the function
//==		returns false.

//function checkFormPage4() {
//	var strPersonType = ""; 
//	var intPersonTypeCount = 0;
//
//	for (var intPerson = 1; intPerson <= constMaxNumberParty; intPerson++) {		//== Each person on the form
//		var objTitle		= glbGetElementById(glbTitlePrefixName + intPerson);
//		var objForename		= glbGetElementById(glbForenamePrefixName + intPerson);
//		var objSurname		= glbGetElementById(glbSurnamePrefixName + intPerson);
//		var strTitle		= getFieldValue(objTitle);
//		var strForename		= getFieldValue(objForename);
//		var strSurname		= getFieldValue(objSurname);
//		
//		if (objTitle && strTitle == "") {						//== Check title has been set
//			alert (msgInvalidTitle);
//			objTitle.focus();
//			return false;
//		}
//			
//		if (objTitle && strTitle == -1) {						//== -1 can only exist for infants
//			alert (msgInvalidAge);								//== If -1 no age has been set
//			objTitle.focus();
//			return false;
//		}
//
//		var strNewPersonType = "";
//	
//		if (objForename) {										//== Update the person type for this person
//			if (objTitle.options[0].value == "Mr.") strNewPersonType = "Adult";
//			if (objTitle.options[0].value == "Mstr.") strNewPersonType = "Child";
//			if (objTitle.options[0].value == -1) strNewPersonType = "Infant";
//
//			if (strNewPersonType == strPersonType) {			//== Add to the person type count
//				intPersonTypeCount++;
//			} else {
//				strPersonType = strNewPersonType;				//== New person type - reset the count
//				intPersonTypeCount = 1;
//			}
//			
//			if (!checkRequiredField(objForename, "First name for " + strPersonType + " " + intPersonTypeCount, true, "")) return false;
//			if (!checkRequiredField(objSurname, "Surname for " + strPersonType + " " + intPersonTypeCount, true, "")) return false; 
//			
//			if (strSurname.length < 2) { 
//				alert (msgGenericInvalidStart + "Surname for " + strPersonType + " " + intPersonTypeCount + msgGenericInvalidEnd);
//				objSurname.focus();
//				return false;
//			}
//						
//		} 
//	}
//
//	var objContactPhoneHome		= glbGetElementById(glbContactPhoneHome);
//	var objContactPhoneAway		= glbGetElementById(glbContactPhoneAway);
//	var objContactEmail			= glbGetElementById(glbContactEmail);
//
//	if (!checkRequiredField(objContactPhoneHome, "phone number", true, "number")) return false;		
////==	if (!checkRequiredField(objContactPhoneAway, "phone number", true, "number")) return false;
//	if (!checkRequiredField(objContactEmail, "Email address", false, "email")) return false;
//	
//	return true; 
//} 

function refreshThings() {    parent.location.href=parent.location.href;
}
function add_names() {    parent.location.href='171032?020830115252.10.1.0.1';
}


function getElByName(name,occurrence)
{
	if (isIE4)
	{
		var col;

		// assume that we want an INPUT element
		col = document.all.tags("INPUT");

		var i,nCount;

		nCount = 0;

		for (i = 0;i < col.length;i++)
		{
			if (col[i].name == name)
			{
				nCount ++;
				if (nCount == occurrence || occurrence == null)
				{
					return col[i];
				}
			}
		}
		
		// didn't find the requested element
		return null;
	}
	else
	{
		return document.getElementsByName(name);
	}
}
function getElsByTagName(tagName)
{
	if (isIE4)
	{
		return document.all.tags(tagName);
	}
	else
	{
		return document.getElementsByTagName(tagName);
	}

}

function checkFormPage42()
{

}
function checkFormPage4()
{
//	var col = document.getElementsByTagName("input");
	var sel = getElsByTagName("select");
	var col = getElsByTagName("input");
	var i;
	var bFirstNameErr,bLastNameErr,bIDErr,bEmailErr,bCarErr,bLegalErr;
	
	bFirstNameErr = bLastNameErr = bIDErr = bEmailErr = bCarErr = bLegalErr = 0;

	for (i = 0;i < col.length;i++)
	{
		var strName = col[i].name;
		strName = strName.substring(0,3);

        // to make sure it contains more than spaces
        strCheck = col[i].value;
        var regexp = / /g;
        strCheck = strCheck.replace(regexp, "");
		
		// check the First name fields
		if (strName == "IME")
		{
			//if (col[i].value == null || col[i].value == "" || col[i].value.length < 2)
            if (strCheck == null || strCheck == "" || strCheck.length < 2)
			{
				alert('Please fill out the names of all passengers flying.\n(must be at least 2 characters long)');
				return false;
			}
		}
		
		// check the Last name fields
		if (strName == "PRE")
		{
			//if (col[i].value == null || col[i].value == "" || col[i].value.length < 2)
            if (strCheck == null || strCheck == "" || strCheck.length < 2)
			{
				alert('Please fill out the last names of all passengers flying.\n(must be at least 2 characters long)');
				return false;
			}
		}
	
		// check the ID/Passport fields	
//		if (strName == "PAS")
//		{
//			if (col[i].value == null || col[i].value == "")
//			{
//				alert('Please fill out the ID/Passport numbers of all passengers flying.');
//				return false;
//			}
//		}
		
         // check the PHONE fields 
         if (strName == "PHO")
         {

			//if (col[i].value == null || col[i].value == "")
            if (strCheck == null || strCheck == "" || strCheck.length < 2)
			{
				alert('Please enter a valid phone number.');
				return false;
			}
         }
                  if (strName == "CEL")
         {

			//if (col[i].value == null || col[i].value == "")
            if (strCheck == null || strCheck == "" || strCheck.length < 2)
			{
				alert('Please enter a valid phone number.');
				return false;
			}
         }
		// check the Email field
		if (strName  == "EMA")
		{
			if (col[i].value == null || col[i].value == "" || col[i].value.length < 5 || col[i].value.search("@") == -1)
			{
				alert('Please fill in a valid Email address.');
				return false;
			}
		}	
	}

	for (i = 0;i < sel.length;i++)
	{
		var selName = sel[i].name;
		selName = selName.substring(0,3);
		if (selName == "PTC")
		{
			var infantAge = sel[i].selectedIndex
			if (infantAge < '1')
			{
				alert('Please enter an age for the infant');
				return false;
			}
		}
	}
}


//==	bool checkFormPage5() 
//
//==		returns true if the following tests are passed:
//==			Payment type has been selected
//==			Booking terms have been accepted
//==		if any check fails, the relevant field is focused and the function
//==		returns false.
//==		if payment is Debit, redirects to etranzact site
//
function checkFormPage5() {
	
	var objPaymentRadio			= getElByName(glbPaymentRadio);
	var objBillTermsAccept			= glbGetElementById(glbBillTermsName);

	if (!checkRequiredField(objPaymentRadio, "Payment type", true, "")) return false;

	if (!objBillTermsAccept.checked) {	//==	The user has not ticked the Terms box
		alert (msgAcceptTerms);
		objBillTermsAccept.focus();
		return false;
	}

	// if no error, disable submit button and return true
	var objSubmitButton =	 glbGetElementById("submitButton");
	objSubmitButton.disabled = 'true';

	return true;
} 

function openTermsWindow () {
	var agent = document.forms[0].AGENT.value;
	var url = "/cgi-bin/airkiosk/I7/191003?" + agent  +"+/aero/I7/EN/static/conditionsofcarriage.htm";
	
	termsWindow = window.open(url,'AeroPolicies','scrollbars=yes,width=550,height=450,resizable=yes');
	termsWindow.focus();	
}


//== validation for LFF
function checkFormLFFIE4()
{
	var col = document.all.tags("INPUT");
	var i;
	var bSelect1 = false;
	var bSelect2 = false;

	for (i = 0;i < col.length;i++)
	{
	  if (col[i].name == "SELECT_LINE")
	  {
		if (col[i].checked)
		{
			bSelect1 = true;
		}
	  }
	  if (col[i].name == "SELECT_LINE2")
	  {
		if (col[i].checked)
		{
			bSelect2 = true;
		}
	  }
	}

	if (!(bSelect1 && bSelect2))
	{
		alert("Please select your flight(s)");
		return false;
	}

	return true;
}
function checkFormLFF()
{
    var objOrigin = document.forms[0].elements['ORIGIN'].value;
    var objDestination = document.forms[0].elements['DESTINATION'].value;
    var objDate            = document.forms[0].elements['MONTHYEAR'].selectedIndex;
    var objRDate           = document.forms[0].elements['RMONTHYEAR'].selectedIndex;
	var objAdults					= glbGetElementById(glbAdultsName);
	var objChildren					= glbGetElementById(glbChildrenName);
	var objInfants					= glbGetElementById(glbInfantsName);
	var strAdultsValue				= getFieldValue(objAdults);
	var strChildrenValue			= getFieldValue(objChildren);
	var strInfantsValue				= getFieldValue(objInfants);

	if (isIE4)
	{
		return checkFormLFFIE4();
	}
   if (!objDate) {
        alert("Please select a departure date");
        document.forms[0].elements['MONTHYEAR'].focus();
       return false;
    }

    if (objDate > objRDate) {                //==    Leeds Bradford not Origin or Destination
        if (objRDate) {
            alert("Please select a departure date earlier than the return date");
            document.forms[0].elements['MONTHYEAR'].focus();
            return false;
        }
    }
	var intTotalParty = parseInt(strAdultsValue) 
					  + parseInt(strChildrenValue);
					  //-- + parseInt(strInfantsValue);								//==	Add up total party 

	return true;
}


function checkFormLFF2(thisForm) {
    if ((navigator.appName == "Netscape") && (browserVnum < 5)) {
        return true;
    }
    else {

	var objOutboundMonthYear		= thisForm.MONTHYEAR;
	var objReturnMonthYear			= thisForm.RMONTHYEAR;
	var objOutboundDay			= thisForm.DAY;
	var objReturnDay			= thisForm.RDAY;

	var strOutboundDateValue		= getDateValue(objOutboundDay, objOutboundMonthYear);
	var strReturnDateValue			= getDateValue(objReturnDay, objReturnMonthYear);

	var dteOutbound 			= new Date (strOutboundDateValue);
	var dteReturn				= new Date (strReturnDateValue);


if (document.forms[0].DIRECTION.value != 'SEARCH') {
	if (!getFieldValue(objOutboundDay)) {
		alert ("Please select an outbound day.");
		return false;
	}
}
	if (strReturnDateValue != "") {							//==	Return date set
		if (!getFieldValue(objReturnDay) && (document.forms[0].DIRECTION.value != 'SEARCH')) {
			alert ("Please select a day of return.");
			return false;
		}

		if (dteOutbound > dteReturn) {						//==	Outbound date not before Return date
			alert (msgOutboundBeforeReturn);
			return false;
		}
	}
    }

    return true;	// Checks passed sucessfully
} 




//== added 10/16/2003
//== copy of checkFormPage5() with address info commented

function checkFormChange4() {
	var objCardName				= glbGetElementById(glbCardNameName);

//var objCardType                         = glbGetElementById(glbCardTypeName);

	var objCardNumber			= glbGetElementById(glbCardNumberName);

	var objCardExpiryMonth		= glbGetElementById(glbCardExpiryMonthName);
	var objCardExpiryYear		= glbGetElementById(glbCardExpiryYearName);
	var objCardIssueNumber		= glbGetElementById(glbCardIssueNumberName);
//	var objBillHouse			= glbGetElementById(glbBillHouseName);
//	var objBillStreet			= glbGetElementById(glbBillStreetName);
//	var objBillTown				= glbGetElementById(glbBillTownName);
//	var objBillPostcode			= glbGetElementById(glbBillPostcodeName);
//	var objBillCountry			= glbGetElementById(glbBillCountryName);
	var objBillEmail			= glbGetElementById(glbBillEmailName);
	var objBillTermsAccept		= glbGetElementById(glbBillTermsName);
	
//	var strBillCountry			= getFieldValue(objBillCountry);

//	var blnPostcodeRequired = false;
	
	if (!checkRequiredField(objCardName, "Name for the Card", true, "")) return false;


	if (!checkRequiredField(objCardNumber, "Card number", true, "number")) return false;
	if (!checkRequiredField(objCardExpiryMonth, "Card expiry month", true, "")) return false;
	if (!checkRequiredField(objCardExpiryYear, "Card expiry year", true, "")) return false;
	
	var strMonth = getFieldValue(objCardExpiryMonth);

	if (strMonth.substr(0,1) == "0")						//==	Remove padded zero	
		strMonth = strMonth.substr(1,1);
	var intMonth = parseInt(strMonth);
	
	var strYear = getFieldValue(objCardExpiryYear);
	if (strYear.length == 2) strYear = "20" + strYear;
	var intYear = parseInt(strYear);
	
	var intDaysMonth = daysInMonth(intMonth, intYear);
	
	var dteExpiryDate = new Date (intDaysMonth + " " + monthName(intMonth) + " " + intYear);
	var dteNow = new Date();
	
	if (dteNow > dteExpiryDate) {
		alert (msgInvalidExpiryDate);
		objCardExpiryMonth.focus();
		return false;
	}
	
	if (!checkRequiredField(objCardIssueNumber, "Card Issue number", false, "number")) return false;

//	if (!checkRequiredField(objBillHouse, "Street address", true, "")) return false;
//	if (!checkRequiredField(objBillStreet, "Street", true, "")) return false;
//	if (!checkRequiredField(objBillTown, "Town", true, "")) return false;
//
//	if (strBillCountry == "UK") {		//==	Require the postcode for UK customers
//		blnPostcodeRequired = true;
//	} else {
//		blnPostcodeRequired = false;
//	}

//	if (!checkRequiredField(objBillPostcode, "Postcode", blnPostcodeRequired, "")) return false;
//	if (!checkRequiredField(objBillCountry, "Country", true, "")) return false;
	if (!checkRequiredField(objBillEmail, "Email address", true, "email")) return false;

	if (!objBillTermsAccept.checked) {	//==	The user has not ticked the Terms box
		alert (msgAcceptTerms);
		objBillTermsAccept.focus();
		return false;
	}

	return true;

} 
function saveValidate(){
	toBox = document.getElementById("to");
	toVal = toBox.value;
	setCookie("last_to",toVal,3);
	return checkFormPage1();
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function autoFillTo(){
	fromBox = document.getElementById("from");
	toBox = document.getElementById("to");
	if(fromBox.value != "-1"){
		fillBox(fromBox,toBox);
		toVal = getCookie("last_to");
		if(toVal != ""){
			toBox.value = toVal;
		}
	}
}

function autoFillDates(obj){
	var obDay = document.getElementById("outbound_day");
	var obMonthYear = document.getElementById("outbound_month_and_year");
	var rtDay = document.getElementById("return_day");
	var rtMonthYear = document.getElementById("return_month_and_year");
	var switchedObj = obj;
	
	if(switchedObj == obDay){
		if(obDay.value != -1){
			if((rtMonthYear.selectedIndex < obMonthYear.selectedIndex) && (rtMonthYear.selectedIndex != 0)){
				rtMonthYear.selectedIndex = obMonthYear.selectedIndex;
			}
			if((rtMonthYear.selectedIndex == obMonthYear.selectedIndex) && (obMonthYear.selectedIndex != 0)){
				if(rtDay.selectedIndex <= obDay.selectedIndex){
					rtDay.selectedIndex = obDay.selectedIndex + 1;
				}
			}
		}
	}
	else if(switchedObj == obMonthYear){
		if(obMonthYear.value != -1){
			if((rtMonthYear.selectedIndex < obMonthYear.selectedIndex) && (rtMonthYear.selectedIndex != 0)){
				rtMonthYear.selectedIndex = obMonthYear.selectedIndex;
			}
			if((rtMonthYear.selectedIndex == obMonthYear.selectedIndex) && (obMonthYear.selectedIndex != 0)){
				if(rtDay.selectedIndex <= obDay.selectedIndex){
					rtDay.selectedIndex = obDay.selectedIndex + 1;
				}
			}
		}
	}
	else if(switchedObj == rtDay){
		if(rtDay.value != -1){
			if(obMonthYear.selectedIndex == 0){
				obMonthYear.selectedIndex = 1;
			}
			if((rtMonthYear.selectedIndex < obMonthYear.selectedIndex)){
				rtMonthYear.selectedIndex = obMonthYear.selectedIndex;
			}
			if(rtMonthYear.selectedIndex == obMonthYear.selectedIndex){
				if(rtDay.selectedIndex <= obDay.selectedIndex){
					rtDay.selectedIndex = obDay.selectedIndex + 1;
				}
			}
		}
	}
	else if(switchedObj == rtMonthYear){
		if(rtMonthYear.value != -1){
			if(obMonthYear.selectedIndex == 0){
				obMonthYear.selectedIndex = 1;
			}
			if((rtMonthYear.selectedIndex < obMonthYear.selectedIndex)){
				rtMonthYear.selectedIndex = obMonthYear.selectedIndex;
			}
			if(rtMonthYear.selectedIndex == obMonthYear.selectedIndex){
				if(rtDay.selectedIndex <= obDay.selectedIndex){
					rtDay.selectedIndex = obDay.selectedIndex + 1;
				}
			}
			if(rtDay.selectedIndex == 0){
				rtDay.selectedIndex = 1;
			}
		}
	}
	
}

function getRadioVal(radObj){
	if(radObj.length){
		for(p=0;p<radObj.length;p++){
 			if(radObj[p].checked == true){
			return radObj[p].value;
 			}
		}
	}
	else{
		if (radObj.checked == true){
		return radObj.value;
		}
	}
}

function setRadioVal(radObj, radVal){
	if(radObj.length){
		for(p=0;p<radObj.length;p++){
 			if(radObj[p].value == radVal){
			return radObj[p].checked = true;
 			}
		}
	}
	else{
		radObj.checked = true;
	}
}

function countRadioObj(radObj){
	if(radObj.length){
		return radObj.length;
	}
	else{
		return 1;
	}
}

function getRadioIndex(radObj){
	if(radObj.length){
		for(p=0;p<radObj.length;p++){
 			if(radObj[p].checked == true){
			return p;
 			}
		}
	}
	else{
		return 0;
	}
}