Kill is_IE.
[platal.git] / htdocs / javascript / xorg.js
CommitLineData
0337d704 1/***************************************************************************
5e1513f6 2 * Copyright (C) 2003-2011 Polytechnique.org *
0337d704 3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
0337d704 21// {{{ function getNow()
80dcbd9a
FB
22var days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
23var months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
34cc65fd 24 'août', 'septembre', 'octobre', 'novembre', 'décembre'];
0337d704 25
0337d704 26function getNow() {
80dcbd9a
FB
27 var dt = new Date();
28 var dy = dt.getDay();
29 var mh = dt.getMonth();
30 var wd = dt.getDate();
31 var yr = dt.getYear();
80dcbd9a
FB
32 var hr = dt.getHours();
33 var mi = dt.getMinutes();
34cc65fd
FB
34 var se = dt.getSeconds();
35
36 if (yr<1000) {
37 yr += 1900;
38 }
80dcbd9a
FB
39 if (mi < 10) {
40 mi = '0' + mi;
41 }
80dcbd9a
FB
42 if (se < 10) {
43 se = '0' + se;
44 }
9f449375 45
80dcbd9a
FB
46 $(".date-heure").html(days[dy] + ' ' + wd + ' ' + months[mh] + ' ' + yr + '<br />'
47 + hr + ':' + mi + ':' + se);
9f449375 48}
49
50// }}}
a27c6df8 51// {{{ Search Engine
52
53function canAddSearchEngine()
54{
34cc65fd
FB
55 if (((typeof window.sidebar === "object") && $.isFunction(window.sidebar.addSearchEngine))
56 || ((typeof window.external === "object") && $.isFunction(window.external.AddSearchProvider))) {
350ba5ac
FB
57 return true;
58 }
59 return false;
a27c6df8 60}
39fd8f50 61
b09e5dea 62function addSearchEngine()
63{
350ba5ac 64 var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
34cc65fd 65 if ((typeof window.sidebar === "object") && $.isFunction(window.sidebar.addSearchEngine)) {
350ba5ac
FB
66 window.sidebar.addSearchEngine(
67 searchURI,
68 "http://www.polytechnique.org/images/xorg.png",
69 "Annuaire Polytechnique.org",
70 "Academic");
71 } else {
72 try {
73 window.external.AddSearchProvider(searchURI);
74 } catch(e) {
75 alert("Impossible d'installer la barre de recherche");
76 }
b09e5dea 77 }
39fd8f50 78}
79
39fd8f50 80// }}}
0337d704 81
82/***************************************************************************
83 * POPUP THINGS
84 */
85
769dc7d5
VZ
86// {{{ function goodiesPopup()
87
048c44a3
FB
88(function($) {
89 var goodies = {
90 ical: {
91 default_title: 'Calendrier iCal',
92 sites: [
93 {url_prefix: '',
94 img: 'images/icons/calendar_view_day.gif',
95 title: 'Calendrier iCal'},
96 {url_prefix: 'http://www.google.com/calendar/render?cid=',
97 img: 'images/goodies/add-google-calendar.gif',
98 title: 'Ajouter à Google Calendar'},
99 {url_prefix: 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
100 img: 'images/goodies/add-google-calendar.gif',
101 title: 'Ajouter à Google Apps / Calendar'}
102 ]
103 },
104
105 rss: {
106 default_title: 'Fils RSS',
107 sites: [
108 {url_prefix: '',
109 img: 'images/icons/feed.gif',
110 title: 'Fil rss'},
111 {url_prefix: 'http://fusion.google.com/add?feedurl=',
112 img: 'images/goodies/add-google.gif',
113 alt: 'Add to Google',
114 title: 'Ajouter à iGoogle/Google Reader'},
115 {url_prefix: 'http://www.netvibes.com/subscribe.php?url=',
116 img: 'images/goodies/add-netvibes.gif',
117 title: 'Ajouter à Netvibes'},
118 {url_prefix: 'http://add.my.yahoo.com/content?.intl=fr&url=',
119 img: 'images/goodies/add-yahoo.gif',
120 alt: 'Add to My Yahoo!',
121 title: 'Ajouter à My Yahoo!'}
122 ]
123 }
124 };
125
126 $.fn.extend({
127 goodiesPopup: function goodiesPopup(type) {
128 var text = '<div style="text-align: center; line-height: 2.2">';
34cc65fd
FB
129 var site;
130 var entry;
131 var s_alt;
132 var s_img;
133 var s_title;
134 var s_url;
135
136 for (site in goodies[type].sites) {
137 entry = goodies[type].sites[site];
138 s_alt = entry.alt || "";
139 s_img = entry.img;
140 s_title = entry.title || "";
141 s_url = entry.url_prefix.length > 0 ? entry.url_prefix + escape(this.href) : this.href;
048c44a3
FB
142
143 text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
144 }
145 text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
769dc7d5 146
048c44a3
FB
147 return this.overlib({
148 text: text,
34cc65fd 149 caption: this.attr('title') || goodies.default_title,
048c44a3
FB
150 close_text: 'Fermer',
151 delay: 800,
152 sticky: true,
153 width: 150
154 });
155 }
156 });
157}(jQuery));
769dc7d5
VZ
158
159// }}}
0337d704 160// {{{ function auto_links()
161
0337d704 162function auto_links() {
80dcbd9a
FB
163 var url = document.URL;
164 var fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
63c89179
FB
165 var light = url.indexOf('display=light') > url.indexOf('?');
166 var resource_page = url.contains('rss') || url.contains('ical');
e83d83e8 167
b804b882
FB
168 $("a,link").each(function(i) {
169 var node = $(this);
170 var href = this.href;
63c89179
FB
171 var matches;
172 var rss;
173 var ical;
174
b804b882 175 if(!href || node.hasClass('xdx')
63c89179 176 || href.startsWith('mailto:') || href.startsWith('javascript:')) {
b804b882
FB
177 return;
178 }
63c89179 179 if ((!href.contains(fqdn) && !this.className.contains('popup')) || node.hasClass('popup')) {
b804b882
FB
180 node.click(function () {
181 window.open(href);
182 return false;
183 });
184 }
63c89179 185 if (href.contains(fqdn) && light) {
b804b882
FB
186 href = href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
187 this.href = href;
188 }
63c89179
FB
189 rss = href.contains('rss');
190 ical = href.contains('ical');
b804b882 191 if (rss || ical) {
63c89179 192 if (!href.startsWith('http')) {
b804b882 193 href = 'http://' + fqdn + '/' + href;
e83d83e8 194 }
b804b882 195 }
34cc65fd 196 if (this.nodeName.toLowerCase() === 'a' && !resource_page) {
63c89179 197 if (rss && !href.contains('prefs/rss') && (href.contains('xml') || href.contains('hash'))) {
048c44a3 198 node.goodiesPopup('rss');
b804b882 199 } else if (ical) {
048c44a3 200 node.goodiesPopup('ical');
769dc7d5 201 }
3def38d5 202 }
34cc65fd
FB
203 matches = /^popup_([0-9]*)x([0-9]*)$/.exec(this.className);
204 if (matches) {
205 node.popWin(matches[1], matches[2]);
b804b882
FB
206 }
207 });
208 $('.popup2').popWin(840, 600);
209 $('.popup3').popWin(640, 800);
0337d704 210}
211
e83d83e8 212
0337d704 213// }}}
214
7143ad2b
FB
215/***************************************************************************
216 * Password check
217 */
218
219// {{{ function checkPassword
220
5ff39ae1
FB
221/* {{{ SHA1 Implementation */
222
223/*
224 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
225 * in FIPS PUB 180-1
226 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
227 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
228 * Distributed under the BSD License
229 * See http://pajhome.org.uk/crypt/md5 for details.
230 */
231
232/*
233 * Configurable variables. You may need to tweak these to be compatible with
234 * the server-side, but the defaults work in most cases.
235 */
236var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
237var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
238var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
239
240/*
241 * These are the functions you'll usually want to call
242 * They take string arguments and return either hex or base-64 encoded strings
243 */
244function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
245function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
246function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
247function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
248function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
249function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
250
251/*
252 * Perform a simple self-test to see if the VM is working
253 */
254function sha1_vm_test()
255{
34cc65fd 256 return hex_sha1("abc") === "a9993e364706816aba3e25717850c26c9cd0d89d";
5ff39ae1
FB
257}
258
259/*
260 * Calculate the SHA-1 of an array of big-endian words, and a bit length
261 */
262function core_sha1(x, len)
263{
34cc65fd
FB
264 var w, a, b, c, d, e;
265 var olda, oldb, oldc, oldd, olde;
266 var i, j, t;
267
5ff39ae1
FB
268 /* append padding */
269 x[len >> 5] |= 0x80 << (24 - len % 32);
270 x[((len + 64 >> 9) << 4) + 15] = len;
271
34cc65fd
FB
272 w = Array(80);
273 a = 1732584193;
274 b = -271733879;
275 c = -1732584194;
276 d = 271733878;
277 e = -1009589776;
5ff39ae1 278
34cc65fd 279 for(i = 0; i < x.length; i += 16)
5ff39ae1 280 {
34cc65fd
FB
281 olda = a;
282 oldb = b;
283 oldc = c;
284 oldd = d;
285 olde = e;
5ff39ae1 286
34cc65fd 287 for(j = 0; j < 80; j++)
5ff39ae1
FB
288 {
289 if(j < 16) w[j] = x[i + j];
290 else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
34cc65fd 291 t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
5ff39ae1
FB
292 safe_add(safe_add(e, w[j]), sha1_kt(j)));
293 e = d;
294 d = c;
295 c = rol(b, 30);
296 b = a;
297 a = t;
298 }
299
300 a = safe_add(a, olda);
301 b = safe_add(b, oldb);
302 c = safe_add(c, oldc);
303 d = safe_add(d, oldd);
304 e = safe_add(e, olde);
305 }
306 return Array(a, b, c, d, e);
307
308}
309
310/*
311 * Perform the appropriate triplet combination function for the current
312 * iteration
313 */
314function sha1_ft(t, b, c, d)
315{
316 if(t < 20) return (b & c) | ((~b) & d);
317 if(t < 40) return b ^ c ^ d;
318 if(t < 60) return (b & c) | (b & d) | (c & d);
319 return b ^ c ^ d;
320}
321
322/*
323 * Determine the appropriate additive constant for the current iteration
324 */
325function sha1_kt(t)
326{
327 return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
328 (t < 60) ? -1894007588 : -899497514;
329}
330
331/*
332 * Calculate the HMAC-SHA1 of a key and some data
333 */
334function core_hmac_sha1(key, data)
335{
336 var bkey = str2binb(key);
34cc65fd
FB
337 var i, ipad, opad;
338 var hash;
339
5ff39ae1
FB
340 if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
341
34cc65fd
FB
342 ipad = Array(16);
343 opad = Array(16);
344 for(i = 0; i < 16; i++)
5ff39ae1
FB
345 {
346 ipad[i] = bkey[i] ^ 0x36363636;
347 opad[i] = bkey[i] ^ 0x5C5C5C5C;
348 }
349
34cc65fd 350 hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
5ff39ae1
FB
351 return core_sha1(opad.concat(hash), 512 + 160);
352}
353
354/*
355 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
356 * to work around bugs in some JS interpreters.
357 */
358function safe_add(x, y)
359{
360 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
361 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
362 return (msw << 16) | (lsw & 0xFFFF);
363}
364
365/*
366 * Bitwise rotate a 32-bit number to the left.
367 */
368function rol(num, cnt)
369{
370 return (num << cnt) | (num >>> (32 - cnt));
371}
372
373/*
374 * Convert an 8-bit or 16-bit string to an array of big-endian words
375 * In 8-bit function, characters >255 have their hi-byte silently ignored.
376 */
377function str2binb(str)
378{
379 var bin = Array();
380 var mask = (1 << chrsz) - 1;
34cc65fd
FB
381 var i;
382 for(i = 0; i < str.length * chrsz; i += chrsz)
5ff39ae1
FB
383 bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
384 return bin;
385}
386
387/*
388 * Convert an array of big-endian words to a string
389 */
390function binb2str(bin)
391{
392 var str = "";
393 var mask = (1 << chrsz) - 1;
34cc65fd
FB
394 var i;
395 for(i = 0; i < bin.length * 32; i += chrsz)
5ff39ae1
FB
396 str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
397 return str;
398}
399
400/*
401 * Convert an array of big-endian words to a hex string.
402 */
403function binb2hex(binarray)
404{
405 var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
406 var str = "";
34cc65fd
FB
407 var i;
408 for(i = 0; i < binarray.length * 4; i++)
5ff39ae1
FB
409 {
410 str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
411 hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
412 }
413 return str;
414}
415
416/*
417 * Convert an array of big-endian words to a base-64 string
418 */
419function binb2b64(binarray)
420{
421 var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
422 var str = "";
34cc65fd
FB
423 var i, j, triplet;
424 for(i = 0; i < binarray.length * 4; i += 3)
5ff39ae1 425 {
34cc65fd 426 triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
5ff39ae1
FB
427 | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
428 | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
34cc65fd 429 for(j = 0; j < 4; j++)
5ff39ae1
FB
430 {
431 if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
432 else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
433 }
434 }
435 return str;
436}
437
438/* }}} */
439
440function hash_encrypt(a) {
441 return hex_sha1(a);
442}
443
444var hexa_h = "0123456789abcdef";
445
446function dechex(a) {
447 return hexa_h.charAt(a);
448}
449
450function hexdec(a) {
451 return hexa_h.indexOf(a);
452}
453
454function hash_xor(a, b) {
34cc65fd 455 var c,i,j,k,d;
5ff39ae1
FB
456 c = "";
457 i = a.length;
458 j = b.length;
459 if (i < j) {
5ff39ae1
FB
460 d = a; a = b; b = d;
461 k = i; i = j; j = k;
462 }
34cc65fd 463 for (k = 0; k < j; k++) {
5ff39ae1 464 c += dechex(hexdec(a.charAt(k)) ^ hexdec(b.charAt(k)));
34cc65fd
FB
465 }
466 for (; k < i; k++) {
5ff39ae1 467 c += a.charAt(k);
34cc65fd 468 }
5ff39ae1
FB
469 return c;
470}
471
472
0ba43ee4
VZ
473function getType(c) {
474 if (c >= 'a' && c <= 'z') {
7143ad2b 475 return 1;
0ba43ee4 476 } else if (c >= 'A' && c <= 'Z') {
7143ad2b 477 return 2;
0ba43ee4 478 } else if (c >= '0' && c <= '9') {
7143ad2b
FB
479 return 3;
480 } else {
481 return 4;
482 }
483}
484
4baa7323 485function differentTypes(password) {
7143ad2b 486 var prev = 0;
34cc65fd 487 var type;
4baa7323
SJ
488
489 for (i = 0 ; i < password.length ; ++i) {
34cc65fd
FB
490 type = getType(password.charAt(i));
491 if (prev !== 0 && prev !== type) {
4baa7323
SJ
492 return true;
493 }
494 prev = type;
495 }
496 return false;
497}
498
499function passwordStrength(password) {
7143ad2b 500 var prop = 0;
4baa7323 501 var prev = 0;
eaa3f284 502 var firstType = true;
4baa7323 503 var types = Array(0, 0, 0, 0, 0);
34cc65fd 504 var type;
4baa7323
SJ
505
506 for (i = 0 ; i < password.length ; ++i) {
34cc65fd
FB
507 type = getType(password.charAt(i));
508 if (prev !== 0 && prev !== type) {
7143ad2b 509 prop += 5;
4baa7323 510 firstType = false;
7143ad2b 511 }
eaa3f284 512 prop += i;
34cc65fd 513 if (types[type] === 0 && !firstType) {
eaa3f284 514 prop += 15;
7143ad2b
FB
515 }
516 types[type]++;
517 prev = type;
518 }
4baa7323
SJ
519 if (password.length < 6) {
520 prop *= 0.75;
521 }
522 if (firstType) {
aca1582e 523 prop *= 0.75;
eaa3f284 524 }
7143ad2b
FB
525 if (prop > 100) {
526 prop = 100;
527 } else if (prop < 0) {
528 prop = 0;
529 }
4baa7323
SJ
530
531 return prop;
532}
533
534function checkPassword(box, okLabel) {
535 var password = box.value;
536 var prop = passwordStrength(password);
34cc65fd 537 var submitButton;
4baa7323 538
de99248c 539 if (prop >= 60) {
00681970
FB
540 color = "#4f4";
541 bgcolor = "#050";
de99248c 542 ok = true;
23f6d4cc 543 } else if (prop >= 35) {
de99248c 544 color = "#ff4";
00681970 545 bgcolor = "#750";
b19839fd 546 ok = true;
de99248c
FB
547 } else {
548 color = "#f20";
00681970 549 bgcolor = "#700";
de99248c
FB
550 ok = false;
551 }
552 $("#passwords_measure")
00681970
FB
553 .stop()
554 .animate({ width: prop + "%",
555 backgroundColor: color
556 }, 750)
557 .parent().stop()
558 .animate({ backgroundColor: bgcolor }, 750);
34cc65fd 559 submitButton = $(":submit[name='" + passwordprompt_submit + "']");
4baa7323 560 if (ok && password.length >= 6 && differentTypes(password)) {
7b7d0970 561 submitButton.attr("value", okLabel);
de99248c 562 submitButton.removeAttr("disabled");
7143ad2b 563 } else {
7b7d0970 564 submitButton.attr("value", "Mot de passe trop faible");
de99248c 565 submitButton.attr("disabled", "disabled");
7143ad2b
FB
566 }
567}
568
5ff39ae1 569function hashResponse(password1, password2, hasConfirmation) {
34cc65fd
FB
570 var pw1 = $('[name=' + password1 + ']').val();
571 var pw2;
5ff39ae1
FB
572
573 if (hasConfirmation) {
574 pw2 = $('[name=' + password2 + ']').val();
34cc65fd 575 if (pw1 !== pw2) {
5ff39ae1
FB
576 alert("\nErreur : les deux champs ne sont pas identiques !");
577 return false;
578 }
579 $('[name=' + password2 + ']').val('');
34cc65fd 580 } else if (pw1 === '********') {
5ff39ae1
FB
581 return true;
582 }
583
584 if (pw1.length < 6) {
585 alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
586 return false;
587 }
588 if (!differentTypes(pw1)) {
589 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.");
590 return false;
591 }
592
593 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.");
594 $('[name=' + password1 + ']').val('');
595 $('[name=pwhash]').val(hash_encrypt(pw1));
596 return true;
597}
598
599function correctUserName() {
600 var u = document.forms.login.username;
34cc65fd
FB
601 var mots;
602
5ff39ae1 603 // login with no space
460098c8 604 if (!u.value.contains(' ')) {
34cc65fd
FB
605 return true;
606 }
607 mots = u.value.split(' ');
5ff39ae1 608 // jean paul.du pont -> jean-paul.du-pont
460098c8 609 if (u.value.contains('.')) {
34cc65fd
FB
610 u.value = mots.join('-');
611 return true;
612 }
5ff39ae1 613 // jean dupont -> jean.dupont
34cc65fd
FB
614 if (mots.length === 2) {
615 u.value = mots[0] + "." + mots[1];
616 return true;
617 }
5ff39ae1 618 // jean dupont 2001 -> jean.dupont.2001
34cc65fd
FB
619 if (mots.length === 3 && mots[2] > 1920 && mots[2] < 3000) {
620 u.value = mots.join('.');
621 return true;
622 }
5ff39ae1 623 // jean de la vallee -> jean.de-la-vallee
34cc65fd
FB
624 if (mots[1].toUpperCase() === 'DE') {
625 u.value = mots[0] + "." + mots.join('-').substr(mots[0].length+1);
626 return true;
627 }
5ff39ae1 628 // jean paul dupont -> jean-paul.dupont
34cc65fd
FB
629 if (mots.length === 3 && mots[0].toUpperCase() === 'JEAN') {
630 u.value = mots[0] + "-" + mots[1] + "." + mots[2];
631 return true;
632 }
5ff39ae1
FB
633
634 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 -');
635
636 return false;
637}
638
639function doChallengeResponse() {
34cc65fd 640 var new_pass, old_pass, str;
5ff39ae1 641
34cc65fd
FB
642 if (!correctUserName()) {
643 return false;
644 }
5ff39ae1 645
34cc65fd
FB
646 new_pass = hash_encrypt(document.forms.login.password.value);
647 old_pass = hash_encrypt(document.forms.login.password.value.substr(0, 10));
5ff39ae1
FB
648
649 str = document.forms.login.username.value + ":" +
650 new_pass + ":" +
651 document.forms.loginsub.challenge.value;
652
653 document.forms.loginsub.response.value = hash_encrypt(str);
34cc65fd 654 if (new_pass !== old_pass) {
5ff39ae1
FB
655 document.forms.loginsub.xorpass.value = hash_xor(new_pass, old_pass);
656 }
657 document.forms.loginsub.username.value = document.forms.login.username.value;
658 document.forms.loginsub.remember.value = document.forms.login.remember.checked;
659 document.forms.loginsub.domain.value = document.forms.login.domain.value;
660 document.forms.login.password.value = "";
661 document.forms.loginsub.submit();
662}
663
664function doChallengeResponseLogged() {
34cc65fd 665 var str = document.forms.loginsub.username.value + ":" +
5ff39ae1
FB
666 hash_encrypt(document.forms.login.password.value) + ":" +
667 document.forms.loginsub.challenge.value;
668
669 document.forms.loginsub.response.value = hash_encrypt(str);
670 document.forms.loginsub.remember.value = document.forms.login.remember.checked;
671 document.forms.login.password.value = "";
672 document.forms.loginsub.submit();
673}
674
7143ad2b 675// }}}
b0e935d6
FB
676// {{{ send test email
677
678function sendTestEmail(token, hruid)
679{
680 var url = 'emails/test';
681 var msg = "Un email a été envoyé avec succès";
34cc65fd 682 if (hruid) {
b0e935d6
FB
683 url += '/' + hruid;
684 msg += " sur l'adresse de " + hruid + ".";
685 } else {
686 msg += " sur ton addresse.";
687 }
688 $('#mail_sent').successMessage($url + '?token=' + token, msg);
689 return false;
690}
691
692// }}}
7143ad2b
FB
693
694
0337d704 695/***************************************************************************
048c44a3
FB
696 * Overlib made simple
697 */
698
699(function($) {
700 $.fn.extend({
701 overlib: function(text, width, height) {
702 var args = [ ];
34cc65fd
FB
703 var key;
704
705 if (typeof text === 'string') {
048c44a3 706 args.push(text);
34cc65fd
FB
707 if (width) {
708 args.push(width);
709 }
710 if (height) {
711 args.push(height);
712 }
048c44a3 713 } else {
34cc65fd 714 for (key in text) {
048c44a3
FB
715 switch (key) {
716 case 'text':
717 args.unshift(text[key]);
718 break;
719 case 'caption':
720 args.push(CAPTION, text[key]);
721 break;
722 case 'close_text':
723 args.push(CLOSETEXT, text[key]);
724 break;
725 case 'delay':
726 args.push(DELAY, text[key]);
727 break;
728 case 'sticky':
729 if (text[key]) {
730 args.push(STICKY);
731 }
732 break;
733 case 'width':
734 args.push(WIDTH, text[key]);
735 break;
736 case 'height':
737 args.push(HEIGHT, text[key]);
738 break;
739 }
740 }
741 }
742 return this
743 .mouseover(function () {
744 return overlib.apply(null, args);
745 })
746 .mouseout(nd);
747 }
748 });
749}(jQuery));
750
751
752/***************************************************************************
0337d704 753 * The real OnLoad
754 */
755
4171c0bf 756$(function() {
80dcbd9a
FB
757 auto_links();
758 getNow();
759 setInterval(getNow, 1000);
760 $("#quick")
761 .focus(function() {
762 if ($(this).val() === 'Recherche dans l\'annuaire') {
763 $(this).val('');
764 }
765 $("#quick_button").show();
766 })
767 .blur(function() {
768 $("#quick_button").hide();
769 });
770 $("#quick_button").click(function() {
771 if ($("#quick").val() === 'Recherche dans l\'annuaire'
772 || $("#quick").val() === '') {
773 return false;
774 }
775 return true;
776 });
777});
0337d704 778
a14159bf 779// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: