<!--
var sCurForm
var sCurSearchType

function changeCarInclude(sFrm) {
	var iFound = 0;
	sList = sFrm.includecar;
	for(x=0;x<sList.length;x++) {
		if(sList(x).checked == true && sList(x).value == 'yes') {
			iFound = 1
			sFrm.flexibility.disabled = true;
			if(sFrm.flexibility.value != '0' && sFrm.flexibility.value != '') {
				alert('No alternative departure dates are shown when the search includes a car.');
			}
			sFrm.flexibility.selectedIndex = 1;
		}else{
			if(iFound == 0) {
				sFrm.flexibility.disabled = '';
			}
		}
	}
}


function validateLocationForm() {
	sSubmitForm = document.getElementsByName('frm'+sCurForm);
	sLocationID = document.getElementById('idLocationto'+sCurForm);
	var e = sSubmitForm.elements, m = '';
	if(sLocationID.value=='-'){m += '- Please select a destination.\n';}
	if(validateDate('startdate_d'+sCurForm,'startdate_m'+sCurForm,'startdate_y'+sCurForm)<=0) {m += '- Departure date is not valid.\n';}
	if(document.getElementById('flexibility'+sCurForm)) {
		if(!document.getElementById('flexibility'+sCurForm).value) {
			m+='- Please select flexibility\n';
		}
	}
	//alert('duration'+sCurForm);
	if(document.getElementById('duration'+sCurForm)) {
		if(!document.getElementById('duration'+sCurForm).value) {
			m+='- Please select duration\n';
		}
	}
	if(document.getElementById('rooms'+sCurForm)) {
		if(document.getElementById('rooms'+sCurForm).value=='0') {
			m+='- Please select no. of rooms\n';
		}
	}
	if(m) {
		OpenSearch();
		switchLocationDivs('divLocation'+sCurForm);
		alert('The following errors occurred:\n\n' + m);
		return false;
	}else{
		sSubmitForm[0].submit();
	}	
}

function locationGoBack(sForm) {
	var sLocationID = document.getElementById('idLocationto'+sForm);
	var sFreetext = document.getElementById('idFreetext'+sForm);
	//alert(parseInt(GetElementWidth('idLocationto'+sForm)+6));
	sLocationID.style.width = '200px';
	clearLocationList(sLocationID);
	div_switch('divLocationLoad'+sForm, false, true);
	div_switch('divLocation'+sForm, false, true);
	div_switch('divFreetext'+sForm, true, true);
	sFreetext.focus();sFreetext.select();
}

function switchLocationDivs(sDiv) {
	div_switch('divFreetext'+sCurForm, false, true);
	div_switch('divLocationLoad'+sCurForm, false, true);
	div_switch('divLocation'+sCurForm, false, true);
	div_switch(sDiv, true, true);
}

//Clear List
function clearLocationList(listElem) {
	if(listElem!=0){
		while(listElem.options.length > 0) {
			listElem.options[0] = null;
		}
		while(listElem.hasChildNodes()) {
			listElem.removeChild(listElem.firstChild);
		}
	}
}

//On Change Event
function getLocations(sLocation,sForm,sSearchType) {
	sLocation = sLocation.replace("'","");
	sCurForm = sForm;
	sCurSearchType = sSearchType;
	var sLocationID = document.getElementById('idLocationto'+sCurForm);
	var sFreetextID = document.getElementById('idFreetext'+sCurForm);
	var oFreetextDivID = document.getElementById('divFreetext' + sCurForm);
	var bFreeTextVis = (oFreetextDivID == null || oFreetextDivID.style.display != 'none');
	
	if(bFreeTextVis && (sFreetextID.value.length<1 || sFreetextID.value == "- type your destination -")) {
		OpenSearch();
		alert('Please type your destination');
		sFreetextID.focus();
	}else if(sLocationID.value=='') {
		sURL = "/includes/search/LookupXML.asp?searchtype="+sCurSearchType+"&location=" + sLocation
		if(sURL!='') {
			//if(confirm('Open '+ sURL)) {
			//	window.open(sURL);
			//}
			clearLocationList(sLocationID);
			setTimeout("loadLocationXMLDoc('"+sURL+"')", 100);
		}else{
			alert('No url defined');	
		}
	}else{
		validateLocationForm();	
	}
}

//XML Loader
function loadLocationXMLDoc(url) {
    // branch for native XMLHttpRequest object
	var processChange = processLocationChange
	
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
		req.onreadystatechange = processChange;
        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 = processChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processLocationChange() {
	switchLocationDivs('divLocationLoad'+sCurForm);
	var divLocationBorder = document.getElementById('divLocationBorder'+sCurForm);
	//var divLocationPointer = document.getElementById('divLocationPointer'+sCurForm);
	var sLocationID = document.getElementById('idLocationto'+sCurForm);
	var sFreetext = document.getElementById('idFreetext'+sCurForm);
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			xmldoc = req.responseXML.documentElement;
			nodes = xmldoc.getElementsByTagName('Location');
			sLocationID.options[0] = new Option('- Select a destination -','-');
			for(var i = 0; i < nodes.length; i++) {
				if (nodes.length != 0) {
					var GroupName = nodes.item(i).attributes.getNamedItem("title").nodeValue
					if(PreGroupName!=GroupName){
						var RegionName = document.createElement('optgroup');
						RegionName.label = GroupName;
						if(GroupName!='zzz') {
							sLocationID.appendChild(RegionName);
						}else if(i>0) {
							RegionName.label = 'Others';
							sLocationID.appendChild(RegionName);
						}
					}
					var PreGroupName = GroupName
					sCode = nodes.item(i).attributes.getNamedItem("code").nodeValue;
					sName = nodes.item(i).childNodes.item(0).nodeValue;
					sLocationID.options[sLocationID.options.length] = new Option(sName, sCode);
					
				}
			}
			if(nodes.length==1) {
				sLocationID.options[1].selected = true;
				validateLocationForm();
			}else if(nodes.length<1){
				OpenSearch();
				alert('No destinations found.\n\nPlease refine your search.');
				locationGoBack(sCurForm);
				sFreetext.focus();sFreetext.select();
			}else{
				OpenSearch();
				switchLocationDivs('divLocation'+sCurForm);
				divLocationBorder.className='chooseDropDown';
				div_switch('divLocationPointer'+sCurForm, true, true);
				sLocationID.style.width = parseInt(GetElementWidth('idLocationto'+sCurForm)-6)+'px';
			}
				
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

function addToDuration(sform,svalue,stype) {
	if(stype=='freetext') {
		if(isValidField(svalue,1)==false){
			document.getElementById('duration'+sform).value='';
			document.getElementById('durationFree'+sform).value='';
			alert('You can only use numbers in this field')
		}else{
			document.getElementById('duration'+sform).value=svalue;
		}
	}else{
		if(svalue=='other') {
			document.getElementById('duration'+sform).value='';
			div_switch('searchReturnFree'+sform,true,true)
			div_switch('searchReturnSelect'+sform,false,true)
		}else{
			document.getElementById('duration'+sform).value=svalue;
			div_switch('searchReturnFree'+sform,false,true)
			div_switch('searchReturnSelect'+sform,true,true)
		}
	}
	addDurationBYO(sform);
}


function addDurationBYO(sform){
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
		oSelect = document.getElementById('startdate_d'+sform);
		iDay = oSelect.options[oSelect.selectedIndex].value;
		oSelect = document.getElementById('startdate_m'+sform);
		iMonth = oSelect.options[oSelect.selectedIndex].value;
		oSelect = document.getElementById('startdate_y'+sform);
		iYear = oSelect.options[oSelect.selectedIndex].value;
	
	cindate = new Date(iYear, iMonth - 1, iDay, 0, 0, 0);
	
	oSelect = document.getElementById('duration'+sform);

	
	iDuration = oSelect.value;
	if(iDuration == '') {
		iDuration = 7;
	}

//	if (oSelect.options[oSelect.selectedIndex].value == 'other')
//	{
//	alert('test');
//	}
//	else
//	{
//		iDuration = oSelect.options[oSelect.selectedIndex].value;
//	}

	// Amend the end date
	days = 1000 * 60 * 60 * 24 * iDuration;
	newdate = new Date(cindate.valueOf() + days);
	if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
		// Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
		// Work out time in milliseconds
		time = newdate.getHours() * 60 * 60 * 1000;
		time += newdate.getMinutes() * 60 * 1000;
		time += newdate.getSeconds() * 1000;
		newdate = new Date(newdate.getTime() + time);
	}
	
	if(newdate.getDate()+'' != "NaN") {
		sArrDate = newdate.getDate() + ' ' + months[newdate.getMonth()] + ' ' + newdate.getFullYear();
	 } else {
		 sArrDate = 'Please select a departure date.';
	 }
	
	//alert(sArrDate);
	document.getElementById("arrdate"+sform).innerHTML = '<b>' + sArrDate + '</b>'
}

function GetElementWidth(sObject) {
	var elem;
	if(typeof(sObject) == "object") {
		elem = sObject;
	} else {
		elem = document.getElementById(sObject);
	}
	return parseInt(elem.offsetWidth);
}


 -->