Subversion Repositories eFlore/Applications.cel

Rev

Rev 1438 | Rev 1445 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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