var initPage = function(){
	Event.observe(window, 'unload', function(){
		if(map){
			GUnload();
		}
	});	
	RollOverImage();
	inputDate();
	/* HAUTEUR COLONNE PIED /*/
	hauteurRub('#pied .pied4 .col');
	
	Event.observe('bt_choix_langue','click',function(){
		if($('choix_langue').style.display != 'none'){
			new Effect.BlindUp('choix_langue',{duration:0.3});
		}else{
			new Effect.BlindDown('choix_langue',{duration:0.3});
		}
	});
	/* CHOIX LANGUE */
	if($('selection_langue')){
		$$('#selection_langue .item').each( function(e){
			e.observe('mouseenter',function(){
				e.addClassName('on');
				e.down('ul').show();
			});
			e.observe('mouseleave',function(){
				e.removeClassName('on');
				e.down('ul').hide();
			});
		});
		$('fermer_langue').observe('click',function(){
			new Effect.Fade('selection_langue',{duration:0.5});
		});
	}
	/* MENU DEROULANT */
	$$('.cont_menu ul > li').each(function(e){
		if(e.down('ul')){
			e.observe('mouseenter', function(){
				e.addClassName('hover');
				e.down('a').addClassName('on');
			});
			e.observe('mouseleave', function(){
				e.removeClassName('hover');
				e.down('a').removeClassName('on');
			});			
		}
	});
	/* RECHERCHE CARTE */
	if($('carte_recherche')){
		$('bandeau').insert({before:'<div id="etiquette_region"></div>'});
		$('etiquette_region').hide();
		var tab_europe = new Array();
		$$('#carte_recherche area').each(function(e,i){
			tab_europe.push({
				nom:e.alt.split('|')[0],
				nb : e.alt.split('|')[1]
			});
			e.alt='';
			Event.observe(e,'mouseout',function(){
				Event.stopObserving(document,'mousemove',coordMouse);
				pX=0;
				pY=0;
				$('etiquette_region').hide();
			});
			Event.observe(e,'mouseover',function(){
				$('etiquette_region').show();
				$('etiquette_region').update('<h4>'+tab_europe[i].nom+'</h4><p>'+tab_europe[i].nb+'</p>');
				Event.observe(document,'mousemove',coordMouse);				
			});
			// CLIC SUR LA FRANCE
			if(e.hash.substr(1) == 67){
				e.stopObserving('click');
				e.observe('click',function(event){
					$('carte_europe').hide();
					$('carte_france').show();
				});
			}
		});
		Event.observe('bt_retour_carte','click',function(){
			$('carte_europe').show();
			$('carte_france').hide();
		});
	}
	
	/* SELECT PAYS */
	$$('.selectPays').each(function(e){
		e.observe('change',function(){
			new Ajax.Request(SiteUrl+'_ajax.php?ACT=selectPays',{
				parameters:{pays:$F(e)},
				onComplete: function(transport){
					selectRegion = e.up('form').down('.selectRegion');
					if(transport.responseText != 'false'){
						selectRegion.disabled = '';
						selectRegion.removeClassName('disabled');
						selectRegion.update(transport.responseText);
					}else{
						selectRegion.disabled = 'disabled';
						selectRegion.addClassName('disabled');
						selectRegion.update('<option>-- '+LG_select_region+' --</option>');
					}
				}
			});
		});
	});
	
	/* HOME */
	if($('home')){
		var ss = new slideShow('ss','cont_ss','item',{
			slideControl2:true,
			slideAutostart:true,
			slideControl2Pause:true,
			slideTempo : 5,
			slideDuree:0.5
		});
		var sb = new SwitchBloc('sb_actu','item');
		$('nb_actu').update($$('#sb_actu .item').size());
		$$('#sb_actu .item').each(function(e,i){
			Event.observe(e,'mouseenter',function(){
				e.addClassName('on');									  
			});
			Event.observe(e,'mouseleave',function(){
				e.removeClassName('on');									  
			});
			e.observe('click',function(event){
				sbActu('home',e,i);
				event.stop();
			});
		});
	}
	/* RECHERCHE */
	if($('resultat_recherche')){
		carteRecherche();
		Event.observe('bt_fermer_carte','click',function(){
			if($('cont_gmap').style.height != '0px'){
				new Effect.Morph('cont_gmap',{style :'height :0px',duration:0.3,afterFinish:
					function(){
						$('bt_fermer_carte').update(LG_gmap_ouvrir);														 
					}
				});
			}else{
				new Effect.Morph('cont_gmap',{style:'height:350px',duration:0.3,afterFinish:
					function(){
						$('bt_fermer_carte').update(LG_gmap_fermer);														 
					}
				});
			}
		});
		$$('.recherche .bt_recherche').each(function(e){
			e.observe('click',function(){
				if(e.hasClassName('nouvelle') == true){
					$('date_debut').value = '';
					$('date_fin').value = '';					
					$('pays').selectedIndex = 0;					
					$('region').selectedIndex = 0;					
				}
				if($('frm_recherche_carte').style.display == 'none'){
					new Effect.BlindDown('frm_recherche_carte',{duration:0.3});
				}
			});
		});
	}
	/* CAMPINGS */
	if($('campings') && $$('.accueil').size()>0){
		$$('.liste_coeur .item').each(function(e,i){
			Event.observe(e,'mouseenter',function(){
				e.addClassName('on');									  
			});
			Event.observe(e,'mouseleave',function(){
				e.removeClassName('on');									  
			});
			e.observe('click',function(event){
				sbActu('campings',e,i);
				event.stop();
			});
		});
	}
	/* SB DERNIERES PHOTOS*/
	if($('sb_photo')){
		var sb = new SwitchBloc('sb_photo','item',{SwiDirection:'vertical'});
	}
	/* COMMUNAUTE */
	if($('communaute') && $$('.membre_photo').size()>0){
		$$('.photo .supprimer').each( function(e){
			Event.observe(e,'click',function(event){
				if(window.confirm(LG_confirm_suppr_photo) == true){
					window.location.href = e.href;
				}
				event.stop();								 
			});
		});
	}
	if($('communaute') && $$('.membre_rallye').size()>0){
		$$('.pagination select').each( function(e){
			Event.observe(e,'change',function(event){
				$('frm_tri').submit();
				event.stop();								 
			});
		});
	}
	/* DETAIL RALLYE */
	if($$('#rallye .detail').size()>0){
		carteRallye();
		$$('.carnet .voir_note').each( function(e){
			Event.observe(e,'click',function(event){
				if(e.up().down('.note').hasClassName('on') == false){
					e.up().down('.note').addClassName('on');
					e.addClassName('on');
					e.update(LG_reduire_note);
				}else{
					e.up().down('.note').removeClassName('on');
					e.removeClassName('on');
					e.update(LG_voir_note);
				}
				event.stop();								 
			});								
		});
	}
	/* CARTE CAMPING */
	if($$('#campings_detail #gmap').size()>0){
		var baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.iconSize = new GSize(15,24);
		baseIcon.shadowSize = new GSize(0,0);
		baseIcon.iconAnchor = new GPoint(7,24);
		map = new GMap2($("gmap"));
		creerBoutons();
		var IconType = new GIcon(baseIcon);
		IconType.image = SiteUrl+'images/commun/marker.png';
		markerOptions = {
			icon: IconType
		}
		if($F('latitude')!='' && $F('longitude')!=''){
			point = new GLatLng($F('latitude'),$F('longitude'));
			var marker = new GMarker(point, markerOptions);
			map.addOverlay(marker);
			map.setCenter(point,10);
		}else{
			geocoder = new GClientGeocoder();
			geocoder.getLatLng($F('adresse'),function(cb){
				point = new GLatLng(cb.y,cb.x);
				var marker = new GMarker(point, markerOptions);
				map.addOverlay(marker);
				map.setCenter(point,10);
			});
		}
	}
	/* SB VISIONNEUSE*/
	if($('sb_visionneuse')){
		var sb_visionneuse = new SwitchBloc('sb_visionneuse','item');
		visionneuse(0);
	}
	/* INFOBOX */
	$$('#campings_detail .infobox').each(function(e){
		e.observe('click', function(event){
			e.blur();						
			var envoyerPage = new infoBox(SiteUrl+'plugins/mod_camping/templates/envoyer_mail.php?cam_idt='+e.rel+'&type='+e.name,{BoxdomNode:'infoNode', BoxSrcFermer:SiteUrl+'images/infoBox/infobox_bt_fermer.gif'});
			envoyerPage.ouvrir();
			if(navigator.userAgent.include('MSIE 6') == false){
				event.stop();
			}
		});
	});
	
	/* COMMANDE */
	if($('frm_commande')){
		$$('.ligne.radio.carte input').each(function(e){
			e.observe('click',function(){
				if($F(e) == '0'){
					new Effect.Fade(e.up().next('.ligne'),{duration:0.3,
						beforeStart:function(){
							$('numero_gold_commande').value = '';
						}
					});
				}else{
					new Effect.Appear(e.up().next('.ligne'),{duration:0.3});
				}
			});
		});
		$$('.commande input').each(function(e){
			e.observe('keyup',function(){
				calcCommande();
			});
		});
		if($('nb_camping_cheque').value != '' || $('nb_guide').value != '') calcCommande();
	}
	
	// POPUP
	$$('.a_popup').each(function(e){
		e.onclick = function(){ return false;}
		Event.observe(e,'click',function(){
			if(e.rel!=''){
				var w = e.rel.split('x')[0];
				var h =  e.rel.split('x')[1];
			}else{
				var w = 620;
				var h = 500;
			}
			var l = (screen.availWidth-10 - w) / 2;
			var t = (screen.availHeight-20 - h) / 2;
			features = "width="+w+",height="+h+",left="+l+",top="+t+",screenX="+l+",screenY="+t+",scrollbars=1,resizable=0,location=0,menubar=0,toolbar=0,status=1";
			window.open(e.href, 'Camping Cheque', features);
		});							 
	});
	
	// INSCRIPTION
	if($$('#profil .inscription_profil').size() > 0){
		$$('.inscription_profil h4 a').each(function(e){
			e.observe('click',function(){
				if(e.up().next('fieldset').style.display=='none'){
					e.addClassName('on');
					new Effect.BlindDown(e.up().next('fieldset'),{duration:0.5});
				}else{
					e.removeClassName('on');
					new Effect.BlindUp(e.up().next('fieldset'),{duration:0.5});
				}
			});
		});
	}
};

// INFOBULLE
var coordMouse = function(e){
	pX = Event.pointerX(e);
	pY = Event.pointerY(e);
	w = $('etiquette_region').getWidth()/2;
	$('etiquette_region').setStyle({display:'block', top:pY-50+'px', left:pX-w+'px'});
};

// VISIONNEUSE CAMPING
var visionneuse = function(num){
	pos = num;
	tab_photo = new Array();
	tab_ecran = new Array();
	tab_ecran2 = new Array();
	$$('#liste_sb_visionneuse a').each(function(e,i){
		tab_photo.push(e.href);
		
		preload = new Image();
		preload.src = e.href;
		
		e.observe('click',function(event){
			$('detail_photo').update('<img src="'+e.href+'" alt="" />');
			e.up().siblings().each( function(n){
				n.down('a').removeClassName('on');								
			});
			e.addClassName('on');
			pos = i
			event.stop();
		});
		if(i%4 == 0){
			tab_ecran.push(i);
		}else{
			tab_ecran2.push(i);
		}
	});
	$$('#liste_sb_visionneuse a')[num].addClassName('on');
	if(pos > 0){
		$('precedent_detail_visionneuse').removeClassName('off');
		$('precedent_detail_visionneuse').stopObserving('click');
		$('precedent_detail_visionneuse').observe('click',function(){
			$$('#liste_sb_visionneuse a').each(function(t){
				t.removeClassName('on');											
			});
			/*
			if(tab_ecran2.include(pos+1) == true){
				sb_visionneuse.move(Math.ceil((pos/4)));
			};
			*/
			pos--;
			$$('#liste_sb_visionneuse a')[pos].addClassName('on');
			$('detail_photo').update('<img src="'+tab_photo[pos]+'" alt="" />');
			visionneuse(pos);
		});
	}else{
		$('precedent_detail_visionneuse').addClassName('off');
		$('precedent_detail_visionneuse').stopObserving('click');
	}
	if(pos < tab_photo.size()-1){
		$('suivant_detail_visionneuse').removeClassName('off');
		$('suivant_detail_visionneuse').stopObserving('click');
		$('suivant_detail_visionneuse').observe('click',function(){
			$$('#liste_sb_visionneuse a').each(function(t){
				t.removeClassName('on');											
			});
			/*
			if(tab_ecran.include(pos+1) == true){
				sb_visionneuse.move(Math.ceil((pos/4)+1));
			};
			*/
			pos++;
			$$('#liste_sb_visionneuse a')[pos].addClassName('on');
			$('detail_photo').update('<img src="'+tab_photo[pos]+'" alt="" />');
			visionneuse(pos);
		});
	}else{
		$('suivant_detail_visionneuse').addClassName('off');
		$('suivant_detail_visionneuse').stopObserving('click');
	}
};

// CARTE

var map;
var polyPoints = [];
var polyPoints2 = new Array();
var postal = [];
var couleur = "#cd0746";
var opacite = 0.8;
var epaisseur = 4;

var carteRallye = function(){
	var baseIcon = new GIcon(G_DEFAULT_ICON);

	baseIcon.iconSize = new GSize(23,37);
	baseIcon.shadowSize = new GSize(0,0);
	baseIcon.iconAnchor = new GPoint(10,37);
	baseIcon.infoWindowAnchor = new GPoint(10, 10);

	map = new GMap2($("gmap"));
	map.enableScrollWheelZoom();
	creerBoutons();

	$('gmap').insert({top:'<div id="loading_gmap"></div>'});
	new Ajax.Request(SiteUrl+'_ajax.php?ACT=gmap_rallye',{
		onComplete: function(transport){
			$('loading_gmap').remove();
			if(transport.responseText != 'false'){
				map.clearOverlays();
				transport = transport.responseText.evalJSON();
				tab_point = transport.point;
				creerParcours();
			}else{
				if(!$('erreur_gmap')){
					$('centre').insert({top:'<div class="erreur" id="erreur_gmap"><p>'+LG_gmap_erreur+'</p></div>'});
				}
			}
		}
	});
};
var creerParcours = function(){
	var baseIcon = new GIcon(G_DEFAULT_ICON);

	tab_lat = new Array();
	tab_lng = new Array();
	tab_point.each( function(e,i){
		if(e.latitude != 0 && e.longitude != 0){
			var point = new GLatLng(e.latitude,e.longitude);
			polyPoints.push(point);
			tab_lat.push(e.latitude);
			tab_lng.push(e.longitude);
		}
	});
	centrerCarte();
	traceParcours();
};
var traceParcours = function(){
	var baseIcon = new GIcon(G_DEFAULT_ICON);

	ligne = new GPolyline(polyPoints,couleur,epaisseur,opacite,{geodesic:true});
	map.clearOverlays();
	map.addOverlay(ligne);
	
	var IconType1 = new GIcon(baseIcon);
	var IconType2 = new GIcon(baseIcon);
	IconType1.image = SiteUrl+'images/commun/marker_depart.png';
	IconType2.image = SiteUrl+'images/commun/marker_arrivee.png';
	marker1 = {
		icon:IconType1,
		clickable : false
	};
	marker2 = {
		icon:IconType2,
		clickable : false
	};
	
	var depart = new GMarker(new GLatLng(tab_point.first().latitude,tab_point.first().longitude), marker1);
	var arrivee = new GMarker(new GLatLng(tab_point.last().latitude,tab_point.last().longitude), marker2);
	map.addOverlay(depart);
	map.addOverlay(arrivee);
}


var carteRecherche = function(){
	var baseIcon = new GIcon(G_DEFAULT_ICON);

	$$('.filtres .ligne input').each( function(e){
		e.stopObserving();									  
	});

	map = new GMap2($("gmap"));
	//map.enableScrollWheelZoom();
	creerBoutons();
	$('no_item').hide();
	if($('erreur_gmap')){
		$('erreur_gmap').remove();
	}
	$('t_resultat').show();
	$('t_carte').show();
	$('cont_gmap').setStyle({height:'350px'});
	$('resultats').show();
	$$('#resultats .item').each(function(e){
		e.remove();									 
	});
	
	// Titres recherche
	if($('pays').options[$('pays').selectedIndex].value == '') lib_pays = '';
	else lib_pays = $('pays').options[$('pays').selectedIndex].innerHTML;
	if($('region').options[$('region').selectedIndex].value == '') lib_region = '';
	else lib_region = $('region').options[$('region').selectedIndex].innerHTML;	
	lib_datedeb = $F('date_debut');
	lib_datefin = $F('date_fin');
	lib_rech1 = '';
	if(lib_pays != '') lib_rech1 += lib_pays;
	if(lib_region != '') lib_rech1 += ' - '+lib_region;	
	lib_rech2 = lib_rech1;
	if(lib_datedeb != '' && lib_datefin!='') lib_rech2 += ' '+LG_du+' '+lib_datedeb+' '+LG_au+' '+lib_datefin;
	else{
		if(lib_datedeb != '') lib_rech2 += ' '+LG_le+' '+lib_datedeb;
		else{
			if(lib_datefin != '') lib_rech2 += ' '+LG_le+' '+lib_datefin;
		}
	}	
	$('localisation1').update(lib_rech1);
	$('localisation2').update(lib_rech2);

	$('gmap').insert({top:'<div id="loading_gmap"></div>'});
	p1 = $('frm_filtres').serialize();
	p2 = $('frm_recherche_carte').serialize();
	p = p1+'&'+p2;
	new Ajax.Request(SiteUrl+'_ajax.php?ACT=gmap_recherche',{
		parameters: p,
		onComplete: function(transport){
			$('loading_gmap').remove();
			if(transport.responseText != 'false'){
				map.clearOverlays();
				transport = transport.responseText.evalJSON();
				
				tab_point = transport.point;
				creerPoint();
				tab_data = transport.data;
				$('nb_resultat').update(tab_data.nb_resultat);
				$('nav_resultat').update(tab_data.pagination1);
				$('nav_resultat2').update(tab_data.pagination2);
				RollOverImage({RollRech:'#resultats .item '});
				GEvent.addListener(map, "zoomend", function(){
					afficheMarker();
					verifBoundZoom();
				});
				GEvent.addListener(map, "move", function(){
					verifBoundZoom();
				});
				$$('.pagination li a').each( function(e){
					Event.observe(e,'click',function(event){
						$('page').value = e.hash.substr(1);
						carteRecherche();
						event.stop();
					});									  
				});
			}else{
				if(!$('erreur_gmap')){
					$('centre').insert({top:'<div class="erreur" id="erreur_gmap"><p>'+LG_gmap_erreur+'</p></div>'});
				}
				$('t_resultat').hide();
				$('t_carte').hide();
				$('cont_gmap').setStyle({height:'0px'});
				$('resultats').hide();
			}
			$$('.filtres .ligne input').each( function(e){
				e.observe('click',function(event){
					carteRecherche();
				});									  
			});
		}
	});
};
var verifBoundZoom = function(){
	mapSize = map.getSize();
	zoom_ne = map.fromContainerPixelToLatLng(new GPoint(mapSize.width,0));
	zoom_sw = map.fromContainerPixelToLatLng(new GPoint(0,mapSize.height));
	var boundsZoom = new GLatLngBounds(zoom_sw, zoom_ne);
	var nb_item = tab_point.size();
	tab_point.each( function(e,i){
		if(boundsZoom.containsLatLng(new GLatLng(e.latitude,e.longitude)) == false){
			$('item'+e.id).addClassName('off');
			nb_item--;
		}else{
			$('item'+e.id).removeClassName('off');
		}
	});
	if(nb_item == 0){
		$('no_item').show();
	}else{
		$('no_item').hide();
	}
};
var centrerCarte = function(){
	var sw = new GLatLng(calculCoord('lat_min'), calculCoord('lng_min'));
	var ne = new GLatLng(calculCoord('lat_max'), calculCoord('lng_max'));
	var bounds = new GLatLngBounds(sw, ne);
	level = map.getBoundsZoomLevel(bounds);
	map.setCenter(new GLatLng(calculCoord('lat_moy'), calculCoord('lng_moy')), level-1);	
};
var tri_nombres = function(a,b){
	return a-b;
};
var calculCoord = function(calcul){
	var lat_min = parseFloat(tab_lat.sort(tri_nombres).first());
	var lat_max = parseFloat(tab_lat.sort(tri_nombres).last());
	var lng_min = parseFloat(tab_lng.sort(tri_nombres).first());
	var lng_max = parseFloat(tab_lng.sort(tri_nombres).last());
	
	if(calcul=='lat_moy'){return (lat_min+lat_max)/2;}
	if(calcul=='lng_moy'){return (lng_min+lng_max)/2;}
	if(calcul=='lat_min'){return lat_min;}
	if(calcul=='lat_max'){return lat_max;}
	if(calcul=='lng_min'){return lng_min;}
	if(calcul=='lng_max'){return lng_max;}
};
var creerPoint = function(){
	tab_lat = new Array();
	tab_lng = new Array();
	tabMarkerPetit = new Array();
	tabMarkerGros = new Array();
	//db(tab_point);
	tab_point.each( function(e,i){
		var tpl = '<div id="item'+e.id+'" class="item">';
		tpl+='			<div class="col1">';
		tpl+='			<h2><a href="'+e.url+'">'+e.nom+'</a></h2>';
		//tpl+='			<img src="'+SiteUrl+'images/commun/pictos/'+e.etoile+'etoile.png" alt="'+e.etoile+' '+LG_etoiles+'" class="fixpng" />';
		tpl+= e.etoile;
		if(e.region != "") tpl+='			<p class="region">'+e.pays+' - '+e.region+'</p>';
		else tpl+='			<p class="region">'+e.pays+'</p>';
		if(e.fil_naturiste == "Y") tpl+='<span class="naturisme"><span>'+LG_camping_naturiste+'</span></span>';
		tpl+='			<a href="'+e.url+'" class="visuel"><img src="'+e.visuel+'" alt="" /></a>';
		tpl+='			<div class="texte">'+e.description+'</div>';
		tpl+='		</div>';
		tpl+='		<div class="col2">';
		tpl+='			<span><strong>'+e.note+'</strong> / 10</span>';
		tpl+='			<a href="'+e.url+'"><img src="'+SiteUrl+'images/'+Langue+'/boutons/bt_voir_fiche2.png" alt="'+LG_voir_fiche+'" class="rollover" /></a>';
		tpl+='		</div>';
		tpl+= '</div>';
		$('resultats').insert({bottom:tpl});
		if(e.latitude != 0 && e.longitude != 0){
			var point = new GLatLng(e.latitude,e.longitude);
			tabMarkerPetit.push(createMarker(point, i,'petit'));
			tabMarkerGros.push(createMarker(point, i,'gros'));
			tab_lat.push(e.latitude);
			tab_lng.push(e.longitude);
		}else{
			geocoder = new GClientGeocoder();
			geocoder.getLocations(e.adresse,
				function(cb){
					//db('A geocoder : '+cb.Status.code+'\nnom : '+e.nom+'\nid :'+e.id+'\nadresse : '+e.adresse);
					if(cb.Status.code == 200){						
						tab_lat.push(cb.Placemark[0].Point.coordinates[1]);
						tab_lng.push(cb.Placemark[0].Point.coordinates[0]);
						cbPoint = new GLatLng(cb.Placemark[0].Point.coordinates[1],cb.Placemark[0].Point.coordinates[0]);
						tabMarkerPetit.push(createMarker(cbPoint, i,'petit'));
						tabMarkerGros.push(createMarker(cbPoint, i,'gros'));
					}else{
						//db('Code erreur Google : '+cb.Status.code+'\nnom : '+e.nom+'\nid :'+e.id+'\nadresse : '+e.adresse);
					}
				}
			);
		}
	});
	window.setTimeout(function(){
		afficheMarker();
		centrerCarte();
	},500);
	if(navigator.appVersion.indexOf("MSIE 6.0")!=-1){
		correctPNG();
	}
};
var afficheMarker = function(){
	map.clearOverlays();
	if(map.getZoom() > 5){
		tabMarkerGros.each(function(e){
			map.addOverlay(e);
		});
	}else{
		tabMarkerPetit.each(function(e){
			map.addOverlay(e);
		});
	}
};
var createMarker = function(point,i,taille) {
	baseIcon = new GIcon(G_DEFAULT_ICON);
	if(taille == 'petit'){
		baseIcon.iconSize = new GSize(10,16);
		baseIcon.iconAnchor = new GPoint(5,8);
	}else{
		baseIcon.iconSize = new GSize(17,24);
		baseIcon.iconAnchor = new GPoint(8,12);
	}
	baseIcon.shadowSize = new GSize(0,0);
	baseIcon.infoWindowAnchor = new GPoint(0, 0);
	IconType = new GIcon(baseIcon);
	if(taille == 'petit'){
		IconType.image =  SiteUrl+'images/commun/marker_petit.png';
	}else{
		IconType.image =  SiteUrl+'images/commun/marker.png';
	}
	markerOptions = {
		title : tab_point[i].nom,
		icon:IconType
	};
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, "click", function() {
		etiquette(point,i);
	});
	return marker;
};
var etiquette = function(point,i){
	var infoOptions = {
		pixelOffset : new GSize(-3,-4),
		onOpenFn : masqueBt,
		onCloseFn : afficheBt
	}
	var tpl = '<div id="etiquette" style="width:300px; height:115px;">';
	tpl+= '<h2><a href="'+tab_point[i].url+'" class="nom">'+tab_point[i].nom+'</a></h2>';
	//tpl+= '<img src="'+SiteUrl+'images/commun/pictos/'+tab_point[i].etoile+'etoile.png" alt="'+tab_point[i].etoile+' '+LG_etoiles+'" class="fixpng" />';
	tpl+= tab_point[i].etoile;
	if(tab_point[i].region != "")
	tpl+= '<p class="region">'+tab_point[i].pays+' - '+tab_point[i].region+'</p>';
	else tpl+= '<p class="region">'+tab_point[i].pays+'</p>';
	tpl+= '<img src="'+tab_point[i].visuel+'" alt="" class="visuel" />';
	tpl+= '<div class="texte">';
	tpl+= '<a href="'+tab_point[i].url+'" class="tous">'+LG_voir_fiche+'</a>';
	tpl+= '<p>'+tab_point[i].description+'<br />'+tab_point[i].adresse+'</p>';	
	tpl+='</div>'
	tpl+='</div>'
	map.openInfoWindowHtml(point,tpl, infoOptions);
};
var creerBoutons = function(bt){
	// VUE
	$("gmap").insert({top:'<div id="bt_map"></div>'});
	$("bt_map").insert({bottom:'<a href="javascript:void(0)" id="bt_plan" class="bt_map on"><span>'+LG_gmap_plan+'</span></a>'});
	$("bt_map").insert({bottom:'<a href="javascript:void(0)" id="bt_mixte" class="bt_map"><span>'+LG_gmap_mixte+'</span></a>'});
	$("bt_map").insert({bottom:'<a href="javascript:void(0)" id="bt_satelite" class="bt_map"><span>'+LG_gmap_sat+'</span></a>'});
	$("bt_map").insert({bottom:'<a href="javascript:void(0)" id="bt_relief" class="bt_map"><span>'+LG_gmap_relief+'</span></a>'});
	// ZOOM
	$("gmap").insert({top:'<div id="bt_zoom_map"></div>'});
	$("bt_zoom_map").insert({bottom:'<a href="javascript:void(0)" id="bt_zoom_in" class="bt_zoom_in"><span>'+LG_gmap_zoomin+'</span></a>'});
	$("bt_zoom_map").insert({bottom:'<a href="javascript:void(0)" id="bt_zoom_out" class="bt_zoom_out"><span>'+LG_gmap_zoomout+'</span></a>'});
	/* RETOUR FRANCE
	$("gmap").insert({top:'<div id="bt_pays"></div>'});
	$("bt_pays").insert({bottom:'<a href="javascript:void(0)" id="bt_france" class="bt_france"><span>'+LG_gmap_france+'</span></a>'});
	
	Event.observe('bt_france','click',function(){
		map.setCenter(new GLatLng(47.05515408550348, 2.4169921875),5);
	});
	*/
	Event.observe('bt_zoom_in','click',function(){
		map.zoomIn(false, false)
	});
	Event.observe('bt_zoom_out','click',function(){
		map.zoomOut(false, false)
	});
	Event.observe('bt_relief','click',function(){
		changeCss(this);							   
		map.setMapType(G_PHYSICAL_MAP);
	});
	Event.observe('bt_satelite','click',function(){
		changeCss(this);							   
		map.setMapType(G_SATELLITE_MAP);
	});
	Event.observe('bt_mixte','click',function(){
		changeCss(this);							   
		map.setMapType(G_HYBRID_MAP);
	});
	Event.observe('bt_plan','click',function(){
		changeCss(this);							   
		map.setMapType(G_NORMAL_MAP);
	});
};
var changeCss = function(bt){
	$$("#bt_map a").each(function(e){
		e.removeClassName("on");
	});
	bt.addClassName("on");
};
var masqueBt = function(bt){
	$('bt_map').hide();
	$('bt_zoom_map').hide();
	//$('bt_pays').hide();
};
var afficheBt = function(bt){
	$('bt_map').show();
	$('bt_zoom_map').show();
	//$('bt_pays').show();
};
/*-----------------------------------------------------------------------------------------------
Fonctions
-----------------------------------------------------------------------------------------------*/
var sbActu = function(page,e,i){
	var path1;
	var path2;
	var path3;
	var act;
	switch(page){
		case 'campings' :
			path1 = '.liste_coeur .item';
			path2 = '#cont_coeur .item';
			path3 = 'cont_coeur';
			act = 'campingCoeur'
		break;
		default : 
			path1 = '#sb_actu .item';
			path2 = '#cont_actu .item';
			path3 = 'cont_actu';
			act = 'sbActu';
		break;
	}
	
	$$(path1).each(function(e2){
		e2.stopObserving('click');
	});
	if(page == 'home'){
		$('actu_courant').update(i+1);
	}
	e.previousSiblings().each(function(p){
		p.removeClassName('in');		   
	});
	e.nextSiblings().each(function(p){
		p.removeClassName('in');		   
	});
	e.addClassName('in');
	id_actu = e.down('a').id.substr(4);
	if($('detail_actu'+id_actu)){
		$('detail_actu'+id_actu).previousSiblings().each(function(p){
			p.hide();		   
		});
		$('detail_actu'+id_actu).nextSiblings().each(function(n){
			n.hide();		   
		});
		$('detail_actu'+id_actu).show();
		$$(path1).each(function(e2,i){
			e2.observe('click',function(event){
				sbActu(page,e2,i);
				event.stop();
			});
		});
	}else{
		$(path3).insert({top:'<div id="loading_actu"><div>'});
		$$(path2).each(function(e){
			e.hide();		   
		});
		new Ajax.Request(SiteUrl+'_ajax.php?ACT='+act,{
			parameters : {
				id:id_actu
			},
			onComplete:function(transport){
				actu = transport.responseText.evalJSON();
				var tpl = '<div class="item" id="detail_actu'+actu.id+'">';
				if(page == "campings") tpl+='<a href="'+actu.url+'" class="visuel"><img src="'+actu.visuel+'" width="148" alt="" /></a>';
				else tpl+='<a href="'+actu.url+'" class="visuel"><img src="'+actu.visuel+'" alt="" /></a>';
				tpl+='<h2><a href="'+actu.url+'">'+actu.titre+'</a></h2>';
				if(page == 'campings'){
					//tpl+= '<img src="./images/commun/pictos/'+actu.etoile+'etoile.png" alt="" class="fixpng" />'
					tpl+= actu.etoile
					if(actu.region != '' && actu.region != 'null') tpl+= '<p class="region">'+actu.region+'</p>'
				}
				tpl+='<p>'+actu.description+'</p>';
				if(page == 'campings'){
					tpl+='<a href="'+actu.url+'" class="suite">'+LG_en_savoir_plus+'</a>';
				}else{
					tpl+='<a href="'+actu.url+'" class="suite">'+LG_suite+'</a>';
				}
				tpl+='</div>';
				$('loading_actu').remove();
				$(path3).insert({top:tpl});
				if(navigator.appVersion.indexOf("MSIE 6.0")!=-1 && page == 'campings'){
					correctPNG();
				}
				$$(path1).each(function(e2,i){
					e2.observe('click',function(event){
						sbActu(page,e2,i);
						event.stop();
					});
				});
			}
		});
	}	
}

var hauteurRub = function(rule){
	var tab = new Array();
	$$(rule).each(function(e,i){
		tab.push(e.getHeight() - e.getStyle('padding-top').substr(0,e.getStyle('padding-top').length-2) - e.getStyle('padding-bottom').substr(0,e.getStyle('padding-top').length-2));
	});
	$$(rule).each(function(e,i){
		e.style.height = tab.max()+'px';
	});
};
var inputDate = function(){
	$$('input.calendrier').each(function(e){
		e.observe('focus',function(){
			displayCalendar(this,'dd/mm/yyyy',this,false,false);
		});
		
		e.observe('blur',function(){
			if(e.id=='date_debut' && $F('date_fin')== ''){
				$('date_fin').value = $F('date_debut');
			}
		});	
		
	});	
};

//  Total Commande
var calcCommande = function(){
	Type = $F('com_type');
	expression = /^[0-9]{1,}$/;                
	if(expression.test($F('nb_camping_cheque')) == true){
		nb_cheque = $F('nb_camping_cheque');
		if(nb_cheque>0) {
			extra_cheque = parseFloat($F('px_traitement'));
			if( $('is_membre_tcs') && $('membre_tcs') ) {
				if( $('is_membre_tcs').checked && $('membre_tcs').value != "" ) {
					if( extra_cheque == 16 ) extra_cheque = 12;
					else if( extra_cheque == 8 ) extra_cheque = 4;
				}
			}
		}
		else extra_cheque = 0;
		tot = Math.round(parseFloat(nb_cheque)*parseFloat($F('px_camping_cheque'))*100)/100;
		if (Devise == "CHF") {
			$('total1').update(Devise+" "+tot);
		} else {
			$('total1').update(tot+Devise);
		}
		$('tr_total1').show();
		$('tr_total4').show();
		$('table_total').show();
	}else{
		nb_cheque = 0;
		extra_cheque = 0;
		$('tr_total1').hide();
		$('tr_total4').hide();
		$('table_total').hide();
	}
	if(expression.test($F('nb_guide')) == true){
		nb_guide = $F('nb_guide');
//		if(nb_cheque > 0) extra_guide = 0;
//		else extra_guide = parseFloat($F('px_fdp'));
		if(nb_cheque>0){
			extra_guide = 0;
		} else {
			if(nb_guide>1) {
				extra_guide = Math.round(parseFloat(nb_guide) * parseFloat($F('px_fdp2'))*100)/100;
			} else {
				if(nb_guide>0) extra_guide = parseFloat($F('px_fdp'));
				else extra_guide = 0;
			}
		}
		tot = Math.round(parseFloat(nb_guide)*parseFloat($F('px_guide'))*100)/100;
		if( Devise == "CHF" ) {
			$('total2').update(Devise+" "+tot);
		} else {
			$('total2').update(tot+Devise);
		}
		if(Type == "" || Type == "papier"){
			$('tr_total2').show();
			$('tr_total3').show();
		}		
		$('table_total').show();
	}else{
		nb_guide = 0;
		extra_guide = 0;
		$('tr_total2').hide();
		$('tr_total3').hide();
	}
	tot_cheque = Math.round(parseFloat(nb_cheque)*parseFloat($F('px_camping_cheque'))*100)/100;
	tot_guide = Math.round(parseFloat(nb_guide)*parseFloat($F('px_guide'))*100)/100;

	total = Math.round((tot_cheque + tot_guide + extra_cheque + extra_guide)*100)/100;
	if( Devise == "CHF" ) {
		$('tot_port').update(Devise+" "+extra_guide);
		$('tot_trait').update(Devise+" "+extra_cheque);
		$('total3').update(Devise+" "+total);
	} else {
		$('tot_port').update(extra_guide+Devise);
		$('tot_trait').update(extra_cheque+Devise);
		$('total3').update(total+Devise);
	}
}

// VERIFS
var frmNewsletter = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		email_newsletter: {type:'mel',alerte:LG_verif_email}
	};
	var res = formVerif('frm_newsletter', champs_form, param_form);
	if(res == true){
		new Ajax.Request(SiteUrl+'_ajax.php?ACT=newsletter',{
			parameters : {email:$F('email_newsletter')},
			onComplete:function(transport){
				if(transport.responseText != 'true'){
					if(!$('retour_newsletter')){
						$('frm_newsletter').insert({top:'<div id="retour_newsletter"><div class="erreur"><p>'+transport.responseText+'</p></div></div>'});
					}else{
						$('retour_newsletter').update('<div class="erreur"><p>'+transport.responseText+'</p></div>');
					}
				}else{
					if(!$('retour_newsletter')){
						$('frm_newsletter').insert({top:'<div id="retour_newsletter"><div class="confirmation"><p>'+LG_confirm_newsletter+'</p></div></div>'});
					}else{
						$('retour_newsletter').update('<div class="confirmation"><p>'+LG_confirm_newsletter+'</p></div>');
					}
				}
			}
		});
		return false;
	}else{
		return formVerif('frm_newsletter', champs_form, param_form);
	}
};
var frmInscription = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		nom_inscription: {alerte:LG_verif_nom},
		prenom_inscription: {alerte:LG_verif_prenom},
		email_inscription: {type:'mel',alerte:LG_verif_email}
	};
	return formVerif('frm_inscription', champs_form, param_form);
};
var frmRecherche = function(form){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		pays: {alerte:LG_verif_pays}
	};
	var res = formVerif(form, champs_form, param_form);
	if(res == true && form=='frm_recherche_carte'){
		carteRecherche();
		return false;
	}else{
		return formVerif(form, champs_form, param_form);
	}
};
var frmCommentaire = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		message_commentaire: {alerte:LG_verif_commentaire}
	};
	return formVerif('frm_depot_commentaire', champs_form, param_form);
};
var frmCommander = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		email_commande: {type:'mel',alerte:LG_verif_email},
		prenom_commande: {alerte:LG_verif_prenom},
		nom_commande: {alerte:LG_verif_nom},
		adresse_commande: {alerte:LG_verif_adresse},
		cp_commande: {alerte:LG_verif_cp},
		ville_commande: {alerte:LG_verif_ville},
		pays_commande: {alerte:LG_verif_pays}
	};	
	//cp_commande: {type:'chiffre',alerte:LG_verif_cp},
	return formVerif('frm_commande', champs_form, param_form);
};
var frmCommanderGold = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		numero_gold_commande: {alerte:LG_verif_numero_gold},
		numero_gold_commande2: {alerte:LG_verif_numero_gold2},
		email_commande: {type:'mel',alerte:LG_verif_email},
		cp_commande: {alerte:LG_verif_cp}
	};	
	return formVerif('frm_commande', champs_form, param_form);
};
var frmCommanderSilver = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		numero_gold_commande: {alerte:LG_verif_numero_gold},
		email_commande: {type:'mel',alerte:LG_verif_email},
		cp_commande: {alerte:LG_verif_cp}
	};	
	return formVerif('frm_commande', champs_form, param_form);
};
var frmCarte = function(){
	var errorMessage ='';
	if($F('tel_commande') =='' && $F('gsm_commande') ==''){
		errorMessage = LG_verif_tel;		
		$('tel_commande').addClassName('inputError');
		$('gsm_commande').addClassName('inputError');
		$('gsm_commande').insert({after:'<div id="tel_erreur" class="divError"><p>'+LG_verif_tel+'</p></div>'});
	}else{
		if($('tel_erreur')){
			$('tel_erreur').remove();	 
		}
		$('tel_commande').removeClassName('inputError');
		$('gsm_commande').removeClassName('inputError');
		errorMessage = '';
	}
	
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		email_commande: {type:'mel',alerte:LG_verif_email},
		prenom_commande: {alerte:LG_verif_prenom},
		nom_commande: {alerte:LG_verif_nom},
		adresse_commande: {alerte:LG_verif_adresse},
		cp_commande: {alerte:LG_verif_cp},
		ville_commande: {alerte:LG_verif_ville},
		pays_commande: {alerte:LG_verif_pays}
	};	
	return formVerif('frm_carte', champs_form, param_form, {errorMessage:errorMessage});
};
var frmActiverSilver = function(){
	var errorMessage ='';
	if($F('tel_commande') =='' && $F('gsm_commande') ==''){
		errorMessage = LG_verif_tel;		
		$('tel_commande').addClassName('inputError');
		$('gsm_commande').addClassName('inputError');
		$('gsm_commande').insert({after:'<div id="tel_erreur" class="divError"><p>'+LG_verif_tel+'</p></div>'});
	}else{
		if($('tel_erreur')){
			$('tel_erreur').remove();	 
		}
		$('tel_commande').removeClassName('inputError');
		$('gsm_commande').removeClassName('inputError');
		errorMessage = '';
	}
	
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		numero_gold_commande: {alerte:LG_verif_numero_gold},
		email_commande: {type:'mel',alerte:LG_verif_email},
		prenom_commande: {alerte:LG_verif_prenom},
		nom_commande: {alerte:LG_verif_nom},
		adresse_commande: {alerte:LG_verif_adresse},
		cp_commande: {alerte:LG_verif_cp},
		ville_commande: {alerte:LG_verif_ville},
		pays_commande: {alerte:LG_verif_pays}
	};	
	return formVerif('frm_carte', champs_form, param_form, {errorMessage:errorMessage});
};
var frmIdentification = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		email_identification: {type:'mel',alerte:LG_verif_email},
		mdp_identification: {alerte:LG_verif_mdp}
	};	
	return formVerif('frm_identification', champs_form, param_form);
};

var frmInfoboxMail = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		sujet_mail: {alerte:LG_verif_sujet},
		email_mail: {type:'mel', alerte:LG_verif_email},
		message_mail: {alerte:LG_verif_commentaire}
	};	
	var res = formVerif('infobox_mail', champs_form, param_form);
	
	if(res==true){
		var f = $('infobox_mail');
		var p = Form.serialize(f)
		f.update('<div class="loading"><img src="'+SiteUrl+'images/commun/loading.gif" alt="" /></div>');
		new Ajax.Request(SiteUrl+'_ajax.php?ACT=envoyer_mail',{
			parameters: p,
			onComplete: function(transport){
				f.update(transport.responseText);
			}
		});		
	}
	return false;
};

var manageTCSMember = function()
{
	if( ! $("membre_tcs") || ! $("is_membre_tcs") ) return;
	if( $("is_membre_tcs").checked ) {
		$("membre_tcs").disabled = '';
		$("membre_tcs").focus();
	} else {
		$("membre_tcs").disabled = 'disabled';
		$("membre_tcs").value = ''; 
	}
	calcCommande();
}

var frmInscription2 = function(){
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
	champs_form = {
		pseudo_inscription: {alerte:LG_verif_pseudo},
		mdp_inscription: {alerte:LG_verif_mdp},
		interet_inscription: {alerte:LG_verif_interet},
		nom_inscription: {alerte:LG_verif_nom},
		prenom_inscription: {alerte:LG_verif_prenom},
		email_inscription: {type:'mel',alerte:LG_verif_email}
	};
	return formVerif('frm_inscription', champs_form, param_form);
};

var frmFormulaireContact = function(){

	champs_form = {
		mail_contact	: {alerte:LG_verif_email},
		nom_contact		: {alerte:LG_verif_nom},
		sujet_contact	: {alerte:LG_verif_sujet}
	};
		
	param_form = { mep: 'msg_champ', autoScroll: false, action: 'submit'};
    return formVerif('frm_contact', champs_form, param_form);			
};
