Subversion Repositories eFlore/Applications.cel

Rev

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