Subversion Repositories eFlore/Applications.cel

Rev

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

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