var map = null;
var geocoder = null;

function loadMapPreview() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("previewMap"));
		map.markAt =
		function (point, zoomLevel) {
			if (map.isLoaded()) {
				map.panTo(point);
			}
			else {
				map.setCenter(point, zoomLevel);
			}
			var marker = new GMarker(point);
			map.clearOverlays();
			map.addOverlay(marker);
		};
		GEvent.addListener(map, "click", function(marker, point) {
			map.markAt(point, 15);
			document.getElementById("hidden_lat").value = point.lat();
			document.getElementById("hidden_lng").value = point.lng();			
		});
		map.addControl(new GSmallMapControl());
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		geocoder = new GClientGeocoder();
		geocoder.reset();
		var hidden_lat = document.getElementById("hidden_lat").value;
		var hidden_lng = document.getElementById("hidden_lng").value;
		if (hidden_lat != 0 && hidden_lng != 0) map.markAt(new GLatLng(hidden_lat, hidden_lng), 15)
	}
}

function showAddress(event) {
	var eve = (window.event)? window.event : event;
	eve.cancelBubble = true;
	var address = document.getElementById("meetPlaceMap").value;
	geocoder.getLatLng(address,
	function(point) {
		if (!point) {
			alert(address + " not found.\nPlease make sure the address is entered with ONLY (street number, street name, city, province and postal code).\nIf the correct format of address is given and still cannot locate the map,\n please enter ONLY city and/or postal to obtain an approximation and proceed to step 2 to place the marker onto the map.");
		}
		else {
			map.markAt(point, 15);
			document.getElementById("hidden_lat").value = point.lat();
			document.getElementById("hidden_lng").value = point.lng();
		}
	}
	);
}

