
/************************************************************
 * Created with GoogleMapAPI 2.0
 * Author:	Loredana Zeca (typo3dev AT ameos DOT com)
 * Company:	AMEOS, France
 ************************************************************/


// declare global variables
var k;
var bSelectCats = "1";

var gmXmlDoc;
var gmMap = null;

var gmMarkers;
var gmMarkerTabs;
var gmMarkerTrace;
var gmMarkerZipcode;
var gmMarkerAddress;

var gmIcons = [];



// attach an event to the window, properly
addEvent(window, 'load', getXml);
addEvent(window, 'unload', GUnload);
function addEvent(obj, sEventType, oFunction){ 
	if (obj.addEventListener){ 
		obj.addEventListener(sEventType, oFunction, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on" + sEventType, oFunction); 
		return r; 
	} else { 
		return false; 
	}
}

// attach the corresponding XML to the current page
function getXml() {

	if (GBrowserIsCompatible()) {

		// Generate the xml behind googlemap
		var oRequest = GXmlHttp.create();  
		oRequest.open("GET", "http://www.apave.com/typo3temp/ameos_googlemap/country-53-fr.xml", true);

		oRequest.onreadystatechange = function() {
			if (oRequest.readyState == 4) {
				if (oRequest.status != 200) {
					alert("file not found: " + oRequest.status);
					return;
				}
				gmXmlDoc = oRequest.responseXML;
				if (!gmXmlDoc) {
					alert("invalid xml file");
					return;
				}

				// define global icons for markers
									var cat0 = new GIcon();
					cat0.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_blue.gif";
					cat0.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat0.shadowSize = new GSize(22, 20);
					cat0.iconSize = new GSize(12, 20);
					cat0.iconAnchor = new GPoint(6, 20);
					cat0.infoWindowAnchor = new GPoint(5, 1);
					cat0.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat0.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_blue.gif"] = new GIcon(cat0);
					var cat1 = new GIcon();
					cat1.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_green.gif";
					cat1.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat1.shadowSize = new GSize(22, 20);
					cat1.iconSize = new GSize(12, 20);
					cat1.iconAnchor = new GPoint(6, 20);
					cat1.infoWindowAnchor = new GPoint(5, 1);
					cat1.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat1.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_green.gif"] = new GIcon(cat1);
					var cat2 = new GIcon();
					cat2.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_purple.gif";
					cat2.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat2.shadowSize = new GSize(22, 20);
					cat2.iconSize = new GSize(12, 20);
					cat2.iconAnchor = new GPoint(6, 20);
					cat2.infoWindowAnchor = new GPoint(5, 1);
					cat2.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat2.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_purple.gif"] = new GIcon(cat2);
					var cat3 = new GIcon();
					cat3.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_red.gif";
					cat3.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat3.shadowSize = new GSize(22, 20);
					cat3.iconSize = new GSize(12, 20);
					cat3.iconAnchor = new GPoint(6, 20);
					cat3.infoWindowAnchor = new GPoint(5, 1);
					cat3.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat3.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_red.gif"] = new GIcon(cat3);
					var cat4 = new GIcon();
					cat4.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_silver.gif";
					cat4.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat4.shadowSize = new GSize(22, 20);
					cat4.iconSize = new GSize(12, 20);
					cat4.iconAnchor = new GPoint(6, 20);
					cat4.infoWindowAnchor = new GPoint(5, 1);
					cat4.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat4.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_silver.gif"] = new GIcon(cat4);
					var cat5 = new GIcon();
					cat5.image = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_yellow.gif";
					cat5.shadow = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_shadow.png";
					cat5.shadowSize = new GSize(22, 20);
					cat5.iconSize = new GSize(12, 20);
					cat5.iconAnchor = new GPoint(6, 20);
					cat5.infoWindowAnchor = new GPoint(5, 1);
					cat5.imageMap = [4,0,0,4,0,7,3,11,4,19,7,19,8,11,11,7,11,4,7,0];
					cat5.transparent = "http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/bubble_transparent.png";
					gmIcons["bubble_yellow.gif"] = new GIcon(cat5);


				// set the initial trace for googlemap
							document.getElementById("tx-ameosgooglemap-trace").innerHTML = " &raquo; Côte d'Ivoire";
				

				// generate the map, center and zoom it
				makeMap();

				// Instanciate the GDirection map
								gdir = new GDirections(gmMap, document.getElementById("tx-ameosgooglemap-direction"));
				GEvent.addListener(gdir, "load", onGDirectionsLoad);
				GEvent.addListener(gdir, "error", onGDirectionError);

				// check if there was a search for a zipcode and if yes, then show the point information
				executeDefaultSearch();
			}
		}

		oRequest.send(null);

	} else {
		document.write("JavaScript must be enabled in order to use Google Maps!");
	}

}

// generate the map, center and zoom it
function makeMap() {

	// set the map center and zoom
	if (gmMap == null) {
		oMapCenter = new GLatLng(7.819847426192587, -5.82275390625);
		iMapZoom = 6;
	} else {
		oMapCenter = gmMap.getCenter();
		iMapZoom = gmMap.getZoom();
	}

	// create the map and customize the design of map
	gmMap = new GMap2(document.getElementById("tx-ameosgooglemap-map"));
	gmMap.addControl(new GLargeMapControl());gmMap.addControl(new GMapTypeControl());addDragZoomControl("draging");
	gmMap.setCenter(oMapCenter, iMapZoom);


	k = 0;
	gmMarkers = new Array();
	gmMarkerTabs = new Array();
	gmMarkerTrace = new Array();
	gmMarkerZipcode = new Array();
	gmMarkerAddress = new Array();

	xmlMarkers = gmXmlDoc.getElementsByTagName("marker");
	for (var i=0; i < xmlMarkers.length; i++) {

		if (xmlMarkers[i].getAttribute("hastabs") == "1") {

			// if the click on a marker must display the marker infos
			addInfosMarker(xmlMarkers[i]);

		} else {

			// if the click on a marker must generate a link to another page
			addLinkMarker(xmlMarkers[i]);
		}
	}
}

// create area for Drag and Zoom buttons
function addDragZoomControl(state) {

	// define the style of icon
	var boxStyleOpts = {
		opacity: 0.2,
		border: "2px solid red"
	}

	// set the 2 buttons: zoom and drag used to manipulate the zoom/drag on map
	var otherOpts = {
		buttonStyle: {background: 'transparent'},
		buttonStartingStyle: {border: 'none', margin: '0px', padding: '0px'},
		buttonHTMLZoom: '   <div class=\"tx-ameosgooglemap-zoom\">  <img src=\"http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/zoom.gif\" alt=\"\" onmouseover=\"showTooltip(\'tx_ameosgooglemap_zoom\');\" onmouseout=\"hideTooltip(\'tx_ameosgooglemap_zoom\');\" />  <div id=\"tx_ameosgooglemap_zoom\" class=\"tooltip\" style=\"display: none;\">   Pour zoomer sur une zone de la carte: S&eacute;lectionnez la zone &agrave; agrandir &agrave; l\'aide de votre souris  </div>  <div class=\"clear\"></div> </div>  ',
		buttonZoomingHTMLZoom: '   <div class=\"tx-ameosgooglemap-zoom\">  <img src=\"http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/zoom_active.gif\" alt=\"\" onmouseover=\"showTooltip(\'tx_ameosgooglemap_zoom\');\" onmouseout=\"hideTooltip(\'tx_ameosgooglemap_zoom\');\" />  <div id=\"tx_ameosgooglemap_zoom\" class=\"tooltip\" style=\"display: none;\">   Pour zoomer sur une zone de la carte: S&eacute;lectionnez la zone &agrave; agrandir &agrave; l\'aide de votre souris  </div>  <div class=\"clear\"></div> </div>  ',
		buttonZoomingStyle: {background: 'transparent'},
		buttonHTMLDrag: '   <div class=\"tx-ameosgooglemap-drag\">  <img src=\"http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/drag.gif\" alt=\"\" onmouseover=\"showTooltip(\'tx_ameosgooglemap_drag\');\" onmouseout=\"hideTooltip(\'tx_ameosgooglemap_drag\');\" />  <div id=\"tx_ameosgooglemap_drag\" class=\"tooltip\" style=\"display: none;\">   Pour d&eacute;placer la carte: Faites-la glisser &agrave; l\'aide de votre souris  </div>  <div class=\"clear\"></div> </div>  ',
		buttonZoomingHTMLDrag: '   <div class=\"tx-ameosgooglemap-drag\">  <img src=\"http://www.apave.com/typo3conf/ext/ameos_googlemap/res/images/drag_active.gif\" alt=\"\" onmouseover=\"showTooltip(\'tx_ameosgooglemap_drag\');\" onmouseout=\"hideTooltip(\'tx_ameosgooglemap_drag\');\" />  <div id=\"tx_ameosgooglemap_drag\" class=\"tooltip\" style=\"display: none;\">   Pour d&eacute;placer la carte: Faites-la glisser &agrave; l\'aide de votre souris  </div>  <div class=\"clear\"></div> </div>  ',
		stickyZoomEnabled: true
	};

	// set callback function, if needed
	var callbacks = {};

	// execute the zoom
	var dragZoomControl = new DragZoomControl(boxStyleOpts, otherOpts, callbacks);
	gmMap.addControl(dragZoomControl, 
		new GControlPosition(
			G_ANCHOR_TOP_LEFT, 
			new GSize(
				70, 
				10
			)
		)
	);
	
	switch (state) {
	case "zooming":
		gmMap.disableDoubleClickZoom();
		break;
	case "draging":
		gmMap.enableDoubleClickZoom();
		break;
	}
	dragZoomControl.setDragZoomMode(state);

	return;
}

// refresh the map: show the map with all markers on it
function refreshMap() {
	if (bSelectCats == "0") return;

	var aAllCats = document.getElementById("tx_ameosgooglemap_catchk").getElementsByTagName("input");
	for (i=0; i < aAllCats.length; i++) { 
		aAllCats[i].checked = "true";
	}

	makeMap();
}

// create a LINK marker for the map
function addLinkMarker(xmlMarker) {

	var lng = parseFloat(xmlMarker.getAttribute("lng"));
	var lat = parseFloat(xmlMarker.getAttribute("lat"));

	if ((lat == "0") || (lng == "0") ) {

		msgError = "";
		if (lat == "") {
			msgError = "the Latitude";
		}
		if (lng == "") {
			msgError = (msgError == "") ? "the Longitude" : msgError + " and the Longitude";
		}
		msgError = "You must set " + msgError + " for the country " + xmlMarker.getAttribute("title");
		alert(msgError);
		return;
	}

	var title = xmlMarker.getAttribute("title");
	var icon = xmlMarker.getAttribute("icon");

	var point = new GPoint(lng, lat);
	var marker = new GMarker(point, {
		"icon": gmIcons[icon], 
		"title": title
	});

	GEvent.addListener(
		marker, 
		"click", 
		function() {
			var uid = xmlMarker.getAttribute("uid");
			var searchUrl = "http://www.apave.com/nous-decouvrir/le-groupe/implantations/region/carte-region/gmfocus/carte-retour/130/carte-retour-zoom/country-53.html";
			searchUrl = searchUrl.replace(/gmfocus/, uid);
			window.location = searchUrl;
		}
	);
	gmMap.addOverlay(marker);
}

// create a INFO WINDOW marker for the map
function addInfosMarker(xmlMarker) {

	var lat = parseFloat(xmlMarker.getAttribute("lat"));
	var lng = parseFloat(xmlMarker.getAttribute("lng"));

	var cat = xmlMarker.getAttribute("cat");

	var trace = xmlMarker.getElementsByTagName("trace")[0];

	// construct the content of each marker tab
	var htmls = [];
	var labels = [];

	var tabs = xmlMarker.getElementsByTagName("htmls")[0];
	var content1 = GXml.value(xmlMarker.getElementsByTagName("html1")[0]);
	var content2 = GXml.value(xmlMarker.getElementsByTagName("html2")[0]);
	var content3 = GXml.value(xmlMarker.getElementsByTagName("html3")[0]);
	var content4 = GXml.value(xmlMarker.getElementsByTagName("html4")[0]);
	if (tabs.getAttribute("tab1") == "1" && content1) { 
		labels.push("Infos");
		htmls.push(content1);
	}
	if (tabs.getAttribute("tab2") == "1" && content2) { 
		labels.push("Contacts");
		htmls.push(content2);
	}
	if (tabs.getAttribute("tab3") == "1" && content3) { 
		labels.push("Accès");
		htmls.push(content3);
	}
	if (tabs.getAttribute("tab4") == "1" && content4) { 
		labels.push("Présentation");
		htmls.push(content4);
	}

	var title = xmlMarker.getAttribute("title");
	var icon = xmlMarker.getAttribute("icon");

	// generate the marker location and title
	var point = new GPoint(lng, lat);
	var marker = new GMarker(
		point, 
		{
			"icon": gmIcons[icon], 
			"title": title
		}
	);

	// generate the marker infos windows
	var tabs = [];
	for (var i=0; i < htmls.length; i++) {
		//htmls[i] = \'<div id="tx_ameosgooglemap_tab">\' + htmls[i] + \'</div>\';
		var oInfoWindow = new GInfoWindowTab(labels[i], htmls[i]);
		tabs.push(oInfoWindow);
	}


	// add the marker and marker tabs into global arrays for later use
	gmMarkers[k] = marker;
	gmMarkerTabs[k] = tabs;
	gmMarkerTrace[k] = trace;
	gmMarkerZipcode[xmlMarker.getAttribute("zipcode")] = k;
	gmMarkerAddress[xmlMarker.getAttribute("uid")] = k;
	k++;


	GEvent.addListener(
		marker, 
		"click", 
		function() {

			// set the page trace
			if (document.getElementById("tx-ameosgooglemap-trace")) {
				document.getElementById("tx-ameosgooglemap-trace").innerHTML = getMarkerTrace(trace);
			}

			// on click on the marker, open his tabbed window
			marker.openInfoWindowTabsHtml(tabs);
			//marker.openInfoWindowTabsHtml(tabs, {maxWidth:gmMap.getSize().width/2});
		}
	);


	GEvent.addListener(
		gmMap,
		"infowindowclose", 
		function() {
			if (document.getElementById("tx-ameosgooglemap-trace")) {
							document.getElementById("tx-ameosgooglemap-trace").innerHTML = " &raquo; Côte d'Ivoire";
			}
		}
	);


	// show or hide this marker function of category selection
	if (canShowMarker(cat) == "1") {
		gmMap.addOverlay(marker);
	} else {
		gmMap.removeOverlay(marker);
	}
}

// check if we can show this category: return TRUE, if this category must be displayed on map, either FALSE
function canShowMarker(catUid) {
	//if (typeof(catUid) == "undefined")
	if (bSelectCats == "0") return "1";

	var aCats = catUid.split(',');
	for (i=0; i < aCats.length; i++) { 
		if (aCats[i]=="" || document.getElementById("category_chk_" + aCats[i]).checked) {
			return "1";
		}
	}
	return "0";
}

// get the map trace
function getMarkerTrace(trace) {
	var sTrace = "";
	if (trace.getAttribute("country") != null) {
		sTrace += " &raquo; " + trace.getAttribute("country");
	}
	if (trace.getAttribute("region") != null) {
		sTrace += " &raquo; " + trace.getAttribute("region");
	}
	if (trace.getAttribute("department") != null) {
		sTrace += " &raquo; " + trace.getAttribute("department");
	}
	if (trace.getAttribute("city") != null) {
		sTrace += " &raquo; " + trace.getAttribute("city");
	}
	if (trace.getAttribute("agency") != null) {
		sTrace += " &raquo; " + trace.getAttribute("agency");
	}
	return sTrace;
}

// if there is a seach made, then execute the default search
function executeDefaultSearch() {

	var searchCode = "";
	if (searchCode != "") {
		new Ajax.Request(
			"/?eID=tx_ameosgooglemap_search", {
				method: 'get',
				asynchronous: false,
				parameters: {
					'searchType': 'zipcode',
					'searchText': searchCode
				},
				onSuccess: function (oResponse) {
					var sJSONtext = oResponse.responseText;
					if (sJSONtext.isJSON()) {
						var aJSON = sJSONtext.evalJSON(true);
						if (aJSON && !aJSON.data.zip.blank()) {
							searchMarker(aJSON.data.zip, 0, 0);
						} else {
							alert("Il n'y a aucun établissement en France correspondant au code postal recherché! Svp effectuez une autre recherche.");
						}
					}
				}
			}
		);
	}
}


// search the specified marker on the map and display it, if exists
function searchMarker(code, to, from) {
	
	// refresh the map, in order to have all the markers on map
	if (to == 0 && from == 0) {
		refreshMap();
	}

	// show the tabs infos of searched marker, if exists
	var idx = gmMarkerZipcode[code];
	if (gmMarkers[idx] && gmMarkerTabs[idx]) {
		
		// set the page trace
		document.getElementById("tx-ameosgooglemap-trace").innerHTML = getMarkerTrace(gmMarkerTrace[idx]);

		// show or hide gmDirections
		if (to == 1) {
			document.getElementById("tx_ameosgooglemap_gdirections_all").style.display = "none";
			document.getElementById("tx_ameosgooglemap_gdirections_to").style.display = "block";
			document.getElementById("tx_ameosgooglemap_gdirections_from").style.display = "none";
			document.getElementById("tx_ameosgooglemap_directions_to").style.display = "block";
			document.getElementById("tx_ameosgooglemap_directions_from").style.display = "none";
			try {document.getElementById("gmDirTo").focus();} catch(e) {}
		}
		if (from == 1) {
			document.getElementById("tx_ameosgooglemap_gdirections_all").style.display = "none";
			document.getElementById("tx_ameosgooglemap_gdirections_to").style.display = "none";
			document.getElementById("tx_ameosgooglemap_gdirections_from").style.display = "block";
			document.getElementById("tx_ameosgooglemap_directions_to").style.display = "none";
			document.getElementById("tx_ameosgooglemap_directions_from").style.display = "block";
			try {document.getElementById("gmDirTo").focus();} catch(e) {}
		}

		// open infos
		gmMarkers[idx].openInfoWindowTabsHtml(gmMarkerTabs[idx]);

	} else {

		// redirect to the search page with the searched zipcode
		redirectToSearchPage('zipcode');
	}
}

// execute the zoom on specified country, region, department, city....
function setMapZoom(sSearch) {

	//var sSearch = document.getElementById("tx_ameosgooglemap_" + sZoomType).value;
	if (typeof(gmcityfocus[sSearch]) != "undefined") {

		// set the page trace
					document.getElementById("tx-ameosgooglemap-trace").innerHTML = " &raquo; Côte d'Ivoire";
		document.getElementById("tx-ameosgooglemap-trace").innerHTML += " &raquo; " + sSearch;

		// center and zoom the map
		var aMapCenter = gmcityfocus[sSearch].split(",");
		gmMap.setCenter(
			new GLatLng(aMapCenter[0], aMapCenter[1]),
			aMapCenter[2]
		);

	} else {

		// redirect to the search page with the searched zipcode
		redirectToSearchPage('city');
	}
}

// print all the marker infos (all the infos from tabs)
function printMarkerInfos(addressUid) {

	var idx = gmMarkerAddress[addressUid];
	if (gmMarkers[idx] && gmMarkerTabs[idx]) {

		// get the marker tabs infos to print
		var tabs = gmMarkerTabs[idx];
		var res = [];
		res.push("<h2 class='header'>Informations sur l'établissement APAVE</h2>");
		res.push("<h3 class='trace'>" + document.getElementById("tx-ameosgooglemap-trace").innerHTML + "</h3>");
		for (var i=0; i < tabs.length; i++) {
			if (i != 2) {
				res.push("<h3>" + tabs[i].name + "</h3>"); 
				res.push(tabs[i].contentElem.innerHTML);
			}
		}

		// open the content to print into new window
		window.googlemapMarkersContent = res.join("<br />");
		window.open(
			"http://www.apave.com/fileadmin/templates/v1/template-implantations-print.html", 
			"myWin",
			"toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, width=800, height=600"
		);

		return false;
	}
}

// search direction for the selected point
function searchDirection() {
	gdir.load(
		"from: " + document.getElementById("tx_ameosgooglemap_fromaddress").innerHTML + 
		" to: " + document.getElementById("tx_ameosgooglemap_toaddress").innerHTML,
		{ "locale": document.getElementById("tx_ameosgooglemap_lang").innerHTML }
	);

	return false;
}

// search direction from the selected point
function setDirectionFromHere(fromAddress, fromPoint, toAddress, lang) {
	fromAddress = unescape(fromAddress);
	document.getElementById("tx_ameosgooglemap_fromaddress").innerHTML = fromAddress;
	document.getElementById("tx_ameosgooglemap_toaddress").innerHTML = toAddress;
	gmMap.getInfoWindow().hide();
	document.getElementById("tx_ameosgooglemap_direction").style.display = "block";
	
	var aPoint = fromPoint.split(",");
	var point = new GLatLng(aPoint[0], aPoint[1]);
	gdir.load(
		"from: " + point.toUrlValue(6) + " to: " + toAddress,
		{ "locale": lang }
	);

	return false;
}

// search direction to the selected point
function setDirectionToHere(fromAddress, toAddress, toPoint, lang) {
	toAddress = unescape(toAddress);
	document.getElementById("tx_ameosgooglemap_fromaddress").innerHTML = fromAddress;
	document.getElementById("tx_ameosgooglemap_toaddress").innerHTML = toAddress;
	gmMap.getInfoWindow().hide();
	document.getElementById("tx_ameosgooglemap_direction").style.display = "block";
	
	var aPoint = toPoint.split(",");
	var point = new GLatLng(aPoint[0], aPoint[1]);
	gdir.load(
		"from: " + fromAddress + " to: " + point.toUrlValue(6),
		{ "locale": lang }
	);

	return false;
}

// do something on gdirection load
function onGDirectionsLoad() { 

	// Use this function to access information about the latest load()
	// results.

	// e.g.
	// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
}

// get an error trace when the gdirection was failed out
function onGDirectionError() {

	switch(gdir.getStatus().code) {

	case G_GEO_SERVER_ERROR:
		alert("Google Map: Impossible de traiter la demande en raison d'un motif inconnu.");
		break;

	case G_GEO_MISSING_ADDRESS:  
		alert("Google Map: Format d'adresse invalide ou adresse manquante.");
		break;

	case G_GEO_UNKNOWN_ADDRESS:
		alert("Google Map: Adresse inconnue.");
		break;

	case G_GEO_BAD_KEY:
		alert("Google Map: Clé invalide pour le site.");
		break;

	default:
		alert("Google Map: Impossible de trouver l'emplacement.");
	}
}

// show tooltip
function showTooltip(tooltip) {
	document.getElementById(tooltip).style.display = "block";
}

// hide tooltip
function hideTooltip(tooltip) {
	document.getElementById(tooltip).style.display = "none";
}

