
/*
// Set initial values for global variables
*/
var num_RoomsRequired;
var obj_Occupancy;
var obj_ChildAges;
var minStringLen = 2;
var lastSearch = "";
var directionActive = "";
var currentSearch = 0;

/************************************************************************/
/* Internal call functions												*/
/************************************************************************/
function js_DOMCreateDiv(str_Class, str_Text, obj_ChildNode) {
	el_NewDiv = document.createElement('div');
	if (str_Class.length > 0) {
		el_NewDiv.className=str_Class;
	}
	if (str_Text != '') {
		el_NewText = document.createTextNode(str_Text);
		el_NewDiv.appendChild(el_NewText);
	}
	if (obj_ChildNode)
		el_NewDiv.appendChild(obj_ChildNode);
	return el_NewDiv;
}

function js_DOMCreateP(str_Class, str_Text, obj_ChildNode) {
	el_NewDiv = document.createElement("P");
	if (str_Class.len > 0) {
		if (navigator.userAgent.indexOf('MSIE') == -1) 
			el_NewDiv.setAttribute("class", str_Class);
		else
			el_NewDiv.setAttribute("className", str_Class);
	}
	if (str_Text != '') {
		el_NewText = document.createTextNode(str_Text);
		el_NewDiv.appendChild(el_NewText);
	}
	if (obj_ChildNode)
		el_NewDiv.appendChild(obj_ChildNode);
	return el_NewDiv;
}

function js_checkChildAgesFilled(formEle) {
	while (formEle.tagName!=='FORM') formEle=formEle.parentNode;	
	rExp=/frm_Child[0-9]/gi;
	allSet=true;
	if(formEle.elements.length>0) for(i=0;i<formEle.elements.length;i++) if(formEle.elements[i].id.search(rExp)>-1 && formEle.elements[i].options[formEle.elements[i].selectedIndex].value==-1) allSet=false;
	return allSet;
}

function js_DOMCreateSelect(str_FieldName, num_Min, num_Max, id) {
	if (id === undefined)
	{
		id = "";
	}
	el_NewSelect = document.createElement('SELECT');
	el_NewSelect.setAttribute('name', str_FieldName);
	el_NewSelect.setAttribute('id', id + str_FieldName);
	rExp=/frm_Child[0-9]/gi;
	if (str_FieldName.search(rExp)>-1) {
		js_addOption(el_NewSelect,'-1','-',false);
		if(document.getElementById('holSearchSubmit')) {
			el_NewSelect.onchange=function(){js_checkChildAgesFilled(this)};
		}
	}
	rExp=/frm_AdultsRoom[0-9]/gi;
	for (j = num_Min; j <= num_Max; j++) 
		if ((str_FieldName.search(rExp)>-1) && (j==2))
			js_addOption(el_NewSelect, j, j, true);
		else
			js_addOption(el_NewSelect, j, j, false);
	return el_NewSelect;
}

function js_SelectRoomOccupants(num_Rooms, id) {
	for (rl = 0; rl < num_Rooms; rl++) {
		num_RoomNum = rl + 1;
		var num_children = parseInt(obj_Occupancy["occupancy"][rl]["num_numchildren"]) + parseInt(obj_Occupancy["occupancy"][rl]["num_numinfants"]);
		js_selectValue('frm_AdultsRoom'+(num_RoomNum), obj_Occupancy["occupancy"][rl]["num_numadults"], false);
		js_selectValue('frm_ChildrenRoom'+(num_RoomNum), num_children, false);
	}
}

function js_SelectChildAges(id) {
	id = id || '';
	var num_Children = 0;
	for (i = 1; i <= num_RoomsRequired; i++) {
		num_Children = num_Children + parseInt($(id + 'frm_ChildrenRoom'+i).value)
	}
	for (ch = 1; ch <= num_Children; ch++) {
		js_selectValue(id + 'frm_Child'+(ch), arr_ChildAges[ch-1], false);
	}
}


// Function to add an option to a select list
function js_addOption(obj_docElem, str_value, str_text, bol_Selected) {
	var newElem = document.createElement("OPTION");
	newElem.value = str_value;
	newElem.text = str_text;
	if (bol_Selected) newElem.selected = 'selected';
	if (navigator.userAgent.indexOf('MSIE') == -1)
		obj_docElem.add(newElem, null);
	else
		obj_docElem.add(newElem);
}

// Function to select a value in the select list
function js_selectValue(str_formID, str_changeToValue, bol_CallOnChange) {
	var obj_SelectList = $(str_formID);
	if (obj_SelectList) {
		var num_SelectListItems = obj_SelectList.childNodes.length;
		if (num_SelectListItems != 0) {
			for (i=0; i<num_SelectListItems; i++) {
				if (obj_SelectList.childNodes[i].value == str_changeToValue) {
					obj_SelectList.childNodes[i].selected = true;
					if (bol_CallOnChange)
						obj_SelectList.onchange();
					return true;
				}
			}
		}
	}
}

// Function to remove the first child of a select list
function js_removeFirstChild(obj_docElem) {
	obj_docElem.removeChild(obj_docElem.firstChild);
}

// Function to remove all items from a select list
function js_removeAllChildren(obj_docElem) {
	if (obj_docElem !== null && obj_docElem.firstChild) {
		while (obj_docElem.firstChild) {
			obj_docElem.removeChild(obj_docElem.firstChild);
		}
	}
}

/************************************************************************/
/* External call functions												*/
/************************************************************************/

// Function to initialise the search form
function initHolidaySearchForm(id) {
	if (id === undefined)
	{
		id = '';
	}
	if (id.length === undefined)
	{
		// passed an event so clear id
		id = '';
	}
	for (i=1;i<10;i++) {
		if ($(id + 'JSonly_'+i)) {
			$(id + 'JSonly_'+i).style.display = 'block';
		} else break;
	}
	for (i=1;i<10;i++) {
		if ($(id + 'JSonlyrow_'+i)) {
			try{$(id + 'JSonlyrow_'+i).style.display = 'table-row';}
			catch(e){$(id + 'JSonlyrow_'+i).style.display = 'block';}
		} else break;
	}
	try {$(id + 'cal1input').style.backgroundImage='url(/images/icon_calendar.gif)';} catch (e) {}
	try {$(id + 'cal2input').style.backgroundImage='url(/images/icon_calendar.gif)';} catch (e) {}
	try {$(id + 'cal3input').style.backgroundImage='url(/images/icon_calendar.gif)';} catch (e) {}
	try {$(id + 'cal4input').style.backgroundImage='url(/images/icon_calendar.gif)';} catch (e) {}

	if ($(id + 'hs_ChildAges'))
	{ 
		$(id + 'hs_ChildAges').style.display = 'block';
	}
	js_OutputRoomOccupants(num_RoomsRequired, id);
	js_selectValue(id + 'frm_AdultsRoom1', 2, false);
	if (obj_Occupancy !== undefined)
	{
		js_SelectRoomOccupants(num_RoomsRequired, id);
	}
	js_OutputChildAges(id);
	js_SelectChildAges(id);
}

function js_OutputRoomOccupants(num_Rooms, id) {
	if (id === undefined)
	{
		id = '';
	}
	var adultslabel = '';
	var childrenlabel = '';
	
	obj_Occupants = $(id + 'hs_Occupants');
	num_RoomsRequired = num_Rooms;
	js_removeAllChildren(obj_Occupants);
	for (i = 1; i <= num_Rooms; i++) {
		// Create select lists
		obj_AdultsSelect = js_DOMCreateSelect('frm_AdultsRoom'+i, 1, 9, id);
		obj_ChildrenSelect = js_DOMCreateSelect('frm_ChildrenRoom'+i, 0, 9, id);
		// Create div's
		obj_RoomNumber = js_DOMCreateDiv('hs_OccupantsRoomNumber', 'Room '+i);
		obj_Adults = js_DOMCreateDiv('hs_OccupantsAdults', '', obj_AdultsSelect);
		obj_Children = js_DOMCreateDiv('hs_OccupantsChildren', '', obj_ChildrenSelect);
		if (navigator.userAgent.indexOf('MSIE') == -1){
			obj_Children.onchange = function() { js_OutputChildAges (id) };
		}
		obj_Clear = js_DOMCreateDiv('hs_Clear', '');
		// Append the div's to the main object
		obj_Occupants.appendChild(obj_RoomNumber);
		obj_Occupants.appendChild(obj_Adults);
		obj_Occupants.appendChild(obj_Children);
		obj_Occupants.appendChild(obj_Clear);
		if (navigator.userAgent.indexOf('MSIE') != -1)
			eventAttached = document.getElementById(id + 'frm_ChildrenRoom'+i).attachEvent('onchange', function() { js_OutputChildAges(id) });
	}
	js_OutputChildAges(id);
}

function js_OutputChildAges(id) {
	if (id === undefined)
	{
		id = '';
	}
	if (Number(id) == id) {
		id = '';
	}
	obj_ChildAges = $(id + 'hs_ChildAges');
	if (obj_ChildAges !== null) {
		js_removeAllChildren(obj_ChildAges);
		var num_Children = 0;
		for (i = 1; i <= num_RoomsRequired; i++) {
				num_Children = num_Children + parseInt($(id + 'frm_ChildrenRoom'+i).value)
		}
		if (num_Children != 0) {
			obj_IntroText = js_DOMCreateDiv('hs_ChildIntroText', 'Please specify the ages of children at time of travel.');
			obj_ChildAges.appendChild(obj_IntroText);
			obj_ChildAges.appendChild(obj_Clear);
			for (i = 1; i <= num_Children; i++) {
				// Create select lists
				obj_ChildAgeSelect = js_DOMCreateSelect('frm_Child'+i, 0, 17, id);
				// Create div's
				obj_ChildNumber = js_DOMCreateDiv('hs_ChildrenNumber', 'Child '+i);
				obj_ChildAge = js_DOMCreateDiv('hs_Children', '', obj_ChildAgeSelect);
				obj_Clear = js_DOMCreateDiv('hs_Clear', '');
				// Append the div's to the main object
				obj_ChildAges.appendChild(obj_ChildNumber);
				obj_ChildAges.appendChild(obj_ChildAge);
				obj_ChildAges.appendChild(obj_Clear);
			}
			obj_ChildAges.style.display = 'block';
		} else {
			obj_ChildAges.style.display = 'none';
		}
	}
	try{initmargins();}catch(e){}
}

function toggle_advSearch() {
	if($('hs_adv_hide')) var B=$('hs_adv_hide').style.display;
	if($('hs_adv_show')) var A=$('hs_adv_show').style.display;
	//fix for IE
	if(A === '') A = 'block';
	if(B === '') B = 'block';
	if (A && B) {
		$('hs_adv_show').style.display=B;
		$('hs_adv_hide').style.display=A;
		if($('hs_adv_1')) $('hs_adv_1').style.display=A;
		if($('hs_adv_2')) $('hs_adv_2').style.display=A;
		if($('hs_adv_3')) $('hs_adv_3').style.display=A;
		if($('hs_adv_4')) $('hs_adv_4').style.display=A;
	}
}

function js_hideAllPopups() {
		try {hidePopups();} catch (e) {}
		if($('cal1anchor')) $('cal1anchor').style.display = 'none';
		if($('cal2anchor')) $('cal2anchor').style.display = 'none';
		if($('cal3anchor')) $('cal3anchor').style.display = 'none';
		if($('frm_departure_suggestions')) $('frm_departure_suggestions').style.display = 'none';
		if($('frm_destination_suggestions')) $('frm_destination_suggestions').style.display = 'none';
		if ($("hideDiv"))$("hideDiv").style.display = 'none';
		if (navigator.userAgent.match('MSIE 6')) {
			if($('NoA')) $('NoA').style.visibility = 'visible';
			if($('NoC')) $('NoC').style.visibility = 'visible';
		}
		if($('submitButton')) $('submitButton').disabled=false;
}

	
	function js_updateNights(num_Nights) {
		var inwardDate = document.getElementById("cal1input");
		var outwardDate = document.getElementById("cal2input");
		
		var endDate = new Date(inwardDate.value.substr(6,4),(inwardDate.value.substr(3,2)-1),inwardDate.value.substr(0,2));
		
		endDate.setTime(endDate.getTime()+(num_Nights*24*60*60*1000));
		outwardDate.value = lZero(endDate.getDate(),2)+"/"+lZero(endDate.getMonth()+1,2)+"/"+lZero(endDate.getFullYear(),2);
		
		DLHNS.calendar.cal2.select((endDate.getMonth()+1)+"/"+endDate.getDate()+"/"+endDate.getFullYear());
		DLHNS.calendar.cal2.setYear(endDate.getFullYear());
		DLHNS.calendar.cal2.setMonth(endDate.getMonth());
		DLHNS.calendar.cal2.render();
	}
	
	// FUNCTIONS FOR AJAX FLIGHT SEARCH (FREEFORM)
	
	
	function js_suggestAirport(airportDirection,searchString) {
		if ( searchString != lastSearch) {
			directionActive = airportDirection;
			//js_hideAllPopups();
			if (searchString.length >= minStringLen) {
				// Perform search
					// Search token
					currentSearch++;
					// Update last search variable
					lastSearch = searchString;
					
					// Generate query string with string attached, not forgetting to specify if it's departure or destination
					var url = '/flight_search_ajax.cfm';
					var pars = 'method=suggestAirport&currentSearch='+currentSearch+'&direction='+directionActive+'&searchString='+searchString;
		
					// If it is destination field, then make sure that there is a departure airport selected
					if (directionActive == 'destination' && document.getElementById('frm_departure_point').value != "") {
						// If so then append to query string
						pars += '&deptCode='+document.getElementById('frm_departure_point').value;
					} 
					if (directionActive == 'departure' && document.getElementById('frm_destination_point').value != "") {
						pars += '&destCode='+document.getElementById('frm_destination_point').value;
					}
		
					// Submit the query string and then this function is done
					var myAjax = new Ajax.Request(	url, 
							{
								method: 'get', 
								parameters: pars, 
								onComplete: js_updateSuggestionField
							});
			} else {
				// If string is too short, clear out element
				js_hideAllPopups();
				var obj_divElement = document.getElementById('frm_'+directionActive+'_suggestions');
				while (obj_divElement.firstChild) obj_divElement.removeChild(obj_divElement.firstChild);
				lastSearch = "";
			}
		}
	}
	
	function js_hideAndSelect() {
		// Find selected index
		selIndex = js_findSelectedIndex();
		// If there is a selected index, then execute onclick
		if (!isNaN(selIndex) && directionActive) {
			document.getElementById('frm_'+directionActive+'_suggestions').style.display = 'none';
			if (document.getElementById('li_' + directionActive + '_' + selIndex + '_text')) {
				document.getElementById('frm_'+directionActive+'_name').value = document.getElementById('li_' + directionActive + '_' + selIndex + '_text').value;
				lastSearch = document.getElementById('li_' + directionActive + '_' + selIndex + '_text').value;
			} 
			if (document.getElementById('li_' + directionActive + '_' + selIndex + '_value')) document.getElementById('frm_'+directionActive+'_point').value = document.getElementById('li_' + directionActive + '_' + selIndex + '_value').value;
			
			// Unset these variables
			directionActive = "";
		}
		
		// Finally hide the element and show selects again
		js_hideAllPopups();
	}
	
	function js_findSelectedIndex() {
		// Need to first see if there is a list in the defined direction
		if (document.getElementById(directionActive+'_ul')) {
			list = document.getElementById(directionActive+'_ul');
			// Then need to find out how many children
			nChildren = list.childNodes.length;
			if (nChildren > 0) {
				// Then need to go through the children to find which is currently selected
				for (i = 0; i < nChildren; i++) {
					if (list.childNodes[i] && list.childNodes[i].className && list.childNodes[i].className == 'frm_suggest_list_hover') {
						return i;
					}
				}
			}
		}
		// If none is selected then false needs to be returned
		return false;
	}
	
	function js_highlightSelection(selIndex) {
		// Determine previously selected index
		curIndex = js_findSelectedIndex();
		if (document.getElementById(directionActive+'_ul') && curIndex !== selIndex) {
			list = document.getElementById(directionActive+'_ul');
			
			if (selIndex == 'n' || selIndex == 'p') {
				if (selIndex == 'n' && curIndex < list.childNodes.length - 1) {
					selIndex = curIndex + 1;
				} else if (selIndex == 'p' && curIndex > 0) {
					selIndex = curIndex - 1;
				}
			}
			if (!isNaN(selIndex)) {
				// Find current selected index, and unset that
				list.childNodes[selIndex].className = 'frm_suggest_list_hover';
				if (curIndex !== false) list.childNodes[curIndex].className = '';
			}
		}
	}
	function js_moveSelection(e, element) {
		if (element.id == "hotel_name")
		{
			js_moveHotelSelection(e);
			return;
		}
		
		if (!e) e = window.event;
		if (e.keyCode == 38) {
			// Move up
			js_highlightSelection('p');
		} else if (e.keyCode == 40) {
			// Move down
			js_highlightSelection('n');
		} else if (e.keyCode == 9 || e.keyCode == 13) {
			// Tab so deselect
			js_hideAndSelect();
		} else if ((e.keyCode == 8 || e.keyCode == 46) && document.getElementById('frm_'+directionActive+'_point').value != '') {
			// If something has been deleted unset airport code and all that jazz
			document.getElementById('frm_'+directionActive+'_point').value = '';
			while (document.getElementById('frm_'+directionActive+'_suggestions').firstChild) document.getElementById('frm_'+directionActive+'_suggestions').removeChild(document.getElementById('frm_'+directionActive+'_suggestions').firstChild);
		}
	}
	
	function js_updateSuggestionField(responseData) {
		// Need text field, div, and hidden
		var xml_data = responseData.responseXML;
		var searchid = xml_data.getElementsByTagName('r')[0].getAttribute('sid');
		var searchterm = document.getElementById('frm_' + directionActive + '_name').value;
		// If this matches the current search id, continue
		if (searchid == currentSearch && searchterm.length >= minStringLen) {
			var obj_divElement = document.getElementById('frm_'+directionActive+'_suggestions');
			var num_Elements = xml_data.getElementsByTagName('p').length;
			// Clear out the div
			while (obj_divElement.firstChild) obj_divElement.removeChild(obj_divElement.firstChild);
			// If there are any results then enter them,hiding stuff first
			obj_divElement.style.display = 'none';
			if (num_Elements > 0) {
				// Regexp string for the entered text
				rExp = new RegExp('('+searchterm+')','gi');
				
				// Now cycle through any results adding to the div
				newUL = document.createElement('ul');
				newUL.id = directionActive+'_ul';
				for (var i = 0; i < num_Elements; i++) {
					airportCode = xml_data.getElementsByTagName('p')[i].getAttribute('v');
					airportName = xml_data.getElementsByTagName('p')[i].firstChild.data;
					divText = airportName.replace(rExp,'<span class="selHighlight">$1</span>');
					newUL.innerHTML += '<li onmouseover="js_highlightSelection(' + i + ')" onclick="js_hideAndSelect()"><input type="hidden" id="li_' + directionActive + '_' + i + '_value" value="' + airportCode + '" /><input type="hidden" id="li_' + directionActive + '_' + i + '_text" value="' + airportName + '" />' + divText + '</li>';
				}
				obj_divElement.appendChild(newUL);
				
				// And display, hiding selects for IE
				if (navigator.userAgent.match('MSIE 6')) {
					if ($('NoA')) $('NoA').style.visibility = 'hidden';
					if ($('NoC')) $('NoC').style.visibility = 'hidden';
				}
				// Disable submit button until done to prevent submission on enter
				if ($('submitButton')) $('submitButton').disabled=true;
				obj_divElement.style.display = 'block';
				// Highlight first choice
				js_highlightSelection(0);
			} else {
				// No results, say so
				obj_divElement.innerHTML += '<div class="noFFResults"><i>no results found</i></div>'
				obj_divElement.style.display = 'block';
			}
			if (document.getElementById("hideDiv")) 		document.getElementById("hideDiv").style.display = 'block';
		}
	}
	
	function fs_deptClearOnFirstClick() {
		$('frm_departure_point').value = '';
		$('frm_departure_name').value = '';
		$('frm_departure_name').onclick = js_hideAllPopups;
		js_hideAllPopups();
	}
	
	function ms_SetSite(site_id) {
		switch (site_id) {
			case 'DLF' :
				if ($('dlh_dayslater')) $('dlh_dayslater').style.display = 'none';
				if ($('dlh_dest_point')) $('dlh_dest_point').style.display = 'none';
				if ($('dlh_dept_point')) $('dlh_dept_point').style.display = 'none';
				if ($('dla_dest_point')) $('dla_dest_point').style.display = 'none';
				if ($('hs_dates')) $('hs_dates').style.display = 'none';
				if ($('hs_duration')) $('hs_duration').style.display = 'none';
				if ($('hs_rooms')) $('hs_rooms').style.display = 'none';
				if ($('hs_rooms_occ')) $('hs_rooms_occ').style.display = 'none';
				if ($('hs_extras')) $('hs_extras').style.display = 'none';
				if ($('hs_extras_switch')) $('hs_extras_switch').style.display = 'none';
				
				if ($('dlf_dest_point')) $('dlf_dest_point').style.display = 'block';
				if ($('hs_dept_header')) $('hs_dept_header').style.display = 'block';
				if ($('dlf_dept_point')) $('dlf_dept_point').style.display = 'block';
				if ($('dlf_dates')) $('dlf_dates').style.display = 'block';
				if ($('dlf_rooms')) $('dlf_rooms').style.display = 'block';
				break;
				
			case 'DLH' :
				if ($('dla_dest_point')) $('dla_dest_point').style.display = 'none';
				
				if ($('dlh_dest_point')) $('dlh_dest_point').style.display = 'block';
				if ($('hs_dept_header')) $('hs_dept_header').style.display = 'block';
				if ($('dlh_dept_point')) $('dlh_dept_point').style.display = 'block';
				if ($('dlh_dayslater')) $('dlh_dayslater').style.display = 'block';
				
			case 'DLA' :
				if (site_id == 'DLA') {
					if ($('dlh_dest_point')) $('dlh_dest_point').style.display = 'none';
					if ($('hs_dept_header')) $('hs_dept_header').style.display = 'none';
					if ($('dlh_dept_point')) $('dlh_dept_point').style.display = 'none';
					if ($('dlh_dayslater')) $('dlh_dayslater').style.display = 'none';
					
					if ($('dla_dest_point')) $('dla_dest_point').style.display = 'block';
				}
				
				if ($('dlf_dest_point')) $('dlf_dest_point').style.display = 'none';
				if ($('dlf_dept_point')) $('dlf_dept_point').style.display = 'none';
				if ($('dlf_dates')) $('dlf_dates').style.display = 'none';
				if ($('dlf_rooms')) $('dlf_rooms').style.display = 'none';
				
				if ($('hs_dates')) $('hs_dates').style.display = 'block';
				if ($('hs_duration')) $('hs_duration').style.display = 'block';
				if ($('hs_rooms')) $('hs_rooms').style.display = 'block';
				if ($('hs_rooms_occ')) $('hs_rooms_occ').style.display = 'block';
				if ($('hs_extras')) $('hs_extras').style.display = 'block';
				if ($('hs_extras_switch')) $('hs_extras_switch').style.display = 'block';
				
				break;
		}
		js_OutputChildAges();
		js_SelectChildAges();
	}

	function js_suggestHotel(searchString) {
		if ( searchString != lastSearch) {
			//js_hideAllPopups();
			if (searchString.length >= minStringLen) {
				// Perform search
					// Search token
					currentSearch++;
					// Update last search variable
					lastSearch = searchString;
					
					// Generate query string with string attached, not forgetting to specify if it's departure or destination
					var url = '/hotel_search_ajax.cfm';
					var pars = 'method=suggestHotel&currentSearch='+currentSearch+'&searchString='+searchString;
		
					// Submit the query string and then this function is done
					var myAjax = new Ajax.Request(	url, 
							{
								method: 'get', 
								parameters: pars, 
								onComplete: js_updateHotelSuggestionField
							});
			} else {
				// If string is too short, clear out element
				js_hideAllPopups();
				var obj_divElement = $('hotel_suggestions');
				while (obj_divElement.firstChild) obj_divElement.removeChild(obj_divElement.firstChild);
				lastSearch = "";
			}
		}
	}
	
	function js_updateHotelSuggestionField(responseData) {
		// Need text field, div, and hidden
		var xml_data = responseData.responseXML;
		var searchid = xml_data.getElementsByTagName('r')[0].getAttribute('sid');
		var searchterm = $('hotel_name').value;
		// If this matches the current search id, continue
		if (searchid == currentSearch && searchterm.length >= minStringLen) {
			var obj_divElement = $('hotel_suggestions');
			var num_Elements = xml_data.getElementsByTagName('p').length;
			// Clear out the div
			while (obj_divElement.firstChild) obj_divElement.removeChild(obj_divElement.firstChild);
			// If there are any results then enter them,hiding stuff first
			obj_divElement.style.display = 'none';
			if (num_Elements > 0) {
				// Regexp string for the entered text
				rExp = new RegExp('('+searchterm.replace(/ /g,'|')+')','gi');
				
				// Now cycle through any results adding to the div
				newUL = document.createElement('ul');
				newUL.id = 'hotel_ul';
				for (var i = 0; i < num_Elements; i++) {
					hotelDEBUG = xml_data.getElementsByTagName('p')[i];
					hotelName = xml_data.getElementsByTagName('p')[i].firstChild.data;
					hotelID = xml_data.getElementsByTagName('p')[i].getAttribute('id');
					divText = hotelName.replace(rExp,'<span class="selHighlight">$1</span>');
					newUL.innerHTML += '<li onmouseover="js_highlightHotelSelection(' + i + ')" onclick="js_hideAndSelectHotel()"><input type="hidden" id="li_hotel_' + i + '_text" value="' + hotelName + '" /><input type="hidden" id="li_hotel_' + i + '_id" value="' + hotelID + '">' + divText + '</li>';
				}
				obj_divElement.appendChild(newUL);
				
				// And display, hiding selects for IE
				if (navigator.userAgent.match('MSIE 6')) {
					for (i=0; i<hideElements.length; i++) {
						if (document.getElementById(hideElements[i])) document.getElementById(hideElements[i]).style.visibility = 'hidden';	
					}
				}
				// Disable submit button until done to prevent submission on enter
				document.getElementById('submitButton').disabled=true;
				obj_divElement.style.display = 'block';
				// Highlight first choice
				js_highlightHotelSelection(0);
			} else {
				// No results, say so
				obj_divElement.innerHTML += '<div class="noFFResults"><i>no results found</i></div>'
				obj_divElement.style.display = 'block';
			}
			if (document.getElementById("hideDiv")) 		document.getElementById("hideDiv").style.display = 'block';
		}
	}
	
	function js_moveHotelSelection(e) {
		if (!e) e = window.event;
		if (e.keyCode == 38) {
			// Move up
			js_highlightSelection('p');
		} else if (e.keyCode == 40) {
			// Move down
			js_highlightSelection('n');
		} else if (e.keyCode == 9 || e.keyCode == 13) {
			// Tab so deselect
			js_hideAndSelect();
		} else if ((e.keyCode == 8 || e.keyCode == 46) && document.getElementById('hotel_value').value != '') {
			// If something has been deleted unset airport code and all that jazz
			document.getElementById('hotel_value').value = '';
			while (document.getElementById('hotel_suggestions').firstChild) document.getElementById('hotel_suggestions').removeChild(document.getElementById('hotel_suggestions').firstChild);
		}
	}
	function js_highlightHotelSelection(selIndex) {
		// Determine previously selected index
		curIndex = js_findSelectedHotelIndex();
		if (document.getElementById('hotel_ul') && curIndex !== selIndex) {
			list = document.getElementById('hotel_ul');
			
			if (selIndex == 'n' || selIndex == 'p') {
				if (selIndex == 'n' && curIndex < list.childNodes.length - 1) {
					selIndex = curIndex + 1;
				} else if (selIndex == 'p' && curIndex > 0) {
					selIndex = curIndex - 1;
				}
			}
			if (!isNaN(selIndex)) {
				// Find current selected index, and unset that
				list.childNodes[selIndex].className = 'frm_suggest_list_hover';
				if (curIndex !== false) list.childNodes[curIndex].className = '';
			}
		}
	}
	
	function js_hideAndSelectHotel() {
		// Find selected index
		selIndex = js_findSelectedHotelIndex();
		// If there is a selected index, then execute onclick
		if (!isNaN(selIndex)) {
			$('hotel_suggestions').style.display = 'none';
			if ($('li_hotel_' + selIndex + '_text')) {
				$('hotel_name').value = $('li_hotel_' + selIndex + '_text').value;
				$('hotel_value').value = $('li_hotel_' + selIndex + '_id').value;
				if ($('sl_hotel_value')) $('sl_hotel_value').innerHTML = $('li_hotel_' + selIndex + '_id').value;
				lastSearch = $('hotel_name').value
			}
		}
		
		// Finally hide the element and show selects again
		js_hideAllPopups();
	}
	function js_findSelectedHotelIndex() {
		// Need to first see if there is a list in the defined direction
		if (document.getElementById('hotel_ul')) {
			list = document.getElementById('hotel_ul');
			// Then need to find out how many children
			nChildren = list.childNodes.length;
			if (nChildren > 0) {
				// Then need to go through the children to find which is currently selected
				for (i = 0; i < nChildren; i++) {
					if (list.childNodes[i] && list.childNodes[i].className && list.childNodes[i].className == 'frm_suggest_list_hover') {
						return i;
					}
				}
			}
		}
		// If none is selected then false needs to be returned
		return false;
	}
