//Global Variables
var mapCenter;
var map;
var mapEle;
var minZoom;
var container;
var opacity;
var horizontal;
var vertical;
var rightSide;
var leftSide;
var mgr;
var locationsArray = new Array(86);

function initMap() {
	if (GBrowserIsCompatible()) {
		minZoom = 1;
		mapEle = document.getElementById("map");
		map = new GMap2(document.getElementById("map"), {draggableCursor:"crosshair"});
		map.addControl(new GLargeMapControl());
		
		LoadMapCenter();
		mgr = new MarkerManager(map);

		//map.enableContinuousZoom();
		//map.enableScrollWheelZoom();
		GEvent.addListener(map, "click", MapClick);	
		GEvent.addListener(map, "moveend", MapMoveEnd);
		GEvent.addListener(map, "zoomend", MapZoomEnd);

		//window.setTimeout(AddContinentOverlays, 0);
		window.setTimeout(AddDestinationMarkers, 0);
	} 
}

//NMG: this doesn't seem to work reliably
//function AddContinentOverlays() {
//    GDownloadUrl("continents.xml", function (data, responseCode) {
//        if (responseCode = 200) {
//            var xml = GXml.parse(data);
//            var continents = xml.documentElement.getElementsByTagName("continent");
//            for (var a = 0; a < continents.length; a++) {
//                var name = continents[a].getAttribute("name");
//                var points = continents[a].getElementsByTagName("point");
//                var pts = [];
//                for (var i = 0; i < points.length; i++) {
//                    pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")), parseFloat(points[i].getAttribute("lng")));
//                }
//                var continent = new GPolygon(pts, '#FF0000', 1, 0, '#0000FF', 0.8); 
//                continent.center = new GLatLng(parseFloat(continents[a].getAttribute("lat")), parseFloat(continents[a].getAttribute("lng")));
//                continent.zoom = parseFloat(continents[a].getAttribute("zoom"));
//                map.addOverlay(continent);
//                GEvent.addListener(continent, "click", function (point) {
//                    alert("continent click");
//                    if (map.getZoom() == 1) {
//                        map.setCenter(this.center, this.zoom);
//                    } else {
//                        map.setCenter(point, map.getZoom() + 1);
//                    }
//                });
//                
//            }
//        }
//    });
//}

function resetZoom(){
	mapCenter = new GLatLng(27.0, -2.4);
	// NMG: Only pan if zoom level isn't changing as otherwise it looks odd.
	if (map.getZoom() == minZoom) {
		map.panTo(mapCenter);
	} else {
		map.setZoom(minZoom);
		map.setCenter(mapCenter);
	}
	SaveMapCenter();
}

function resetMap(){
	resetZoom();
	alert("resetMap() is used");
}

function SaveMapCenter() {
	mapCenter = map.getCenter();
	var latlng = mapCenter.lat() + "," + mapCenter.lng();
	setCookie("IC_mapCenter",latlng, null);
	setCookie("IC_mapZoom", map.getZoom(), null);
}

function SaveMapCenterLatLng(lat, lng) {
	setCookie("IC_mapCenter",lat + "," + lng, null);
	setCookie("IC_mapZoom", map.getZoom(), null);
}

function LoadMapCenter() {
	var mc = "27.0, -2.4";
	var zoom = minZoom;
	try {
		var cookieMC;
		var cookieZoom;
		cookieMC = getCookie("IC_mapCenter");
		cookieZoom = getCookie("IC_mapZoom");
		if (cookieMC.length > 0) mc = cookieMC;
		if (cookieZoom.length > 0) zoom = parseInt(cookieZoom,10);
	} catch(err) {}
	var t = mc.split(',');
	mapCenter = new GLatLng(t[0],t[1]);
	map.setCenter(mapCenter, zoom);
}

function getCookie(c_name)	{
	if (document.cookie.length > 0)  {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// Event Handlers
function MapMoveEnd(){
}

function MapZoomEnd(oldLevel,  newLevel){
	if (newLevel < minZoom)	map.setZoom(minZoom);
	UpdateMapTip();
}

function MapClick(overlay, point) {
    if (overlay == null) { // stops zoom if you click on a destination marker
        map.setCenter(point, map.getZoom() + 1);
    }
}

function AddDestinationMarkers() {
	// mgr is the marker manager
	mgr.addMarkers(GetDestinationMarkers(), 3);
	mgr.refresh();
}

function UpdateMapTip(text) {
	var mapTips = document.getElementById("mapTips");
	if (text) {
		mapTips.innerHTML = text;
	} else {
		var zoomLevel = map.getZoom();
		if (zoomLevel <=2) {
			mapTips.innerHTML = "To use this map, first select a continent on the map above";
		} else if (zoomLevel >=3) {
			mapTips.innerHTML = "Now select a destination by clicking a red marker";
		} else {
			mapTips.innerHTML ="";
		}
	}
}

function CreateDestinationMarker(point, markerOptions, countryID, countryName, destinationID, destinationName) {
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, "click", function () {
	    //alert("destinationmarkerclick");
	    var url = "<b>" + destinationName + "</b><br><br>";
	    url += '<table><tr><td>';
	    url += '<img align=right src="thumbnail.ashx?ivID=' + destinationID + '&w=70&h=70" width=70 height=70 border="0" vspace=0 style="border: 1px black solid; margin-left:6px; margin-bottom:2px;" />';
	    url += '</td><td>';
	    url += "<a href=\"javascript:GetAllVenuesByDestination(" + destinationID + ",'" + destinationName + "', " + point.lat() + "," + point.lng() + ");\">Show me all venues in " + destinationName + "</a> or<br>";
	    url += "<a href=\"javascript:void(0)\" onclick=\"DestinationSearchClick(" + destinationID + ",'" + destinationName + "', " + point.lat() + "," + point.lng() + ");SetCityTip(" + countryID + ",'" + destinationName + "');\">Refine search using form below</a><br><br>";
	    url += "<a href=\"country-info.aspx?id=" + countryID + "\">Show me information on " + countryName + "</a><br>";
	    url += "<a href=\"country-info.aspx?id=" + countryID + "#" + destinationName + "\">Show me information on " + destinationName + "</a>";
	    url += '</td></tr></table>';
	    marker.openInfoWindowHtml(url);
	});
	return marker;
}

function GetAllVenuesByDestination(destinationID, destinationName, lat, lng) {
	var ddl = document.getElementById("TownCityDropDownList");
	for (i=0; i<ddl.options.length; i++) {
        if (ddl.options[i].value == destinationName) {
            ddl.selectedIndex = i;
            break;
        }
    }
	SaveMapCenterLatLng(lat, lng);
	__doPostBack('GetAllVenuesByDestinationButton', destinationName);
}

function DestinationSearchClick(destinationID, destinationName, lat, lng) {
	// TODO: clear country selection
	var ddl = document.getElementById("TownCityDropDownList");
	for (i=0; i<ddl.options.length; i++) {
        if (ddl.options[i].value == destinationName) {
            ddl.selectedIndex = i;
            break;
        }
    }
	UpdateMapTip("You have selected <b>" + destinationName + "</b>.  Now click 'view results'.");
	map.closeInfoWindow();
	SaveMapCenterLatLng(lat, lng);
	window.scrollBy(0,200);
	ddl.style.backgroundColor= "yellow";
	setTimeout('ResetBGColor()',2000);
}

function ResetBGColor() {
	var ddl = document.getElementById("TownCityDropDownList");
	ddl.style.backgroundColor = "white";
}

function GetDestinationMarkers() {
	var markers = [];
	SetlocationArray();
	var destinationIcon = new GIcon();
	destinationIcon.image  = "http://www.venuefinder.com/images/mm_20_red.png";
	destinationIcon.shadow = "http://www.venuefinder.com/images/mm_20_shadow.png";
	destinationIcon.iconSize = new GSize(12, 20);
	destinationIcon.shadowSize = new GSize(22, 20);
	destinationIcon.iconAnchor = new GPoint(6, 20);
	destinationIcon.infoWindowAnchor = new GPoint(5, 1);
	markerOptions = { icon:destinationIcon };
	// TODO: Should be dynamic. Perhaps consider using JSON or AJAX etc?
markers.push(CreateDestinationMarker(new GLatLng(48.2167,16.3667), markerOptions ,1,"Austria",1,"Vienna"));
markers.push(CreateDestinationMarker(new GLatLng(47.8,13.0333), markerOptions ,1,"Austria",2,"Salzburg"));
markers.push(CreateDestinationMarker(new GLatLng(47.2667,11.3833), markerOptions ,1,"Austria",3,"Innsbruck"));
markers.push(CreateDestinationMarker(new GLatLng(50.8467,4.35248), markerOptions ,2,"Belgium",4,"Brussels"));
markers.push(CreateDestinationMarker(new GLatLng(51.2167,4.4), markerOptions ,2,"Belgium",5,"Antwerp"));
markers.push(CreateDestinationMarker(new GLatLng(51.2167,3.23333), markerOptions ,2,"Belgium",6,"Bruges"));
markers.push(CreateDestinationMarker(new GLatLng(-22.9083,-43.2436), markerOptions ,3,"Brazil",7,"Rio de Janeiro"));
markers.push(CreateDestinationMarker(new GLatLng(-23.5433,-46.633), markerOptions ,3,"Brazil",8,"Sao Paulo"));
markers.push(CreateDestinationMarker(new GLatLng(42.7004,23.3337), markerOptions ,4,"Bulgaria",9,"Sofia"));
markers.push(CreateDestinationMarker(new GLatLng(43.2167,27.9167), markerOptions ,4,"Bulgaria",10,"Varna"));
markers.push(CreateDestinationMarker(new GLatLng(22.1833,114.133), markerOptions ,5,"China",11,"Hong Kong"));
markers.push(CreateDestinationMarker(new GLatLng(31.1667,121.467), markerOptions ,5,"China",12,"Shanghai"));
markers.push(CreateDestinationMarker(new GLatLng(45.8167,15.9833), markerOptions ,6,"Croatia",13,"Zagreb"));
markers.push(CreateDestinationMarker(new GLatLng(35.1667,33.35), markerOptions ,7,"Cyprus",14,"Nicosia"));
markers.push(CreateDestinationMarker(new GLatLng(34.6667,33.0333), markerOptions ,7,"Cyprus",15,"Limassol"));
markers.push(CreateDestinationMarker(new GLatLng(34.7667,32.4167), markerOptions ,7,"Cyprus",16,"Paphos"));
markers.push(CreateDestinationMarker(new GLatLng(50.0833,14.4167), markerOptions ,8,"Czech Republic",17,"Prague"));
markers.push(CreateDestinationMarker(new GLatLng(55.675,12.5687), markerOptions ,9,"Denmark",18,"Copenhagen"));
markers.push(CreateDestinationMarker(new GLatLng(25.2697,55.3095), markerOptions ,10,"United Arab Emirates",19,"Dubai"));
markers.push(CreateDestinationMarker(new GLatLng(60.1708,24.9375), markerOptions ,11,"Finland",20,"Helsinki"));
markers.push(CreateDestinationMarker(new GLatLng(48.8667,2.33306), markerOptions ,12,"France",21,"Paris"));
markers.push(CreateDestinationMarker(new GLatLng(45.7669,4.83417), markerOptions ,12,"France",22,"Lyon"));
markers.push(CreateDestinationMarker(new GLatLng(43.7398,7.4272), markerOptions ,39,"Monaco",23,"Monte Carlo"));
markers.push(CreateDestinationMarker(new GLatLng(43.7028,7.26917), markerOptions ,12,"France",24,"Nice"));
markers.push(CreateDestinationMarker(new GLatLng(43.5533,7.02222), markerOptions ,12,"France",25,"Cannes"));
markers.push(CreateDestinationMarker(new GLatLng(43.2972,5.381), markerOptions ,12,"France",26,"Marseille"));
markers.push(CreateDestinationMarker(new GLatLng(53.55,9.98333), markerOptions ,13,"Germany",27,"Hamburg"));
markers.push(CreateDestinationMarker(new GLatLng(52.5167,13.4167), markerOptions ,13,"Germany",28,"Berlin"));
markers.push(CreateDestinationMarker(new GLatLng(50.734,7.09981), markerOptions ,13,"Germany",29,"Bonn"));
markers.push(CreateDestinationMarker(new GLatLng(48.1333,11.5667), markerOptions ,13,"Germany",30,"Munich"));
markers.push(CreateDestinationMarker(new GLatLng(48.7786,9.17944), markerOptions ,13,"Germany",31,"Stuttgart"));
markers.push(CreateDestinationMarker(new GLatLng(51.2333,6.78333), markerOptions ,13,"Germany",32,"Dusseldorf"));
markers.push(CreateDestinationMarker(new GLatLng(50.95,6.96667), markerOptions ,13,"Germany",33,"Cologne"));
markers.push(CreateDestinationMarker(new GLatLng(50.1103,8.68222), markerOptions ,13,"Germany",34,"Frankfurt"));
markers.push(CreateDestinationMarker(new GLatLng(37.9667,23.7167), markerOptions ,14,"Greece",35,"Athens"));
markers.push(CreateDestinationMarker(new GLatLng(36.1667,28), markerOptions ,14,"Greece",36,"Rhodes"));
markers.push(CreateDestinationMarker(new GLatLng(35.196,24.95), markerOptions ,14,"Greece",37,"Crete"));
markers.push(CreateDestinationMarker(new GLatLng(47.4719,19.0503), markerOptions ,15,"Hungary",38,"Budapest"));
markers.push(CreateDestinationMarker(new GLatLng(64.1333,-21.9333), markerOptions ,16,"Iceland",39,"Reykjavik"));
markers.push(CreateDestinationMarker(new GLatLng(32.0833,34.8), markerOptions ,18,"Israel",43,"Tel Aviv"));
markers.push(CreateDestinationMarker(new GLatLng(32.8167,34.9833), markerOptions ,18,"Israel",44,"Haifa"));
markers.push(CreateDestinationMarker(new GLatLng(45.4636,9.1884), markerOptions ,19,"Italy",45,"Milan"));
markers.push(CreateDestinationMarker(new GLatLng(40.8333,14.25), markerOptions ,19,"Italy",46,"Naples"));
markers.push(CreateDestinationMarker(new GLatLng(41.9,12.5), markerOptions ,19,"Italy",47,"Rome"));
markers.push(CreateDestinationMarker(new GLatLng(43.7703,11.2547), markerOptions ,19,"Italy",48,"Florence"));
markers.push(CreateDestinationMarker(new GLatLng(45.4333,12.3167), markerOptions ,19,"Italy",49,"Venice"));
markers.push(CreateDestinationMarker(new GLatLng(40,9), markerOptions ,19,"Italy",50,"Sardinia"));
markers.push(CreateDestinationMarker(new GLatLng(40.626,14.376), markerOptions ,19,"Italy",51,"Sorrento"));
markers.push(CreateDestinationMarker(new GLatLng(49.6,6.11667), markerOptions ,20,"Luxembourg",52,"Luxembourg"));
markers.push(CreateDestinationMarker(new GLatLng(3.13333,101.7), markerOptions ,21,"Malaysia",53,"Kuala Lumpur"));
markers.push(CreateDestinationMarker(new GLatLng(5.4,100.233), markerOptions ,21,"Malaysia",54,"Penang"));
markers.push(CreateDestinationMarker(new GLatLng(35.8978,14.5125), markerOptions ,22,"Malta",55,"Valletta"));
markers.push(CreateDestinationMarker(new GLatLng(31.6333,-8), markerOptions ,23,"Morocco",56,"Marrakech"));
markers.push(CreateDestinationMarker(new GLatLng(33.5333,-7.58333), markerOptions ,23,"Morocco",57,"Casablanca"));
markers.push(CreateDestinationMarker(new GLatLng(30.4167,-9.58333), markerOptions ,23,"Morocco",58,"Agadir"));
markers.push(CreateDestinationMarker(new GLatLng(51.9217,4.48111), markerOptions ,24,"Netherlands",59,"Rotterdam"));
markers.push(CreateDestinationMarker(new GLatLng(52.373,4.893), markerOptions ,24,"Netherlands",60,"Amsterdam"));
markers.push(CreateDestinationMarker(new GLatLng(59.9333,10.75), markerOptions ,25,"Norway",61,"Oslo"));
markers.push(CreateDestinationMarker(new GLatLng(52.23,21.0108), markerOptions ,26,"Poland",62,"Warsaw"));
markers.push(CreateDestinationMarker(new GLatLng(50.0614,19.9372), markerOptions ,26,"Poland",63,"Krakow"));
markers.push(CreateDestinationMarker(new GLatLng(38.7,-9.18333), markerOptions ,27,"Portugal",64,"Lisbon"));
markers.push(CreateDestinationMarker(new GLatLng(37.04,-7.95), markerOptions ,27,"Portugal",65,"Algarve"));
markers.push(CreateDestinationMarker(new GLatLng(41.15,-8.63333), markerOptions ,27,"Portugal",66,"Porto"));
markers.push(CreateDestinationMarker(new GLatLng(44.4167,26.1), markerOptions ,28,"Romania",67,"Bucharest"));
markers.push(CreateDestinationMarker(new GLatLng(55.7522,37.6322), markerOptions ,29,"Russia",68,"Moscow"));
markers.push(CreateDestinationMarker(new GLatLng(59.9333,30.3333), markerOptions ,29,"Russia",69,"St Petersburg"));
markers.push(CreateDestinationMarker(new GLatLng(1.36667,103.8), markerOptions ,30,"Singapore",70,"Singapore"));
markers.push(CreateDestinationMarker(new GLatLng(48.1447,17.1128), markerOptions ,31,"Slovakia",71,"Bratislava"));
markers.push(CreateDestinationMarker(new GLatLng(-33.9264,18.4227), markerOptions ,32,"South Africa",72,"Cape Town"));
markers.push(CreateDestinationMarker(new GLatLng(-29.8833,31.05), markerOptions ,32,"South Africa",73,"Durban"));
markers.push(CreateDestinationMarker(new GLatLng(-26.1333,27.9), markerOptions ,32,"South Africa",74,"Johannesburg"));
markers.push(CreateDestinationMarker(new GLatLng(41.3856,2.1702), markerOptions ,33,"Spain",75,"Barcelona"));
markers.push(CreateDestinationMarker(new GLatLng(40.4,-3.68333), markerOptions ,33,"Spain",76,"Madrid"));
markers.push(CreateDestinationMarker(new GLatLng(36.7167,-4.41667), markerOptions ,33,"Spain",77,"Malaga"));
markers.push(CreateDestinationMarker(new GLatLng(37.3772,-5.98694), markerOptions ,33,"Spain",78,"Seville"));
markers.push(CreateDestinationMarker(new GLatLng(38.3453,-0.483056), markerOptions ,33,"Spain",79,"Alicante"));
markers.push(CreateDestinationMarker(new GLatLng(59.35,18.0667), markerOptions ,34,"Sweden",80,"Stockholm"));
markers.push(CreateDestinationMarker(new GLatLng(47.3667,8.55), markerOptions ,35,"Switzerland",81,"Zurich"));
markers.push(CreateDestinationMarker(new GLatLng(46.2,6.15), markerOptions ,35,"Switzerland",82,"Geneva"));
markers.push(CreateDestinationMarker(new GLatLng(36.8,10.17), markerOptions ,36,"Tunisia",83,"Tunis"));
markers.push(CreateDestinationMarker(new GLatLng(41.0122,28.976), markerOptions ,37,"Turkey",84,"Istanbul"));
markers.push(CreateDestinationMarker(new GLatLng(39.8667,32.8667), markerOptions ,37,"Turkey",85,"Ankara"));
markers.push(CreateDestinationMarker(new GLatLng(50.45,30.5233), markerOptions ,38,"Ukraine",86,"Kiev"));
markers.push(CreateDestinationMarker(new GLatLng(24.4765,54.3693), markerOptions ,10,"United Arab Emirates",87,"Abu Dhabi"));
markers.push(CreateDestinationMarker(new GLatLng(36.85,27.2333), markerOptions ,5,"China",88,"Beijing"));
markers.push(CreateDestinationMarker(new GLatLng(52.08,4.3), markerOptions ,24,"Netherlands",89,"The Hague"));
markers.push(CreateDestinationMarker(new GLatLng(18.96,72.82), markerOptions ,41,"India",91,"Mumbai"));
markers.push(CreateDestinationMarker(new GLatLng(28.7,77.2), markerOptions ,41,"India",92,"New Delhi"));
markers.push(CreateDestinationMarker(new GLatLng(35.6833,139.767), markerOptions ,40,"Japan",93,"Tokyo"));
markers.push(CreateDestinationMarker(new GLatLng(32.6292,-16.9217), markerOptions ,27,"Portugal",94,"Madeira"));
markers.push(CreateDestinationMarker(new GLatLng(56.9667,24.1333), markerOptions ,42,"Latvia",95,"Riga"));
markers.push(CreateDestinationMarker(new GLatLng(59.4333,24.75), markerOptions ,43,"Estonia",96,"Tallinn"));
markers.push(CreateDestinationMarker(new GLatLng(54.6833,25.2833), markerOptions ,46,"Lithuania",97,"Vilnius"));
markers.push(CreateDestinationMarker(new GLatLng(39.6167,2.98333), markerOptions ,33,"Spain",100,"Mallorca"));
markers.push(CreateDestinationMarker(new GLatLng(39.4735,-0.3766), markerOptions ,33,"Spain",101,"Valencia"));
markers.push(CreateDestinationMarker(new GLatLng(36.143,-5.353), markerOptions ,48,"Gibraltar",102,"Gibraltar"));
markers.push(CreateDestinationMarker(new GLatLng(29.0081,-13.6312), markerOptions ,33,"Spain",103,"Lanzarote, Canary Islands"));
markers.push(CreateDestinationMarker(new GLatLng(35.9186,14.49), markerOptions ,22,"Malta",104,"St Julians"));
markers.push(CreateDestinationMarker(new GLatLng(-33.86,151.211), markerOptions ,49,"Australia",105,"Sydney"));
markers.push(CreateDestinationMarker(new GLatLng(13.75, 100.483), markerOptions, 50, "Thailand", 112, "Bangkok"));
markers.push(CreateDestinationMarker(new GLatLng(-20.282293, 57.56012), markerOptions, 51, "Mauritius", 114, "Mauritius"));

	
	// Handle England and Ireland separately.
	var irelandMarker = new GMarker(new GLatLng(53.435,-7.7783), markerOptions);
		GEvent.addListener(irelandMarker, "click", function() {
			var url = "<b>Ireland</b><br><br>";
			url += "<a href='search-loc.aspx'>go to UK and Ireland channel</a>";
			irelandMarker.openInfoWindowHtml(url);
		});
	markers.push(irelandMarker);
	
	var englandMarker = new GMarker(new GLatLng(51.6428,-0.974), markerOptions);
		GEvent.addListener(englandMarker, "click", function() {
			var url = "<b>United Kingdom</b><br><br>";
			url += "<a href='search-loc.aspx'>go to UK and Ireland channel</a>";
			englandMarker.openInfoWindowHtml(url);
		});
	markers.push(englandMarker);
	return markers;
}


function OnCountryChange() {
	var countrySelectBox = document.getElementById('CountryDropDownList');
	var selectedText = countrySelectBox.options[countrySelectBox.selectedIndex].text
	if (selectedText == "United Kingdom" || selectedText == "Ireland"){
		if (confirm("Would you like to go to the UK and Ireland channel which has over 7700 venues?")) {
			countrySelectBox.selectedIndex = 0;
			var url;
			var baseAddr = null;
			// Handle BASE tag
			if (document.getElementsByTagName) {
				var elems = document.getElementsByTagName( 'base' );
				if (elems.length) baseAddr = elems[0].href;
				url = baseAddr + "search-loc.aspx";
			} else {
				url = "/search-loc.aspx";
			}
			window.location = url;
		} else {
			countrySelectBox.selectedIndex =0;
			document.getElementById("countryTip").style.display="none";
		}
	} else if (countrySelectBox.selectedIndex == 0) {
		// "- any -" country has been selected - reenable any disabled search options.
		document.getElementById("FlightTimeDropDown").disabled = false;
		document.getElementById("IncludeUKVenuesCheckBox").disabled = false;
		document.getElementById("countryTip").style.display="none";
		
		// reset destinations to normal list
		var townDDL = document.getElementById("TownCityDropDownList");
		townDDL.options.length=0;
		addOption(townDDL," - any -","");
		for(var i=0; i < locationsArray.length; i++) {
			addOption(townDDL,locationsArray[i][3],locationsArray[i][3]);
		}
		sortDropDownList(townDDL);
		townDDL.selectedIndex=0;
		
	} else {
		// A country has been selected so disable options applicable when searching a specific country.
		document.getElementById("FlightTimeDropDown").disabled = true;
		document.getElementById("IncludeUKVenuesCheckBox").disabled = true;
		document.getElementById("countryTip").style.display="block";
		document.getElementById("countryTip").innerHTML = '<a href="country-info.aspx?id='+countrySelectBox.value+'">Show&nbsp;me&nbsp;information&nbsp;on&nbsp;'+selectedText+'</a>';
		
		// Show correct cities in city drop down
		var cityArray = new Array();
		for(var i=0; i < locationsArray.length; i++) {
			if(locationsArray[i][0] == countrySelectBox.options[countrySelectBox.selectedIndex].value) {
				cityArray.push(locationsArray[i]);
			}
		}
		var townDDL = document.getElementById("TownCityDropDownList");
		townDDL.options.length=0;
		addOption(townDDL," - any -","");
		for(var i=0; i < cityArray.length; i++) {
			addOption(townDDL,cityArray[i][3],cityArray[i][3]);
		}
		
		
	} 
}

function addOption(selectbox,text,value ) {
	var optn = document.createElement("option");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function sortDropDownList(dropDownList) {
	var lb = dropDownList;
	arrTexts = new Array();

	for(i=0; i<lb.length; i++)  {
	  arrTexts[i] = lb.options[i].text;
	}

	arrTexts.sort();

	for(i=0; i<lb.length; i++)  {
	  lb.options[i].text = arrTexts[i];
	  lb.options[i].value = arrTexts[i];
	}
}

function OnBedroomOptionChange(bedOption) {
    if (bedOption == "perdestination") {
        document.getElementById("IncludeUKVenuesCheckBox").disabled = true;
    } else {
        document.getElementById("IncludeUKVenuesCheckBox").disabled = false;
    }
}

function OnIncludeUKVenuesChange() {
    var checkBox = document.getElementById("IncludeUKVenuesCheckBox");
    if (checkBox.checked) {
        var el = document.getElementById("CountryDropDownList");
        el.disabled = true;
        el.selectedIndex =0;
        el = document.getElementById("FlightTimeDropDown");
        el.selectedIndex =0;
        el.disabled = true;
        el = document.getElementById("TownCityDropDownList");
        el.selectedIndex =0;
        el.disabled = true;
        document.getElementById("BedroomsOption_0").checked = true;
    } else {
        var el = document.getElementById("TownCityDropDownList");
        el.disabled = false;
        document.getElementById("CountryDropDownList").disabled = false;
        document.getElementById("FlightTimeDropDown").disabled = false;
    }
}

function OnTownCityChange() {
	var dropDown = document.getElementById("TownCityDropDownList");
	if (dropDown.selectedIndex != 0) {
		document.getElementById("IncludeUKVenuesCheckBox").disabled = true;
		document.getElementById("FlightTimeDropDown").disabled = true;
		document.getElementById("FlightTimeDropDown").selectedIndex = 0;
		ChangeCityTip(dropDown.value);
		resetZoom();
	} else {
		document.getElementById("IncludeUKVenuesCheckBox").disabled = false;
		document.getElementById("FlightTimeDropDown").disabled = false;
		document.getElementById("cityTip").style.display="none";
	}
}

function OnFlightTimesChange() {
	var dropDown = document.getElementById("FlightTimeDropDown");
	if (dropDown.selectedIndex != 0) {
		document.getElementById("IncludeUKVenuesCheckBox").disabled = true;
	} else {
		document.getElementById("IncludeUKVenuesCheckBox").disabled = false;
	}
}

function SetupForm() { 
	/*SetlocationArray()
	OnCountryChange();
	OnTownCityChange();
	OnFlightTimesChange();
	OnBedroomOptionChange();
	OnIncludeUKVenuesChange();*/
}

function SetCityTip(destinationId, destinationName){
	document.getElementById("cityTip").style.display="block";
	document.getElementById("cityTip").innerHTML = '<a href="country-info.aspx?id=' + destinationId + '#' + destinationName + '">Show&nbsp;me&nbsp;information&nbsp;on&nbsp;'+destinationName+'</a>';
}

function ChangeCityTip(destinationName){
	var destinationId;
	for(var i = 0; i<locationsArray.length;i++){
		if(locationsArray[i][3] == destinationName)
			destinationId = locationsArray[i][0];
	}
	SetCityTip(destinationId, destinationName);
	map.panTo(mapCenter);
}

function SetlocationArray() {
    locationsArray.length = 0;

    locationsArray.push([49, "Australia", 105, "Sydney"]);
    locationsArray.push([1, "Austria", 3, "Innsbruck"]);
    locationsArray.push([1, "Austria", 2, "Salzburg"]);
    locationsArray.push([1, "Austria", 1, "Vienna"]);
    locationsArray.push([2, "Belgium", 5, "Antwerp"]);
    locationsArray.push([2, "Belgium", 6, "Bruges"]);
    locationsArray.push([2, "Belgium", 4, "Brussels"]);
    locationsArray.push([3, "Brazil", 7, "Rio de Janeiro"]);
    locationsArray.push([3, "Brazil", 8, "Sao Paulo"]);
    locationsArray.push([4, "Bulgaria", 9, "Sofia"]);
    locationsArray.push([4, "Bulgaria", 10, "Varna"]);
    locationsArray.push([5, "China", 88, "Beijing"]);
    locationsArray.push([5, "China", 11, "Hong Kong"]);
    locationsArray.push([5, "China", 12, "Shanghai"]);
    locationsArray.push([6, "Croatia", 13, "Zagreb"]);
    locationsArray.push([7, "Cyprus", 15, "Limassol"]);
    locationsArray.push([7, "Cyprus", 14, "Nicosia"]);
    locationsArray.push([7, "Cyprus", 16, "Paphos"]);
    locationsArray.push([8, "Czech Republic", 17, "Prague"]);
    locationsArray.push([9, "Denmark", 18, "Copenhagen"]);
    locationsArray.push([43, "Estonia", 96, "Tallinn"]);
    locationsArray.push([11, "Finland", 20, "Helsinki"]);
    locationsArray.push([12, "France", 25, "Cannes"]);
    locationsArray.push([12, "France", 22, "Lyon"]);
    locationsArray.push([12, "France", 26, "Marseille"]);
    locationsArray.push([12, "France", 24, "Nice"]);
    locationsArray.push([12, "France", 21, "Paris"]);
    locationsArray.push([13, "Germany", 28, "Berlin"]);
    locationsArray.push([13, "Germany", 29, "Bonn"]);
    locationsArray.push([13, "Germany", 33, "Cologne"]);
    locationsArray.push([13, "Germany", 32, "Dusseldorf"]);
    locationsArray.push([13, "Germany", 34, "Frankfurt"]);
    locationsArray.push([13, "Germany", 27, "Hamburg"]);
    locationsArray.push([13, "Germany", 30, "Munich"]);
    locationsArray.push([13, "Germany", 31, "Stuttgart"]);
    locationsArray.push([48, "Gibraltar", 102, "Gibraltar"]);
    locationsArray.push([14, "Greece", 35, "Athens"]);
    locationsArray.push([14, "Greece", 37, "Crete"]);
    locationsArray.push([14, "Greece", 36, "Rhodes"]);
    locationsArray.push([15, "Hungary", 38, "Budapest"]);
    locationsArray.push([16, "Iceland", 39, "Reykjavik"]);
    locationsArray.push([41, "India", 91, "Mumbai"]);
    locationsArray.push([41, "India", 92, "New Delhi"]);
    locationsArray.push([18, "Israel", 44, "Haifa"]);
    locationsArray.push([18, "Israel", 43, "Tel Aviv"]);
    locationsArray.push([19, "Italy", 48, "Florence"]);
    locationsArray.push([19, "Italy", 45, "Milan"]);
    locationsArray.push([19, "Italy", 46, "Naples"]);
    locationsArray.push([19, "Italy", 47, "Rome"]);
    locationsArray.push([19, "Italy", 50, "Sardinia"]);
    locationsArray.push([19, "Italy", 51, "Sorrento"]);
    locationsArray.push([19, "Italy", 49, "Venice"]);
    locationsArray.push([40, "Japan", 93, "Tokyo"]);
    locationsArray.push([42, "Latvia", 95, "Riga"]);
    locationsArray.push([46, "Lithuania", 97, "Vilnius"]);
    locationsArray.push([20, "Luxembourg", 52, "Luxembourg"]);
    locationsArray.push([21, "Malaysia", 53, "Kuala Lumpur"]);
    locationsArray.push([21, "Malaysia", 54, "Penang"]);
    locationsArray.push([22, "Malta", 104, "St Julians"]);
    locationsArray.push([22, "Malta", 55, "Valletta"]);
    locationsArray.push([39, "Monaco", 23, "Monte Carlo"]);
    locationsArray.push([23, "Morocco", 58, "Agadir"]);
    locationsArray.push([23, "Morocco", 57, "Casablanca"]);
    locationsArray.push([23, "Morocco", 56, "Marrakech"]);
    locationsArray.push([24, "Netherlands", 60, "Amsterdam"]);
    locationsArray.push([24, "Netherlands", 59, "Rotterdam"]);
    locationsArray.push([24, "Netherlands", 89, "The Hague"]);
    locationsArray.push([25, "Norway", 61, "Oslo"]);
    locationsArray.push([26, "Poland", 63, "Krakow"]);
    locationsArray.push([26, "Poland", 62, "Warsaw"]);
    locationsArray.push([27, "Portugal", 65, "Algarve"]);
    locationsArray.push([27, "Portugal", 64, "Lisbon"]);
    locationsArray.push([27, "Portugal", 94, "Madeira"]);
    locationsArray.push([27, "Portugal", 66, "Porto"]);
    locationsArray.push([28, "Romania", 67, "Bucharest"]);
    locationsArray.push([29, "Russia", 68, "Moscow"]);
    locationsArray.push([29, "Russia", 69, "St Petersburg"]);
    locationsArray.push([30, "Singapore", 70, "Singapore"]);
    locationsArray.push([31, "Slovakia", 71, "Bratislava"]);
    locationsArray.push([32, "South Africa", 72, "Cape Town"]);
    locationsArray.push([32, "South Africa", 73, "Durban"]);
    locationsArray.push([32, "South Africa", 74, "Johannesburg"]);
    locationsArray.push([33, "Spain", 79, "Alicante"]);
    locationsArray.push([33, "Spain", 75, "Barcelona"]);
    locationsArray.push([33, "Spain", 103, "Lanzarote, Canary Islands"]);
    locationsArray.push([33, "Spain", 76, "Madrid"]);
    locationsArray.push([33, "Spain", 77, "Malaga"]);
    locationsArray.push([33, "Spain", 100, "Mallorca"]);
    locationsArray.push([33, "Spain", 78, "Seville"]);
    locationsArray.push([33, "Spain", 101, "Valencia"]);
    locationsArray.push([34, "Sweden", 80, "Stockholm"]);
    locationsArray.push([35, "Switzerland", 82, "Geneva"]);
    locationsArray.push([35, "Switzerland", 81, "Zurich"]);
    locationsArray.push([50, "Thailand", 112, "Bangkok"]);
    locationsArray.push([36, "Tunisia", 83, "Tunis"]);
    locationsArray.push([37, "Turkey", 85, "Ankara"]);
    locationsArray.push([37, "Turkey", 84, "Istanbul"]);
    locationsArray.push([38, "Ukraine", 86, "Kiev"]);
    locationsArray.push([10, "United Arab Emirates", 87, "Abu Dhabi"]);
    locationsArray.push([10, "United Arab Emirates", 19, "Dubai"]);
    locationsArray.push([51, "Mauritius", 114, "Mauritius"]);
    locationsArray.push([33, "Spain", 115, "Toledo"]);
}
