/******************************************************************************
* gmapsUtils.js
*******************************************************************************
fonctions de creation de cartes
*******************************************************************************
*                                                                             *
* Copyright 2006									                          *
*                                                                             *
******************************************************************************/


/////////////////////////////////////////////
//
function positionMap (theMap, theGeocoder, theGoogleAddress) {

	if (theGeocoder) {
        	theGeocoder.getLatLng(
			theGoogleAddress [0],
			function(point) {
				if (!point) {
					alert("Impossible de trouver\n" + theGoogleAddress[0]);
				} else {
					theMap.setCenter(point, 13);
					var tooltip = theGoogleAddress[1] + "\n" + theGoogleAddress[2] +"\n"+ theGoogleAddress[3];
					var marker = new GMarker(point, { draggable:false, title:tooltip });
					marker.isoAdress = '<span style="font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif">'+theGoogleAddress[1]+'<br>'+theGoogleAddress[2]+'<br>'+ theGoogleAddress[3]+'</span>';
					theMap.addOverlay(marker);
					GEvent.addListener(marker, "click", function() {  marker.openInfoWindowHtml(marker.isoAdress);  });
					marker.openInfoWindowHtml(marker.isoAdress);
				}
			}
		);
	}
}

function Prepare (theMap, theGeocoder, bShowSmallMap, theGoogleAddress)
{
	theMap.addControl(new GLargeMapControl());
	theMap.addControl(new GMapTypeControl());
	if (bShowSmallMap)
		theMap.addControl(new GOverviewMapControl());
	positionMap (theMap, theGeocoder, theGoogleAddress);
}


function PrepareRoute (theMap, theGdir, theHandleErrors)
{
	theMap.addControl(new GSmallMapControl());
	theMap.addControl(new GMapTypeControl());
	GEvent.addListener(theGdir, 'error', theHandleErrors);
}

function PreparePos (theMap, bShowSmallMap, point, theGoogleAddress)
{
	theMap.addControl(new GLargeMapControl());
	theMap.addControl(new GMapTypeControl());
	if (bShowSmallMap)
		theMap.addControl(new GOverviewMapControl());

        theMap.setCenter(point, 13);
	var tooltip = theGoogleAddress[1] + "\n" + theGoogleAddress[2] +"\n"+ theGoogleAddress[3];
	var marker = new GMarker(point, { draggable:false, title:tooltip });
	marker.isoAdress = '<span style="font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif">'+theGoogleAddress[1]+'<br>'+theGoogleAddress[2]+'<br>'+ theGoogleAddress[3]+'</span>';
	theMap.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {  marker.openInfoWindowHtml(marker.isoAdress);  });
	marker.openInfoWindowHtml(marker.isoAdress);
}

window.onunload = function myUnload() 
{
	try {
		GUnload (); 
	} 
	catch (e) {
		// Nothing to do...
	}
}

