﻿function showMap(address) {
	var map = document.getElementById('googleMapDiv');
	if (!map) return;
	
	var y = document.body.clientWidth / 2 - 250;
	var x = document.body.scrollTop + (document.body.clientHeight / 2 - 160);

	map.style.left = y + "px";
	map.style.top = x + "px";
	
	map.style.visibility = "visible";
	map.style.display = "block";
	
	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(document.getElementById("googleMapContainer"));
		gmap.addControl(new GSmallMapControl());
		var geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					hideMap();
					alert('Sorry, no map is currently available for this location.');
				} else {
					gmap.setCenter(point, 13);
					var marker = new GMarker(point);
					gmap.addOverlay(marker);
					marker.openInfoWindowHtml(address);
				}
			}
		);
	}
};

function hideMap() {
	var map = document.getElementById('googleMapDiv');
	if (!map) return;

	map.style.visibility = "hidden";
	map.style.display = "none";
};