$(document).ready(function() {
/*
  if ($('#catadomaine span, #catasansdrm span').length>0) $('#catadomaine span, #catasansdrm span').each(function() {
			$(this).click(function() {
				if($('> ul', $(this).parent()).css('display') == 'none'){
					$('> ul', $(this).parent()).show();
					$(this).css('background-image','url("/imagesV3/arrow_down.png")');
				}	else {
					$('> ul', $(this).parent()).hide();
					$(this).css('background-image','url("/imagesV3/arrow_straight.png")');
				}
			});
		});
    */
  if ($('.span_lit').length>0) $('.span_lit').click();

  if ($('.topnav a').length>0) $('.topnav a').hover(function() {
	    $(this).parent().find("ul.subnav").show();
			$(this).parent().hover(function(){
			  },function(){
    		$(this).parent().find("ul.subnav").hide();
		  });
	});

  if ($('#slid_promo1').length>0) $('#slid_promo1').attr({ src:"/imagesv3/slider/visu_slider_01.png" });
  if ($('#slid_promo2').length>0) $('#slid_promo2').attr({ src:"/imagesv3/slider/visu_slider_02.png" });
  if ($('#slid_promo3').length>0) $('#slid_promo3').attr({ src:"/imagesv3/slider/visu_slider_03.png" });
  if ($('#slid_promo4').length>0) $('#slid_promo4').attr({ src:"/imagesv3/slider/visu_slider_04.png" });
  if ($('#sliderIndex').length>0) $('#sliderIndex').easySlider({
  	auto:true,controlsShow:true,continuous:false,numeric:true,numericId:'controls',speed:500,pause:10000
  });

  if ($('#inscripForm').length>0) $('#inscripForm').validate({
  		rules: {
  			prenom: {
  				required: true,
  				minlength: 2
  			},
  			nom: {
  				required: true,
  				minlength: 2
  			},
  			email: {
  				required: true,
  				email: true
  			},
  			verifemail: {
  				required: true,
  				equalTo: "#iemail"
  			},
  			motdepasse: {
  				required: true,
  				minlength: 5
  			},
  			verifmotdepasse: {
  				required: true,
  				equalTo: "#imotdepasse"
  			}
  		},
  		messages: {
  			prenom: {
					required: "Entrez votre pr&eacute;nom",
					minlength: "Entrez votre pr&eacute;nom"
				},
  			nom: {
					required: "Entrez votre nom",
					minlength: "Entrez votre nom"
				},
  			motdepasse: {
  				required: "Veuillez d&eacute;finir un mot de passe",
  				minlength: "Entrez au moins 5 caract&egrave;res"
  			},
  			verifmotdepasse: {
  				required: "Veuillez saisir votre mot de passe &agrave; nouveau",
  				equalTo: "Veuillez saisir le m&ecirc;me mot de passe que pr&eacute;c&eacute;dement"
  			},
  			email: {
  				required: "Veuillez entrer un courriel valide",
  				email: "Veuillez entrer un courriel valide"
  			},
  			verifemail: {
  				required: "Veuillez saisir votre courriel &agrave; nouveau",
  				equalTo: "Veuillez saisir le m&ecirc;me courriel que pr&eacute;c&eacute;dement"
  			}
  		},
			invalidHandler: function(form, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'Pour finaliser votre inscription, veuillez renseigner tous les champs du formulaire.'
						: 'Pour finaliser votre inscription, veuillez renseigner tous les champs du formulaire.';
					$(".alert-insc").html(message);
					$(".alert-insc").show();
				} else {
					$(".alert-insc").hide();
				}
			}
  });

  if ($('#connexForm').length>0) $('#connexForm').validate({
    rules: {
      login: {
        required: true,
        minlength: 2,
        email: true
      },
      mdp: {
        required: true,
        minlength: 2
      }
    },
    messages: {
      login: {
        required: "Veuillez saisir votre courriel",
        minlength: "Veuillez saisir votre courriel",
        email: "Veuillez saisir correctement votre courriel"
      },
      mdp: {
        required: "Veuillez saisir votre mot de passe",
        minlength: "Veuillez saisir votre mot de passe"
      }
    },
    submitHandler: function(form) {
			var referer = $('#referer').attr('value');
			//alert(referer);
			logIN(referer);
      return false;
    }

  });

  if ($('#recupmdpForm').length>0) $('#recupmdpForm').validate({
    rules: {
      email: {
        required: true,
        minlength: 2,
        email: true
      }
    },
    messages: {
      email: {
        required: "Veuillez saisir votre courriel",
        minlength: "Veuillez saisir votre courriel",
        email: "Veuillez saisir correctement votre courriel"
      }
    }
  });

 if ($('span.mail').length>0) mailto();

	if ($('.identification_connect').length>0) $('.identification_connect').toggle(
		  function () {
				$(".identification_connect").css("background","#1e1e1e url(\'/images/deplo_on.png\') no-repeat top right")
				$("#compte_connect ul").slideDown('fast');
			},
			function () {
				$(".identification_connect").css("background","#1e1e1e url(\'/images/deplo_off.png\') no-repeat top right")
				$("#compte_connect ul").slideUp('fast');
			}
		);

	if ($('#bloc_panier').length>0) $('#bloc_panier').click(function(){$(document).attr("location","/panier.php")});

	if ($('#searchbarre').length>0) $('#searchbarre > form').submit(function(){return ($('.schbarre').attr('value')!='')});

}); /*fin document ready*/

function mailto(){
	var spt = $('span.mail');
	var at = / at /;
	var dot = / dot /g;
	var addr = $(spt).text().replace(at,"@").replace(dot,".");
	$(spt).after(
		'<a href="mailto:'+addr+'">'+ addr +'</a>').hover(function(){
			window.status="envoyé un courriel";},
			function(){window.status="";}
	);
	$(spt).remove();
}

function SwitchMonCompte(lnk,urlnk) {
	$(".moncomptemenu ul li a").removeClass("liencompteactif");
	$(".moncomptemenu ul li a."+lnk).addClass("liencompteactif");
  // $(".moncomptemenu ul li a").css({'color':'#262524'});
  // $(".moncomptemenu ul li a."+lnk).css({'color':'#28CDE4'});
  $(".mcomptecorps").css({ 'min-height' : $(".mcomptemenu").height() });
  var DataCompte=$.ajax({
    url: urlnk,
    async: false
		//,sucess: alert(urlnk)
  }).responseText;
	//alert(DataCompte);
  $(".mcomptecorps").html(DataCompte).show();
 }

function showInput() {
	$(".lnkmodif").hide();
	$(".cchoisie").hide();
	$(".cmodif").show();
	$(".cmodif .chg").removeClass("noboite");
	$(".cmodif .chg").addClass("boitefocus");
	$(".recmodif").show();
}

function showInput2() {
	$(".lnkmodif2").hide();
	$(".cchoisie2").hide();
	$(".cmodif2").show();
	$(".cmodif2 .chg").removeClass("noboite2");
	$(".cmodif2 .chg").addClass("boitefocus");
	$(".recmodif2").show();
}

function modifInfoPerso() {
  var news_val = 0;
  if ($('input[name=news]').is(':checked')) news_val = 1;
  var mabib_val = 0;
  if ($('input[name=mabib]').is(':checked')) mabib_val = 1;

  if (
		($('#nom').val()!='')&&
		 ($("input[name='civ']:checked").val()!="")&&
		($('#prenom').val()!="")
		// ($('#codepostal').val()!="")&&
		// ($('#ville').val()!="")&&
		// ($('#adresse').val()!="")
		) {
      var set_tel = '';
      if ($('#tel').val()) set_tel = $('#tel').val();
    $.ajax({
      url : 'updatepages/upinfoperso.php',
      type : 'post',
      async : false,
      data : {
        civ : $("input[name='civ']:checked").val(),
        nom : $('#nom').val(),
        prenom : $('#prenom').val(),
        tel : set_tel,
        adresse : $('#adresse').val(),
        codepostal : $('#codepostal').val(),
        ville : $('#ville').val(),
        pays : $('#pays').val(),
        news : news_val,
        mabib : mabib_val,
        email : $('#email').val(),
        modif:'ok'
      }
      //,success : function(data) { alert("Data Loaded: " + data); }
    });

    document.location.reload();
    $(".cchoisie").show();
    $(".cmodif").hide();
    $(".recmodif").hide();
    $(".cmodif input.chg").removeClass("boitefocus");
    $(".cmodif input.chg").addClass("noboite");
    $(".lnkmodif").show();
  }
  else {
    if ($('#manque_infos').length == 0)
      $('form[name="ins"]').prepend('<p id="manque_infos" style="margin : 15px 0; border : solid 1px #ddd; padding : 4px 8px;">Des champs sont vides</p>');
  }
  return false;
}

function modifAdresse2() {
  $.ajax({
    url : 'updatepages/upadresse2.php',
    type : 'post',
    async : false,
    data : {
      civ: $("input[name='civ2']:checked").val(),
      nom: $('#nom2').val(),
      prenom: $('#prenom2').val(),
      societe: $('#societe2').val(),
      tel: $('#tel2').val(),
      adresse: $('#adresse2').val(),
      codepostal: $('#codepostal2').val(),
      ville: $('#ville3').val(),
      pays : $('#pays2').val(),
      modif:'ok'
    }
    //success : function(data) { alert("Data Loaded: " + data); }
  });

	location.reload();
	$(".cchoisie2").show();
	$(".cmodif2").hide();
	$(".recmodif2").hide();
	$(".cmodif2 input.chg").removeClass("boitefocus");
	$(".cmodif2 input.chg").addClass("noboite");
	$(".lnkmodif2").show();
  return false;
}

function AffiFenetre(urlv,divid,TimeToHide) {
  $("div.taillesite").addClass("opac");
  $("#"+divid).html($.ajax({
    url: urlv,
    method:'POST',
    async: false
  }).responseText).draggable().show("slow");
  $("#"+divid+" #Fermer").click(
    function() {
      $("#"+divid).hide("slow").html("&nbsp;");
      $("div.taillesite").removeClass("opac");
    }
  );
  /*if (TimeToHide!=undefined) setTimeout(function() {
    $("#"+divid).hide("slow").html("&nbsp;");
    $("div.taillesite").removeClass("opac");
  }, 4000);*/
}

function PosiFenetre(divid) {
  var hauteur=$(window).scrollTop()+($(window).height()/4);
  var largeur=($(window).width()/2)-($("#"+divid+" div").width()/2);
  $("#"+divid).css({ 'top':hauteur,'left':largeur });
}

function AffiDomaine(CSR) {
  if ($("#d"+CSR)) $("#d"+CSR).show();
  var parents=$("#p"+CSR).parents();
  if ($(parents).length==0) parents=$("#d"+CSR).parents();
  for(i=0;i<$(parents).length;i++) {
     if ($(parents[i]).attr("id")=="menucsr") break;
     if ($(parents[i]).attr("id")!="") $(parents[i]).show();
  }
}

function clicktoplay(EAN) {
  $("#conttext").html('<object type="application/x-shockwave-flash" data="dewplayer-mini.swf?mp3=http://images.epagine.fr/'+EAN.substring(10,13)+'/'+EAN+'_s_1001.mp3&autostart=true" width="155" height="20"><param name="wmode" value="transparent" /><param name="movie" value="dewplayer-mini.swf?mp3=http://images.epagine.fr/'+EAN.substring(10,13)+'/'+EAN+'_s_1001.mp3&autostart=true" /></object>');
}

function SrcText() {
  $("#fen_stc").toggle("slow");
}

function ChSupport(support) {
  if ($("#Supports")) $("#Supports").html($("#support"+support).html());
}

function ScrollDetail() {
  $(function(){
    var maxScroll = $("#scroller").attr("scrollHeight") - $("#scroller").height();
    if (maxScroll<=0) {
      $("#slider").hide();
    } else {
      $("#slider").slider({
        orientation: 'vertical',
        range:'max',
    		animate: true,
        value: 100,
        handle: '.slider',
        change: handleSliderChange,
    		slide: handleSliderSlide
      });
    }
  });
  function handleSliderChange(e, ui) {
    var maxScroll = $("#scroller").attr("scrollHeight") - $("#scroller").height();
    $("#scroller").animate({scrollTop: (maxScroll-(ui.value * (maxScroll/100))) }, 1000);
  }
  function handleSliderSlide(e, ui) {
    var maxScroll = $("#scroller").attr("scrollHeight") - $("#scroller").height();
    $("#scroller").attr({scrollTop: (maxScroll-(ui.value * (maxScroll/100))) });
  }
}

function DevLib() {
  if ($("#ListeLibs").html()=="") $("#ListeLibs").html($("#Libs").html());
  else $("#ListeLibs").html("");
}

function AffiCentre(p) {
  $(".mcomptecorps").html($("#c"+p).html());
//	alert("#c"+p);
  $("ul.menu li a").css({'color':'#FFF'});
  $("ul.menu li a."+p).css({'color':'#28CDE4'});
}

function modifLib() {
if ($('#libselected').val()!="") {
    $.post("updatepages/uplibrairie.php",{
			 libselected: $('#libselected').val(),
       modif:'ok'
       }, function(data){if (data=="ok") {location.reload();} }
    );
    return false;
}}

function logIN(VaRef) {
  if (($('#login').val()=="")||($('#mdp').val()=="")) { $("div.errormail").slideDown('fast'); }
  if (($('#login').val()!="")&&($('#mdp').val()!="")) {
    $.post("updatepages/uplogin.php",{
      login: $('#login').val(),
      mdp: $('#mdp').val(),
      accook: $('#accook').val()},
      function(data){
        if (data=="ko") {
          $("div.errormail").slideDown('fast'); }
        //else if (VaRef=='inscription.php' || VaRef=='/inscription.php' ) document.location.href='inscription.php';
				else document.location.href=VaRef;
      }
    );
  }
  return false;
}

function log(VaRef) {
  if ((login!='')&&(mdp!='')) {
    $.post("updatepages/uplogin.php",{
      login: login,
      mdp: mdp},
      function(data){
        if (VaRef=='inscription.php') document.location.href='index.php';
				else document.location.href=VaRef;
      }
    );
  }
  return false;
}

function drlmdp() {
 $("div.drlmdp").slideDown("slow");
 $('.mdp_oublie').hide();
}


function sendMDP() {
if ($('#email').val()!="") {
	$.post("updatepages/upforgetmdp.php",{ email: $('#email').val() }, function (data) {
 if (data=="ko") {
  $("p.msgmdplost_ko").slideDown('fast');
  $("p.msgmdplost_ok").hide();
 } else {
  $("p.msgmdplost_ok").slideDown('fast');
  $("p.msgmdplost_ko").hide();
 }
});
}
return false;
}

function buy1clic(rid) {
	/*
	var NFlc=$('#choixformat .FL:checked').length;
	var NFl=$('#choixformat .FL').length;
	if (NFl==1) fli=$('#choixformat .FL').val();
	else fli = $('#choixformat .FL:checked').val();
	*/
	// if ( NFlc==1 || NFl==1 )
	document.location.href="/panier.php?Livrel="+ rid +"&FL="+ fli;
	// else alert('Veuillez sélectionner un format');
}

function lstacht(rid) {
	var NFlc=$('#choixformat .FL:checked').length;
	var NFl=$('#choixformat .FL').length;
	if (NFl==1) fli=$('#choixformat .FL').val();
	else fli = $('#choixformat .FL:checked').val();
	if ( NFlc==1 || NFl==1 ) {
		AffiFenetre("/ajoutpanier.php?oai_id="+ rid +"&record_format_id="+fli,'Affiche','4s');
		PosiFenetre('Affiche');
	} else alert('Veuillez sélectionner un format');
}


/* ancienne fonction lstacht_det2() */
function addBasket(formatid) {
	AffiFenetre("/ajoutpanier.php?record_format_id="+formatid,'Affiche','4s');
	PosiFenetre('Affiche');
	return false;
}

function affGoConnect(extrait){
  // si c'est un achat
  if(extrait==0){AffiFenetre('/se_connecter.php','Affiche','4s');}
  // si c'est un DL d'extrait
  else {AffiFenetre('/se_connecter.php?extrait='+extrait,'Affiche','4s');}
	PosiFenetre('Affiche');
	return false;
}

/* Fonction V3 */

function finalbasktB() {
  // enregistrer l'adresse du relai ?
  var livraison_params = '';
  if ($('#relais_enabled').attr('checked') == true) {
    //livraison_params += '&relais_code='+$('#tntRCSelectedCode').attr('value');
    livraison_params += 'relais_code='+$('#tntRCSelectedCode').attr('value');
    livraison_params += '&relais_nom='+encodeURIComponent($('#tntRCSelectedNom').attr('value'));
    livraison_params += '&relais_adresse='+encodeURIComponent($('#tntRCSelectedAdresse').attr('value'));
    livraison_params += '&relais_cpostal='+$('#tntRCSelectedCodePostal').attr('value');
    livraison_params += '&relais_ville='+encodeURIComponent($('#tntRCSelectedCommune').attr('value'));
  }
  if ($('#choix_livraison input:checked').length) livraison_params += '&fport_id='+$('#choix_livraison input:checked').val();
  //if (livraison_params) livraison_params = '?' + livraison_params.substring(1);

	//if ($('#cgv:checked').length!=0) {
	 //AffiFenetre("/paiement.php"+livraison_params,'Affiche');
   //PosiFenetre('Affiche');
   if ($('input[name=cb_abo]').is(':checked')) cb_abo=$('input[name=cb_abo]:checked').val(); else cb_abo=2;
   if ($('#cb_no').val().length<12&&cb_abo!=1) alert('Numéro de carte invalide');
   else if ($('#cb_cvv').val().length<3&&cb_abo!=1) alert('Code sécurité invalide');
   else {
     if (livraison_params) $('#livraison_params').val(livraison_params);
     //$('#final').submit();
     if ($('input[name=cb_1c]').is(':checked')) cb_1c=1; else cb_1c=0;
     $.ajax({
       url:'/paiementpaybox.php',
       data:{cb_abo:cb_abo,livraison_params:$('#livraison_params').val(),cb_no:$('#cb_no').val(),cb_mois:$('#cb_mois').val(),cb_annee:$('#cb_annee').val(),cb_cvv:$('#cb_cvv').val(),cb_1c:cb_1c},
       type:'post',
       success:function(data){
         if (data=='ok') $(location).attr('href','validpl.php');
         else $(location).attr('href','panier.php?erreur='+data);
       },
       beforeSend:function(){
         $('#InfoCarte').html('<b>Merci de patienter, nous interrogeons le serveur bancaire</b> <img src="/images/loader.gif" style="vertical-align:middle"/>');
         $('.btn_finaliser').hide();
       }
     });
   }
	//} else alert('Veuillez auparavant accepter les conditions générales de ventes');
}

function inscriptionmsg(cond) {
	var civ = $('.iciv').val();
	var	nom = $('#inom').val();
	var	prenom = $('#iprenom').val();
	var	email = $('#iemail').val();
	$.post("inscriptionmsg.php",{cond:cond,civ:civ,nom:nom,prenom:prenom,email:email},function(data){
    // alert('chevreuil'+corbid);
		if (cond=="ok") {
			// if (!corbid) {
			// setTimeout(function() { $(location).attr('href',"index.php") }, 10000);
			// } else {
			setTimeout(function() { $(location).attr('href',"panier.php") }, 10000);
			// }
			AffiFenetre('inscriptionmsg.php?cond=ok&civ='+ civ +'&prenom='+ prenom +'&nom=' + nom,'Affiche','10s');
			PosiFenetre('Affiche');
		} else if (cond=="ko") {
			AffiFenetre('inscriptionmsg.php?cond=ko&email='+ email,'Affiche');
			PosiFenetre('Affiche');
			$(".telextrait #Fermer").click(
				function() {
					//alert(cond);
					$(location).attr('href','index.php');
				});
		}
		return false;
	});
}

function inscription_ok(reussi, cible) {
  $("div.taillesite").addClass("opac");
  $("#inscription_ok").draggable().show("slow");
  PosiFenetre("inscription_ok");
  if (reussi) $("#inscription_ok_fermer").attr('href', cible);
  else
    $("#inscription_ok_fermer").click(
      function() {
        $("#inscription_ok").hide("slow").html("&nbsp;");
        $("div.taillesite").removeClass("opac");
      }
    );
  if (reussi) setTimeout(function() { $(location).attr('href',cible); }, 4000);
  else
    setTimeout(function() {
      $("#inscription_ok").hide("slow").html("&nbsp;");
      $("div.taillesite").removeClass("opac");
    }, 4000);
}

function ChgArticle(id, type_produit) {
  $.ajax({
  url:'updatepages/uparticle.php',
  data:{id : id, qte: 0},
  type:'post',
  success:function(data) {
    var TotPan = $("#TotalFinal").html();
    var selecteur = "#Pan"+id;
    if ($("#total_sans_fdp")) var total_sans_fdp = $("#total_sans_fdp").html();

    articles_quantites[id]--;

    if (articles_quantites[id] <= 0) {
      if (type_produit == 2) nb_liseuses--;
      if (nb_liseuses <= 0) {
        $(document).attr('location', 'panier.php')
        selecteur += ', #frais_de_port';
        //TotPan -= prix_port;
      }

      $(selecteur).hide('slow');
    }
    else {
      var val_qte = $(selecteur+' .article_quantite span').html();
      val_qte--;
      $(selecteur+' .article_quantite span').html(val_qte);

      var val_prix = $(selecteur+' .article_prix').html();
      val_prix -= data;
      $(selecteur+' .article_prix').html(val_prix);

      var val_eco_taxe = $(selecteur+' .article_eco_taxe').html();
      val_eco_taxe -= 0.03;
      $(selecteur+' .article_eco_taxe').html(val_eco_taxe);
    }

    if (total_sans_fdp) {
      total_sans_fdp -= data;
      centime = Math.round((total_sans_fdp - Math.floor(total_sans_fdp)) * 100);
      if (centime <= 9) total_sans_fdp = total_sans_fdp + "." + "0" + centime;
      else total_sans_fdp = Math.floor(total_sans_fdp) + "." + centime;
      $("#total_sans_fdp").html(total_sans_fdp);
    }

    TotPan -= data;
    centime = Math.round((TotPan - Math.floor(TotPan)) * 100);
    if (centime <= 9) { TotPan = TotPan +"."+ "0" + centime; } else { TotPan = Math.floor(TotPan) +"."+ centime }
    $("#TotalFinal").html(TotPan);
  },async: false});
}

function formatprix(from) {
  var val = from;
  var centime = Math.round((val - Math.floor(val)) * 100);
  if (centime <= 9) val = val + "." + "0" + centime;
  else val = Math.floor(val) + "." + centime;
  return val;
}

function chgArrow(blockcata,idmenug) {
	var Display = $("#"+idmenug).css("display");
  if (Display=="none") {
		$("#"+blockcata).removeClass('menugtitre_md');
		$("#"+blockcata).addClass('menugtitre_md2');
	} else if (Display=="block") {
		$("#"+blockcata).removeClass('menugtitre_md2');
		$("#"+blockcata).addClass('menugtitre_md');
	}
}

function DerouleCatalog(divlnkid,blockcata,idmenug) {
	if (divlnkid=='catadomaine' || divlnkid=='catasansdrm')
    $("#"+divlnkid).children().slideToggle("slow",chgArrow(blockcata, idmenug));
  else
    $("#"+divlnkid).slideToggle("slow", chgArrow(blockcata, idmenug));
}

function deroulblock(block) {
	$("."+block).slideToggle("fast");
}

function selectlibtest(libID){
if ($("#libselected").val()!=libID) {
		$(".btn-chgmntlib").fadeOut("fast");
		$("div.alib").removeClass("alib").addClass("alib_h");
		$("."+libID).removeClass("alib_h").addClass("alib");
    $(".prop").html('Vous avez choisi la librairie :');
    $(".bloclibchoix").html($("."+libID).html());
    $("#libselected").val(libID);
    $(".r"+libID).fadeIn("slow");
  }
}

function schVal() {
	$('#schname').val('');
	$('.schbarre').css({ 'font-style':'normal'});
}

function insc1to2() {
  if (($("#inom").val()!="")&&
      ($("#iprenom").val()!="")&&
      ($("#iadresse").val()!="")&&
      ($("#icodepostal").val()!="")&&
      ($("#iville").val()!="")&&
      ($("#iemail").val()!="")&&
      ($("#imotdepasse").val()!="")) {
    $('.alert-insc').hide();
	}
    $('.insc-1').hide();
    $('.insc-2').show();
    $('.1to2').css({'color':'#DD2C0D'});
    $('.2to1').css({'color':'#DED0A5'});
    if ($("#icodepostal").val()!="") {
      mag2dep=$.ajax({url: 'searchlibydep.php',data: {codep:$("#icodepostal").val()},async: false}).responseText;
      if (mag2dep!="") selectlibtest(mag2dep);
    }
}

function insc2to1() {
	$('.insc-1').show();
	$('.insc-2').hide();
  $('.1to2').css({'color':'#DED0A5'});
  $('.2to1').css({'color':'#DD2C0D'}) ;
}

function AffiQtip(IdImg,RecId,etat){ //Infobulle
  //alert(IdImg+" "+RecId);
  divapp="Plus"+IdImg;
  if (etat!=null) srcinfbu="infobullepack.php"; else srcinfbu="infobulle.php";
  $("#"+IdImg).parent().parent().append("<div id='"+divapp+"' style='display:none;width:213px;position:absolute;'></div>").hover(null,function(){$("#"+divapp).hide();});
  bulle="";
  bulle=$.ajax({
   url: srcinfbu,
   data: {recid:RecId},
   async: false
  }).responseText;
  //alert(bulle);
  $("#"+divapp).html(bulle);
  width=$("#"+IdImg).position().left;
  width+=$("#"+IdImg).width();
  height=$("#"+IdImg).position().top;
  height+=$("#"+IdImg).height()/2;
  height-=$("#"+divapp).height()/2;
  $("#"+divapp).css({left:width,top:height}).show().hover(function(){
    $(this).show();
  },function(){
    $(this).hide();
  });
}


$(window).scroll(function() {
    if($(window).scrollTop() == 0){
      $('#scrollToTop').fadeOut("fast");
    } else {
      if($('#scrollToTop').length == 0){
        $('body').append('<div id="scrollToTop"><a title="Retour en haut de page" class="round-5" href="#"><img src="/imagesv3/totop.png" /></a></div>');
      }
      $('#scrollToTop').fadeIn("fast");
    }
  });

$('#scrollToTop a').live('click', function(event){
  event.preventDefault();
  $('html,body').animate({scrollTop: 0}, 'slow');
});

// info bulle
$(document).ready(function() {
  refreshBulle(0);
});

function refreshBulle(num_table){ // voir index_bloc_tables.php

  var table_selec = $('#bloc_tablelivrel .tablelivrel[num_table="' + num_table + '"] td>a>img');

	table_selec.mouseover(function() {
	  if ($('#bulle').length && $('#bulle').css('display') == 'block') return true;
	  // if ($('#bulle').length) return true;
	  //alert('length : '+$('#bulle').length+' display : '+$('#bulle').css('display'));
	  var record_id = $(this).attr('record_id');
	  var this_img = $(this);
	  $.ajax({
		url : 'infobulle.php',
		type : 'get',
		data : { 'recid' : record_id },
		async : false,
		success : function(data) {
		  // alert(data);
		  var bulle_html = '<div id="bulle" style=""></div>';
		  // $('#bulle').not();
		  $('#bulle').remove();
		  this_img.parent().parent()
			.append(bulle_html)
			.hover(null, function() { $('#bulle').hide(); });
		  $('#bulle').html(data);
		  // display:none;width:213px;position:absolute;
		  var width = this_img.position().left + this_img.width();
		  var height = this_img.position().top + this_img.height() / 2 - $('#bulle').height() / 2;
		  var css_top = 0 - this_img.height() / 2 - $('#bulle').height() / 2;
		  var css_left = this_img.width();
		  // $('#bulle > div').css({ position : 'relative', top : css_top+'px', left : css_left+'px' });
		  $('#bulle')
			.css({left : width, top : height})
			.show()
			.hover(
			function() { $(this).show(); },
			function() { $(this).hide(); }
		  );
		}
	  })
	});
}
