var map;
var geocoder = new GClientGeocoder();
var centerMapFix = false;

function loadMap(mapfix)
{
	centerMapFix = mapfix;
	var centerPoint;
	if (GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallZoomControl());

		if($('lat').value && $('lng').value)
			centerPoint = new GLatLng($('lat').value, $('lng').value);
		else
			centerPoint = new GLatLng(43.678, -79.398);

		map.setCenter(centerPoint, 14);
		var marker = new GMarker(centerPoint);
		map.addOverlay(marker);
	}

	if($('address')) $('address').onblur = showAddress; 
	if($('city')) $('city').onblur = showAddress; 
	if($('region')) $('region').onblur = showAddress; 
	if($('country')) $('country').onblur = showAddress; 
}

function showAddress()
{
	var address = '';
	if(!$('address').value) return; else address += $('address').value + ', ';
	if(!$('city').value) return; else address += $('city').value + ', ';
	if(!$('region').value) return; else address += $('region').value + ', ';
	if(!$('country').value) return; else address += $('country').value;


	geocoder.getLatLng(address, function(point) {
	        if (!point) {
		//        alert(address + " not found");
		} else {
		$('lat').value = point.lat();
		$('lng').value = point.lng();

		if(centerMapFix)
			map.setCenter(new GLatLng(point.lat()+0.008, point.lng()-0.01));
		else
			map.setCenter(point);

		var marker = new GMarker(point);
		map.clearOverlays();
		map.addOverlay(marker);
//		marker.openInfoWindowHtml(address);
		}
	});

}

