function create_tooltip(map, marker, tooltip)
{
	marker.openInfoWindowHtml(tooltip);
	
	// Mouseover marker -> show tooltip:
	GEvent.addListener(marker, 'click', function() {
		if ( map.getInfoWindow().isHidden() )
			marker.openInfoWindowHtml(tooltip);
		else
			map.getInfoWindow().hide();
	});
}

function showMapPoint(idMapCanvas, latitude, longitude, zoom, isEdit, idAlertMessage, tooltip, functionMarker) {
    if ( GBrowserIsCompatible() )
	{
        var map = new GMap2(document.getElementById(idMapCanvas));
        var point = new GLatLng(latitude, longitude);
	
		// create the custom icon
		var customIcon = new GIcon(G_DEFAULT_ICON);
		customIcon.image = 'visuals/images/marker.png';
		customIcon.iconSize = new GSize(20, 34);
		customIcon.iconAnchor = new GPoint(9, 34);
		var marker = new GMarker( point, {draggable: isEdit, icon: customIcon} );
		
		create_tooltip(map, marker, tooltip);
		
        map.setCenter(point, zoom);
		map.setUIToDefault();
		if ( functionMarker ) functionMarker(map, marker);
		map.addOverlay(marker);
    }
}

function showUnitOnMap(idMapCanvas, visitation_address, visitation_city, visitation_zipcode,
						post_address, post_city, post_zipcode, zoom, isEdit,
						defaultAddress, defaultCountry, idAlertMessage, tooltip, functionMarker) {
    
    document.getElementById(idAlertMessage).style.display = 'none'; 
    
    if (GBrowserIsCompatible()) {
        var geocoder = new GClientGeocoder();  
        var map = new GMap2(document.getElementById(idMapCanvas));
	  
        if (geocoder) {
			// Visitation address -> street, city
			showMapAddress(geocoder, map, idMapCanvas, '' + visitation_address + ', ' + visitation_city + ', '+ defaultCountry, zoom, isEdit, idAlertMessage, tooltip, functionMarker, function(){
			  // Visitation address -> street, ZIP:
			  showMapAddress(geocoder, map, idMapCanvas, '' + visitation_address + ', ' + visitation_zipcode + ', '+ defaultCountry, zoom, isEdit, idAlertMessage, tooltip, functionMarker, function(){
				// Post address -> street, city:
				showMapAddress(geocoder, map, idMapCanvas, '' + post_address + ', ' + post_city + ', '+ defaultCountry, zoom, isEdit, idAlertMessage, tooltip, functionMarker, function(){
				  // Post address -> street, ZIP:
				  showMapAddress(geocoder, map, idMapCanvas, '' + post_address + ', ' + post_zipcode + ', '+ defaultCountry, zoom, isEdit, idAlertMessage, tooltip, functionMarker, function(){
					// No match -> view default address: {* Settings::$map_default_address, Settings::$map_default_country *}
					showMapAddress(geocoder, map, idMapCanvas, defaultAddress +', '+ defaultCountry, zoom, isEdit, idAlertMessage, tooltip, functionMarker);
				  });
				});
			  });
			});
        }
    }
}  

function showMapAddress(geocoder, map, idMapCanvas, address, zoom, isEdit, idAlertMessage, tooltip, functionMarker, callback) {
    
    geocoder.getLatLng(address, function(point) {
        if (point) {
			// create the custom icon:
			var customIcon = new GIcon(G_DEFAULT_ICON);
			customIcon.image = 'visuals/images/marker.png';
			customIcon.iconSize = new GSize(20, 34);
			customIcon.iconAnchor = new GPoint(9, 34);
			var marker = new GMarker(point,{draggable: isEdit, icon: customIcon});
		
			create_tooltip(map, marker, tooltip);
		
			map.setCenter(point, zoom);
			map.setUIToDefault();
			if ( functionMarker ) functionMarker(map, marker);
			map.addOverlay(marker);
        }
        else{
            if (callback != null){
                callback();
            }else{
				$('#'+idAlertMessage).fadeIn();
				$('#'+idMapCanvas).fadeOut();
            }
        }
      });     
} 