//==============================================================
// Globals
var $ = jq = jQuery; // Pour faire court...
var llbRestBaseUri = "/wp-llb-rest-server.php";


function llb_log( msg ){
  if($("#debug-infos").length < 1){
    $("body").append('<div id="debug-infos"/>');
  }
  $("#debug-infos").prepend( msg+"<br/>");
}

//==============================================================
function init_ac_villes(psInputIdLib, psInputIdZip,psInputIdVille, psInputDptLib){
    jq("#"+psInputIdLib).autocomplete(
    llbRestBaseUri+"?function=llb_get_autocomplete_villes",
    {
      dataType: 'json', minChars: 3, max: 15,autoFill: false,
      mustMatch: false, matchContains: true, cacheLength:0,
      selectFirst:false, matchSubset:true, delay: 100,
      parse: function(data) {
        var rows = [];
        if (data!=null){
          for(var i=0; i<data.length; i++){
            rows[i] = {
              data:data[i],
              value:data[i].vil_nom, // + " - "+ data[i].vil_code_postal,
              result:data[i].vil_nom //+ " - "+ data[i].vil_code_postal
            };
          }
        }
        return rows;
      },
      formatItem: function(row, i, n) {
        var sVal = row.vil_nom;
        var sOut  = '<div class="sclear"><div class="ac_left" title="'+sVal+'">'+sVal+ '</div>';
        if(row.vil_code_postal != ""){
          sOut += '<div class="ac_right">('+ row.vil_zip + ')</div>';
        }
        sOut += '</div>';
        return sOut;
      }
   }
  ).result(
    function(event, data, formatted) {
       jq("#"+psInputIdVille).val( data.vil_insee );
       set_ville_from_inseeid( psInputIdLib, psInputIdVille, psInputIdZip, psInputDptLib );
    }
  ).blur(
    function(){
      if( window.ac_villes_timer ){
        window.clearTimeout( window.ac_villes_timer );
      }
      window.ac_villes_timer = setTimeout( function(){ check_ville_from_inseeid(psInputIdLib, psInputIdVille)}, 200 );
    }
  );
}

function check_ville_from_inseeid(psInputIdLib, psInputIdVille){
  if( jq(".ac_results").length > 0 && jq(".ac_results").css('display') != 'none' ){
    return;
  }
  var sVilleLib   = jq("#"+psInputIdLib).val();
  var sVilleInsee = jq("#"+psInputIdVille).val();

  jq.ajax({
    url: llbRestBaseUri+"?function=llb_get_ville_by_inseeid&array_args=["+sVilleInsee+",true]"
    ,dataType:'json'
    ,success: function(datas){
      if( "undefined" != typeof(datas) && sVilleLib == datas.vil_nom ){
        jq("#"+psInputIdLib).removeClass( 'frm-error' );
      }else{
        jq("#"+psInputIdLib).addClass('frm-error').val('');
      }
    }
  });
}


function set_dpt_cp( iDptId, psInputDptLib ){
	oParam = '{"iDptId":"'+iDptId+'","bEcho":"1"}';
  jq.ajax({
    url: llbRestBaseUri+"?function=llb_get_departement_by_id&array_args="+oParam
    ,dataType:'json'
    ,success: function(datas){
      jq("#"+psInputDptLib).val( datas.dpt_nom_maj );
    }
  });
}


function set_ville_from_inseeid(psInputIdLib, psInputIdVille, psInputIdZip, psInputDptLib){
	oParam = '{"iInseeId":"'+jq("#"+psInputIdVille).val()+'","bEcho":"1"}';
  jq.ajax({
    url: llbRestBaseUri+"?function=llb_get_ville_by_inseeid&array_args="+oParam
    ,dataType:'json'
    ,success: function(datas){
      if( "undefined" != typeof(datas) ){
        jq("#"+psInputIdLib).val( datas.vil_nom );
        jq("#"+psInputIdZip).val( datas.vil_code_postal );
        set_dpt_cp( datas.vil_departement,psInputDptLib );
      }
    }
  });
}

//==============================================================
function init_ac_personnes(psInputIdLib, psInputIdPrs){
    jq("#"+psInputIdLib).autocomplete(
    llbRestBaseUri+"?function=llb_get_autocomplete_prs",
    {
      dataType: 'json', minChars: 3, max: 15,autoFill: false,
      mustMatch: false, matchContains: true, cacheLength:0,
      selectFirst:false, matchSubset:true, delay: 100,
      parse: function(data) {
        var rows = [];
        if (data!=null){
          for(var i=0; i<data.length; i++){
            rows[i] = {
              data:data[i],
              value:data[i].prs_nom+" "+data[i].prs_prenom,
              result:data[i].prs_nom+" "+data[i].prs_prenom
            };
          }
        }
        return rows;
      },
      formatItem: function(row, i, n) {
        var sVal = row.prs_nom+" "+row.prs_prenom;
        var sOut  = '<div class="sclear" title="'+sVal+'">'+sVal+ '</div>';
        return sOut;
      }
   }
  ).result(
    function(event, data, formatted) {
       jq("#"+psInputIdPrs).val( data.prs_id );
       set_personne_from_id( psInputIdLib, psInputIdPrs );
    }
  ).blur(
    function(){
      if( window.ac_prs_timer ){
        window.clearTimeout( window.ac_prs_timer );
      }
      window.ac_prs_timer = setTimeout( function(){ check_prs_from_id(psInputIdLib, psInputIdPrs)}, 200 );
    }
  );
}

function set_personne_from_id( psInputIdLib, psInputIdPrs ){
  oParam = '{"iPrsId":"'+jq("#"+psInputIdPrs).val()+'","bEcho":"1"}';
  jq.ajax({
    url: llbRestBaseUri+"?function=llb_get_prs_by_id&array_args="+oParam
    ,dataType:'json'
    ,success: function(datas){
      if( "undefined" != typeof(datas) ){
        jq("#"+psInputIdLib).val( datas.prs_nom+" "+datas.prs_prenom );
      }
    }
  });
}
function check_prs_from_id(psInputIdLib, psInputIdPrs){
  if( jq(".ac_results").length > 0 && jq(".ac_results").css('display') != 'none' ){
    return;
  }
  var sPrsLib   = jq("#"+psInputIdLib).val();
  var sPrsId = jq("#"+psInputIdPrs).val();

  jq.ajax({
    url: llbRestBaseUri+"?function=llb_get_prs_by_id&array_args=["+sPrsId+",true]"
    ,dataType:'json'
    ,success: function(datas){
      if( "undefined" != typeof(datas) && sPrsLib == datas.prs_nom+" "+datas.prs_prenom ){
        jq("#"+psInputIdLib).removeClass( 'frm-error' );
      }else{
        jq("#"+psInputIdLib).addClass('frm-error').val('');
        jq("#"+psInputIdPrs).val('');
      }
    }
  });
}

//------------------------------------------------
function set_validation_rules( jqField ){
  
  var sFldId = jqField.attr('id');
  var sFldClass = jqField.attr('class');
  var jqFldLabel = jq('label[for='+sFldId+']');

  if( /\(\*\)/.test( jqFldLabel.text()) ){ return; }

  // Champ obligatoire ?
  if( /llbRequired/.test(sFldClass) ){

   var jqFldLabelTxt =  jqFldLabel.text().replace(" :", "");

   // Ajout * dans le label...
   jqFldLabel.append('<span class="req-field">(*)</span>');

    var strValidate = " {required: true";
    if( /isEmail/.test(sFldClass) ){// E-mail
      strValidate += ",email: true";
    }
    if( /isDate/.test(sFldClass) ){// Date
      strValidate += ",dateISO: true";
    }
    if( /isDigit/.test(sFldClass) ){// Digit
      strValidate += ",digits: true";
    }
    // Si besoin, ajout de tests particuliers ici...

    strValidate += ",messages:{required:\""+jqFldLabelTxt+"\"}}";
    jqField.attr("class", sFldClass+strValidate);
  }
}
//------------------------------------------------
function set_array_validation_rules( aIdArray ){
  for(var i=0; i<aIdArray.length;i++ ){
    jq("#"+aIdArray[i]).addClass('llbRequired');
    set_validation_rules( jq("#"+aIdArray[i]) );
  }
}
//------------------------------------------------
function remove_validation_rules( jqField ){

   jq('label[for='+jqField.attr('id')+'] span[class=req-field]').remove();

  var sFldClass = jqField.attr('class');
      sFldClass = sFldClass.replace(/llbRequired/,'');
      sFldClass = sFldClass.replace(/{.*}/,'');

  jqField.attr('class', sFldClass);
}
//------------------------------------------------
function remove_array_validation_rules( aIdArray ){
  for(var i=0; i<aIdArray.length;i++ ){
    remove_validation_rules( jq("#"+aIdArray[i]) );
  }
}

// ------------------------------------------------------
function check_pass_strength () {
  var pass = $('#prs_pwd').val();
  var user = $('#prs_login').val();

  $('#pass-strength-result').removeClass('short bad good strong');
  if ( ! pass ) {
    $('#pass-strength-result').html( 'Indicateur de sûreté' );
    return;
  }

  var strength = passwordStrength(pass, user);

  if ( 2 == strength )
    $('#pass-strength-result').addClass('bad').html( "Faible" );
  else if ( 3 == strength )
    $('#pass-strength-result').addClass('good').html( "Moyenne" );
  else if ( 4 == strength )
    $('#pass-strength-result').addClass('strong').html( "Forte" );
  else
    // this catches 'Too short' and the off chance anything else comes along
    $('#pass-strength-result').addClass('short').html( "Très faible" );
}
// -----------------------------------------------------
// Password strength meter
function passwordStrength(password,username) {
 var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4;

 //password < 4
 if (password.length < 4 ) { return shortPass };

 //password == username
 if (password.toLowerCase()==username.toLowerCase()) return badPass;

 var symbolSize = 0;
 if (password.match(/[0-9]/)) symbolSize +=10;
 if (password.match(/[a-z]/)) symbolSize +=26;
 if (password.match(/[A-Z]/)) symbolSize +=26;
 if (password.match(/[^a-zA-Z0-9]/)) symbolSize +=31;

 var natLog = Math.log( Math.pow(symbolSize,password.length) );
 var score = natLog / Math.LN2;
 if (score < 40 ) return badPass
 if (score < 56 ) return goodPass
 return strongPass;
}
// -----------------------------------------------------
function check_pass_confirm(){
  var pwd   = jq('#prs_pwd').val();
  var pwd2  = jq('#prs_pwd2').val();

  if( pwd2 != pwd ){
    alert('Les 2 mots de passe ne sont pas équivalents.');
    jq('#prs_pwd2').val('');
  }
}
// -----------------------------------------------------
function test_dispo_login( jqField ){
  jq.ajax({
    url: llbRestBaseUri+"?function=llb_test_dispo_login&args="+jqField.val()
    ,dataType:'json'
    ,success: function(datas){
      if( datas > 0 ){
        jqField.addClass('frm-error').bind('blur',function(){ jqField.val(''); jq("#divMsgLogin").remove();});
        if( jq("#divMsgLogin").length < 1 ){
          jqField.before('<span id="divMsgLogin" style="color:red">Ce login existe déjà ! </span>');
        }
      }else{
        jqField.removeClass('frm-error').unbind('blur');
        jq("#divMsgLogin").remove();
      }
    }
  });

}

// -----------------------------------------------------
function test_dispo_email( jqField ){
  //email_exists( $email )
  jq.ajax({
    url: llbRestBaseUri+"?function=llb_email_exists&args="+jqField.val()
    ,dataType:'json'
    ,success: function(datas){
       jq("#"+jqField.attr('id')+"_unique").val( datas );
    }
  });

}

// -----------------------------------------------------
function set_bloc_hidden_value( jqChk, sBlocId  ){
  var aNewVal = [];
  jq("#div-"+sBlocId+" input[type=checkbox]").each(
    function(o){
      if( jq(this).is(':checked') ){
        aNewVal.push( jq(this).val() );
      }
    }
  )
  var sNewVal = aNewVal.join(",")
  jq("#bloc-"+sBlocId).val(sNewVal);
}

// =============================================================================
function init_ac_to_checklist(sIdBlocs, sType, sLiClass) {

    var sAcFldName      = sIdBlocs+"_lib";
    var sFuncName       = "llb_get_autocomplete_"+sIdBlocs;
    var sAddFldName     = sIdBlocs+"_add";
    var sAddBtnName     = sIdBlocs+"_btnadd";
    var sListContainer  = sIdBlocs+"-list";

    // Initialisation de l'auto-complétion
   jq("#"+sAcFldName).autocomplete(
    llbRestBaseUri+"?function="+sFuncName,
    {
      //dataType: 'json', minChars: 3, max: 15,autoFill: false,
      dataType: 'json', minChars: 3, max: 60,autoFill: false,
      mustMatch: false, matchContains: true, cacheLength:0,
      selectFirst:false, matchSubset:true, delay: 150,
      parse: function(data) {
        var rows = [];
        if (data!=null){
          for(var i=0; i<data.length; i++){
            if(sType == 'prs'){
              rows[i] = {
                data:data[i],
                value: data[i].prs_nom+" "+data[i].prs_prenom,
                result:data[i].prs_nom+" "+data[i].prs_prenom
              };
            }
            else if(sType == 'vil'){
              rows[i] = {
                data:data[i],
                value:data[i].vil_nom,
                result:data[i].vil_nom
              };
            }
            else if(sType == 'dpt'){
              rows[i] = {
                data:data[i],
                value:data[i].dpt_nom,
                result:data[i].dpt_nom
              };
            }
						else if(sType == 'evt'){
              rows[i] = {
                data:data[i],
                value:data[i].evt_libelle,
                result:data[i].evt_libelle
              };
            }else{
              rows[i] = {
                data:data[i],
                value: data[i].stc_nom,
                result:data[i].stc_nom
              };
            }

          }
        }
        return rows;
      },
      formatItem: function(row, i, n) {
        if( "undefined" != typeof(row.prs_id)){
          return row.prs_nom+" "+row.prs_prenom;
        }
        else if( "undefined" != typeof(row.vil_insee)){
          return row.vil_nom+" <small>("+row.vil_zip+")</small>";
        }
        else if( "undefined" != typeof(row.evt_id)){
          return row.evt_libelle;
        }
        else if( "undefined" != typeof(row.dpt_id)){
          return row.dpt_nom+" <small>("+row.dpt_num+")</small>";
        }
        else{
          return row.stc_nom;
        }
      }
   }
  ).result(function(event, data, formatted) {
      var sVal = "";
      var sId = "";
      if(sType == 'prs'){
        sId = data.prs_id;
        sVal = data.prs_nom+" "+data.prs_prenom;
      }
      else if(sType == 'vil'){
        sId = data.vil_insee;
        sVal = data.vil_nom+" ("+data.vil_zip+")";
      }
      else if(sType == 'dpt'){
        sId = data.dpt_id;
        sVal = data.dpt_nom;
      }
      else if(sType == 'evt'){
        sId = data.evt_id;
        sVal = data.evt_libelle;
      }
      else{
        sId = data.stc_id;
        sVal = data.stc_nom;
      }
      jq("#"+sAddFldName).val( sId+"#"+sVal );
  });

  // Fonction d'ajout
  jq("#"+sAddBtnName).click(
    function(){
      var sAddValue = jq("#"+sAddFldName).val();
      if( sAddValue != '' ){
        var aValues = sAddValue.split("#");
        // Composition de la li...
        var sClassLi = ( "undefined" != typeof(sLiClass) )? sLiClass : "col-3";
        var sLiHtml  = '<li class="'+sClassLi+'"><input type="checkbox" class="check '+sLiClass+'" name="'+sIdBlocs+'[]" id="'+sIdBlocs+'-'+aValues[0]+'" value="'+aValues[0]+'" checked="checked" />';
            sLiHtml += '<label for="'+sIdBlocs+'-'+aValues[0]+'"> '+aValues[1]+'</label></li>';
        // Ajout de la li...
        jq("#"+sListContainer+" > ul ").append(sLiHtml);
        // Effacement du champ caché...
        jq("#"+sAddFldName).val('');
        // Effacement du champ AC...
        jq("#"+sAcFldName).val('');
      }else{
        alert('Merci de sélectionner une valeur dans la liste proposée.');
      }
    }
  )
}

// =============================================================================
//SPECIF GESTION DES MEDIAS
function openMediaManager(psCodeDoc, psTypeEntitie, piKeyVal)
{
jq.get("/wp-content/plugins/livre-lecture-bretagne/llb-media-manager.php",{type_doc:psCodeDoc,sTable:psTypeEntitie,iKey:piKeyVal}, function(data){
			// create a modal dialog with the data
			jq(data).dialog(
			{
				modal:true,
				title:'Gestionnaire média',
				resizable:false,
				draggable:true,
				bgiframe:true,
				width:865,
				height:500,
				position:'middle',
				open: function(ev, ui) { jq("#tabs_upload").tabs();init_frm_edit_doc();},
				close: function(ev, ui) { jq(this).remove(); },
				overlay: {
					opacity: 0.1,
					background: 'gray'
				}
			});
		});
}

//Call when user want to play Video or Sound, and download others
function openMediaViewer(piDocId)
{
	jq.get("/wp-content/plugins/livre-lecture-bretagne/llb-media-manager.php?do=getPlayer",
			{doc_id:piDocId}
			, function(data){
			// create a modal dialog with the data
			jq("<span>"+data+"</span>").dialog(
			{
				modal:true,
				title:'Vision média',
				resizable:true,
				draggable:true,
				bgiframe:true,
				width:500,
				height:200,
				position:'middle',
				close: function(ev, ui) { jq(this).remove(); },
				overlay: {
					opacity: 0.1,
					background: 'gray'
				}
			});
		});
}

function add_assoc_document(piDocId, piRefId, psTypeEntitie, poHref)
{
  var oParams = '{"iDocId":"'+piDocId+'","iRefId":"'+piRefId+'","sEntitie":"'+psTypeEntitie+'"}';
	return llb_doc_assoc_ajax_dbaction( 'do_add_assoc', oParams, poHref );
}

function del_assoc_document(piDocId, piRefId, psTypeEntitie, poHref)
{
  var oParams = '{"iDocId":"'+piDocId+'","iRefId":"'+piRefId+'","sEntitie":"'+psTypeEntitie+'"}';
	return llb_doc_assoc_ajax_dbaction( 'do_del_assoc', oParams, poHref );
}

// =============================================================================
// Fonction générique sur l'association personnes-structures
function llb_doc_assoc_ajax_dbaction( sAction, oParams, poHref ){

  var func;
  var aParams = eval ('('+oParams+')');
  switch (sAction) {
    case 'do_del_assoc':
      func = 'llb_del_assoc_doc';
      break;
    case 'do_add_assoc':
      func = 'llb_add_assoc_doc';
      break;
    default:
      return false;
      break;
  }

  jq("#ajax-response")
      .css({'right':'250px','top':'250px','z-index':'10000'})
      .html( "Action en cours..." )
      .attr("class", "frmInfo")
      .show();

  // Exécution de l'appel ajax
  jq.ajax({
    url: llbRestBaseUri+'?function='+func+'&array_args='+oParams
    ,dataType:'json'
    ,success: function(msg){
      if( msg["status"] == 'OK' ){
        jq("#ajax-response").html( msg["message"] ).attr("class", "frmSuccess").show();

        // Diffuseur ------------------------------------------------
        if( func == 'llb_add_assoc_doc' ){ // Ajout
					jq(poHref).remove(); //Suppression du lien d'ajout
					updateAssocDocList(aParams['iRefId'], aParams['sEntitie']);
        }
        if( func == 'llb_del_assoc_doc' ){ // Suppression
					jq(poHref).parents("tr:first").remove();
					removeDefaultMedia(aParams['iDocId'],aParams['sEntitie']);
        }
      }else {
        jq("#ajax-response").html( msg["message"] ).attr("class", "frmError").show();
      }
      window.clearTimeout(window.timer);
      window.timer = window.setTimeout('jq("#ajax-response").fadeOut(\'slow\')', 2500);
    }
    ,error: function(XMLHttpRequest, textStatus, errorThrown){
      jq("#ajax-response").html( 'Erreur : '+textStatus ).attr("class", "frmError").show();
      window.clearTimeout(window.timer);
      window.timer = window.setTimeout('jq("#ajax-response").fadeOut(\'slow\')', 2500);
    }
  });
  return true;
}

//Call onload page and when user select another document from the popup list selection
function updateAssocDocList(piKey, psTable) {
	if(isNaN(piKey))
		return false;
	iDefaultDoc=0;
	switch (psTable) {
		case 'structure':
			iDefaultDoc = jq("#stc_document").val();
			break;
		case 'personne':
			iDefaultDoc = jq("#prs_document").val();
			break;
		case 'evenement':
			iDefaultDoc = jq("#evt_document").val();
			break;
		default:
			break;
	}
	var oParams = '{"piDefaultDoc":"'+iDefaultDoc+'","piKey":"'+piKey+'","psTable":"'+psTable+'"}';
	jq.ajax({
		url: llbRestBaseUri+'?function=llb_get_AssocDocument&array_args='+oParams
		,
		dataType:'html'
		,
		success: function(msg){
			jq("#doc_assoc").prev("table").remove();
			jq(msg).insertBefore("#doc_assoc");
			jq("input[name=default_doc]").click(
				function(){
					setDefaultMedia(this,psTable);
				}
			);

		}
		,
		error: function(XMLHttpRequest, textStatus, errorThrown){
			//alert( 'Erreur updateAssocDocList : '+textStatus+'//'+llbRestBaseUri+'?function=llb_get_AssocDocument&array_args='+oParams);
		}
	});
	return true;
}

//Use after user delete document from the list
function removeDefaultMedia(piDocId, psTable) {
	switch (psTable) {
		case 'structure':
			oDefaultDoc = jq("#stc_document");
			oContentImg = jq("#prs_photo_view");
			break;
		case 'personne':
			oDefaultDoc = jq("#prs_document");
			oContentImg = jq("#prs_photo_view");
			break;
		case 'evenement':
			oDefaultDoc = jq("#evt_document");
			oContentImg = jq("#prs_photo_view");
			break;
		default:
			break;
	}
	if(!jq("input[name=default_doc][value="+piDocId+"]").is(":checked"))
	{
		jq(oDefaultDoc).val("");
		jq(oContentImg).html("");
	}
}

//Use when user select or unselect default media
function setDefaultMedia(poCheckbox, psTable) {
	switch (psTable) {
		case 'structure':
			oDefaultDoc = jq("#stc_document");
			oContentImg = jq("#prs_photo_view");
			break;
		case 'personne':
			oDefaultDoc = jq("#prs_document");
			oContentImg = jq("#prs_photo_view");
			break;
		case 'evenement':
			oDefaultDoc = jq("#evt_document");
			oContentImg = jq("#prs_photo_view");
			break;
		default:
			break;
	}
	if(!jq(poCheckbox).is(':checked'))
	{
		jq(oDefaultDoc).val("");
		jq(oContentImg).html("");
		return;
	}
	else
	{
		jq(oDefaultDoc).val(jq(poCheckbox).val());
		jq(oContentImg).html("<img src=\"/wp-content/plugins/livre-lecture-bretagne/llb-media-manager.php?do=getDefaultVignette&doc_id&doc_id="+jq(poCheckbox).val()+"\"/>");
		jq("input[name=default_doc]").removeAttr("checked");
		jq(poCheckbox).attr("checked","checked");
	}
}


// =============================================================================
// A LA FIN ...
// =============================================================================
jq(document).ready(
  function($){

    var sHost = document.location.host;

    //---------------------------------------------
    if( 'www.livre-et-lecture-en-bretagne.eu' != sHost ){
      jq("a[href*='www.livre-et-lecture-en-bretagne.eu']").each(
        function(o){
          var newHref = this.href.replace('http://www.livre-et-lecture-en-bretagne.eu/', sHost);
          this.href = newHref;
        }
        );
      jq("img[src*='www.livre-et-lecture-en-bretagne.eu']").each(
        function(o){
          var newSrc = this.src.replace('www.livre-et-lecture-en-bretagne.eu', sHost);
          this.src = newSrc;
        }
        );
    }
    //---------------------------------------------
    // Formulaire d'édition des personnes...
    if( jq("#frmEditLlbPersonne").length > 0 ){
      init_prs_back();
    }
    if( jq("#frmPrsCreerCompte").length > 0 ){
      init_frm_creer_compte();
    }
    //---------------------------------------------
    // Formulaire d'édition des thèmes feq...
    if( jq("#frmEditLlbFeqTheme").length > 0 ){
      init_feq_theme_back();
    }
    //---------------------------------------------
    // Formulaire d'édition des options feq...
    if( jq("#frmEditLlbFeqOption").length > 0 ){
      init_feq_option_back();
    }
    //---------------------------------------------
    // Formulaire d'édition des questions feq en back...
    if( jq("#frmEditLlbFeqQuestion").length > 0 ){
      init_feq_question_back();
    }
    //---------------------------------------------
    // Formulaire d'édition des questions feq en front...
    if( jq("#frmEditLlbFeqFrontQuestion").length > 0 ){
      init_feq_question_front();
    }
		if( jq("#frmEditLlbStructure").length > 0 ){
	    init_frm_edit_stc();
		}
		if( jq("#frmEditLlbDocument").length > 0 ){
			init_frm_edit_doc();
		}
		//---------------------------------------------
    // Formulaire de recherche feq ...
    if( jq("#frmFeqQuestSearch").length > 0 ){
      init_quest_search();
    }
		
 //---------------------------------------------
    // Formulaire d'édition des thèmes de newsletter...
		if( jq("#frmEditLlbNwsTheme").length > 0 ){
			init_frm_edit_nwt();
		}
    // Formulaire d'édition des lettres d'info...
		if( jq("#frmEditLlbNwsLetter").length > 0 ){
			init_frm_edit_nwl();
		}
    //---------------------------------------------
    // Formulaire de recherche biblio
    if( jq("#frmAnnBibSearch").length > 0 ){
      init_bib_search();
    }
    if( jq("#frmAnnMediSearch").length > 0 ){
      init_medi_search();
    }
    if( jq("#frmAnnLibrSearch").length > 0 ){
      init_libr_search();
    }
    if( jq("#frmAnnMdllSearch").length > 0 ){
      init_mdll_search();
    }
    if( jq("#frmAnnOrgaSearch").length > 0 ){
      init_orga_search();
    }
    if( jq("#frmAnnStcSearch").length > 0 ){
      init_stc_search();
    }
    if( jq("#frmAnnAutSearch").length > 0 ){
      init_aut_search();
    }
    if( jq("#frmAnnPrsSearch").length > 0 ){
      init_prs_search();
    }

    //---------------------------------------------
    // Formulaire recherche feq...
    

    //---------------------------------------------
    // Formulaire d'édition des événements...
    if( jq("#frmEditLlbEvenement").length > 0 ){
      init_evt_back();
    }
    if( jq("#frmEvtSearch").length > 0 ){
      init_evt_front_search();
    }
    //---------------------------------------------
    // INSTANCES DE TRAVAIL
    // Formulaire d'édition des Groupes & Ateliers...
    if( jq("#frmEditLlbItGroupes, #frmEditLlbItAteliers").length > 0 ){
      init_it_back();
    }
    if( jq("#frmEditLlbIt").length > 0 || /instances-de-travail/.test(jq("body").attr('class')) ){
      init_it_front();
    }



    if( jq("#mycarousel").length > 0 ){
			jq('#mycarousel').jcarousel();
		}
  }//EO function
);