Merge remote branch 'origin/xorg/maint' into xorg/master
[platal.git] / htdocs / javascript / xorg.js
index 8805ed4..7ed0138 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-var is_IE       = $.browser.msie;
-
 // {{{ function getNow()
 var days   = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
 var months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
-              'août', 'septembre', 'octobre', 'novembre', 'décembre']
+              'août', 'septembre', 'octobre', 'novembre', 'décembre'];
 
 function getNow() {
     var dt = new Date();
@@ -31,13 +29,16 @@ function getNow() {
     var mh = dt.getMonth();
     var wd = dt.getDate();
     var yr = dt.getYear();
-    if (yr<1000) yr += 1900;
     var hr = dt.getHours();
     var mi = dt.getMinutes();
+    var se = dt.getSeconds();
+
+    if (yr<1000) {
+        yr += 1900;
+    }
     if (mi < 10) {
         mi = '0' + mi;
     }
-    var se = dt.getSeconds();
     if (se < 10) {
         se = '0' + se;
     }
@@ -51,8 +52,8 @@ function getNow() {
 
 function canAddSearchEngine()
 {
-    if (((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine))
-        || ((typeof window.external == "object") && $.isFunction(window.external.AddSearchProvider))) {
+    if (((typeof window.sidebar === "object") && $.isFunction(window.sidebar.addSearchEngine))
+        || ((typeof window.external === "object") && $.isFunction(window.external.AddSearchProvider))) {
         return true;
     }
     return false;
@@ -61,7 +62,7 @@ function canAddSearchEngine()
 function addSearchEngine()
 {
     var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
-    if ((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine)) {
+    if ((typeof window.sidebar === "object") && $.isFunction(window.sidebar.addSearchEngine)) {
         window.sidebar.addSearchEngine(
             searchURI,
             "http://www.polytechnique.org/images/xorg.png",
@@ -77,53 +78,6 @@ function addSearchEngine()
 }
 
 // }}}
-// {{{ dynpost()
-
-function dynpost(action, values)
-{
-    var form = document.createElement('form');
-    form.action = action;
-    form.method = 'post';
-
-    $('body').get(0).appendChild(form);
-
-    for (var k in values) {
-        var input = document.createElement('input');
-        input.type = 'hidden';
-        input.name = k;
-        input.value = values[k];
-        form.appendChild(input);
-    }
-
-    form.submit();
-}
-
-
-function dynpostkv(action, k, v)
-{
-    var dict = {};
-    dict[k] = v;
-    dynpost(action, dict);
-}
-
-// }}}
-// {{{ function RegExp.escape()
-
-RegExp.escape = function(text) {
-  if (!arguments.callee.sRE) {
-    var specials = [
-      '/', '.', '*', '+', '?', '|',
-      '(', ')', '[', ']', '{', '}',
-      '\\', '^' , '$'
-    ];
-    arguments.callee.sRE = new RegExp(
-      '(\\' + specials.join('|\\') + ')', 'g'
-    );
-  }
-  return text.replace(arguments.callee.sRE, '\\$1');
-}
-
-// }}}
 
 /***************************************************************************
  * POPUP THINGS
@@ -131,72 +85,76 @@ RegExp.escape = function(text) {
 
 // {{{ function goodiesPopup()
 
-var __goodies_active = true;
-
-var __goodies_ical = {
-    default_title: 'Calendrier iCal',
-    sites: [
-        {'url_prefix': '',
-         'img': 'images/icons/calendar_view_day.gif',
-         'title': 'Calendrier iCal'},
-        {'url_prefix': 'http://www.google.com/calendar/render?cid=',
-         'img': 'images/goodies/add-google-calendar.gif',
-         'title': 'Ajouter à Google Calendar'},
-        {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
-         'img': 'images/goodies/add-google-calendar.gif',
-         'title': 'Ajouter à Google Apps / Calendar'}
-    ]
-};
-
-var __goodies_rss = {
-    default_title: 'Fils RSS',
-    sites: [
-        {'url_prefix': '',
-         'img': 'images/icons/feed.gif',
-         'title': 'Fil rss'},
-        {'url_prefix': 'http://fusion.google.com/add?feedurl=',
-         'img': 'images/goodies/add-google.gif',
-         'alt': 'Add to Google',
-         'title': 'Ajouter à iGoogle/Google Reader'},
-        {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
-         'img': 'images/goodies/add-netvibes.gif',
-         'title': 'Ajouter à Netvibes'},
-        {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
-         'img': 'images/goodies/add-yahoo.gif',
-         'alt': 'Add to My Yahoo!',
-         'title': 'Ajouter à My Yahoo!'}
-    ]
-};
-
-function disableGoodiesPopups() {
-    __goodies_active = false;
-}
-
-function goodiesPopup(node, goodies) {
-    var text = '<div style="text-align: center; line-height: 2.2">';
-    for (var site in goodies.sites) {
-        var entry = goodies.sites[site];
-        var s_alt   = entry["alt"] ? entry["alt"] : "";
-        var s_img   = entry["img"];
-        var s_title = entry["title"] ? entry["title"] : "";
-        var s_url   = entry["url_prefix"].length > 0 ? entry["url_prefix"] + escape(this.href) : this.href;
-
-        text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
-    }
-    text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
+(function($) {
+    var goodies = {
+        ical: {
+            default_title: 'Calendrier iCal',
+            sites: [
+                {url_prefix: '',
+                 img: 'images/icons/calendar_view_day.gif',
+                 title: 'Calendrier iCal'},
+                {url_prefix: 'http://www.google.com/calendar/render?cid=',
+                 img: 'images/goodies/add-google-calendar.gif',
+                 title: 'Ajouter à Google Calendar'},
+                {url_prefix: 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
+                 img: 'images/goodies/add-google-calendar.gif',
+                 title: 'Ajouter à Google Apps / Calendar'}
+            ]
+        },
 
-    var title = node.title ? node.title : goodies.default_title;
+        rss: {
+            default_title: 'Fils RSS',
+            sites: [
+                {url_prefix: '',
+                 img: 'images/icons/feed.gif',
+                 title: 'Fil rss'},
+                {url_prefix: 'http://fusion.google.com/add?feedurl=',
+                 img: 'images/goodies/add-google.gif',
+                 alt: 'Add to Google',
+                 title: 'Ajouter à iGoogle/Google Reader'},
+                {url_prefix: 'http://www.netvibes.com/subscribe.php?url=',
+                 img: 'images/goodies/add-netvibes.gif',
+                 title: 'Ajouter à Netvibes'},
+                {url_prefix: 'http://add.my.yahoo.com/content?.intl=fr&url=',
+                 img: 'images/goodies/add-yahoo.gif',
+                 alt: 'Add to My Yahoo!',
+                 title: 'Ajouter à My Yahoo!'}
+            ]
+        }
+    };
 
-    $(node)
-        .mouseover(
-            function() {
-                if (__goodies_active) {
-                    return overlib(text, CAPTION, title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150);
+    $.fn.extend({
+        goodiesPopup: function goodiesPopup(type) {
+            var text = '<div style="text-align: center; line-height: 2.2">';
+            var site;
+            var entry;
+            var s_alt;
+            var s_img;
+            var s_title;
+            var s_url;
+
+            for (site in goodies[type].sites) {
+                entry = goodies[type].sites[site];
+                s_alt   = entry.alt || "";
+                s_img   = entry.img;
+                s_title = entry.title || "";
+                s_url   = entry.url_prefix.length > 0 ? entry.url_prefix + escape(this.href) : this.href;
+
+                text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
                 }
-            }
-        )
-        .mouseout(nd);
-}
+            text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
+
+            return this.overlib({
+                text: text,
+                caption: this.attr('title') || goodies.default_title,
+                close_text: 'Fermer',
+                delay: 800,
+                sticky: true,
+                width: 150
+            });
+        }
+    });
+}(jQuery));
 
 // }}}
 // {{{ function auto_links()
@@ -204,43 +162,47 @@ function goodiesPopup(node, goodies) {
 function auto_links() {
     var url  = document.URL;
     var fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
-    var light = (url.indexOf('display=light') > url.indexOf('?'));
-    var resource_page = (url.indexOf('rss') > -1 || url.indexOf('ical') > -1);
+    var light = url.indexOf('display=light') > url.indexOf('?');
+    var resource_page = url.contains('rss') || url.contains('ical');
 
     $("a,link").each(function(i) {
         var node = $(this);
         var href = this.href;
+        var matches;
+        var rss;
+        var ical;
+
         if(!href || node.hasClass('xdx')
-           || href.indexOf('mailto:') > -1 || href.indexOf('javascript:') > -1) {
+           || href.startsWith('mailto:') || href.startsWith('javascript:')) {
             return;
         }
-        if ((href.indexOf(fqdn) < 0 && this.className.indexOf('popup') < 0) || node.hasClass('popup')) {
+        if ((!href.contains(fqdn) && !this.className.contains('popup')) || node.hasClass('popup')) {
             node.click(function () {
                 window.open(href);
                 return false;
             });
         }
-        if (href.indexOf(fqdn) > -1 && light) {
+        if (href.contains(fqdn) && light) {
             href = href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
             this.href = href;
         }
-        var rss  = href.indexOf('rss') > -1;
-        var ical = href.indexOf('ical') > -1;
+        rss  = href.contains('rss');
+        ical = href.contains('ical');
         if (rss || ical) {
-            if (href.indexOf('http') < 0) {
+            if (!href.startsWith('http')) {
                 href = 'http://' + fqdn + '/' + href;
             }
         }
-        if (this.nodeName.toLowerCase() == 'a' && !resource_page) {
-            if (rss && href.indexOf('prefs/rss') < 0 &&  (href.indexOf('xml') > -1 || href.indexOf('hash'))) {
-                goodiesPopup(this, __goodies_rss);
+        if (this.nodeName.toLowerCase() === 'a' && !resource_page) {
+            if (rss && !href.contains('prefs/rss') && (href.contains('xml') || href.contains('hash'))) {
+                node.goodiesPopup('rss');
             } else if (ical) {
-                goodiesPopup(this, __goodies_ical);
+                node.goodiesPopup('ical');
             }
         }
-        if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className)) {
-            var w = matches[1], h = matches[2];
-            node.popWin(w, h);
+        matches = /^popup_([0-9]*)x([0-9]*)$/.exec(this.className);
+        if (matches) {
+            node.popWin(matches[1], matches[2]);
         }
     });
     $('.popup2').popWin(840, 600);
@@ -256,6 +218,257 @@ function auto_links() {
 
 // {{{ function checkPassword
 
+/* {{{ SHA1 Implementation */
+
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
+ * in FIPS PUB 180-1
+ * Version 2.1a Copyright Paul Johnston 2000 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
+
+/*
+ * Configurable variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ */
+var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
+var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
+var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
+
+/*
+ * These are the functions you'll usually want to call
+ * They take string arguments and return either hex or base-64 encoded strings
+ */
+function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
+function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
+function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
+function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
+function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
+function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
+
+/*
+ * Perform a simple self-test to see if the VM is working
+ */
+function sha1_vm_test()
+{
+  return hex_sha1("abc") === "a9993e364706816aba3e25717850c26c9cd0d89d";
+}
+
+/*
+ * Calculate the SHA-1 of an array of big-endian words, and a bit length
+ */
+function core_sha1(x, len)
+{
+  var w, a, b, c, d, e;
+  var olda, oldb, oldc, oldd, olde;
+  var i, j, t;
+
+  /* append padding */
+  x[len >> 5] |= 0x80 << (24 - len % 32);
+  x[((len + 64 >> 9) << 4) + 15] = len;
+
+  w = Array(80);
+  a =  1732584193;
+  b = -271733879;
+  c = -1732584194;
+  d =  271733878;
+  e = -1009589776;
+
+  for(i = 0; i < x.length; i += 16)
+  {
+    olda = a;
+    oldb = b;
+    oldc = c;
+    oldd = d;
+    olde = e;
+
+    for(j = 0; j < 80; j++)
+    {
+      if(j < 16) w[j] = x[i + j];
+      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
+      t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
+                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
+      e = d;
+      d = c;
+      c = rol(b, 30);
+      b = a;
+      a = t;
+    }
+
+    a = safe_add(a, olda);
+    b = safe_add(b, oldb);
+    c = safe_add(c, oldc);
+    d = safe_add(d, oldd);
+    e = safe_add(e, olde);
+  }
+  return Array(a, b, c, d, e);
+
+}
+
+/*
+ * Perform the appropriate triplet combination function for the current
+ * iteration
+ */
+function sha1_ft(t, b, c, d)
+{
+  if(t < 20) return (b & c) | ((~b) & d);
+  if(t < 40) return b ^ c ^ d;
+  if(t < 60) return (b & c) | (b & d) | (c & d);
+  return b ^ c ^ d;
+}
+
+/*
+ * Determine the appropriate additive constant for the current iteration
+ */
+function sha1_kt(t)
+{
+  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
+         (t < 60) ? -1894007588 : -899497514;
+}
+
+/*
+ * Calculate the HMAC-SHA1 of a key and some data
+ */
+function core_hmac_sha1(key, data)
+{
+  var bkey = str2binb(key);
+  var i, ipad, opad;
+  var hash;
+
+  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
+
+  ipad = Array(16);
+  opad = Array(16);
+  for(i = 0; i < 16; i++)
+  {
+    ipad[i] = bkey[i] ^ 0x36363636;
+    opad[i] = bkey[i] ^ 0x5C5C5C5C;
+  }
+
+  hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
+  return core_sha1(opad.concat(hash), 512 + 160);
+}
+
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+function safe_add(x, y)
+{
+  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+  return (msw << 16) | (lsw & 0xFFFF);
+}
+
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function rol(num, cnt)
+{
+  return (num << cnt) | (num >>> (32 - cnt));
+}
+
+/*
+ * Convert an 8-bit or 16-bit string to an array of big-endian words
+ * In 8-bit function, characters >255 have their hi-byte silently ignored.
+ */
+function str2binb(str)
+{
+  var bin = Array();
+  var mask = (1 << chrsz) - 1;
+  var i;
+  for(i = 0; i < str.length * chrsz; i += chrsz)
+    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
+  return bin;
+}
+
+/*
+ * Convert an array of big-endian words to a string
+ */
+function binb2str(bin)
+{
+  var str = "";
+  var mask = (1 << chrsz) - 1;
+  var i;
+  for(i = 0; i < bin.length * 32; i += chrsz)
+    str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
+  return str;
+}
+
+/*
+ * Convert an array of big-endian words to a hex string.
+ */
+function binb2hex(binarray)
+{
+  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
+  var str = "";
+  var i;
+  for(i = 0; i < binarray.length * 4; i++)
+  {
+    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
+           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
+  }
+  return str;
+}
+
+/*
+ * Convert an array of big-endian words to a base-64 string
+ */
+function binb2b64(binarray)
+{
+  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+  var str = "";
+  var i, j, triplet;
+  for(i = 0; i < binarray.length * 4; i += 3)
+  {
+    triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
+                | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
+                |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
+    for(j = 0; j < 4; j++)
+    {
+      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
+      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
+    }
+  }
+  return str;
+}
+
+/* }}} */
+
+function hash_encrypt(a) {
+    return hex_sha1(a);
+}
+
+var hexa_h = "0123456789abcdef";
+
+function dechex(a) {
+    return hexa_h.charAt(a);
+}
+
+function hexdec(a) {
+    return hexa_h.indexOf(a);
+}
+
+function hash_xor(a, b) {
+    var c,i,j,k,d;
+    c = "";
+    i = a.length;
+    j = b.length;
+    if (i < j) {
+        d = a; a = b; b = d;
+        k = i; i = j; j = k;
+    }
+    for (k = 0; k < j; k++) {
+        c += dechex(hexdec(a.charAt(k)) ^ hexdec(b.charAt(k)));
+    }
+    for (; k < i; k++) {
+        c += a.charAt(k);
+    }
+    return c;
+}
+
 function getType(c) {
     if (c >= 'a' && c <= 'z') {
         return 1;
@@ -270,10 +483,11 @@ function getType(c) {
 
 function differentTypes(password) {
     var prev = 0;
+    var type;
 
     for (i = 0 ; i < password.length ; ++i) {
-        var type = getType(password.charAt(i));
-        if (prev != 0 && prev != type) {
+        type = getType(password.charAt(i));
+        if (prev !== 0 && prev !== type) {
             return true;
         }
         prev = type;
@@ -286,15 +500,16 @@ function passwordStrength(password) {
     var prev = 0;
     var firstType = true;
     var types = Array(0, 0, 0, 0, 0);
+    var type;
 
     for (i = 0 ; i < password.length ; ++i) {
-        var type = getType(password.charAt(i));
-        if (prev != 0 && prev != type) {
+        type = getType(password.charAt(i));
+        if (prev !== 0 && prev !== type) {
             prop += 5;
             firstType = false;
         }
         prop += i;
-        if (types[type] == 0 && !firstType) {
+        if (types[type] === 0 && !firstType) {
             prop += 15;
         }
         types[type]++;
@@ -318,6 +533,7 @@ function passwordStrength(password) {
 function checkPassword(box, okLabel) {
     var password = box.value;
     var prop = passwordStrength(password);
+    var submitButton;
 
     if (prop >= 60) {
         color = "#4f4";
@@ -339,7 +555,7 @@ function checkPassword(box, okLabel) {
                     }, 750)
            .parent().stop()
                     .animate({ backgroundColor: bgcolor }, 750);
-    var submitButton = $(":submit[name='" + passwordprompt_submit + "']");
+    submitButton = $(":submit[name='" + passwordprompt_submit + "']");
     if (ok && password.length >= 6 && differentTypes(password)) {
         submitButton.attr("value", okLabel);
         submitButton.removeAttr("disabled");
@@ -349,6 +565,129 @@ function checkPassword(box, okLabel) {
     }
 }
 
+function hashResponse(password1, password2, hasConfirmation) {
+    var pw1 = $('[name=' + password1 + ']').val();
+    var pw2;
+
+    if (hasConfirmation) {
+        pw2 = $('[name=' + password2 + ']').val();
+        if (pw1 !== pw2) {
+            alert("\nErreur : les deux champs ne sont pas identiques !");
+            return false;
+        }
+        $('[name=' + password2 + ']').val('');
+    } else if (pw1 === '********') {
+        return true;
+    }
+
+    if (pw1.length < 6) {
+        alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
+        return false;
+    }
+    if (!differentTypes(pw1)) {
+        alert ("\nErreur : le nouveau mot de passe doit comporter au moins deux types de caractères parmi les suivants : lettres minuscules, lettres majuscules, chiffres, caractères spéciaux.");
+        return false;
+    }
+
+    alert("Le mot de passe que tu as rentré va être chiffré avant de nous parvenir par Internet ! Ainsi il ne circulera pas en clair.");
+    $('[name=' + password1 + ']').val('');
+    $('[name=pwhash]').val(hash_encrypt(pw1));
+    return true;
+}
+
+function correctUserName() {
+    var u = document.forms.login.username;
+    var mots;
+
+    // login with no space
+    if (!u.value.contains(' ')) {
+        return true;
+    }
+    mots = u.value.split(' ');
+    // jean paul.du pont -> jean-paul.du-pont
+    if (u.value.contains('.')) {
+        u.value = mots.join('-');
+        return true;
+    }
+    // jean dupont  -> jean.dupont
+    if (mots.length === 2) {
+        u.value = mots[0] + "." + mots[1];
+        return true;
+    }
+    // jean dupont 2001 -> jean.dupont.2001
+    if (mots.length === 3 && mots[2] > 1920 && mots[2] < 3000) {
+        u.value = mots.join('.');
+        return true;
+    }
+    // jean de la vallee -> jean.de-la-vallee
+    if (mots[1].toUpperCase() === 'DE') {
+        u.value = mots[0] + "." + mots.join('-').substr(mots[0].length+1);
+        return true;
+    }
+    // jean paul dupont -> jean-paul.dupont
+    if (mots.length === 3 && mots[0].toUpperCase() === 'JEAN') {
+        u.value = mots[0] + "-" + mots[1] + "." + mots[2];
+        return true;
+    }
+
+    alert('Ton email ne doit pas contenir de blanc.\nLe format standard est\n\nprenom.nom.promotion\n\nSi ton nom ou ton prenom est composé,\nsépare les mots par des -');
+
+    return false;
+}
+
+function doChallengeResponse() {
+    var new_pass, old_pass, str;
+
+    if (!correctUserName()) {
+        return false;
+    }
+
+    new_pass = hash_encrypt(document.forms.login.password.value);
+    old_pass = hash_encrypt(document.forms.login.password.value.substr(0, 10));
+
+    str = document.forms.login.username.value + ":" +
+        new_pass + ":" +
+        document.forms.loginsub.challenge.value;
+
+    document.forms.loginsub.response.value = hash_encrypt(str);
+    if (new_pass !== old_pass) {
+        document.forms.loginsub.xorpass.value = hash_xor(new_pass, old_pass);
+    }
+    document.forms.loginsub.username.value = document.forms.login.username.value;
+    document.forms.loginsub.remember.value = document.forms.login.remember.checked;
+    document.forms.loginsub.domain.value = document.forms.login.domain.value;
+    document.forms.login.password.value = "";
+    document.forms.loginsub.submit();
+}
+
+function doChallengeResponseLogged() {
+    var str = document.forms.loginsub.username.value + ":" +
+        hash_encrypt(document.forms.login.password.value) + ":" +
+        document.forms.loginsub.challenge.value;
+
+    document.forms.loginsub.response.value = hash_encrypt(str);
+    document.forms.loginsub.remember.value = document.forms.login.remember.checked;
+    document.forms.login.password.value = "";
+    document.forms.loginsub.submit();
+}
+
+// }}}
+// {{{ send test email
+
+function sendTestEmail(token, hruid)
+{
+    var url = 'emails/test';
+    var msg = "Un email a été envoyé avec succès";
+    if (hruid) {
+        url += '/' + hruid;
+        msg += " sur l'adresse de " + hruid + ".";
+    } else {
+        msg += " sur ton addresse.";
+    }
+    $('#mail_sent').successMessage($url + '?token=' + token, msg);
+    return false;
+}
+
 // }}}
 // {{{ jQuery object extension
 
@@ -513,10 +852,67 @@ function sendTestEmail(token, hruid)
 
 
 /***************************************************************************
+ * Overlib made simple
+ */
+
+(function($) {
+    $.fn.extend({
+        overlib: function(text, width, height) {
+            var args = [ ];
+            var key;
+
+            if (typeof text === 'string') {
+                args.push(text);
+                if (width) {
+                    args.push(width);
+                }
+                if (height) {
+                    args.push(height);
+                }
+            } else {
+                for (key in text) {
+                    switch (key) {
+                      case 'text':
+                        args.unshift(text[key]);
+                        break;
+                      case 'caption':
+                        args.push(CAPTION, text[key]);
+                        break;
+                      case 'close_text':
+                        args.push(CLOSETEXT, text[key]);
+                        break;
+                      case 'delay':
+                        args.push(DELAY, text[key]);
+                        break;
+                      case 'sticky':
+                        if (text[key]) {
+                            args.push(STICKY);
+                        }
+                        break;
+                      case 'width':
+                        args.push(WIDTH, text[key]);
+                        break;
+                      case 'height':
+                        args.push(HEIGHT, text[key]);
+                        break;
+                    }
+                }
+            }
+            return this
+                .mouseover(function () {
+                    return overlib.apply(null, args);
+                })
+                .mouseout(nd);
+        }
+    });
+}(jQuery));
+
+
+/***************************************************************************
  * The real OnLoad
  */
 
-$(document).ready(function() {
+$(function() {
     auto_links();
     getNow();
     setInterval(getNow, 1000);