/**
 * Fonction de traduction des chaines javascript
 */

function trad_js(id, rubrique) {
    if (typeof(i18n_tab) != 'undefined') {
        if (typeof(i18n_tab[id + '#' + rubrique]) != 'undefined') {
            return i18n_tab[id + '#' + rubrique];
        }
    }

    return id;
}

$(document).ready(function(){
    /*$(function(){
        $('img').error(function(){
            $(this).attr({
                'src' : '/images/common/broken_img.png',
                'alt' : "Desole, l'image n'est pas disponible",
                'style': 'border: 1px solid #f00;width:69px;height:56px;'
            });
        });
    });*/

    $(".img_message_confirm_annuler").click(close_popin_message);
        $("div.video").click(function(){
            var id = $(this).attr("id");

            ouverture_popup_lecture(elements[id]["mms"], elements[id]["type"], elements[id]["titre_js"], elements[id]["duree_reelle"]);
        });

	$('#navigation>li').hover(function(){
		$(this).find('ul').css('visibility', 'visible');
	},function(){
		$(this).find('ul').css('visibility', 'hidden');
	});

	$('#sous_navigation>ul>li').hover(function(){
		$(this).find('ul').css('visibility', 'visible');
	},function(){
		$(this).find('ul').css('visibility', 'hidden');
	});

    $(".onglet_no_actif>a").hover(function(){
        $(this).parent().css('background', 'url(/images/common/onglet_non_actif_over.png) no-repeat');
    }, function(){
        $(this).parent().css('background', 'url(/images/common/onglet_non_actif.png) no-repeat');
    });

    $(".onglet_no_actif .type_link").hover(function(){
        $(this).parent().parent().css('background', 'url(/images/common/onglet_non_actif_over.png) no-repeat');
    }, function(){
        $(this).parent().parent().css('background', 'url(/images/common/onglet_non_actif.png) no-repeat');
    });

    //-----------------------------------------------------------
    // Gestion des messages d'aide situés au niveau du sous menu
    //-----------------------------------------------------------

    // Récupération du message courant se trouvant dans help fonction
    var current_msg_menu = $("#help_page_sous_menu").html();

    $("#ma_bibliotheque_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_MA_BIBLIOTHEQUE', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    $("#mon_compte_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_MON_COMPTE', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    $("#creer_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_CREER', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    $("#mon_profil_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_MON_PROFIL', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    $("#mes_commandes_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_MES_COMMANDES', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    $("#mes_partages_msg").hover(function(){
        $("#help_page_sous_menu").html(trad_js('MESSAGE_MES_PARTAGES', 'header'));
    }, function (){
        $("#help_page_sous_menu").html(current_msg_menu);
    });

    //---------------------------------------------------------------------------------
    // Tooltips pour les onglets "myforever manager", "myforever studio" et "boutique"
    //---------------------------------------------------------------------------------

    $("#myforever_studio_msg").wTooltip({
        content: "<p>" + trad_js('MESSAGE_MYFOREVER_STUDIO', rubrique='header') + "</p>",
        offsetY: 30,
        fadeIn: "slow",
        delay: 100,
        style: {
            fontSize : "14px",
            width: "200px",
            background: "#c3c3d7"
        }
    })

    $("#myforever_manager_msg").wTooltip({
        content: "<p>" + trad_js('MESSAGE_MYFOREVER_MANAGER', rubrique='header') + "</p>",
        offsetY: 30,
        fadeIn: "slow",
        delay: 100,
        style: {
            fontSize : "14px",
            width: "200px",
            background: "#c3c3d7"
        }
    })

    $("#boutique_msg").wTooltip({
        content: "<p>" + trad_js('MESSAGE_BOUTIQUE', rubrique='header') + "</p>",
        offsetY: 30,
        fadeIn: "slow",
        delay: 100,
        style: {
            fontSize : "14px",
            width: "200px",
            background: "#c3c3d7"
        }
    })

    // Hack safari pour régler le problème des bords arrondis
    if ($.browser.safari) {
        $('.grey_rounded_zone').find('.top_left_corner, .top_right_corner, .bottom_left_corner, .bottom_right_corner').css('display', 'none');
        $('.grey_rounded_zone').find('.middle_top').css({
            '-webkit-border-top-left-radius': '7px',
            '-webkit-border-top-right-radius': '7px',
            'margin': '0px'
        });
        $('.grey_rounded_zone').find('.middle_bottom').css({
            '-webkit-border-bottom-left-radius': '7px',
            '-webkit-border-bottom-right-radius': '7px',
            'margin': '0px'
        });
        $('.dark_rounded_zone').find('.top_left_corner, .top_right_corner, .bottom_left_corner, .bottom_right_corner').css('display', 'none');
        $('.dark_rounded_zone').find('.middle_top').css({
            '-webkit-border-top-left-radius': '7px',
            '-webkit-border-top-right-radius': '7px',
            'margin': '0px'
        });
        $('.dark_rounded_zone').find('.middle_bottom').css({
            '-webkit-border-bottom-left-radius': '7px',
            '-webkit-border-bottom-right-radius': '7px',
            'margin': '0px'
        });
    }

    // Initialisation des hideshow
    init_hideshow(document);

    init_tabzone_elements();
    init_tabzone();
    init_popup();
	init_paiement();
    init_popin();

    // Activation des modes de visualisation de vidéos sur la home de l'espace mon-compte
    if ($('#tabzone_elements').length == 1) {
        $('.tabzone_zone').each(function() {
            var current_tabzone = this;
            $(current_tabzone).find('.element_video_mode_action_small').click(function() {
                if ($(current_tabzone).find('.element_video').hasClass('element_video_mode_large')) {
                    $(current_tabzone).find('.element_video')
                        .removeClass('element_video_mode_large')
                        .addClass('element_video_mode_small');
                }
                $(this)
                    .addClass('selected_element_video_mode')
                $(current_tabzone).find('.element_video_mode_action_large')
                    .removeClass('selected_element_video_mode')
            })
            .css('cursor', 'pointer');

            $(current_tabzone).find('.element_video_mode_action_large').click(function() {
                if ($(current_tabzone).find('.element_video').hasClass('element_video_mode_small')) {
                    $(current_tabzone).find('.element_video')
                        .removeClass('element_video_mode_small')
                        .addClass('element_video_mode_large');
                }
                $(this)
                    .addClass('selected_element_video_mode')
                $(current_tabzone).find('.element_video_mode_action_small')
                    .removeClass('selected_element_video_mode')
            })
            .css('cursor', 'pointer');

        });
    }

    // Application d'ifixpng
    $.ifixpng('/images/common/pixel.gif');
    $('img[src$=.png]').not('.no_ifix').ifixpng();

    // Code temporaire pour l'icone facebook
    $('.action_facebook_temp').click(function() {
        alert('Bientôt disponible sur la Forever Box');
    }).css('cursor', 'pointer');

    //Code appliqué sur commande-num permettant de choisir les données de livraison (même adresse ou adresse différente)
    $('.livraison_choix_true').click(function(){
        $('input[name="livraison_choix"]').val(1);
    });

    $('.livraison_choix_false').click(function(){
        $('input[name="livraison_choix"]').val(0);
    });

    //Code temporaire pour charger l'adresse dans le cadre même adresse
    // A améliorer
    if($('#affichage_adresse').size() > 0){
        $("input").blur(function(){
            if($('input[name="numerisation"]').val() == 'true'){

                var adresse = $('input[name="enlevement_nom"]').val()+' '+$('input[name="enlevement_prenom"]').val()+'<br/>'+
                            $('input[name="enlevement_adresse1"]').val();

                if($('input[name="enlevement_adresse2"]').val().length > 0){
                    adresse += ' - ';
                }

                adresse += $('input[name="enlevement_adresse2"]').val()+'<br/>'+
                        $('input[name="enlevement_code_postal"]').val()+' '+$('input[name="enlevement_ville"]').val();

                $('#affichage_adresse').empty();
                $('#affichage_adresse').append(adresse);

            }else{

                var adresse = $('input[name="nom"]').val()+' '+$('input[name="prenom"]').val()+'<br/>'+
                            $('input[name="adresse1"]').val();

                if($('input[name="adresse2"]').val().length > 0){
                    adresse += ' - ';
                }

                adresse += $('input[name="adresse2"]').val()+'<br/>'+
                        $('input[name="code_postal"]').val()+' '+$('input[name="ville"]').val();

                $('#affichage_adresse').empty();
                $('#affichage_adresse').append(adresse);
            }
        });
    }

});


if(navigator && navigator.vendor && navigator.vendor.match(new RegExp("Apple", "g"))){
    var safari = 1;
}else{
    var safari = 0;
}

function ouverture_popup_lecture(src, type, nomelem, duree){
    if($("#fond").length == 0){
        $("body").prepend("<div id=\"fond\" style=\"display: none;\"></div>");
    }

    if($("#lecture").length == 0){
        $("#contenu_rubrique").before("<div id=\"lecture\" style=\"display: none;\">\n" +
            "<table>\n" +
                "<tr>\n" +
                    "<td></td>\n" +
                    "<td style=\"padding-bottom: 15px;\" align=\"right\" class=\"action-fermer\"><span style=\"border-bottom: 1px solid #999;\">" + trad_js('FERMER', 'global') + "</span></td>\n" +
                "</tr>\n" +
            "</table>\n" +

            "<table>\n" +
                "<tr>\n" +
                    "<td style=\"width: 80px; background-color: #eee; padding: 2px;\"><strong>" + trad_js('TITRE', 'indexation') + "</strong></td>\n" +
                    "<td style=\"width: 520px; background-color: #eee; padding: 2px;\"><div id=\"lecture-titre\"></div></td>\n" +
                "</tr>\n" +
                "<tr>\n" +
                    "<td style=\"padding: 2px;\"><strong>" + trad_js('TYPE', 'indexation') + "</strong></td>\n" +
                    "<td style=\"padding: 2px;\"><div id=\"lecture-type\"></div></td>\n" +
                "</tr>\n" +
                "<tr>\n" +
                    "<td style=\"background-color: #eee; padding: 2px;\" valign=\"top\"><strong>" + trad_js('DUREE', 'indexation') + "</strong></td>\n" +
                    "<td style=\"background-color: #eee; padding: 2px;\" valign=\"top\"><div id=\"lecture-duree\"></div></td>\n" +
                "</tr>\n" +
                "<tr>\n" +
                    "<td style=\"padding: 10px 0;\" colspan=\"2\" align=\"center\"><div id=\"media-player\"></div></td>\n" +
                "</tr>\n" +
            "</table>\n" +
            "</div>");
    }

    /*
    if(safari){
        $("#lecture-type-safari").html(type);
        $("#lecture-titre-safari").html(nomelem.replace(/</g, "&lt;"));
        $("#lecture-duree-safari").html(duree);

        $("#lecture-safari").show();

        lire_video("media_player_lecture_safari", src);
    }else{
    */
        $("#lecture-type").html(type);
        $("#lecture-titre").html(nomelem.replace(/</g, "&lt;"));
        $("#lecture-duree").html(duree);

        var flash = document.getElementsByTagName("object");
        for(var i = 0; i < flash.length; i++){
            if(flash[i].type != "video/x-ms-wmv"){
                flash[i].style.visibility = "hidden";
            }
        }

        lire_video(src);

        $("#fond").css("height", document.documentElement.scrollHeight + "px");
        $("#fond").show();
        $("#lecture").show();
    //}

    $("#fond").click(function(){
        fermeture_popup_lecture();
    });

    $("td.action-fermer").click(function(){
        fermeture_popup_lecture();
    }).hover(function(){
        $(this).css("cursor", "pointer");
    }, function(){});

    document.location.href = "#";
}

function fermeture_popup_lecture(){
    $("#lecture").hide();
    $("#fond").hide().unbind("click");
    $("td.action-fermer").unbind("click").unbind("hover");

    var flash = document.getElementsByTagName("object");
    for(var i = 0; i < flash.length; i++){
        if(flash[i].type != "video/x-ms-wmv"){
            flash[i].style.visibility = "visible";
        }
    }
}

function lire_video(src){
    var media_player_id = "media-player";

    if(safari){
        var object_height = 260;
    }else{
        var object_height = 304;
    }
/*
    var html = '<object type="video/x-ms-wmv" data="' + src + '" width="320" height="' + object_height + '">'+ "\n" +
        '<param name="src" value="' + src + '" />'+ "\n" +
        '<param name="qtsrc" value="' + src + '" />'+ "\n" +
        '<param name="controller" value="true" />'+ "\n" +
        '<param name="autoplay" value="true" />'+ "\n" +
        '<param name="autostart" value="true" />'+ "\n" +
        '<param name="url" value="' + src + '">'+ "\n" +
        '</object>';


    var html = '<object type="video/x-ms-wmv" data="' + src + '" width="320" height="' + object_height + '">'+ "\n" +
        '<param name="src" value="' + src + '">'+ "\n" +
        '<param name="autoStart" value="0">'+ "\n" +
        'alt : <a href="' + src + '">' + src + '</a>'+ "\n" +
        '</object>';
*/

    var html = '<object type="video/x-ms-wmv" data="' + src + '" width="320" height="' + object_height + '">'+
        '<param name="src" value="' + src + '" />'+
        '<param name="qtsrc" value="' + src + '" />'+
        '<param name="controller" value="true" />'+
        '<param name="autoplay" value="true" />'+
        '<param name="autostart" value="true" />'+
        '<param name="url" value="' + src + '">'+
        '</object>';

    $("#" + media_player_id).html(html);
}

/**
 * Initialise l'effet de hideshow
 */
function init_hideshow(parent_element) {
    if (!parent_element) {
        parent_element = document;
    }

	$(parent_element).find('.hideshow').each(function() {
		//$(this).addClass('hideshow_mode_hide');
		$(this).find('.hideshow_action_show').click(function() {
			var currentHideshow = $(this).parents('.hideshow').eq(0);
			$(currentHideshow).addClass('hideshow_current');
			$(currentHideshow)
				.removeClass('hideshow_mode_hide')
				.addClass('hideshow_mode_show');

			$(currentHideshow).find('.hideshow_onshow').map(function() {
				if ($(this).parents('.hideshow').eq(0).hasClass('hideshow_current')) {
					return this;
				}
			})
			.css('display', '');

			$(currentHideshow).find('.hideshow_onhide').map(function() {
				if ($(this).parents('.hideshow').eq(0).hasClass('hideshow_current')) {
					return this;
				}
			})
			.css('display', 'none');

			$(currentHideshow).removeClass('hideshow_current');
		})
		.css('cursor', 'pointer');

		$(this).find('.hideshow_action_hide').click(function() {
			var currentHideshow = $(this).parents('.hideshow').eq(0);
			$(currentHideshow).addClass('hideshow_current');
			$(currentHideshow)
				.removeClass('hideshow_mode_show')
				.addClass('hideshow_mode_hide');

			$(currentHideshow).find('.hideshow_onshow').map(function() {
				if ($(this).parents('.hideshow').eq(0).hasClass('hideshow_current')) {
					return this;
				}
			})
			.css('display', 'none');

			$(currentHideshow).find('.hideshow_onhide').map(function() {
				if ($(this).parents('.hideshow').eq(0).hasClass('hideshow_current')) {
					return this;
				}
			})
			.css('display', '');

			$(currentHideshow).removeClass('hideshow_current');
		})
		.css('cursor', 'pointer');

        if ($(this).hasClass('hideshow_mode_show')) {
            $(this).find('.hideshow_onshow').css('display', '');
            $(this).find('.hideshow_onhide').css('display', 'none');
        } else {
            $(this).find('.hideshow_onshow').css('display', 'none');
            $(this).find('.hideshow_onhide').css('display', '');
        }
	});
	//$(parent_element).find('.hideshow_onshow').css('display', 'none');
    //$(parent_element).find('.hideshow_onhide').css('display', '');
}

function init_tabzone_elements() {
    var ancre = document.location.hash;
    $('#tabzone_elements li:has(a)').each(function() {
        if($(this).find('a').attr('href') == ancre) {
            $('#tabzone_elements').find('.tabzone_current').removeClass('tabzone_current');
            $(this).addClass('tabzone_current');
        }
    });
}

/**
 * Initialise tab effect on related elements
 */
function init_tabzone() {
	$('.tabzone').each(function() {
		var tabzone = this;
		$(tabzone).find('.tabzone_zone').css('display', 'none');

		var listTabs = $(tabzone).find('.tabzone_tabs_container li:has(a)');
		if (listTabs.length != $(tabzone).find('.tabzone_zone').length) {
			return;
		}

		for (var i = 0; i < listTabs.length; i++) {
			listTabs[i].tabId = i;
			$(listTabs[i]).click(function() {
                $(tabzone).find('.tabzone_current').removeClass('tabzone_current');

				$(this).addClass('tabzone_current');

				$('#' + tabzone.id).find('.tabzone_zone').css('display', 'none');
				$('#' + tabzone.id).find('.tabzone_zone').eq(this.tabId).css('display', '');
			});

			if ($(listTabs[i]).hasClass('tabzone_current')) {
				$(tabzone).find('.tabzone_zone').eq(i).css('display', '');
			}
		}

	});
}

/**
 * Initialise des popups
 */
function init_popup(){
    this.popup_window = false;
	$(".popup").click(function() {
		var reg    = new RegExp("popup_size_([0-9]+)x([0-9]+)","g");
		var result = reg.exec($(this).attr('class'));
		var width  = result[1];
		var height = result[2];
		if (this.popup_window) {
            this.popup_window.close();
        }
		this.popup_window = window.open($(this).attr("href"), 'popup', 'scrollbars=yes, width=' + width + ', height=' + height );

		return false;
	});
}

/**
 * Traitement effectué au chargement d'une page à l'interieur de l'iframe
 */
function joomla_iframe_onload() {
    top.window.scrollTo(0,0);
    joomla_iframe_resize();
}

/**
 * Maj de la hauteur de l'iframe joomla
 */
function joomla_iframe_resize() {
    $(parent.document).find('iframe.wrapper')
        .css("height", $('#conteneur').height() + "px");
}

function init_paiement() {
	if($("#accept_cgv").length > 0) {

		$("form[name=saisie]").submit( function() {
			if($('#accept_cgv input').attr('checked')) {
                if ($(this).hasClass('no_alert')) {
                    return true;
                } else {
                    return confirm(trad_js('CONFIRMER_PAIEMENT_CHEQUE', 'commande'));
                }
			}
			else {
				alert(trad_js('VEUILLEZ_ACCEPTER_CGU', 'commande'));
				$('#accept_cgv').fadeOut('fast');
				$('#accept_cgv').fadeIn('slow');
				return false;
			}
		});

		$("form[name=PaymentRequest]").submit( function() {
			if($('#accept_cgv input').attr('checked')) {
                if ($(this).hasClass('no_alert')) {
                    return true;
                } else {
                    return confirm(trad_js('CONFIRMER_PAIEMENT_CB', 'commande'));
                }
			}
			else {
				alert(trad_js('VEUILLEZ_ACCEPTER_CGU', 'commande'));
				$('#accept_cgv').fadeOut('fast');
				$('#accept_cgv').fadeIn('slow');
				return false;
			}
		});

		$("form[name=paypal]").submit( function() {
			if($('#accept_cgv input').attr('checked')) {
                if ($(this).hasClass('no_alert')) {
                    return true;
                } else {
                    return confirm(trad_js('CONFIRMER_PAIEMENT_PAYPAL', 'commande'));
                }
			}
			else {
				alert(trad_js('VEUILLEZ_ACCEPTER_CGU', 'commande'));
				$('#accept_cgv').fadeOut('fast');
				$('#accept_cgv').fadeIn('slow');
				return false;
			}
		});
	}
}

/**
 * Maj des infos du code promo
 */

function maj_code_promo(total_ttc) {
    // Récupération des données
    var code_promo = $('#code_promo').val();
    var type_commande = $('#type_commande').val();

    // Si le montant total ttc courant n'est pas fournit
    if (total_ttc == null) {
        total_ttc = '-1';
    }

    // Appel du ws
    $.ajax({
        type: "POST",
        url: "/code-promo-ajax.php?lang=" + js_language,
        data: "check_promo=check&code_promo=" + code_promo + "&total_ttc=" + total_ttc + "&type_commande=" + type_commande,
        async: "false",
        dataType: "text",
        success: function(msg) {
            // Récupération du message de retour
            var tab_msg = msg.split('||');
            if (tab_msg.length >= 2) {
                switch (tab_msg[0]) {
                    // Succès
                    case 'OK':
                        if (tab_msg[1] != '') {
                            $('#code_promo_info')
                                .fadeOut('400', function() {
                                    $(this)
                                        .attr('class', '')
                                        .addClass('message-info')
                                        .html(tab_msg[1])
                                        .fadeIn('400');
                                });

                            $('#code_promo_remise').html(parseFloat(tab_msg[2]).toFixed(2));
                        }
                        break;

                    // Mitigé
                    case 'OKO':
                        if (tab_msg[1] != '') {
                            $('#code_promo_info')
                                .fadeOut('400', function() {
                                    $(this)
                                        .attr('class', '')
                                        .addClass('message-warning')
                                        .html(tab_msg[1])
                                        .fadeIn('400');
                                });
                            $('#code_promo_remise').html('0');
                        }
                        break;

                    // Echec
                    case 'KO':
                        if (tab_msg[1] != '') {
                            $('#code_promo_info')
                                .fadeOut('400', function() {
                                    $(this)
                                        .attr('class', '')
                                        .addClass('message-erreur')
                                        .html(tab_msg[1])
                                        .fadeIn('400');
                                });
                            $('#code_promo_remise').html('0');
                        }
                        break;
                }
            }
        }
    });
}

/**
 * Completion à zéro d'un id
 */

function strpad_zero(input) {
    var tmp = '0000000' + input;
    var output = tmp.split('').reverse().slice(0, 7).reverse().join('');
    return output;
}

/**
 * Initialisation des popins
 */

function init_popin() {
    // Recherche des elements de déclenchement
    $('.popin_onclick').each(function() {
        var message = $(this).attr("class").match(/popin-([-_a-zA-Z]+)/)[1];
        if (message != undefined) {
            $(this).click(function() {
                popin('#' + message);
            })
            .css('cursor', 'pointer');
        }
    });
}

/**
 * Affichage d'une popin
 */

function popin(message, titre) {
    if (titre == undefined) {
        titre = 'Informations';
    }

    //Recuperation de la taille du conteneur pour savoir quelle popin choisir
    if($(message).attr("class").match(/popin_size-([0-9]+)/)){
        var popin_size = $(message).attr("class").match(/popin_size-([0-9]+)/)[1];
        //Choix de la taille de la popin en fonction de popin size
        if(popin_size < 250){
            $("#popin_message").addClass('base_popin_mini_message_container ');
            $("#popin_message").data('newClass', 'base_popin_mini_message_container ');
        }else if(popin_size >= 250 && popin_size < 400){
            $("#popin_message").addClass('base_popin_container');
            $("#popin_message").data('newClass', 'base_popin_container');
        }else if(popin_size >= 400 && popin_size < 600){
            $("#popin_message").addClass('base_popin_message_container ');
            $("#popin_message").data('newClass', 'base_popin_message_container');
        }else if(popin_size >= 600){
            $("#popin_message").addClass('base_popin_large_message_container');
            $("#popin_message").data('newClass', 'base_popin_large_message_container');
        }
    }

    //Recuperation de la classe de popin
    if($(message).attr("class").match(/popin_class-([_a-z]+)/)){
        var popin_class = $(message).attr("class").match(/popin_class-([_a-z]+)/)[1];

        $("#popin_message").addClass(popin_class);
        $("#popin_message").data('customClass', popin_class);
    }

    // S'il s'agit de l'id d'un élément existant
    if (message.charAt(0) == '#') {
        popin_message(message);
    } else {
        popin_alert(message, titre);
    }
}

/*function close_popin_message() {
    $.unblockUI({
        onUnblock: function() {
            var message = $('#popin_message').data('current_id');

            // S'il s'agit de l'id d'un élément existant
            if (message != undefined && message.charAt(0) == '#') {
                // Récupération du corp de la popin
                var inner = $(message);
                inner.appendTo('#contenus_container');
            }

            // Effacement du contenu de la popin
            $('#popin_message').find('.base_popin_inner').html('');
            $('#popin_message').find('.base_popin_header').find('span').html('');
        }
    });
}*/

/**
 * Affichage d'un message dans une popin
 */

function popin_message(dom_id) {
    // Modification du corp de la popin
    var inner = $('#popin_message').find('.base_popin_inner');
    $(dom_id).appendTo(inner);

    // Enregistrement de l'id
    $('#popin_message').data('current_id', dom_id);

    // Positionnement de la popin
    var window_height = $(window).height();
    var popin_height = $('#popin_message').height();
    var top_value = 0;
    if (window_height > popin_height) {
        $('#popin_message').css('top', ((window_height / 2) - (popin_height / 2)) + 'px');
    }

    // Affichage de la popin
    $.blockUI({
        message: $('#popin_message'),
        centerX: false,
        centerY: false,
        css: { cursor: 'default' }
    });

    // Activation de la fermeture
    if ($('#popin_message').data('is_running') == undefined) {
        $('#popin_message').find('.base_popin_close').click(close_popin_message);
        $('#popin_message').data('is_running', true);
    }
}


/**
 * Fermeture de la popin message
 */

function close_popin_message() {
    $.unblockUI({
        onUnblock: function() {
            var dom_id = $('#popin_message').data('current_id');
            // Récupération du corp de la popin
            var inner = $(dom_id);
            inner.appendTo('#contenus_container');

            // Effacement du contenu de la popin
            $('#popin_message').find('.base_popin_inner').html('');
            $('#popin_message').find('.base_popin_header > span').html('');
            if($("#popin_message").data('newClass') != undefined){
                $("#popin_message").removeClass($("#popin_message").data('newClass'));
            }

            if($("#popin_message").data('customClass')!= undefined){
                $("#popin_message").removeClass($("#popin_message").data('customClass'));
            }
            if($("#popin_message").data('onCloseCallback')!= undefined){
                var onCloseCallback = $("#popin_message").data('onCloseCallback');
                onCloseCallback();
                $("#popin_message").removeData('onCloseCallback');
            }
        }
    });
}

/**
 * Affichage d'un alert dans une popin
 */

function popin_alert(message, titre) {
    // Modification du corp de la popin
    $('#popin_alert').find('.base_popin_inner').html(message);

    // Modification titre de la popin
    $('#popin_alert').find('.base_popin_header').find('span').html(titre);

    // Positionnement de la popin
    var window_height = $(window).height();
    var popin_height = $('#popin_alert').height();
    var top_value = 0;
    if (window_height > popin_height) {
        $('#popin_alert').css('top', ((window_height / 2) - (popin_height / 2)) + 'px');
    }

    // Affichage de la popin
    $.blockUI({
        message: $('#popin_alert'),
        centerX: true,
        centerY: false,
        css: { cursor: 'default' }
    });

    // Activation de la fermeture
    if ($('#popin_alert').data('is_running') == undefined) {
        $('#popin_alert').find('.base_popin_close').click(close_popin_alert);
        $('#popin_alert').data('is_running', true);
    }
}


/**
 * Fermeture de la popin d'alert
 */

function close_popin_alert() {
    $.unblockUI({
        onUnblock: function() {
            // Effacement du contenu de la popin
            $('#popin_alert').find('.base_popin_inner').html('');
            $('#popin_alert').find('.base_popin_header').find('span').html('');
        }
    });
}