Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 836 Rev 841
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
3
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
4
var pointsOrigine = null;
4
var pointsOrigine = null;
5
var boundsOrigine = null;
5
var boundsOrigine = null;
6
var markerClusterer = null;
6
var markerClusterer = null;
7
var map = null;
7
var map = null;
8
var infoBulle = new google.maps.InfoWindow();
8
var infoBulle = new google.maps.InfoWindow();
9
var pointClique = null;
9
var pointClique = null;
10
var carteCentre = new google.maps.LatLng(46.4, 3.10);
10
var carteCentre = new google.maps.LatLng(46.4, 3.10);
11
var carteOptions = {
11
var carteOptions = {
12
	zoom: 6,
12
	zoom: 6,
13
	mapTypeId: google.maps.MapTypeId.ROADMAP,
13
	mapTypeId: google.maps.MapTypeId.ROADMAP,
14
	mapTypeControlOptions: {
14
	mapTypeControlOptions: {
15
		mapTypeIds: ['OSM', 
15
		mapTypeIds: ['OSM', 
16
		             google.maps.MapTypeId.ROADMAP, 
16
		             google.maps.MapTypeId.ROADMAP, 
17
		             google.maps.MapTypeId.HYBRID, 
17
		             google.maps.MapTypeId.HYBRID, 
18
		             google.maps.MapTypeId.SATELLITE, 
18
		             google.maps.MapTypeId.SATELLITE, 
19
		             google.maps.MapTypeId.TERRAIN]
19
		             google.maps.MapTypeId.TERRAIN]
20
	}
20
	}
21
};			
21
};			
22
var ctaLayer = null;
22
var ctaLayer = null;
23
var osmMapType = new google.maps.ImageMapType({
23
var osmMapType = new google.maps.ImageMapType({
24
	getTileUrl: function(coord, zoom) {
24
	getTileUrl: function(coord, zoom) {
25
		return "http://tile.openstreetmap.org/" +
25
		return "http://tile.openstreetmap.org/" +
26
		zoom + "/" + coord.x + "/" + coord.y + ".png";
26
		zoom + "/" + coord.x + "/" + coord.y + ".png";
27
	},
27
	},
28
	tileSize: new google.maps.Size(256, 256),
28
	tileSize: new google.maps.Size(256, 256),
29
	isPng: true,
29
	isPng: true,
30
	alt: "OpenStreetMap",
30
	alt: "OpenStreetMap",
31
	name: "OSM",
31
	name: "OSM",
32
	maxZoom: 19
32
	maxZoom: 19
33
});
33
});
34
 
34
 
35
/*+--------------------------------------------------------------------------------------------------------+*/
35
/*+--------------------------------------------------------------------------------------------------------+*/
36
// INITIALISATION DU CODE
36
// INITIALISATION DU CODE
37
 
37
 
38
 
38
 
39
//Déclenchement d'actions quand JQuery et le document HTML sont OK
39
//Déclenchement d'actions quand JQuery et le document HTML sont OK
40
$(document).ready(function() {
40
$(document).ready(function() {
41
	initialiserWidget();
41
	initialiserWidget();
42
});
42
});
43
/*+--------------------------------------------------------------------------------------------------------+*/
43
/*+--------------------------------------------------------------------------------------------------------+*/
44
// FONCTIONS
44
// FONCTIONS
45
 
45
 
46
function initialiserWidget() {
46
function initialiserWidget() {
47
	afficherStats();
47
	afficherStats();
48
	initialiserAffichageCarte();
48
	initialiserAffichageCarte();
49
	initialiserAffichagePanneauLateral();
49
	initialiserAffichagePanneauLateral();
50
	
50
	
51
	initialiserCarte();
51
	initialiserCarte();
52
	initialiserInfoBulle();
52
	initialiserInfoBulle();
53
	chargerLimitesCommunales();
53
	chargerLimitesCommunales();
54
	rafraichirCarte();
54
	rafraichirCarte();
55
}
55
}
56
 
56
 
57
function afficherStats() {
57
function afficherStats() {
58
	// Ajout du nombre de communes où des observations ont eu lieu
58
	// Ajout du nombre de communes où des observations ont eu lieu
59
	$('#commune-nbre').append(obs.stats.communes.formaterNombre());
59
	$('#commune-nbre').append(obs.stats.communes.formaterNombre());
60
	// Ajout du nombre d'observations
60
	// Ajout du nombre d'observations
61
	$('#obs-nbre').append(obs.stats.observations.formaterNombre());
61
	$('#obs-nbre').append(obs.stats.observations.formaterNombre());
62
	// Ajout du nombre de plantes
62
	// Ajout du nombre de plantes
63
	$('.plantes-nbre').append(plantesNbre.formaterNombre());
63
	$('.plantes-nbre').append(plantesNbre.formaterNombre());
64
}
64
}
65
 
65
 
66
function initialiserAffichageCarte() {
66
function initialiserAffichageCarte() {
67
	$('#carte').height($(window).height() - 35);
67
	$('#carte').height($(window).height() - 35);
68
	$('#carte').width($(window).width() - 24);
68
	$('#carte').width($(window).width() - 24);
69
	
69
	
70
	if (nt != '*') {
70
	if (nt != '*') {
71
		$('#carte').css('left', 0);
71
		$('#carte').css('left', 0);
72
	}
72
	}
73
}
73
}
74
 
74
 
75
function initialiserAffichagePanneauLateral() {
75
function initialiserAffichagePanneauLateral() {
76
	$('#panneau-lateral').height($(window).height() - 35);
76
	$('#panneau-lateral').height($(window).height() - 35);
77
	
77
	
78
	if (nt == '*') {
78
	if (nt == '*') {
79
		$('#pl-ouverture').bind('click', afficher);
79
		$('#pl-ouverture').bind('click', afficher);
80
		$('#pl-fermeture').bind('click', cacher);
80
		$('#pl-fermeture').bind('click', cacher);
81
		$('.taxon').live('click', filtrerParTaxon);
81
		$('.taxon').live('click', filtrerParTaxon);
82
	}
82
	}
83
}
83
}
84
 
84
 
85
function initialiserCarte() {
85
function initialiserCarte() {
86
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
86
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
87
	// Ajout de la couche OSM à la carte
87
	// Ajout de la couche OSM à la carte
88
	map.mapTypes.set('OSM', osmMapType);
88
	map.mapTypes.set('OSM', osmMapType);
89
}
89
}
90
 
90
 
91
function initialiserInfoBulle() {
91
function initialiserInfoBulle() {
92
	google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle);
92
	google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle);
93
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
93
	google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
94
}
94
}
95
 
95
 
96
function chargerLimitesCommunales() {
96
function chargerLimitesCommunales() {
97
	if (urlsLimitesCommunales != null) {
97
	if (urlsLimitesCommunales != null) {
98
		for (urlId in urlsLimitesCommunales) { 
98
		for (urlId in urlsLimitesCommunales) { 
99
			var url = urlsLimitesCommunales[urlId];
99
			var url = urlsLimitesCommunales[urlId];
100
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
100
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
101
			ctaLayer.setMap(map);
101
			ctaLayer.setMap(map);
102
		}
102
		}
103
	}
103
	}
104
}
104
}
105
 
105
 
106
function rafraichirCarte() {
106
function rafraichirCarte() {
107
	var points = [];
107
	var points = [];
108
	var bounds = new google.maps.LatLngBounds();
108
	var bounds = new google.maps.LatLngBounds();
109
	for (var i = 0; i < obs.stats.communes; ++i) {
109
	for (var i = 0; i < obs.stats.communes; ++i) {
110
		var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y);
110
		var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y);
111
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
111
		var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
112
		var point = new google.maps.Marker({
112
		var point = new google.maps.Marker({
113
			position: maLatLng,
113
			position: maLatLng,
114
			map: map,
114
			map: map,
115
			icon: pointImage,
115
			icon: pointImage,
116
			stationId: obs.points[i].id
116
			stationId: obs.points[i].id
117
		});
117
		});
118
 
118
 
119
		bounds.extend(maLatLng);
119
		bounds.extend(maLatLng);
120
		
120
		
121
		google.maps.event.addListener(point, 'click', function() {
121
		google.maps.event.addListener(point, 'click', function() {
122
			pointClique =  this;
122
			pointClique =  this;
123
			
123
			
124
			infoBulle.open(map, this);
124
			infoBulle.open(map, this);
125
			
125
			
126
			var limites = map.getBounds();
126
			var limites = map.getBounds();
127
			var centre = limites.getCenter();
127
			var centre = limites.getCenter();
128
			var nordEst = limites.getNorthEast();
128
			var nordEst = limites.getNorthEast();
129
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
129
			var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
130
			map.panTo(centreSudLatLng);
130
			map.panTo(centreSudLatLng);
131
			
131
			
132
			afficherMsgChargement();
132
			afficherMsgChargement();
133
			chargerFormatObs(this.stationId, '*');
133
			chargerFormatObs(this.stationId, '*');
134
		});
134
		});
135
		
135
		
136
		points.push(point);
136
		points.push(point);
137
	}
137
	}
138
 
138
 
139
	if (pointsOrigine == null && boundsOrigine == null) {
139
	if (pointsOrigine == null && boundsOrigine == null) {
140
		pointsOrigine = points;
140
		pointsOrigine = points;
141
		boundsOrigine = bounds;
141
		boundsOrigine = bounds;
142
	}
142
	}
143
	
143
	
144
	executerMarkerClusterer(points, bounds);
144
	executerMarkerClusterer(points, bounds);
145
}
145
}
146
 
146
 
147
function modifierContenuInfoBulle() {
147
function modifierContenuInfoBulle() {
148
	// Onglet Tableau : Jquery => TableSorter
148
	// Onglet Tableau : Jquery => TableSorter
149
	if ($("#observations table").get() != '') {
149
	if ($("#observations table").get() != '') {
150
		ajouterTableauTriable("#observations table");
150
		ajouterTableauTriable("#observations table");
151
	}
151
	}
152
	// Onglet Liste : Jquery => FancyBox
152
	// Onglet Liste : Jquery => FancyBox
153
	if ($("#observations ol").get() != '') {
153
	if ($("#observations ol").get() != '') {
154
		ajouterGaleriePhoto("a.cel-img");
154
		ajouterGaleriePhoto("a.cel-img");
155
	}
155
	}
156
}
156
}
157
 
157
 
158
function ajouterTableauTriable(element) {
158
function ajouterTableauTriable(element) {
159
	// add parser through the tablesorter addParser method 
159
	// add parser through the tablesorter addParser method 
160
	$.tablesorter.addParser({ 
160
	$.tablesorter.addParser({ 
161
		// Définition d'un id unique pour ce parsseur 
161
		// Définition d'un id unique pour ce parsseur 
162
		id: 'date_cel', 
162
		id: 'date_cel', 
163
		is: function(s) { 
163
		is: function(s) { 
164
			// retourne false si le parsseur n'est pas autodétecté 
164
			// retourne false si le parsseur n'est pas autodétecté 
165
			return false; 
165
			return false; 
166
		}, 
166
		}, 
167
		format: function(s) { 
167
		format: function(s) { 
168
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
168
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
169
			s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
169
			s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
170
			// Remplace la date par un nombre de millisecondes pour trier numériquement
170
			// Remplace la date par un nombre de millisecondes pour trier numériquement
171
			return $.tablesorter.formatFloat(new Date(s).getTime());
171
			return $.tablesorter.formatFloat(new Date(s).getTime());
172
		}, 
172
		}, 
173
		// set type, either numeric or text 
173
		// set type, either numeric or text 
174
		type: 'numeric' 
174
		type: 'numeric' 
175
	});
175
	});
176
	$(element).tablesorter({ 
176
	$(element).tablesorter({ 
177
        headers: { 
177
        headers: { 
178
            1: { 
178
            1: { 
179
                sorter:'date_cel' 
179
                sorter:'date_cel' 
180
            } 
180
            } 
181
        } 
181
        } 
182
    });
182
    });
183
}
183
}
184
 
184
 
185
function ajouterGaleriePhoto(element) {
185
function ajouterGaleriePhoto(element) {
186
	$(element).fancybox({
186
	$(element).fancybox({
187
		transitionIn : 'elastic',
187
		transitionIn : 'elastic',
188
		transitionOut : 'elastic',
188
		transitionOut : 'elastic',
189
		speedIn	 : 600, 
189
		speedIn	 : 600, 
190
		speedOut : 200, 
190
		speedOut : 200, 
191
		overlayShow : true
191
		overlayShow : true
192
	}).live('click', function(e) {
192
	}).live('click', function(e) {
193
		if (e.stopPropagation) {
193
		if (e.stopPropagation) {
194
			e.stopPropagation();
194
			e.stopPropagation();
195
		}
195
		}
196
		return false;
196
		return false;
197
	});
197
	});
198
}
198
}
199
 
199
 
200
function deplacerCartePointClique() {
200
function deplacerCartePointClique() {
201
	map.panTo(pointClique.position);
201
	map.panTo(pointClique.position);
202
}
202
}
203
 
203
 
204
function executerMarkerClusterer(points, bounds) {
204
function executerMarkerClusterer(points, bounds) {
205
	if (markerClusterer) {
205
	if (markerClusterer) {
206
		markerClusterer.clearMarkers();
206
		markerClusterer.clearMarkers();
207
	}
207
	}
208
	markerClusterer = new MarkerClusterer(map, points);
208
	markerClusterer = new MarkerClusterer(map, points);
209
	map.fitBounds(bounds);
209
	map.fitBounds(bounds);
210
}
210
}
211
 
211
 
212
function afficherMsgChargement() {
212
function afficherMsgChargement() {
213
	var chargement = document.getElementById('chargement').cloneNode(true);
213
	var chargement = document.getElementById('chargement').cloneNode(true);
214
	chargement.setAttribute('id', 'chargement-copie');
214
	chargement.setAttribute('id', 'chargement-copie');
215
	infoBulle.setContent(chargement);
215
	infoBulle.setContent(chargement);
216
}
216
}
-
 
217
 
-
 
218
var pagineur = {'limite':150, 'obsTotal':0, 'stationId':null, 'format':null};
-
 
219
 
-
 
220
function handlePaginationClick(new_page_index, pagination_container) {
-
 
221
	$('.obs-liste-conteneur').css('display', 'none');
-
 
222
	$('#chargement').clone().attr('id', 'chargement-copie').appendTo('#observations').css('display', 'block');
-
 
223
	console.log($('#chargement').get());
-
 
224
	
-
 
225
	var start = new_page_index * pagineur.limite;
-
 
226
	var url = urlObs+
-
 
227
	'&format='+pagineur.format+
-
 
228
	'&station='+pagineur.stationId+
-
 
229
	'&start='+start+
-
 
230
	'&limit='+pagineur.limite;
-
 
231
	$.get(url, function(observations) {
-
 
232
		$('#chargement-copie').remove();
-
 
233
		$('.obs-liste-conteneur').css('display', 'block');
-
 
234
		$('#obs-liste').empty();
-
 
235
		$('#obs-liste').append(observations);
-
 
236
	});
-
 
237
	return false;
-
 
238
}
217
 
239
 
-
 
240
function chargerFormatObs(stationId, format) {
-
 
241
	pagineur.obsTotal = parseInt($('#obs-total').text());
-
 
242
	pagineur.stationId = stationId;
-
 
243
	pagineur.format = format;
-
 
244
	
218
function chargerFormatObs(stationId, format) {
245
	var start = 1 * pagineur.limite;
219
	var url = urlObsStation+
246
	var url = urlStation+
220
		'&format='+format+'&'+
247
		'&format='+format+
-
 
248
		'&station='+stationId+
-
 
249
		'&start='+start+
221
		'station='+stationId;
250
		'&limit='+pagineur.limite;
222
	$.get(url, function(observations){
251
	$.get(url, function(observations){
-
 
252
		infoBulle.setContent(observations);
-
 
253
		// First Parameter: number of items
-
 
254
		// Second Parameter: options object
-
 
255
		$("#pagination").pagination(pagineur.obsTotal, {
-
 
256
			items_per_page:pagineur.limite,
-
 
257
			callback:handlePaginationClick
223
		infoBulle.setContent(observations);
258
		});
224
	});
259
	});
225
}
260
}
226
 
261
 
227
function arreter(event) {
262
function arreter(event) {
228
	if (event.stopPropagation) {
263
	if (event.stopPropagation) {
229
		event.stopPropagation();
264
		event.stopPropagation();
230
	} else if (window.event) {
265
	} else if (window.event) {
231
		window.event.cancelBubble = true;
266
		window.event.cancelBubble = true;
232
	}
267
	}
233
	return false;
268
	return false;
234
}
269
}
235
 
270
 
236
function afficher() {
271
function afficher() {
237
	$('#panneau-lateral').width(300);
272
	$('#panneau-lateral').width(300);
238
	$('#pl-contenu').css('display', 'block');
273
	$('#pl-contenu').css('display', 'block');
239
	$('#pl-ouverture').css('display', 'none');
274
	$('#pl-ouverture').css('display', 'none');
240
	$('#pl-fermeture').css('display', 'block');
275
	$('#pl-fermeture').css('display', 'block');
241
	$('#carte').css('left', '300px');
276
	$('#carte').css('left', '300px');
242
 
277
 
243
	google.maps.event.trigger(map, 'resize');
278
	google.maps.event.trigger(map, 'resize');
244
};
279
};
245
 
280
 
246
function cacher() {
281
function cacher() {
247
	$('#panneau-lateral').width(24);
282
	$('#panneau-lateral').width(24);
248
	$('#pl-contenu').css('display', 'none');
283
	$('#pl-contenu').css('display', 'none');
249
	$('#pl-ouverture').css('display', 'block');
284
	$('#pl-ouverture').css('display', 'block');
250
	$('#pl-fermeture').css('display', 'none');
285
	$('#pl-fermeture').css('display', 'none');
251
	$('#carte').css('left', '24px');
286
	$('#carte').css('left', '24px');
252
	
287
	
253
	google.maps.event.trigger(map, 'resize');
288
	google.maps.event.trigger(map, 'resize');
254
};
289
};
255
 
290
 
256
function ouvrirPopUp(url, nom) {
291
function ouvrirPopUp(url, nom) {
257
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
292
	window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
258
};
293
};
259
 
294
 
260
function filtrerParTaxon() {
295
function filtrerParTaxon() {
261
	var ntAFiltrer = $('.nt', this).text();
296
	var ntAFiltrer = $('.nt', this).text();
262
	infoBulle.close();
297
	infoBulle.close();
263
	$('#taxon-'+nt).removeClass('taxon-actif');
298
	$('#taxon-'+nt).removeClass('taxon-actif');
264
	if (nt == ntAFiltrer) {
299
	if (nt == ntAFiltrer) {
265
		nt = '*';
300
		nt = '*';
266
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
301
		executerMarkerClusterer(pointsOrigine, boundsOrigine);
267
	} else {
302
	} else {
268
		var url = urlObsCarte+'&'+
303
		var url = urlObsCarte+'&'+
269
			'num_taxon='+ntAFiltrer+'&'+
304
			'num_taxon='+ntAFiltrer+'&'+
270
			'formatRetour=jsonp'+'&'+
305
			'formatRetour=jsonp'+'&'+
271
			'callback=?';
306
			'callback=?';
272
		$.getJSON(url, function (observations) {
307
		$.getJSON(url, function (observations) {
273
			obs = observations;
308
			obs = observations;
274
			nt = ntAFiltrer;
309
			nt = ntAFiltrer;
275
			$('#taxon-'+nt).addClass('taxon-actif');
310
			$('#taxon-'+nt).addClass('taxon-actif');
276
			rafraichirCarte();
311
			rafraichirCarte();
277
		});
312
		});
278
	}
313
	}
279
};
314
};
280
 
315
 
281
/**
316
/**
282
 * +-------------------------------------+
317
 * +-------------------------------------+
283
 * Number.prototype.formaterNombre
318
 * Number.prototype.formaterNombre
284
 * +-------------------------------------+
319
 * +-------------------------------------+
285
 * Params (facultatifs):
320
 * Params (facultatifs):
286
 * - Int decimales: nombre de decimales (exemple: 2)
321
 * - Int decimales: nombre de decimales (exemple: 2)
287
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
322
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
288
 * - String separateurMilliers: comme son nom l'indique
323
 * - String separateurMilliers: comme son nom l'indique
289
 * Returns:
324
 * Returns:
290
 * - String chaine formatee
325
 * - String chaine formatee
291
 * @author	::mastahbenus::
326
 * @author	::mastahbenus::
292
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
327
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
293
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
328
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
294
 */
329
 */
295
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
330
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
296
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
331
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
297
	
332
	
298
	function is_int(nbre) {
333
	function is_int(nbre) {
299
		nbre = nbre.replace(',', '.');
334
		nbre = nbre.replace(',', '.');
300
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
335
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
301
	}
336
	}
302
 
337
 
303
	if (decimales == undefined) {
338
	if (decimales == undefined) {
304
		if (is_int(_sNombre)) {
339
		if (is_int(_sNombre)) {
305
			decimales = 0;
340
			decimales = 0;
306
		} else {
341
		} else {
307
			decimales = 2;
342
			decimales = 2;
308
		}
343
		}
309
	}
344
	}
310
	if (signe == undefined) {
345
	if (signe == undefined) {
311
		if (is_int(_sNombre)) {
346
		if (is_int(_sNombre)) {
312
			signe = '';
347
			signe = '';
313
		} else {
348
		} else {
314
			signe = '.';
349
			signe = '.';
315
		}
350
		}
316
	}
351
	}
317
	if (separateurMilliers == undefined) {
352
	if (separateurMilliers == undefined) {
318
		separateurMilliers = ' ';
353
		separateurMilliers = ' ';
319
	}
354
	}
320
	
355
	
321
	function separeMilliers (sNombre) {
356
	function separeMilliers (sNombre) {
322
		var sRetour = "";
357
		var sRetour = "";
323
		while (sNombre.length % 3 != 0) {
358
		while (sNombre.length % 3 != 0) {
324
			sNombre = "0"+sNombre;
359
			sNombre = "0"+sNombre;
325
		}
360
		}
326
		for (i = 0; i < sNombre.length; i += 3) {
361
		for (i = 0; i < sNombre.length; i += 3) {
327
			if (i == sNombre.length-1) separateurMilliers = '';
362
			if (i == sNombre.length-1) separateurMilliers = '';
328
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
363
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
329
		}
364
		}
330
		while (sRetour.substr(0, 1) == "0") {
365
		while (sRetour.substr(0, 1) == "0") {
331
			sRetour = sRetour.substr(1);
366
			sRetour = sRetour.substr(1);
332
		}
367
		}
333
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
368
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
334
	}
369
	}
335
	
370
	
336
	if (_sNombre.indexOf('.') == -1) {
371
	if (_sNombre.indexOf('.') == -1) {
337
		for (i = 0; i < decimales; i++) {
372
		for (i = 0; i < decimales; i++) {
338
			_sDecimales += "0";
373
			_sDecimales += "0";
339
		}
374
		}
340
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
375
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
341
	} else {
376
	} else {
342
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
377
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
343
		if (sDecimalesTmp.length > decimales) {
378
		if (sDecimalesTmp.length > decimales) {
344
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
379
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
345
			var nDiv = 1;
380
			var nDiv = 1;
346
			for (i = 0; i < nDecimalesManquantes; i++) {
381
			for (i = 0; i < nDecimalesManquantes; i++) {
347
				nDiv *= 10;
382
				nDiv *= 10;
348
			}
383
			}
349
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
384
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
350
		}
385
		}
351
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
386
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
352
	}
387
	}
353
	return _sRetour;
388
	return _sRetour;
354
}
389
}