/**
 * Lance les fonctions necessaires au chargement de la page
 */ 
var j = jQuery.noConflict();
function majTinyMceProgramme(i){
    if(i == 0)
    {
      tinyMCE.execCommand("mceAddControl", false, "sous_programme_fr_descriptif");
      j.ajax({
            type: "GET",
            url: "/extranet_dev.php/operation/retourneValeur/moduleId/64",
            success: function(msg){
                gestionLangue();
                majTinyMceProgramme(1);
                j('#modifmodule').html(msg);
            }
        });
      /*new Ajax.Updater(j('#modifmodule'), '/extranet_dev.php/operation/retourneValeur/moduleId/64', {asynchronous:true, evalScripts:false, onComplete:function(request, json){gestionLangue();majTinyMceProgramme(1);}});*/
    }
    else if(i == 1)
    {
      tinyMCE.execCommand("mceAddControl", false, "sous_programme_en_descriptif");
    }
}
function gestionLangue(){
	
	// Gere la langue
    var langue = j('html').attr('lang');
    // Defini l'affichage en fonction de la langue
    if(langue == "en") {
        j('.langue .choixFr').removeClass('actif');
        j('.langue .choixEn').addClass('actif');
        j('.langue .fr').hide();
        j('.langue .en').show();
    } else {
        j('.langue .choixFr').addClass('actif');
        j('.langue .choixEn').removeClass('actif');
        j('.langue .fr').show();
        j('.langue .en').hide();
    }
    
    // Affiche le panneau de langue s'il contient une erreur
    j('.langue .error_list').each(function(){
        var divLangue = j(this).parent().parent();
        divLangue.show();
        if(divLangue.parent().find('.fr .error_list').length >= 1 && divLangue.parent().find('.en .error_list').length >= 1) {
            divLangue.parent().find('.choix a').addClass('actif');
        }
    });
    
    // Affiche le panneau anglais
    j('.langue .choixEn').click(function(){
        j(this).addClass('actif').prev().removeClass('actif').parent('.choix').next('.fr').hide().next('.en').show();
        return false;
    });   
    
    // Affiche le panneau francais
    j('.langue .choixFr').click(function(){
        j(this).addClass('actif').next().removeClass('actif').parent('.choix').next('.fr').show().next('.en').hide();
        return false;
    });

    // Affiche le detail des initiatives en mode liste
    j('.voirDetail').click(function(){
    	j(this).parent('td').parent('tr').next('tr').find('.switcher').slideToggle('normal');
    	return false;
    });
}

j(document).ready(function(){

    //gestion de l'affichage des tableau Js.
    if(j('.hidePadding').length) {
        var url = window.location.href;
        var ancre = url.split('#');
        if(typeof(ancre[1]) != 'undefined') {
            var initiativeId = ancre[1].split('_');
            if(typeof(initiativeId[1]) != 'undefined') {
                j('#'+initiativeId[0]).parent().parent().next().find('.switcher').show();
                location.replace('#'+ancre[1]);
            }
        }
    }
	gestionLangue();
	/**
 	* Gestion de la Modal Box Ajax
 	*/  
    j("a.jqModal").click(function () { 
        var id = j(this).attr('id');
        j('body').prepend('<div id="dialog" class="jqmWindow jqmID1" style="height: 80%; width: 600px; z-index: 3000; display: block; overflow:auto;">Veuillez patienter</div>');
        j('body').prepend('<div id="fondModal" class="jqmOverlay" style="height: 100%; width: 100%; position: fixed; left: 0pt; top: 0pt; z-index: 2999; opacity: 0.5; filter : alpha(opacity=50);" onClick="document.location.reload();return(false)"></div>');
        j.ajax({
            type: "GET",
            url: "/extranet.php/operation/modalParticipant",
            data: id,
            success: function(msg){
                j('#dialog').html(msg);
            }
        });
        return false;
    });
});
