Subversion Repositories eFlore/Applications.cel

Rev

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

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