var map = null;
var geocoder = null;

function showAddress() {
	var address = document.getElementById('mapAddress').value;
	var lat = document.getElementById('mapLat').value;
	var lon = document.getElementById('mapLon').value;
	var infotext = document.getElementById('mapInfotext').value;
	if (lat > 0 && lon > 0 ) { 
		point = new GLatLng (lon, lat);
		map.setCenter(point, 13);
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(infotext);
		});
		map.addOverlay(marker);
		marker.openInfoWindowHtml(infotext);
	} else {
		if (geocoder) {
			geocoder.getLatLng(
				address,
			function (point) {
				if (!point) {
					GUnload();
				} else {
					map.setCenter(point, 13);
					var marker = new GMarker(point);
					GEvent.addListener(marker, "click", function() {
							marker.openInfoWindowHtml(infotext);
					});
					map.addOverlay(marker);
					marker.openInfoWindowHtml(infotext);
				}
			}
			);
		}	
	}
}

function load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		showAddress();
	} else {
		document.getElementById("map").style.display="none";
	}
}
