Valid HTML test
[weblabels.fsf.org.git] / www.fsf.org / 20131028 / files / login.js
1 // Functions used by login pages
2
3 function cookiesEnabled() {
4 // Test whether cookies are enabled by attempting to set a cookie and then change its value
5 // set test cookie
6 var c = "areYourCookiesEnabled=0";
7 document.cookie = c;
8 var dc = document.cookie;
9 // cookie not set? fail
10 if (dc.indexOf(c) == -1) return 0;
11 // change test cookie
12 c = "areYourCookiesEnabled=1";
13 document.cookie = c;
14 dc = document.cookie;
15 // cookie not changed? fail
16 if (dc.indexOf(c) == -1) return 0;
17 // delete cookie
18 document.cookie = "areYourCookiesEnabled=; expires=Thu, 01-Jan-70 00:00:01 GMT";
19 return 1;
20 }
21
22 function setLoginVars(user_name_id, alt_user_name_id, password_id, empty_password_id, js_enabled_id, cookies_enabled_id) {
23 // Indicate that javascript is enabled, set cookie status, copy username and password length info to
24 // alternative variables since these vars are removed from the request by zope's authentication mechanism.
25 if (js_enabled_id) {
26 el = document.getElementById(js_enabled_id);
27 if (el) { el.value = 1; }
28 }
29 if (cookies_enabled_id) {
30 el = document.getElementById(cookies_enabled_id);
31 // Do a fresh cookies enabled test every time we press the login button
32 // so that we are up to date in case the user enables cookies after seeing
33 // the cookies message.
34 if (el) { el.value = cookiesEnabled(); }
35 }
36 if (user_name_id && alt_user_name_id) {
37 user_name = document.getElementById(user_name_id)
38 alt_user_name = document.getElementById(alt_user_name_id)
39 if (user_name && alt_user_name) {
40 alt_user_name.value = user_name.value;
41 }
42 }
43 if (password_id && empty_password_id) {
44 password = document.getElementById(password_id)
45 empty_password = document.getElementById(empty_password_id)
46 if (password && empty_password) {
47 if (password.value.length==0) {
48 empty_password.value = '1';
49 } else {
50 empty_password.value = '0';
51 }
52 }
53 }
54 return 1;
55 }
56
57 function showCookieMessage(msg_id) {
58 // Show the element with the given id if cookies are not enabled
59 msg = document.getElementById(msg_id)
60 if (msg) {
61 if (cookiesEnabled()) {
62 msg.style.display = 'none';
63 } else {
64 msg.style.display = 'block';
65 }
66 }
67 }
68
69 function showEnableCookiesMessage() {
70 // Show the element with the id 'enable_cookies_message' if cookies are not enabled
71 showCookieMessage('enable_cookies_message')
72 }
73 // Call showEnableCookiesMessage after the page loads
74 registerPloneFunction(showEnableCookiesMessage);