Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 950 Rev 953
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
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
5
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
6
var pointsOrigine = null;
6
var pointsOrigine = null;
7
var boundsOrigine = null;
7
var boundsOrigine = null;
8
var markerClusterer = null;
8
var markerClusterer = null;
9
var map = null;
9
var map = null;
10
var infoBulle = new google.maps.InfoWindow();
10
var infoBulle = new google.maps.InfoWindow();
11
var pointClique = null;
11
var pointClique = null;
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
12
var carteCentre = new google.maps.LatLng(46.4, 3.10);
13
var carteOptions = {
13
var carteOptions = {
14
	zoom: 6,
14
	zoom: 6,
15
	mapTypeId: google.maps.MapTypeId.ROADMAP,
15
	mapTypeId: google.maps.MapTypeId.ROADMAP,
16
	mapTypeControlOptions: {
16
	mapTypeControlOptions: {
17
		mapTypeIds: ['OSM', 
17
		mapTypeIds: ['OSM', 
18
		             google.maps.MapTypeId.ROADMAP, 
18
		             google.maps.MapTypeId.ROADMAP, 
19
		             google.maps.MapTypeId.HYBRID, 
19
		             google.maps.MapTypeId.HYBRID, 
20
		             google.maps.MapTypeId.SATELLITE, 
20
		             google.maps.MapTypeId.SATELLITE, 
21
		             google.maps.MapTypeId.TERRAIN]
21
		             google.maps.MapTypeId.TERRAIN]
22
	}
22
	}
23
};			
23
};			
24
var ctaLayer = null;
24
var ctaLayer = null;
25
var osmMapType = new google.maps.ImageMapType({
25
var osmMapType = new google.maps.ImageMapType({
26
	getTileUrl: function(coord, zoom) {
26
	getTileUrl: function(coord, zoom) {
27
		return "http://tile.openstreetmap.org/" +
27
		return "http://tile.openstreetmap.org/" +
28
		zoom + "/" + coord.x + "/" + coord.y + ".png";
28
		zoom + "/" + coord.x + "/" + coord.y + ".png";
29
	},
29
	},
30
	tileSize: new google.maps.Size(256, 256),
30
	tileSize: new google.maps.Size(256, 256),
31
	isPng: true,
31
	isPng: true,
32
	alt: "OpenStreetMap",
32
	alt: "OpenStreetMap",
33
	name: "OSM",
33
	name: "OSM",
34
	maxZoom: 19
34
	maxZoom: 19
35
});
35
});
36
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
36
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
37
var station = {'commune':'', 'obsNbre':0};
37
var station = {'commune':'', 'obsNbre':0};
38
var obsStation = new Array();
38
var obsStation = new Array();
39
var obsPage = new Array();
39
var obsPage = new Array();
40
var taxonsCarte = new Array();
40
var taxonsCarte = new Array();
41
/*+--------------------------------------------------------------------------------------------------------+*/
41
/*+--------------------------------------------------------------------------------------------------------+*/
42
// INITIALISATION DU CODE
42
// INITIALISATION DU CODE
43
 
43
 
44
//Déclenchement d'actions quand JQuery et le document HTML sont OK
44
//Déclenchement d'actions quand JQuery et le document HTML sont OK
45
$(document).ready(function() {
45
$(document).ready(function() {
46
	initialiserWidget();
46
	initialiserWidget();
47
});
47
});
48
 
48
 
49
function initialiserWidget() {
49
function initialiserWidget() {
50
	afficherStats();
50
	afficherStats();
51
	initialiserAffichageCarte();
51
	initialiserAffichageCarte();
52
	initialiserAffichagePanneauLateral();
52
	initialiserAffichagePanneauLateral();
53
	
53
	
54
	initialiserCarte();
54
	initialiserCarte();
55
	initialiserInfoBulle();
55
	initialiserInfoBulle();
56
	initialiserFormulaireContact();
56
	initialiserFormulaireContact();
57
	chargerLimitesCommunales();
57
	chargerLimitesCommunales();
58
	rafraichirCarte();
58
	rafraichirCarte();
59
}
59
}
60
 
60
 
61
/*+--------------------------------------------------------------------------------------------------------+*/
61
/*+--------------------------------------------------------------------------------------------------------+*/
62
// AFFICHAGE GÉNÉRAL
62
// AFFICHAGE GÉNÉRAL
63
 
63
 
64
function afficherStats() {
64
function afficherStats() {
65
	// Ajout du nombre de communes où des observations ont eu lieu
65
	// Ajout du nombre de communes où des observations ont eu lieu
66
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
66
	$('#commune-nbre').text(stations.stats.communes.formaterNombre());
67
	// Ajout du nombre d'observations
67
	// Ajout du nombre d'observations
68
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
68
	$('#obs-nbre').text(stations.stats.observations.formaterNombre());
69
}
69
}
70
 
70
 
71
/*+--------------------------------------------------------------------------------------------------------+*/
71
/*+--------------------------------------------------------------------------------------------------------+*/
72
// CARTE
72
// CARTE
73
 
73
 
74
function initialiserAffichageCarte() {
74
function initialiserAffichageCarte() {
75
	$('#carte').height($(window).height() - 35);
75
	$('#carte').height($(window).height() - 35);
76
	$('#carte').width($(window).width() - 24);
76
	$('#carte').width($(window).width() - 24);
77
	
77
	
78
	if (nt != '*') {
78
	if (nt != '*') {
79
		$('#carte').css('left', 0);
79
		$('#carte').css('left', 0);
80
	}
80
	}
81
}
81
}
82
 
82
 
83
function initialiserCarte() {
83
function initialiserCarte() {
84
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
84
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
85
	// Ajout de la couche OSM à la carte
85
	// Ajout de la couche OSM à la carte
86
	map.mapTypes.set('OSM', osmMapType);
86
	map.mapTypes.set('OSM', osmMapType);
87
}
87
}
88
 
88
 
89
 
89
 
90
function chargerLimitesCommunales() {
90
function chargerLimitesCommunales() {
91
	if (urlsLimitesCommunales != null) {
91
	if (urlsLimitesCommunales != null) {
92
		for (urlId in urlsLimitesCommunales) { 
92
		for (urlId in urlsLimitesCommunales) { 
93
			var url = urlsLimitesCommunales[urlId];
93
			var url = urlsLimitesCommunales[urlId];
94
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
94
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
95
			ctaLayer.setMap(map);
95
			ctaLayer.setMap(map);
96
		}
96
		}
97
	}
97
	}
98
}
98
}
99
 
99
 
100
function rafraichirCarte() {
100
function rafraichirCarte() {
101
	var points = [];
101
	var points = [];
102
	var bounds = new google.maps.LatLngBounds();
102
	var bounds = new google.maps.LatLngBounds();
103
	for (var i = 0; i < stations.stats.communes; ++i) {
103
	for (var i = 0; i < stations.stats.communes; ++i) {
104
		var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y);
104
		var maLatLng = new google.maps.LatLng(stations.points[i].coord_x, stations.points[i].coord_y);
105
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
105
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
106
		var point = new google.maps.Marker({
106
		var point = new google.maps.Marker({
107
			position: maLatLng,
107
			position: maLatLng,
108
			map: map,
108
			map: map,
109
			icon: pointImage,
109
			icon: pointImage,
110
			stationId: stations.points[i].id
110
			stationId: stations.points[i].id
111
		});
111
		});
112
 
112
 
113
		bounds.extend(maLatLng);
113
		bounds.extend(maLatLng);
114
		
114
		
115
		google.maps.event.addListener(point, 'click', function() {
115
		google.maps.event.addListener(point, 'click', function() {
116
			pointClique =  this;
116
			pointClique =  this;
117
			infoBulle.open(map, this);
117
			infoBulle.open(map, this);
118
			
118
			
119
			var limites = map.getBounds();
119
			var limites = map.getBounds();
120
			var centre = limites.getCenter();
120
			var centre = limites.getCenter();
121
			var nordEst = limites.getNorthEast();
121
			var nordEst = limites.getNorthEast();
122
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
122
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
123
			map.panTo(centreSudLatLng);
123
			map.panTo(centreSudLatLng);
124
			
124
			
125
			afficherInfoBulle();
125
			afficherInfoBulle();
126
			chargerObs(0, 0);
126
			chargerObs(0, 0);
127
		});
127
		});
128
		
128
		
129
		points.push(point);
129
		points.push(point);
130
	}
130
	}
131
 
131
 
132
	if (pointsOrigine == null && boundsOrigine == null) {
132
	if (pointsOrigine == null && boundsOrigine == null) {
133
		pointsOrigine = points;
133
		pointsOrigine = points;
134
		boundsOrigine = bounds;
134
		boundsOrigine = bounds;
135
	}
135
	}
136
	
136
	
137
	executerMarkerClusterer(points, bounds);
137
	executerMarkerClusterer(points, bounds);
138
}
138
}
139
 
139
 
140
function deplacerCartePointClique() {
140
function deplacerCartePointClique() {
141
	map.panTo(pointClique.position);
141
	map.panTo(pointClique.position);
142
}
142
}
143
 
143
 
144
function executerMarkerClusterer(points, bounds) {
144
function executerMarkerClusterer(points, bounds) {
145
	if (markerClusterer) {
145
	if (markerClusterer) {
146
		markerClusterer.clearMarkers();
146
		markerClusterer.clearMarkers();
147
	}
147
	}
148
	markerClusterer = new MarkerClusterer(map, points);
148
	markerClusterer = new MarkerClusterer(map, points);
149
	map.fitBounds(bounds);
149
	map.fitBounds(bounds);
150
}
150
}
151
 
151
 
152
/*+--------------------------------------------------------------------------------------------------------+*/
152
/*+--------------------------------------------------------------------------------------------------------+*/
153
// INFO BULLE
153
// INFO BULLE
154
 
154
 
155
function initialiserInfoBulle() {
155
function initialiserInfoBulle() {
156
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
156
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
157
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
157
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
158
}
158
}
159
 
159
 
160
function afficherInfoBulle() {
160
function afficherInfoBulle() {
161
	var obsHtml = $("#tpl-obs").html();
161
	var obsHtml = $("#tpl-obs").html();
162
	infoBulle.setContent(obsHtml);
162
	infoBulle.setContent(obsHtml);
163
}
163
}
164
 
164
 
165
function afficherMessageChargement(element) {
165
function afficherMessageChargement(element) {
166
	if ($('#chargement').get() == '') {
166
	if ($('#chargement').get() == '') {
167
		$('#tpl-chargement').tmpl().appendTo(element);
167
		$('#tpl-chargement').tmpl().appendTo(element);
168
	}
168
	}
169
}
169
}
170
 
170
 
171
function supprimerMessageChargement() {
171
function supprimerMessageChargement() {
172
	$('#chargement').remove();
172
	$('#chargement').remove();
173
}
173
}
174
 
174
 
175
function chargerObs(depart, total) {
175
function chargerObs(depart, total) {
176
	if (depart == 0 || depart < total) {
176
	if (depart == 0 || depart < total) {
177
		var limite = 300;
177
		var limite = 300;
178
		if (depart == 0) {
178
		if (depart == 0) {
179
			obsStation = new Array();
179
			obsStation = new Array();
180
		}
180
		}
181
		//console.log("Chargement de "+depart+" à "+(depart+limite));
181
		//console.log("Chargement de "+depart+" à "+(depart+limite));
182
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
182
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
183
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
183
		urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationId);
184
		urlObs = urlObs.replace(/\{nt\}/g, nt);
184
		urlObs = urlObs.replace(/\{nt\}/g, nt);
185
		urlObs = urlObs.replace(/\{start\}/g, depart);
185
		urlObs = urlObs.replace(/\{start\}/g, depart);
186
		
186
		
187
		$.getJSON(urlObs, function(observations){
187
		$.getJSON(urlObs, function(observations){
188
			obsStation = obsStation.concat(observations.observations);
188
			obsStation = obsStation.concat(observations.observations);
189
			if (depart == 0) {
189
			if (depart == 0) {
190
				actualiserInfosStation(observations);
190
				actualiserInfosStation(observations);
191
				actualiserPagineur();
191
				actualiserPagineur();
192
				creerTitreInfoBulle();
192
				creerTitreInfoBulle();
193
			}
193
			}
194
			//console.log("Chargement ok");
194
			//console.log("Chargement ok");
195
			chargerObs(depart+limite, station.obsNbre);
195
			chargerObs(depart+limite, station.obsNbre);
196
		});
196
		});
197
	} else {
197
	} else {
198
		if (pagineur.limite < total) {
198
		if (pagineur.limite < total) {
199
			afficherPagination();
199
			afficherPagination();
200
		} else {
200
		} else {
201
			surClicPagePagination(0, null);
201
			surClicPagePagination(0, null);
202
			selectionnerOnglet("#obs-vue-"+pagineur.format);
202
			selectionnerOnglet("#obs-vue-"+pagineur.format);
203
		}
203
		}
204
	}
204
	}
205
}
205
}
206
 
206
 
207
function actualiserInfosStation(infos) {
207
function actualiserInfosStation(infos) {
208
	station.commune = infos.commune;
208
	station.commune = infos.commune;
209
	station.obsNbre = infos.total;
209
	station.obsNbre = infos.total;
210
}
210
}
211
 
211
 
212
function actualiserPagineur() {
212
function actualiserPagineur() {
213
	pagineur.stationId = pointClique.stationId;
213
	pagineur.stationId = pointClique.stationId;
214
	pagineur.total = station.obsNbre;
214
	pagineur.total = station.obsNbre;
215
	//console.log("Total pagineur: "+pagineur.total);
215
	//console.log("Total pagineur: "+pagineur.total);
216
	if (pagineur.total > 4) {
216
	if (pagineur.total > 4) {
217
		pagineur.format = 'tableau';
217
		pagineur.format = 'tableau';
218
	} else {
218
	} else {
219
		pagineur.format = 'liste';
219
		pagineur.format = 'liste';
220
	}
220
	}
221
}
221
}
222
 
222
 
223
function afficherPagination(observations) {
223
function afficherPagination(observations) {
224
	$(".navigation").pagination(pagineur.total, {
224
	$(".navigation").pagination(pagineur.total, {
225
		items_per_page:pagineur.limite,
225
		items_per_page:pagineur.limite,
226
		callback:surClicPagePagination,
226
		callback:surClicPagePagination,
227
		next_text:'Suivant',
227
		next_text:'Suivant',
228
		prev_text:'Précédent',
228
		prev_text:'Précédent',
229
		prev_show_always:false,
229
		prev_show_always:false,
230
		num_edge_entries:1,
230
		num_edge_entries:1,
231
		num_display_entries:5,
231
		num_display_entries:4,
232
		load_first_page:true
232
		load_first_page:true
233
	});
233
	});
234
}
234
}
235
 
235
 
236
function surClicPagePagination(pageIndex, paginationConteneur) {
236
function surClicPagePagination(pageIndex, paginationConteneur) {
237
	var index = pageIndex * pagineur.limite;
237
	var index = pageIndex * pagineur.limite;
238
	var indexMax = index + pagineur.limite;
238
	var indexMax = index + pagineur.limite;
239
	pagineur.depart = index;
239
	pagineur.depart = index;
240
	obsPage = new Array();
240
	obsPage = new Array();
241
    for(index; index < indexMax; index++) {
241
    for(index; index < indexMax; index++) {
242
    	obsPage.push(obsStation[index]);
242
    	obsPage.push(obsStation[index]);
243
    }
243
    }
244
    
244
    
245
    supprimerMessageChargement();
245
    supprimerMessageChargement();
246
    mettreAJourObservations();
246
    mettreAJourObservations();
247
	return false;
247
	return false;
248
}
248
}
249
 
249
 
250
function mettreAJourObservations() {
250
function mettreAJourObservations() {
251
	$("#obs-"+pagineur.format+"-lignes").empty();
251
	$("#obs-"+pagineur.format+"-lignes").empty();
252
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
252
   	$("#obs-vue-"+pagineur.format).css('display', 'block');
253
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
253
   	$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
254
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
254
	$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
255
	
255
	
256
	// Actualisation de Fancybox
256
	// Actualisation de Fancybox
257
	ajouterFomulaireContact("a.contact");
257
	ajouterFomulaireContact("a.contact");
258
	if (pagineur.format == 'liste') {
258
	if (pagineur.format == 'liste') {
259
		ajouterGaleriePhoto("a.cel-img");
259
		ajouterGaleriePhoto("a.cel-img");
260
	}
260
	}
261
}
261
}
262
 
262
 
263
function creerTitreInfoBulle() {
263
function creerTitreInfoBulle() {
264
	$("#obs-total").append(station.obsNbre);
264
	$("#obs-total").text(station.obsNbre);
265
	$("#obs-commune").append(station.commune);	
265
	$("#obs-commune").text(station.commune);	
266
}
266
}
267
 
267
 
268
function initialiserContenuInfoBulle() {
268
function initialiserContenuInfoBulle() {
269
	afficherOnglets();
269
	afficherOnglets();
270
	afficherMessageChargement('#observations');
270
	afficherMessageChargement('#observations');
271
	ajouterTableauTriable("#obs-tableau");
271
	ajouterTableauTriable("#obs-tableau");
272
	afficherTextStationId();
272
	afficherTextStationId();
273
	corrigerLargeurInfoWindow();
273
	corrigerLargeurInfoWindow();
274
}
274
}
275
 
275
 
276
function afficherOnglets() {
276
function afficherOnglets() {
277
	var $tabs = $('#obs').tabs();
277
	var $tabs = $('#obs').tabs();
278
	$('#obs').bind('tabsselect', function(event, ui) {
278
	$('#obs').bind('tabsselect', function(event, ui) {
279
		if (ui.panel.id == 'obs-vue-tableau') {
279
		if (ui.panel.id == 'obs-vue-tableau') {
280
			surClicAffichageTableau();
280
			surClicAffichageTableau();
281
		} else if (ui.panel.id == 'obs-vue-liste') {
281
		} else if (ui.panel.id == 'obs-vue-liste') {
282
			surClicAffichageListe();
282
			surClicAffichageListe();
283
		}
283
		}
284
	});
284
	});
285
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
285
	$tabs.tabs('select', "#obs-vue-"+pagineur.format);
286
}
286
}
287
 
287
 
288
function selectionnerOnglet(onglet) {
288
function selectionnerOnglet(onglet) {
289
	$('#obs').tabs('select', onglet);
289
	$('#obs').tabs('select', onglet);
290
}
290
}
291
 
291
 
292
function afficherTextStationId() {
292
function afficherTextStationId() {
293
	$('#obs-station-id').text(pointClique.stationId);
293
	$('#obs-station-id').text(pointClique.stationId);
294
}
294
}
295
 
295
 
296
function corrigerLargeurInfoWindow() {
296
function corrigerLargeurInfoWindow() {
297
	$("#info-bulle").width($("#info-bulle").width() - 16);
297
	$("#info-bulle").width($("#info-bulle").width() - 17);
298
}
298
}
299
 
299
 
300
function surClicAffichageTableau(event) {
300
function surClicAffichageTableau(event) {
301
	//console.log('tableau');
301
	//console.log('tableau');
302
	pagineur.format = 'tableau';
302
	pagineur.format = 'tableau';
303
	mettreAJourObservations();
303
	mettreAJourObservations();
304
	mettreAJourTableauTriable("#obs-tableau");
304
	mettreAJourTableauTriable("#obs-tableau");
305
}
305
}
306
 
306
 
307
function surClicAffichageListe(event) {
307
function surClicAffichageListe(event) {
308
	//console.log('liste');
308
	//console.log('liste');
309
	pagineur.format = 'liste';
309
	pagineur.format = 'liste';
310
	mettreAJourObservations();
310
	mettreAJourObservations();
311
	ajouterGaleriePhoto("a.cel-img");
311
	ajouterGaleriePhoto("a.cel-img");
312
}
312
}
313
 
313
 
314
function ajouterTableauTriable(element) {
314
function ajouterTableauTriable(element) {
315
	// add parser through the tablesorter addParser method 
315
	// add parser through the tablesorter addParser method 
316
	$.tablesorter.addParser({ 
316
	$.tablesorter.addParser({ 
317
		// Définition d'un id unique pour ce parsseur 
317
		// Définition d'un id unique pour ce parsseur 
318
		id: 'date_cel', 
318
		id: 'date_cel', 
319
		is: function(s) { 
319
		is: function(s) { 
320
			// doit retourner false si le parsseur n'est pas autodétecté
320
			// doit retourner false si le parsseur n'est pas autodétecté
321
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
321
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
322
		}, 
322
		}, 
323
		format: function(date) { 
323
		format: function(date) { 
324
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
324
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
325
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
325
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
326
			// Remplace la date par un nombre de millisecondes pour trier numériquement
326
			// Remplace la date par un nombre de millisecondes pour trier numériquement
327
			return $.tablesorter.formatFloat(new Date(date).getTime());
327
			return $.tablesorter.formatFloat(new Date(date).getTime());
328
		}, 
328
		}, 
329
		// set type, either numeric or text 
329
		// set type, either numeric or text 
330
		type: 'numeric' 
330
		type: 'numeric' 
331
	});
331
	});
332
	$(element).tablesorter({ 
332
	$(element).tablesorter({ 
333
        headers: { 
333
        headers: { 
334
			1: { 
334
			1: { 
335
            	sorter:'date_cel' 
335
            	sorter:'date_cel' 
336
        	} 
336
        	} 
337
    	} 
337
    	} 
338
	});
338
	});
339
}
339
}
340
 
340
 
341
function mettreAJourTableauTriable(element) {
341
function mettreAJourTableauTriable(element) {
342
	$(element).trigger('update');
342
	$(element).trigger('update');
343
}
343
}
344
 
344
 
345
function ajouterGaleriePhoto(element) {
345
function ajouterGaleriePhoto(element) {
346
	$(element).fancybox({
346
	$(element).fancybox({
347
		transitionIn:'elastic',
347
		transitionIn:'elastic',
348
		transitionOut:'elastic',
348
		transitionOut:'elastic',
349
		speedIn	:600, 
349
		speedIn	:600, 
350
		speedOut:200,
350
		speedOut:200,
351
		overlayShow:true,
351
		overlayShow:true,
352
		titleShow:true,
352
		titleShow:true,
353
		titlePosition:'inside',
353
		titlePosition:'inside',
354
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
354
		titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
355
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
355
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
356
			motif.exec(titre);
356
			motif.exec(titre);
357
			var id = RegExp.$1;
357
			var id = RegExp.$1;
358
			var info = $('#cel-info-'+id).clone().html();
358
			var info = $('#cel-info-'+id).clone().html();
359
			var tpl = 
359
			var tpl = 
360
				'<div class="cel-legende">'+
360
				'<div class="cel-legende">'+
361
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
361
				'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
362
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
362
				(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
363
				'<\/div>';
363
				'<\/div>';
364
			return tpl;
364
			return tpl;
365
		}
365
		}
366
		}).live('click', function(e) {
366
		}).live('click', function(e) {
367
			if (e.stopPropagation) {
367
			if (e.stopPropagation) {
368
				e.stopPropagation();
368
				e.stopPropagation();
369
			}
369
			}
370
			return false;
370
			return false;
371
		});
371
		});
372
}
372
}
373
 
373
 
374
function ajouterFomulaireContact(element) {
374
function ajouterFomulaireContact(element) {
375
	$(element).fancybox({
375
	$(element).fancybox({
376
		transitionIn:'elastic',
376
		transitionIn:'elastic',
377
		transitionOut:'elastic',
377
		transitionOut:'elastic',
378
		speedIn	:600, 
378
		speedIn	:600, 
379
		speedOut:200,
379
		speedOut:200,
380
		scrolling: 'no',
380
		scrolling: 'no',
381
		titleShow: false,
381
		titleShow: false,
382
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
382
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
383
			var element = selectedArray[selectedIndex];
383
			var element = selectedArray[selectedIndex];
384
 
384
 
385
			var motif = / contributeur-([0-9]+)$/;
385
			var motif = / contributeur-([0-9]+)$/;
386
			motif.exec($(element).attr('class'));
386
			motif.exec($(element).attr('class'));
387
			var id = RegExp.$1;
387
			var id = RegExp.$1;
388
			//console.log('Destinataire id : '+id);
388
			//console.log('Destinataire id : '+id);
389
			$("#fc_destinataire_id").attr('value', id);
389
			$("#fc_destinataire_id").attr('value', id);
390
		
390
		
391
			var motif = / obs-([0-9]+) /;
391
			var motif = / obs-([0-9]+) /;
392
			motif.exec($(element).attr('class'));
392
			motif.exec($(element).attr('class'));
393
			var id = RegExp.$1;
393
			var id = RegExp.$1;
394
			//console.log('Obs id : '+id);
394
			//console.log('Obs id : '+id);
395
			chargerInfoObsPourMessage(id);
395
			chargerInfoObsPourMessage(id);
396
		},
396
		},
397
		onCleanup: function() {
397
		onCleanup: function() {
398
			//console.log('Avant fermeture fancybox');
398
			//console.log('Avant fermeture fancybox');
399
			$("#fc_destinataire_id").attr('value', '');
399
			$("#fc_destinataire_id").attr('value', '');
400
			$("#fc_sujet").attr('value', '');
400
			$("#fc_sujet").attr('value', '');
401
			$("#fc_message").text('');
401
			$("#fc_message").text('');
402
		},
402
		},
403
		onClosed: function(e) {
403
		onClosed: function(e) {
404
			//console.log('Fermeture fancybox');
404
			//console.log('Fermeture fancybox');
405
			if (e.stopPropagation) {
405
			if (e.stopPropagation) {
406
				e.stopPropagation();
406
				e.stopPropagation();
407
			}
407
			}
408
			return false;
408
			return false;
409
		}
409
		}
410
	});
410
	});
411
}
411
}
412
 
412
 
413
function chargerInfoObsPourMessage(idObs) {
413
function chargerInfoObsPourMessage(idObs) {
414
	var sujet = "Remarque sur l'observation #"+idObs;
414
	var nomSci = trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
415
	var message = "--\nConcerne l'observation de "+ 
415
	var date = trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
416
		' "'+trim($("#cel-obs-"+idObs+" .nom-sci").text())+'" '+
416
	var lieu = trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
417
		'du "'+trim($("#cel-obs-"+idObs+" .date").text())+'" '+
417
	var sujet = "Observation #"+idObs+" de "+nomSci;
418
		'au lieu "'+trim($("#cel-obs-"+idObs+" .lieu").text())+'".';
418
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
419
	$("#fc_sujet").attr('value', sujet);
419
	$("#fc_sujet").attr('value', sujet);
420
	$("#fc_message").text(message);
420
	$("#fc_message").text(message);
421
}
421
}
422
 
422
 
423
function initialiserFormulaireContact() {
423
function initialiserFormulaireContact() {
424
	//console.log('Initialisation du form contact');
424
	//console.log('Initialisation du form contact');
425
	$("#form-contact").validate({
425
	$("#form-contact").validate({
426
		rules: {
426
		rules: {
427
			fc_sujet : "required",
427
			fc_sujet : "required",
428
			fc_message : "required",
428
			fc_message : "required",
429
			fc_courriel : {
429
			fc_utilisateur_courriel : {
430
			required : true,
430
				required : true,
431
			email : true}
431
				email : true}
432
		}
432
		}
433
	});
433
	});
434
	$("#form-contact").bind("submit", envoyerCourriel);
434
	$("#form-contact").bind("submit", envoyerCourriel);
435
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
435
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
436
	
436
	
437
}
437
}
438
 
438
 
439
function envoyerCourriel() {
439
function envoyerCourriel() {
440
	//console.log('Formulaire soumis');
440
	//console.log('Formulaire soumis');
441
	if ($("#form-contact").valid()) {
441
	if ($("#form-contact").valid()) {
442
		//console.log('Formulaire valide');
442
		//console.log('Formulaire valide');
443
		//$.fancybox.showActivity();
443
		//$.fancybox.showActivity();
444
		var destinataireId = $("#fc_destinataire_id").attr('value');
444
		var destinataireId = $("#fc_destinataire_id").attr('value');
445
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
445
		var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
446
		var erreurMsg = "";
446
		var erreurMsg = "";
447
		var donnees = new Array();
447
		var donnees = new Array();
448
		$.each($(this).serializeArray(), function (index, champ) {
448
		$.each($(this).serializeArray(), function (index, champ) {
449
			var cle = champ.name;
449
			var cle = champ.name;
450
			cle = cle.replace(/^fc_/, '');
450
			cle = cle.replace(/^fc_/, '');
-
 
451
			
-
 
452
			if (cle = 'sujet') {
-
 
453
				champ.value += " - Carnet en ligne - Tela Botanica";
-
 
454
			}
451
			//console.log('Clé:'+cle);
455
			if (cle == 'message') {
-
 
456
				champ.value += "\n--\n"+
-
 
457
					"Ce message vous est envoyé par l'intermédiaire du widget Cartographique "+
-
 
458
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
-
 
459
					"http://www.tela-botanica.org/widget:cel:carto";
-
 
460
			}
-
 
461
			
452
			donnees[index] = {'name':cle,'value':champ.value};
462
			donnees[index] = {'name':cle,'value':champ.value};
453
		});
463
		});
454
		$.ajax({
464
		$.ajax({
455
			type : "POST",
465
			type : "POST",
456
			cache : false,
466
			cache : false,
457
			url : urlMessage,
467
			url : urlMessage,
458
			data : donnees,
468
			data : donnees,
459
			beforeSend : function() {
469
			beforeSend : function() {
460
				$(".msg").remove();
470
				$(".msg").remove();
461
			},
471
			},
462
			success : function(data) {
472
			success : function(data) {
463
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
473
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
464
			},
474
			},
465
			error : function(jqXHR, textStatus, errorThrown) {
475
			error : function(jqXHR, textStatus, errorThrown) {
466
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
476
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
467
				reponse = jQuery.parseJSON(jqXHR.responseText);
477
				reponse = jQuery.parseJSON(jqXHR.responseText);
468
				if (reponse != null) {
478
				if (reponse != null) {
469
					$.each(reponse, function (cle, valeur) {
479
					$.each(reponse, function (cle, valeur) {
470
						erreurMsg += valeur + "\n";
480
						erreurMsg += valeur + "\n";
471
					});
481
					});
472
				}				
482
				}				
473
			},
483
			},
474
			complete : function(jqXHR, textStatus) {
484
			complete : function(jqXHR, textStatus) {
475
				var debugMsg = '';
485
				var debugMsg = '';
476
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
486
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
477
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
487
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
478
					if (debugInfos != null) {
488
					if (debugInfos != null) {
479
						$.each(debugInfos, function (cle, valeur) {
489
						$.each(debugInfos, function (cle, valeur) {
480
							debugMsg += valeur + "\n";
490
							debugMsg += valeur + "\n";
481
						});
491
						});
482
					}
492
					}
483
				}
493
				}
484
				if (erreurMsg != '') {
494
				if (erreurMsg != '') {
485
					$("#fc-zone-dialogue").append('<p class="msg">'+
495
					$("#fc-zone-dialogue").append('<p class="msg">'+
486
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
496
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
487
							'Vous pouvez signaler le disfonctionnement à <a href="'+
497
							'Vous pouvez signaler le disfonctionnement à <a href="'+
488
							'mailto:cel@tela-botanica.org'+'?'+
498
							'mailto:cel@tela-botanica.org'+'?'+
489
							'subject=Disfonctionnement du widget de Cartographie'+
499
							'subject=Disfonctionnement du widget de Cartographie'+
490
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
500
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
491
							'">cel@tela-botanica.org</a>.'+
501
							'">cel@tela-botanica.org</a>.'+
492
							'</p>');
502
							'</p>');
493
				}
503
				}
494
				if (DEBUG) {
504
				if (DEBUG) {
495
					console.log('Débogage : '+debugMsg);
505
					console.log('Débogage : '+debugMsg);
496
				}
506
				}
497
				//console.log('Débogage : '+debugMsg);
507
				//console.log('Débogage : '+debugMsg);
498
				//console.log('Erreur : '+erreurMsg);
508
				//console.log('Erreur : '+erreurMsg);
499
			}
509
			}
500
		});
510
		});
501
	}
511
	}
502
	return false;
512
	return false;
503
}
513
}
504
/*+--------------------------------------------------------------------------------------------------------+*/
514
/*+--------------------------------------------------------------------------------------------------------+*/
505
// PANNEAU LATÉRAL
515
// PANNEAU LATÉRAL
506
 
516
 
507
function initialiserAffichagePanneauLateral() {
517
function initialiserAffichagePanneauLateral() {
508
	$('#panneau-lateral').height($(window).height() - 35);
518
	$('#panneau-lateral').height($(window).height() - 35);
509
	
519
	
510
	if (nt == '*') {
520
	if (nt == '*') {
511
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
521
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
512
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
522
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
513
	}
523
	}
514
	chargerTaxons(0, 0);
524
	chargerTaxons(0, 0);
515
}
525
}
516
 
526
 
517
function chargerTaxons(depart, total) {
527
function chargerTaxons(depart, total) {
518
	if (depart == 0 || depart < total) {
528
	if (depart == 0 || depart < total) {
519
		var limite = 7000;
529
		var limite = 7000;
520
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
530
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
521
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
531
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
522
		urlTax = urlTax.replace(/\{start\}/g, depart);
532
		urlTax = urlTax.replace(/\{start\}/g, depart);
523
		$.getJSON(urlTax, function(infos) {
533
		$.getJSON(urlTax, function(infos) {
524
			taxonsCarte = taxonsCarte.concat(infos.taxons);
534
			taxonsCarte = taxonsCarte.concat(infos.taxons);
525
			//console.log("Nbre taxons :"+taxonsCarte.length);
535
			//console.log("Nbre taxons :"+taxonsCarte.length);
526
			chargerTaxons(depart+limite, infos.total);
536
			chargerTaxons(depart+limite, infos.total);
527
		});
537
		});
528
	} else {
538
	} else {
529
		if (nt == '*') {
539
		if (nt == '*') {
530
			afficherTaxons();
540
			afficherTaxons();
531
		} else {
541
		} else {
532
			afficherNomPlante();
542
			afficherNomPlante();
533
		}
543
		}
534
	}
544
	}
535
}
545
}
536
 
546
 
537
function afficherTaxons() {
547
function afficherTaxons() {
538
	// Ajout du nombre de plantes au titre
548
	// Ajout du nombre de plantes au titre
539
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
549
	$('.plantes-nbre').text(taxonsCarte.length.formaterNombre());
540
	
550
	
541
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
551
	$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
542
	$('.taxon').live('click', filtrerParTaxon);
552
	$('.taxon').live('click', filtrerParTaxon);
543
}
553
}
544
 
554
 
545
function afficherNomPlante() {
555
function afficherNomPlante() {
546
	if (nt != '*') {
556
	if (nt != '*') {
547
		var taxon = taxonsCarte[0];
557
		var taxon = taxonsCarte[0];
548
		$('.plante-titre').text('pour '+taxon.nom);
558
		$('.plante-titre').text('pour '+taxon.nom);
549
	}
559
	}
550
}
560
}
551
 
561
 
552
function afficherPanneauLateral() {
562
function afficherPanneauLateral() {
553
	$('#panneau-lateral').width(300);
563
	$('#panneau-lateral').width(300);
554
	$('#pl-contenu').css('display', 'block');
564
	$('#pl-contenu').css('display', 'block');
555
	$('#pl-ouverture').css('display', 'none');
565
	$('#pl-ouverture').css('display', 'none');
556
	$('#pl-fermeture').css('display', 'block');
566
	$('#pl-fermeture').css('display', 'block');
557
	$('#carte').css('left', '300px');
567
	$('#carte').css('left', '300px');
558
 
568
 
559
	google.maps.event.trigger(map, 'resize');
569
	google.maps.event.trigger(map, 'resize');
560
};
570
};
561
 
571
 
562
function cacherPanneauLateral() {
572
function cacherPanneauLateral() {
563
	$('#panneau-lateral').width(24);
573
	$('#panneau-lateral').width(24);
564
	$('#pl-contenu').css('display', 'none');
574
	$('#pl-contenu').css('display', 'none');
565
	$('#pl-ouverture').css('display', 'block');
575
	$('#pl-ouverture').css('display', 'block');
566
	$('#pl-fermeture').css('display', 'none');
576
	$('#pl-fermeture').css('display', 'none');
567
	$('#carte').css('left', '24px');
577
	$('#carte').css('left', '24px');
568
	
578
	
569
	google.maps.event.trigger(map, 'resize');
579
	google.maps.event.trigger(map, 'resize');
570
};
580
};
571
 
581
 
572
function ouvrirPopUp(url, nom) {
582
function ouvrirPopUp(url, nom) {
573
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
583
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
574
};
584
};
575
 
585
 
576
function filtrerParTaxon() {
586
function filtrerParTaxon() {
577
	var ntAFiltrer = $('.nt', this).text();
587
	var ntAFiltrer = $('.nt', this).text();
578
	infoBulle.close();
588
	infoBulle.close();
579
	$('#taxon-'+nt).removeClass('taxon-actif');
589
	$('#taxon-'+nt).removeClass('taxon-actif');
580
	if (nt == ntAFiltrer) {
590
	if (nt == ntAFiltrer) {
581
		nt = '*';
591
		nt = '*';
582
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
592
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
583
	} else {
593
	} else {
584
		var url = stationsUrl+'&'+
594
		var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer)+
585
			'num_taxon='+ntAFiltrer+'&'+
-
 
586
			'formatRetour=jsonP'+'&'+
595
			'&formatRetour=jsonP'+
587
			'callback=?';
596
			'&callback=?';
588
		$.getJSON(url, function (stationsFiltrees) {
597
		$.getJSON(url, function (stationsFiltrees) {
589
			stations = stationsFiltrees;
598
			stations = stationsFiltrees;
590
			nt = ntAFiltrer;
599
			nt = ntAFiltrer;
591
			$('#taxon-'+nt).addClass('taxon-actif');
600
			$('#taxon-'+nt).addClass('taxon-actif');
592
			rafraichirCarte();
601
			rafraichirCarte();
593
		});
602
		});
594
	}
603
	}
595
};
604
};
596
 
605
 
597
/*+--------------------------------------------------------------------------------------------------------+*/
606
/*+--------------------------------------------------------------------------------------------------------+*/
598
// FONCTIONS UTILITAIRES
607
// FONCTIONS UTILITAIRES
599
 
608
 
600
function arreter(event) {
609
function arreter(event) {
601
	if (event.stopPropagation) {
610
	if (event.stopPropagation) {
602
		event.stopPropagation();
611
		event.stopPropagation();
603
	} else if (window.event) {
612
	} else if (window.event) {
604
		window.event.cancelBubble = true;
613
		window.event.cancelBubble = true;
605
	}
614
	}
606
	return false;
615
	return false;
607
}
616
}
608
 
617
 
609
/**
618
/**
610
 * +-------------------------------------+
619
 * +-------------------------------------+
611
 * Number.prototype.formaterNombre
620
 * Number.prototype.formaterNombre
612
 * +-------------------------------------+
621
 * +-------------------------------------+
613
 * Params (facultatifs):
622
 * Params (facultatifs):
614
 * - Int decimales: nombre de decimales (exemple: 2)
623
 * - Int decimales: nombre de decimales (exemple: 2)
615
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
624
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
616
 * - String separateurMilliers: comme son nom l'indique
625
 * - String separateurMilliers: comme son nom l'indique
617
 * Returns:
626
 * Returns:
618
 * - String chaine formatee
627
 * - String chaine formatee
619
 * @author	::mastahbenus::
628
 * @author	::mastahbenus::
620
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
629
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
621
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
630
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
622
 */
631
 */
623
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
632
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
624
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
633
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
625
	
634
	
626
	function is_int(nbre) {
635
	function is_int(nbre) {
627
		nbre = nbre.replace(',', '.');
636
		nbre = nbre.replace(',', '.');
628
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
637
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
629
	}
638
	}
630
 
639
 
631
	if (decimales == undefined) {
640
	if (decimales == undefined) {
632
		if (is_int(_sNombre)) {
641
		if (is_int(_sNombre)) {
633
			decimales = 0;
642
			decimales = 0;
634
		} else {
643
		} else {
635
			decimales = 2;
644
			decimales = 2;
636
		}
645
		}
637
	}
646
	}
638
	if (signe == undefined) {
647
	if (signe == undefined) {
639
		if (is_int(_sNombre)) {
648
		if (is_int(_sNombre)) {
640
			signe = '';
649
			signe = '';
641
		} else {
650
		} else {
642
			signe = '.';
651
			signe = '.';
643
		}
652
		}
644
	}
653
	}
645
	if (separateurMilliers == undefined) {
654
	if (separateurMilliers == undefined) {
646
		separateurMilliers = ' ';
655
		separateurMilliers = ' ';
647
	}
656
	}
648
	
657
	
649
	function separeMilliers (sNombre) {
658
	function separeMilliers (sNombre) {
650
		var sRetour = "";
659
		var sRetour = "";
651
		while (sNombre.length % 3 != 0) {
660
		while (sNombre.length % 3 != 0) {
652
			sNombre = "0"+sNombre;
661
			sNombre = "0"+sNombre;
653
		}
662
		}
654
		for (i = 0; i < sNombre.length; i += 3) {
663
		for (i = 0; i < sNombre.length; i += 3) {
655
			if (i == sNombre.length-1) separateurMilliers = '';
664
			if (i == sNombre.length-1) separateurMilliers = '';
656
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
665
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
657
		}
666
		}
658
		while (sRetour.substr(0, 1) == "0") {
667
		while (sRetour.substr(0, 1) == "0") {
659
			sRetour = sRetour.substr(1);
668
			sRetour = sRetour.substr(1);
660
		}
669
		}
661
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
670
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
662
	}
671
	}
663
	
672
	
664
	if (_sNombre.indexOf('.') == -1) {
673
	if (_sNombre.indexOf('.') == -1) {
665
		for (i = 0; i < decimales; i++) {
674
		for (i = 0; i < decimales; i++) {
666
			_sDecimales += "0";
675
			_sDecimales += "0";
667
		}
676
		}
668
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
677
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
669
	} else {
678
	} else {
670
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
679
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
671
		if (sDecimalesTmp.length > decimales) {
680
		if (sDecimalesTmp.length > decimales) {
672
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
681
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
673
			var nDiv = 1;
682
			var nDiv = 1;
674
			for (i = 0; i < nDecimalesManquantes; i++) {
683
			for (i = 0; i < nDecimalesManquantes; i++) {
675
				nDiv *= 10;
684
				nDiv *= 10;
676
			}
685
			}
677
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
686
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
678
		}
687
		}
679
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
688
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
680
	}
689
	}
681
	return _sRetour;
690
	return _sRetour;
682
}
691
}
683
 
692
 
684
function debug(objet) {
693
function debug(objet) {
685
	var msg = '';
694
	var msg = '';
686
	if (objet != null) {
695
	if (objet != null) {
687
		$.each(objet, function (cle, valeur) {
696
		$.each(objet, function (cle, valeur) {
688
			msg += cle+":"+valeur + "\n";
697
			msg += cle+":"+valeur + "\n";
689
		});
698
		});
690
	} else {
699
	} else {
691
		msg = "La variable vaut null.";
700
		msg = "La variable vaut null.";
692
	}
701
	}
693
	console.log(msg);
702
	console.log(msg);
694
}
703
}
695
 
704
 
696
function trim (chaine) {
705
function trim (chaine) {
697
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
706
	return chaine.replace(/^\s+/g, '').replace(/\s+$/g, '');
698
}
707
}