$(document).ready(function() {

	$(".topnav a").hover(function() {
	    $(this).parent().find("ul.subnav").show();
			$(this).parent().hover(function(){
			  },function(){
    		$(this).parent().find("ul.subnav").hide();
		  });
	});

if ($("#slid_9782072025327")) $("#slid_9782072025327").attr({ src:"/images/9782072025327.png" });
if ($("#slid_9782715230248")) $("#slid_9782715230248").attr({ src:"/images/9782715230248.png" });	
	
$("#sliderIndex").easySlider({
	auto: true,
	controlsShow: true,
	continuous: false,
	numeric: true,
	numericId: 'controls',
	speed: 500,
	pause: 10000
});	

$('.TableUp').codaSlider();

  var PageEnCours = jQuery.url.attr("file");
	var LnkQuery = jQuery.url.attr("query");

  if ( PageEnCours == "moncompte.php"&&LnkQuery==null ) {
    SwitchMonCompte('infoperso','/moncompte_infoperso.php');
	}
	else if ( PageEnCours == "libraires.php"||PageEnCours =="editeurs.php"||PageEnCours =="aidelivrel.php" ) {
    AffiCentre(1);		
	}
	
	if ( PageEnCours == "moncompte.php"&&LnkQuery == "choix=2" ) {
		SwitchMonCompte('choixlib','/moncompte_choixlib.php');
	}
  
	if ( PageEnCours == "aidelivrel.php"&&LnkQuery == "help=1") {
 		  AffiCentre(1);
	} else if (
		 PageEnCours == "aidelivrel.php"&&LnkQuery == "help=2") {
 		 AffiCentre(2);
	} else if (
		 PageEnCours == "aidelivrel.php"&&LnkQuery == "help=3") {
 		 AffiCentre(3);
	} else if (
		 PageEnCours == "aidelivrel.php"&&LnkQuery == "help=4") {
 		 AffiCentre(4);
	} else if (
		 PageEnCours == "aidelivrel.php"&&LnkQuery == "help=5") {
 		 AffiCentre(5);
	} else if (
		 PageEnCours == "aidelivrel.php"&&LnkQuery == "help=6") {
 		 AffiCentre(6);
	}

	
	// validate signup form on keyup and submit
$("#inscripForm").validate({
		rules: {
			prenom: "required",
			nom: "required",
			adresse: "required",
			email: {
				required: true,
				email: true
			},
			verifemail: {
				required: true,
				equalTo: "#iemail"
			},
			motdepasse: {
				required: true,
				minlength: 5
			},
			verifmotdepasse: {
				required: true,
				equalTo: "#imotdepasse"
			},
			codepostal: {
				required: true,
				number: true,
				minlength: 5
			}
		},
		messages: {
			prenom: "Entrez votre pr&eacute;nom",
			nom: "Entrez votre nom",
			adresse: "Entrez votre adresse",
			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"
			},
			codepostal : {
				required: "Entrez votre code postal",
				number: "Veuillez entrez un code postal valide",
				minlength: "Veuillez entrez un code postal valide"
			}
		}
});

 mailto();
 
}); /*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="Send a letter!";},
			function(){window.status="";}
	);
	$(spt).remove();
}

function SwitchMonCompte(lnk,urlnk) { 
  $(".blocmcompte h1 a").css({'color':'#FFF'});
  $(".blocmcompte h1 a."+lnk).css({'color':'#28CDE4'});
  $(".mcomptecorps").css({ 'min-height' : $(".mcomptemenu").height() });
  var DataCompte=$.ajax({
    url: urlnk,
    async: false
  }).responseText;
  //alert(DataCompte);
  $(".mcomptecorps").html(DataCompte).show();
 }
 
 /*
 function ChangeRegion() {
  $("#ChLibs").html($.ajax({
    url: '/updatepages/uplibregion.php',
    data: "IdRegion="+$('select#region option:selected').val(),
    async:false
    ,success: function(data){alert( data );}
  }).responseText);
}

function ChangeMagasin() {
  if ($(".NoMagACheck:checked").val()!="") $.post('/updatepages/uplibrairie.php',{ NoMag:$(".NoMagACheck:checked").val() },function(data){
    if (data=="ok") location.reload();
  });
  else alert("Veuillez sélectionner une librairie");
}
*/
 
function showInput() {
	$(".lnkmodif").hide();
	$("div.infoperso input").removeClass("noboite");
	$("div.infoperso input").addClass("boitefocus");
	$(".recmodif").show();
}

function showInput2() {
	$(".lnkmodif2").hide();
	$("div.infoperso2 input").removeClass("noboite2");
	$("div.infoperso2 input").addClass("boitefocus");
	$(".recmodif2").show();
}

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) $("#"+divid).everyTime("4s", function() {
    $("#"+divid).hide("slow").html("&nbsp;");
    $("div.taillesite").removeClass("opac");
  }, 1);
}

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();
     //alert($(parents[i]).attr("id"));
  }
}

/*
function ChangeDLRD(argument) {
  if ($("#DL").attr("src")=='/images/pictodlon.jpg') {
	  $("#DL").attr({ src:'/images/pictodloff.jpg' });
	  $("#RD").attr({ src:'/images/pictofeuilleteron.jpg' });
    $("#conttext").html('<a href="'+argument+'" target="_blank" style="color:#FFEC00;font-size:10px;">FEUILLETER UN EXTRAIT</a>');
  } else {
    $("#DL").attr({ src:'/images/pictodlon.jpg' });
    $("#RD").attr({ src:'/images/pictofeuilleteroff.jpg' });
    $("#conttext").html('<a href="javascript:AffiFenetre(\'/telextrait.php?idl='+argument+'\',\'Affiche\');PosiFenetre(\'Affiche\');" style="color:#FFEC00;font-size:10px;">T&Eacute;L&Eacute;CHARGER UN EXTRAIT</a>');
  }
}
*/

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 modifInfoPerso() {
if (($('#nom').val()!="")&&
	($('#prenom').val()!="")&&
	($('#codepostal').val()!="")&&
	($('#ville').val()!="")&&
	($('#adresse').val()!="")) {
		$.post("updatepages/upinfoperso.php",{
			 nom: $('#nom').val(),
			 prenom: $('#prenom').val(),
			 adresse: $('#adresse').val(),
 			 codepostal: $('#codepostal').val(),
 			 ville: $('#ville').val(),
       modif:'ok'
		}
      );
  }	
 $(".recmodif").hide();
 $("input").removeClass("boitefocus");
 $("div.infoperso input").addClass("noboite");
 $(".lnkmodif").show(); 
  return false;
}

function modifLib() {
if ($('#libselected').val()!="") {
    $.post("updatepages/uplibrairie.php",{
			 libselected: $('#libselected').val(),
       modif:'ok'
       }, function(data){if (data=="ok") {location.reload();} }
    );
    return false;
}}


function modifAdresse2() {
  $.post("updatepages/upadresse2.php",{
     adresse: $('#adresse2').val(),
     codepostal: $('#codepostal2').val(),
     ville: $('#ville3').val(),
     modif:'ok'
  });
 $(".recmodif2").hide();
 $("div.infoperso2 input").removeClass("boitefocus");
 $("div.infoperso2 input").addClass("noboite");
 $(".lnkmodif2").show(); 
  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() },
      function(data){
        //alert(data);
        if (data=="ko") { $("div.errormail").slideDown('fast'); }
        else if (VaRef=='inscription.php') document.location.href='index.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 aftVille() {
  if ($('#icodepostal').val()=='') {
  	alert('Entrez d\'abord un code-postal');
  	$('#iville').val('');
  }
}*/

/*function cpVille() {
	var cp = $('#icodepostal').val();
	
	$("#res").show();
	if (cp.length==5) {
  		$("#res").html($.ajax({
    		url: '/inscriptionville.php',
				data: "icodepostal="+cp,
				async:false
				//,success: function(data){alert( data );}
  	  }).responseText);
	}
	$('#ville2').change(function() {
	 	var vil2 = $('select#ville2 option:selected').val();
		$('#iville').val("");
		$('#iville').val(vil2);
    $('#res').hide();
	 } );
}*/

function drlmdp() {
 $("div.drlmdp").slideDown("slow");
}

function sendMDP() {
if ($('#email').val()!="") {
	$.post("updatepages/upforgetmdp.php",{ email: $('#email').val() },
		function(data){
     if (data=="ko") {
			$("div.msgmdplost_ko").slideDown('fast');
      $("div.msgmdplost_ok").hide();
		 } else { 
      $("div.msgmdplost_ok").slideDown('fast');
      $("div.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?Livrel="+ rid +"&FL="+fli,'Affiche','4s');
		PosiFenetre('Affiche');
	} else alert('Veuillez sélectionner un format');
}


function lstacht_det2(rid,formatid) {
	AffiFenetre("/ajoutpanier.php?Livrel="+ rid +"&FL="+formatid,'Affiche','4s');
	PosiFenetre('Affiche');
	return false;
}


function finalbasktB() {
	if ($('#cgv:checked').length!=0) {
	 AffiFenetre("/paiement.php",'Affiche');
   PosiFenetre('Affiche');
	} 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(data);
		if (cond=="ok") {
			AffiFenetre('inscriptionmsg.php?cond=ok&civ='+ civ +'&nom'+ nom +'&prenom=' + prenom,'Affiche','10s');
			PosiFenetre('Affiche');
			$(location).attr('href',"index.php");
		} 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 ChgArticle(gencod,qte) {
  $("#Pan"+gencod).hide('slow');
  $.post("updatepages/uparticle.php",{
     gencod: gencod,
     qte: qte
  },function(data){
    var TotPan=$("#TotalFinal").html();
    TotPan-=data;
    centime = Math.round((TotPan - Math.floor(TotPan)) * 100);
    //alert(centime);
    if (centime <= 9) { TotPan = TotPan +"."+ "0" + centime; } else { TotPan = Math.floor(TotPan) +"."+ centime }
    //alert(TotPan);
    $("#TotalFinal").html(TotPan);
  });
}
/*
function chgArrow(blockcata) {
	if ($("#"+blockcata).hasClass('menugtitre_md')) {
			alert('md');
			$("#"+blockcata).removeClass('menugtitre_md');
			$("#"+blockcata).addClass('menugtitre_md2');
	} else
	if ($("#"+blockcata).hasClass('menugtitre_md2')) {
		$("#"+blockcata).removeClass('menugtitre_md2');
		$("#"+blockcata).addClass('menugtitre_md');
	}
}
*/

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).children().slideToggle("slow",chgArrow(blockcata, idmenug)); 
  else 
    $("#"+divlnkid).slideToggle("slow", chgArrow(blockcata, idmenug));
}

function deroulblock(block) {
	$("."+block).slideToggle("fast");
}
/*
function selectlib(libID){
  if ($("#libselected").val()!=libID) {
    var echange=$("#MyLibSelect").html();
    var echange2=$("."+libID).html();
    $("."+libID).html(echange);
    $("#MyLibSelect").html(echange2);
    $("."+libID).removeClass(libID).addClass($("#libselected").val());
    $("#libselected").val(libID);
  }
}
*/
function selectlib(libID){
if ($("#libselected").val()!=libID) {
		$("div.alib").removeClass("alib").addClass("alib_h");
		$("."+libID).removeClass("alib_h").addClass("alib");
		//$(".tot").removeClass("alib").addClass("alib_h");
		$("#libselected").val(libID);
	}	
}

function schVal() {
	$('#schname').val('');
	$('.schbarre').css({ 'font-style':'normal'});
}



