Subversion Repositories eFlore/Applications.cel

Rev

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

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