Subversion Repositories eFlore/Applications.cel

Rev

Rev 1091 | Rev 1151 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1091 Rev 1107
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
// Mettre à true pour afficher les messages de débogage
3
// Mettre à true pour afficher les messages de débogage
4
var DEBUG = false; 
4
var DEBUG = false; 
5
/**
5
/**
6
 * Indication de certaines variables ajoutée par php
6
 * Indication de certaines variables ajoutée par php
7
* var communeImageUrl ;
7
* var communeImageUrl ;
8
* var pointImageUrl ;
8
* var pointImageUrl ;
9
* var groupeImageUrlTpl ;
9
* var groupeImageUrlTpl ;
10
*/
10
*/
11
var pointsOrigine = null;
11
var pointsOrigine = null;
12
var boundsOrigine = null;
12
var boundsOrigine = null;
13
var markerClusterer = null;
13
var markerClusterer = null;
14
var map = null;
14
var map = null;
15
var infoBulle = new google.maps.InfoWindow();
15
var infoBulle = new google.maps.InfoWindow();
16
var stations = null;
16
var stations = null;
17
var pointClique = null;
17
var pointClique = null;
18
var carteCentre = new google.maps.LatLng(25, 10);
18
var carteCentre = new google.maps.LatLng(25, 10);
19
var carteOptions = {
19
var carteOptions = {
20
	zoom: 3,
20
	zoom: 3,
21
	center:carteCentre,
21
	center:carteCentre,
22
	mapTypeId: google.maps.MapTypeId.ROADMAP,
22
	mapTypeId: google.maps.MapTypeId.ROADMAP,
23
	mapTypeControlOptions: {
23
	mapTypeControlOptions: {
24
		mapTypeIds: ['OSM', 
24
		mapTypeIds: ['OSM', 
25
		             google.maps.MapTypeId.ROADMAP, 
25
		             google.maps.MapTypeId.ROADMAP, 
26
		             google.maps.MapTypeId.HYBRID, 
26
		             google.maps.MapTypeId.HYBRID, 
27
		             google.maps.MapTypeId.SATELLITE, 
27
		             google.maps.MapTypeId.SATELLITE, 
28
		             google.maps.MapTypeId.TERRAIN]
28
		             google.maps.MapTypeId.TERRAIN]
29
	}
29
	}
30
};			
30
};			
31
var osmMapType = new google.maps.ImageMapType({
31
var osmMapType = new google.maps.ImageMapType({
32
	getTileUrl: function(coord, zoom) {
32
	getTileUrl: function(coord, zoom) {
33
		return "http://tile.openstreetmap.org/" +
33
		return "http://tile.openstreetmap.org/" +
34
		zoom + "/" + coord.x + "/" + coord.y + ".png";
34
		zoom + "/" + coord.x + "/" + coord.y + ".png";
35
	},
35
	},
36
	tileSize: new google.maps.Size(256, 256),
36
	tileSize: new google.maps.Size(256, 256),
37
	isPng: true,
37
	isPng: true,
38
	alt: "OpenStreetMap",
38
	alt: "OpenStreetMap",
39
	name: "OSM",
39
	name: "OSM",
40
	maxZoom: 19
40
	maxZoom: 19
41
});
41
});
42
var ctaLayer = null;
42
var ctaLayer = null;
43
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
43
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
44
var station = {'commune':'', 'obsNbre':0};
44
var station = {'commune':'', 'obsNbre':0};
45
var obsStation = new Array();
45
var obsStation = new Array();
46
var obsPage = new Array();
46
var obsPage = new Array();
47
var taxonsCarte = new Array();
47
var taxonsCarte = new Array();
48
var mgr = null;
48
var mgr = null;
49
var marqueursCache = new Array();
49
var marqueursCache = new Array();
50
var zonesCache = new Array();
50
var zonesCache = new Array();
51
var requeteChargementPoints;
51
var requeteChargementPoints;
52
/*+--------------------------------------------------------------------------------------------------------+*/
52
/*+--------------------------------------------------------------------------------------------------------+*/
53
// INITIALISATION DU CODE
53
// INITIALISATION DU CODE
54
 
54
 
55
//Déclenchement d'actions quand JQuery et le document HTML sont OK
55
//Déclenchement d'actions quand JQuery et le document HTML sont OK
56
$(document).ready(function() {
56
$(document).ready(function() {
57
	initialiserWidget();
57
	initialiserWidget();
58
});
58
});
59
 
59
 
60
function initialiserWidget() {
60
function initialiserWidget() {
61
	definirTailleTitre();
61
	definirTailleTitre();
62
	initialiserAffichageCarte();
62
	initialiserAffichageCarte();
63
	initialiserAffichagePanneauLateral();
63
	initialiserAffichagePanneauLateral();
64
	initialiserCarte();
64
	initialiserCarte();
65
	initialiserGestionnaireMarqueurs()
65
	initialiserGestionnaireMarqueurs()
66
	initialiserInfoBulle();
66
	initialiserInfoBulle();
67
	initialiserFormulaireContact();
67
	initialiserFormulaireContact();
68
	chargerLimitesCommunales();
68
	chargerLimitesCommunales();
69
	attribuerListenerCarte();
69
	attribuerListenerCarte();
70
	programmerRafraichissementCarte();
70
	programmerRafraichissementCarte();
71
}
71
}
72
 
72
 
73
/*+--------------------------------------------------------------------------------------------------------+*/
73
/*+--------------------------------------------------------------------------------------------------------+*/
74
// AFFICHAGE GÉNÉRAL
74
// AFFICHAGE GÉNÉRAL
75
 
75
 
76
function afficherTitreCarte() {
76
function afficherTitreCarte() {
77
	if (stations != null && taxonsCarte.length > 0) {
77
	if (stations != null && taxonsCarte.length > 0) {
78
		var obsNbre = stations.stats.observations;
78
		var obsNbre = stations.stats.observations;
79
		var obsNbreFormate = stations.stats.observations.formaterNombre();
79
		var obsNbreFormate = stations.stats.observations.formaterNombre();
80
		var plteNbre = taxonsCarte.length;
80
		var plteNbre = taxonsCarte.length;
81
		var plteNbreFormate = taxonsCarte.length.formaterNombre();
81
		var plteNbreFormate = taxonsCarte.length.formaterNombre();
82
		var communeNbre = stations.stats.communes;
82
		var communeNbre = stations.stats.communes;
83
		var communeNbreFormate = stations.stats.communes.formaterNombre();
83
		var communeNbreFormate = stations.stats.communes.formaterNombre();
84
	
84
	
85
		var titre = obsNbreFormate+' observation';
85
		var titre = obsNbreFormate+' observation';
86
		titre += (obsNbre > 1) ? 's' : '' ;
86
		titre += (obsNbre > 1) ? 's' : '' ;
87
		
87
		
88
		if (nt == '*') {
88
		if (nt == '*') {
89
			titre += ' de '+plteNbreFormate+' plante';
89
			titre += ' de '+plteNbreFormate+' plante';
90
			titre += (plteNbre > 1) ? 's' : '' ;
90
			titre += (plteNbre > 1) ? 's' : '' ;
91
		} else {
91
		} else {
92
			if (taxonsCarte[0]) {
92
			if (taxonsCarte[0]) {
93
				var taxon = taxonsCarte[0];
93
				var taxon = taxonsCarte[0];
94
				titre += ' pour '+taxon.nom;
94
				titre += ' pour '+taxon.nom;
95
			}
95
			}
96
		}
96
		}
97
		
97
		
98
		titre += ' sur '+communeNbreFormate+' commune';
98
		titre += ' sur '+communeNbreFormate+' commune';
99
		titre += (communeNbre > 1) ? 's' : '' ;
99
		titre += (communeNbre > 1) ? 's' : '' ;
100
		
100
		
101
		$('#carte-titre-infos').text(titre);
101
		$('#carte-titre-infos').text(titre);
102
	}
102
	}
103
}
103
}
104
 
104
 
105
function definirTailleTitre() {
105
function definirTailleTitre() {
106
	var largeurViewPort = $(window).width();
106
	var largeurViewPort = $(window).width();
107
	var taille = null;
107
	var taille = null;
108
	if (largeurViewPort < 400) {
108
	if (largeurViewPort < 400) {
109
		taille = '0.8';
109
		taille = '0.8';
110
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
110
	} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
111
		taille = '1.0';
111
		taille = '1.0';
112
	} else if (largeurViewPort >= 800) {
112
	} else if (largeurViewPort >= 800) {
113
		taille = '1.6';
113
		taille = '1.6';
114
	}
114
	}
115
	$("#carte-titre").css('font-size', taille+'em');
115
	$("#carte-titre").css('font-size', taille+'em');
116
}
116
}
117
 
117
 
118
/*+--------------------------------------------------------------------------------------------------------+*/
118
/*+--------------------------------------------------------------------------------------------------------+*/
119
// CARTE
119
// CARTE
120
 
120
 
121
function initialiserAffichageCarte() {
121
function initialiserAffichageCarte() {
122
	$('#carte').height($(window).height() - 35);
122
	$('#carte').height($(window).height() - 35);
123
	$('#carte').width($(window).width() - 24);
123
	$('#carte').width($(window).width() - 24);
124
 
124
 
125
	if (nt != '*') {
125
	if (nt != '*') {
126
		$('#carte').css('left', 0);
126
		$('#carte').css('left', 0);
127
	}
127
	}
128
}
128
}
129
 
129
 
130
function initialiserCarte() {
130
function initialiserCarte() {
131
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
131
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
132
	// Ajout de la couche OSM à la carte
132
	// Ajout de la couche OSM à la carte
133
	map.mapTypes.set('OSM', osmMapType);
133
	map.mapTypes.set('OSM', osmMapType);
134
}
134
}
135
 
135
 
136
function initialiserGestionnaireMarqueurs() {
136
function initialiserGestionnaireMarqueurs() {
137
	mgr = new MarkerManager(map);
137
	mgr = new MarkerManager(map);
138
}
138
}
139
 
139
 
140
function chargerLimitesCommunales() {
140
function chargerLimitesCommunales() {
141
	if (urlsLimitesCommunales != null) {
141
	if (urlsLimitesCommunales != null) {
142
		for (urlId in urlsLimitesCommunales) { 
142
		for (urlId in urlsLimitesCommunales) { 
143
			var url = urlsLimitesCommunales[urlId];
143
			var url = urlsLimitesCommunales[urlId];
144
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: false});
144
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
145
			ctaLayer.setMap(map);
145
			ctaLayer.setMap(map);
146
		}
146
		}
147
	}
147
	}
148
}
148
}
149
 
149
 
150
var listener = null;
150
var listener = null;
151
var timer = null;
151
var timer = null;
152
function attribuerListenerCarte() {
152
function attribuerListenerCarte() {
153
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
153
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
154
		programmerRafraichissementCarte();
154
		programmerRafraichissementCarte();
155
	});
155
	});
156
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
156
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
157
		programmerRafraichissementCarte();
157
		programmerRafraichissementCarte();
158
	});
158
	});
159
}
159
}
160
function programmerRafraichissementCarte() {
160
function programmerRafraichissementCarte() {
161
	if(timer != null) {
161
	if(timer != null) {
162
        window.clearTimeout(timer);
162
        window.clearTimeout(timer);
163
    }
163
    }
164
	if(requeteChargementPoints != null) {
164
	if(requeteChargementPoints != null) {
165
		requeteChargementPoints.abort();
165
		requeteChargementPoints.abort();
166
	}
166
	}
167
	timer = window.setTimeout(function() {
167
	timer = window.setTimeout(function() {
168
		var zoom = map.getZoom();
168
		var zoom = map.getZoom();
169
		var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(map.getBounds().getNorthEast().lng());
169
		var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(map.getBounds().getNorthEast().lng());
170
		var SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(map.getBounds().getSouthWest().lng());
170
		var SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(map.getBounds().getSouthWest().lng());
171
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
171
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
172
    }, 400);		
172
    }, 400);		
173
}
173
}
174
 
174
 
175
var marqueurs = new Array();
175
var marqueurs = new Array();
176
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
176
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
177
	var url = stationsUrl+
177
	var url = stationsUrl+
178
		'&zoom='+zoom+
178
		'&zoom='+zoom+
179
		'&ne='+NELatLng+
179
		'&ne='+NELatLng+
180
		'&sw='+SWLatLng;
180
		'&sw='+SWLatLng;
181
	
181
	
182
	if(infoBulleOuverte) {
182
	if(infoBulleOuverte) {
183
		return;
183
		return;
184
	}
184
	}
185
	
185
	
186
	if(requeteChargementPoints != null) {
186
	if(requeteChargementPoints != null) {
187
		requeteChargementPoints.abort();
187
		requeteChargementPoints.abort();
188
		cacherMessageChargementPoints();
188
		cacherMessageChargementPoints();
189
	}
189
	}
190
	
190
	
191
	afficherMessageChargementPoints();
191
	afficherMessageChargementPoints();
192
	requeteChargementPoints = $.getJSON(url, function(data) {
192
	requeteChargementPoints = $.getJSON(url, function(data) {
193
		rafraichirMarqueurs(data);
193
		rafraichirMarqueurs(data);
194
		cacherMessageChargementPoints();
194
		cacherMessageChargementPoints();
195
	});
195
	});
196
}
196
}
197
 
197
 
198
function afficherMessageChargementPoints() {
198
function afficherMessageChargementPoints() {
199
	$('#zone-chargement-point').css('display','block');
199
	$('#zone-chargement-point').css('display','block');
200
}
200
}
201
 
201
 
202
function cacherMessageChargementPoints() {
202
function cacherMessageChargementPoints() {
203
	$('#zone-chargement-point').css('display','none');
203
	$('#zone-chargement-point').css('display','none');
204
}
204
}
-
 
205
 
-
 
206
premierChargement = true;
205
 
207
 
206
function rafraichirMarqueurs(data) {
208
function rafraichirMarqueurs(data) {
207
	$.each(marqueurs, function(index, marqueur) {
209
	$.each(marqueurs, function(index, marqueur) {
208
		marqueur.setMap(null);
210
		marqueur.setMap(null);
209
	});
211
	});
210
	marqueurs = new Array();
212
	marqueurs = new Array();
211
	
213
	
212
	stations = data;
214
	stations = data;
213
	afficherTitreCarte();
215
	afficherTitreCarte();
214
	
216
	
215
	$.each(stations.points, function (index, station) {		
217
	$.each(stations.points, function (index, station) {		
216
		if(station != null) {
218
		if(station != null) {
217
			var nouveauMarqueur = creerMarqueur(station);
219
			var nouveauMarqueur = creerMarqueur(station);
218
			marqueurs.push(nouveauMarqueur);
220
			marqueurs.push(nouveauMarqueur);
219
		}
221
		}
220
	});
222
	});
-
 
223
	
-
 
224
	if(premierChargement) {
-
 
225
		premierChargement = false;
-
 
226
		var bounds = new google.maps.LatLngBounds();
-
 
227
		var latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax);
-
 
228
		var latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
-
 
229
		bounds.extend(latMax);
-
 
230
		bounds.extend(latMin);
-
 
231
		rendrePointsVisibles(bounds);	
-
 
232
	}
221
}
233
}
222
 
234
 
223
function creerMarqueur(station) {
235
function creerMarqueur(station) {
224
	var titre = '';
236
	var titre = '';
225
	if(station.nbreMarqueur) {
237
	if(station.nbreMarqueur) {
226
		titre = station.nbreMarqueur+' points renseignés';
238
		titre = station.nbreMarqueur+' points renseignés';
227
	} else {
239
	} else {
228
		if(station.nom) {
240
		if(station.nom) {
229
			titre = station.nom;
241
			titre = station.nom;
230
		}
242
		}
231
	}
243
	}
232
	//var titre = station['nbreMarqueur'];
244
	//var titre = station['nbreMarqueur'];
233
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
245
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
234
	var latLng = new google.maps.LatLng(station['lat'], station['lng']);
246
	var latLng = new google.maps.LatLng(station['lat'], station['lng']);
235
	var marqueur = new google.maps.Marker({
247
	var marqueur = new google.maps.Marker({
236
		position: latLng,
248
		position: latLng,
237
		icon: icone,
249
		icon: icone,
238
		title: ''+titre,
250
		title: ''+titre,
239
		map: map,
251
		map: map,
240
		stationInfos: station
252
		stationInfos: station
241
	});
253
	});
242
	attribuerListenerClick(marqueur, station['id']);
254
	attribuerListenerClick(marqueur, station['id']);
243
	marqueur.setMap(map);
255
	marqueur.setMap(map);
244
    return marqueur;
256
    return marqueur;
245
}
257
}
246
 
258
 
247
function rendrePointsVisibles(bounds) {
259
function rendrePointsVisibles(bounds) {
248
	map.setCenter(bounds.getCenter());
260
	map.setCenter(bounds.getCenter());
249
	map.fitBounds(bounds);
261
	map.fitBounds(bounds);
250
	map.panToBounds(bounds);
262
	map.panToBounds(bounds);
251
}
263
}
252
 
264
 
253
function programmerRafraichissementCarteSauv() {
265
function programmerRafraichissementCarteSauv() {
254
	
266
	
255
	var points = [];
267
	var points = [];
256
	var bounds = new google.maps.LatLngBounds();
268
	var bounds = new google.maps.LatLngBounds();
257
	for (var i = 0; i < stations.points.length; ++i) {
269
	for (var i = 0; i < stations.points.length; ++i) {
258
		var point = stations.points[i];
270
		var point = stations.points[i];
259
		var maLatLng = new google.maps.LatLng(point.lat, point.lng);
271
		var maLatLng = new google.maps.LatLng(point.lat, point.lng);
260
		var stationImage = attribuerImageMarqueur(point.id); 
272
		var stationImage = attribuerImageMarqueur(point.id); 
261
		var point = new google.maps.Marker({
273
		var point = new google.maps.Marker({
262
			position: maLatLng,
274
			position: maLatLng,
263
			map: map,
275
			map: map,
264
			icon: stationImage,
276
			icon: stationImage,
265
			stationInfos: point
277
			stationInfos: point
266
		});
278
		});
267
		bounds.extend(maLatLng);
279
		bounds.extend(maLatLng);
268
		google.maps.event.addListener(point, 'click', surClickMarqueur);
280
		google.maps.event.addListener(point, 'click', surClickMarqueur);
269
		points.push(point);
281
		points.push(point);
270
	}
282
	}
271
 
283
 
272
	if (pointsOrigine == null && boundsOrigine == null) {
284
	if (pointsOrigine == null && boundsOrigine == null) {
273
		pointsOrigine = points;
285
		pointsOrigine = points;
274
		boundsOrigine = bounds;
286
		boundsOrigine = bounds;
275
	}
287
	}
276
	
288
	
277
	executerMarkerClusterer(points, bounds);
289
	executerMarkerClusterer(points, bounds);
278
}
290
}
279
 
291
 
280
function attribuerImageMarqueur(id, nbreMarqueur) {
292
function attribuerImageMarqueur(id, nbreMarqueur) {
281
	var marqueurImage = null;
293
	var marqueurImage = null;
282
	if (etreMarqueurCommune(id)) {
294
	if (etreMarqueurCommune(id)) {
283
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
295
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
284
	} else if (etreMarqueurStation(id)) {
296
	} else if (etreMarqueurStation(id)) {
285
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
297
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
286
	} else if (etreMarqueurGroupe(id)) {
298
	} else if (etreMarqueurGroupe(id)) {
287
		var type = 0;
299
		var type = 0;
288
		var largeur = 0;
300
		var largeur = 0;
289
		var hauteur = 0;
301
		var hauteur = 0;
290
		if (nbreMarqueur != null) {
302
		if (nbreMarqueur != null) {
291
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
303
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
292
				type = '1';
304
				type = '1';
293
				largeur = 53;
305
				largeur = 53;
294
				hauteur = 52;
306
				hauteur = 52;
295
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
307
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
296
				type = '2';
308
				type = '2';
297
				largeur = 56;
309
				largeur = 56;
298
				hauteur = 55;
310
				hauteur = 55;
299
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
311
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
300
				type = '3';
312
				type = '3';
301
				largeur = 66;
313
				largeur = 66;
302
				hauteur = 65;
314
				hauteur = 65;
303
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
315
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
304
				type = '4';
316
				type = '4';
305
				largeur = 78;
317
				largeur = 78;
306
				hauteur = 77;
318
				hauteur = 77;
307
			} else if (nbreMarqueur >= 20000) {
319
			} else if (nbreMarqueur >= 20000) {
308
				type = '5';
320
				type = '5';
309
				largeur = 66;
321
				largeur = 66;
310
				hauteur = 65;
322
				hauteur = 65;
311
			}
323
			}
312
		}
324
		}
313
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
325
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
314
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
326
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
315
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
327
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
316
	}
328
	}
317
	return marqueurImage
329
	return marqueurImage
318
}
330
}
319
 
331
 
320
function attribuerListenerClick(marqueur, id) {
332
function attribuerListenerClick(marqueur, id) {
321
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
333
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
322
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
334
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
323
	} else if (etreMarqueurGroupe(id)) {
335
	} else if (etreMarqueurGroupe(id)) {
324
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
336
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
325
	}
337
	}
326
}
338
}
327
 
339
 
328
function surClickMarqueur(event) {
340
function surClickMarqueur(event) {
329
 
341
 
330
	if(infoBulleOuverte) {
342
	if(infoBulleOuverte) {
331
	    infoBulle.close();
343
	    infoBulle.close();
332
	}
344
	}
333
  
345
  
334
	pointClique = this;
346
	pointClique = this;
335
	infoBulle.open(map, this);
347
	infoBulle.open(map, this);
336
	actualiserPagineur();
348
	actualiserPagineur();
337
	
349
	
338
	var limites = map.getBounds();
350
	var limites = map.getBounds();
339
	var centre = limites.getCenter();
351
	var centre = limites.getCenter();
340
	var nordEst = limites.getNorthEast();
352
	var nordEst = limites.getNorthEast();
341
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
353
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
342
	map.panTo(centreSudLatLng);
354
	map.panTo(centreSudLatLng);
343
	
355
	
344
	afficherInfoBulle();
356
	afficherInfoBulle();
345
}
357
}
346
 
358
 
347
function surClickGroupe() {
359
function surClickGroupe() {
348
	map.setCenter(this.getPosition());
360
	map.setCenter(this.getPosition());
349
	var nouveauZoom = map.getZoom() + 2;
361
	var nouveauZoom = map.getZoom() + 2;
350
	map.setZoom(nouveauZoom);
362
	map.setZoom(nouveauZoom);
351
	mgr.clearMarkers();
363
	mgr.clearMarkers();
352
}
364
}
353
 
365
 
354
function etreMarqueurGroupe(id) {
366
function etreMarqueurGroupe(id) {
355
	var groupe = false;
367
	var groupe = false;
356
	var motif = /^GROUPE/;
368
	var motif = /^GROUPE/;
357
	if (motif.test(id)) {
369
	if (motif.test(id)) {
358
		groupe = true;
370
		groupe = true;
359
	}
371
	}
360
	return groupe;
372
	return groupe;
361
}
373
}
362
 
374
 
363
function etreMarqueurCommune(id) {
375
function etreMarqueurCommune(id) {
364
	var commune = false;
376
	var commune = false;
365
	var motif = /^COMMUNE:/;
377
	var motif = /^COMMUNE:/;
366
	if (motif.test(id)) {
378
	if (motif.test(id)) {
367
		commune = true;
379
		commune = true;
368
	}
380
	}
369
	return commune;
381
	return commune;
370
}
382
}
371
 
383
 
372
function etreMarqueurStation(id) {
384
function etreMarqueurStation(id) {
373
	var station = false;
385
	var station = false;
374
	var motif = /^STATION:/;
386
	var motif = /^STATION:/;
375
	if (motif.test(id)) {
387
	if (motif.test(id)) {
376
		station = true;
388
		station = true;
377
	}
389
	}
378
	return station;
390
	return station;
379
}
391
}
380
 
392
 
381
function deplacerCarteSurPointClique() {
393
function deplacerCarteSurPointClique() {
382
	map.panTo(pointClique.position);
394
	map.panTo(pointClique.position);
383
}
395
}
384
 
396
 
385
function executerMarkerClusterer(points, bounds) {
397
function executerMarkerClusterer(points, bounds) {
386
	if (markerClusterer) {
398
	if (markerClusterer) {
387
		markerClusterer.clearMarkers();
399
		markerClusterer.clearMarkers();
388
	}
400
	}
389
	markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
401
	markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
390
	map.fitBounds(bounds);
402
	map.fitBounds(bounds);
391
}
403
}
392
 
404
 
393
/*+--------------------------------------------------------------------------------------------------------+*/
405
/*+--------------------------------------------------------------------------------------------------------+*/
394
// INFO BULLE
406
// INFO BULLE
395
var infoBulleOuverte = false;
407
var infoBulleOuverte = false;
396
function initialiserInfoBulle() {
408
function initialiserInfoBulle() {
397
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
409
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
398
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
410
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
399
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
411
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
400
}
412
}
401
 
413
 
402
function surFermetureInfoBulle() {
414
function surFermetureInfoBulle() {
403
	infoBulleOuverte = false;
415
	infoBulleOuverte = false;
404
	programmerRafraichissementCarte();
416
	programmerRafraichissementCarte();
405
}
417
}
406
 
418
 
407
function centrerInfoBulle() {
419
function centrerInfoBulle() {
408
	var limites = map.getBounds();
420
	var limites = map.getBounds();
409
	var centre = limites.getCenter();
421
	var centre = limites.getCenter();
410
	var nordEst = limites.getNorthEast();
422
	var nordEst = limites.getNorthEast();
411
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
423
	var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
412
	map.panTo(centreSudLatLng);
424
	map.panTo(centreSudLatLng);
413
}
425
}
414
 
426
 
415
function afficherInfoBulle() {
427
function afficherInfoBulle() {
416
	var obsHtml = $("#tpl-obs").html();
428
	var obsHtml = $("#tpl-obs").html();
417
	var largeur = definirLargeurInfoBulle();
429
	var largeur = definirLargeurInfoBulle();
418
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
430
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
419
	infoBulle.setContent(obsHtml);
431
	infoBulle.setContent(obsHtml);
420
	chargerObs(0, 0);
432
	chargerObs(0, 0);
421
	infoBulleOuverte = true;
433
	infoBulleOuverte = true;
422
}
434
}
423
 
435
 
424
function definirLargeurInfoBulle() {
436
function definirLargeurInfoBulle() {
425
	var largeurViewPort = $(window).width();
437
	var largeurViewPort = $(window).width();
426
	var lageurInfoBulle = null;
438
	var lageurInfoBulle = null;
427
	if (largeurViewPort < 800) {
439
	if (largeurViewPort < 800) {
428
		largeurInfoBulle = 400;
440
		largeurInfoBulle = 400;
429
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
441
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
430
		largeurInfoBulle = 500;
442
		largeurInfoBulle = 500;
431
	} else if (largeurViewPort >= 1200) {
443
	} else if (largeurViewPort >= 1200) {
432
		largeurInfoBulle = 600;
444
		largeurInfoBulle = 600;
433
	}
445
	}
434
	return largeurInfoBulle;
446
	return largeurInfoBulle;
435
}
447
}
436
 
448
 
437
function afficherMessageChargement(element) {
449
function afficherMessageChargement(element) {
438
	if ($('#chargement').get() == '') {
450
	if ($('#chargement').get() == '') {
439
		$('#tpl-chargement').tmpl().appendTo(element);
451
		$('#tpl-chargement').tmpl().appendTo(element);
440
	}
452
	}
441
}
453
}
442
 
454
 
443
function afficherMessageChargementTitreInfoBulle() {
455
function afficherMessageChargementTitreInfoBulle() {
444
	$("#obs-station-titre").text("Chargement des observations");	
456
	$("#obs-station-titre").text("Chargement des observations");	
445
}
457
}
446
 
458
 
447
function supprimerMessageChargement() {
459
function supprimerMessageChargement() {
448
	$('#chargement').remove();
460
	$('#chargement').remove();
449
}
461
}
450
 
462
 
451
function chargerObs(depart, total) {
463
function chargerObs(depart, total) {
452
	if (depart == 0 || depart < total) {
464
	if (depart == 0 || depart < total) {
453
		var limite = 300;
465
		var limite = 300;
454
		if (depart == 0) {
466
		if (depart == 0) {
455
			viderTableauObs();
467
			viderTableauObs();
456
		}
468
		}
457
		
469
		
458
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
470
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
459
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
471
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
460
		if (pointClique.stationInfos.type_emplacement == 'communes') {
472
		if (pointClique.stationInfos.type_emplacement == 'communes') {
461
			urlObs = urlObs.replace(/commune=%2A/g, 'commune='+pointClique.stationInfos.nom);
473
			urlObs = urlObs.replace(/commune=%2A/g, 'commune='+pointClique.stationInfos.nom);
462
		}
474
		}
463
		urlObs = urlObs.replace(/\{nt\}/g, nt);
475
		urlObs = urlObs.replace(/\{nt\}/g, nt);
464
		urlObs = urlObs.replace(/\{start\}/g, depart);
476
		urlObs = urlObs.replace(/\{start\}/g, depart);
465
		
477
		
466
		$.getJSON(urlObs, function(observations){
478
		$.getJSON(urlObs, function(observations){
467
			surRetourChargementObs(observations, depart, total);
479
			surRetourChargementObs(observations, depart, total);
468
			chargerObs(depart+limite, observations.total);
480
			chargerObs(depart+limite, observations.total);
469
		});
481
		});
470
	}
482
	}
471
}
483
}
472
 
484
 
473
function viderTableauObs() {
485
function viderTableauObs() {
474
	obsStation = new Array();	
486
	obsStation = new Array();	
475
	surClicPagePagination(0, null);
487
	surClicPagePagination(0, null);
476
}
488
}
477
 
489
 
478
function surRetourChargementObs(observations, depart, total) {
490
function surRetourChargementObs(observations, depart, total) {
479
	obsStation = obsStation.concat(observations.observations);
491
	obsStation = obsStation.concat(observations.observations);
480
	if (depart == 0) {
492
	if (depart == 0) {
481
		actualiserInfosStation(observations);
493
		actualiserInfosStation(observations);
482
		creerTitreInfoBulle();
494
		creerTitreInfoBulle();
483
		surClicPagePagination(0, null);	
495
		surClicPagePagination(0, null);	
484
	}
496
	}
485
	
497
	
486
	afficherPagination();
498
	afficherPagination();
487
	actualiserPagineur();
499
	actualiserPagineur();
488
	selectionnerOnglet("#obs-vue-"+pagineur.format);
500
	selectionnerOnglet("#obs-vue-"+pagineur.format);
489
}
501
}
490
 
502
 
491
function actualiserInfosStation(infos) {
503
function actualiserInfosStation(infos) {
492
	pointClique.stationInfos.commune = infos.commune;
504
	pointClique.stationInfos.commune = infos.commune;
493
	pointClique.stationInfos.obsNbre = infos.total;
505
	pointClique.stationInfos.obsNbre = infos.total;
494
}
506
}
495
 
507
 
496
function creerTitreInfoBulle() {
508
function creerTitreInfoBulle() {
497
	$("#obs-total").text(station.obsNbre);
509
	$("#obs-total").text(station.obsNbre);
498
	$("#obs-commune").text(station.commune);
510
	$("#obs-commune").text(station.commune);
499
	var titre = '';
511
	var titre = '';
500
	titre += pointClique.stationInfos.obsNbre+' observation';
512
	titre += pointClique.stationInfos.obsNbre+' observation';
501
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
513
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
502
	titre += ' pour ';
514
	titre += ' pour ';
503
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
515
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
504
		nomStation = 'la commune : ';
516
		nomStation = 'la commune : ';
505
	} else {
517
	} else {
506
		nomStation = 'la station : ';
518
		nomStation = 'la station : ';
507
	}
519
	}
508
	titre += pointClique.stationInfos.nom;
520
	titre += pointClique.stationInfos.nom;
509
	$("#obs-station-titre").text(titre);	
521
	$("#obs-station-titre").text(titre);	
510
}
522
}
511
 
523
 
512
function actualiserPagineur() {
524
function actualiserPagineur() {
513
	pagineur.stationId = pointClique.stationInfos.id;
525
	pagineur.stationId = pointClique.stationInfos.id;
514
	pagineur.total = pointClique.stationInfos.obsNbre;
526
	pagineur.total = pointClique.stationInfos.obsNbre;
515
	if (pagineur.total > 4) {
527
	if (pagineur.total > 4) {
516
		pagineur.format = 'tableau';
528
		pagineur.format = 'tableau';
517
	} else {
529
	} else {
518
		pagineur.format = 'liste';
530
		pagineur.format = 'liste';
519
	}
531
	}
520
}
532
}
521
 
533
 
522
function afficherPagination(observations) {
534
function afficherPagination(observations) {
523
	$(".navigation").pagination(pagineur.total, {
535
	$(".navigation").pagination(pagineur.total, {
524
		items_per_page:pagineur.limite,
536
		items_per_page:pagineur.limite,
525
		callback:surClicPagePagination,
537
		callback:surClicPagePagination,
526
		next_text:'Suivant',
538
		next_text:'Suivant',
527
		prev_text:'Précédent',
539
		prev_text:'Précédent',
528
		prev_show_always:false,
540
		prev_show_always:false,
529
		num_edge_entries:1,
541
		num_edge_entries:1,
530
		num_display_entries:4,
542
		num_display_entries:4,
531
		load_first_page:true
543
		load_first_page:true
532
	});
544
	});
533
}
545
}
534
 
546
 
535
function surClicPagePagination(pageIndex, paginationConteneur) {
547
function surClicPagePagination(pageIndex, paginationConteneur) {
536
	var index = pageIndex * pagineur.limite;
548
	var index = pageIndex * pagineur.limite;
537
	var indexMax = index + pagineur.limite;
549
	var indexMax = index + pagineur.limite;
538
	pagineur.depart = index;
550
	pagineur.depart = index;
539
	obsPage = new Array();
551
	obsPage = new Array();
540
    for(index; index < indexMax; index++) {
552
    for(index; index < indexMax; index++) {
541
    	obsPage.push(obsStation[index]);
553
    	obsPage.push(obsStation[index]);
542
    }
554
    }
543
    
555
    
544
    supprimerMessageChargement();
556
    supprimerMessageChargement();
545
    mettreAJourObservations();
557
    mettreAJourObservations();
546
	return false;
558
	return false;
547
}
559
}
548
 
560
 
549
function mettreAJourObservations() {
561
function mettreAJourObservations() {
550
	$("#obs-"+pagineur.format+"-lignes").empty();
562
	$("#obs-"+pagineur.format+"-lignes").empty();
551
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
563
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
552
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
564
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
553
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
565
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
554
	
566
	
555
	// Actualisation de Fancybox
567
	// Actualisation de Fancybox
556
	ajouterFomulaireContact("a.contact");
568
	ajouterFomulaireContact("a.contact");
557
	if (pagineur.format == 'liste') {
569
	if (pagineur.format == 'liste') {
558
		ajouterGaleriePhoto("a.cel-img");
570
		ajouterGaleriePhoto("a.cel-img");
559
	}
571
	}
560
}
572
}
561
 
573
 
562
function initialiserContenuInfoBulle() {
574
function initialiserContenuInfoBulle() {
563
	afficherMessageChargement('#observations');
575
	afficherMessageChargement('#observations');
564
	cacherContenuOnglets();
576
	cacherContenuOnglets();
565
	afficherOnglets();
577
	afficherOnglets();
566
	ajouterTableauTriable("#obs-tableau");
578
	ajouterTableauTriable("#obs-tableau");
567
	afficherTextStationId();
579
	afficherTextStationId();
568
	corrigerLargeurInfoWindow();
580
	corrigerLargeurInfoWindow();
569
}
581
}
570
 
582
 
571
function cacherContenuOnglets() {
583
function cacherContenuOnglets() {
572
	$("#obs-vue-tableau").css("display", "none");
584
	$("#obs-vue-tableau").css("display", "none");
573
	$("#obs-vue-liste").css("display", "none");
585
	$("#obs-vue-liste").css("display", "none");
574
}
586
}
575
 
587
 
576
function afficherOnglets() {
588
function afficherOnglets() {
577
	var $tabs = $('#obs').tabs();
589
	var $tabs = $('#obs').tabs();
578
	$('#obs').bind('tabsselect', function(event, ui) {
590
	$('#obs').bind('tabsselect', function(event, ui) {
579
		if (ui.panel.id == 'obs-vue-tableau') {
591
		if (ui.panel.id == 'obs-vue-tableau') {
580
			surClicAffichageTableau();
592
			surClicAffichageTableau();
581
		} else if (ui.panel.id == 'obs-vue-liste') {
593
		} else if (ui.panel.id == 'obs-vue-liste') {
582
			surClicAffichageListe();
594
			surClicAffichageListe();
583
		}
595
		}
584
	});
596
	});
585
	if (pointClique.stationInfos.nbre > 4) {
597
	if (pointClique.stationInfos.nbre > 4) {
586
		$tabs.tabs('select', "#obs-vue-tableau");
598
		$tabs.tabs('select', "#obs-vue-tableau");
587
	} else {
599
	} else {
588
		$tabs.tabs('select', "#obs-vue-liste");
600
		$tabs.tabs('select', "#obs-vue-liste");
589
	}
601
	}
590
	
602
	
591
}
603
}
592
 
604
 
593
function selectionnerOnglet(onglet) {
605
function selectionnerOnglet(onglet) {
594
	$(onglet).css('display', 'block');
606
	$(onglet).css('display', 'block');
595
	$('#obs').tabs('select', onglet);
607
	$('#obs').tabs('select', onglet);
596
}
608
}
597
 
609
 
598
function afficherTextStationId() {
610
function afficherTextStationId() {
599
	$('#obs-station-id').text(pointClique.stationInfos.id);
611
	$('#obs-station-id').text(pointClique.stationInfos.id);
600
}
612
}
601
 
613
 
602
function corrigerLargeurInfoWindow() {
614
function corrigerLargeurInfoWindow() {
603
	$("#info-bulle").width($("#info-bulle").width() - 17);
615
	$("#info-bulle").width($("#info-bulle").width() - 17);
604
}
616
}
605
 
617
 
606
function surClicAffichageTableau(event) {
618
function surClicAffichageTableau(event) {
607
	pagineur.format = 'tableau';
619
	pagineur.format = 'tableau';
608
	mettreAJourObservations();
620
	mettreAJourObservations();
609
	mettreAJourTableauTriable("#obs-tableau");
621
	mettreAJourTableauTriable("#obs-tableau");
610
}
622
}
611
 
623
 
612
function surClicAffichageListe(event) {
624
function surClicAffichageListe(event) {
613
	pagineur.format = 'liste';
625
	pagineur.format = 'liste';
614
	mettreAJourObservations();
626
	mettreAJourObservations();
615
	ajouterGaleriePhoto("a.cel-img");
627
	ajouterGaleriePhoto("a.cel-img");
616
}
628
}
617
 
629
 
618
function ajouterTableauTriable(element) {
630
function ajouterTableauTriable(element) {
619
	// add parser through the tablesorter addParser method 
631
	// add parser through the tablesorter addParser method 
620
	$.tablesorter.addParser({ 
632
	$.tablesorter.addParser({ 
621
		// Définition d'un id unique pour ce parsseur 
633
		// Définition d'un id unique pour ce parsseur 
622
		id: 'date_cel', 
634
		id: 'date_cel', 
623
		is: function(s) { 
635
		is: function(s) { 
624
			// doit retourner false si le parsseur n'est pas autodétecté
636
			// doit retourner false si le parsseur n'est pas autodétecté
625
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
637
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
626
		}, 
638
		}, 
627
		format: function(date) { 
639
		format: function(date) { 
628
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
640
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
629
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
641
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
630
			// Remplace la date par un nombre de millisecondes pour trier numériquement
642
			// Remplace la date par un nombre de millisecondes pour trier numériquement
631
			return $.tablesorter.formatFloat(new Date(date).getTime());
643
			return $.tablesorter.formatFloat(new Date(date).getTime());
632
		}, 
644
		}, 
633
		// set type, either numeric or text 
645
		// set type, either numeric or text 
634
		type: 'numeric' 
646
		type: 'numeric' 
635
	});
647
	});
636
	$(element).tablesorter({ 
648
	$(element).tablesorter({ 
637
        headers: { 
649
        headers: { 
638
			1: { 
650
			1: { 
639
            	sorter:'date_cel' 
651
            	sorter:'date_cel' 
640
        	} 
652
        	} 
641
    	} 
653
    	} 
642
	});
654
	});
643
}
655
}
644
 
656
 
645
function mettreAJourTableauTriable(element) {
657
function mettreAJourTableauTriable(element) {
646
	$(element).trigger('update');
658
	$(element).trigger('update');
647
}
659
}
648
 
660
 
649
function ajouterGaleriePhoto(element) {
661
function ajouterGaleriePhoto(element) {
650
	$(element).fancybox({
662
	$(element).fancybox({
651
		transitionIn:'elastic',
663
		transitionIn:'elastic',
652
		transitionOut:'elastic',
664
		transitionOut:'elastic',
653
		speedIn	:600, 
665
		speedIn	:600, 
654
		speedOut:200,
666
		speedOut:200,
655
		overlayShow:true,
667
		overlayShow:true,
656
		titleShow:true,
668
		titleShow:true,
657
		titlePosition:'inside',
669
		titlePosition:'inside',
658
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
670
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
659
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
671
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
660
			motif.exec(titre);
672
			motif.exec(titre);
661
			var id = RegExp.$1;
673
			var id = RegExp.$1;
662
			var info = $('#cel-info-'+id).clone().html();
674
			var info = $('#cel-info-'+id).clone().html();
663
			var tpl = 
675
			var tpl = 
664
				'<div class="cel-legende">'+
676
				'<div class="cel-legende">'+
665
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
677
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
666
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
678
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
667
				'<\/div>';
679
				'<\/div>';
668
			return tpl;
680
			return tpl;
669
		}
681
		}
670
	}).live('click', function(e) {
682
	}).live('click', function(e) {
671
		if (e.stopPropagation) {
683
		if (e.stopPropagation) {
672
			e.stopPropagation();
684
			e.stopPropagation();
673
		}
685
		}
674
		return false;
686
		return false;
675
	});
687
	});
676
}
688
}
677
 
689
 
678
function ajouterFomulaireContact(element) {
690
function ajouterFomulaireContact(element) {
679
	$(element).fancybox({
691
	$(element).fancybox({
680
		transitionIn:'elastic',
692
		transitionIn:'elastic',
681
		transitionOut:'elastic',
693
		transitionOut:'elastic',
682
		speedIn	:600, 
694
		speedIn	:600, 
683
		speedOut:200,
695
		speedOut:200,
684
		scrolling: 'no',
696
		scrolling: 'no',
685
		titleShow: false,
697
		titleShow: false,
686
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
698
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
687
			var element = selectedArray[selectedIndex];
699
			var element = selectedArray[selectedIndex];
688
 
700
 
689
			var motif = / contributeur-([0-9]+)$/;
701
			var motif = / contributeur-([0-9]+)$/;
690
			motif.exec($(element).attr('class'));
702
			motif.exec($(element).attr('class'));
691
			var id = RegExp.$1;
703
			var id = RegExp.$1;
692
			//console.log('Destinataire id : '+id);
704
			//console.log('Destinataire id : '+id);
693
			$("#fc_destinataire_id").attr('value', id);
705
			$("#fc_destinataire_id").attr('value', id);
694
		
706
		
695
			var motif = / obs-([0-9]+) /;
707
			var motif = / obs-([0-9]+) /;
696
			motif.exec($(element).attr('class'));
708
			motif.exec($(element).attr('class'));
697
			var id = RegExp.$1;
709
			var id = RegExp.$1;
698
			//console.log('Obs id : '+id);
710
			//console.log('Obs id : '+id);
699
			chargerInfoObsPourMessage(id);
711
			chargerInfoObsPourMessage(id);
700
		},
712
		},
701
		onCleanup: function() {
713
		onCleanup: function() {
702
			//console.log('Avant fermeture fancybox');
714
			//console.log('Avant fermeture fancybox');
703
			$("#fc_destinataire_id").attr('value', '');
715
			$("#fc_destinataire_id").attr('value', '');
704
			$("#fc_sujet").attr('value', '');
716
			$("#fc_sujet").attr('value', '');
705
			$("#fc_message").text('');
717
			$("#fc_message").text('');
706
		},
718
		},
707
		onClosed: function(e) {
719
		onClosed: function(e) {
708
			//console.log('Fermeture fancybox');
720
			//console.log('Fermeture fancybox');
709
			if (e.stopPropagation) {
721
			if (e.stopPropagation) {
710
				e.stopPropagation();
722
				e.stopPropagation();
711
			}
723
			}
712
			return false;
724
			return false;
713
		}
725
		}
714
	});
726
	});
715
}
727
}
716
 
728
 
717
function chargerInfoObsPourMessage(idObs) {
729
function chargerInfoObsPourMessage(idObs) {
718
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
730
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
719
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
731
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
720
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
732
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
721
	var sujet = "Observation #"+idObs+" de "+nomSci;
733
	var sujet = "Observation #"+idObs+" de "+nomSci;
722
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
734
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
723
	$("#fc_sujet").attr('value', sujet);
735
	$("#fc_sujet").attr('value', sujet);
724
	$("#fc_message").text(message);
736
	$("#fc_message").text(message);
725
}
737
}
726
 
738
 
727
function initialiserFormulaireContact() {
739
function initialiserFormulaireContact() {
728
	//console.log('Initialisation du form contact');
740
	//console.log('Initialisation du form contact');
729
	$("#form-contact").validate({
741
	$("#form-contact").validate({
730
		rules: {
742
		rules: {
731
			fc_sujet : "required",
743
			fc_sujet : "required",
732
			fc_message : "required",
744
			fc_message : "required",
733
			fc_utilisateur_courriel : {
745
			fc_utilisateur_courriel : {
734
				required : true,
746
				required : true,
735
				email : true}
747
				email : true}
736
		}
748
		}
737
	});
749
	});
738
	$("#form-contact").bind("submit", envoyerCourriel);
750
	$("#form-contact").bind("submit", envoyerCourriel);
739
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
751
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
740
	
752
	
741
}
753
}
742
 
754
 
743
function envoyerCourriel() {
755
function envoyerCourriel() {
744
	//console.log('Formulaire soumis');
756
	//console.log('Formulaire soumis');
745
	if ($("#form-contact").valid()) {
757
	if ($("#form-contact").valid()) {
746
		//console.log('Formulaire valide');
758
		//console.log('Formulaire valide');
747
		//$.fancybox.showActivity();
759
		//$.fancybox.showActivity();
748
		var destinataireId = $("#fc_destinataire_id").attr('value');
760
		var destinataireId = $("#fc_destinataire_id").attr('value');
749
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
761
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
750
		var erreurMsg = "";
762
		var erreurMsg = "";
751
		var donnees = new Array();
763
		var donnees = new Array();
752
		$.each($(this).serializeArray(), function (index, champ) {
764
		$.each($(this).serializeArray(), function (index, champ) {
753
			var cle = champ.name;
765
			var cle = champ.name;
754
			cle = cle.replace(/^fc_/, '');
766
			cle = cle.replace(/^fc_/, '');
755
			
767
			
756
			if (cle == 'sujet') {
768
			if (cle == 'sujet') {
757
				champ.value += " - Carnet en ligne - Tela Botanica";
769
				champ.value += " - Carnet en ligne - Tela Botanica";
758
			}
770
			}
759
			if (cle == 'message') {
771
			if (cle == 'message') {
760
				champ.value += "\n--\n"+
772
				champ.value += "\n--\n"+
761
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
773
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
762
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
774
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
763
					"http://www.tela-botanica.org/widget:cel:carto";
775
					"http://www.tela-botanica.org/widget:cel:carto";
764
			}
776
			}
765
			
777
			
766
			donnees[index] = {'name':cle,'value':champ.value};
778
			donnees[index] = {'name':cle,'value':champ.value};
767
		});
779
		});
768
		$.ajax({
780
		$.ajax({
769
			type : "POST",
781
			type : "POST",
770
			cache : false,
782
			cache : false,
771
			url : urlMessage,
783
			url : urlMessage,
772
			data : donnees,
784
			data : donnees,
773
			beforeSend : function() {
785
			beforeSend : function() {
774
				$(".msg").remove();
786
				$(".msg").remove();
775
			},
787
			},
776
			success : function(data) {
788
			success : function(data) {
777
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
789
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
778
			},
790
			},
779
			error : function(jqXHR, textStatus, errorThrown) {
791
			error : function(jqXHR, textStatus, errorThrown) {
780
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
792
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
781
				reponse = jQuery.parseJSON(jqXHR.responseText);
793
				reponse = jQuery.parseJSON(jqXHR.responseText);
782
				if (reponse != null) {
794
				if (reponse != null) {
783
					$.each(reponse, function (cle, valeur) {
795
					$.each(reponse, function (cle, valeur) {
784
						erreurMsg += valeur + "\n";
796
						erreurMsg += valeur + "\n";
785
					});
797
					});
786
				}				
798
				}				
787
			},
799
			},
788
			complete : function(jqXHR, textStatus) {
800
			complete : function(jqXHR, textStatus) {
789
				var debugMsg = '';
801
				var debugMsg = '';
790
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
802
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
791
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
803
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
792
					if (debugInfos != null) {
804
					if (debugInfos != null) {
793
						$.each(debugInfos, function (cle, valeur) {
805
						$.each(debugInfos, function (cle, valeur) {
794
							debugMsg += valeur + "\n";
806
							debugMsg += valeur + "\n";
795
						});
807
						});
796
					}
808
					}
797
				}
809
				}
798
				if (erreurMsg != '') {
810
				if (erreurMsg != '') {
799
					$("#fc-zone-dialogue").append('<p class="msg">'+
811
					$("#fc-zone-dialogue").append('<p class="msg">'+
800
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
812
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
801
							'Vous pouvez signaler le disfonctionnement à <a href="'+
813
							'Vous pouvez signaler le disfonctionnement à <a href="'+
802
							'mailto:cel@tela-botanica.org'+'?'+
814
							'mailto:cel@tela-botanica.org'+'?'+
803
							'subject=Disfonctionnement du widget carto'+
815
							'subject=Disfonctionnement du widget carto'+
804
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
816
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
805
							'">cel@tela-botanica.org</a>.'+
817
							'">cel@tela-botanica.org</a>.'+
806
							'</p>');
818
							'</p>');
807
				}
819
				}
808
				if (DEBUG) {
820
				if (DEBUG) {
809
					console.log('Débogage : '+debugMsg);
821
					console.log('Débogage : '+debugMsg);
810
				}
822
				}
811
				//console.log('Débogage : '+debugMsg);
823
				//console.log('Débogage : '+debugMsg);
812
				//console.log('Erreur : '+erreurMsg);
824
				//console.log('Erreur : '+erreurMsg);
813
			}
825
			}
814
		});
826
		});
815
	}
827
	}
816
	return false;
828
	return false;
817
}
829
}
818
/*+--------------------------------------------------------------------------------------------------------+*/
830
/*+--------------------------------------------------------------------------------------------------------+*/
819
// PANNEAU LATÉRAL
831
// PANNEAU LATÉRAL
820
 
832
 
821
function initialiserAffichagePanneauLateral() {
833
function initialiserAffichagePanneauLateral() {
822
	$('#panneau-lateral').height($(window).height() - 35);
834
	$('#panneau-lateral').height($(window).height() - 35);
823
	
835
	
824
	if (nt == '*') {
836
	if (nt == '*') {
825
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
837
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
826
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
838
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
827
	}
839
	}
828
	chargerTaxons(0, 0);
840
	chargerTaxons(0, 0);
829
}
841
}
830
 
842
 
831
function chargerTaxons(depart, total) {
843
function chargerTaxons(depart, total) {
832
	if (depart == 0 || depart < total) {
844
	if (depart == 0 || depart < total) {
833
		var limite = 7000;
845
		var limite = 7000;
834
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
846
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
835
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
847
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
836
		urlTax = urlTax.replace(/\{start\}/g, depart);
848
		urlTax = urlTax.replace(/\{start\}/g, depart);
837
		$.getJSON(urlTax, function(infos) {
849
		$.getJSON(urlTax, function(infos) {
838
			taxonsCarte = taxonsCarte.concat(infos.taxons);
850
			taxonsCarte = taxonsCarte.concat(infos.taxons);
839
			//console.log("Nbre taxons :"+taxonsCarte.length);
851
			//console.log("Nbre taxons :"+taxonsCarte.length);
840
			chargerTaxons(depart+limite, infos.total);
852
			chargerTaxons(depart+limite, infos.total);
841
		});
853
		});
842
	} else {
854
	} else {
843
		if (nt == '*') {
855
		if (nt == '*') {
844
			afficherTaxons();
856
			afficherTaxons();
845
		}
857
		}
846
		afficherTitreCarte();
858
		afficherTitreCarte();
847
	}
859
	}
848
}
860
}
849
 
861
 
850
function afficherTaxons() {
862
function afficherTaxons() {
851
	$(".plantes-nbre").text(taxonsCarte.length);
863
	$(".plantes-nbre").text(taxonsCarte.length);
852
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
864
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
853
	$('.taxon').live('click', filtrerParTaxon);
865
	$('.taxon').live('click', filtrerParTaxon);
854
}
866
}
855
 
867
 
856
 
868
 
857
function afficherPanneauLateral() {
869
function afficherPanneauLateral() {
858
	$('#panneau-lateral').width(300);
870
	$('#panneau-lateral').width(300);
859
	$('#pl-contenu').css('display', 'block');
871
	$('#pl-contenu').css('display', 'block');
860
	$('#pl-ouverture').css('display', 'none');
872
	$('#pl-ouverture').css('display', 'none');
861
	$('#pl-fermeture').css('display', 'block');
873
	$('#pl-fermeture').css('display', 'block');
862
	$('#carte').css('left', '300px');
874
	$('#carte').css('left', '300px');
863
 
875
 
864
	google.maps.event.trigger(map, 'resize');
876
	google.maps.event.trigger(map, 'resize');
865
};
877
};
866
 
878
 
867
function cacherPanneauLateral() {
879
function cacherPanneauLateral() {
868
	$('#panneau-lateral').width(24);
880
	$('#panneau-lateral').width(24);
869
	$('#pl-contenu').css('display', 'none');
881
	$('#pl-contenu').css('display', 'none');
870
	$('#pl-ouverture').css('display', 'block');
882
	$('#pl-ouverture').css('display', 'block');
871
	$('#pl-fermeture').css('display', 'none');
883
	$('#pl-fermeture').css('display', 'none');
872
	$('#carte').css('left', '24px');
884
	$('#carte').css('left', '24px');
873
	
885
	
874
	google.maps.event.trigger(map, 'resize');
886
	google.maps.event.trigger(map, 'resize');
875
};
887
};
876
 
888
 
877
function filtrerParTaxon() {
889
function filtrerParTaxon() {
878
	var ntAFiltrer = $('.nt', this).text();
890
	var ntAFiltrer = $('.nt', this).text();
879
	infoBulle.close();
891
	infoBulle.close();
880
	var zoom = map.getZoom();
892
	var zoom = map.getZoom();
881
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
893
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
882
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
894
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
883
	
895
	
884
	$('#taxon-'+nt).removeClass('taxon-actif');
896
	$('#taxon-'+nt).removeClass('taxon-actif');
885
	if (nt == ntAFiltrer) {
897
	if (nt == ntAFiltrer) {
886
		nt = '*';
898
		nt = '*';
887
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
899
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
888
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
900
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
889
	} else {
901
	} else {
890
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
902
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
891
		url = stationsUrl;
903
		url = stationsUrl;
892
		url += '&zoom='+zoom+
904
		url += '&zoom='+zoom+
893
			'&ne='+NELatLng+
905
			'&ne='+NELatLng+
894
			'&sw='+SWLatLng;
906
			'&sw='+SWLatLng;
895
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
907
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
896
			stations = stationsFiltrees;
908
			stations = stationsFiltrees;
897
			nt = ntAFiltrer;
909
			nt = ntAFiltrer;
898
			$('#taxon-'+nt).addClass('taxon-actif');
910
			$('#taxon-'+nt).addClass('taxon-actif');
899
			rafraichirMarqueurs(stations);
911
			rafraichirMarqueurs(stations);
900
		});
912
		});
901
	}
913
	}
902
};
914
};
903
 
915
 
904
/*+--------------------------------------------------------------------------------------------------------+*/
916
/*+--------------------------------------------------------------------------------------------------------+*/
905
// FONCTIONS UTILITAIRES
917
// FONCTIONS UTILITAIRES
906
 
918
 
907
function ouvrirPopUp(element, nomPopUp, event) {
919
function ouvrirPopUp(element, nomPopUp, event) {
908
	var options = 
920
	var options = 
909
		'width=650,'+
921
		'width=650,'+
910
		'height=600,'+
922
		'height=600,'+
911
		'scrollbars=yes,'+
923
		'scrollbars=yes,'+
912
		'directories=no,'+
924
		'directories=no,'+
913
		'location=no,'+
925
		'location=no,'+
914
		'menubar=no,'+
926
		'menubar=no,'+
915
		'status=no,'+
927
		'status=no,'+
916
		'toolbar=no';
928
		'toolbar=no';
917
	var popUp = window.open(element.href, nomPopUp, options);
929
	var popUp = window.open(element.href, nomPopUp, options);
918
	if (window.focus) {
930
	if (window.focus) {
919
		popUp.focus();
931
		popUp.focus();
920
	}
932
	}
921
	return arreter(event);
933
	return arreter(event);
922
};
934
};
923
 
935
 
924
function ouvrirNouvelleFenetre(element, event) {
936
function ouvrirNouvelleFenetre(element, event) {
925
	window.open(element.href);
937
	window.open(element.href);
926
	return arreter(event);
938
	return arreter(event);
927
}
939
}
928
 
940
 
929
function arreter(event) {
941
function arreter(event) {
930
	if (event.stopPropagation) {
942
	if (event.stopPropagation) {
931
		event.stopPropagation();
943
		event.stopPropagation();
932
	} else if (window.event) {
944
	} else if (window.event) {
933
		window.event.cancelBubble = true;
945
		window.event.cancelBubble = true;
934
	}
946
	}
935
	if (event.preventDefault) {
947
	if (event.preventDefault) {
936
		event.preventDefault();
948
		event.preventDefault();
937
	}
949
	}
938
	event.returnValue = false;
950
	event.returnValue = false;
939
	return false;
951
	return false;
940
}
952
}
941
 
953
 
942
/**
954
/**
943
 * +-------------------------------------+
955
 * +-------------------------------------+
944
 * Number.prototype.formaterNombre
956
 * Number.prototype.formaterNombre
945
 * +-------------------------------------+
957
 * +-------------------------------------+
946
 * Params (facultatifs):
958
 * Params (facultatifs):
947
 * - Int decimales: nombre de decimales (exemple: 2)
959
 * - Int decimales: nombre de decimales (exemple: 2)
948
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
960
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
949
 * - String separateurMilliers: comme son nom l'indique
961
 * - String separateurMilliers: comme son nom l'indique
950
 * Returns:
962
 * Returns:
951
 * - String chaine formatee
963
 * - String chaine formatee
952
 * @author	::mastahbenus::
964
 * @author	::mastahbenus::
953
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
965
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
954
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
966
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
955
 */
967
 */
956
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
968
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
957
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
969
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
958
	
970
	
959
	function is_int(nbre) {
971
	function is_int(nbre) {
960
		nbre = nbre.replace(',', '.');
972
		nbre = nbre.replace(',', '.');
961
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
973
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
962
	}
974
	}
963
 
975
 
964
	if (decimales == undefined) {
976
	if (decimales == undefined) {
965
		if (is_int(_sNombre)) {
977
		if (is_int(_sNombre)) {
966
			decimales = 0;
978
			decimales = 0;
967
		} else {
979
		} else {
968
			decimales = 2;
980
			decimales = 2;
969
		}
981
		}
970
	}
982
	}
971
	if (signe == undefined) {
983
	if (signe == undefined) {
972
		if (is_int(_sNombre)) {
984
		if (is_int(_sNombre)) {
973
			signe = '';
985
			signe = '';
974
		} else {
986
		} else {
975
			signe = '.';
987
			signe = '.';
976
		}
988
		}
977
	}
989
	}
978
	if (separateurMilliers == undefined) {
990
	if (separateurMilliers == undefined) {
979
		separateurMilliers = ' ';
991
		separateurMilliers = ' ';
980
	}
992
	}
981
	
993
	
982
	function separeMilliers (sNombre) {
994
	function separeMilliers (sNombre) {
983
		var sRetour = "";
995
		var sRetour = "";
984
		while (sNombre.length % 3 != 0) {
996
		while (sNombre.length % 3 != 0) {
985
			sNombre = "0"+sNombre;
997
			sNombre = "0"+sNombre;
986
		}
998
		}
987
		for (i = 0; i < sNombre.length; i += 3) {
999
		for (i = 0; i < sNombre.length; i += 3) {
988
			if (i == sNombre.length-1) separateurMilliers = '';
1000
			if (i == sNombre.length-1) separateurMilliers = '';
989
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1001
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
990
		}
1002
		}
991
		while (sRetour.substr(0, 1) == "0") {
1003
		while (sRetour.substr(0, 1) == "0") {
992
			sRetour = sRetour.substr(1);
1004
			sRetour = sRetour.substr(1);
993
		}
1005
		}
994
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1006
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
995
	}
1007
	}
996
	
1008
	
997
	if (_sNombre.indexOf('.') == -1) {
1009
	if (_sNombre.indexOf('.') == -1) {
998
		for (i = 0; i < decimales; i++) {
1010
		for (i = 0; i < decimales; i++) {
999
			_sDecimales += "0";
1011
			_sDecimales += "0";
1000
		}
1012
		}
1001
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1013
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1002
	} else {
1014
	} else {
1003
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1015
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1004
		if (sDecimalesTmp.length > decimales) {
1016
		if (sDecimalesTmp.length > decimales) {
1005
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1017
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1006
			var nDiv = 1;
1018
			var nDiv = 1;
1007
			for (i = 0; i < nDecimalesManquantes; i++) {
1019
			for (i = 0; i < nDecimalesManquantes; i++) {
1008
				nDiv *= 10;
1020
				nDiv *= 10;
1009
			}
1021
			}
1010
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1022
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1011
		}
1023
		}
1012
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1024
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1013
	}
1025
	}
1014
	return _sRetour;
1026
	return _sRetour;
1015
}
1027
}
1016
 
1028
 
1017
function debug(objet) {
1029
function debug(objet) {
1018
	var msg = '';
1030
	var msg = '';
1019
	if (objet != null) {
1031
	if (objet != null) {
1020
		$.each(objet, function (cle, valeur) {
1032
		$.each(objet, function (cle, valeur) {
1021
			msg += cle+":"+valeur + "\n";
1033
			msg += cle+":"+valeur + "\n";
1022
		});
1034
		});
1023
	} else {
1035
	} else {
1024
		msg = "La variable vaut null.";
1036
		msg = "La variable vaut null.";
1025
	}
1037
	}
1026
	console.log(msg);
1038
	console.log(msg);
1027
}
1039
}