// JavaScript Document

var win = null;
function mail(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings);
}

function createRequestObject()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer")
	{
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http	 	= createRequestObject(); 

var hotelBookingEngines = new Object();
var hotelBookingIDs = new Object();
var hotelBookingChainIDs = new Object();
var netbookerName		 = new Object();
var netbookerCity		 = new Object();

function BookingHotelSelectChanged(evnt) {
	//console.log("BookingHotelSelectChanged");
	var idMatch = this.value.match(/^([0-9]+)$/);
	if(idMatch == null) idMatch = ["", ""]; //spoof
	var hotelID = idMatch[1];
	//console.log("hotel id "+hotelID);
	if(typeof(hotelBookingEngines["hotel"+hotelID]) != 'undefined' 
			&& hotelBookingEngines["hotel"+hotelID] == "roommaster") {
		//Populate the rates select item
		new Ajax.Request('/booking/ajax_booking_form_rates/'+hotelID+'.htm', {
			method:"get", 
			onSuccess:BookingHotelSelectChangedCB
		});
	}
	else {
		//Remove the rates element, if there is one.
		$('bookingElementRateCont').style.display = "none";
		$('bookingElementRateLabel').style.display = "none";
	}
	
	if(typeof(hotelBookingEngines["hotel"+hotelID]) != 'undefined' 
			&& hotelBookingEngines["hotel"+hotelID] == "legacy") {
		//Can't launch into stage two,
		//so launch at stage one.
		var hotelBookingID = hotelBookingIDs["hotel"+hotelID];
		mail('http://bookings.legacy-hotels.co.uk/hotel-details&hotel_id='+hotelBookingID, 'legacybookng', 820, 630, 'yes');
	}
	
	if(typeof(hotelBookingEngines["hotel"+hotelID]) != 'undefined' 
			&& hotelBookingEngines["hotel"+hotelID] == "bookerrez") {
		//Show child controls	
		$('bookingElementChildrenLabel').style.display = "block";
		$('bookingElementChildCont').style.display = "block";
		//Add a listener to the child input box.
		var childInput = document.BookingTeaser.children;
		Event.observe(childInput, "keyup", BookingChildrenChanged);
	}
	else {
		//Hide child controls	
		$('bookingElementChildrenLabel').style.display = "none";
		$('bookingElementChildCont').style.display = "none";
		//Remove a listener to the child input box.
		var childInput = document.BookingTeaser.children;
		Event.stopObserving(childInput, "keyup", BookingChildrenChanged);
	}
}

function BookingChildrenChanged(evnt) {
	if(this.value.match(/^[0-9]*$/) == null) {
		$('BookingTeaserError').update("");
		$('BookingTeaserError').appendChild(new Element("div", {style:'color:#ff0000;'}).update("Please enter a number of children, or leave blank"));
		this.value = "";
		return;
	}
	
	if(parseInt(this.value) > 4) {
		$('BookingTeaserError').update("");
		$('BookingTeaserError').appendChild(new Element("div", {style:'color:#ff0000;'}).update("Maximum number of 4 children allowed"));
		this.value = "4";
	}
	
	var childAgesCont = $('bookingElementChildCont');
	while(childAgesCont.select("select").length > this.value) {
		childAgesCont.removeChild(childAgesCont.select("select")[0]);
	}
	
	while(childAgesCont.select("select").length < this.value) {
		var newChildAgeSel = new Element("select", {'class':'formInputSmall', style:'width:3.2em;'});
		if(childAgesCont.select("select").length > 0) childAgesCont.appendChild(document.createTextNode(' '));
		childAgesCont.appendChild(newChildAgeSel);
		for(var  i = 0; i <= 14; i++) {
			var opt = new Element("option", {value:i});
			opt.update((i == 0 ? i : i));
			newChildAgeSel.appendChild(opt);
		}
	}
}

function BookingHotelSelectChangedCB(transport) {
	try {
		var xml = transport.responseXML;
		var statusElem = xml.getElementsByTagName("status")[0];
		if(statusElem.firstChild == null) {
			alert("No or empty status tag found");	
			return;
		}
		
		if(statusElem.firstChild.data != "true") {
			alert(statusElem.firstChild.data);	
			return;
		}
		
		var rates = xml.getElementsByTagName("rate");
		/*
		var bookingDiv = $$('.booking-btm')[0];
		var rows = bookingDiv.select("tr");
		if(rows.length <= 5) {
			var ratesSelectRow = new Element("tr");
			var rateSelectCell = new Element("td", {colspan:2});
			rateSelectCell.style.paddingTop = "10px";
			ratesSelectRow.appendChild(rateSelectCell);
			var label = new Element("label", {"for":"bookingElementRate"});
			label.update("Rate:");
			var select = new Element("select", {name:"txtRateSelected", id:"bookingElementRate", "class":"formInputSelectHotel"});
			rateSelectCell.appendChild(label);
			rateSelectCell.appendChild(select);
			//select.appendChild(new Element("option").update("Getting rates..."));
			rows[rows.length-1].parentNode.insertBefore(ratesSelectRow, rows[rows.length-1]);
		}
		*/
		
		var rateSelect = $('bookingElementRate');
		//Remove existing.
		var options = rateSelect.getElementsByTagName("option");
		while(options.length > 0) {
			options[0].parentNode.removeChild(options[0]);	
			options = rateSelect.getElementsByTagName("option");
		}
		
		//Put in new.
		for(var i = 0; i < rates.length; i++) {
			//<option value="0">TEST Rate</option>
			var newOption = document.createElement("option");
			newOption.appendChild(document.createTextNode(rates[i].getAttribute("name")));
			newOption.value = rates[i].getAttribute("value");
			rateSelect.appendChild(newOption);		
		}
		
		$('bookingElementRateCont').style.display = "block";
		$('bookingElementRateLabel').style.display = "block";
	}
	catch(e) {
		console.log(e);	
	}
}

function RunBookingValidation ()
{
	
	var property 			= document.BookingTeaser.property;
	var property_index 		= property.options.selectedIndex;
	var property			= property.options[property_index].value;
	
	var day					= document.getElementById('arr_date').value;
	
	var nights				= document.BookingTeaser.nights.value;
	
	var adults				= document.BookingTeaser.adults.value;
	
	var children			= document.BookingTeaser.children.value;
	
	if(hotelBookingEngines["hotel"+property] == "cybarez" 
	|| hotelBookingEngines["hotel"+property] == "rezplatform") {
		var params 				= "property=" + property + "&arr_date=" + day + "&nights=" + nights + "&adults=" + adults + "&children=" + children;
		
		http.open('POST', '/booking/ajax_handle');
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		http.onreadystatechange = handleAjaxReturn; 
		http.send(params);
		
		return false;
	}
	
	var errors = new Array();
	
	if(typeof hotelBookingEngines["hotel"+property] == "undefined") errors.push("Please select a hotel");
	
	if(!nights.match(/^[0-9]+$/)) errors.push("Please enter a number of nights");
	else {
		if(new Number(nights) == 0) errors.push("Please enter at least one night");	
	}
	
	if(!adults.match(/^[0-9]+$/)) errors.push("Please enter a number of adults");
	else {
		if(new Number(adults) == 0) errors.push("Please enter at least one adult");	
	}
	
	if(!children.match(/^[0-9]*$/)) errors.push("Please enter a number of children, or leave blank");
	if(children.length == 0) children = "0";
	
	if(!day.match(/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/)) errors.push("Please enter arrival date: dd/mm/yyyy");
	else {
		var dateParts = day.split("/");
		var date =  new Date();
		date.setUTCFullYear(dateParts[2], dateParts[1] - 1, dateParts[0]);
		if(dateParts[2] != date.getUTCFullYear() 
		|| dateParts[1] != (date.getUTCMonth()+1)
		|| dateParts[0] != date.getUTCDate()) {
			 errors.push("Please enter arrival date: dd/mm/yyyy");
		}
	}
	
	var rate = null
	if(hotelBookingEngines["hotel"+property] == "roommaster") {
		////In addition, we need the rate
		var rateElement = $('bookingElementRate');
		if(rateElement == null) {
			 errors.push("Couldn't find the rate select. Try re-selecting the property.");
		}
		else {
			//console.log(rateElement.value);
			rate = rateElement.value;
		}
	}	
	
	if(errors.length > 0) {
		document.getElementById('BookingTeaserError').innerHTML = '';
		for (e in errors) {
			document.getElementById('BookingTeaserError').innerHTML += "<div style=\"color:#ff0000;\">"+errors[e]+"</div>";
		}
	}
	else {
		switch(hotelBookingEngines["hotel"+property]) {
			case "synxis":
				launchSynxis(property, date, nights, adults, children);
			break;
			case "ihotelier":
				launchIhotelier(property, date, nights, adults, children);
			case "ihotelier2":
				launchIhotelier2(property, date, nights, adults, children);
			break;
			case "roommaster":
				launchRoomMaster(property, date, nights, adults, children, rate);
			break;
			case "netbooker":
				launchNetbooker(property, date, nights, adults, children);
			break;
			case "bookerrez":
				launchBookerRez(property, date, nights, adults, children);
			break;
			case "watersmeet_custom":
				var arriveString = date.getUTCDate()+"/"+(date.getUTCMonth()+1)+"/"+date.getUTCFullYear();
				window.open('http://watersmeethotel.co.uk/hotelbooking.aspx?arrivaldate='+arriveString+'%2000:00:00&nights='+nights,'BookingWindow');
			break;
			case "bebox":
				launchBeBox(property, date, nights);
			break;
		}
	}
	
}

function handleAjaxReturn ()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		var trimmed = response.replace(/^\s+|\s+$/g, '') ;
		//alert('|' + response + '|');
		
		if (trimmed == 'VALIDATION_PASSED')
		{
			//alert('submitting form');
			document.BookingTeaser.submit();
		} else {
			document.getElementById('BookingTeaserError').innerHTML = response;
		}
		
	} else {
		document.getElementById('BookingTeaserError').innerHTML = 'Please Wait...';	
	}
}

function launchSynxis(property, date, nights, adults, children) {
	var baseURL = "https://reservations.synxis.com/LBE/rez.aspx";
	var chainID = 6661;
	if(hotelBookingChainIDs["hotel"+property] != null) chainID = hotelBookingChainIDs["hotel"+property];
	var arriveString = (date.getUTCMonth()+1) +"/"+date.getUTCDate()+"/"+date.getUTCFullYear();
	
	var bookingURL = baseURL+"?Hotel="+hotelBookingIDs["hotel"+property]+
					"&Chain="+chainID+"&Dest=BESPOKE&level=2"+
					"&arrive="+arriveString+
					"&nights="+nights+
					"&adult="+adults;
	if(children.length > 0) bookingURL += "&child="+children;
	bookingURL += "&step=2";
	//alert(bookingURL);
	mail(bookingURL, 'BookingWindow', 850, 580, 'yes');
}

function launchBookerRez(property, date, nights, adults, children) { //https://www.yourreservation.net/ibe/15922-Pinewood-Htl/main.html
	var bookingURL = 'https://www.yourreservation.net/ibe/'+hotelBookingIDs["hotel"+property]+'/main.htm?quick=quick&language=EN&ccpSelectCountry=GB-XX';
	
	var month = ""+(date.getUTCMonth()+1);
	if(month.length < 2) month = "0"+month;
	var day = ""+date.getUTCDate();
	if(day.length < 2) day = "0"+day;
	
	var endDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 1);
	endDate.setDate(endDate.getDate() + new Number(nights));
	//////////alert(endDate);
	var endMonth = ""+(endDate.getUTCMonth()+1);
	if(endMonth.length < 2) endMonth = "0"+endMonth;
	var endDay = ""+endDate.getUTCDate();
	if(endDay.length < 2) endDay = "0"+endDay;
	
	var childAgeInputs = $$('#bookingElementChildCont select');
	bookingURL += '&calArrivalDateField='+date.getUTCFullYear()+'-'+month+'-'+day;	
	bookingURL += '&calDepartureDateField='+endDate.getUTCFullYear()+'-'+endMonth+'-'+endDay;
	bookingURL += '&occupancy='+(parseInt(adults)+parseInt(childAgeInputs.length));
	bookingURL += '&prsRoomCount=1';
	bookingURL += '&prsNumChildren='+childAgeInputs.length;
	
	for(var  i = 0; i < childAgeInputs.length; i++) {
		bookingURL += '&prsRoomAge='+childAgeInputs[i].value;
	}
	mail(bookingURL, 'BookingWindow', 1020, 580, 'yes');
}

function launchIhotelier(property, date, nights, adults, children) {
	var baseURL = "https://reservations.ihotelier.com/istay.cfm";
	var bookingURL = baseURL+"?hotelid="+hotelBookingIDs["hotel"+property]+
					"&Rooms=1"+
					"&Length="+nights+
					"&Adults="+adults+
					"&Children="+children+
					"&DateIN="+(date.getUTCMonth()+1)+"/"+date.getUTCDate()+"/"+date.getUTCFullYear();
	//alert(bookingURL);
	mail(bookingURL, 'ihotelierbookng', 1030, 750);
}

function launchBeBox(property, date, nights) {
	var sub = netbookerName["hotel"+property];
	var baseURL 	= "http://" + sub + ".visrez.com/web_reservations/show_availability?reservation_search[arrival_date]=";
	var bookingURL	= baseURL + "" + date.getUTCDate()+"."+(date.getUTCMonth()+1)+"."+date.getUTCFullYear() +
					  "&reservation_search[nights]=" + nights +
					  "&reservation_search[property_id]=" + hotelBookingIDs['hotel' + property];
	//alert(bookingURL);
	mail(bookingURL, 'beboxbooking', 1030, 750);
}

function launchIhotelier2(property, date, nights, adults, children) {
	var baseURL = "https://booking.ihotelier.com/istay/istay.jsp";
	var bookingURL = baseURL+"?hotelid="+hotelBookingIDs["hotel"+property]+"&locale=EN&languageid=11"+
					"&Length="+nights+
					"&adults="+adults+
					"&children="+children+
					"&datein="+(date.getUTCMonth()+1)+"/"+date.getUTCDate()+"/"+date.getUTCFullYear();
	//alert(bookingURL);
	mail(bookingURL, 'ihotelierbookng', 1030, 750);
}

function launchRoomMaster(property, date, nights, adults, children, rate) {
	var endDate = new Date();
	endDate.setTime(date.getTime());
	endDate.setDate(endDate.getDate() + new Number(nights));
	var baseURL = "http://"+hotelBookingIDs["hotel"+property]+"/asp/AgentLogin.asp";
	
	var inDay = new String(date.getUTCDate());
	if(inDay.length < 2) inDay = "0"+inDay;
	var inMonth = new String((date.getUTCMonth()+1));
	if(inMonth.length < 2) inMonth = "0"+inMonth;
	var outDay = new String(endDate.getUTCDate());
	if(outDay.length < 2) outDay = "0"+outDay;
	var outMonth = new String((endDate.getUTCMonth()+1));
	if(outMonth.length < 2) outMonth = "0"+outMonth;
	
	var bookingURL = baseURL+"?txtNumRooms=1"+
					"&txtAdults="+adults+
					"&txtChildren="+children+
					"&txtRateSelected="+rate+
					"&CheckOutDay="+outDay+
					"&CheckOutMonth="+outMonth+
					"&CheckOutYear="+endDate.getUTCFullYear()+
					"&CheckInDay="+inDay+
					"&CheckInMonth="+inMonth+
					"&CheckInYear="+date.getUTCFullYear();
	//alert(bookingURL);
	mail(bookingURL, 'BookingWindow', 800, 600);
}

/*function launchNetbooker(property, date, nights, adults, children) {
	//Initialise session
	var win = mail("https://unirez.ibe.netbooker.com/web/FrontController.nb4?module=PropertySearch&operation=SinglePropertySearch&execute=yes&chainCode="+hotelBookingChainIDs["hotel"+property]+"&propertyCode="+hotelBookingIDs["hotel"+property]+"&instanceId=72", 'BookingWindow', 800, 600, 'yes');
	
	var endDate = new Date();
	endDate.setTime(date.getTime());
	endDate.setDate(endDate.getDate() + new Number(nights));
	
	var inDay = new String(date.getUTCDate());
	if(inDay.length < 2) inDay = "0"+inDay;
	var inMonth = new String((date.getUTCMonth()+1));
	if(inMonth.length < 2) inMonth = "0"+inMonth;
	var outDay = new String(endDate.getUTCDate());
	if(outDay.length < 2) outDay = "0"+outDay;
	var outMonth = new String((endDate.getUTCMonth()+1));
	if(outMonth.length < 2) outMonth = "0"+outMonth;
	
	var bookingURL = "https://unirez.ibe.netbooker.com/web/SinglePropertySearchAction.do";
	bookingURL += "?operation=SinglePropertySearchResult";
	bookingURL += "&pageID=SPS.001";
	bookingURL += "&instanceId=72";
	bookingURL += "&chainCode="+hotelBookingChainIDs["hotel"+property];
	bookingURL += "&propertyCode="+hotelBookingIDs["hotel"+property];
	bookingURL += "&arriveDay="+inDay;
	bookingURL += "&arriveMonth="+inMonth;
	bookingURL += "&arriveYear="+date.getUTCFullYear();
	bookingURL += "&departDay="+outDay;
	bookingURL += "&departMonth="+outMonth;
	bookingURL += "&departYear="+endDate.getUTCFullYear();
	bookingURL += "&adults="+adults;
	bookingURL += "&numberOfNights="+nights;
	bookingURL += "&numberOfRooms=1";
	if(children.length > 0) bookingURL += "&children="+children;
	//mail(bookingURL, 'BookingWindow', 800, 600);
	setTimeout("mail('"+bookingURL+"', 'BookingWindow', 800, 600);", 3000);
}*/

// NEW NETBOOKER PARAMETERS - NEED TO OBTAIN PROPERTY NAME AND CITY DYNAMICALLY!!
function launchNetbooker(property, date, nights, adults, children, name, city) {
	//Initialise session
	//var win = mail("https://unirez.ibe.netbooker.com/web/FrontController.nb4?module=PropertySearch&operation=SinglePropertySearch&execute=yes&chainCode="+hotelBookingChainIDs["hotel"+property]+"&propertyCode="+hotelBookingIDs["hotel"+property]+"&instanceId=72", 'BookingWindow', 800, 600, 'yes');
	
	var endDate = new Date();
	endDate.setTime(date.getTime());
	endDate.setDate(endDate.getDate() + new Number(nights));
	
	var inDay = new String(date.getUTCDate());
	if(inDay.length < 2) inDay = "0"+inDay;
	var inMonth = new String((date.getUTCMonth()+1));
	if(inMonth.length < 2) inMonth = "0"+inMonth;
	var outDay = new String(endDate.getUTCDate());
	if(outDay.length < 2) outDay = "0"+outDay;
	var outMonth = new String((endDate.getUTCMonth()+1));
	if(outMonth.length < 2) outMonth = "0"+outMonth;
	
	var bookingURL = "https://secure.netbookerng.com/hotels";
	
	/*bookingURL += "/royalhotel";
	//bookingURL += "/cardiff"*/
	
	bookingURL += "/"+netbookerName["hotel"+property];
	bookingURL += "/"+netbookerCity["hotel"+property];
	
	bookingURL += "/hseoptx_"+hotelBookingChainIDs["hotel"+property];
	bookingURL += "/hseoid_"+hotelBookingIDs["hotel"+property];
	bookingURL += "?&refurl=.bespokehotels.com&autosearch=true";
	bookingURL += "&begindate="+inMonth;
	bookingURL += "/"+inDay;
	bookingURL += "/"+date.getUTCFullYear();
	bookingURL += "&enddate="+outMonth;
	bookingURL += "/"+outDay;
	bookingURL += "/"+endDate.getUTCFullYear();
	bookingURL += "&adults="+adults;
	bookingURL += "&numberOfNights="+nights;
	if(children.length > 0) bookingURL += "&children="+children;
	//mail(bookingURL, 'BookingWindow', 800, 600);
	mail(bookingURL, 'BookingWindow', 1020, 750);
	
}


/******************************************************
			FUNCTIONS FOR THE NETSPIN BOOKING FORM 
******************************************************/

var targetfield = null;
var targetroomid = null;
var targethotelid = null;
var targetxmlroomid = null;

var isused = new Array();
isused[1] = null;
isused[2] = null;
isused[3] = null;

function getRoomFields(HotelID, RoomId, Field, XMLroomID)
{
	var ajax_fieldname;
	if (XMLroomID == 'none')
	{
		ajax_fieldname = 'AJAX_Adults_' + RoomId;
		document.getElementById(ajax_fieldname).innerHTML = '&nbsp;';
		
		ajax_fieldname = 'AJAX_Child_' + RoomId;
		document.getElementById(ajax_fieldname).innerHTML = '&nbsp;';
		
		isused[RoomId] = false;
	} else {
			
		targetfield 	= Field;
		targetroomid	= RoomId;
		targethotelid	= HotelID;
		targetxmlroomid	= XMLroomID;
		
		var A_field	= Field + '_' + RoomId;
		
		//alert('1 ' + A_field);
		
		http	 	= createRequestObject(); 
		
		http.open('get', '/booking/netspin_handle_room_ajax/' + HotelID + '/' + XMLroomID + '/' + A_field);
		http.onreadystatechange = handleRoomAjaxReturn; 
		http.send(null);
	}
}

function handleRoomAjaxReturn ()
{
	ajax_fieldname = 'AJAX_' + targetfield + '_' + targetroomid;
	
	if(http.readyState == 4)
	{
		var response = http.responseText;
				
		document.getElementById(ajax_fieldname).innerHTML = response;
		
		if (targetfield == 'Adults')
		{
			targetfield = 'Child';
			getRoomFields(targethotelid, targetroomid, 'Child', targetxmlroomid);			
			placeholder();
		} else {
			placeholder();
		}
	} else {
		document.getElementById(ajax_fieldname).innerHTML = '<img src="/images/ajax-loader.gif" width="16" height="16" border="0" alt="Loading" />';
	}
}

function placeholder ()
{
	// moo
}

function checkLimits (RoomID, Maxocupancy)
{						
	var adults 			= document.getElementById('Adults_' + RoomID);
	var adults_index	= adults.options.selectedIndex;
	var adults_count	= adults.options[adults_index].value;
	
	var child 			= document.getElementById('Child_' + RoomID);
	var child_index		= child.options.selectedIndex;
	var child_count		= child.options[child_index].value;
	
	adults_count		= parseInt(adults_count);
	child_count			= parseInt(child_count);
	
	var totalcount 		= adults_count+child_count;
	
	var tick 		= '<img src="/images/icons/tick_256.png" width="16" height="16" alt="Valid number of occupants" border="0" align="absmiddle" />';
	var cross 		= '<img src="/images/icons/cross_256.png" width="16" height="16" alt="Invalid number of occupants" border="0" align="absmiddle" />';
	var image		= null;
		
	if (!isNaN(totalcount))
	{
		isused[RoomID] = true;
		
		if (totalcount < 1)
		{
			image = cross;
			isused[RoomID] = 'fail';
			
		} else if (totalcount > Maxocupancy) {
			image = cross;
			isused[RoomID] = 'fail';
			
		} else {
			image = tick;
			isused[RoomID] = 'ok';
		}
		
		var counter 		= 'AJAX_Count_' + RoomID;
		document.getElementById(counter).innerHTML = image + ' <strong>' + totalcount + '/' + Maxocupancy + '</strong>';
	}
}

function doFinalCheck ()
{
	var fail 	= false;
	var allnull = true;
	
	if (isused[1] != null)
	{
		allnull = false;
		if (isused[1] == 'fail')
		{
			fail = true;
		}
	}
	
	if (isused[2] != null)
	{
		allnull = false;
		if (isused[2] == 'fail')
		{
			fail = true;
		}
	}
	
	if (isused[3] != null)
	{
		allnull = false;
		if (isused[3] == 'fail')
		{
			fail = true;
		}
	}
	
	var message = document.getElementById('AJAX_Message');
	
	if (allnull == true)
	{
		message.innerHTML = "Please select at least one room and ensure you have selected <br />both the number of adults and number of children.";
	} else {
		if (fail == true)
		{
			message.innerHTML = "At least one selected room does not meet occupancy. <br />(Look for a red cross)";
		} else {
			document.SelectRooms.submit();
		}
	}
}