$(document).ready(function() {  
	if(window.location.pathname == '/location') googleMap(); //Chargement de google map pour la page location lors d'un accés non ajax

	
	// Menu fade (live car sinon bug lors de la selection)
	$('#menu a[class!=actif]').css({backgroundColor:'#000'});
	$('#menu a[class!=actif]').live('mouseover', function () { $(this).animate({backgroundColor:'#EFEFEF'}, 200); });
  $('#menu a[class!=actif]').live('mouseout', function () { $(this).stop().animate({backgroundColor:'#000'}, 300); });
  
  // Animation pour les liens du pied de page
  $('#pied ul li a').bind('mouseover', function () { $(this).animate({color: '#369'}, 200); });
  $('#pied ul li a').bind('mouseout', function () { $(this).stop().animate({color: '#efefef'}, 300); });
  
  // Animation pour les liens
  $("a[rel=effet]").live('mouseover', function () { $(this).animate({color: '#693'}, 200); });
  $("a[rel=effet]").live('mouseout', function () { $(this).stop().animate({color: '#369'}, 300); });  
  $(".espace-client a").live('mouseover', function () { $(this).animate({color: '#693'}, 200); });
  $(".espace-client a").live('mouseout', function () { $(this).stop().animate({color: '#369'}, 300); });  
  $(".plan-du-site a").live('mouseover', function () { $(this).animate({color: '#693'}, 200); });
  $(".plan-du-site a").live('mouseout', function () { $(this).stop().animate({color: '#369'}, 300); });  
  
  // Script pour les liens de suppression
	$('.lienSupprimer').live('click', function () { supprimer($(this));	return false; });
	$('.lienSupprimerCommentaire').live('click', function () { 
		if ($('#ajax-afficher-commentaire').length == 1) supprimer($(this), 'afficher');	
		else supprimer($(this));	
		return false; 
	});
  
  
 	// ************************************************  Navigation AJAX **********************************************
  
  // Clique sur le cadre du menu gauche
  $('#menu-gauche .cadre').live('click', function () { navigationCorps($(this).find('a').attr('href')); return false; });
  $('#menu-gauche .cadre a').live('click', function () { navigationCorps($(this).attr('href')); return false; });
  
  // Clique sur un lien du menu
  $('#menu a').click( function () { 
  	navigationPage($(this).attr('href'), true, true);
		$(this).addClass('actif');
		$('#menu a[class!=actif]').animate({backgroundColor:'#000'}, 400);
		$(this).animate({backgroundColor:'#EFEFEF'}, 200);
		return false;
  });
  
  // Clique sur un lien avec la class 'ajax'
	$('a.ajax').live('click', function () { navigationPage($(this).attr('href'), true); return false; });
	// Clique sur un lien du pied de page
  $('#pied ul li a').live('click', function () { navigationPage($(this).attr('href')); return false; });
  // Accés au panier
  $('a#menu-panier').live('click', function () { navigationPage($(this).attr('href')); return false; });
  // Clique sur un lien bouton de la page panier hormis si il à la class poubelle (sinon bug: impossible de supprimer deux articles de la même ligne de suite !)
  $('#panier a[class!=poubelle]').live('click', function () { navigationPage($(this).attr('href'), true); return false; });
  // Clique sur le bouton 'espace client'
	$('a#connexion-espace-client').live('click', function () { navigationPage($(this).attr('href')); return false; });
	
	function navigationPage(lien, nePasScrollerLaPage, masquerLonglet) {
		if ( $('body').attr('class') == lien ) return false; // Permet de ne pas charger la page si elle a déja été chargé
		avantAjax('#page');
		if (!nePasScrollerLaPage) $.scrollTo(0, 200, {queue:false} );
		if (!masquerLonglet) $('#menu a').animate({backgroundColor:'#000'}, 300);
		else scroll = $('body').scrollTop();
		$('#pied-fond').fadeOut(400);	
		$.ajax({
			url: lien,
			cache: true,
			success: function(html){
				split = html.split('<div id="ajax-page">');
				split = split[1].split('<div id="ajax-page-fin">');
				$('.chargement').remove();
				$('#menu-gauche').fadeOut(400);
				$('#ajax-page').fadeOut(400, function () {
					$('#ajax-page').empty();
					$('#ajax-page').html(split[0]);
					$('#pied-fond').fadeIn(400);
					$('#page').animate({'min-height':'100%'}, 400);
					$('#ajax-page').fadeIn(400);
					if (nePasScrollerLaPage) $('body').scrollTop(scroll);
					document.title = "Altiplanet - "+ucFirst(lien);
					$('input.actualiser').remove(); //Suppression du bouton actualiser s'il existe (pour le panier)
					if (lien == 'location' ) googleMap(); //Affichage de la carte
					
					apresAjax(lien);
					redirection();
				});
			},
			error: function(){
				$('#voilage').remove();
			  alert("Une erreur est survenue lors du chargement de la page.");
			}
		});
		$('#menu a').removeClass('actif');
		$('#menu-panier').removeClass('actif');
  }
  
  function navigationCorps(lien) {
  	if ( $('body').attr('class') == lien ) return false; // Permet de ne pas charger la page si elle a déja été chargé
		avantAjax('#ajax-corps');
		lien = lien.split('/');
  	if ( $('body').scrollTop() > 250 ) $.scrollTo(250, 800, {queue:false} );
    $.ajax({
			url: 'index.php',
			type: 'GET',
			data: 'page='+lien[0]+'&activite='+lien[1],
			cache: true,
			success: function(html){
				$('.chargement').remove();
				split = html.split('<div id="ajax-corps">');
				split = split[1].split('<div id="ajax-corps-fin">');
				$('#ajax-page').find('#ajax-corps').fadeOut(400, function () {
					$('#ajax-corps').html(split[0]);
					$('#ajax-corps').fadeIn(400);
					if (lien[0] != "news") document.title = "Altiplanet - "+ucFirst(lien[0])+" : "+ucFirst(lien[1]);
					else document.title = "Altiplanet - News";

					apresAjax(lien);
				});
			},
			error: function(){
				$('#voilage').remove();
			  alert("Une erreur est survenue lors du chargement de la page.");
			}
		});
  }
  
  function avantAjax(cible) {
   	//Suppression de tinymce pour éviter un bug
		tinyMCE.execCommand('mceRemoveControl', false, 'commentaire');
		
   	$('#notification').fadeOut('slow', function() { $(this).remove(); });
   	
   	if (!$('div.chargement').length)
		{
			$(cible).prepend('<div class="chargement"><div class="voilage"></div><div class="loader-cadre"><div class="loader"></div></div></div>');
			if (cible == "#ajax-corps") 
				$('.chargement').css({'height':$('#ajax-corps').css('height'), 'width':(parseInt($('#ajax-corps').css('width'))-260)+'px', 'left':'280px'});
			else 
				$('.chargement').css({'height':(parseInt($('#page').css('height'))-250)+'px', 'top':'250px'});
			$('.voilage').animate({'opacity':'0.35'}, 1000);
			$('.loader-cadre').animate({'opacity':'1'}, 1000, 'linear');
		}	
  }
  
  function apresAjax(lien) {
   	$('body').attr('class', lien); // Permet de ne pas charger la page si elle a déja été chargé
   	
   	// Chargement de tinymce et des commentaires
   	chargementCommentaires();
   	masquerCommentaires();
  }

	// ************************************************  Réservation AJAX **********************************************
  
  $('input.actualiser').remove();
  
  
  // Réservation ---  Sélection du parcours, de la date et de l'heure
  
  $('.reservation-panier a.bouton-panier').live('click', function () {
  	if ( !$(this).hasClass('actif') ) 
  	{
  		$('.reservation-panier a.bouton-panier').removeClass('actif');
  		$('#reservationAjax-calendrier').slideUp(function () { $(this).remove(); });
  	}
  	lien = $(this).attr('href');
  	$(this).addClass('actif');
  	reservationAjax(lien, 'parcours');
    return false;
  });
  
  $('#calendrier a#heureAjax').live('click', function () {
  	$('#calendrier a.bouton-calendrier').removeClass('actif');
  	$('#calendrier a.bouton-calendrier-matin').removeClass('actif');
  	$('#calendrier a.bouton-calendrier-apresMidi').removeClass('actif');
  	lien = $(this).attr('href');
  	$(this).addClass('actif');
  	reservationAjax(lien, 'calendrier');
    return false;
  });
  
  function reservationAjax(lien, id) {
  	lien = lien.split('/');
  	parametres = lien[1].split('#');
  	parametres[0] = parametres[0].replace("?","&");
    $.ajax({
			url: 'index.php',
			type: 'GET',
			data: 'page='+lien[0]+'&activite='+parametres[0],
			cache: false,
			success: function(html){
				split = html.split('<div id="reservationAjax">');
				split = split[1].split('<div id="reservationAjax-fin">');
				if (!$('#reservationAjax-'+id).length)
				{
					$('#ajax-page').find('#reservationAjax').append('<div id="reservationAjax-'+id+'" class="trait"></div>');
					$('#reservationAjax-'+id).css('display', 'none').html(split[0]);
					$('#reservationAjax-'+id).slideDown();
					$.scrollTo('#reservation', 800, {queue:false} );
				}
				else
				{
					$('#reservationAjax-'+id).html(split[0])
				}
			},
			error: function(){
			  alert("Une erreur est survenue lors du chargement de la page.");
			}
		});
  }
  
  
  // Slide du calendrier
	$("#calendrier a.moissuiv").live('click', function () { slideCalendrier($(this).attr('href'), 'gauche'); return false; });
	$("#calendrier a.moisprec").live('click', function () { slideCalendrier($(this).attr('href'), 'droite'); return false; });
	
	
	// Bulle d'aide
  $("#calendrier a").live("mouseover", function(){
      if($(this).attr("title")=="") return false;
      
      $("body").append('<span class="infobulle"></span>');
      var bulle = $(".infobulle:last");
      bulle.append($(this).attr("title"));
      $(this).attr("title","");
      var posTop = $(this).offset().top-$(this).height();
      var posLeft = $(this).offset().left+$(this).width()/2-bulle.width()/2;
      bulle.css({
          left:posLeft,
          top:posTop-20,
          opacity:0
      });
      bulle.animate({
          top:posTop-10,
          opacity:0.75
      });
  });
  
  $("#calendrier a").live("mouseout", function(){
      var bulle = $(".infobulle:last");
      $(this).attr("title",bulle.text());
      bulle.animate(
          {
              top:bulle.offset().top+10,
              opacity:0
          },
          500,
          "linear",
          function(){
              bulle.remove();  
          }
      );
  });
	
	
	function slideCalendrier(cible, direction) {  
		//$('#reservationAjax-calendrier').slideUp(function () { $(this).remove(); });
		$.ajax({ url: cible,
 						 cache: false,
 						 success: function(html){ 
 						 		splitM = html.split('<div id="calendrier"><h3>');
								splitM = splitM[1].split('</h3><div id="ajax-calendrier">');
 						 		$('#calendrier h3').html(splitM[0]);
 						 
 						 	  split = html.split('<div id="ajax-calendrier">');
								split = split[1].split('</div><div id="ajax-calendrier-fin"></div>');
								if (direction == 'gauche') 
								{
									$('#ajax-calendrier').animate({'margin-left':'-1000px'}, 400);
									$('#calendrier').append('<div id="ajax-calendrier-temp-gauche">'+split[0]+'</div>');
									hauteur = parseInt($('#ajax-calendrier-temp-gauche').css('height')) + 70;
									$('#calendrier').animate({'height':hauteur+'px'}, 400);
									$('#ajax-calendrier-temp-gauche').animate({'right':'0px'}, 400, function() { 
										$('#ajax-calendrier-temp-gauche').remove(); 
										$('#ajax-calendrier').html(split[0]);
										$('#ajax-calendrier').animate({'margin-left':'0px'}, 0);
									});
								}
								else
								{
									$('#ajax-calendrier').animate({'margin-right':'-1000px'}, 400);
									$('#calendrier').append('<div id="ajax-calendrier-temp-droite">'+split[0]+'</div>');
									hauteur = parseInt($('#ajax-calendrier-temp-droite').css('height')) + 70;
									$('#calendrier').animate({'height':hauteur+'px'}, 400);
									$('#ajax-calendrier-temp-droite').animate({'left':'0px'}, 400, function() { 
										$('#ajax-calendrier-temp-droite').remove(); 
										$('#ajax-calendrier').html(split[0]);
										$('#ajax-calendrier').animate({'margin-right':'0px'}, 0);
									});
								}
							},
							error: function(){
			  				alert("Une erreur est survenue lors du chargement du calendrier.");
							}
						 });
	}

    
  // Réservation ---  Ajout au panier
  $('a#panierAjax').live('click', function () { 
  	$.scrollTo(0, 800, {queue:false} );
  	$('#menu a').removeClass('actif');
  	if (!$('#menu-panier').length) $('#page').prepend('<a id="menu-panier" href="panier" class="actif"><span></span></a>');
  	lien = $(this).attr('href');
  	$.ajax({
			url: lien,
			cache: false,
			success: function(html){
				split = html.split('<div id="ajax-page">');
				split = split[1].split('<div id="ajax-page-fin">');
				$('#ajax-page').fadeOut(400, function () {
					$('#ajax-page').html(split[0]);
					$('#ajax-page').fadeIn(400);
					document.title = "Altiplanet - Panier";
					$('input.actualiser').remove(); //Suppression du bouton actualiser
				});
			},
			error: function(){
			  alert("Une erreur est survenue lors du chargement de la page.");
			}
		});
		
		return false;
  });
  
	// Actualisation du panier
  $('#panier-inc select').live('change', function () { 
  	q = $(this).val();
  	m = $(this).find("option:last-child").attr('value');
  	var i = 0;
  	var quantite = "";
  	$('#panier-inc select').each( function() { 
  		quantite = quantite+'&quantite['+i+']='+$(this).val(); 
  		i++; 
  	});
		quantite.replace("quantite=&","");
  	
  	$.ajax({
			url: 'panier.php',
			type: 'POST',
			data: 'quantite[]='+quantite+'&action=actu',
			cache: false,
			success: function(html){
				split = html.split('<div id="ajax-page">');
				split = split[1].split('<div id="ajax-page-fin">');
				$('#ajax-page').html(split[0]);
				$('#montantTotal').css({backgroundColor:'#aaa'}); 
				$('#montantTotal').animate({backgroundColor:'#fff'}, 300); //flash pour montrer le changement
				$('input.actualiser').remove(); //Suppression du bouton actualiser s'il existe (pour le panier)
				
				
				if (q < 3 && m > 3)
				{
					$('<div id="informationQuantite" title="Attention"><p>Vous avez sélectionné une quantité inférieure au nombre de personnes minimum défini pour l\'activité.<br/><br/>Afin de respecter notre politique : "le moniteur pour vous tout seul !", le montant total ne pourra pas être inférieur à celui initialement affiché.</p></div>').prependTo('body');
					
					$('#informationQuantite').dialog({
						autoOpen: false,
						modal: true,
						width: 450,
						buttons: { Ok: function() { $(this).dialog('close'); } },
						close: function() { $('#informationQuantite').detach(); }
					}).dialog('open');
					return false;
				}
				
				
				
			},
			error: function(){
			  alert("Une erreur est survenue lors du chargement de la page.");
			}
		});
  });
  
	// Vérification des mensurations du panier
	$('.etape-3 input[type=submit]').live('click', function () { 	
		verificationMensurations($(this)); 
		if (!$('#notification').length) 
			return true;
		else
			return false;  
	});
	$('.etape-3 input').live('change', function () { verificationMensurations($(this)) });
	
	function verificationMensurations(input) { 
		input.parent().find('input[type!=hidden]').each( function() { 
			var name = $(this).attr('name');
			var cible;
			if (name.indexOf('prenom') != -1) cible = 'prenom';
			if (name.indexOf('nom') != -1) cible = 'nom';
			if (name.indexOf('taille') != -1) cible = 'taille';
			if (name.indexOf('poids') != -1) cible = 'poids';
			if (cible)
			{
				if ( verification($(this), true) )
				{
					if (cible != 'poids') $(this).css("border", "solid #ccc 1px");
					else $(this).parent().css("border", "solid #ccc 1px");
				}
				else
				{
					if (cible != 'poids') $(this).css("border", "solid #ff6666 1px");
					else $(this).parent().css("border", "solid #ff6666 1px");
				}
			}
		});
	}
	
	// Vérification des conditions générales de vente
	$('.etape-4 input[VALUE=Payer]').live('click', function () { 	
		if ($('#cgv input:checked').length == 1) return true;
		else 
		{
			$('<div id="informationCGV" title="Attention"><p>Veuillez prendre connaissance des Conditions Générales de Vente et les accepter afin de pouvoir terminer votre commande.</p></div>').prependTo('body');
					
			$('#informationCGV').dialog({
				autoOpen: false,
				modal: true,
				width: 400,
				buttons: { Ok: function() { $(this).dialog('close'); } },
				close: function() { $('#informationCGV').detach(); }
			}).dialog('open');
			return false;
		}
	});
	


	// ************************************************ Commentaires **********************************************

	function chargementCommentaires() {
		if ($('#commentaires #commentaire').length >= 1)
		{
			$('#commentaire').before('<br/><br/>');
			tinyMCE.execCommand('mceAddControl', false, 'commentaire');
		}
		chargementEtoiles();
	}
	
	// évaluation des activité : note
	$('#commentaires #evaluation a').live('mouseover', function () { etoiles($(this).attr('href'), 'hover'); });
	$('#commentaires #evaluation a').live('mouseout', function () { $('#commentaires #evaluation a').removeClass('hover'); });
	$('#commentaires #evaluation a').live('click', function () { etoiles($(this).attr('href'), 'selected'); return false; });
	
	function etoiles(note, etat) {
		x = 1;
		while (x < 6)
		{ 
			if (x <= note)
				$('#commentaires #evaluation a[href='+x+']').addClass(etat);
			else
				$('#commentaires #evaluation a[href='+x+']').removeClass(etat);
			x = x + 1;
		}
		if (etat == 'selected') $('#commentaires #evaluation input').attr('value',note);
			
	}
	
	function chargementEtoiles() {
		if ($('#commentaires #evaluation select').length >= 1)
		{
			note = $('#commentaires #evaluation select').attr('class').split('note-');
			note = note[1];
			if (note == '') note = '0';
			if (note >= 1) note1 = 'selected'; else note1 = '';
			if (note >= 2) note2 = 'selected'; else note2 = '';
			if (note >= 3) note3 = 'selected'; else note3 = '';
			if (note >= 4) note4 = 'selected'; else note4 = '';
			if (note >= 5) note5 = 'selected'; else note5 = '';
			$('#commentaires #evaluation').html('<label for="evaluation">Notez cette activité<span class="requis">*</span> :</label><input name="evaluation" type="hidden" value="'+note+'" /><a class="etoile '+note1+'" href="1"></a><a class="etoile '+note2+'" href="2"></a><a class="etoile '+note3+'" href="3"></a><a class="etoile '+note4+'" href="4"></a><a class="etoile '+note5+'" href="5"></a><br/><br/>');
		}
	}


	function tinyInit() {
		//Permet d'éviter que le textarea apparaisse à droite du label dans firefox
		$('#commentaire').before('<br/><br/>');
		
		// This is where the compressor will load all components, include all components used on the page here
		tinyMCE_GZ.init({
			plugins : 'advimage,advlink,emotions,insertdatetime,searchreplace,visualchars,inlinepopups',
			disk_cache : true,
			dialog_type : "modal",
			debug : false
		});

		// Normal initialization of TinyMCE
		tinyMCE.init({
			// General options
			language : "fr",
			mode : "exact",
			elements : "commentaire",
			theme : "advanced",
			plugins : 'advimage,advlink,emotions,insertdatetime,searchreplace,visualchars,inlinepopups',
					
			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,forecolor,backcolor",
			theme_advanced_buttons2 : "removeformat,|,cleanup,code,|,undo,redo,|,cut,copy,paste|,search,replace,|,sub,sup,|,bullist,numlist,|,outdent,indent,|,link,unlink,image,charmap,emotions,|,insertdate,inserttime",
			theme_advanced_buttons3 : "",
			
			theme_advanced_toolbar_location : "top",
			theme_advanced_resizing : true,
			setup : function(ed) {
		      ed.onKeyUp.add(function(ed) {
		         tinyMCE.triggerSave();
		         verification( $('#commentaire') );
		      });
		   }
		});
	}

	// vérification des commentaires
	$('input#envoyerCommentaire').live('click', function () {  
		tinyMCE.triggerSave();

		verification( $('#commentaire') );
		verification( $('input[name=evaluation]') );
		
		if (!$('#notification').length) 
			return true; 
		else
			return false; 
	});
	
	
	// envoi en ajax des commentaires-news
	$('input#envoyerCommentaire-news').live('click', function () {  
		verification( $('textarea') );
		verification( $('input[name=pseudo]') );
		verification( $('input[name=capcha]') );
		
		if (!$('#notification').length) 
		{ 
			$.ajax({ 
				type: "POST",
				url: $(this).closest('form').attr('action'),
				data: $(this).closest('form').serialize(),
				success: function(html){ 
					$('#commenter').slideUp('slow', function()
					{ 
						if (!$('#afficher').length || $(this).parent().find('input[name=newsId]').val())
						{
							split = html.split('<div id="ajax-afficher-commentaire-news">');
							split = split[1].split('</div><div id="ajax-afficher-commentaire-news-fin"></div>');
						 	$('#ajax-afficher-commentaire-news').html(split[0]).hide();
							$('#ajax-afficher-commentaire-news').slideDown('slow');
					 	}
					 	else
					 	{
					 		split = html.split('<div class="ajax-afficher-commentaire-news-detail">');
						split = split[1].split('</div><div class="ajax-afficher-commentaire-news-detail-fin"></div>');
					 		$('.ajax-afficher-commentaire-detail-news:first').before('<div class="ajax-afficher-commentaire-news-detail">'+split[0]+'</div><div class="ajax-afficher-commentaire-detail-news-fin"></div>').hide();
						 	$('.ajax-afficher-commentaire-news-detail').slideDown('slow');
					 	}
					});
					$('body').removeClass(); // Permet de pourvoir cliquer sur editer car sinon il considère la page déja affiché
				},
				error: function(html){ 
				alert("Une erreur est survenue lors de l'envoi des données."); }
			});
		}
		return false; 
	});
	
	// Masquage des champs des commentaires
	function masquerCommentaires() {
		if (!$('.ajax-afficher-commentaire-news-detail').length) 
		{
			$('#commentaires-news .commentaires-news-contenu').hide();
			$('#commentaires-news').css("margin-top", "-40px");
			
			$('#commentaires-news .cadre-700-top').css("background", "url(images/commentaire-700-masquer.png) no-repeat left top");
			$('#commentaires-news .legend').html('<a style="color: #333; cursor: pointer;">Cliquez ici pour laisser un commentaire</a>');	
			$('#commentaires-news .legend').css("text-indent", "190px");
		}
	}
	masquerCommentaires();
	$('#commentaires-news .legend a').live("click", function () { 
		$('#commentaires-news').css("margin-top", "20px");
		$('#commentaires-news .legend').css("text-indent", "0px");
		$('#commentaires-news .cadre-700-top').css("background", "url(images/commentaire-700.png) no-repeat left top");
		$('#commentaires-news .commentaires-news-contenu').slideDown("slow");
		$('#commentaires-news .legend').html('Commentaires');
	});


	// ************************************************ Google Map **********************************************

	// Script pour les cartes google map
	$('img.bouton_googlemap').live('click', function () {  
		var coordonnees = $(this).attr('longdesc').split(',');
		X = coordonnees[0];
		Y = coordonnees[1];
		
		$('<div id="googleMap" title="Google map" ><div id="map"></div></div>').prependTo('body');
		
		$('#googleMap').dialog({
			autoOpen: false,
			width: 850,
			height: 550,
			modal: true,
			open: function() { googleMap(X, Y); },
			close: function() { $('#googleMap').detach(); }
		}).dialog('open');
		return false;
	});
  

	function googleMap(X, Y) {
		if (!X) { X = 45.176685; Y = 5.716814; }
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(X, Y), 13);
			map.setUIToDefault();
			var point = new GLatLng(X, Y);
			map.addOverlay(new GMarker(point));
		}
	}
	
	
	
	// ************************************************  Admin **********************************************
  

	// Script pour ajouter et supprimer des parcours dans admin-activité
	$('#parcoursAjouter').live('click', function () {  
		if ( $("input:hidden:last").attr('name').substring(0,4) == 'id--' ) 
			var num = parseInt($("input:hidden:last").attr('value').substring(1,$("input:hidden:last").attr('value').length))+1;
		else 
			var num = 0;
		texte = '<div class="section" id="section--'+num+'"><input type="hidden" name="id--'+num+'" value="-'+num+'"/><label for="ordre--'+num+'">Ordre :</label><input name="ordre--'+num+'" maxlength = "3" /><br/><label for="titre--'+num+'">Titre :</label><input name="titre--'+num+'" maxlength = "50" /><br/><label for="contenu--'+num+'">Contenu :</label><input name="contenu--'+num+'" maxlength = "50" /><br/><label for="tarif--'+num+'">Tarif :</label><input name="tarif--'+num+'" maxlength = "5" /><br/><label for="duree--'+num+'">Durée :</label><select name="duree--'+num+'"><option value="demi">Demi-journée</option><option value="une">Journée</option></select><br/><label for="nombreMin--'+num+'">Nombre minimum :</label><input name="nombreMin--'+num+'" maxlength = "3" /><br/><label for="nombreMax--'+num+'">Nombre maximum :</label><input name="nombreMax--'+num+'" maxlength = "3" /><br/><a id="parcoursSupprimer" class="parcoursSupprimer--'+num+'" href="#supprimer" title="Supprimer le parcours">Supprimer le parcours</a></div>';
		$(texte).insertBefore($('#parcoursAjouter')).css("display", "none").slideDown("slow");
		
		return false;
	});	
	
	$('#parcoursSupprimer').live('click', function () {  
		var num = $(this).attr('class').substring(18,$(this).attr('class').length);
		if (num.substring(0,1) == '-') //si c'est un nouveau le supprime
			$('#section-'+num).slideUp("slow", function () { $('#section-'+num).remove(); });
		else //si c'est un ancien on vide le champs titre et on le masque
			$('#section-'+num).slideUp("slow", function () { $('#section-'+num+' input').val(""); });
		
		return false;
	});	
		
	
	//admin-clients
	$('select[id*=activite]').change(function(){ ajout_fichier($(this)); });
	function ajout_fichier(cible)
	{
		choix = cible.val();
		id = cible.attr('id').substring(9,cible.attr('id').length);
		if(choix == "fichiers")
		{
			if ($('#'+id).length) 
				$('#'+id).html('<br/><label for="fichiers-'+id+'">Fichiers :</label><input name="fichiers-'+id+'" type="file"/>');
			else
				cible.after('<span id='+id+'><br/><label for="fichiers-'+id+'">Fichiers :</label><input name="fichiers-'+id+'" type="file"/></span>');
		}
		else if(choix == "date")
		{
			if ($('#'+id).length) 
				$('#'+id).html('<br/><label for="date-'+id+'">Date de l\'activité :</label><input name="date-'+id+'"/>');
			else
				cible.after('<span id='+id+'><br/><label for="date-'+id+'">Date de l\'activité :</label><input name="date-'+id+'"/></span>');
		}
		else
		{
			if ($('#'+id).length) 
				$('#'+id).slideUp('slow', function() { $(this).remove(); });
		}
	}
	
	$('select#activite-ajax').change(function(){
		$.ajax({ 
				type: "POST",
				url: 'ajax/admin-client.ajax.php',
				data: "activiteId="+$(this).val(),
				success: function(html){ 
					if ($('#parcours-ajax').length) 
						$('#parcours-ajax').remove();
					$('select#activite-ajax').after(html);
				},
				error: function(html){ 
					alert("Une erreur est survenue lors de l'envoi des données."); }
			});
	});
	
	
	// ************************************************ Général **********************************************
	
	//verification des formulaires
	$('input').live('change', function(){ verification($(this)); });
	$('textarea').live('change', function(){ verification($(this)); });
	$('select').live('change', function(){ verification($(this)); });
	$('checkbox').live('change', function(){ verification($(this)); });
	
	$('input[type=submit]').live('click', function(){ 
		$(this).parent().find('input[type!=hidden]').each( function() { verification($(this)); });
		$(this).parent().find('select').each( function() { verification($(this)); });
		$(this).parent().find('checkbox').each( function() { verification($(this)); });
		$(this).parent().find('textarea').each( function() { verification($(this)); });
		if (!$('#notification').length) { return true; }
		else
			return false; 
	});

	// Chargement de TinyMCE puis initalisation des étoiles et des champs textarea si il y en a
	tinyInit();
	chargementEtoiles();
	
});