Subversion Repositories eFlore/Applications.cel

Rev

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

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