function QQ_changeByAirportGroup(formname, airportGroupId, airportId) {
	
	// redirect to uk quickquote when applicable
	if (airportGroupId == -1) {
		window.location = '';	
		return;
	};
		
	
	//var airportSelectList = eval('document.forms.' + formname + '.airportid');	
	var resortSelectList = eval('document.forms.' + formname + '.resortid');
	var ss = false;
	for(var del in airportSelectList.options) {
		airportSelectList.length = 1;
	};
	for(var del in resortSelectList.options) {
		resortSelectList.length = 1;
	};	
	if (airportGroupId != '') {
		var l; var f;
		for (var i in arrAirports) {
			if(arrAirports[i][1] == airportGroupId) {
				l = airportSelectList.length;
				if ( arrAirports[i][0] == airportId ) {
					var ss = l;
				}
				newElem = new Option(arrAirports[i][2], arrAirports[i][0], false, false);
				airportSelectList.options[l] = newElem;
				f = true;
			};
		};
	};
	resortSelectList.disabled = true;
	if (f) {
		if (ss) {
			airportSelectList.options[ss].selected = true;
		}
		airportSelectList.disabled = false;
	} else {
		airportSelectList.disabled = true;
	}
}

function QQ_changeByAirport(formname, airportId, resortId) {
	//var airportSelectList = eval('document.forms.' + formname + '.airportid');
	var resortSelectList = eval('document.forms.' + formname + '.resortid');
	//var airportGroupId = eval('document.forms.' + formname + '.airportgroupid.value');
	var ss = false;

	// redirect to uk quickquote when applicable
	if (airportId == -1) {
		window.location = '';	
		return;
	};
	
	for(var del in resortSelectList.options) {
		resortSelectList.length = 1;
	};
	if (airportId != '') {
		var l; var f;
		for (var i in arrResorts) {			
			if(arrResorts[i][1] == airportId && arrResorts[i][2] == airportGroupId) {
				l = resortSelectList.length;
				if ( arrResorts[i][0] == resortId ) {
					ss = l;
				}
				newElem = new Option(arrResorts[i][3], arrResorts[i][0], false, false);
				resortSelectList.options[l] = newElem;
				f = true;
			};
		};
	};
	
	if (f) {
		if (ss) {
			resortSelectList.options[ss].selected = true;
		}
		resortSelectList.disabled = false;
	} else {
		resortSelectList.disabled = true;
	}
}

function QQ_populateLists()
{
	var objAirportGroups 	= document.forms.quickquoteform.airportgroupid;
	var objAirports		= document.forms.quickquoteform.airportid;
	var objResorts		= document.forms.quickquoteform.resortid;
	var objForm		= document.forms.quickquoteform;
	
	for (var i = 1; i < arrAirportGroups.length; i++)
	{
		objAirportGroups.options[i] = new Option(arrAirportGroups[i][1], arrAirportGroups[i][0]);
	}
	
	for (var i = 1; i < arrAirports.length; i++)
	{
		objAirports.options[i] = new Option(arrAirports[i][2], arrAirports[i][0]);
	}
	
	for (var i = 1; i < arrResorts.length; i++)
	{
		objResorts.options[i] = new Option(arrResorts[i][3], arrResorts[i][0]);
	}
	//2 days ahead
	objForm.today.options[new Date().getDate()+1].selected = true;
	//set to current month
	objForm.tomonth.options[new Date().getUTCMonth()].selected = true;
}


function getBookingType() {
	
	// Determine type of control used to select booking type (select or option)
	var selectBookingType = true;
	
	if (document.getElementById("bookingtypeid1")) {
		selectBookingType = false;
	}
	
	if (selectBookingType)	// Get bookingtypeid from select
	{
		if (document.getElementById("bookingtypeid")) {
			bookingTypeId = document.getElementById('bookingtypeid').value;
		}
		else
		{
			return false;
		}
	}
	else			// Get bookingtypeid from option
	{
		for (i=0;i<document.quickquoteform.bookingtypeid.length;i++) {
			if (document.quickquoteform.bookingtypeid[i].checked) {
				bookingTypeId = document.quickquoteform.bookingtypeid[i].value;
			}
		}
	}
	
	return bookingTypeId;
}
		
		
function QQ_validateQuicksearchForm(objForm) {
	
	var errMsg = quickQuoteErrorMessages['ERROR_MESSAGE'] + "\n\n";
	var isErr = false;
	
	// Default style has 2 date fields now - arrival and departure
	var defaultStyle = false;
	if (document.getElementsByName("today").length == 0) {	
		defaultStyle = true;
	}

	// Set available date to one day in the future
	var availableDate = new Date();
	availableDate.setDate(availableDate.getDate() + 1);
		
	var airportgroupid = objForm.airportgroupid.value;
	var airportid = objForm.airportid.value;
	var resortid = objForm.resortid.value;

	if ( airportgroupid == "" || airportid == "" || resortid == "" ) {
		errMsg += quickQuoteErrorMessages['DEST_ERROR'] + "\n";
		isErr = true;
	};
	
	if (defaultStyle)
	{
		var bookingTypeId = getBookingType();
		
		if ( (bookingTypeId == '1') || (bookingTypeId == '2') ) {
			
			var arrivalmonthyear = objForm.arrivalmonthyear.value;
			var arrivalday = objForm.arrivalday.value;
			var arrivalmonth = arrivalmonthyear.substring(0,2);
			var arrivalyear = arrivalmonthyear.substring(2,6);
			var arrivalhours = objForm.arrivalhours.value;
			var arrivalminutes = objForm.arrivalminutes.value;
			var arrivalDateTime = new Date(arrivalyear, arrivalmonth-1, arrivalday, arrivalhours, arrivalminutes);
		
			if ( arrivalDateTime < availableDate ) {
				isErr = true;
				errMsg += quickQuoteErrorMessages['ARR_DATE_ERROR'] + "\n";
			};
		
			if (! isValidDate(arrivalday, arrivalmonth, arrivalyear) ) {
				errMsg += quickQuoteErrorMessages['VALID_DATE_ERROR'] + "\n";
				isErr = true;
			};
		};

		if ( (bookingTypeId == '1') || (bookingTypeId == '3') ) {
					
			var departuremonthyear = objForm.departuremonthyear.value;
			var departureday = objForm.departureday.value;
			var departuremonth = departuremonthyear.substring(0,2);
			var departureyear = departuremonthyear.substring(2,6);
			var departurehours = objForm.departurehours.value;
			var departureminutes = objForm.departureminutes.value;
			var departureDateTime = new Date(departureyear, departuremonth-1, departureday, departurehours, departureminutes);
	
			if ( departureDateTime < availableDate ) {
				isErr = true;
				errMsg += quickQuoteErrorMessages['DEP_DATE_ERROR'] + "\n";
			};
		
			if (! isValidDate(departureday, departuremonth, departureyear) ) {
				errMsg += quickQuoteErrorMessages['VALID_DATE_ERROR'] + "\n";
				isErr = true;
			};
		};
		
		if (bookingTypeId == '1') {
			
			// Check departure date after arrival date
			if (arrivalDateTime >= departureDateTime)
			{
				errMsg += quickQuoteErrorMessages['DEP_DATE_FIRST_ERROR'] + "\n";
			};
		};
				
	} else {
		
		var today = objForm.today.value;
		var tomonthyear = objForm.tomonthyear.value;
		var tomonth = tomonthyear.substring(0,2);
		var toyear = tomonthyear.substring(2,6);
		var toDateTime = new Date(toyear, tomonth-1, today, 23, 59);
	
		if ( toDateTime < availableDate ) {
			isErr = true;
			errMsg += quickQuoteErrorMessages['ARR_DATE_ERROR'] + "\n";
		};
	
		if (! isValidDate(today, tomonth, toyear) ) {
			errMsg += quickQuoteErrorMessages['VALID_DATE_ERROR'] + "\n";
			isErr = true;
		};
	};
	
	if (isErr) {
		alert(errMsg); 
		return false;
	};

	return true;
	
}

function QQ_changeBookingType() {

	var bookingTypeId = getBookingType();
	
	// Enable/disable dates based on booking type
	switch (bookingTypeId)
	{
		case '1':
			document.getElementById('arrivalminutes').disabled = '';
			document.getElementById('arrivalhours').disabled = '';
			document.getElementById('arrivalday').disabled = '';
			document.getElementById('arrivalmonthyear').disabled = '';
			document.getElementById('frm_arrival_trigger').style.display = '';
			
			document.getElementById('departureminutes').disabled = '';
			document.getElementById('departurehours').disabled = '';
			document.getElementById('departureday').disabled = '';
			document.getElementById('departuremonthyear').disabled = '';
			document.getElementById('frm_departure_trigger').style.display = '';	
			break;
			
		case '2':
			document.getElementById('arrivalminutes').disabled = '';
			document.getElementById('arrivalhours').disabled = '';
			document.getElementById('arrivalday').disabled = '';
			document.getElementById('arrivalmonthyear').disabled = '';
			document.getElementById('frm_arrival_trigger').style.display = '';
			
			document.getElementById('departureminutes').disabled = 'disabled';
			document.getElementById('departurehours').disabled = 'disabled';
			document.getElementById('departureday').disabled = 'disabled';
			document.getElementById('departuremonthyear').disabled = 'disabled';
			document.getElementById('frm_departure_trigger').style.display = 'none';
			break;
			
		case '3':
			document.getElementById('arrivalminutes').disabled = 'disabled';
			document.getElementById('arrivalhours').disabled = 'disabled';
			document.getElementById('arrivalday').disabled = 'disabled';
			document.getElementById('arrivalmonthyear').disabled = 'disabled';
			document.getElementById('frm_arrival_trigger').style.display = 'none';
			
			document.getElementById('departureminutes').disabled = '';
			document.getElementById('departurehours').disabled = '';
			document.getElementById('departureday').disabled = '';
			document.getElementById('departuremonthyear').disabled = '';
			document.getElementById('frm_departure_trigger').style.display = '';			
			break;
	}
	
}

function QQ_populateContent(elementName, selectedValue, highlight, anchorhighlight) {

	var htmlStr = '';
	
	if (! highlight ) var highlight = "#ffc000";
	if (! anchorhighlight ) var anchorhighlight = "#000";
	
	switch ( elementName ) {
		case "airportgroups":
			htmlStr += '<table style="width: 100%" cellspacing="0" cellpadding="0">';
			var count = 0;
			for (var i in arrAirportGroups) {
				htmlStr += '<tr onmouseover="this.style.backgroundColor = \'' + highlight + '\'; document.getElementById(\'airportgroupanchor' + count + '\').style.color = \'' + anchorhighlight + '\';"';
				htmlStr += ' onmouseout="this.style.backgroundColor = \'\'; document.getElementById(\'airportgroupanchor' + count + '\').style.color = \'\';"';
				if (arrAirportGroups[i][0] == -1) {
					htmlStr += '>';
					htmlStr += '<td><a id="airportgroupanchor' + count + '" href="/uk-quickquote.php">' + arrAirportGroups[i][1] + '</a></td>';					
				} else {
					htmlStr += ' onclick="QQ_populateContent(\'airports\',' + arrAirportGroups[i][0] + ', \'' + highlight + '\', \'' + anchorhighlight + '\');">';
					htmlStr += '<td><a id="airportgroupanchor' + count + '" href="/resorts.php" onclick="return false;">' + arrAirportGroups[i][1] + '</a></td>';	
				};
				htmlStr += '</tr>';
				count++;
			};
			htmlStr += '</table>';
			document.getElementById(elementName).innerHTML = htmlStr;
			break;
		case "airports":
			document.getElementById('resorts').innerHTML = '';
			if (selectedValue != '') {
				htmlStr += '<table style="width: 100%" cellspacing="0" cellpadding="0">';
				var count = 0;
				for (var i in arrAirports) {
					if(selectedValue == 9 && arrAirports[i][1] == selectedValue) {
						htmlStr += '<tr onmouseover="this.style.backgroundColor = \'' + highlight + '\'; document.getElementById(\'airportanchor' + count + '\').style.color = \'' + anchorhighlight + '\';"';
						htmlStr += ' onmouseout="this.style.backgroundColor = \'\'; document.getElementById(\'airportanchor' + count + '\').style.color = \'\';"';
						htmlStr += ' onclick="displaySkiResortMap('+ arrAirports[i][0] +', \'' + highlight + '\', \'' + anchorhighlight + '\');">';
						htmlStr += '<td><a id="airportanchor' + count + '" href="/resorts.php" onclick="return false;">' + arrAirports[i][2] + '</a></td>';
						htmlStr += '</tr>';
					} else if(arrAirports[i][1] == selectedValue) {
						htmlStr += '<tr onmouseover="this.style.backgroundColor = \'' + highlight + '\'; document.getElementById(\'airportanchor' + count + '\').style.color = \'' + anchorhighlight + '\';"';
						htmlStr += ' onmouseout="this.style.backgroundColor = \'\'; document.getElementById(\'airportanchor' + count + '\').style.color = \'\';"';
						htmlStr += ' onclick="QQ_populateContent(\'resorts\',' + arrAirports[i][0] + ', \'' + highlight + '\', \'' + anchorhighlight + '\');">';
						htmlStr += '<td><a id="airportanchor' + count + '" href="/resorts.php" onclick="return false;">' + arrAirports[i][2] + '</a></td>';
						htmlStr += '</tr>';
					};
					count++;
				};
				htmlStr += '</table>';
				document.getElementById(elementName).innerHTML = htmlStr;
				window.scrollTo(0,0);
			} else {
				document.getElementById(elementName).innerHTML = '';
			}
			document.retainvalues.airportgroupid.value = selectedValue;
			break;
		case "resorts":
			if (selectedValue != '') {
				var airportGroupId = document.retainvalues.airportgroupid.value;
				htmlStr += '<table style="width: 100%" cellspacing="0" cellpadding="0">';
				var count = 0;
				for (var i in arrResorts) {
					if(arrResorts[i][1] == selectedValue && arrResorts[i][2] == airportGroupId) {
						htmlStr += '<tr onmouseover="this.style.backgroundColor = \'' + highlight + '\'; document.getElementById(\'resortanchor' + count + '\').style.color = \'' + anchorhighlight + '\';"';
						htmlStr += ' onmouseout="this.style.backgroundColor = \'\'; document.getElementById(\'resortanchor' + count + '\').style.color = \'\';"';
						htmlStr += ' onclick="window.location=\'/products.php?airportgroupid=' + airportGroupId + '&airportid=' + selectedValue + '&resortid=' + arrResorts[i][0] + '\';">';
						htmlStr += '<td><a id="resortanchor' + count + '" href="/resorts.php" onclick="return false;">' + arrResorts[i][3] + '</a></td>';
						htmlStr += '</tr>';
						count++;
					};
				};
				htmlStr += '</table>';
				document.getElementById(elementName).innerHTML = htmlStr;
				window.scrollTo(0,0);
			} else {
				document.getElementById(elementName).innerHTML = '';
			}
			break;
		default:
			break;
	};
}

function QQ_mouseoverAirportMap(default_map, airport)
{
	document.getElementById(default_map).style.display = 'none'; 
	document.getElementById(airport).style.position = 'relative'; 
	document.getElementById(airport).style.left = '0';
}

function QQ_mouseoutAirportMap(default_map, airport)
{
	document.getElementById(default_map).style.display = '';
	document.getElementById(airport).style.position = 'absolute';
	document.getElementById(airport).style.left = '-1000px';
}

/*
function QQ_changeResortMap(airportId, airportCode, originUrl, lang) {
	//originText = (originText != undefined) ? originText : "All Airports";
	originText = "All Airports";
	//resortMapName = airportCode.toLowerCase()+"_resorts_bg.png";
	originUrl = (originUrl != "undefined" && originUrl != undefined) ? originUrl : window.location.pathname;
	
	if(hideElements) {
		for (var key in hideElements) {
			var e = document.getElementById(hideElements[key]);
			if(e) {
				e.style.display = "none";
			}
		}
	}

	var element = document.getElementById('map');
	element.style.width = "714px";
	
	var airport;
	for(var i = 0; i < arrAirports.length; i++) {
		if(arrAirports[i][0] == airportId) {
			airport = arrAirports[i];
			break;
		}
	}
	if(airport == undefined) {
		return;
	}
	
	var airportGroupId = document.retainvalues.airportgroupid.value ? document.retainvalues.airportgroupid.value : airport[1];
	QQ_changeByAirportGroup('quickquoteform', airportGroupId, airport[0]);
	QQ_changeByAirport('quickquoteform', airport[0]);
	
	//element.style.backgroundImage = "url('/images/resorts/"+resortMapName +"')";
	element.className = airportCode.toLowerCase() + "_map" + ((lang != undefined) ? ("_" + lang) :  "");
	var crumbLink = '<div class="resortmap_crumblink"><a href="'+originUrl+'">' + originText + '</a>' + ' &gt; ' + airport[2] + '</div>';
	
	var resorts = [];
	var numResorts = 0;
	
	var htmlStr = '<ol id="resort_link_list">';
	for(var i = 0; i < arrResorts.length; i++) {
		if(arrResorts[i][1] == airport[0] && arrResorts[i][2] == airport[1]) {
			var resortName = (arrResorts[i][3].toLowerCase()).replace(/[\.]?\s/g, '_');
			resortName = resortName.replace(/\'/g, '');
			htmlStr += '<li>';
			htmlStr += '<a href="/products.php?airportgroupid='+arrResorts[i][2]+'&airportid='+arrResorts[i][1]+'&resortid='+arrResorts[i][0]+'" id="'+airportCode.toLowerCase()+'_'+resortName+'" class="map_link">'+resortName+'</a>';
			//htmlStr += '<a href="#" id="'+resortName+'" class="map_link">'+resortName+'</a>';
			htmlStr += '</li>';
			
			resorts[arrResorts[i][0]] = {airportGroupId: arrResorts[i][2], airportId: arrResorts[i][1], linkId: (airportCode.toLowerCase()+'_'+resortName)};
			numResorts++;
		}
	}
	htmlStr += '</ol>';
	element.innerHTML = htmlStr;
	element.parentNode.innerHTML = crumbLink + element.parentNode.innerHTML;
	
	if(i > 0) {
		var htu1 = document.getElementById('mainmap_howtouse');
		var htu2 = document.getElementById('resortmap_howtouse');
		if(htu1 && htu2) {
			htu1.style.display = 'none';
			htu2.style.display = 'block';
		}
		//addFlashBoxListener(resorts);
	}
	xajax_getCheapestOptions(airportGroupId, airportId, resorts, airportCode.toLowerCase());
	
	if(displayResorts[airportCode.toLowerCase()]) {
		var otherHtmlStr = "";
		var displayResort = displayResorts[airportCode.toLowerCase()];
		for (var r in displayResort) {
			if(!document.getElementById(airportCode.toLowerCase()+'_'+displayResort[r])) {
				var resortStr = displayResort[r].toString();
				resortStr = resortStr.replace(/_/g, ' ');
				resortStr = resortStr.replace(/^\w/, resortStr.charAt(0).toUpperCase()); //Make sentense case
				otherHtmlStr += "<li><a onmouseover='displayTip(this);' href='javascript:' id='"+airportCode.toLowerCase()+"_"+displayResort[r]+"' class='map_link'>"+resortStr+"</a></li>";
			}
		}
		document.getElementById('resort_link_list').innerHTML = document.getElementById('resort_link_list').innerHTML + otherHtmlStr; 
	}
	
}


function QQ_changeResortList(selectedValue, originUrl) {
	//originText = (originText != undefined) ? originText : "Back";
	originText = "Back";
	originUrl = (originUrl != "undefined" && originUrl != undefined) ? originUrl : window.location.pathname;
	var element = document.getElementById('map');
	var airport;
	
	for(var i = 0; i < arrAirports.length; i++) {
		if(arrAirports[i][0] == selectedValue) {
			airport = arrAirports[i];
			break;
		}
	}
	if(airport != undefined) {
		var resort_element = '<table id="resort_container" cellspacing="0" cellpadding="0" class="destinations">';
		resort_element += '<tr><td style="width: 2%;">&nbsp;</td><td class="headingleft">Resorts served by ' + (airport ? airport[2] : '')+ '</td><td class="headingright" style="text-align: right;"><a href="'+originUrl+'" style="color: #FFF;">&laquo;'+ originText +'</a></td></tr>';
		resort_element += '<tr><td style="width: 2%;">&nbsp;</td><td class="inner" colspan="2"><div id="resorts" name="resorts">';
		//element.style.padding = "0px 0px 0px 20px";
	
		//document.retainvalues.airportgroupid.value = airport[1];
		var selectedValue = airport[0];
		var airportGroupId = document.retainvalues.airportgroupid.value ? document.retainvalues.airportgroupid.value : airport[1];
		
		QQ_changeByAirportGroup('quickquoteform', airportGroupId, airport[0]);
		QQ_changeByAirport('quickquoteform', airport[0]);
		
		var highlight = "#ffc000";
		var anchorhighlight = "#000";
		
		var htmlStr = '<table style="width: 100%" cellspacing="0" cellpadding="0" valign="top">';
		htmlStr += '<tr><td><ul class="resort_list">';
		var count = 0;
		for (var i in arrResorts) {
			if(arrResorts[i][1] == selectedValue && arrResorts[i][2] == airportGroupId) {
				htmlStr += '<li onmouseover="this.style.backgroundColor = \'' + highlight + '\'; document.getElementById(\'resortanchor' + count + '\').style.color = \'' + anchorhighlight + '\';"';
				htmlStr += ' onmouseout="this.style.backgroundColor = \'\'; document.getElementById(\'resortanchor' + count + '\').style.color = \'\';"';
				htmlStr += ' onclick="window.location=\'/products.php?airportgroupid=' + airportGroupId + '&airportid=' + selectedValue + '&resortid=' + arrResorts[i][0] + '\';">';
				htmlStr += '<a id="resortanchor' + count + '" href="/resorts.php" onclick="return false;">' + arrResorts[i][3] + '</a></li>';
				count++;
				if(count > 21) {
					htmlStr += '</ul></td><td valign="top"><ul class="resort_list">';
					count = 0;
				}
			};
		};
		htmlStr += '</ul></td></tr>';
		htmlStr += '</table>';
		resort_element += htmlStr;
		window.scrollTo(0,0);
		
		resort_element += '</div></tr><td></table>';
		element.innerHTML = resort_element;
		
		var htu1 = document.getElementById('mainmap_howtouse');
		var htu2 = document.getElementById('resortlist_howtouse');
		if(htu1 && htu2) {
			htu1.style.display = 'none';
			htu2.style.display = 'block';
		}
	}
}*/

function displaySkiResortMap(airportId, highlight, anchorhighlight) {
	if((typeof skiLanguageCode == "string") && skiLanguageCode == 'en') {
		window.location = '/ski/?airportid='+airportId+'&redirect=\/\?airportgroupid\=9';
	} else {
		QQ_populateContent('resorts', airportId, highlight, anchorhighlight);
	}
};

function redirectTransferType() {

	len = document.quickquoteform.transfertype.length;
	
	for (i = 0; i <len; i++) 
	{
		if (document.quickquoteform.transfertype[i].checked) {
			chosen = document.quickquoteform.transfertype[i].value
		}
	}
	
	url = '';
	switch ( chosen ) {
		case "HOL":
			url = 'http://www.solartours.net';
			break;
		case "SKI":
			url = 'http://www.solartours.net';
			break;
		case "BSI":
			url = 'http://www.solartours.net';
			break;			
		default:
			break;
	};
	
	if (url != '')
	{
		newWindow = window.open(url, '_blank');
		newWindow.focus();
	}
}

