// Variables globale
var dispNumNav;

$(document).ready(function () {

    // D�tection de la plateforme
    // 1- Gestion des vid�os
    var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
    if (agentID) {
        $('#video_multi_plateform').hide();
        $('#video_mac').show();
    }

    // URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
    /*if( jQuery.browser.msie && (jQuery.browser.version == '6.0') )
     DD_belatedPNG.fix('#container_main_top img, #container_main_bottom img, #menu_bottom .box_logo img, \n\
     #header_main .box_logo img, \n\
     #container_main,\n\
     #container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_topLeft,\n\
     #container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_topRight,\n\
     #container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_bottomLeft,\n\
     #container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_bottomRight,\n\
     .jcarousel-skin-vge-simple .jcarousel-prev-horizontal,\n\
     .jcarousel-skin-vge-simple .jcarousel-next-horizontal,\n\
     .jcarousel-skin-vge-simple .jcarousel-clip-horizontal .jcarousel-control a,\n\
     .jcarousel-skin-vge-simple .jcarousel-clip-horizontal .jcarousel-control a.curNav,\n\
     #container_center #content_main_carrousel .carrouselTitle h3,\n\
     #container_center #content_main .content_main_language,\n\

     .dropdown_opener_closed,\n\
     .dropdown_bottom,\n\
     .submenu_bottom,\n\
     .submenu_top,\n\
     .jcarousel-skin-vge-simple .carrouselImg,\n\
     #menu_bottom_bottom,\n\
     #menu_bottom #menu_bottom_center');*/
    if (jQuery.browser.msie && (jQuery.browser.version == '6.0'))
        DD_belatedPNG.fix('.dropdown_bottom,\n\
		#container_main_home #content_container #content_main .content_main_visitors,\n\
		#container_main_home #content_container #content_main .content_main_notice,\n\
		.submenu_bottom,\n\
		.dropdown_opener_closed,\n\
		#menu_top li a.btn1,\n\
		.submenu_top');

    if (jQuery.browser.msie && (jQuery.browser.version == '6.0' || jQuery.browser.version == '7.0')) {
        /*DD_roundies.addRule('#menu_top a.btn1', '5px 0 0 5px', true);
         DD_roundies.addRule('#menu_top #plan_de_ville a', '0 5px 5px 0', true);
         DD_roundies.addRule('#content_surtitre.stickTitle', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_center.theme #content_surtitre', '5px', true);
         DD_roundies.addRule('#content_left #content_left_title', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_center #content_main .blocPublic', '5px', true);
         DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion ul', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion ul.listLink', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion #firstMenu', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_center #content_main .content_1col_grey', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_right h3.csc-firstHeader', '5px 5px 0 0', true);
         DD_roundies.addRule('#menu_bottom #menu_bottom_center', '5px 5px 0 0', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_news_links', '5px', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_notice', '5px', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_visitors', '5px', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_language', '5px', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_zone', '5px', true);
         DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_zone_bottom', '5px', true);*/
    }
    if ($('#container_right_1 ul li').length != 0) {
        $("#container_right_1 ul li:last-child").css('border-bottom', 'none');
        $("#container_right_1 ul li:last-child").css('margin-bottom', '0');
    }
    if ($('.inside_right_column_middle .box_generic').length) {
        $('.inside_right_column_middle .box_generic:last-child .csc-textpic-intext-left').css('border-bottom', 'none');
    }
    // Gestion des pages d'atterrissage
    // Si image : changement de classe pour qu'elle soit collée au surtitre
    if ($('#content_image').length != 0) {
        //$('#content_surtitre').next('.content_separator_5').css('display','none');
        //$('#content_image').addClass('stickImage');
        $('#content_surtitre').addClass('stickTitle');
        $('#container_image').css("width", $('#content_image img').width());
        if ($('#content_image img').width() < '595')
            $('#container_image').css("margin", '5px 0 0 20px');
    }

    $("#accessibility").css({display:"none"});

    $('#content_main p.bodytext img').each(function () {
        if ($(this).css('float') == 'left')
            $(this).css({'margin':'5px 10px 10px 0'});
        else
            $(this).css({'margin':'5px 0 10px 10px'});
    });

    $('#content_main #content_main_zone_right p.bodytext img').each(function () {
        $(this).css({'margin':'0'});
    });

    // On cache les sous-menus
    // sauf celui qui porte la classe "open_at_load" :
    $("div.subMenu:not('.open_at_load')").hide();
    // On selectionne tous les items de liste portant la classe "toggleSubMenu"

    // On modifie l'évènement "click" sur les liens dans les items de liste
    // qui portent la classe "toggleSubMenu" :
    $("li.toggleSubMenu").children("span").click(function () {
        // Si le sous-menu était déjà ouvert, on le referme :
        if ($(this).parent().children("div.subMenu:visible").length != 0) {
            $(this).parent().children("div.subMenu").slideUp("normal", function () {
                $(this).parent().removeClass("open")
                /* $("#content_left").animate( {
                 marginTop:$("#container_left").height()
                 }, "medium");*/
            });
        }
        // Si le sous-menu est caché, on ferme les autres et on l'affiche :
        else {
            $(".nav div.subMenu").slideUp("normal", function () {
                $(this).parent().removeClass("open")
                /*$("#content_left").animate( {
                 marginTop:$("#container_left").height()
                 }, "medium");*/
            });
            $(this).parent().children("div.subMenu").slideDown("fast", function () {
                $(this).parent().addClass("open")
                /*$("#content_left").animate( {
                 marginTop:$("#container_left").height()
                 }, "medium");*/
            });
        }
        // On empêche le navigateur de suivre le lien :
        //return false;
    });

    /**
     * Gestion de la hauteur de la page
     * Ajuste la colonne centrale et la gauche en fonction de la colonne de droite
     */
    if ($('#content_container').height() < $('#container_right').height()) {
        var rightHeight = parseInt($('#container_right').height()) - parseInt('10')
        $('#content_container').height(rightHeight)
    }

    var leftColHeight = parseInt($('#container_left').height()) + parseInt($('#content_left').height()) + parseInt('120')

    if ($('#content_container').height() < leftColHeight) {
        $('#content_container').height(leftColHeight)
    }

    /**
     * Gestion des annonces
     */

    var p = $("#content_left");
    var w = $("#container_left");
    p.css({
        'margin-top':w.height() + parseInt('100')
    });

    // On cache le titre si il n'y a pas d'annonces
    if ($('#content_left_1').html() == '<!--TYPO3SEARCH_begin--><!--TYPO3SEARCH_end-->')
        $('#content_left').css('display', 'none');

    $('#content_left .texteAnnonce').click(function () {
        window.location = $(this).prevAll('a').attr('href');
    });

    // Initialise le carrousel
    if ($(".carrousel").length !== 0)
        jQuery('.carrousel').jcarousel();

    if ($(".carrousel_simple").length !== 0) {
        // Initialisation du carrousel
        dispNumNav = 'caroussel_home';
        jQuery('.carrousel_simple').jcarousel({
            scroll:1,
            wrap:'last',
            auto:5,
            animation:'medium',
            easing:'linear',
            initCallback:carrousel_initCallback,
            itemLoadCallback:carrousel_itemLoadCallbackFunction
        });

    }

    if ($(".carrousel_plan_de_ville").length !== 0) {
        dispNumNav = 'caroussel_pdv';
        // Initialisation du carrousel
        jQuery('.carrousel_plan_de_ville').jcarousel({
            scroll:1,
            wrap:'last',
            auto:5,
            animation:'medium',
            easing:'linear',
            initCallback:carrousel_initCallback,
            itemLoadCallback:carrousel_itemLoadCallbackFunction_illus
        });
    }

    // Gestion du rollover sur le titre - Affichage du caption
    $(".carrouselTitle h3 a").mouseenter(function () {
        if ($(".carrouselTitle h3").css('top') == '161px') {
            $(".caption").hide('fast');
            $(".carrouselTitle h3").animate({top:"216px"}, 300, false);
        } else {
            $(".carrouselTitle h3").animate({top:"161px"}, 300, false);
            $(".caption").show('slow');
        }

    });

    /**
     *
     *   GESTION DES SELECTEURS
     *   utilise extensions.mins.js
     *
     **/
    $(".sel_openPage").change(function () {
        if ($(this).val() != '')
            window.location.href = "http://" + window.location.host + "/" + $(this).val();
    });

    $(".content_shortcut_middle .wrapper select").change(function () {
        if ($(this).val() != '')
            window.location.href = "http://" + window.location.host + "/" + $(this).val();
    });

    if (!$('#content_main select').hasClass('specialSelect')) {
        $('#content_main select').sSelect({
            ddMaxHeight:'300px',
            ddDefWidth:'2'
        });
    }

    if (!$('#container_left select').hasClass('specialSelect')) {
        $('#container_left select').sSelect({
            ddMaxHeight:'300px',
            ddDefWidth:'2'
        });
    }

    $('#container_right .panier select').sSelect({
        ddMaxHeight:'300px',
        ddDefWidth:'2'
    });

    // Search query
    var page_query = "";
    // Starting page offset, usually 0 for 1st page, 10 for 2nd, 20 for 3rd.
    var page_start = "";
    // Front end that served the page.
    var page_site = "www";
    //

// Affichage des légendes d'images pour le caroussel
    $("ul.carrousel li.jcarousel-item").each(function (i) // Notice the 'i' argument
    {
        if ($(this).children(".caption").children(".csc-caption").length != 0) {
            $(this).qtip({
                content:$(this).children(".caption").children(".csc-caption").html(),
                position:{
                    // adjust: { x: 0, y: -$("li.jcarousel-item-1 a img").height() },
                    adjust:{x:0, y:-20},
                    corner:{
                        target:'bottomMiddle',
                        tooltip:'topMiddle'
                    }
                },
                style:{
                    width:200,
                    padding:5,
                    background:'#FFFFFF',
                    color:'black',
                    textAlign:'center',
                    border:{
                        width:1,
                        radius:2,
                        color:'#CECECE'
                    },
                    tip:{
                        corner:true,
                        size:{
                            x:20, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                            y:30 // Depending on which corner your tooltip is at, x and y could mean either height or width!
                        }
                    }
                    //name: 'dark' // Inherit the rest of the attributes from the preset dark style
                }
            })

        }
    });

// Gestion des liens pour les listes des sous rubriques - Entrée de thème
// Permet de cliquer sur tout le block
    $('div#content_main ul.csc-menu li').mouseover(
        function () {
            $(this).css('cursor', 'pointer')
            /*$(this).css('background-color', '#F8F8F8')*/
        }).mouseout(function () {
            $(this).css('cursor', 'default')
            /*$(this).css('background-color', 'transparent')*/
        });

    $('div#content_main ul.csc-menu li').click(function () {
        rubLink = $(this).children('a').attr('href');
        window.location = rubLink;
    });

// Cartes CFF
    $('ul.carteCFF li').each(function (i) {
        var nbCartes = $(this).children('p.nbCartesCFF').html()
        if (parseInt(nbCartes) <= 6) {
            $(this).removeClass('cff_vert');
            $(this).addClass('cff_orange');
        }
        if (parseInt(nbCartes) == 0) {
            $(this).removeClass('cff_vert');
            $(this).addClass('cff_rouge');
        }
    });

    //Affichage des block de mois
    $('ul.carteCFF').each(function (i) {
        // Identifiant des blocks
        $(this).parent().addClass('cff_' + i);
        //$('span.navPrev').css('display','none');

        // Nombre d'élément dans la page
        nbElt = $('div.box_generic').find('ul.carteCFF').length;

        // Masque tous les mois sauf le premier
        if (i != 0)
            $(this).parent().hide()

        // Précédent
        $(this).prev().children('span.navPrev').click(function () {

            if ($(this).hasClass('disable'))
                return

            prev_item = parseInt(i) - 1

            // Masque le mois courant
            $(this).parent().parent().fadeOut(500, function () {
                $('.cff_' + prev_item).fadeIn(500);
                // Gestion des boutons de nav
                $('span.navNext').removeClass('disable');
                if (prev_item == 0)
                    $('span.navPrev').addClass('disable');
            });
        });

        // Suivant
        $(this).prev().children('span.navNext').click(function () {

            if ($(this).hasClass('disable'))
                return

            next_item = parseInt(i) + 1
            next_item_tot = parseInt(i) + 2

            $(this).parent().parent().fadeOut(500, function () {
                $('.cff_' + next_item).fadeIn(500);
                // Gestion des boutons de nav
                $('span.navPrev').removeClass('disable');
                // Masque le bouton suivant si on est au dernier mois
                if (next_item_tot == nbElt)
                    $('span.navNext').addClass('disable');
            });

        });
    });

    // Gestion des listes à puces. Si commence par un lien - Ajout de la classe listLink pour avoir les flèches
    $('#content_main ul li:first-child').each(function () {
        if ($(this).parent().parent().parent().parent().parent().attr('class') != 'boxAtterissageAccordion') {
            if ($(this).html().substr(0, 2) == '<a' || $(this).html().substr(0, 2) == '<A') {
                if (!$(this).parent().hasClass('sanspuce')) {
                    $(this).parent().addClass('listLink');
                }
            }
        }
    });

    // Traitement de la zone de recherche

    // Ajout de la propriété autocomplete
    $('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').attr("autocomplete", "off");

    $('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').focus(function () {
        if ($(this).val() == 'Rechercher') {
            $(this).val('');
        }
        $(this).css("color", "#000000");
    });

    $('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').blur(function () {
        if ($(this).val() == '') {
            $(this).val('Rechercher');
            $(this).css("color", "#9f9f9f");
        }
    });

    /**************************************************************************
     *
     * POWERMAIL
     *
     *************************************************************************/
    $('input.powermail_submit').wrap('<span class="button"></span>')
    $('input.tx_powermail_pi1_submitmultiple_forward').wrap('<span class="button"></span>')
    $('input.tx_powermail_pi1_submitmultiple_back').wrap('<span class="button"></span>')
    $('.tx_powermail_pi1_fieldwrap_html_navigation').each(function () {
        if ($.trim($(this).html()) == '')
            $(this).hide();
    });

    /*************************************************************************
     *
     * PAGE DE REGROUPEMENT DES LIEUX
     * Affichage sous forme d'accordéon des lieux
     *
     ************************************************************************/

    initRegroupementsLieux('v1');
    initRegroupementsLieux('v2');


    /*************************************************************************
     *
     * PAGE DE REGROUPEMENT DES CONTACTS
     * Affichage sous forme d'accordéon des contacts
     *
     ************************************************************************/

    if ($('div.tx-vgecontacts-pi1').length != 0) {

        pListGroup = $('div.tx-vgecontacts-pi1').parent().position();
        pListGroupTop = pListGroup.top;
        if ($('#content_image').length != 0) {
            // Hauteur de l'image
            hImg = $('#content_image').height();
            // Position de l'image
            pImg = $('#content_image').position();

            posEndImg = parseInt(hImg) + parseInt(pImg.top);
        } else {
            posEndImg = 0;
        }

        // Si le bas est plus haut que le début de la liste -> Pas de modification
        doImgMod = true;
        if (pListGroupTop > posEndImg) {
            doImgMod = false;
        } else {
            if ($('div.tx-vgecontacts-pi1').parent().prev().hasClass('box_generic')) {
                $('div.tx-vgecontacts-pi1').parent().prevAll().width(217);
                $('div.tx-vgecontacts-pi1 div:first').width(217);
            }
        }

        $('input[name$="tpl_contact"]').each(function () {
            if ($(this).val() == 'group_title') {
                // Regroupement par titre
                $(this).parent().children().hide();

                // Supprime le background des li
                $(this).parent().find('li').css('background', 'none');
                $(this).parent().find('li span').hide();
                $(this).parent().find('li div.titre_lieu').hide();

                $(this).parent().prev().css('cursor', 'pointer');
                $(this).parent().prev().children().addClass('titre_groupe');

                $(this).parent().prev().children().hover(function () {
                    $(this).css('color', '#0062DC');
                }, function () {
                    $(this).css('color', '#990000');
                });

                $(this).parent().prev().click(function () {
                    // refermer tous les détails de lieu

                    $(".detail_lieu").each(function () {
                        if ($(this).parent().parent().prev().val() != 'group_title') {
                            $(this).slideUp("fast");
                            $(this).parent().removeClass("open");
                        } else {
                            //$(this).parent().parent().parent().prev().removeClass("open");
                            //console.info( $(this).parent().parent().parent().prev().attr('class') )
                        }
                    });

                    if ($(this).children().hasClass('open')) {
                        $(this).children().removeClass("open");
                        $(this).next().children().slideUp("fast");
                    } else {
                        $(this).children().addClass("open");
                        $(this).next().children().slideDown("slow");
                    }
                });
            } else {
                // Regroupement par mot clé
                var cur_container = $(this).parent();

                // Séléctionne les fiches de lieux
                cur_container.find('.detail_lieu').each(function () {

                    $(this).hide();

                    $(this).prev().css('cursor', 'pointer')

                    // Maintien la largeur de la div
                    $(this).prev().wrapInner('<span class="c_titre"></span>');
                    curTitre = $(this).prev().children().innerWidth();
                    $(this).prev().width(curTitre);

                    $(this).prev().click(function () {

                        if ($(this).parent().hasClass("open")) {
                            //Modifie les propriétés de l'image
                            if (doImgMod)
                                $('#container_image').removeClass("image_w_list");

                            $(this).parent().removeClass("open");
                            $(this).parent().children(".detail_lieu").slideUp("fast");
                        } else {
                            //Modifie les propriétés de l'image
                            if (doImgMod)
                                $('#container_image').addClass("image_w_list");

                            $(this).parent().addClass("open");
                            $(this).parent().children(".detail_lieu").slideDown("slow");
                        }

                        curEl = $(this).parent();
                        // refermer tous les détails de lieu - sauf ceux regroupés par titre
                        $(".detail_lieu").each(function () {

                            if ($(this).parent().parent().prev().val() != 'group_title') {
                                if (curEl.html() != $(this).parent().html()) {
                                    $(this).slideUp("fast");
                                    $(this).parent().removeClass("open");
                                }
                            } else {
                                $(this).parent().parent().parent().children().hide();
                                $(this).parent().parent().parent().prev().children().removeClass("open");
                            }
                        });
                    });
                });
            }
        });
    }

    /*************************************************************************
     *
     * Affichage des vidéos en LightBox
     * Librairie : top_up - http://gettopup.com/
     * Modifications VGE - ligne 455 + 635 + 636
     *
     ************************************************************************/
    TopUp.host = location.protocol + "//www.ville-geneve.ch/";
    TopUp.players_path = "fileadmin/public/mediaplayer/";
    TopUp.images_path = "fileadmin/villege/templates/images/top_up/";

    if (($('p.video a').length != 0) || ($('td.video a').length != 0) || ($('th.video a').length != 0) || ($('li.video a').length != 0) || ($('a.video img').length != 0) || ($('a.video_home').length != 0)) {


        TopUp.addPresets({
            "p.video a":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:700,
                height:400,
                title:'Vidéo VGE',
                shaded:1 // Vidéo dans une fenêtre modal
            },
            "td.video a":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:700,
                height:400,
                title:"Vidéo Ville de Genève",
                shaded:1 // Vidéo dans une fenêtre modal
            },
            "th.video a":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:700,
                height:400,
                title:"Vidéo Ville de Genève",
                shaded:1 // Vidéo dans une fenêtre modal
            },
            "li.video a":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:700,
                height:400,
                title:"Vidéo Ville de Genève",
                shaded:1 // Vidéo dans une fenêtre modal
            },
            "a.video":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:700,
                height:400,
                title:"Vidéo Ville de Genève",
                shaded:1 // Vidéo dans une fenêtre modal
            },
            "a.video_home":{
                type:"flashvideo",
                layout:"quicklook",
                modal:1,
                width:800,
                height:600,
                title:"Vidéo Ville de Genève",
                shaded:1 // Vidéo dans une fenêtre modal
            }
        });
    }

    /*************************************************************************
     *
     * Menu Wiki
     * Affiche / Masque le menu
     *
     ************************************************************************/

    if ($(".menu_wiki_middle").lenght != 0) {
        $(".menu_wiki_middle a.small").click(function () {

            if ($(this).hasClass("close")) {
                $(this).next().show();
                $(this).text("[masquer]")
            }
            else {
                $(this).next().hide();
                $(this).text("[afficher]")
            }

            $(this).toggleClass("close");
            return false;
        });
    }

    /*************************************************************************
     *
     * Zone de partage
     * Affiche / Masque la zone de partage
     *
     ************************************************************************/

    if ($(".call_network_area").lenght != 0) {

        var leaveButton = false;
        var networkEnter = false;
        var time = 1000;

        $(".call_network_area").mouseover(
            function () {
                if ($(".network_area_top").hasClass("close")) {
                    $(".network_area").show();
                    $(".network_area_top").toggleClass("close");
                }

                return false;
            }).mouseleave(function () {
                setTimeout(function () {
                    if (leaveButton == true) {
                        $(".network_area").hide();
                        $(".network_area_top").addClass("close");
                    }
                }, time);
                leaveButton = true;
            });

        $(".network_area_top").mouseenter(function () {
            leaveButton = false;
            networkEnter = true;
        });

        $(".network_area_top").mouseleave(function () {
            setTimeout(function () {
                if (!$('.network_area_top').hasClass("close") && networkEnter == false) {
                    $('.network_area_top').parent().hide();
                    $('.network_area_top').toggleClass("close");
                }
            }, time);

            networkEnter = false;

            return false;
        });
    }

    /**
     *
     * Gestion des filtres de l'agenda des évènements
     */

    if ($('.content_filter_cal').length > 0) {

        // Affichage du calendrier pour la date de début
        $('#popupDatepickerStart').datepick({
            //defaultDate: '+0w',
            //selectDefaultDate: true,
            pickerClass:'pickerVGE',
            minDate:'0',
            renderer:$.extend({}, $.datepick.defaultRenderer, {picker:$.datepick.defaultRenderer.picker.replace(/\{link:clear\}/, '')}),
            changeMonth:false,
            prevText:'M', nextText:'M',
            commandsAsDateFormat:true,
            onSelect:reformatStartDate
            //showTrigger: '#calImgStart'
        });

        // Affichage du calendrier pour la date de fin
        $('#popupDatepickerEnd').datepick({
            //defaultDate: '+0w',
            //selectDefaultDate: true,
            pickerClass:'pickerVGE',
            minDate:'0',
            renderer:$.extend({}, $.datepick.defaultRenderer, {picker:$.datepick.defaultRenderer.picker.replace(/\{link:clear\}/, '')}),
            changeMonth:false,
            prevText:'M', nextText:'M',
            commandsAsDateFormat:true,
            onSelect:reformatEndDate
            //showTrigger: '#calImgEnd'
        });

        $('#selectGenres').sSelect({
            defaultText:'Tous les genres',
            ddMaxHeight:'300px',
            ddDefWidth:'2'
        });

        $('#selectLieuxCat').sSelect({
            defaultText:'Catégorie des lieux',
            ddMaxHeight:'300px',
            ddDefWidth:'2'
        });

        $('#selectLieux').sSelect({
            defaultText:'Tous les lieux',
            ddMaxHeight:'300px',
            ddDefWidth:'2'
        });

        // Désactive la sélection des lieux si il n'y a pas de catégorie
        if ($('#selectLieuxCat').children().attr('selected').length == 0 || $('#selectLieuxCat').children().attr('selected')) {
            $('#selectLieux').children('option').hide();
            $('#selectLieux').prev('.newListSelected').addClass('disable');
            $('#selectLieux').prev('.newListSelected').children('ul').children().hide();
        }

        $('#selectLieuxCat').change(function () {

            $('#selectLieux').prev('.newListSelected').children('ul').children().hide();
            $('#selectLieux').prev('.newListSelected').children('.newListSelectedBtn').children().html('Tous les lieux');

            var curVal = $(this).children('option:selected').attr('class');

            if (curVal != '') {
                $('#selectLieux').prev('.newListSelected').removeClass('disable');
            }
            else if (!$('#selectLieux').prev('.newListSelected').hasClass('disable')) {
                $('#selectLieux').prev('.newListSelected').addClass('disable');
            }

            $('#selectLieux .lieux_' + curVal).show();
            $('#selectLieux').prev('.newListSelected').children('ul').children('.lieux_' + curVal).show();

            var option = $('#selectLieux:first-child');
            option.attr('selected', 'selected');
        });

        // Bouton reset
        $('a.reset').click(function () {
            var dateToday = new Date();
            var dateTodayForm = new Date();

            dateToday = $.datepick.formatDate('dd/mm/yyyy', dateToday);
            dateTodayForm = $.datepick.formatDate('yyyymmdd', dateTodayForm);
            // Date de début
            $('#popupDatepickerStart').val(dateToday);
            $('input[name$="tx_displaycontroller[datePickerStart]"]').val(dateTodayForm);
            // Date de fin
            $('#popupDatepickerEnd').val(dateToday);
            $('input[name$="tx_displaycontroller[datePickerEnd]"]').val(dateTodayForm);

            $('.selectedTxt').each(function () {
                $(this).html($(this).parent().parent().next().children().html());
            });

            // Catégorie des lieux
            $('#selectLieuxCat').children().removeAttr('selected');
            $('#selectLieuxCat').prev('.newListSelected').children('ul').children().removeClass('hiLite');

            // Liste des lieux
            $('#selectLieux').children().removeAttr('selected');
            $('#selectLieux').prev('.newListSelected').children('ul').children().hide();
            $('#selectLieux').prev('.newListSelected').children('ul').children().removeClass('hiLite');
            $('#selectLieux').prev('.newListSelected').children('ul').children().removeClass('notDisplayInList');
            $('#selectLieux').prev('.newListSelected').addClass('disable');

            // Genre
            $('#selectGenres').children().removeAttr('selected');
            $('#selectGenres').prev('.newListSelected').children('ul').children().removeClass('hiLite');

            // Public
            $('input[name$="tx_displaycontroller[public][]"]').removeAttr('checked');
            $('input[name$="tx_displaycontroller[public][]"]:first').attr('checked', 'checked');

            $('.newListOptionTitle').children('ul').children().attr('class', '');
            $('.specialSelect').children('optgroup').children().removeAttr('selected');

            return false;
        });

        /*
         $('#selectGenres').change(function(){
         $('input[name$="tx_displaycontroller[genres]"]').val( $(this).val() );
         });

         $('#selectLieuxCat').change(function(){
         $('input[name$="tx_displaycontroller[catLieux]"]').val( $(this).val() );
         });

         $('#selectLieux').change(function(){
         $('input[name$="tx_displaycontroller[lieux]"]').val( $(this).val() );
         });

         $('input[name$="selectPublic"]').click(function(){
         // Récupère la valeur actuelle
         var curVal = $('input[name$="tx_displaycontroller[public]"]').val();
         if(curVal != '')
         $('input[name$="tx_displaycontroller[public]"]').val( curVal+','+$(this).val() );
         else
         $('input[name$="tx_displaycontroller[public]"]').val( $(this).val() );
         });
         */

    } // Fin du filtre de l'agenda

    /**
     * Galerie du CJB - Arbres
     *
     */

        // Mise à jour des listes dépendantes Nom commun et nom latin
    $('#selectGenresArbres').change(function () {

        $('#selectEspeces').prev('.newListSelected').children('.newListSelectedBtn').children().html('Nom commun');
        $('#selectNomLatin').prev('.newListSelected').children('.newListSelectedBtn').children().html('Nom latin');
        $('#selectEspeces').prev('.newListSelected').children('ul').children().removeClass('notDisplayInList');
        $('#selectNomLatin').prev('.newListSelected').children('ul').children().removeClass('notDisplayInList');

        if ($(this).val() != '') {

            // Enlève le select courant
            $('#selectEspeces').children().removeAttr('selected');
            $('#selectNomLatin').children().removeAttr('selected');
            // Cache tous les enfants
            $('#selectEspeces').prev('.newListSelected').children('ul').children().hide();
            $('#selectNomLatin').prev('.newListSelected').children('ul').children().hide();

            var curVal = $(this).val(); // Valeur courante
            // Affiche les valeurs correspondantes
            $('#selectEspeces .' + curVal).show();
            $('#selectNomLatin .' + curVal).show();
            $('#selectEspeces').prev('.newListSelected').children('ul').children('.' + curVal).show();
            $('#selectNomLatin').prev('.newListSelected').children('ul').children('.' + curVal).show();

            // Adapte la taille de la liste déroulante
            var nbEltEspeces = $('#selectEspeces').prev('.newListSelected').children('ul').children('.' + curVal).length;
            var nbEltNomLatin = $('#selectNomLatin').prev('.newListSelected').children('ul').children('.' + curVal).length;
            $('#selectEspeces').prev('.newListSelected').children('ul').height(26 * nbEltEspeces + 3);
            $('#selectNomLatin').prev('.newListSelected').children('ul').height(26 * nbEltNomLatin + 3);

            // Sélectionne l'élement pour le _POST
            var option = $('#selectEspeces:first-child');
            var option2 = $('#selectNomLatin:first-child');
            option.attr('selected', 'selected');
            option2.attr('selected', 'selected');
        }
        else {
            $('#selectEspeces').prev('.newListSelected').children('ul').height(300);
            $('#selectNomLatin').prev('.newListSelected').children('ul').height(300);
            $('#selectEspeces').prev('.newListSelected').children('ul').children().show();
            $('#selectNomLatin').prev('.newListSelected').children('ul').children().show();
            $('#selectEspeces').prev('.newListSelected').children('ul').children().removeClass('hiLite');
            $('#selectNomLatin').prev('.newListSelected').children('ul').children().removeClass('hiLite');
        }

    });

    // Bouton reset
    $('a.resetGalerieArbres').click(function () {

        $('#selectGenresArbres').children().removeAttr('selected');
        $('#selectEspeces').children().removeAttr('selected');
        $('#selectNomLatin').children().removeAttr('selected');
        $('#selectQuartier').children().removeAttr('selected');

        $('input[name$="tx_displaycontroller[sujetPhoto][]"]').removeAttr('checked');

        $('input[name$="tx_displaycontroller[qualite]"]').removeAttr('checked');
        $('input[name$="tx_displaycontroller[qualite]"]:first').attr('checked', 'checked');

        $('input[name$="tx_displaycontroller[inventaireCanton]"]').removeAttr('checked');
        $('input[name$="tx_displaycontroller[inventaireCanton]"]:first').attr('checked', 'checked');

        $('#selectGenresArbres').prev('.newListSelected').children('.newListSelectedBtn').children().html('Genre');
        $('#selectEspeces').prev('.newListSelected').children('.newListSelectedBtn').children().html('Nom commun');
        $('#selectNomLatin').prev('.newListSelected').children('.newListSelectedBtn').children().html('Nom latin');
        $('#selectQuartier').prev('.newListSelected').children('.newListSelectedBtn').children().html('Quartier');

        // Réinitialise les valeurs pour les listes dépendantes
        $('#selectEspeces').prev('.newListSelected').children('ul').height(300);
        $('#selectNomLatin').prev('.newListSelected').children('ul').height(300);
        //Affiche tous les enfants
        $('#selectEspeces').prev('.newListSelected').children('ul').children().show();
        $('#selectNomLatin').prev('.newListSelected').children('ul').children().show();
        //Suppression des class dans les div parentes
        $('#selectGenresArbres').prev('.newListSelected').children('ul').children().removeClass('hiLite');
        $('#selectEspeces').prev('.newListSelected').children('ul').children().removeClass('hiLite');
        $('#selectNomLatin').prev('.newListSelected').children('ul').children().removeClass('hiLite');
        $('#selectQuartier').prev('.newListSelected').children('ul').children().removeClass('hiLite');

        return false;
    });

    // Masque la galerie par défaut si il y a un résultat
    if ($('.page_browser').length > 0) {
        $('.galerieDefaut').hide();
        $('.galerieDefaut').children().children().children('a').removeAttr('rel');
    }

    // Carte des arbres
    // Gestion du bouton pour l'ouverture en plein écran
    if ($('#openBigMap').length > 0) {
        $('#openBigMap').click(function () {
            // Récupère la hauteur et largeur de la page pour s'adapter à la résolution
            var bodyHeight = $('body').height();
            var bodyWidth = $('body').width() - 237;
            // Masque les enfants
            $('body').addClass('noBackground');
            $('body').children().hide();
            // Affiche la carte en grand
            // Définition des éléments html
            var htmlRender = '<div id="mapArbre"><div class="leftCol"></div><div class="bigMap"></div></div>';
            var logoVille = '<div id="openBigMap_vgeLogo"></div>';
            var btnClose = '<div id="closeBigMap"><span>Fermer le plein écran</span></div>';
            var legende = '<div id="legendCjb">&nbsp;</div>';
            // Ajout au DOM
            $('body').append(htmlRender);
            $('.bigMap').append($('#carteArbres'));
            $('.leftCol').append(logoVille);
            $('.leftCol').append(btnClose);
            $('.leftCol').append(legende);
            $('#carteArbres').height(bodyHeight);
            $('.leftCol').height(bodyHeight);
            $('#carteArbres').width(bodyWidth);

            // Gestion du btn fermer
            $('#closeBigMap').click(function () {
                $('body').removeClass('noBackground');
                $('#carteArbres').removeAttr('style');
                $('#content_main').children('.box_generic:first-child').append($('#carteArbres'));
                $('#mapArbre').remove();
                $('#container_page').show();
                $('#temp_up').show();
            });

        });
    }

    // Livre virtuel
    // Gestion du bouton pour l'ouverture en plein écran
    if ($('#openBigMapLivre').length > 0) {
        $('#openBigMapLivre').click(function () {
            // Récupère la hauteur et largeur de la page pour s'adapter à la résolution
            var bodyHeight = $('body').height() - 60;
            var bodyWidth = $('body').width();
            // Masque les enfants
            $('body').addClass('noBackground');
            $('body').children().hide();
            // Affiche la carte en grand
            // Définition des éléments html
            var htmlRender = '<div id="bigLivreVirtuel"><div class="topCol"></div><div class="contentLivreVirtuel"></div></div>';
            var logoVille = '<div id="openBigMap_vgeLogo"></div>';
            var btnClose = '<div id="closeBigMap"><span>Fermer le plein écran</span></div>';
            // Ajout au DOM
            $('body').append(htmlRender);
            $('.contentLivreVirtuel').append($('#livreVirtuel'));
            $('.topCol').append(logoVille);
            $('.topCol').append(btnClose);
            $('#livreVirtuel').height(bodyHeight);
            $('#livreVirtuel').width(bodyWidth);

            // Gestion du btn fermer
            $('#closeBigMap').click(function () {
                $('body').removeClass('noBackground');
                $('#livreVirtuel').removeAttr('style');
                $('#content_main').children('.box_generic:first-child').append($('#livreVirtuel'));
                $('#bigLivreVirtuel').remove();
                $('#container_page').show();
                $('#temp_up').show();
            });

        });
    }

    if ($('#openBigMapChantiers').length > 0) {
        $('#openBigMapChantiers').click(function () {
            // R�cup�re la hauteur et largeur de la page pour s'adapter � la r�solution
            var bodyHeight = $('body').height();
            var bodyWidth = $('body').width() - 237;
            // Masque les enfants
            $('body').addClass('noBackground');
            $('body').children().hide();
            // Affiche la carte en grand
            // D�finition des �l�ments html
            var htmlRender = '<div id="mapArbre"><div class="leftCol"></div><div class="bigMap"></div></div>';
            var logoVille = '<div id="openBigMap_vgeLogo"></div>';
            var btnClose = '<div id="closeBigMap"><span>Fermer le plein &eacute;cran</span></div>';
            var legende = '<div id="legendChantiers">&nbsp;</div>';
            // Ajout au DOM
            $('body').append(htmlRender);
            $('.bigMap').append($('#carteArbres'));
            $('.leftCol').append(logoVille);
            $('.leftCol').append(btnClose);
            $('.leftCol').append(legende);
            $('#carteArbres').height(bodyHeight);
            $('.leftCol').height(bodyHeight);
            $('#carteArbres').width(bodyWidth);

            // Gestion du btn fermer
            $('#closeBigMap').click(function () {
                $('body').removeClass('noBackground');
                $('#carteArbres').removeAttr('style');
                $('#content_main').children('.box_generic:first-child').append($('#carteArbres'));
                $('#mapArbre').remove();
                $('#container_page').show();
                $('#temp_up').show();
            });

        });
    }

    /**
     *
     * Ouverture des galeires depuis un lien
     *    Chargement du contenu de la page en ajax
     *
     *    Limite :
     *        - Lien sur 1 seul galerie
     *        - Les galeries doivent être sur 1 page
     */
    if ($('.lienGalerie').length > 0) {
        // Charge la galerie dans la page
        $.ajax({
            type:"GET",
            async:false,
            url:$('.lienGalerie').attr('href'),
            success:function (data) {
                // Isole les éléments de la galerie
                var contenuGalerie = $(data).find('#content_main').children().html();
                $('#content_main').append('<div style="display:none;">' + contenuGalerie + '</div>');
            },
            complete:function () {
                // Lance la galerie
                $('.lienGalerie').click(function () {
                    $('.galeriePlanche:first a').trigger('click');
                    return false;
                });
            }
        });
    }

});


// Remise à zéro des formulaires pour GSA
function resetForms() {
    for (var i = 0; i < document.forms.length; i++) {
        document.forms[i].reset();
    }
}

function openAccessibility() {
    // Recuperation de la propriete visible de la barre d'accessibilite
    state_barre_acc = $("#accessibility").css("display");

    // Chgt d'etat
    if (state_barre_acc == "block")
        $("#accessibility").css({
            display:"none"
        });
    else
        $("#accessibility").css({
            display:"block"
        });
}

// Gestion du menu Guide des quartiers
function openGuideQuartiers() {
    state_guide = $("#guide_quartier").css("display");
    if (state_guide == "block")
        $("#guide_quartier").css({
            display:"none"
        });
    else
        $("#guide_quartier").css({
            display:"block"
        });
}

/**
 * Carrousel
 *
 */
function carrousel_initCallback(carrousel) {

    // Disable autoscrolling if the user clicks the prev or next button.
    carrousel.buttonNext.bind('click', function () {
        carrousel.startAuto(0);
    });

    carrousel.buttonPrev.bind('click', function () {
        carrousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carrousel.clip.hover(function () {
        carrousel.stopAuto();
    }, function () {
        carrousel.startAuto();
    });

    if (dispNumNav == 'caroussel_home') { //Variable globale définie à l'init du carrousel
        // Ajout des boutons de navigation (1 2 3...)
        block_num_detail = '';
        for (i = 1; i <= $(".jcarousel-item").length; i++) {
            if (i == 1)
                block_num_detail += "<a href='#' class='curNav'>" + i + "</a>&nbsp;"
            else
                block_num_detail += "<a href='#'>" + i + "</a>&nbsp;"
        }
        block_num = "<div class='jcarousel-control'>" + block_num_detail + "</div>"
        $(".jcarousel-clip-horizontal").append(block_num);

        // Ajout de l'écouteur
        if ($(".jcarousel-control").length != 0) {
            $('.jcarousel-control a').bind('click', function () {
                // Disable autoscrolling
                carrousel.startAuto(0);

                if ($(this).html() != $('.jcarousel-control a.curNav').html()) {
                    carrousel_display_nextItem($(this), "number", carrousel);
                    carrousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
                }

                return false;
            });

            $('.jcarousel-control a').bind('click', function () {
                return false;
            });
        }
    }
    else if (dispNumNav == 'caroussel_pdv') {
        // Ajout des boutons de navigation (1 2 3...)
        block_num_detail = '';
        for (i = 1; i <= $(".jcarousel-item").length; i++) {
            if (i == 1)
                block_num_detail += "<div class='carrousel_illus curNav'> </div>"
            else
                block_num_detail += "<div class='carrousel_illus'> </div>"
        }
        block_num = "<div class='jcarousel-control'>" + block_num_detail + "<div class='clear_both'> </div></div>"
        $(".jcarousel-clip-horizontal").before(block_num);
    }
}

function initRegroupementsLieux(extensionVersion) {
    if (extensionVersion == 'v1') {
        var extensionName = 'vgelocations';
		var debugLieux = false;
    }
    else {
        var extensionName = 'vgelieux';
		var debugLieux = true;
    }

    if ($('div.tx-' + extensionName + '-pi1').length != 0) {

        	pListGroup = $('div.tx-' + extensionName + '-pi1').parent().position();
        pListGroupTop = pListGroup.top;

        if ($('#content_image').length != 0) {
            // Hauteur de l'image
            hImg = $('#content_image').height();
            // Position de l'image
            pImg = $('#content_image').position();

            posEndImg = parseInt(hImg) + parseInt(pImg.top);
        } else {
            posEndImg = 0;
        }
        // Si le bas est plus haut que le début de la liste -> Pas de modification
        doImgMod = true;
        if (pListGroupTop > posEndImg) {
            doImgMod = false;
        } else {
            if ($('div.tx-' + extensionName + '-pi1').parent().prev().hasClass('box_generic')) {
                $('div.tx-' + extensionName + '-pi1').parent().prevAll().width(217);
                $('div.tx-' + extensionName + '-pi1 div:first').width(217);
            }
        }

        $('input[name$="tpl_location"]').each(function () {
	
            if ($(this).val() == 'group_title') {
                // Regroupement par titre
                $(this).parent().children().hide();

                // Supprime le background des li
                $(this).parent().find('li').css('background', 'none');
                $(this).parent().find('li span').hide();
                $(this).parent().find('li div.titre_lieu').hide();

                $(this).parent().prev().css('cursor', 'pointer');
                $(this).parent().prev().children().addClass('titre_groupe');

                $(this).parent().prev().children().hover(function () {
                    $(this).css('color', '#0062DC');
                }, function () {
                    $(this).css('color', '#990000');
                });

                $(this).parent().prev().click(function () {
                    // refermer tous les détails de lieu

                    $(".detail_lieu").each(function () {
                        if ($(this).parent().parent().prev().val() != 'group_title') {
                            $(this).slideUp("fast");
                            $(this).parent().removeClass("open");
                        } else {
                            //$(this).parent().parent().parent().prev().removeClass("open");
                            //console.info( $(this).parent().parent().parent().prev().attr('class') )
                        }
                    });

                    if ($(this).children().hasClass('open')) {
                        $(this).children().removeClass("open");
                        $(this).next().children().slideUp("fast");
                    } else {
                        $(this).children().addClass("open");
                        $(this).next().children().slideDown("slow");
                    }
                });
            } else {
                // Regroupement par mot clé
                var cur_container = $(this).parent();

                // Séléctionne les fiches de lieux
                cur_container.find('.detail_lieu').each(function () {

                    $(this).hide();

                    $(this).prev().css('cursor', 'pointer')

                    // Maintien la largeur de la div
                    $(this).prev().wrapInner('<span class="c_titre"></span>');
                    curTitre = $(this).prev().children().innerWidth();
                    $(this).prev().width(curTitre);

                    $(this).prev().click(function () {

                        if ($(this).parent().hasClass("open")) {
                            //Modifie les propriétés de l'image
                            if (doImgMod)
                                $('#container_image').removeClass("image_w_list");

                            $(this).parent().removeClass("open");
                            $(this).parent().children(".detail_lieu").slideUp("fast");
                        } else {
                            //Modifie les propriétés de l'image
                            if (doImgMod)
                                $('#container_image').addClass("image_w_list");

                            $(this).parent().addClass("open");
                            $(this).parent().children(".detail_lieu").slideDown("slow");
                        }

                        curEl = $(this).parent();
                        // refermer tous les détails de lieu - sauf ceux regroupé par titre
                        $(".detail_lieu").each(function () {
                            if ($(this).parent().parent().prev().val() != 'group_title') {
                                if (curEl.html() != $(this).parent().html()) {
                                    $(this).slideUp("fast");
                                    $(this).parent().removeClass("open");
                                }
                            } else {
                                $(this).parent().parent().parent().children().hide();
                                $(this).parent().parent().parent().prev().children().removeClass("open");
                            }
                        });
                    });
                });
            }
        });
    }
}


function carrousel_display_nextItem(curObj, typeButton, curCarrousel) {
    $(".caption").hide();

    // Calcul le numéro du block suivant
    if (typeButton == "arrow")
        nextItemNum = parseInt(curObj) + 1;
    else
        nextItemNum = parseInt(curObj.html()) + 1;

    // Ajout de l'état actif sur les boutons

    $('.jcarousel-control').children().removeClass('curNav');
    $('.jcarousel-control').children().each(function () {
        if ($(this).html() == curObj)
            $(this).addClass('curNav');
    });

    // Ajout du block de la photo suivante sauf pour la dernière
    if (nextItemNum <= $(".jcarousel-item").length) {

        nextItem = ".jcarousel-item-" + nextItemNum + " h3";
        linkItem = ".jcarousel-item-" + nextItemNum + " a";

        block_nextItem = "<div class='jcarousel-next-item'>Suivant (" + nextItemNum + "/" + $(".jcarousel-item").length + ") : <a href='" + nextItemNum + "'>" + $(nextItem).text() + "</a></div>"

        $(".jcarousel-next-item").remove();
        $(".jcarousel-clip-horizontal").append(block_nextItem)
    }
    else {
        $(".jcarousel-next-item").remove();
    }

    $('.jcarousel-next-item a').bind('click', function () {
        curCarrousel.scroll(jQuery.jcarousel.intval($(this).attr("href")));
        return false;
    });
}

function carrousel_itemLoadCallbackFunction(carrousel, state) {
    carrousel_display_nextItem(carrousel.first, "arrow", carrousel)
}

function carrousel_itemLoadCallbackFunction_illus(carrousel, state) {
    // Ajout de l'état actif sur les boutons
    $('.jcarousel-control').children().removeClass('curNav');
    var k = 0; // Position de l'enfant
    var pos_car = parseInt(carrousel.first);
    $('.jcarousel-control').children().each(function () {
        k++;
        if (k == pos_car)
            $(this).addClass('curNav');
    });
}

// Agenda

// Format la date de début pour effectuer la recherche
function reformatStartDate(dates) {
    dFormat = $.datepick.formatDate('yyyymmdd', $('#popupDatepickerStart').datepick('getDate')[0]);
    $('input[name$="tx_displaycontroller[datePickerStart]"]').val(dFormat);
    // +7 à la date de fin par défaut
    var curDateEnd = $('input[name$="tx_displaycontroller[datePickerEnd]"]').val();
    var date = new Date($('#popupDatepickerStart').datepick('getDate')[0].getTime());
    var curDateStart = $.datepick.formatDate('yyyymmdd', date);
    if (curDateStart > curDateEnd) {
        var dateEnd = $.datepick.add(date, '7', 'd');
        $('input[name$="tx_displaycontroller[datePickerEnd]"]').val($.datepick.formatDate('yyyymmdd', dateEnd));
        $('#popupDatepickerEnd').val($.datepick.formatDate('dd/mm/yyyy', dateEnd));
    }
    // bloque la date de fin
    $('#popupDatepickerEnd').datepick('option', 'minDate', dates[0] || null);

}

// Format la date de début pour effectuer la recherche
function reformatEndDate(dates) {
    dFormat = $.datepick.formatDate('yyyymmdd', $('#popupDatepickerEnd').datepick('getDate')[0]);
    $('input[name$="tx_displaycontroller[datePickerEnd]"]').val(dFormat);
    // bloque la date de début
    $('#popupDatepickerStart').datepick('option', 'maxDate', dates[0] || null);
}

/***************************************************************************
 * Définition de la variable $_GET
 */
function getQueryParams(qs) {
    qs = qs.split("+").join(" ");

    var params = new Array();
    var tokens;
    var regex = /[?&]?([^=]+)=([^&]*)/g;

    while (( tokens = regex.exec(qs) ) != null) {
        var zeroLengthMatch = !tokens[0].length;
        // Fix IE's incorrect lastIndex
        if (zeroLengthMatch && regex.lastIndex > tokens.index)
            regex.lastIndex--;

        params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);

        // Avoid an infinite loop with zero-length matches
        if (zeroLengthMatch)
            regex.lastIndex++;
    }

    return params;
}

var $_GET = getQueryParams(document.location.search);


