
/* 
 * PageIdentificationModule
 * Description: la classe qui contient les variables et les méthodes de la page identification_module.jsp
 **/
$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

function PageIdentificationModule () { }

/** Initialisation des objets pour "click"  **/
PageIdentificationModule.initialisation = function() {

    // objets identifiés après l?affichage de formulaire identification
    PageIdentificationModule.prototype.formulaire = document.identificationForm;
    PageIdentificationModule.prototype.formulaireS = document.zoneSecuriseeIdentification;
    PageIdentificationModule.prototype.formulaireSProfil = document.zoneSecuriseeProfil;
    PageIdentificationModule.prototype.formulaireEnvoyerMotDuPasse = document.formOublieMotDePasse;
    PageIdentificationModule.prototype.formulaireIdentification = document.formIdentification;
    
    $('.jumpnext').keyup(function(){if (this.value != ""){$(this).next("input[type=text]").focus();}});

    /* la variable #identificationOKIni test si l'initialisation a été effectué
     * elle est "true" quand le bouton est initialisé */
    if ($("#identificationOKIni").attr("id") && $("#identificationOKIni").html() == "false") {
        $("#identificationOK").click(function(event){
            event.preventDefault();
            PageIdentificationModule.soumettre();
        });
        $('#identificationMotDePasse').keypress(function(event) {
            if(event.keyCode == 13) {
                event.preventDefault();
                $("#identificationOK").click();
            }
        });
        $("#identificationOKIni").html("true");
    }

    if ($("#submitS").attr("id") && $("#submitSIni").html() == "false") {
        $("#submitS").click(function(event){
            event.preventDefault();
            PageIdentificationModule.soumettreS();
        });
        $('#motDePasseS').keypress(function(event) {
            if(event.keyCode == 13) {
                event.preventDefault();
                $("#submitS").click();
            }
        });
        $("#submitSIni").html("true");
    }
    if ($("#submitP").attr("id") && $("#submitPIni").html() == "false") {
        if ($("#submitP").attr("id")) {
            $("#submitP").click(function(event){
                event.preventDefault();
                PageIdentificationModule.soumettreProfil();
            });
            $('#codePostalP').keypress(function(event) {
                if(event.keyCode == 13) {
                    event.preventDefault();
                    $("#submitP").click();
                }
            });
        }
        $("#submitPIni").html("true");
    }
    
    /* bouton est initialisé */
    if ($("#lien-deconnexion").attr("id") && $("#lien-deconnexion").is(':visible')) {
        $("#lien-deconnexion").one('click', function(event) {
            //$("#lien-deconnexion").unbind(event);
            event.preventDefault();
            PageIdentificationModule.fermerSession();
        });
    }
    
    /* bouton est initialisé */
    if ($("#non-identifie").attr("id")) {
        $("#non-identifie").click(function(event){
            event.preventDefault();
            var endroit = window.location.pathname;
            document.location = "/identification?urlPageRedirectionApresIdentification="+endroit;
        });
    }

    /* bouton est initialisé */
    if ($("#non-adherent").attr("id")) {
        $("#non-adherent").click(function(event){
            event.preventDefault();

         //   var dateFinAbo=new Date();
        //    dateFinAbo.setFullYear(2012,02,12);

        //    var today = new Date();

        //    if (dateFinAbo > today) {
                /* On affiche la prime abo (4 livres pour 4 CHF */
           //     top.document.location = "/abo";
         //   } else {
                top.document.location = "/recrutementaa";
           // }
        });
    }

    if ($("#effacer-cookies").attr("id")) {
        $("#effacer-cookies").click(function(event){
            event.preventDefault();
            var endroit = window.location.pathname;
            document.location = "/identification?urlPageRedirectionApresIdentification="+endroit;
            //PageIdentificationModule.effacerCookies();
        });
    }
    /* la variable #effacerCookiesLinkIni test si l'initialisation a été effectué
     * elle est "true" quand le bouton est initialisé */
    if ($("#effacerCookiesLinkIni").attr("id") && $("#effacerCookiesLinkIni").html() == "false") {
        $("#effacerCookiesLink").click(function(event){
            event.preventDefault();
            PageIdentificationModule.effacerCookies();
        });
        $("#effacerCookiesLinkIni").html("true");
    }
    /* la variable #motDePasseOublieLinkIni test si l'initialisation a été effectué
     * elle est "true" quand le bouton est initialisé
     */
    if ($("#motDePasseOublieLink1").attr("id") && $("#motDePasseOublieLinkIni").html() == "false") {
        $("#motDePasseOublieLink1").click(function(event){
            event.preventDefault();
            PageIdentificationModule.affichageMotDePasseOublieForm1();
        });
        $("#motDePasseOublieLinkIni").html("true");
    }
    if ($("#problemesIdentificationLink").attr("id")) {
        $("#problemesIdentificationLink").click(function(event){
            event.preventDefault();
            PageIdentificationModule.affichageMotDePasseOublieForm1();
        });
    }
    if ($("#submitRecrutement").attr("id")) {
        $("#submitRecrutement").click(function(event){
            event.preventDefault();
            top.document.location = "/recrutementaa";
        });
    }
    if ($("#submitRecrutementAbo").attr("id")) {
        $("#submitRecrutementAbo").click(function(event){
            event.preventDefault();
            top.document.location = "/abo";
        });
    }
    /* la variable #envoyerMotDePasseLinkIni test si l'initialisation a été effectué
     * elle est "true" quand le bouton est initialisé
     */
    if ($("#submitRecupererMDP").attr("id")) {
        $("#submitRecupererMDP").click(function(event){
            event.preventDefault();
            PageIdentificationModule.soumettreFormulaireEnvoyerMotDePasse();
        });
        $('#inputCourriel').keypress(function(event) {
            if(event.keyCode == 13) {
                event.preventDefault();
                $("#submitRecupererMDP").click();
            }
        });
    }
    if ($("#submitIdentification").attr("id")) {
        $("#submitIdentification").click(function(event){
            event.preventDefault();
            PageIdentificationModule.soumettreFormulaireIdentification();
        });
        $('#identificationMotDePasse').keypress(function(event) {
            if(event.keyCode == 13) {
                event.preventDefault();
                $("#submitIdentification").click();
            }
        });
    }
    if($("#jeMIdentifieLink").attr("id")) {
        $("#jeMIdentifieLink").click(function(event){
            window.location.reload(true);
            //event.preventDefault();
            //PageIdentificationModule.lancerFenetreModale();
        });
    }
}
/** soumettre
 * Le formulaire d'identification est soumis **/
PageIdentificationModule.soumettre = function() {
    var formulaire = PageIdentificationModule.prototype.formulaire;
    if ($("#moduleEnvoyerMotDePasse").is(':visible')) {$("#moduleEnvoyerMotDePasse").hide("slow");}
    if (!formulaire) {
        $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurValidationForm").val()),{
            align:"right",
            verticalAlign:"top",
            time:6000
        });
    }
    if ($("#identificationCourriel").val() == "") {
        return;
    }
    /* validation du formulaire */
   /* if (!validForm(formulaire,undefined,'',1, "")) {
        return;
    }*/
    /* fonction ajax de soumettre les valeurs du formulaire */
	var chURL = "/identifications-clients";
    if ("https:" == document.location.protocol){
        chURL = "/identification-client";
    }

    $.ajax({
		url: chURL,
        data: "identificationCourriel=" + $("#identificationCourriel").val() + "&identificationMotDePasse=" + $("#identificationMotDePasse").val(),
        async: false,
        cache: false,
        success: function(html){
            if(Generale.removeChar(html).fullTrim() == "existeListe"){
                window.location.href='/identification-multiple';
            }else if (Generale.removeChar(html).fullTrim() == "identifie") {
                /* l'identification a réussi est la salutation et le formulaire d'identification sont actualisé */
                PageIdentificationModule.changerAffichage();
                if (window.location.pathname == "/index"){
                    top.location.reload(true);
                }
            } else if(Generale.removeChar(html).fullTrim() == "nonIdentifie") {
                /* l'identification a échoué */
                $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurAdrOuMotDePasse").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            } else {
                $.floatingMessage(Base.encapsulerMessageErreur(Generale.removeChar(html).fullTrim()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurAdherent").val()),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** soumettreS
 * Le formulaire d'identification est soumis **/
PageIdentificationModule.soumettreS = function() {
    var formulaire = PageIdentificationModule.prototype.formulaireS;
    if (!formulaire) {
        $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurValidationForm").val()),{
            align:"right",
            verticalAlign:"top",
            time:6000
        });
    }
    /* validation du formulaire */
    /*if (!validForm(formulaire,undefined,'',1, "")) {
        return;
    }*/
    /* fonction ajax de soumettre les valeurs du formulaire */
    var chURL = "/identifications-clients";
    if ("https:" == document.location.protocol){
        chURL = "/identification-client";
    }

    $.ajax({
        url: chURL,
        data: "identificationCourriel=" + $("#courrielS").val() + "&identificationMotDePasse=" + $("#motDePasseS").val() + "&V_identificationCourriel="+ $("#V_courrielS").val() + + "&V_identificationMotDePasse="+ $("#V_motDePasseS").val(),
        async: false,
        cache: false,
        success: function(html){
            if(Generale.removeChar(html).fullTrim() == "existeListe"){
                window.location.href='/identification-multiple';
            }
            else if (Generale.removeChar(html).fullTrim() == "identifie") {
                /* l'identification a réussi est la salutation et le formulaire d'identification sont actualisé */
                PageIdentificationModule.changerAffichage();
            } else if(Generale.removeChar(html).fullTrim() == "nonIdentifie") {
                /* l'identification a échoué */
                $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurAdrOuMotDePasse").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            } else {
                $.floatingMessage(Base.encapsulerMessageErreur(Generale.removeChar(html).fullTrim()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurAdherent").val()),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** soumettreProfil
 * Le formulaire de profil est soumis **/
PageIdentificationModule.soumettreProfil = function() {

    var formulaire = PageIdentificationModule.prototype.formulaireSProfil;
    if (!formulaire) {
        $.floatingMessage(Base.encapsulerMessageErreur($("#ErreurValidationForm").val()),{
            align:"right",
            verticalAlign:"top",
            time:6000
        });
    }
    $("#noAdherentP").val($("#noAdherentP1").val()+$("#noAdherentP2").val()+$("#noAdherentP3").val()+$("#noAdherentP4").val()+$("#noAdherentP5").val()+$("#noAdherentP6").val()+$("#noAdherentP7").val()+$("#noAdherentP0").val());
    
    /* validation du formulaire */
    if (!validForm(formulaire,undefined,1,1, "")) {
        return;
    }

	var chURL = "/identifications-profils";
    if ("https:" == document.location.protocol){
        chURL = "/identification-profil";
    }
	
    /* fonction ajax de soumettre les valeurs du formulaire */
    $.ajax({
        url: chURL,
        data: "noAdherentP=" + $("#noAdherentP").val() + "&nomP=" + $("#nomP").val() + "&prenomP=" + $("#prenomP").val() + "&codePostalP=" + $("#codePostalP").val(),
        async: false,
        cache: false,
        success: function(html){
            if (Generale.removeChar(html).fullTrim() == "true") {
                /* le courriel a été envoyé */
                PageIdentificationModule.afficherSalutation();
                document.location = "/mon-compte";

            } else if (Generale.removeChar(html).fullTrim() == "false") {

                /* le courriel n'est pas dans le système */
                $.floatingMessage(Base.encapsulerMessageErreur($("#erreurProfilPasTrouve").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            } else {
                $.floatingMessage(Base.encapsulerMessageErreur(Generale.removeChar(html).fullTrim()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur($("#erreurCreationProfil").val()),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** changerAffichage
 * Traitement pour décider la page affichée **/
PageIdentificationModule.changerAffichage = function() {
    /* fonction ajax pour récupérer la page de redirection */
	var chURL = "/servlets/GetUrlPageRedirectionApresIdentification";
    if ("https:" == document.location.protocol){
        chURL = "/servlets/GetUrlPageRedirectionApresIdentifications";
    }
    $.ajax({
        url: chURL,
        data: "",
        async: false,
        cache: false,
        success: function(html){
            
            if (Generale.removeChar(html).fullTrim() != "false") {
                /* la page est redirigée */
                
                top.location = Generale.removeChar(html).fullTrim();
            } else {
                PageIdentificationModule.reloadOuNonPageApresIdentification();
            }
        },
        error: function() {
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors de la récupération de la page de redirection."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}

/** lancerFenetreModaleJS
 * Lancer la fenêtre modale pour identification à partir de javascript **/
PageIdentificationModule.lancerFenetreModaleJS = function() {
    PageIdentificationModule.actionFenetreModale();
}

/** lancerFenetreModale
 * Lancer la fenêtre modale pour identification **/
PageIdentificationModule.lancerFenetreModale = function() {
    /* fonction ajax pour récupérer la page de redirection */
    if ($("#lancerFenetreModale").attr("id") && $("#lancerFenetreModale").val() == "true") {

        PageIdentificationModule.actionFenetreModale();
        
    }
}

/** actionFenetreModale
 * fenêtre modale pour identification **/
PageIdentificationModule.actionFenetreModale = function() {
    /* fonction ajax pour récupérer la page de redirection */
	var chURL = "/identifications-modules?modale=true";
    if ("https:" == document.location.protocol){
        chURL = "/identification-module?modale=true";
    }

    $.ajax({
       url: chURL,
        data: "",
        async: false,
        cache: false,
        success: function(html){
            $("#fmodale").html(html);
            /* Les objets qui sont actualisés vont être initialisés (c'est nécessaire
             * pour chaque actualisation, parce que les anciens objets perdent leurs propriétés) */

        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors du chargement du formulaire d'identification."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
    $.fn.colorbox({open:true, inline:true, href:"#fmodale"});

    PageIdentificationModule.initialisation();

}

/** soumettreFormulaireEnvoyerMotDePasse
 * Le formulaire d'envoyer le mot du passe **/
PageIdentificationModule.soumettreFormulaireEnvoyerMotDePasse = function() {
    var formulaire = PageIdentificationModule.prototype.formulaireEnvoyerMotDuPasse;
    if (!formulaire) {
        $.floatingMessage(Base.encapsulerMessageErreur($("#erreurValidationFormulaire").val()),{
            align:"right",
            verticalAlign:"top",
            time:6000
        });
        return;
    }
    $("#noAdherent").val($("#noAdherent1").val()+$("#noAdherent2").val()+$("#noAdherent3").val()+$("#noAdherent4").val()+$("#noAdherent5").val()+$("#noAdherent6").val()+$("#noAdherent7").val()+$("#noAdherent0").val());
    /* validation du formulaire */
    if (!validForm(formulaire,undefined,'',1, "")) {
        return;
    }
    if ($("#inputCourriel").val() == "" && $("#noAdherent").val() == "") {
        return;
    }
    /* fonction ajax de soumettre les valeurs du formulaire */
    $.ajax({
        url: "/servlets/EnvoyerMotDePasse",
        data: "courriel=" + $("#inputCourriel").val() + "&noAdherent=" + $("#noAdherent").val(),
        async: false,
        cache: false,
        success: function(html){
            if (Generale.removeChar(html).fullTrim() == "true") {
                /* le courriel a été envoyé */
                $.floatingMessage(Base.encapsulerMessageApprobation($("#erreurMotPasseEnvoye").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
                top.document.location = "/";
            }
            if (Generale.removeChar(html).fullTrim() == "falseCourriel") {
                /* le courriel n'est pas dans le système */
                $.floatingMessage(Base.encapsulerMessageErreur($("#erreurCourrielPasDansSysteme").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
            if (Generale.removeChar(html).fullTrim() == "falseNoAdherent") {
                /* le courriel n'est pas dans le système */
                $.floatingMessage(Base.encapsulerMessageErreur($("#erreurNumeroAdherentPasDansSysteme").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
            if (Generale.removeChar(html).fullTrim() == "erreur") {
                /* le courriel n'est pas dans le système */
                $.floatingMessage(Base.encapsulerMessageErreur($("#erreurEnvoyeCourriel").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur($("#erreurEnvoyeMotPasse").val()),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** soumettreformulaireIdentification
 * Le formulaire d'envoyer l'identifiant **/
PageIdentificationModule.soumettreFormulaireIdentification = function() {

    var formulaire = PageIdentificationModule.prototype.formulaireIdentification;
    if (!formulaire) {
        $.floatingMessage(Base.encapsulerMessageErreur($("#erreurValidationFormulaire").val()),{
            align:"right",
            verticalAlign:"top",
            time:6000
        });
        return;
    }
    $("#identificationNoClient").val($("#noAdherent11").val()+$("#noAdherent12").val()+$("#noAdherent13").val()+$("#noAdherent14").val()+$("#noAdherent15").val()+$("#noAdherent16").val()+$("#noAdherent17").val()+$("#noAdherent10").val());

    if ($("#identificationCourriel").val() == "" && $("#identificationNoClient").val() == "") {
        return;
    }
    
    /* validation du formulaire */
    /*if (!validForm(formulaire,undefined,'',1, "")) {
        return;
    }*/
    
    /* fonction ajax de soumettre les valeurs du formulaire */
    var chURL = "/identifications-clients";
    if ("https:" == document.location.protocol){
        chURL = "/identification-client";
    }
    $.ajax({
        url: chURL,
        data: "identificationCourriel=" + $("#identificationCourriel").val() + "&identificationNoClient=" + $("#identificationNoClient").val() + "&identificationMotDePasse=" + $("#identificationMotDePasse").val(),
        async: false,
        cache: false,
        success: function(html){
            if(Generale.removeChar(html).fullTrim() == "existeListe"){
                window.location.href='/identification-multiple';
            } else if (Generale.removeChar(html).fullTrim() == "identifie") {
                /* l'identification a réussi est la salutation et le formulaire d'identification sont actualisé */
                PageIdentificationModule.changerAffichage();
                if (window.location.pathname == "/index"){
                    top.location.reload(true);
                }
            } else if(Generale.removeChar(html).fullTrim() == "nonIdentifie") {
                /* l'identification a échoué */
                $.floatingMessage(Base.encapsulerMessageErreur($("#erreurIdentifiantOuMotDePasse").val()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            } else {
                $.floatingMessage(Base.encapsulerMessageErreur(Generale.removeChar(html).fullTrim()),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur($("#erreurIdentification").val()),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}

PageIdentificationModule.afficherCacherOptionDeconnexion = function() {
    
    if (PageIdentificationModule.prototype.clientIdentifie) {
        if ($("#option-connecter").attr("id")) {
            $("#menu-select option[id='option-connecter']").remove();
        }
        if (!$("#option-deconnecter").attr("id")) {
            $("#menu-select option[id='date-limite-achat']").after($("<option></option>").
                  attr("value","javascript:PageIdentificationModule.fermerSession()").
                  text("Me déconnecter").
                  attr("id", "option-deconnecter"));
        }
    } else {
        if ($("#option-deconnecter").attr("id")) {
            $("#menu-select option[id='option-deconnecter']").remove();
        }
        if (!$("#option-connecter").attr("id")) {
            var endroit = window.location.pathname;
            $("#menu-select option[id='date-limite-achat']").after($("<option></option>").
                  attr("value","javascript:document.location='/identification?urlPageRedirectionApresIdentification=" + endroit + "'").
                  text("Me connecter").
                  attr("id", "option-connecter"));
        }
    }
    
}

/** afficherSalutation
 * La salutation est affichée **/
PageIdentificationModule.afficherSalutation = function() {
    var chURL = "/affichages-salutations";
    if ("https:" == document.location.protocol){
        chURL = "/affichage-salutation";
    }
    $.ajax({
		url: chURL,
        data: "",
        async: false,
        cache: false,
        success: function(html){
            /* convert JSon text dans objet */
            var objSalutation = eval('(' + html + ')');
            $("#genre").html(objSalutation.salutation);
            $("#nom-adherent").html(objSalutation.name);
            if (objSalutation.identified == "true") {
                $("#lien-deconnexion").show();
                $("#non-identifie").hide();
                $("#non-adherent").hide();
                PageIdentificationModule.prototype.clientIdentifie = true;
            } else {
                if (objSalutation.name) {
                    $("#effacer-cookies").show();
                    $("#non-identifie").hide();
                    $("#non-adherent").hide();
                } else {
                    $("#non-identifie").show();
                    $("#non-adherent").show();
                }
                PageIdentificationModule.prototype.clientIdentifie = false;
            }
            /* Les objets qui sont actualisés vont être initialisés (c'est nécessaire
           * pour chaque actualisation, parce que les anciens objets perdent leurs propriétés) */
            
            PageIdentificationModule.initialisation();
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors du chargement du formulaire d'identification."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });

    PageIdentificationModule.afficherCacherOptionDeconnexion();
}
/** fermerSession
 * fermer la session du client, mais ne pas les cookies **/
PageIdentificationModule.fermerSession = function() {
    var chURL = "/servlets/FermerSessionOuCookies";
    if ("https:" == document.location.protocol){
        chURL = "/servlets/FermerSessionOuCookiesSec";
    }
    
    $.ajax({
        url: chURL,
        data: "fermerSession=true",
        async: false,
        cache: false,
        success: function(html){
            
            /* la session est fermé et la salutation et le formulaire d'identification sont actualisé */
            if ($("#identificationModule")) {
                $("#identificationModule").show("fast");
            }
            $("#lien-deconnexion").hide();
            
            PageIdentificationModule.reloadOuNonPageApresDeconnexion();
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors de la fermeture de session."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** effacerCookies
 * effacer les cookies du client **/
PageIdentificationModule.effacerCookies = function() {
    var chURL = "/servlets/FermerSessionOuCookies";
    if ("https:" == document.location.protocol){
        chURL = "/servlets/FermerSessionOuCookiesSec";
    }
    $.ajax({
        url: chURL,
        data: "effacerCookies=true",
        async: false,
        cache: false,
        success: function(html){
            /* les cookies sont effacés et la salutation et le formulaire d'identification sont actualisé */
            //PageIdentificationModule.reloadOuNonPageApresIdentification();
            $("#effacer-cookies").hide();
            $("#non-identifie").show();
            $("#non-adherent").show();
            top.location.reload();
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors de l'effacement des cookies."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** reloadOuNonPageApresIdentification
 * tester de voir si la page va être chargé ou seulement mise à jour **/
PageIdentificationModule.reloadOuNonPageApresIdentification = function() {
    if ($("#pageReloadAfterIdentification") && $("#pageReloadAfterIdentification").val() == "true") {
        /* la page est rechargé */
        top.location.reload();
    } else {
        /* la page n'est pas rechargé */
        PageIdentificationModule.afficherSalutation();
        PageIdentificationModule.afficherFormulaireIdentification();
    }
}
/** reloadOuNonPageApresDeconnexion
 * tester de voir si la page va être chargé ou seulement mise à jour **/
PageIdentificationModule.reloadOuNonPageApresDeconnexion = function() {
    if ($("#pageReloadAfterIdentification") && $("#pageReloadAfterIdentification").val() == "true") {
        /* la page est rechargé */
        top.location = "/";
    } else {
        /* la page n'est pas rechargé */
        PageIdentificationModule.afficherSalutation();
        
        PageIdentificationModule.afficherFormulaireIdentification();
    }
}

/** afficherFormulaireIdentification
 * Le formulaire d'identification est affichée **/
PageIdentificationModule.afficherFormulaireIdentification = function() {
    var chURL = "/identifications-modules";
    if ("https:" == document.location.protocol){
        chURL = "/identification-module";
    }
    $.ajax({
        url: chURL,
        data: "",
        async: false,
        cache: false,
        success: function(html){
            if ($("#identificationModule")) {
                if($("#identificationModule").length>0) {
                    
                    $("#identificationModule").html(html);
                    /* Les objets qui sont actualisés vont être initialisés (c'est nécessaire
                     * pour chaque actualisation, parce que les anciens objets perdent leurs propriétés) */
                    
                    //PageIdentificationModule.initialisation();
                }
            }
        },
        error: function(){
            $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors du chargement du formulaire d'identification."),{
                align:"right",
                verticalAlign:"top",
                time:6000
            });
        }
    });
}
/** affichageMotDePasseOublieForm
 * Le formulaire de mot du passe oublié est affichée ou caché **/
PageIdentificationModule.affichageMotDePasseOublieForm = function() {
    if ($("#moduleEnvoyerMotDePasse").is(':visible')) {
        $("#moduleEnvoyerMotDePasse").hide("fast");
    } else {
        $("#moduleEnvoyerMotDePasse").show("fast");
    }
    if ($("#courrielMotDePasse").val() == "") {
        $("#courrielMotDePasse").val($("#identificationCourriel").val());
    }
}
/** affichageMotDePasseOublieForm
 * Le formulaire de mot du passe oublié est affichée ou caché **/
PageIdentificationModule.affichageMotDePasseOublieForm1 = function() {
    $.ajax({
//            url: "/composants_r/identification/oublie_mot_de_passe.jsp",
//            qq'un a modifié un param de config pour empêcher le chargement direct de fichier .jsp
//            donc, j'ai mit l'url du SERVLET'
            url: "/oublie-mot-de-passe",
            data: "",
            async: false,
            cache: false,
            success: function(html){
                $("#fmodale").html(html);
                /* Les objets qui sont actualisés vont être initialisés (c'est nécessaire
                 * pour chaque actualisation, parce que les anciens objets perdent leurs propriétés) */
                PageIdentificationModule.initialisation();
            },
            error: function(){
                $.floatingMessage(Base.encapsulerMessageErreur("Erreur lors du chargement du formulaire d'identification."),{
                    align:"right",
                    verticalAlign:"top",
                    time:6000
                });
            }
        });
    $.fn.colorbox({open:true, inline:true, href:"#fmodale"});
}
/** Fonction active après le chargement de la page
 * Afficher les div de salutation et le formulaire d'identification
 * Initialisation des objets pour "click" **/
$(document).ready(function(){
    /* definition des variables prototypes (statiques)*/
    PageIdentificationModule.afficherSalutation();
    PageIdentificationModule.prototype.clientIdentifie = false;
    if($.getUrlVar('affichage') === 'motDePasseOublie') {
        PageIdentificationModule.affichageMotDePasseOublieForm1();
    } else {
        PageIdentificationModule.afficherFormulaireIdentification();
        PageIdentificationModule.initialisation();
        PageIdentificationModule.lancerFenetreModale();
    }
});
