function setCity(countryEle)
{
	var countryID = countryEle.value;
	if (countryID != "")
	{
		if (document.getElementById("hotspotscity").hasChildNodes())
		{
			document.getElementById("hotspotscity").disabled = true;
			document.getElementById("hotspotscity").className = "inactive";
			
			while (document.getElementById("hotspotscity").hasChildNodes())
			{
				var children = document.getElementById("hotspotscity").childNodes;
				document.getElementById("hotspotscity").removeChild(children[0]);
			}
			var optionEle = document.createElement("option");
			optionEle.setAttribute("value", "");
			optionEle.innerHTML = "Loading...";
			document.getElementById("hotspotscity").appendChild(optionEle)
		}
		
		var xmlHttp;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					return false;
				}
			}
		}
		
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState == 4)
			{
				var cityList = eval(xmlHttp.responseText);
				for (var i = 0; i < cityList.length; i++)
				{
					if (cityList[i][0] != "")
					{
						var optionEle = document.createElement("option");
						optionEle.setAttribute("value", cityList[i][0]);
						optionEle.innerHTML = cityList[i][0] + " (" + cityList[i][1] + ")";
						
						document.getElementById("hotspotscity").appendChild(optionEle);
					}
					else
					{
						var optionEle = document.createElement("option");
						optionEle.setAttribute("value", "");
						optionEle.innerHTML = "-----";
						
						document.getElementById("hotspotscity").appendChild(optionEle);
					}
				}
				
				var children = document.getElementById("hotspotscity").childNodes;
				for (var i = 0; i < children.length; i++)
				{
					if ((children[i].tagName) && (children[i].tagName.toLowerCase() == "option"))
					{
						if (children[i].value == "")
						{
							children[i].innerHTML = "- Select city -";
							break;
						}
					}
				}
				
				document.getElementById("hotspotscity").disabled = false;
				document.getElementById("hotspotscity").className = "";
			}
		}
		xmlHttp.open("GET", "/mapping.tools.php?action=cities&top5=true&country=" + countryID + "&language=" + language, true);
		xmlHttp.send(null);
	}
	else
	{
		if (document.getElementById("hotspotscity").hasChildNodes())
		{
			while (document.getElementById("hotspotscity").hasChildNodes())
			{
				var children = document.getElementById("hotspotscity").childNodes;
				document.getElementById("hotspotscity").removeChild(children[0]);
			}
			var optionEle = document.createElement("option");
			optionEle.setAttribute("value", "");
			optionEle.innerHTML = "- select city -";
			document.getElementById("hotspotscity").appendChild(optionEle);
		}
		document.getElementById("hotspotscity").disabled = true;
		document.getElementById("hotspotscity").className = "inactive";
	}
}

function setLocationTypes()
{
	var countryID = document.getElementById("hotspotscountry").value;
	var cityName = document.getElementById("hotspotscity").value;
	
	//window.alert(cityName);
	
	//if (countryID != "")
	//{
		if (document.getElementById("hotspotslocationtype").hasChildNodes())
		{
			document.getElementById("hotspotslocationtype").disabled = true;
			document.getElementById("hotspotslocationtype").className = "inactive";
			
			while (document.getElementById("hotspotslocationtype").hasChildNodes())
			{
				var children = document.getElementById("hotspotslocationtype").childNodes;
				document.getElementById("hotspotslocationtype").removeChild(children[0]);
			}
			var optionEle = document.createElement("option");
			optionEle.setAttribute("value", "");
			optionEle.innerHTML = "Loading...";
			document.getElementById("hotspotslocationtype").appendChild(optionEle);
		}
		
		var xmlHttp;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					return false;
				}
			}
		}
		
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState == 4)
			{
				var locationtypeList = eval(xmlHttp.responseText);
				for (var i = 0; i < locationtypeList.length; i++)
				{
					var optionEle = document.createElement("option");
					optionEle.setAttribute("value", locationtypeList[i][1]);
					optionEle.innerHTML = locationtypeList[i][1] + " (" + locationtypeList[i][2] + " hotspots)";
					
					document.getElementById("hotspotslocationtype").appendChild(optionEle);
				}
				
				var children = document.getElementById("hotspotslocationtype").childNodes;
				for (var i = 0; i < children.length; i++)
				{
					if ((children[i].tagName) && (children[i].tagName.toLowerCase() == "option"))
					{
						if (children[i].value == "")
						{
							children[i].innerHTML = "All location types";
							break;
						}
					}
				}
				
				document.getElementById("hotspotslocationtype").disabled = false;
				document.getElementById("hotspotslocationtype").className = "";
			}
		}
		if (countryID == "")
		{
			xmlHttp.open("GET", "/mapping.tools.php?action=locationtypes" + "&language=" + language, true);
		}
		else if (cityName == "")
		{
			xmlHttp.open("GET", "/mapping.tools.php?action=locationtypes&country=" + countryID + "&language=" + language, true);
		}
		else
		{
			xmlHttp.open("GET", "/mapping.tools.php?action=locationtypes&country=" + countryID + "&city=" + cityName + "&language=" + language, true);
		}
		xmlHttp.send(null);
	/*}
	else
	{
		if (document.getElementById("hotspotslocationtype").hasChildNodes())
		{
			while (document.getElementById("hotspotslocationtype").hasChildNodes())
			{
				var children = document.getElementById("hotspotslocationtype").childNodes;
				document.getElementById("hotspotslocationtype").removeChild(children[0]);
			}
			var optionEle = document.createElement("option");
			optionEle.setAttribute("value", "");
			optionEle.innerHTML = "All location types";
			document.getElementById("hotspotslocationtype").appendChild(optionEle)
		}
		//document.getElementById("hotspotslocationtype").disabled = true;
		//document.getElementById("hotspotslocationtype").className = "inactive";
	}*/
}

function setActiveMapTab(tabEle)
{
	if (document.getElementById("maptabs").hasChildNodes())
	{
		for (var i = 0; i < document.getElementById("maptabs").childNodes.length; i++)
		{
			if (document.getElementById("maptabs").childNodes[i].className && (document.getElementById("maptabs").childNodes[i].className.indexOf("mapinfo") != -1))
			{
				document.getElementById("maptabs").childNodes[i].className = "mapinfo";
			}
		}
	}
	tabEle.parentNode.className = "mapinfo active";
	
	if (document.getElementById("map_" + tabEle.className))
	{
		document.getElementById("map_airports").style.display = "none";
		document.getElementById("map_hotels").style.display = "none";
		document.getElementById("map_chains").style.display = "none";
		
		document.getElementById("map_" + tabEle.className).style.display = "block";
	}
}

function checkHotspotSearchForm(theForm)
{
	if ((theForm.elements["country"].value == "") && (theForm.elements["location"].value == ""))
	{
		window.alert("Please select a country or a location type.");
		return false;
	}
	if ((theForm.elements["country"].value != "") && ((theForm.elements["city"].value == "") && (theForm.elements["location"].value == "")))
	{
		window.alert("Please select a city or a location type.");
		return false;
	}
	
	if (theForm.elements["address"].value == "address...")
	{
		theForm.elements["address"].value = "";
	}
	
	if (theForm.elements["postcode"].value == "post code...")
	{
		theForm.elements["postcode"].value = "";
	}
	
	return true;
}

var loadedChains = false;

function loadChains(containerDiv)
{
	if (loadedChains == false)
	{
		if (document.getElementById(containerDiv))
		{
			if (document.getElementById(containerDiv).getElementsByTagName("a"))
			{
				var relevantEles = document.getElementById(containerDiv).getElementsByTagName("a");
				for (var i = 0; i < relevantEles.length; i++)
				{
					var currentChainTitle = relevantEles[i].getAttribute("title");
					var currentChainName = currentChainTitle.substr(0, currentChainTitle.indexOf("-") - 1).toLowerCase();
					currentChainName = currentChainName.replace(/ /gi, "_");
					currentChainName = currentChainName.replace(/&/gi, "-and-");
					
					var imgEle = document.createElement("img");
					imgEle.setAttribute("src", "/images/logo.chain." + currentChainName + ".gif");
					imgEle.setAttribute("alt", currentChainName);
					relevantEles[i].innerHTML = "";
					relevantEles[i].appendChild(imgEle);
				}
			}
		}
		loadedChains = true;
	}
}