Subversion Repositories eFlore/Applications.cel

Rev

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

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