<!--

function onChangeCarCountry(fId)
{
	//div_switch('car_pickup', false, true);
	document.getElementById('car_pickup').style.display = 'none';
	document.getElementById('car_pickup_loading').style.display = 'block';
	//div_switch('car_pickup_loading', true, true);
	document.getElementById('pickup').selectedIndex = 0;
	document.frmCombinedSearch.submit();
}
function checkCarOnlyForm(fId)
{	
	fId2 = document.getElementById("frmProfileSearch")
	
	if(document.getElementById("country").selectedIndex == "0")
	{ 
		alert("Please select a pickup country!"); 
		fId2.country.focus(); 
		return false; 
	}
	else if(document.getElementById("pickup").selectedIndex == "0")
	{ 
		alert("Please select a pickup point!"); 
		fId2.pickup.focus(); 
		return false; 
	}
	else if(checkValidDate(fId) == false)
	{ alert("Please select an alternative departure date!\nThe date you have selected is unavailable."); fId.startdate_d.focus(); return false; }
	else
	{ return true; }
}
function updateDurations()
{
	addDuration(document.frmProfileSearch);
}
function setCarhire(sVal){

	if(document.getElementById('add_car_hire').checked == true){
		document.getElementById('search_type').value = document.getElementById('search_type').value + '_Car';
		bCarhire = true;
	}else{
		document.getElementById('search_type').value = document.getElementById('search_type').value.replace('_Car', '');
		bCarhire = false;
	}
	setSearchGrid('ALL', 'Flight_Hotel', '');
	//alert(document.getElementById('search_type').value);

}
// BEGIN AJAX 
function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() 
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
		
			response  = req.responseXML.documentElement;
			vOptions    =	response.getElementsByTagName('vOption')[0].firstChild.nodeValue
			oOptions = vOptions.split("_");
			document.getElementById('pickup').options.length = oOptions.length;
			for(i=0;i<oOptions.length;i++){
				sDestArray = oOptions[i].split("-");
				//document.getElementById('pickup').options[i] = new Option(sDestArray[1], sDestArray[0], false, false);
				document.getElementById('pickup').options[i].text = sDestArray[1];
				document.getElementById('pickup').options[i].value = sDestArray[0];
				if(sDestArray[2] == 'Selected'){ document.getElementById('pickup').options[i].selected = true;}
			}
		
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}
function checkName(input, response, sSelected)
{
	if(input != 'NEW'){
		//document.getElementById('btnGo').value = 'Amend Programme Details';
	  if (response != ''){ 
		// Response mode
		message   = 'Trumps';
		if (response == '1'){
		  message.className = 'error';
		}else{
		  message.className = 'hidden';
		} 
	  }else{
		// Input mode
		url  = '/carhire/ajax_response.asp?country=' + input + '&Selected='+sSelected;
		loadXMLDoc(url);
		
	  }
	}

}
// END AJAX
// -->

<!--
	var sListBoxToChange = "";
	var sNoResultsMsg = "";
	var oListBoxToReset = null;
	var sSelectedOption = '';
	
	function clearListBox(listElem) {
		if(listElem!=0){
			while(listElem.options.length > 0) {
				listElem.options[0] = null;
			}
			while(listElem.hasChildNodes()) {
				listElem.removeChild(listElem.firstChild);
			}
		}
	}

	function checkSearchForm(sForm) {
		var sSearchType = document.getElementById('search_type').value;
		var oLocationTo = document.getElementById('lstResort');
		var bRetVal = true;
		
		//updates the duration incase user has manually edited the date field
		updateSearchDuration(document.getElementById('lstDepartureDates').value,document.getElementById('rtnDate').value)
		
		
		if(document.getElementById('currentSearchMethodFlag').value == 'predictiveSearchDiv')
		{
			
			getLocations(document.getElementById('idFreetext' + sSearchType).value, sForm, sSearchType);
			bRetVal = false;
		}
		else
		{
			if(sSearchType == 'Flight' || sSearchType == 'Flight_Hotel') {
				//var oDepartures = document.getElementById('lstDepartureDates');
				var oLocationTo = document.getElementById('lstResort');
				if(oLocationTo.options[oLocationTo.selectedIndex].value == '-' || oLocationTo.disabled == true) {
					alert('Please ensure you have selected an option from all \'Going to\' list boxes and try again.');
					bRetVal = false;
				}
				var oDeparturePoint = document.getElementById('predAirportFrom');
				if(oDeparturePoint.options[oDeparturePoint.selectedIndex].value == '-') {
					alert('Please ensure you have selected your departure airport and try again.');
					bRetVal = false;
				}
				
				//else if(!checkDateBoxes()){
				//	bRetVal = false;
				//}
				
			} else if(sSearchType == 'Hotel') {
				if(oLocationTo.options[oLocationTo.selectedIndex].value == '-' || oLocationTo.disabled == true) {
					alert('Please ensure you have selected an option from all \'Going to\' list boxes and try again.');
					bRetVal = false;
				}
				//else if(!checkDateBoxes()){
				//	bRetVal = false;
				//}
			}
		}
		
		return bRetVal;
	}

	function updateDirectOnly(bChecked) {
		if(bChecked && document.getElementById('lstCountry').selectedIndex != 0) {
			sAirportFrom = document.getElementById('lstAirportFrom').options[document.getElementById('lstAirportFrom').selectedIndex].value;
			sLocationTo = document.getElementById('lstResort').options[document.getElementById('lstResort').selectedIndex].value;
			var sUrl = '/buildyourown/includes/navigation/searchBoxAjax.asp?request=departuredates&searchvalue='+sAirportFrom+'&locationto='+sLocationTo+'&directonly=1&selectedvalue=&rand='+Math.random();
			
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
				req.onreadystatechange = changeDirectOnly;
				req.open("GET", sUrl, true);
				req.send(null);
			// branch for IE/Windows ActiveX version
			} else if (window.ActiveXObject) {
				try { 
				   req = new ActiveXObject("Msxml2.XMLHTTP"); 
				} catch (e) { 
					try { 
						req = new ActiveXObject("Microsoft.XMLHTTP"); 
					} catch (e) {} 
				}

				if (req) {
					req.onreadystatechange = changeDirectOnly;
					req.open("GET", sUrl, true);
					req.send();
				}
			}			
		}
	}

	
	function changeDirectOnly() {
		if (req.readyState == 4){
			if (req.status == 200) {
				var oListBox = document.getElementById(sListBoxToChange);
				var oXmlDoc = req.responseXML.documentElement;
				var oNodes = oXmlDoc.getElementsByTagName('Result');
				if(!(oNodes.length > 0)) {
					if(confirm('There are no direct flights available from this airport to this destination. Continuing will reset the destinations selected.\n\nDo you want to continue?')) {
						disableBox('lstCity');
						disableBox('lstResort');
						disableBox('lstAirportFrom');
						disableBox('lstDepartureDates');
						document.getElementById('lstCountry').selectedIndex = 0;
					} else {
						document.getElementById('chkDirectFlight').checked = false;
					}
				}
			} else {
			
			}
		}
	}

	function updateLocationBox(sListBox, sRequestType, sSearchValue, sSelectedValue, sParam1, sParam2, sErrMessage, oListToReset) {
		//alert(sSearchValue);
		sNoResultsMsg = sErrMessage;
		oListBoxToReset = oListToReset;
		//if(document.getElementById("img_"+sListBox)) document.getElementById("img_"+sListBox).style.display = 'inline';
		if(document.getElementById("img_"+sListBox)) document.getElementById("img_"+sListBox).src = '/images/layout/ajax-loader.gif';
		
		document.getElementById(sListBox).options[0].text = 'Please wait...';
		var url = '/buildyourown/includes/navigation/searchBoxAjax.asp?request='+sRequestType+'&searchvalue='+sSearchValue+'&selectedvalue='+sSelectedValue+'&param1='+sParam1+'&param2='+sParam2+'&rand='+Math.random();
		
		//if(confirm('Open window? ' + url)) { window.open(url); }
		
		sListBoxToChange = sListBox;
		sndReq(url);
	}
	
	
	function updateDirectAM(sAirportFrom) {
		// NE 19/02/2008 Ticket 7230 sAirportFrom may have a boolean attached to say whether this was chosen from the direct or indirect section
		if (sAirportFrom.indexOf(';') > -1) {
			sValues = sAirportFrom.split(';');
			sAirportFrom = sValues[0];
			
			if (sValues.length > 1 && (sValues[1] == 'true' || sValues[1] == 'false')) {
				chkDirect = document.getElementById('chkDirectFlight');
				if (chkDirect) { chkDirect.checked = (sValues[1] == 'true') ? true : false; }
			}
			
			//alert(chkDirect.checked)
		}	
	}
	
	function updateDepartureDateOld(sListBox, sLocationTo, sAirportFrom, sDirectOnly, sSelectedValue) {
		sDirectOnly = (sDirectOnly == true) ? 1 : 0;
		//if(document.getElementById("img_"+sListBox)) document.getElementById("img_"+sListBox).style.display = 'inline';
		if(document.getElementById("img_"+sListBox)) document.getElementById("img_"+sListBox).src = '/images/layout/ajax-loader.gif';
		document.getElementById(sListBox).options[0].text = 'Please wait...';
		// NE 19/02/2008 Ticket 7230 sAirportFrom may have a boolean attached to say whether this was chosen from the direct or indirect section
		if (sAirportFrom.indexOf(';') > -1) {
			sValues = sAirportFrom.split(';');
			sAirportFrom = sValues[0];
			
			if (sValues.length > 1 && (sValues[1] == 'true' || sValues[1] == 'false')) {
				chkDirect = document.getElementById('chkDirectFlight');
				if (chkDirect) { chkDirect.checked = (sValues[1] == 'true') ? true : false; }
			}
		}
		
		var url = '/buildyourown/includes/navigation/searchBoxAjax.asp?request=departuredates&searchvalue='+sAirportFrom+'&locationto='+sLocationTo+'&directonly='+sDirectOnly+'&selectedvalue='+sSelectedValue+'&rand='+Math.random();
		//if(confirm('Open window? ' + url)) { window.open(url); }
		sListBoxToChange = sListBox;
		sndReq(url);
	}
	
	function sndReq(sUrl) {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = changeListBox;
			req.open("GET", sUrl, true);
			req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			try { 
			   req = new ActiveXObject("Msxml2.XMLHTTP"); 
			} catch (e) { 
				try { 
					req = new ActiveXObject("Microsoft.XMLHTTP"); 
				} catch (e) {} 
			}
				
			if (req) {
				req.onreadystatechange = changeListBox;
				req.open("GET", sUrl, true);
				req.send();
			}
		}
		//if(confirm('Open window?')) { window.open(sUrl); }
	}
	
	function changeListBox() {
		if (req.readyState == 4){
			if (req.status == 200) {
				var oListBox = document.getElementById(sListBoxToChange);
				var oXmlDoc = req.responseXML.documentElement;
				var oNodes = oXmlDoc.getElementsByTagName('Result');
				clearListBox(oListBox);
				
				//if(document.getElementById("img_"+sListBoxToChange)) document.getElementById("img_"+sListBoxToChange).style.display = 'none';
				if(document.getElementById("img_"+sListBoxToChange)) document.getElementById("img_"+sListBoxToChange).src = '/images/layout/search-arrow-home.gif';
				
				var iSelectedValue = 0;
				
				oListBox.options[0] = new Option('- Select -','-');
				if(oNodes.length > 0) {
					/*
					for(var i = 0; i < oNodes.length; i++) {
						var sValue = oNodes.item(i).attributes.getNamedItem("Value").nodeValue;
						var sName = oNodes.item(i).childNodes.item(0).nodeValue;
						var sSelected = oNodes.item(i).attributes.getNamedItem("Value").nodeValue;
						if(sSelected == '1') { iSelectedValue = i + 1; }
						oListBox.options[oListBox.options.length] = new Option(sName, sValue);
					}
					*/
					// NE 14/02/2008 Ticket 7230 Because OptGroups are required the above code becomes far more complicated. See http://www.thescripts.com/forum/thread92041.html for more information
					var oGroup, oOption; // TODO Too many if statements - could do with tidying up as it is essentially repeated code
					var bPopular = false;
					var bDirect = false;
					var iSearchType = 0; // 1 - lstCity, 2 - lstResort, 3 - lstAirportFrom
					
					var sTextPopular = '', sTextOther = '';
					switch (oListBox.id) {
						case 'lstCity': iSearchType = 1; sTextPopular = 'Top Destinations'; sTextOther = 'Other Destinations'; break;
						case 'lstResort': iSearchType = 2; sTextPopular = 'Most Popular'; sTextOther = 'Other Resorts'; break;
						case 'lstAirportFrom': iSearchType = 3; sTextDirect = 'Direct Available'; sTextOther = 'Indirect Available'; break;
					}
										
					for(var i=0;i<oNodes.length;i++) {
						if ((iSearchType == 1 || iSearchType == 2) && !bPopular && oNodes.item(i).attributes.getNamedItem("Popular").nodeValue == 'true') {
							if (oGroup) { oListBox.appendChild(oGroup); }
							oGroup = document.createElement('optgroup');
							oGroup.label = sTextPopular;
							bPopular = true;
						}
						
						if ((iSearchType == 1 || iSearchType == 2) && bPopular && oNodes.item(i).attributes.getNamedItem("Popular").nodeValue != 'true') {
							if (oGroup) { oListBox.appendChild(oGroup); }
							oGroup = document.createElement('optgroup');
							oGroup.label = sTextOther;
							bPopular = false;
						}
						
						if ((iSearchType == 3) && !bDirect && oNodes.item(i).attributes.getNamedItem("NumStops").nodeValue == '0') {
							if (oGroup) { oListBox.appendChild(oGroup); }
							oGroup = document.createElement('optgroup');
							oGroup.label = sTextDirect;
							bDirect = true;
						}
						
						if ((iSearchType == 3) && bDirect && oNodes.item(i).attributes.getNamedItem("NumStops").nodeValue != '0') {
							if (oGroup) { oListBox.appendChild(oGroup); }
							oGroup = document.createElement('optgroup');
							oGroup.label = sTextOther;
							bDirect = false;
						}
						
						oOption = document.createElement('option');
						oOption.innerHTML = oNodes.item(i).childNodes.item(0).nodeValue;
						oOption.value = oNodes.item(i).attributes.getNamedItem("Value").nodeValue;
						if (oListBox.id == 'lstAirportFrom') { oOption.value += ';' + bDirect; }
//						oOption = new Option(oNodes.item(i).childNodes.item(0).nodeValue, oNodes.item(i).attributes.getNamedItem("Value").nodeValue)
						var sSelected = oNodes.item(i).attributes.getNamedItem("Value").nodeValue;
						if(sSelected == '1') { iSelectedValue = i + 1; }
						
						if (oGroup) { oGroup.appendChild(oOption) } else { oListBox.appendChild(oOption) }
					}
					if (oGroup) { oListBox.appendChild(oGroup); }
					
					oListBox.selectedIndex = iSelectedValue;
					oListBox.disabled = false;
					
					if(oNodes.length == 1 && document.getElementById("search_type").value.toLowerCase() != 'hotel') {
						oListBox.selectedIndex = 1;
						oListBox.onchange();
					}
					
				} else {
					alert(sNoResultsMsg);
					oListBoxToReset.selectedIndex = 0;
				}
				
			} else {
				alert('There has been an error retrieving further information for this location.');
			}
		}
	}
	
	function disableBox(sListBox) {
		var oListBox = document.getElementById(sListBox);
		if(oListBox) {
			oListBox.selectedIndex = 0;
			oListBox.disabled = true;
		}
	}
	
	function changeRequestType(sNewType, sRadioButtons, sCurrentOption, oOptions) {
		
		// calls to disable and update the countries listbox disabled by AM 22/02/2008
		// I'd rather be able to maintain this manually to allow for restricted options on longhaul and short breaks etc.
		
		//if (sCurrentOption == "Hotel"){document.getElementById("airportto").disabled = false;}
		//else {document.getElementById("airportto").disabled = true;}
		
		if(document.getElementById('lstCountry').selectedIndex != 0) {
			if(confirm('Doing this will cause your destination selection to be reset.\n\nDo you want to continue?')) {
				disableBox('lstCity');
				disableBox('lstResort');
				disableBox('lstAirportFrom');
				//disableBox('lstDepartureDates');
				//disableBox('lstCountry');
				//updateLocationBox('lstCountry', 'countries', '', '', sCurrentOption,((document.getElementById('chkDirectFlight').checked == true) ? '1' : '0'),'Sorry, an error occurred', document.getElementById('lstCountries'));
				document.getElementById('lstCountry').selectedIndex = 0;
				document.getElementById('txtRequestType').value = sNewType;
				sSelectedOption = sCurrentOption;
				switchSearchType(sCurrentOption);
				return true;
			} else {
				for(var i = 0; i < oOptions.length; i++) {
					if(oOptions[i].value == sSelectedOption) { oOptions[i].checked = true; }
				}
				//disableBox('lstCountry');
				//updateLocationBox('lstCountry', 'countries', '', '', sCurrentOption,((document.getElementById('chkDirectFlight').checked == true) ? '1' : '0'),'Sorry, an error occurred', document.getElementById('lstCountries'));

				return false;
			}
		}
		//disableBox('lstCountry');
		document.getElementById('txtRequestType').value = sNewType;
		//updateLocationBox('lstCountry', 'countries', '', '', sCurrentOption,((document.getElementById('chkDirectFlight').checked == true) ? '1' : '0'),'Sorry, an error occurred', document.getElementById('lstCountries'));
		switchSearchType(sCurrentOption);
		
		
		return true;
	}

	function switchSearchType(sNewSearchType) {
	
		document.getElementById('search_type').value = sNewSearchType;
		switch (sNewSearchType.toLowerCase()) {
			case "flight":
				switchView('hotelOnlyDepartures', 'none');
				if (document.getElementById('currentSearchMethodFlag').value == 'predictiveSearchDiv'){switchView('flightHotelDepartures', 'none');switchView('predictiveSearchDiv2', 'inline');}else{switchView('flightHotelDepartures', 'inline');switchView('predictiveSearchDiv2', 'none');}
				switchView('flightInfo', '');
				switchView('flightOnlyPax', '');
				switchView('hotelPaxInfo', 'none');
				switchView('hotelRoomInfo', 'none');
				switchView('ReturnOneWay', 'block');
				document.getElementById('DepFromTitle').innerHTML = 'Departing from:';
				document.getElementById('idFreetextHotel').disabled = true;document.getElementById('idFreetextFlight_Hotel').disabled = true;document.getElementById('idFreetextFlight').disabled = false;
				switchView('idFreetextHotel', 'none');switchView('idFreetextFlight_Hotel', 'none');switchView('idFreetextFlight', 'block');
				break;
			case "flight_hotel":
				switchView('hotelOnlyDepartures', 'none');
				if (document.getElementById('currentSearchMethodFlag').value == 'predictiveSearchDiv'){switchView('flightHotelDepartures', 'none');switchView('predictiveSearchDiv2', 'inline');}else{switchView('flightHotelDepartures', 'inline');switchView('predictiveSearchDiv2', 'none');}
				switchView('flightInfo', '');
				switchView('flightOnlyPax', 'none');
				switchView('hotelPaxInfo', 'block');
				switchView('hotelRoomInfo', '');
				switchView('ReturnOneWay', 'none');
				document.getElementById('onewayFalse').checked = true;
				document.getElementById('DepFromTitle').innerHTML = 'Departing from:';
				document.getElementById('idFreetextHotel').disabled = true;document.getElementById('idFreetextFlight_Hotel').disabled = false;document.getElementById('idFreetextFlight').disabled = true;
				switchView('idFreetextHotel', 'none');switchView('idFreetextFlight_Hotel', 'block');switchView('idFreetextFlight', 'none');
				break;
			case "hotel":
				switchView('hotelOnlyDepartures', 'inline');
				switchView('flightHotelDepartures', 'none');
				switchView('predictiveSearchDiv2', 'none');
				switchView('flightInfo', 'none');
				switchView('flightOnlyPax', 'none');
				switchView('hotelPaxInfo', 'block');
				switchView('hotelRoomInfo', '');
				switchView('ReturnOneWay', 'none');	
				document.getElementById('DepFromTitle').innerHTML = 'Stay Dates:';
				document.getElementById('idFreetextHotel').disabled = false;document.getElementById('idFreetextFlight_Hotel').disabled = true;document.getElementById('idFreetextFlight').disabled = true;	
				switchView('idFreetextHotel', 'block');switchView('idFreetextFlight_Hotel', 'none');switchView('idFreetextFlight', 'none');
				break;
		}
	}
	
	function switchView(sId, sDisplay) {
		if(document.getElementById(sId)) {
			document.getElementById(sId).style.display = sDisplay;
		}
	}


	function setCurrentOption(oOptions) {
		for(var i = 0; i < oOptions.length; i++) {
			if(oOptions[i].checked) { sSelectedOption = oOptions[i].value; }
		}
	}
	
	
	function switchDestinationFinder() 
	{
		if(document.getElementById('predictiveSearchDiv').style.display == 'none')
		{
			document.getElementById('divFreetextCombinedSearch').style.display = 'inline';
			document.getElementById('divLocationLoadCombinedSearch').style.display = 'none';
			document.getElementById('divLocationCombinedSearch').style.display = 'none';
			document.getElementById('dropdownSearchDiv').style.display = 'none';
			document.getElementById('predictiveSearchDiv').style.display = 'block';
			document.getElementById('searchSwitchLink').innerHTML = 'Return to destinations list?';
			document.getElementById('currentSearchMethodFlag').value = 'predictiveSearchDiv'
			document.getElementById('predAirportFrom').disabled = false;
			document.getElementById('lstAirportFrom').disabled = true;
			document.getElementById('idLocationtoCombinedSearch').disabled = false;
			document.getElementById('lstResort').disabled = true;
			if (document.getElementById('search_type').value == 'Hotel')
			{switchView('flightHotelDepartures', 'none');switchView('predictiveSearchDiv2', 'none');}
			else
			{switchView('flightHotelDepartures', 'none');switchView('predictiveSearchDiv2', 'inline');}
		}
		else
		{
			document.getElementById('divFreetextCombinedSearch').style.display = 'inline';
			document.getElementById('divLocationLoadCombinedSearch').style.display = 'none';
			document.getElementById('divLocationCombinedSearch').style.display = 'none';
			document.getElementById('dropdownSearchDiv').style.display = 'block';
			document.getElementById('predictiveSearchDiv').style.display = 'none';
			document.getElementById('searchSwitchLink').innerHTML = 'Cant find your destination?';
			document.getElementById('currentSearchMethodFlag').value = 'dropdownSearchDiv'
			document.getElementById('predAirportFrom').disabled = true;
			document.getElementById('lstAirportFrom').disabled = false;
			document.getElementById('idLocationtoCombinedSearch').disabled = true;
			//document.getElementById('lstResort').disabled = false;
			if (document.getElementById('search_type').value == 'Hotel')
			{switchView('flightHotelDepartures', 'none');switchView('predictiveSearchDiv2', 'none');}
			else
			{switchView('flightHotelDepartures', 'inline');switchView('predictiveSearchDiv2', 'none');}
		}
	}
	
	function flightShowHideSearchChoice(searchOption){
		if (searchOption == 'flight'){
			document.getElementById('searchSwitchLink').style.display = 'none';
			if (document.getElementById('predictiveSearchDiv').style.display == 'none'){
				switchDestinationFinder();
			}
		}
		else{
			document.getElementById('searchSwitchLink').style.display = 'block';
		}
	}
//-->
