Subversion Repositories eFlore/Applications.cel

Rev

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

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