$(document).ready(function() {

var RecaptchaOptions = {  
		lang : 'fr',  
		theme : 'white',  
		custom_translations : { instructions_visual : "Entrez les mots ici :"}  
};

if ($("#slid_promo1")) $("#slid_promo1").attr({ src:"/images/promo/promo01.png" });
if ($("#slid_promo2")) $("#slid_promo2").attr({ src:"/images/promo/promo02.png" });
if ($("#slid_promo3")) $("#slid_promo3").attr({ src:"/images/promo/promo03.png" });
if ($("#slid_promo4")) $("#slid_promo4").attr({ src:"/images/promo/promo04.png" });

$("#sliderIndex").easySlider({
	auto: true,
	controlsShow: true,
	continuous: false,
	numeric: true,
	numericId: 'controls',
	speed: 500,
	pause: 10000
});

var PageEnCours = jQuery.url.attr("file");
var LnkQuery = jQuery.url.attr("query");
		
if ( PageEnCours == "aidelivrel.php" ){
    AffiCentre(1);
	}

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);
}

$("#ContactForm").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			message: "required"
		},
		messages: {
			email: {
				required: "Veuillez entrer un courriel valide.",
				email: "Veuillez entrer un courriel valide."
			},
			message: "Veuillez saisir votre message pour nous contacter."
		}
});

$("#inscripForm").validate({
		rules: {
			prenom: "required",
			nom: "required",
			email: {
				required: true,
				email: true
			},
			verifemail: {
				required: true,
				equalTo: "#iemail"
			},
			motdepasse: {
				required: true,
				minlength: 5
			},
			verifmotdepasse: {
				required: true,
				equalTo: "#imotdepasse"
			}
		},
		messages: {
			prenom: "Entrez votre pr&eacute;nom",
			nom: "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écédemment"
			},
			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écédemment"
			}
		}
});	

});

function pgecHelp(numpge) {
	var PageEnCours = jQuery.url.attr("file");
	var LnkQuery = jQuery.url.attr("query");
	if ( PageEnCours == "aide.php"&&LnkQuery == "help="+numpge) {
  	  AffiCentre(numpge);
		} else {
		  AffiCentre(1);
		}
}

function AffiFenetre(urlv,divid) {
  $("body >table").addClass("opac");
  $("#"+divid).html($.ajax({
    url: urlv,
    async: false
  }).responseText).draggable().show("slow");
  $("#"+divid+" #Fermer").click(
    function() {
      $("#"+divid).hide("slow").html("&nbsp;");
      $("body >table").removeClass("opac");
    }
  );
}

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 AffiAide(p) {
  $("#centre").html($("#c"+p).html());
}

function DerouleCatalog(divlnkid) {
	if (divlnkid=='catadomaine') {
		$("#"+divlnkid).children().slideToggle(
		 ); 
	} else {
		$("#"+divlnkid).slideToggle("slow");
	}	 
}

function showCata(divlnkid) {
	$("#"+divlnkid).css({'display':'block'});
	alert();
}


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 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');
}


