// A global var used for js to access the form elements
var thefrm = document.searchForm;
noRail = false;
singleTraveller = false;
 
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
	}

}

//JP - 30th Nov 2007 - functions for dates
function convertMonth(month) {
	var returnMonth = 0;
	if (!(month/1) && month != 0) {
		switch(month) {
			case "Jan":
				returnMonth = 0;
				break;
			case "Feb":
				returnMonth = 1;
				break;
			case "Mar":
				returnMonth = 2;
				break;
			case "Apr":
				returnMonth = 3;
				break;
			case "May":
				returnMonth = 4;
				break;
			case "Jun":
				returnMonth = 5;
				break;
			case "Jul":
				returnMonth = 6;
				break;
			case "Aug":
				returnMonth = 7;
				break;
			case "Sep":
				returnMonth = 8;
				break;
			case "Oct":
				returnMonth = 9;
				break;
			case "Nov":
				returnMonth = 10;
				break;
			case "Dec":
				returnMonth = 11;
				break;
		}
	}
	else {
		switch(month) {
			case 0:
				returnMonth = "Jan";
				break;
			case 1:
				returnMonth = "Feb";
				break;
			case 2:
				returnMonth = "Mar";
				break;
			case 3:
				returnMonth = "Apr";
				break;
			case 4:
				returnMonth = "May";
				break;
			case 5:
				returnMonth = "Jun";
				break;
			case 6:
				returnMonth = "Jul";
				break;
			case 7:
				returnMonth = "Aug";
				break;
			case 8:
				returnMonth = "Sep";
				break;
			case 9:
				returnMonth = "Oct";
				break;
			case 10:
				returnMonth = "Nov";
				break;
			case 11:
				returnMonth = "Dec";
				break;
		}
	}
	return returnMonth;
}


function checkRoomType( ddown) {
	thefrm = document.searchForm;
	if( ddown.options[ddown.selectedIndex].value == '1') {
		singleTraveller = true;
		thefrm.railRadio.disabled = true;
		thefrm.railRadio.checked = false;
		showHideRail();
		document.getElementById('incRail').style.display = 'none';
		document.getElementById('noRailSingleRoom').style.display = '';
	} else {
		singleTraveller = false;
		thefrm.railRadio.disabled = false;
		if(!(noRail)) {
			document.getElementById('incRail').style.display = '';
		}
		document.getElementById('noRailSingleRoom').style.display = 'none';
	}
}

function selectPerformance() {
	thefrm = document.searchForm;
	if ( thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text == 'Meal and Show only - NEW!' ) {
		// Hide hotel rooms and show number of tickets
		thefrm.ArrivalDateDrop.disabled = true;
		thefrm.NightsDrop.disabled = true;
		thefrm.railRadio.disabled = true;
		thefrm.railRadio.checked = false;
		showHideRail();
		document.getElementById('incRail').style.display = 'none';
		document.getElementById('noRailMeal').style.display = '';
		document.getElementById( 'roomTypeDrop' ).style.display = 'none';
		document.getElementById( 'mealTicketsDrop' ).style.display = '';
	} else {
		// Show hotel rooms, night etc
		thefrm.ArrivalDateDrop.disabled = false;
		thefrm.NightsDrop.disabled = false;
		thefrm.railRadio.disabled = false;
		document.getElementById('incRail').style.display = '';
		document.getElementById('noRailMeal').style.display = 'none';
		document.getElementById( 'roomTypeDrop' ).style.display = '';
		document.getElementById( 'mealTicketsDrop' ).style.display = 'none';
	}
}

function showHasStarted() {
	thefrm = document.getElementById( "searchForm" );
	showChosen = thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value;
	returnVal = true;
	if (	showChosen != "" && showChosen!="select" ) {
	try { 
		openFromDate = aOpenFromDates[showChosen][0];
		// returnVal = (convertDate(openFromDate ).getTime() <= convertDate( frm.ShowDate.options[frm.ShowDate.selectedIndex].value ).getTime()) // should this be thfrm and not frm? PC fixed, 23/07/07
		returnVal = (convertDate(openFromDate ).getTime() <= convertDate( thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value ).getTime());
		} catch(e) { }
	}
	return returnVal;
}

function convertDate ( datePassed ) {
    	var d2 = datePassed;
	if (!d2.getDate) {
		d2 = new Date( "20" + datePassed.substr( 5, 2 ), getMonthInt(datePassed.substr( 2, 3 ) ), datePassed.substr( 0, 2 ) );
	}
	return d2;
}

// Function to check all required fields have been filled in
function submitForm() {

	thefrm = document.searchForm;
	var errMsg = '';
	var thedate = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].text;
	// Set the back page
	thefrm.Referer.value = this.document.URL;

	var theShow = thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value;
	var theShowName = thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].text;

	if (theShow == "") {
		thefrm.request.value = "1"
	} else {
		thefrm.request.value = "3"
	}
	
	if (	thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value == "select" ) {
		errMsg += "Please select a show\n";
	}
	
	if(!showHasStarted()) {
		errMsg +=  theShowName + " opens on " + aOpenFromDates[thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value][1] + ". Please search for a later date.\n";
	}
	
	if (	thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text != 'Meal and Show only - NEW!' ) {
		if ( thefrm.ArrivalDateDrop.options[thefrm.ArrivalDateDrop.options.selectedIndex].value == "select" ) {
			errMsg +=  "Please select the day of arrival at the hotel\n";
		}
		if ( thefrm.NightsDrop.options[thefrm.NightsDrop.options.selectedIndex].value=="0" ) {
			errMsg += "Please select the number of nights to stay at the hotel\n";
		} else {
			thefrm.Nights.value = thefrm.NightsDrop.options[thefrm.NightsDrop.options.selectedIndex].value;
		}
	}
	if (thefrm.ShowDate.options[thefrm.ShowDate.options.selectedIndex].value=="select") {
		errMsg += "Please select a show date\n";
	}
	var railSelected = ( thefrm.railRadio.checked || ( thefrm.railRadio.options && thefrm.railRadio.options[thefrm.railRadio.selectedIndex].value == 1 ));



	if ( thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text != 'Meal and Show only - NEW!' ) {
		switch ( thefrm.Rooms.value ) {
			case "1": 
				thefrm.Room1.value = "S10";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 1;
				if (	railSelected ) {
					errMsg += "Single rooms and rail travel cannot be booked, please select an alternative option\n";
				}
				thefrm.RailAdults.value = 1;
				thefrm.RailChildren.value = 0;
				break;
			case "2": 
				thefrm.Room1.value = "A20";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 2;
				thefrm.RailAdults.value = 2;
				thefrm.RailChildren.value = 0;
				break;
			case "3": 
				thefrm.Room1.value = "B20";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 2;
				thefrm.RailAdults.value = 2;
				thefrm.RailChildren.value = 0;
				break;
			case "4": 
				thefrm.Room1.value = "A20";
				thefrm.Room2.value = "A20";
				thefrm.Adults.value = 4;
				thefrm.RailAdults.value = 4;
				thefrm.RailChildren.value = 0;
				break;
			case "5": 
				thefrm.Room1.value = "B20";
				thefrm.Room2.value = "B20";
				thefrm.Adults.value = 4;
				thefrm.RailAdults.value = 4;
				thefrm.RailChildren.value = 0;
				break;
			case "6": 
				thefrm.Room1.value = "A20";
				thefrm.Room2.value = "B20";
				thefrm.Adults.value = 4;
				thefrm.RailAdults.value = 4;
				thefrm.RailChildren.value = 0;
				break;			
			case "7":  
				thefrm.Room1.value = "C12";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 3;
				thefrm.RailAdults.value = 1;
				thefrm.RailChildren.value = 2;
				break;
			case "8": 
				thefrm.Room1.value = "C21";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 3;
				thefrm.RailAdults.value = 2;
				thefrm.RailChildren.value = 1;
				break;
			case "9": 
				thefrm.Room1.value = "C30";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 3;
				thefrm.RailAdults.value = 3;
				thefrm.RailChildren.value = 0;
				break;
			case "10":
				thefrm.Room1.value = "D22";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 4;
				thefrm.RailAdults.value = 2;
				thefrm.RailChildren.value = 2;
				break;
			case "11":
				thefrm.Room1.value = "D13";
				thefrm.Room2.value = "";
				thefrm.Adults.value = 4;
				thefrm.RailAdults.value = 1;
				thefrm.RailChildren.value = 3;
				break;

			default:
				errMsg += "Please select your room type\n";
				break;
		}
		
		if( false && theShow=="SHONME" && (!(thefrm.Room1.value=="A20" || thefrm.Room1.value=="B20") || (thefrm.Room2.value!="" && !(thefrm.Room2.value=="A20" || thefrm.Room2.value=="B20") ) ) ) {
			errMsg += "Only Double and Twin rooms are available for this show.\n";
		}
		
		//thefrm.profile.value = "default_test";
		thefrm.is_showmeal.value = "N";
		thefrm.ArrivalDate.value = thefrm.ArrivalDateDrop.options[thefrm.ArrivalDateDrop.options.selectedIndex].value;
	} else {
		if (	railSelected ) {
			errMsg += "Rail travel cannot be booked with the Meal and Show package, please select an alternative option\n";
		} else {
			if ( thefrm.mealTickets.options[thefrm.mealTickets.options.selectedIndex].value == '0' ) {
				errMsg += "Please select your number of tickets\n";
			} else {
				switch( thefrm.mealTickets.options.selectedIndex ) {
					case 1:
						thefrm.Room1.value = "S10";
						break;
					case 2:
						thefrm.Room1.value = "A20";
						break;
					case 3:
						thefrm.Room1.value = "C12";
						break;
					case 4:
						thefrm.Room1.value = "D22";
						break;
			}
			thefrm.Room2.value = "";
			thefrm.Nights.value = "1";
			thefrm.Adults.value = thefrm.mealTickets.options[thefrm.mealTickets.options.selectedIndex].value;
			thefrm.ArrivalDate.value = thefrm.ShowDate.options[thefrm.ShowDate.options.selectedIndex].value;			}
			//thefrm.profile.value = "showandmeal";
			thefrm.is_showmeal.value = "Y";
		}
	}
	if (thefrm.selectPerformanceType.options[thefrm.selectPerformanceType.options.selectedIndex].value == "select")	{
		errMsg += "Please select a Performance Type\n";
	}
	if (thedate.substr( 0, 3 ) == "Sun") {
		errMsg += "Sorry there are no shows available on a Sunday, please select another day\n";
	}
	
	if ((thedate.substr( 0, 3 ) == "Wed") && theShow == "SHOBME") 
	{
		errMsg += "Sorry Blue Man Group is not available on Wednesdays, please select another day\n";
	}
	
	if ((thedate.substr( 0, 3 ) == "Mon") && theShow == "SHOLKE") 
	{
		errMsg += "Sorry Lion King is not available on Monday, please select another day.\n";
	}

	// PC removed, as per http://abcfusion.abcmail.co.uk/isupport/project_items_detail.php?item_id=5824	
	// if ( (thedate.substr( 0, 3 ) == "Sat" || thedate.substr( 0, 3 ) == "Fri") && ( /* theShow == "SHOGRE" || theShow == "SHOGRF" || */ theShow == "SHOJOE"|| theShow == "SHOJOF") && thefrm.Nights.value == "1") {
	 // 	errMsg += "Sorry, Joseph and the Amazing Technicolor Dreamcoat are only available for 2 night stays or more on Fridays and Saturdays \n";
	// }
	
	//var myDate = new Date(); 
	//myDate.setDate(myDate.getDate()+14);
	
	//var showDateCom = new Date (thefrm.ShowDate.value.dateConvert('DDMMMYY', 'DD MMM 20YY'))

	//if ( theShow == "SHODDE" && showDateCom <= myDate ){
		//if (thedate.substr( 0, 3 ) == "Fri" || thedate.substr( 0, 3 ) == "Sat") {
		//}
		//else {
			//errMsg += "Excluding Friday and Saturdays Dirty Dancing bookings must be made 14 days in advance \n";
		//}
	//}
	
	// Meal and Show Alerts 
	
	if ( (theShow == "SHOWRE" || theShow == "SHOLME") && thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text == 'Meal and Show only - NEW!' ) {
		if (thedate.substr( 0, 3 ) == "Fri" || thedate.substr( 0, 3 ) == "Sat" || thedate.substr( 0, 3 ) == "Sun") {			
			// For loop to find show name from dropdown
			for ( index = 0; index < thefrm.ShowSelect.length; index++ ) {
				if ( thefrm.ShowSelect[index].value == theShow ) {
					showName = thefrm.ShowSelect[index].text;
				}
			}
			errMsg += "Sorry, meal and show packages are only available for Monday - Thursday evening performances of " + showName + "\n";
		}
	}
						
	if ( (theShow == "SHOCGE" || theShow == "SHOSTE" || theShow == "SHOBBE" || theShow == "SHODCE" || theShow == "SHODSE" || theShow == "SHOWBE") && thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text == 'Meal and Show only - NEW!' ) {
		if (thedate.substr( 0, 3 ) == "Sat" || thedate.substr( 0, 3 ) == "Sun") {			
			// For loop to find show name from dropdown
			for ( index = 0; index < thefrm.ShowSelect.length; index++ ) {
				if ( thefrm.ShowSelect[index].value == theShow ) {
					showName = thefrm.ShowSelect[index].text;
				}
			}
			errMsg +=  "Sorry, meal and show packages are only available for Monday - Friday evening performances of " + showName + "\n";
		}
	}
						
	if ( theShow == "SHOBME" && thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text == 'Meal and Show only - NEW!' ) {
		if (thedate.substr( 0, 3 ) == "Tue" || thedate.substr( 0, 3 ) == "Wed" || thedate.substr( 0, 3 ) == "Sun") {			
			// For loop to find show name from dropdown
			for ( index = 0; index < thefrm.ShowSelect.length; index++ ) {
				if ( thefrm.ShowSelect[index].value == theShow ) {
					showName = thefrm.ShowSelect[index].text;
				}
			}
			errMsg += "Sorry, meal and show packages are only available for Monday, Thursday & Saturday evening performances of " + showName + "\n";
		}
	}
	
	//if ((theShow=="SHONME"&&false&&((thedate.substr(0,3)!="Sat")&&(thedate.substr(0,3)!="Thu"))||(theShow!="SHONME"&&thedate.substr(0,3)!="Sat"))&&document.searchForm.selectPerformanceType.options[document.searchForm.selectPerformanceType.options.selectedIndex].value=="MAT") {


	/*if (	thedate.substr( 0, 3 ) == "Sat" && theShow == "SHODDE" && thefrm.Nights.value == "1" ) {
		errMsg +=  "Sorry, Dirty Dancing is only available for 2 night stays or more on Saturdays\n";
	}*/

	if (	railSelected && thefrm.DeptStation.options[thefrm.DeptStation.selectedIndex].value == '') {
		errMsg += 'You have selected rail, but not chosen a station from which to depart.\n';
	}
	if (!thefrm.railRadio.disabled) {
		if (	! singleTraveller && thefrm.railCheckbox.options && thefrm.railCheckbox.options[thefrm.railCheckbox.selectedIndex].value == '' ) {
			errMsg += 'Please select whether or not you would like to include rail and save up to 40%.';
		}
	}
	else {
		thefrm.railRadio.selectedIndex = 2;
	}

	today = new Date();
	matleadtime = dateAdd( today, 8, 0, 0 );
	theshowdate = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 0, 2 ) + ' ' + thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 2 ,5 ) + ' 20' + 					thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 5, 7 );

	theshowdate = new Date( theshowdate );
	
	if (theshowdate < matleadtime &&  thefrm.selectPerformanceType.options[thefrm.selectPerformanceType.options.selectedIndex].value == "MAT") {
		matleadtime = matleadtime.toUTCString();
		errMsg += "Sorry Matinée shows are only available after "+matleadtime.substring(0,3)+' '+matleadtime.substring(5,7)+' '+matleadtime.substring(7,11)+', '+matleadtime.substring(11,16) + '\n';
	}
	if (thefrm.Show.value.length < 6)	{
		thefrm.Show.value = "";
	}
	
	changePT();
	
	var showIndex = -1;
	for( var srchShow = 0; srchShow < showCodes.length; srchShow++) {
		if( showCodes[srchShow] == thefrm.Show.value) {
			// Have found index for show
			showIndex = srchShow;
			break;
		}
	}
	
	if( showIndex != -1) {
		// We have a show with closed dates
		// Loop through their show dates
		for( var closedDatesIndex = 0; closedDatesIndex < closedDates[showIndex].length; closedDatesIndex++) {
			if( (theshowdate >= closedDates[showIndex][closedDatesIndex][0]) && (theshowdate < closedDates[showIndex][closedDatesIndex][1])) {
				errMsg += 'Sorry, the show you have selected is not available on that day with dinner, please choose again\n';
				break;
			}
		}
	}
	
	if (	errMsg == '' ) {
		return true;
	}
	else {	alert( errMsg );
		return false;
	}
}

// Function to add and option element to a select object
function addOption( obj, text, val ) { 
	if (	obj && obj.options ) {
		obj.options[ obj.options.length ] = new Option( text, val );
	}
}

// Function to remove all options for a select object
function delAllOptions( obj ) {
	if (	obj && obj.options ) {
		obj.options.length = 0;
	}
}

// Function to prepend an zero to the front of single digit numbers
function addZero( vNumber ) { 
	return ( ( vNumber < 10 ) ? "0" : "" ) + vNumber;
} 

// Function to add a time period to an existing date
function dateAdd( startDate, numDays, numMonths, numYears ) {
	var returnDate = new Date( startDate.getTime() );
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if ( month > 11 ) {
		yearsToAdd = Math.floor( ( month + 1 ) / 12 );
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth( month );
	returnDate.setFullYear( returnDate.getFullYear()	+ yearsToAdd );
	
	returnDate.setTime( returnDate.getTime() + 60000 * 60 * 25 * numDays );
	
	return returnDate;
}

//	Function to amend show code based on performance type and dinner package
function changePT()	{
	thefrm = document.searchForm;
	var PerformanceType = thefrm.selectPerformanceType[thefrm.selectPerformanceType.options.selectedIndex].value;
	var theShow = thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value;
		var thedate = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].text;
	if(theShow != "") {
		if (thefrm.selectPerformanceType[thefrm.selectPerformanceType.selectedIndex].text == 'Meal and Show only - NEW!' )	{
			thefrm.Show.value = theShow.substr(0,5) + "N";
		} else {
			if (PerformanceType == "EVE")	{
				thefrm.Show.value = theShow.substr(0,5) + "E";
			}	else if (PerformanceType == "DIN")	{
				thefrm.Show.value = theShow.substr(0,5) + "F";
			}	else if (PerformanceType == "MAT")	{
				thefrm.Show.value = theShow.substr(0,5) + "M";
			}
			else if (PerformanceType == "TEA")	{
				thefrm.Show.value = theShow.substr(0,5) + "T";
			}
		}
		thefrm.PerformanceType.value = "";
	}	else if (theShow == "")	{
		thefrm.PerformanceType.value = PerformanceType;
	}
	// Function for September offer - switch Les Mis code to SHOLMO
	//	if (thedate.substr( 0, 3 ) != "Sat" && thefrm.ShowDate.options[thefrm.ShowDate.options.selectedIndex].value.substr(2,3) == "Sep" && theShow == "SHOLME") 
//	{
//	thefrm.Show.value = "SHOLMO";
	//	}

}
var preTTDates="n";
function setTakeThat() {

/*	preTTDates=document.getElementById('ShowDate').innerHTML;
	storeDates();
//	var shit='<option value="select">Select... (Limited Availability)</option><option value="21Aug07">Tue 21 Aug, 2007</option><option value="22Aug07">Wed 22 Aug, 2007</option><option value="23Aug07">Thu 23 Aug, 2007</option><option value="24Aug07">Fri 24 Aug, 2007</option><option value="25Aug07">Sat 25 Aug, 2007</option><option value="26Aug07">Sun 26 Aug, 2007</option><option value="" disabled></option><option value="27Aug07">Mon 27 Aug, 2007</option><option value="28Aug07">Tue 28 Aug, 2007</option><option value="29Aug07">Wed 29 Aug, 2007</option><option value="30Aug07">Thu 30 Aug, 2007</option><option value="31Aug07">Fri 31 Aug, 2007</option><option value="01Sep07">Sat 01 Sep, 2007</option>';
//	document.searchForm.ShowDate.innerHTML='<option value="select">'+shit;
//	alert('IE7 THINKS THE SHOWDATE BOX CONTAINS THIS:\n'+document.searchForm.ShowDate.innerHTML+"\nIT IS PROBABLY LYING BECAUSE THE VARIABLE I SET IT TO IS:\n"+shit);

	delAllOptions( document.getElementById('ShowDate') );
	addOption( document.getElementById('ShowDate'), "Night of Show:");
	addOption( document.getElementById('ShowDate'), "Tue 21 Aug 2007", "21Aug07");
	addOption( document.getElementById('ShowDate'), "Wed 22 Aug 2007", "22Aug07");	
	addOption( document.getElementById('ShowDate'), "Thu 23 Aug 2007", "23Aug07");
	addOption( document.getElementById('ShowDate'), "Fri 24 Aug 2007", "24Aug07");
	addOption( document.getElementById('ShowDate'), "Sat 25 Aug 2007", "25Aug07");
	addOption( document.getElementById('ShowDate'), "", "");
	addOption( document.getElementById('ShowDate'), "Mon 27 Aug 2007", "27Aug07");
	addOption( document.getElementById('ShowDate'), "Tue 28 Aug 2007", "28Aug07");
	addOption( document.getElementById('ShowDate'), "Wed 29 Aug 2007", "29Aug07");
	addOption( document.getElementById('ShowDate'), "Thu 30 Aug 2007", "30Aug07");	
	addOption( document.getElementById('ShowDate'), "Fri 31 Aug 2007", "31Aug07");
	addOption( document.getElementById('ShowDate'), "Sat 01 Sep 2007", "01Sep07");
	
	delAllOptions ( document.searchForm.Rooms );
	addOption( document.searchForm.Rooms, "Room Type", "0");
	addOption( document.searchForm.Rooms, "Double + 2 Tickets", "2");
	addOption( document.searchForm.Rooms, "Twin + 2 Tickets", "3");
	addOption( document.searchForm.Rooms, "2 Doubles + 4 Tickets", "4");	
	addOption( document.searchForm.Rooms, "2 Twins + 4 Tickets", "5");	
	addOption( document.searchForm.Rooms, "Double, Twin + 4 Tickets", "6");
	
	document.getElementById('incRail').innerHTML='Rail is not available with this show.<input type="hidden" name="railRadio" value="0"><input type="hidden" name="railCheckbox" value="0">'; */

}
function unsetTakeThat() {
if(document.getElementById('ShowDate').options[0].innerHTML=="Night of Show:") {
	resetDates();
}
//	if(preTTDates.length>3) {
//		document.getElementById('ShowDate').innerHTML=preTTDates;	
//	}

	delAllOptions ( document.searchForm.Rooms );	
	addOption( document.searchForm.Rooms, "Room Type", "0");
	addOption( document.searchForm.Rooms, "Single + 1 Ticket", "1");
	addOption( document.searchForm.Rooms, "Double + 2 Tickets", "2");
	addOption( document.searchForm.Rooms, "Twin + 2 Tickets", "3");
	addOption( document.searchForm.Rooms, "2 Doubles + 4 Tickets", "4");	
	addOption( document.searchForm.Rooms, "2 Twins + 4 Tickets", "5");	
	addOption( document.searchForm.Rooms, "Double, Twin + 4 Tickets", "6");
	addOption( document.searchForm.Rooms, "1 Triple (1 Adult, 2 Children) + 3 Tickets", "7");
	addOption( document.searchForm.Rooms, "1 Triple (2 Adults, 1 Child) + 3 Tickets", "8");
	addOption( document.searchForm.Rooms, "1 Triple (3 Adults) + 3 Tickets", "9");
	addOption( document.searchForm.Rooms, "1 Quad (2 Adults, 2 Children) + 4 Tickets", "10");
	addOption( document.searchForm.Rooms, "1 Quad (1 Adult, 3 Children) + 4 Tickets", "11");

	
	document.getElementById('incRail').innerHTML='Include Rail Travel? <select id="railCheckbox" onchange="showHideRail( this );" name="railRadio"><option selected="selected" value="">Include rail travel? SAVE up to 40%.</option><option value="1">Yes, please!</option><option value="0">No thankyou.</option></select>';
}

// Function to store the show name for use elsewhere
function showChange() {

	if(document.getElementById('is_testing') && false) {
		addOption(document.getElementById('ShowSelect'),"Take That","SHONME");
	}

	var thefrm = document.searchForm;
		
	showIndex = thefrm.ShowSelect.options.selectedIndex;
	showName = thefrm.ShowSelect.options[showIndex].text;
	thefrm.ShowName.value = showName;
	theShow = thefrm.ShowSelect.options[thefrm.ShowSelect.options.selectedIndex].value;
	showDate = thefrm.ShowDate.options[thefrm.ShowDate.options.selectedIndex].value;
	thefrm.Show.value = theShow;
	if(theShow=="SHONME") {
		setTakeThat();
	}
	else {
		unsetTakeThat();
	}
	
	//if it is tutan exhibition it needs a 10 day lead time
	//JP I dont like this hack but until we get the new forms on the site we are pretty much stuck with it
	try {
	if (theShow == "SHOTCE" || theShow == "SHOTEE" || theShow == "SHOJAE") {
		document.getElementById('standardTicketDate_alt').style.display = "block";
		document.getElementById('standardTicketDate').style.display = "none";
	}
	else {
		document.getElementById('standardTicketDate_alt').style.display = "none";
		document.getElementById('standardTicketDate').style.display = "block";
	}
	} catch(e) { /* Don't know where this is paired with a template not
					containing these elements...but it is somewhere */ }
	// Maintain the chosen performance type.... I can't wait to replace this
	// whole page with an embedded form, working with this file makes me want to drink
	// heavily and break things
	ptIndex = thefrm.selectPerformanceType.selectedIndex;
	
	//Add matinee to dropdown if certain shows selected
	delAllOptions( thefrm.selectPerformanceType );
	addOption( thefrm.selectPerformanceType, 'Performance Type', 'select' );
	addOption( thefrm.selectPerformanceType, ((theShow=="SHOTEE"||theShow=="SHOTCE"||theShow=="SHOJAE")?'Exhibition Tickets':'Evening Show and Hotel'), 'EVE' );
	if (theShow!="SHOTEE" && theShow!="SHOTCE" && theShow!="SHOJAE" && theShow != "SHOHME" ) {

		switch (showDate) {
			case "21Jun08":
				if (theShow != "SHOBBE" && theShow != "SHOMOE" && theShow != "SHOWRE") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}
				break;
			case "17Apr08":
				if (theShow != "SHOMME" && theShow != "SHOPOE") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}
				break;
			case "21Jul08":
				if (theShow != "SHOBBE" && theShow != "SHOMOE" && theShow != "SHOWRE") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}
				break;
			case "15Oct08":
				if (theShow != "SHOMME" && theShow != "SHOPOE") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}
				break;
			case "15Dec08":
			case "16Dec08":
			case "17Dec08":
			case "18Dec08":
			case "19Dec08":
			case "20Dec08":
			case "21Dec08":
			case "22Dec08":
			case "23Dec08":
			case "24Dec08":
			case "25Dec08":
			case "26Dec08":
			case "27Dec08":
			case "28Dec08":
			case "29Dec08":
			case "30Dec08":
			case "31Dec08":
				/*if (showName != "ALL SHOWS") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}*/
				// No pre-theatre meals for all shows for those dates.
				
				break;
			case "01Jan09":
			case "02Jan09":
				/*if (theShow != "SHOBEE" && theShow != "SHOWKE" && showName != "ALL SHOWS") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}*/
				// No pre-theatre meals for all shows for those dates.
				break;
			case "09Feb09":
			case "10Feb09":
			case "11Feb09":
			case "12Feb09":
			case "13Feb09":
			case "14Feb09":
			case "15Feb09":
			case "16Feb09":
			case "17Feb09":
			case "18Feb09":
			case "19Feb09":
			case "20Feb09":
			case "21Feb09":
			case "22Feb09":
			case "23Feb09":
			case "24Feb09":
			case "25Feb09":
			case "26Feb09":
			case "27Feb09":
			case "28Feb09":
				/*if (showName != "ALL SHOWS") {
					addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				}*/
				// No pre-theatre meals for all shows for those dates.
				break;
			default:
				addOption( thefrm.selectPerformanceType, 'Evening Show with pre-theatre dinner and hotel', 'DIN' );
				break;
		}

	}
	var showArray = new Array("SHOLKE","SHOMPE","SHOBEE","SHOBME","SHOSME","SHOJOE","SHOBOE","SHOCAE","SHOFME","SHOBBE","SHOCGE","SHOSTE","SHONME", "SHOBHE", "SHOLME", "SHOSPE", "SHOLRE", "SHOWRE", "SHOWKE", "SHOOLE");
	
/*	for(var i=0;i<showArray.length;i++) { 
		if(theShow == showArray[i]) {
			switch (theShow) {
				case "SHOBEE":
					addOption(thefrm.selectPerformanceType, "Matinee (Thursday or Saturday)", 'MAT' );
					break;
				case "SHOSME":
					addOption(thefrm.selectPerformanceType, "Matinee (Wednesday or Saturday)", 'MAT' );
					break;
				case "SHOBHE":
				case "SHOLME":
				case "SHOWRE":
				case "SHOWKE":
				case "SHOCAE":
					addOption(thefrm.selectPerformanceType, "Matinee (Wednesday Only)", 'MAT' );
					break;
				case "SHOSTE":
				case "SHOLRE":
					addOption(thefrm.selectPerformanceType, "Matinee (Thursday Only)", 'MAT' );
					break;
				case "SHOCGE":
				case "SHOSPE":
					addOption(thefrm.selectPerformanceType, "Matinee (Friday Only)", 'MAT' );
					break;
				case "SHOOLE":
					addOption(thefrm.selectPerformanceType, "Matinee (Saturday Only)", 'MAT' );
					break;
				default:
					addOption( thefrm.selectPerformanceType, (theShow=="SHONME"&&false) ? "Matinee (Thursday or Saturday)" : 'Matin\351e (Saturday only)', 'MAT' );
			}
			//addOption( thefrm.selectPerformanceType, (theShow=="SHONME"&&false) ? "Matinee (Thursday or Saturday)" : 'Matin\351e (Saturday only)', 'MAT' );
		}
	}
	*/
	//Add Meal and Show to dropdown if certain shows selected		
	/*
	
	// Taken out Show and Meal cos shouldnt be live for HEX
	var showArrayMeal = new Array("SHOCGE","SHOSTE","SHOBBE","SHODCE","SHODSE","SHOWBE","SHOWRE","SHOLME","SHOBME");
	for(var j=0;j<showArrayMeal.length;j++) {
		if(theShow == showArrayMeal[j]) {
			addOption( thefrm.selectPerformanceType, 'Meal and Show only - NEW!', 'DIN' );
		}
	}
	*/
	
	thefrm.selectPerformanceType.selectedIndex = ptIndex;
	
	// ticketDate is all backwards, bet that was because of that horrible
	// take that code change
	ticketDate( true);
	
}

//horrible hack again
function updateTicketDate() {
	var thefrm = document.searchForm;
	thefrm.ShowDate.value = thefrm.ShowDate_alt.value;
}


// Function to take the arrive date then populate show date options based on this
function ticketDate( dontChangeShow) {
	if(!dontChangeShow) {
	showChange();
	}
	/*
	datetext = chosenShowDate.options[chosenShowDate.selectedIndex].text;
	thedate = chosenShowDate.options[chosenShowDate.selectedIndex].value.substring( 0, 2 ) + ' ' + chosenShowDate.options[chosenShowDate.selectedIndex].value.substring( 2 ,5 ) + ' ' + chosenShowDate.options[chosenShowDate.selectedIndex].value.substring( 5, 9 );
	thedateval = chosenShowDate.options[chosenShowDate.selectedIndex].value;
	*/
	var thefrm = document.searchForm;
	datetext = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].text;
	thedate = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 0, 2 ) + ' ' + thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 2 ,5 ) + ' ' + thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value.substring( 5, 9 );
	thedateval = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value;
		
	newdate1 = new Date( thedate );
	nextdate1 = dateAdd( newdate1, 1, 0, 0 );
	nextdate = dateAdd( newdate1, 1, 0, 0 ).toUTCString();
	furtherdate1 = dateAdd( newdate1, 2, 0, 0 );
	furtherdate = dateAdd( newdate1, 2, 0, 0 ).toUTCString();

	if ( nextdate1.getDate() < 10 ) { 
		nextdatetext = nextdate.substring(0,3) + ' ' + nextdate.substring(5,7) + ' ' + nextdate.substring(7,11) + ', ' + nextdate.substring(11,16);
		nextdateval = addZero( nextdate1.getDate() ) + nextdate.substring(7,11)+nextdate.substring(11,16);
		nextdateval = nextdateval.replace(/ /g,"");
	} else {
		nextdatetext = nextdate.substring(0,3)+' '+nextdate.substring(4,7)+' '+nextdate.substring(8,11)+', '+nextdate.substring(11,16)
		nextdateval = addZero(nextdate1.getDate())+nextdate.substring(8,11)+nextdate.substring(12,16);
		nextdateval = nextdateval.replace(/ /g,"");
	}

	if ( furtherdate1.getDate() < 10 ) {
		furtherdatetext = furtherdate.substring(0,3)+' '+furtherdate.substring(5,7)+' '+furtherdate.substring(7,11)+', '+furtherdate.substring(11,16);
		furtherdateval = addZero(furtherdate1.getDate())+furtherdate.substring(7,11)+furtherdate.substring(11,16);
		furtherdateval = furtherdateval.replace(/ /g,"");
	} else {
		furtherdatetext = furtherdate.substring(0,3)+' '+furtherdate.substring(4,7)+' '+furtherdate.substring(8,11)+', '+furtherdate.substring(11,16);
		furtherdateval = addZero(furtherdate1.getDate())+furtherdate.substring(8,11)+furtherdate.substring(12,16);
		furtherdateval = furtherdateval.replace(/ /g,"");
	}
	// Populate the show date drop down by using the first 3 dates in the arrival dropdown
	delAllOptions( thefrm.ArrivalDateDrop );
	var offset = 0;
	
	if(thefrm.NightsDrop.value>2 && thefrm.ShowSelect.value=="SHONME" && false) {
		alert("There is a maximum of 2 nights stay for this show.");
		thefrm.NightsDrop.value=2;
	}
	
	var nights = thefrm.NightsDrop.options[thefrm.NightsDrop.options.selectedIndex].value;
	addOption( thefrm.ArrivalDateDrop, "First night of stay", "select" );
	if( thefrm.ShowDate.selectedIndex <= nights) {
		start = thefrm.ShowDate.selectedIndex;
	}
	else {
		start = nights;
	}
	// for ( daysCount = (0 - start); daysCount < nights; daysCount++ ) {
	if(thefrm.ShowSelect.value!="SHONME" || true) {
		var showDateStr = thefrm.ShowDate.options[thefrm.ShowDate.selectedIndex].value;
		var showDay = showDateStr.substring(0, 2);
		var showMonth = convertMonth(showDateStr.substring(2,5));
		var showYear = showDateStr.substring(5);
		var showDate = new Date("20"+showYear, showMonth, showDay);
		//for (i=1; i<=start; i++) {
		for (i=(0-start); i<=0; i++) {
			var newDay = new Date(showDate.getFullYear(), showDate.getMonth(), showDate.getDate()+i);
			var newDayString = "";
			var newMonth = convertMonth(newDay.getMonth());
			switch(newDay.getDay()) {
				case 0:
					newDayString = "Sun";
					break;
				case 1:
					newDayString = "Mon";
					break;
				case 2:
					newDayString = "Tue";
					break;
				case 3:
					newDayString = "Wed";
					break;
				case 4:
					newDayString = "Thu";
					break;
				case 5:
					newDayString = "Fri";
					break;
				case 6:
					newDayString = "Sat";
					break;
			}
			var newDayText = newDayString+" "+newDay.getDate()+" "+newMonth+", "+newDay.getFullYear();
			var newYear = ""+newDay.getFullYear(); //needs to be a string
			if (newDay.getDate().toString().length == 1) {
				var newDayValue = "0"+newDay.getDate() + newMonth + newYear.substring(2);
			}
			else {
				var newDayValue = newDay.getDate() + newMonth + newYear.substring(2);
			}
			if (!isNaN(newDay.getDate())) {
				addOption(thefrm.ArrivalDateDrop, newDayText, newDayValue );
			}
			// Check if the date we have just added match's the stored show date, if so mark it as the selected date
			if (newDayValue == thefrm.arrivalDateSelect.value ) {
				thefrm.ArrivalDateDrop.options[i].selected = true;
			}
		}
	}
	else {
		// longwinded hack but better than rewriting the whole engine for one show
		switch(thefrm.ShowDate.value) {
			case "21Aug07":
				addOption( thefrm.ArrivalDateDrop, "Mon 20 Aug, 2007", "20Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Tue 21 Aug, 2007", "21Aug07" );			
			break;
			case "22Aug07":
				addOption( thefrm.ArrivalDateDrop, "Tue 21 Aug, 2007", "21Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Wed 22 Aug, 2007", "22Aug07" );
			break;
			case "23Aug07":
				addOption( thefrm.ArrivalDateDrop, "Wed 22 Aug, 2007", "22Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Thu 23 Aug, 2007", "23Aug07" );			
			break;
			case "24Aug07":
				addOption( thefrm.ArrivalDateDrop, "Thu 23 Aug, 2007", "23Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Fri 24 Aug, 2007", "24Aug07" );			
			break;
			case "25Aug07":
				addOption( thefrm.ArrivalDateDrop, "Fri 24 Aug, 2007", "24Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Sat 25 Aug, 2007", "25Aug07" );
			break;
			case "27Aug07":
				addOption( thefrm.ArrivalDateDrop, "Sun 26 Aug, 2007", "26Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Mon 27 Aug, 2007", "27Aug07" );
			break;
			case "28Aug07":
				addOption( thefrm.ArrivalDateDrop, "Mon 27 Aug, 2007", "27Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Tue 28 Aug, 2007", "28Aug07" );
			break;
			case "29Aug07":
				addOption( thefrm.ArrivalDateDrop, "Tue 28 Aug, 2007", "28Aug07" );		
				addOption( thefrm.ArrivalDateDrop, "Wed 29 Aug, 2007", "29Aug07" );
			break;
			case "30Aug07":
				addOption( thefrm.ArrivalDateDrop, "Wed 29 Aug, 2007", "29Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Thu 30 Aug, 2007", "30Aug07" );
			break;
			case "31Aug07":
				addOption( thefrm.ArrivalDateDrop, "Thu 30 Aug, 2007", "30Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Fri 31 Aug, 2007", "31Aug07" );
			break;
			case "01Sep07":
				addOption( thefrm.ArrivalDateDrop, "Fri 31 Aug, 2007", "31Aug07" );
				addOption( thefrm.ArrivalDateDrop, "Sat 01 Sep, 2007", "01Sep07" );
			break;
		}
	}
}

// Function to store the show date for use elsewhere 
function storeArrivalDate() { 
	var thefrm = document.searchForm;
	thefrm.arrivalDateSelect.value = thefrm.ArrivalDateDrop.options[ thefrm.ArrivalDateDrop.selectedIndex ].value;
	
	thefrm.RailDepDate.value = thefrm.ArrivalDateDrop.options[ thefrm.ArrivalDateDrop.selectedIndex ].value;
	WriteLayer( 'railOutDate', null, thefrm.ArrivalDateDrop.options[ thefrm.ArrivalDateDrop.selectedIndex ].value);
	// Make the depart drop down select arrival date + numNights
	var railRet = document.getElementById("RailRetDate");
	var stayDate = document.getElementById("ArrivalDateDrop");
	var noOfNights = thefrm.NightsDrop.options[thefrm.NightsDrop.options.selectedIndex].value;
	if (!(stayDate.selectedIndex == 0))	{
		var hotelDate = stayDate.options[stayDate.selectedIndex].value.substring( 0, 2) + ' ' + stayDate.options[stayDate.selectedIndex].value.substring( 2, 5) + ' 20' + stayDate.options[stayDate.selectedIndex].value.substring( 5, 9);
		var hotelDatePlus = new Date( hotelDate);
		hotelDatePlus = dateAdd( hotelDatePlus, noOfNights, 0, 0);
		var hotelDatePlusText = hotelDatePlus.toUTCString();
		
		if( hotelDatePlusText.substring(6,7) == '') {
			var blx = '0' + hotelDatePlusText.substring(5,6) + hotelDatePlusText.substring(7,10) + hotelDatePlusText.substring(13,15);
		}
		else {
			var blx = hotelDatePlusText.substring(5,7) + hotelDatePlusText.substring(8,11) + hotelDatePlusText.substring(14,16);
		}
		
		for( var i=0; i<railRet.length; i++) {
			if( railRet.options[i].value == blx) {
				railRet.selectedIndex = i;
			}
		}
	}
}

function populateRailDates_v1()	{
	thefrm = document.searchForm;
	var railCheckbox = document.getElementById("railCheckbox");
	var railForm = document.getElementById("railForm");
	var stayDate = document.getElementById("ArrivalDateDrop");
	var noOfNights = thefrm.NightsDrop.options[frm.NightsDrop.selectedIndex].value;
	var railDep = document.getElementById("RailDepDate");
	var railRet = document.getElementById("RailRetDate");

	if (!(stayDate.selectedIndex == 0))	{
		// Doesn't wanna be in loop - same each time
		var hotelDate = stayDate.options[stayDate.selectedIndex].value;
		for (var i=1; i < railDep.length; i++)	{
			var railDate = railDep.options[i].value;
			
			if (railDate == hotelDate)	{
				railDep.selectedIndex = i;
				break;
			}
			if (railDate > hotelDate && stayDate.options[stayDate.selectedIndex].value != "select")	{
				break;
			}
		}
	}
}


if (document.getElementById)	{
	if (window.addEventListener)	{
		window.addEventListener("load",ticketDate,false);
		window.addEventListener("load",showChange,false);
		
	}
	else if (window.attachEvent)	{
		window.attachEvent("onload",ticketDate);
		window.attachEvent("onload",showChange);
	
	}
	else	{
		window.onload += ticketDate();
		window.onload += showChange();
	}
}


var dateValues = new Array();
var dateLabels = new Array();

function parseDateToNum(dateVar)	{
	var dateText = new Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var strMonth = dateVar.substr(2,3);
	for (x = 0; x < dateText.length; x++)	{
		if (dateText[x] == strMonth)	{
			var monthNum = x;
			/* Return YYMMDD */
			return dateVar.substr(5,2) + zeroPadding(monthNum) + dateVar.substr(0,2);
		}
	}
}
function parseDateObjToNum(dateObj,daysAhead)	{
	if (daysAhead)	{
		dateObj.setDate(dateObj.getDate() + daysAhead);
	}
	var dYear = dateObj.getFullYear().toString();
	/* Return YYMMDD */
	return dYear.substr(2,2) + zeroPadding(dateObj.getMonth()) + zeroPadding(dateObj.getDate());
}

function zeroPadding(numToPad)	{
	if (numToPad < 10)	{
		numToPad = "0" + numToPad;
	}
	return numToPad;
}

function checkArray(arr,val)	{
	for (i = 0; i < arr.length; i++)	{
		if (arr[i] == val)	{
			return i;
		}
	}
	return false;
}

function storeDates()	{
	if (document.getElementById)	{
		var arrivalSelect = document.getElementById("ShowDate");
		for (i = 0; i < arrivalSelect.options.length; i++)	{
				dateValues[dateValues.length] = arrivalSelect.options[i].value;
				if (arrivalSelect.options[i].innerHTML != "&nbsp;")	{
					dateLabels[dateLabels.length] = arrivalSelect.options[i].innerHTML;
				}
				else	{
					dateLabels[dateLabels.length] = "";
				}
		}
	}
}

function resetDates()	{
	// this messes up take that thing
	if(document.getElementById('ShowSelect').value!="SHONME" && false) {
	if (document.getElementById)	{
		var arrivalDate = document.getElementById("ShowDate");
		arrivalDate.options.length = 0;
		for (i = 0; i < dateValues.length; i++)	{
			arrivalDate.options[i] = new Option(dateLabels[i],dateValues[i]);
		}
	}
	}
}

function removeNights(toDate,selectId)	{
	if (document.getElementById)	{
		var arrivalSelect = document.getElementById(selectId);
		for (i = 1; i < arrivalSelect.length; i++)	{
			if (arrivalSelect.options[i].value == toDate)	{
/*				arrivalSelect.options[i].selected = true;*/
				break;
			}
			else	{
				if ((arrivalSelect.options[i].value == "select") || (parseDateToNum(arrivalSelect.options[i].value) < parseDateToNum(toDate)))	{
					arrivalSelect.options[i] = null;
					i--;
				}
			}
		}
	}
}

function setShowStartDate(showCode)	{
	if (document.getElementById)	{
		resetDates();
		var showCode = document.getElementById("ShowSelect").value;
		var ssIndex = checkArray(soonShow,showCode);
		var today = new Date();
		if (ssIndex != false)	{
			if (parseDateObjToNum(today,7) < parseDateToNum(soonDate[ssIndex]))	{
				removeNights(soonDate[ssIndex],"ArrivalDateDrop");
			}
		}
	}
}

if (document.getElementById)	{
	if (window.addEventListener)	{
		window.addEventListener("load",storeDates,false);
		window.addEventListener("load",function(){document.getElementById("ShowSelect").addEventListener("change",setShowStartDate,false);},false);
		
	}
	else if (window.attachEvent)	{
		window.attachEvent("onload",storeDates);
		window.attachEvent("onload",function(){document.getElementById("ShowSelect").attachEvent("onchange",setShowStartDate);});
	}
	else	{
		window.onload += storeDates();
		window.onload += function(){document.getElementById("ShowSelect").onchange += setShowStartDate();};
	}
}

// Rail Stuff

function showHideRail( obj )	{
	if (	obj == undefined ) {
		obj = document.getElementById("railCheckbox");
	}
	var railForm = document.getElementById("railForm");
	grpBookingSection = document.getElementById( 'groupBookings' );
	var bestPrice = document.getElementById( 'bpg' );
	// PC 7/6/07, need to check for a checkbox OR a select, in case this is used elsewhere, keeping the same name and id
	if (	obj.checked == true || ( obj.options && obj.options[obj.selectedIndex].value == 1 )) {
		if (	bestPrice ) {
			bestPrice.style.display = "none";
		}
		if (	railForm ) {
			railForm.style.display = "";
			// alert( 'showHideRail( ' + obj + ' ), checked is ' + obj.checked + ', sel is ' + obj.options[obj.selectedIndex].value + '. railForm is ' + railForm + ', display is ' + railForm.style.display );
		}
		if (	grpBookingSection ) {
			grpBookingSection.style.display = "none";
		}
	}
	else {	if (	bestPrice ) {
			bestPrice.style.display = "";
		}
		if (	railForm ) {
			railForm.style.display = "none";
		}
		if (	grpBookingSection ) {
			grpBookingSection.style.display = "";
		}
	}
}

function populateRailDates_v2()	{
	var railCheckbox = document.getElementById("railCheckbox");
	var railForm = document.getElementById("railForm");
	var stayDate = document.getElementById("ArrivalDateDrop");
	var noOfNights = document.getElementById("nights");
	var railDep = document.getElementById("RailDepDate");
	var railRet = document.getElementById("RailRetDate");

	if (!(stayDate.selectedIndex == 0))	{
		// Doesn't wanna be in loop - same each time
		var hotelDate = stayDate.options[stayDate.selectedIndex].value;
		for (var i=1; i < railDep.length; i++)	{
			var railDate = railDep.options[i].value;
			//railDep.selectedIndex = 7;
			if( i == 3) {
				alert( railDate);
				alert( hotelDate);
			}
			
			if (railDate == hotelDate)	{
				railDep.selectedIndex = i;
				break;
			}
			if (railDate > hotelDate && stayDate.options[stayDate.selectedIndex].value != "select")	{
				break;
			}
		}
		/*
		if (noOfNights.selectedIndex != 0)	{
			var hotelRetDate = railDep.options[i].value);
			for (i=1; i < railRet.length; i++)	{
				var railRetDate = railRet.options[i].value;
				if (railRetDate == hotelRetDate)	{
					railRet.options[i].selected = true;
					break;
				}
				if (railRetDate > hotelRetDate)	{
					break;
				}
			}
		}
		*/
	}
}

var soonShow = new Array("","SHODCE","SHODDE","SHOSPE","SHOWKE","SHOCAE","SHOLRE","SHOSME");
var soonDate = new Array("","07Sep06","25Oct06","17Oct06","28Sep06","10Oct06","09May07","15Nov06");

// change the color of background depending on error
function setColor(el, bg) {
	if (el.style) {
		el.style.backgroundColor = bg;
	}
}

function checkRailAvailable( x) {
	thefrm = document.searchForm;
	var yr = '20' + x.substring(5,7);
	var dd = x.substring(0,2);
	var strMon = x.substring(2,5);
	var mm;
	switch( strMon) {
		case 'Jan':
			mm = 0;
			break;
		case 'Feb':
			mm = 1;
			break;
		case 'Mar':
			mm = 2;
			break;
		case 'Apr':
			mm = 3;
			break;
		case 'May':
			mm = 4;
			break;
		case 'Jun':
			mm = 5;
			break;
		case 'Jul':
			mm = 6;
			break;
		case 'Aug':
			mm = 7;
			break;
		case 'Sep':
			mm = 8;
			break;
		case 'Oct':
			mm = 9;
			break;
		case 'Nov':
			mm = 10;
			break;
			
		case 'Dec':
			mm = 11;
			break;
	}

	var cutOffDate = new Date();
	cutOffDate.setFullYear( 2009,  4, 1);
	
	var travelDate = new Date();
	travelDate.setFullYear( yr, mm, dd);
/*
	thefrm.railRadio.disabled = true;
	thefrm.railRadio.checked = false;
	showHideRail();
	document.getElementById('incRail').style.display = 'none';
	document.getElementById('noRailSingleRoom').style.display = '';
*/ 

	if( travelDate > cutOffDate) {
		var railCheckbox = document.getElementById("railCheckbox");
		if( railCheckbox.checked) {
			 railCheckbox.checked = false;
			 showHideRail();
		}
		noRail = true;
		thefrm.railRadio.disabled = true;
		thefrm.railRadio.checked = false;
		showHideRail();
		document.getElementById('railAvailable').style.display = 'none';
		document.getElementById('noRailAvailable').style.display = '';
		
		document.getElementById('incRail').style.display = 'none';
		document.getElementById('railForm').style.display = 'none';
		thefrm.railRadio.selectedIndex = 2;
		document.getElementById('bpg').style.display = '';
	}
	else {
		noRail = false;
		if( !( singleTraveller)) {
			document.getElementById('railrow').style.display = '';
			document.getElementById('incRail').style.display = '';
		}
		thefrm.railRadio.disabled = false;
		document.getElementById('railAvailable').style.display = '';
		document.getElementById('noRailAvailable').style.display = 'none';
	}
	return true;
}

function getMonthInt( month ) {
	if(	month == "Jan" )
		return 0;
	if(	month == "Feb" )
		return 1;
	if(	month == "Mar" )
		return 2;
	if(	month == "Apr" )
		return 3;
	if(	month == "May" )
		return 4;
	if(	month == "Jun" )
		return 5;
	if(	month == "Jul" )
		return 6;
	if(	month == "Aug" )
		return 7;
	if(	month == "Sep" )
		return 8;
	if(	month == "Oct" )
		return 9;
	if(	month == "Nov" )
		return 10;
	if(	month == "Dec" )
		return 11;
}

