var addingLocation = false;
var divMapExtras;


function selectCountry(lat, lon, countryCode, countryName)
{
	setCenterAndMinZoom(lat, lon, 5)
	LoadContentService.LoadCountry(countryCode)
}

function selectCity(lat, lon, cityID, locationID, cityName)
{
	setCenterAndMinZoom(lat, lon, 7)
	LoadContentService.LoadCity(cityID)
}

function selectKnownLocation(locationID, locationName, cityID, countryCode, lat, lon)
{
	if (cityID == "")
	{
		setCenterAndMinZoom(lat, lon, 5)
		LoadContentService.LoadCountry(countryCode)
	}
	else
	{
		setCenterAndMinZoom(lat, lon, 7)
		LoadContentService.LoadCity(cityID)
	}
}

function selectUnknownLocation(cityID, cityName, stateCode, countryName, locationName, lat, lon)
{
	setCenterAndMinZoom(lat, lon, 7)
	LoadContentService.LoadCity(cityID)
}

function setCenterAndMinZoom(lat, lng, minZoom)
{
	var zoom = map.getZoom();
	if (zoom < minZoom)
	{
		zoom = minZoom;
	}
	map.setCenter(new GLatLng(lat, lng), zoom);
	
}


/*
function addLocation()
{
	if (!addingLocation)
	{
		var mapDiv = document.getElementById(mapDivID);
		mapDiv.firstChild.firstChild.style.cursor = "crosshair";
	
		divMapExtras.innerHTML = "Click the map to add a place";
		GEvent.bind(map, "mousemove", this, addLocation_MouseMove);
		GEvent.removeListener(mapClickListener);
		GEvent.bind(map, "click", this, addLocation_Click);
		
		addingLocation = true;
	}

}

function addLocation_MouseMove(latlng)
{
	var txt = "Click the map to add a place at (" + latlng.lng() + ", " + latlng.lat() + ")";
	
	divMapExtras.innerHTML = txt;
}

function addLocation_Click(overlay, point)
{
	if (point != null)
	{
		document.CityFinder.cityID.value = "";
		document.CityFinder.countryCode.value = "";
		document.CityFinder.search.value = "";
		document.CityFinder.x.value = point.x;
		document.CityFinder.y.value = point.y;
		
		document.CityFinder.action="/LocationRequest.aspx";
		document.CityFinder.submit();
	}
}
*/


function goSearch()
{
	document.CityFinder.cityID.value = "";
	document.CityFinder.countryCode.value = "";
	document.CityFinder.search.value = document.locationSearch.search.value;
	document.CityFinder.action="/WorldBrowser.aspx";
	document.CityFinder.submit();
}


function worldBrowser_init()
{
	if (document.CityFinder.cityID.value != "")
	{
		renderFeature(document.CityFinder.x.value, document.CityFinder.y.value, document.CityFinder.cityID.value, "");
	}
	
	divMapExtras = document.getElementById("divMapExtras");
	if (divMapExtras)
	{
		divMapExtras.style.visibility = "visible";
	}

}

window.onMapInit = worldBrowser_init;

