//== 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 msgIncludeMyAirport		= "Your journey must start from, or fly to My airport";
var msgTooManyPeople            = "You can only book tickets for up to 6 seats online. Please make multiple online bookings or phone 0870 241 8202 if you wish to book more tickets.";
var msgTooManyInfants			= "Please ensure that the number of infants flying is not more than the number of adults.";
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 msgValidFlights				= "Please select your flight(s)";
var msgInvalidNames				= "Please fill out the names of all passengers flying.";
var msgInvalidLastNames			= "Please fill out the last names of all passengers flying.";
var msgInvalidPhone				= "Please enter a valid phone number.";
var msgInvalidEmail				= "Please fill in a valid Email address.";

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 browserVersion = navigator.appVersion;
var browserVnum = browserVersion.substring(1,0);


//== 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 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 glbCardCVVName			= "card_security_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";

//==    Booking LFF

var glbDirectionName            = "direction";

//== 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	= 6;				//==	Maximum number of total Adults and children for the booking
var constMaxNumberParty			= 8;				//==	Theoretical maximum number in party (max Adults + max Infants)

//var constMyAirport	= "LGW";

//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 objDirection            = glbGetElementById(glbDirectionName);
	
	var strTotalPaymentValue	= getFieldValue(objTotalPayment);
	
    //if (objReturnDay) {
    if ((objReturnDay) && (!objDirection)) {
		objReturnDay.onchange = dateReturnChange;
	}
	
    //if (objReturnMonthYear) {
    if ((objReturnMonthYear) && (!objDirection)) {
		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;
	}
	
	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];
				}
			}
		}
		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) {
	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);
}



//==	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 (8/11/2003)
	        var regexp = / /g;
	        strCheck = strValue.replace(regexp, "");

		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
//==			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() {
    if ((navigator.appName == "Netscape") && (browserVnum < 5)) {
        return true;
    }
    else {

	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 (strOutboundDateValue) {
		var dteOutbound = new Date (strOutboundDateValue);
	}	
	

	if (strReturnDateValue != "") {									//==	Return date set
		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);


	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;
	}
    }
	

	var april10 = new Date(2006, 3, 10);


	//array for flights not bookable by destination and date
	var availability = new Array (
		new Array ("BRSDUB", "<", "april10", "Please note that these services cease from 10 April 2006."),
		new Array ("DUBBRS", "<", "april10", "Please note that these services cease from 10 April 2006."),
		new Array ("BRSNWI", ">=", "april10", "Please note that these services commence on 10 April 2006."),
		new Array ("NWIBRS", ">=", "april10", "Please note that these services commence on 10 April 2006."),
		new Array ("NQYCWL", ">=", "april10", "Please note that these services commence on 10 April 2006."),
		new Array ("CWLNQY", ">=", "april10", "Please note that these services commence on 10 April 2006."),
		new Array ("CWLMAN", ">=", "april10", "Please note that these services commence on 10 April 2006."),
		new Array ("MANCWL", ">=", "april10", "Please note that these services commence on 10 April 2006.")
	);

	var innerArray = new Array();
	var tmpStr = tmpExp = "";
	for (var i = 0; i < availability.length; i++) {
		innerArray = availability[i];
		tmpStr = strOriginAirportValue + strDestinationAirportValue;
		// has a special destination been selected?
		if (tmpStr == innerArray[0]) {
			// evaluate if message should be shown
			tmpExp = "(dteOutbound " + innerArray[1] + " " + innerArray[2] + ") || (dteReturn " + innerArray[1] + " " + innerArray[2] + ")";
			if (!eval(tmpExp)) {
				alert (innerArray[3]);
				return false;
			}
		}
	}

// Save the state of the iframes for people clicking back and forth. 

toBox = document.getElementById("to");
fromBox = document.getElementById("from");
dayoutBox= document.getElementById("outbound_day");
monthoutBox= document.getElementById("outbound_month_and_year");
daybackBox = document.getElementById("return_day");
monthbackBox = document.getElementById("return_month_and_year");
adultBox = document.getElementById("idNumAdults");
childBox = document.getElementById("idNumKids");
infantBox = document.getElementById("idNumInfants");
fromVal = fromBox.value;
toVal = toBox.value;
dayoutVal= dayoutBox.value;
monthoutVal= monthoutBox.value;
monthbackVal= monthbackBox.value;
daybackVal= daybackBox.value;
adultVal= adultBox.value;
childVal= childBox.value;
infantVal= infantBox.value;

setCookie("last_from",fromVal,3);
setCookie("last_to",toVal,3);
setCookie("day_out",dayoutVal,3);
setCookie("month_out",monthoutVal,3);
setCookie("month_back",monthbackVal,3);
setCookie("day_back",daybackVal,3);
setCookie("adults",adultVal,3);
setCookie("children",childVal,3);
setCookie("infants",infantVal,3);


// Newquay airport is closed, whoops! 

var month=document.forms[0].MONTHYEAR.selectedIndex;
godate=document.forms[0].MONTHYEAR.options[month].value;
var day=document.forms[0].DAY.selectedIndex;
goday=document.forms[0].DAY.options[day].value;
var rmonth=document.forms[0].RMONTHYEAR.selectedIndex;
backdate=document.forms[0].RMONTHYEAR.options[rmonth].value;


	if((strOriginAirportValue == "NQY") || (strDestinationAirportValue == "NQY")){

// they are going to Newquay

if (godate.indexOf('2008') !=-1)
	   {
       // they want to travel in 2008
	    if (godate=="DEC2008")
       		// in December
       		{ 
		// Are they trying to go before the 20th?                
		if (day<19)
			{alert("For customers booking to or from Newquay for travel between 01 and 19 December inclusive.\n\nOrigin Newquay\n\nPlease note that Newquay Airport is closed between 01 and 19 December.\nFlights will instead operate from Plymouth.\nGround transport will be provided between Newquay and Plymouth by Newquay Airport.\nPlease make your booking as normal but ensure that you report for your flight\nat least 2 hours prior to the scheduled departure time.\nAlternatively you may wish to book your flight from Plymouth. \n\nDestination Newquay\n\nPlease note that Newquay Airport is closed between 01 and 19 December.\nFlights will instead operate to Plymouth and ground transport will be provided on arrival between Plymouth and Newquay by Newquay Airport.  This journey takes approximately 75 minutes.\nAlternatively you may wish to book your flight to Plymouth.")

        
			}

      		 }
		
	    }
		
	}
	
	return true;	// Checks passed successfully
} 



//==	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(msgValidFlights);
		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(msgValidFlights); return false };
	
	var obVal = getRadioVal(col);
	var rtVal = getRadioVal(col2);	
	if(rtVal){
	var obValArray = obVal.split("::");
	var rtValArray = rtVal.split("::");
	
	if((obValArray[2] == rtValArray[2]) && (obValArray[3] == rtValArray[3]) && (obValArray[4] == rtValArray[4])){
		var obArriveMin = convertMinutes(obValArray[6]);
		var rtDepartMin = convertMinutes(rtValArray[5]);
		
		var timeDiff = rtDepartMin - obArriveMin;
		if(timeDiff < 0){
			alert('Please make certain your return flight time is AFTER your arrival flight time!')
			return false;
		}
		if(timeDiff < 60){
			alert('Please make certain your return flight time is at least 60 minutes AFTER your arrival flight time!');
			return false;
		}
	}

	}
	
	
	
	return true;
}	

function convertMinutes(time){
	// time must be in 24 hour clock in format (h)h:mm
	
	timeArray = time.split(":");
	var allMinutes = 60 *  parseInt(timeArray[0]) + parseInt(timeArray[1]);
	return allMinutes;
	
}

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 osummary(){
	
}
function rsummary(){
	
}
//==	bool checkFormPage3() 
//
//==		returns true. no checks required.

function checkFormPage3() {
	//== No validation required on this page
	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", false, "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;
	var emailObj = document.getElementById("contact_email");
	
	
	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(msgInvalidNames);
				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(msgInvalidLastNames);
				return false;
			}
		}
	
		// check the ID/Passport fields	
//		if (strName == "PAS")
//		{
////			var objAgeGroup = getElByName("AGE"+col[i].name.substring(8,9));
//
//	//		if (objAgeGroup.value == "Adult")
//			{
//				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(msgInvalidPhone);
				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(msgInvalidEmail);
				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(msgInvalidAge);
                         return false;
                 }
		}
	}
//	escapeEmail(emailObj);
	return true;
}


//==	bool checkFormPage5() 
//
//==		returns true if the following tests are passed:
//==			has a valid card name
//==			has a valid card type
//==			has a valid card number
//==			has a valid card expiry month
//==			has a valid card expiry year
//==			has a valid card
//==			Home name / number entered
//==			Home street entered
//==			Home town entered
//==			Home postcode entered (if country UK)
//==			Country selected
//==			Email address entered and valid
//==			Booking terms have been accepted
//==			No field longer than 100 characters
//==		if any check fails, the relevant field is focused and the function
//==		returns false.

function checkFormPage5() {
	var objCardName				= glbGetElementById(glbCardNameName);

	var objCardType                         = glbGetElementById(glbCardTypeName);

	var objCardNumber			= glbGetElementById(glbCardNumberName);
	var objCardCVV				= glbGetElementById(glbCardCVVName);

	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 (objCardType.selectedIndex == 0){
            alert("Please select a Credit Card type");
            //objClickable[0].value = 'no';
            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;
	if (!checkRequiredField(objCardCVV, "Card CVV number", true, "number")) 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();

	// set expiration date to be the very last second of that month
	dteExpiryDate.setUTCHours(23);
	dteExpiryDate.setUTCMinutes(59);
	dteExpiryDate.setUTCSeconds(59);
	
	if (dteNow > dteExpiryDate) {
		alert (msgInvalidExpiryDate);
		objCardExpiryMonth.focus();
		return false;
	}
	
	if (!checkRequiredField(objCardIssueNumber, "Card Issue number", false, "number")) return false;

	//if (!checkRequiredField(objBillHouse, "House name", true, "")) return false;
	if (!checkRequiredField(objBillHouse, "Street", 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;
	}


	// if no error, disable submit button and return true
	var objSubmitButton =	 glbGetElementById("submitButton");	
	objSubmitButton.disabled = 'true';
//	escapeEmail(objBillEmail);
	return true;

} 

function openTermsWindow () {
	
	termsWindow = window.open('booking_terms.html','TandC','scrollbars=yes,width=550,height=450,resizable=yes');
	termsWindow.focus();	
}


//= this version added 9/17/2003
function checkFormLFF(passForm)
{
  if ((navigator.appName == "Netscape") && (browserVnum < 5)) {
      return true;
  }
  else {

	var objOriginAirport			= glbGetElementById(glbOriginAirportName);
	var objDestinationAirport		= glbGetElementById(glbDestinationAirportName);
	var objOutboundMonthYear		= glbGetElementById("idMONTHYEAR");
	var objReturnMonthYear			= glbGetElementById("idRMONTHYEAR");
	var objAdults					= glbGetElementById(glbAdultsName);
	var objChildren					= glbGetElementById(glbChildrenName);
	var objInfants					= glbGetElementById(glbInfantsName);
	
	var strOutboundMonthYearValue	= getFieldValue(objOutboundMonthYear);
	var strReturnMonthYearValue		= getFieldValue(objReturnMonthYear);
	var strOriginAirportValue		= getFieldValue(objOriginAirport);
	var strDestinationAirportValue	= getFieldValue(objDestinationAirport);
	var strAdultsValue				= getFieldValue(objAdults);
	var strChildrenValue			= getFieldValue(objChildren);
	var strInfantsValue				= getFieldValue(objInfants);

	var objDirection				= glbGetElementById(glbDirectionName);
	var strDirectionValue			= getFieldValue(objDirection);

	var objOutboundDay				= passForm.DAY;

	if ((strReturnMonthYearValue != "-1") && (strReturnMonthYearValue != "")) {
		var objReturnDay				= passForm.RDAY;
    }

	if (strDirectionValue == "PROCEED") {
		var strOutboundDayValue	= "";
		var dayCheckedIndex = "-1";
		if (objOutboundDay.length) {
			for (var i=0; i < objOutboundDay.length; i++) {
				if (objOutboundDay[i].checked) {
					var dayCheckedIndex = i;
				}
			}
			if (dayCheckedIndex != "-1") {
				var strOutboundDayValue	= objOutboundDay[dayCheckedIndex].value;
			}
		}
		else {
			if (objOutboundDay.checked) {
				var strOutboundDayValue	= objOutboundDay.value;
			}
		}

		if (strOutboundDayValue == "") {
			alert (msgEnterValidOutboundDate);
			return false;
		}
		if (objReturnDay) {
			var strReturnDayValue	= "";
			var rdayCheckedIndex = "-1";
			if (objReturnDay.length) {
				for (var i=0; i < objReturnDay.length; i++) {
					if (objReturnDay[i].checked) {
						var rdayCheckedIndex = i;
					}
				}
				if (rdayCheckedIndex != "-1") {
					var strReturnDayValue	= objReturnDay[rdayCheckedIndex].value;
				}
			}
			else {
				if (objReturnDay.checked) {
					var strReturnDayValue	= objReturnDay.value;
				}
			}
			if (strReturnDayValue == "") {
				alert (msgEnterValidReturnDate);
				return false;
			}
        }
		var strOutboundDateValue = strOutboundDayValue + " " + strOutboundMonthYearValue.substr(0,3) + " " + strOutboundMonthYearValue.substr(3,4);
		var strReturnDateValue = strReturnDayValue + " " + strReturnMonthYearValue.substr(0,3) + " " + strReturnMonthYearValue.substr(3,4);
	}
	else {
		var strOutboundDateValue = "01 " + strOutboundMonthYearValue.substr(0,3) + " " + strOutboundMonthYearValue.substr(3,4);
		var strReturnDateValue = "01 " + strReturnMonthYearValue.substr(0,3) + " " + strReturnMonthYearValue.substr(3,4);
	}

	if (strOriginAirportValue == strDestinationAirportValue) {						//==	Origin and Destination the same
		alert(msgEnterDifferentDest);
		//objDestinationAirport.focus();
		return false;
	}
	
//	if ((strOriginAirportValue != constMyAirport) && 
//		(strDestinationAirportValue != constMyAirport)) {	//==	MyAirport not Origin or Destination
//		alert(msgIncludeMyAirport);
//		//objOriginAirport.focus();
//		//return true;
//		return false;
//	}
	
	
	if (strOutboundMonthYearValue == "-1") {
		alert (msgEnterValidOutboundDate);
		//objReturnMonthYear.focus();
		return false;
	}
	
	if ((strReturnDateValue != "") || (strReturnDateValue != "-1")) {													//==	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;
	}
  }

// LFF NQY check
/*
var month=document.forms[0].MONTHYEAR.selectedIndex;
godate=document.forms[0].MONTHYEAR.options[month].value;
var rmonth=document.forms[0].RMONTHYEAR.selectedIndex;
backdate=document.forms[0].RMONTHYEAR.options[rmonth].value;
if (godate=="DEC2008" || backdate=="DEC2008")
{
	if((strOriginAirportValue == "NQY") || (strDestinationAirportValue == "NQY")){
		alert("For customers booking to or from Newquay for travel between 01 and 19 December inclusive.\n\nOrigin Newquay\n\nPlease note that Newquay Airport is closed between 01 and 19 December.\nFlights will instead operate from Plymouth.\nGround transport will be provided between Newquay and Plymouth by Newquay Airport.\nPlease make your booking as normal but ensure that you report for your flight\nat least 2 hours prior to the scheduled departure time.\nAlternatively you may wish to book your flight from Plymouth. \n\nDestination Newquay\n\nPlease note that Newquay Airport is closed between 01 and 19 December.\nFlights will instead operate to Plymouth and ground transport will be provided on arrival between Plymouth and Newquay by Newquay Airport.  This journey takes approximately 75 minutes.\nAlternatively you may wish to book your flight to Plymouth.")
	}
}
*/

    return true;
}

// function checkChangePage3() added 4/23/07

function checkChangePage3(){

var OBFlight; 
var RTFlight;

if(OBFlight = document.aForm.SELECT_LINE){
var yes1 = 0;

if(OBFlight.length){
for(i=0;i<OBFlight.length;i++){
 if(OBFlight[i].checked == true){
	yes1 = 1;
 }
}
}
else{
if(OBFlight.checked == true){
	yes1 = 1;
 }
}

if(yes1 == 0){
	alert("Please select a new flight date");
	return false;
}
}


if(RTFlight = document.aForm.SELECT_LINE2){
var yes2 = 0;

if(RTFlight.length){
for(i=0;i<RTFlight.length;i++){
 if(RTFlight[i].checked == true){
	yes2 = 1;
 }
}
}
else{
if(RTFlight.checked == true){
	yes2 = 1;
 }
}
	if(yes2 == 0){
	alert("Please select a new flight date");
	return false;
	}
}

return true;

}


function escapeEmail(emailObj){
	var oldval = emailObj.value;
	var newval;
	
	var valArry = oldval.split('@');
//	valArry[0] = valArry[0].replace(/!/g, "\\!");
//	valArry[0] = valArry[0].replace(/#/g, "\\#");
//	valArry[0] = valArry[0].replace(/\$/g, "\\$");
//	valArry[0] = valArry[0].replace(/%/g, "\\%");
//	valArry[0] = valArry[0].replace(/\*/g, "\\*");
//	valArry[0] = valArry[0].replace(/\//g, "\\/");
//	valArry[0] = valArry[0].replace(/\?/g, "\\?");
//	valArry[0] = valArry[0].replace(/\|/g, "\\|");
//	valArry[0] = valArry[0].replace(/{/g, "\\{");
//	valArry[0] = valArry[0].replace(/\^/g, "\\^");
//	valArry[0] = valArry[0].replace(/}/g, "\\}");
	valArry[0] = valArry[0].replace(/`/g, "\\`");
//	valArry[0] = valArry[0].replace(/~/g, "\\~");
//	valArry[0] = valArry[0].replace(/&/g, "\\&");
	valArry[0] = valArry[0].replace(/'/g, "\\'");
//	valArry[0] = valArry[0].replace(/\+/g, "\\+");
//	valArry[0] = valArry[0].replace(/\-/g, "\\-");
//	valArry[0] = valArry[0].replace(/=/g, "\\=");
//	valArry[0] = valArry[0].replace(/_/g, "\\_");
	
	newval = valArry[0] + "@" + valArry[1];
	emailObj.value = newval;
	
}

function stripEmail(emailObj){
	var emailVal = emailObj.value;
	if (emailVal != ""){
		var checkEx = /[\!\#\$\%\*\/\?\|\^\{\}\`\~\&\'\+\-\=\_]/;
		if(checkEx.test(emailVal)){
		emailObj.value = "";	
		}
	}
}

// Added to store last city searched. 

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 "";
}





