Subversion Repositories eFlore/Applications.cel

Rev

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

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