// JavaScript Document

var updateGooglemapMarkersByLocalisation = function (googlemapObject, departementId){
	departementId = (undefined) ? null : departementId;
	
	googlemapObject.deleteMarkers();
	
	var url_get_googlemap_agence_markers = '/pl/googlemap_markers_agences_json.pl';
	var params = {'lg': shoppingLgString};
	
	if (departementId){
		params.d = departementId;
	} else {
		if ($('departements_agences')){
			if ($('departements_agences').value){
				params.d = $('departements_agences').value;
			}
		}
	}
	
	var jsonRequest = new Request.JSON({
		url: url_get_googlemap_agence_markers, 
		onSuccess: function(responseJSON, responseText){
			var markersArray = new Array();
			
			for(i=0;i<responseJSON.length;i++){
				currentMarker = new GooglemapMarker(responseJSON[i]['ag_gm_lat'], responseJSON[i]['ag_gm_lng']);
				currentMarker.setId(responseJSON[i]['ag_id']);
				currentMarker.setTitle(responseJSON[i]['ag_name']);
				currentMarker.setImage(markerImage);
				currentMarker.setShadow(markerShadow);
				currentMarker.setShape(markerShape);
				markersArray.push(currentMarker);
				
				var markerContent = '';
				markerContent += '<div style="width:310px;padding-right:7px;">';
				if (responseJSON[i]['ag_picture_listing']){
					markerContent += '<img src="/images/upload/agences/listing/'+responseJSON[i]['ag_picture_listing']+'" style="float:left;padding-right:10px;"/>';
				}
				markerContent += '<div style="float:left;width:200px;">'
				markerContent += '<span style="font-family:tahoma;font-size:14px;">'+responseJSON[i]['ag_name']+'</span>';
				markerContent += '<span style="font-family:tahoma;font-size:12px;color:#333;">';
				if (responseJSON[i]['ag_adresse_1']){
					markerContent += '<br>'+responseJSON[i]['ag_adresse_1'];
				}
				if (responseJSON[i]['ag_adresse_2']){
					markerContent += '<br>'+responseJSON[i]['ag_adresse_1'];
				}
				if (responseJSON[i]['ag_code_postal'] || responseJSON[i]['ag_ville']){
					markerContent += '<br>';
				}
				if (responseJSON[i]['ag_code_postal']){
					markerContent += responseJSON[i]['ag_code_postal'];
				}
				if (responseJSON[i]['ag_code_postal'] && responseJSON[i]['ag_ville']){
					markerContent += ', ';
				}
				if (responseJSON[i]['ag_ville']){
					markerContent += responseJSON[i]['ag_ville'];
				}
				if (responseJSON[i]['ag_tel']){
					markerContent += '<br>Tél : '+responseJSON[i]['ag_tel'];
				}
				if (responseJSON[i]['ag_fax']){
					markerContent += '<br>Fax : '+responseJSON[i]['ag_fax'];
				}
				markerContent += '<br><div onclick="window.location.href=\'/pl/agences.pl?itm='+responseJSON[i]['ag_id']+'\'" style="text-decoration:none;color:#666;cursor:pointer;">&rsaquo; Plus d\'informations</div>';
				markerContent += '</span>';
				markerContent += '</div>';
				markerContent += '</div>';
				
				currentMarker.setContent(markerContent);				
			}
			
			googlemapObject.setMarkers(markersArray);
			googlemapObject.addMarkers(true);
		}
	}).get(params);
}
