// Script réalisé par Tout JavaScript.com, revu GB

    // Fonction d'extraction des paramètres
    function TJSExtraireParam() {
        var tabNom = window.location.href.split(/[&?]+/g),
            tabParam = [],
            i = 0,
            tabTemp = [];
        if (tabNom != null) {
            for (i = 1; i < tabNom.length; i++){
                tabTemp = tabNom[i].split (/[=]+/g);
                tabParam [tabTemp[0]] = tabTemp [1];
            }
        }
        return tabParam;
    }


    // Objet Date, création
    var c_Date = function () {
        var that = {};
        that.LaDate = new Date();
        that.RecalDate = function (NouvDate) {
            var NomsJSem = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
            var NomsMois = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août",
                       "Septembre", "Octobre", "Novembre", "Décembre"];
            if (typeof NouvDate != "undefined") {   // Paramètre optionnel
              that.LaDate.setFullYear (NouvDate.substr (0, 4),
                 NouvDate.substr (4,2) - 1, NouvDate.substr (6,2));
            }
            that.JourSem = that.LaDate.getDay();
            that.NomJSem = NomsJSem [that.JourSem];
            that.Mois = that.LaDate.getMonth() + 1;
            that.NomMois = NomsMois [that.Mois - 1];
            that.Jour = that.LaDate.getDate();
            that.JJ = that.Jour < 10 ? "0" + that.Jour : that.Jour;
            that.MM = that.Mois < 10 ? "0" + that.Mois : that.Mois;
            that.Annee = that.LaDate.getFullYear();

        }         // 24 * 3600 * 1000 = 86400000
        that.AjJour = function (jours) {    // Ajoute n jours
          that.LaDate.setTime (that.LaDate.getTime() + jours * 86400000);
          that.RecalDate();
        }
        that.DimProch = function () {
          that.LaDate.setTime (that.LaDate.getTime() + (7 - that.LaDate.getDay()) % 7 * 86400000);
          that.RecalDate();
        }

        that.RecalDate ();
        return that;
    };


var Auj = c_Date();

    // Appel de la fonction et création du tableau des paramètres
function TraiteParam () {        // fonction, pour rendre les variables locales

    var urlParam = TJSExtraireParam(),
        Dte = urlParam ["Date"] || "",
        Dim = urlParam ["Dim"] || "";

    if (Dim === "1") {   // Si paramètre comme quoi qu’on doit aller à dimanche
          Auj.DimProch ();
    } else {
      if (Dte.length == 8) {
        Auj.RecalDate(Dte);
      }
    }
};

TraiteParam();