Subversion Repositories eFlore/Applications.cel

Rev

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

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