/**
 * Trigger de modification DOM, manipulation d'element
 * @param event
 * @param option
 * @return
 */
var majDOM = function (event, option) {
	if(		option['objMap'] != null && option['idGmap'] != null &&
			option['id'] 	 != null && option['x']	 	 != null &&
		    option['y'] 	 != null && option['z'] 	 != null) {
		ShowMap(option['objMap'],
				option['idGmap'],
				option['id'],
				option['x'],
				option['y'],
				option['z']);
				option['objMap'].gmap.checkResize();
	} else if ( option['idGmap'] != null && option['id'] != null) {
		HideMap(option['idGmap'],option['id']);
	}
};

/**
 * Trigger de mise a� jour de formulaire
 * @param event
 * @param name
 * @param id
 */
var majForm = function (event, name, id, option)
{
	if(typeof(option['minZoom']) == 'undefined') {
		option['minZoom'] = 16;
	}
	if(option['zoom'] != null) {
		hideShowRadioBtPoiCaption(option['zoom'], option['current'], option['filter'], option['minZoom']);
	}
};

/**
 * Trigger de mise a jour de la carto
 * @param event
 * @param name
 * @param id
 */
var majMap = function(event, name, id, option)
{
	/* --- Recupere l'objet GMap --- */
	var mapObj;
	if(option['gmap'] != null) {
		mapObj = option['gmap'];
	}

	/* --- Genere les StopArea depuis KML */
	if(name == 'stopAreaKml') {
		mapObj.DrawKmlStopAreas(name, option);
	}

	/* --- Genere les markers des villes a l'echelle regionale --- */
	if(name == 'cityRegionKml') {
		mapObj.DrawMarkerCity(name, option);
	}

	/* --- Genere les markers des villes a l'echelle departementale --- */
	if(name == 'cityDeptKml') {
		mapObj.DrawMarkerCity(name, option);
	}

	if(typeof(option['zoom']) == 'number' && option['ezp_kml'] == true) {
		for(var i = 0 ; i < mapObj.kmlManager.length; i++)
			mapObj.DrawKmlMap(i, option);
	}
		

	/* --- Genere les POIS --- */
	/*if(mapObj.clusterManager[name] == null && id.indexOf('afficher') != -1){
		mapObj.DrawMarkerSite(name, option);
	} else if (mapObj.clusterManager[name] != "undefined" && mapObj.clusterManager[name] != null) {
		if(id.indexOf('afficher') != -1) {
			mapObj.clusterManager[name].showAllMarkers();
		} else if (id.indexOf('masquer') != -1) {
			mapObj.clusterManager[name].hideAllMarkers();
		}
	}*/
	
	/* --- Affiche / Masque les StopArea selon le zoom --- */
	if(name == 'stopAreaZoomAdapt') {
		if(typeof(mapObj.clusterManager['stopAreaKml']) == "object") {
			if(option['zoom'] >= 14) {
				mapObj.clusterManager['stopAreaKml'].showAllMarkers();
			} else {
				mapObj.clusterManager['stopAreaKml'].hideAllMarkers();
			}
		}
	}

	/* --- Affiche / Masque les POIS selon le zoom --- */
	if(name == 'poiZoomAdapt') {
		if(option['zoom'] >= option['minZoom'] && option['zoom'] <= option['maxZoom']) {
			if (mapObj.clusterManager['poiItineraire'] != null)  {
				mapObj.clusterManager['poiItineraire'].showAllMarkers();
			}
		} else {
			var filter = null;
			if(option['filter'] != null)
				filter = 'poi' + option['filter'];
			for(var i in mapObj.clusterManager) {
				if (i != 'in_array' &&  i != 'stopAreaKml' && ((filter != null && filter.indexOf(i) == -1) || filter == null)) {
					if (typeof(mapObj.clusterManager[i].hideAllMarkers) != 'undefined') {
						mapObj.clusterManager[i].hideAllMarkers();
					}
				}
			}
		}
	}
	
	/* --- Affiche / Masque les City selon le zoom --- */
	if(name == 'cityZoomAdapt') {
		if(typeof(option['zoom']) != "number" || typeof(option['minZoom']) != "number" || typeof(option['maxZoom']) != "number") {
			return false;
		} else {
			if(option['zoom'] >= option['minZoom'] && option['zoom'] <= option['maxZoom']) {
				//mapObj.clusterManager[id].showAllMarkers();
			}
			else {
				// [TNY] Question : c'est pas censé être "hideAllMarkers" ici ?
				//mapObj.clusterManager[id].showAllMarkers();
			}
			return true;
		}
	}
	
	if(name == 'kmlHybride') {
		mapObj.DrawKmlHybride(id, option);	
	}
	
	if(name == 'zoomTo') {
		if(typeof(option['value']) != "number") {
			return false;
		} else {
			if(option['value'] >= option['minZoom'] && option['value'] <= option['maxZoom'])
				mapObj.MapZoom(option['value']);
			 else
				mapObj.MapZoom(16);
			return true;
		}
	}

	/* Affichage du point de recherche et ses arrêts à proximité */
	if(name == 'proximityMarker' && option['coordJsTab'] != null) {
		mapObj.DrawProximityMarker(option['coordJsTab']);
	}
};

/**
 * Trigger recherche de lieu/commune (carte interactive)
 * @param event
 * @param mapObj
 * @param options
 */
var LocalitySearch = function(event,mapObj,options)
{
	mapObj.LocalitySearch(options);
}


