function onload_function () {
	/* templates are calling it but I don't think there is one... */
}
function chooseChosen () {
	if (	chosen = get_cookie( "chosenOnes" )) {
		var arrayChosen = chosen.split( '|' );
		if (	chosenForm = eval( 'document.' + arrayChosen[0] ) ) {
			if(  chosenForm.elements){
				startingPoint = arrayChosen[1];
				startingPoint = startingPoint - 0;
				for (	var el = 2; el < arrayChosen.length - 1; el ++ ) {
					try {
						chosenForm.elements[startingPoint].selectedIndex = arrayChosen[el];
					} catch(e) { /* fail */ }
					startingPoint ++;
				}
			}
		}
		showHideParkingSpaces(); // Show the parking spaces if a second room is selected
		checkLGWparking();
	}
}

function checkLGWparking(){
	
	if($('form[@name=basic] select[@name=Location] :selected').val() == 'LGW'){
		document.basic.numCarParking.remove(2);
		//$('form[@name=basic] select[@name=numCarParking]').html('<option value="0">No Parking Spaces</option><option value="1">One Parking Space</option>');
	}else{
		//$('form[@name=basic] select[@name=numCarParking]').html('<option value="0">No Parking Spaces</option><option value="1">One Parking Space</option><option value="2">Two Parking Spaces</option>');
		document.basic.numCarParking.options[2] = new Option('Two Parking Spaces', '2');
	}
}

function showHideParkingSpaces () {
	var hotelForm = document.basic;
	checkLGWparking();
	try {	
		if ( hotelForm.elements ) {
			if (	hotelForm.elements['RoomType[]'][1].value == "" ) {
				document.getElementById( 'parkingDropDown' ).style.display = "none";
				document.getElementById( 'discount' ).style.display = "";
				hotelForm.numCarParking.selectedIndex = 0;
			}
			else {	document.getElementById( 'parkingDropDown' ).style.display = "";
				document.getElementById( 'discount' ).style.display = "none";
			}
		}
	}
	catch ( e ) {
	}
}

function openMetafaq(mfUrl){
window.name = "mfOpener";
winHandle = window.open(mfUrl.href, "mfWindow",
"width=600,height=460,resizable=yes");
winHandle.focus();
return false;}

function getQuote(){
document.quoteForm.quoteRef.value=document.quoteForm.quoteRef.value.toUpperCase();
document.quoteForm.submit();}

function getSearch(){
if(document.searchfrm.search.value == "" || document.searchfrm.search.value == "Search Our Site") {
alert("Please enter a search phrase to search our site");
document.searchfrm.search.focus(); } else {
document.searchfrm.search.value=document.searchfrm.search.value.toLowerCase()
document.searchfrm.search.value=document.searchfrm.search.value.replace(/&/, "and");
document.searchfrm.submit()}}

function WriteLayer(ID,parentID,sText){
if(document.layers){var oLayer=(parentID)? eval('document.'+parentID+'.document.'+ID+'.document'): document.layers[ID].document
oLayer.open()
oLayer.write(sText)
oLayer.close()}
else if(document.all)document.all[ID].innerHTML=sText
else if(parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape"){
document.getElementById(ID).innerHTML=sText}}

function convertMonth( mmm ) {
	switch ( mmm ) {
		case 'Jan': return 1;
		case 'Feb': return 2;
		case 'Mar': return 3;
		case 'Apr': return 4;
		case 'May': return 5;
		case 'Jun': return 6;
		case 'Jul': return 7;
		case 'Aug': return 8;
		case 'Sep': return 9;
		case 'Oct': return 10;
		case 'Nov': return 11;
		case 'Dec': return 12;
		default: return mmm;
	}
}

function checkformbasic(){
	var thefrm=document.basic;
	var today=new Date();
	arrivalday=thefrm.day.options[thefrm.day.selectedIndex].value;
	arrivalyear=thefrm.my.options[thefrm.my.selectedIndex].value.substr(3,4);
	arrivalmonth= convertMonth( thefrm.my.options[thefrm.my.selectedIndex].value.substr(0,3));
	thefrm.ArrivalDate.value=thefrm.day.options[thefrm.day.options.selectedIndex].value+thefrm.my.options[thefrm.my.options.selectedIndex].value;
	arrivaldate=new Date(arrivalyear,arrivalmonth-1,arrivalday,23,59);
	theday=new Date();
	if(arrivaldate<theday){
		WriteLayer('hotelserror',null,'<div align="center">Your arrival date is earlier than now</div>');
		document.getElementById('departdate').style.background='#f7e5ff';
		document.getElementById('hotel').style.color='#ff0000';
		thefrm.day.focus();
		return false
	}
	else {	document.getElementById('departdate').style.backgroundColor="#80d2ff";
		document.getElementById('hotel').style.color='#0197fd';
		WriteLayer('hotelserror',null,'<div align="center"><div id="search">Save up to 60% on Airport Hotels</div></div>')
	}

	count = 1;	

	if(count>0){
		thefrm.action=thefrm.action;
		thefrm.method="post";
	}else{
		thefrm.outday.value=arrivalday;
		thefrm.outdate.value=thefrm.my.options[thefrm.my.selectedIndex].text;
		thefrm.profile.value="default";
		thefrm.airport.value=thefrm.Location.value;
		thefrm.method="get";
		if (thefrm.action == "https://secure.holidayextras.co.uk/book-hotels/c/main,availability/") {
			// This page is for AGENTS
			thefrm.action="https://www.holidayextras.co.uk/gochauntry.html?prod=H";
		} else {
			// This page doesn't work, but should be for direct.
			thefrm.action="http://www1.holidayextras.co.uk/email/bookingengine/new_redirect_hotel.asp";
		}
	}
	if (document.getElementById('hotelHolding')) {
		document.getElementById('removehotels').style.display='none';
		document.getElementById('removeparking').style.display='';
		document.getElementById('hotelHolding').style.display='';
	}
	chosenOnes = 'basic|13|';

	for(i=13; i<(thefrm.elements.length-1); i++) {	
		chosenOnes += thefrm.elements[i].selectedIndex + '|';
	}
	document.cookie= "chosenOnes="+chosenOnes;
	thefrm.submit();
}

function validateForm(){
var theForm=document.advanced;
if( typeof(theForm.ArrivalHourMin) == 'undefined' ) { theForm = theForm[0]; }
var arrival=theForm.ArrivalHourMin.value;
var depart=theForm.DepartureHourMin.value;
arrivalyear=theForm.my.options[theForm.my.selectedIndex].value.substr(3,4);
arrivalmonth= convertMonth( theForm.my.options[theForm.my.selectedIndex].value.substr(0,3));
arrivalday=theForm.day.options[theForm.day.selectedIndex].value;
arrivalhour=theForm.ArrivalHourMin.options[theForm.ArrivalHourMin.selectedIndex].value.substr(0,2);
arrivalmin=theForm.ArrivalHourMin.options[theForm.ArrivalHourMin.selectedIndex].value.substr(3,2);
departmonth = convertMonth( theForm.r_my.options[theForm.r_my.selectedIndex].value.substr(0,3));
thedepartyear=theForm.r_my.options[theForm.r_my.selectedIndex].value.substr(3,4);
departday=theForm.r_day.options[theForm.r_day.selectedIndex].text;
departhour=theForm.DepartureHourMin.options[theForm.DepartureHourMin.selectedIndex].value.substr(0,2);
departmin=theForm.DepartureHourMin.options[theForm.DepartureHourMin.selectedIndex].value.substr(3,2);
if(depart=='' || arrival==''){
}else{
	arrivaldate=new Date(arrivalyear,arrivalmonth-1,arrivalday,arrivalhour,arrivalmin);
	thedepartdate=new Date(thedepartyear,departmonth-1,departday,departhour,departmin);
	theday=new Date();
}
if(arrival==''){
	WriteLayer('parkingerror',null,'<div align="center">Please enter your approximate arrival time</font>');
	document.getElementById('parkingdepartdate').style.backgroundColor="#f7e5ff";
	document.getElementById('parkingfrom').style.color='#ff0000';
	theForm.ArrivalHourMin.focus();
	return false;
}else{
	document.getElementById('parkingdepartdate').style.backgroundColor="#80d2ff";
	document.getElementById('parkingfrom').style.color='#0197fd';
	WriteLayer('parkingerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
}
if(depart==''){
	WriteLayer('parkingerror',null,'<div align="center">Please enter your approximate departure time</font>');
	document.getElementById('parkingreturndate').style.backgroundColor='#f7e5ff';
	document.getElementById('parkingto').style.color='#ff0000';
	theForm.DepartureHourMin.focus();
	return false;
}else{
	document.getElementById('parkingreturndate').style.backgroundColor="#80d2ff";
	document.getElementById('parkingfrom').style.color='#0197fd';
	WriteLayer('parkingerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
}
if(thedepartdate<arrivaldate){
	WriteLayer('parkingerror',null,'<div align="center">Your return date is BEFORE your arrival date</div>');
	document.getElementById('parkingreturndate').style.backgroundColor="#f7e5ff";
	document.getElementById('parkingto').style.color='#ff0000';
	theForm.my.focus();
	return false;
}else{
	document.getElementById('parkingreturndate').style.backgroundColor="#80d2ff";;
	document.getElementById('parkingfrom').style.color='#0197fd'
	document.getElementById('parkingto').style.color='#0197fd';
	WriteLayer('parkingerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
}
if(arrivaldate<theday){
	WriteLayer('parkingerror',null,'<div align="center">Your arrival date is earlier than now</div>');
	document.getElementById('parkingdepartdate').style.background='#f7e5ff';
	document.getElementById('parkingfrom').style.color='#ff0000';
	theForm.r_my.focus();
	return false;
	}
	else {	document.getElementById('parkingdepartdate').style.backgroundColor="#80d2ff";
		document.getElementById('parkingto').style.color='#0197fd';
		WriteLayer('parkingerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
	}
	if (document.getElementById('parkingHolding')) {
		document.getElementById('removeparking').style.display='none';
		document.getElementById('removehotels').style.display='';
		document.getElementById('parkingHolding').style.display='';
	
	}
	chosenOnes = 'advanced|7|';
	for(i=7; i<(theForm.elements.length-1); i++) {	
			chosenOnes += theForm.elements[i].selectedIndex + '|';
	}
	document.cookie= "chosenOnes="+chosenOnes;
	return true;
}


function validateLoungeForm(){
var theForm=document.request1;
if( typeof(theForm.ArrivalTime) == 'undefined' ) { theForm = theForm[0]; }
var arrival=theForm.ArrivalTime.value;
arrivalyear=theForm.my.options[theForm.my.selectedIndex].value.substr(3,4);
arrivalmonth= convertMonth( theForm.my.options[theForm.my.selectedIndex].value.substr(0,3));
arrivalday=theForm.day.options[theForm.day.selectedIndex].value;
arrivalhour=theForm.ArrivalTime.options[theForm.ArrivalTime.selectedIndex].value.substr(0,2);
arrivalmin=theForm.ArrivalTime.options[theForm.ArrivalTime.selectedIndex].value.substr(3,2);
if(arrival==''){
}else{
	arrivaldate=new Date(arrivalyear,arrivalmonth-1,arrivalday,arrivalhour,arrivalmin);
	theday=new Date();
	today=new Date();
	today.setDate(today.getDate()+1);
}
if(arrival==''){
	WriteLayer('loungeerror',null,'<div align="center">Please enter your approximate arrival time</font>');
	document.getElementById('loungeerror').style.color='#ff0000';
	return false;
}
else{
    document.getElementById('loungeerror').style.color='#0197fd';
	WriteLayer('loungeerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
}
if(arrivaldate<theday){
	WriteLayer('loungeerror',null,'<div align="center">Your arrival date is earlier than now</div>');
	document.getElementById('loungeerror').style.color='#ff0000';
	return false;
}
else{
	document.getElementById('loungeerror').style.color='#0197fd';
	WriteLayer('loungeerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
 }
if(arrivaldate<today){
	WriteLayer('loungeerror',null,'<div align="center">Booking within 1 day, Please call 0800 093 5478 to book</div>');
	document.getElementById('loungeerror').style.color='#ff0000';
	return false;
}
else{
	document.getElementById('loungeerror').style.color='#0197fd';
	WriteLayer('loungeerror',null,'<div align="center"><div id="search">WE GUARANTEE YOU WONT FIND CHEAPER</div></div>');
 }
return true;
}





function checkTime(objToRead,objToWrite){
	if(document.getElementById){
		var timeToCheck=parseInt(objToRead.options[objToRead.selectedIndex].value)
		var writeTo=document.getElementById(objToWrite)
		var threshold=1200
		if(timeToCheck<threshold&&isNaN(timeToCheck)!=true){
			writeTo.innerHTML="<div style='text-align:center'>Got an Early Flight?  Why Not Try an Airport Hotel</div>"
			if(writeTo.className.indexOf("emError")==-1){
				if(writeTo.className !=""){
					writeTo.calssName+=" "
				}
				writeTo.className+="emError"
				}
			}
		else if(timeToCheck>=threshold || isNaN(timeToCheck)){
			writeTo.innerHTML="<div style='text-align:center'>Book Now In Two Easy Steps</div>"
			if(writeTo.className.indexOf("emError")!=-1){
				if(writeTo.className.lastIndexOf(" ")==writeTo.className.length){
					writeTo.className=writeTo.className.subStr(0,writeTo.length-1)
				}
				writeTo.className=writeTo.className.replace(new RegExp("emError\\b"),"")
			}
		}
	}
}

var title = 0;
var name = "";
var email = "";
var errorTitle = "Please select your title.";
var errorName = "Please enter your surname.";
var erroremail = "Please enter your e-mail address.";
var invalidAddress = "Please enter a valid e-mail address.\nAddress must be in the format user@domain.com";
function setTitleIndex(selectElement)	{
title = selectElement.selectedIndex;}
function checkAddress()	{
var atIndex = email.indexOf("@");
var dotIndex = email.lastIndexOf(".");
var atIndexPlus = atIndex + 2;
var emailLength = email.length - 1;
if (atIndex < 1) { // @ cannot be at the start of the string
return false;}
if (dotIndex < atIndexPlus) { // . cannot be immediatly after @
return false;}
if (dotIndex == emailLength)	{
return false;}
else {
return true;}}
function checkSignup()		{
name = document.sendmail.surname.value;
email = document.sendmail.email.value;
if (title == 0)	{
alert(errorTitle);
return false;}
if (name.length == 0)	{
alert(errorName);
document.sendmail.surname.focus();
return false;}
else if (email.length == 0)	{
alert(erroremail);
document.sendmail.email.focus();
return false;}
else if (!checkAddress())	{
alert(invalidAddress);
return false;}
else	{
document.sendmail.submit();}}
function enterSubmit()	{
if(window.event && window.event.keyCode == 13) {
checkSignup();
return !(window.event && window.event.keyCode == 13);}
else	{
return true;}}


/*png fix (This is commented out because it effected the google maps on IE, see Sean or Paul Clarke)
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
{
document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs()
{
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--)
{
if (itsAllGood && img.src.match(/\.png$/i) != null)
{
var src = img.src;
var div = document.createElement("DIV");
div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
div.style.width = img.width + "px";
div.style.height = img.height + "px";
img.replaceNode(div);
}
img.style.visibility = "visible";
}
}*/

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
		  offset += search.length
		  // set index of beginning of value
		  end = document.cookie.indexOf(";", offset);
		  // set index of end of cookie value
		  if (end == -1)
			 end = document.cookie.length;
		  returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function qwFormSuccess() {
	$('div#holdingPage').show();
}