Subversion Repositories eFlore/Applications.cel

Rev

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

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