rlm@0: var showingLoggedIn = false; rlm@0: var messageElement = false; rlm@0: var messageP = false; rlm@0: rlm@0: // focusField method: called when username and password gain focus rlm@0: function focusField() rlm@0: { rlm@0: try { rlm@0: if (messageElement != false) rlm@0: { rlm@0: document.getElementById('message').removeChild(messageElement); rlm@0: } rlm@0: getSeed(); rlm@0: } rlm@0: catch (e) rlm@0: { } // do nothing... hides an apparent firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=236791 rlm@0: } rlm@0: rlm@0: // blurField method: called when username and password are blurred rlm@0: function blurField() rlm@0: { rlm@0: try { rlm@0: validateLogin(); rlm@0: } rlm@0: catch (e) rlm@0: { } // hide bug https://bugzilla.mozilla.org/show_bug.cgi?id=236791 rlm@0: } rlm@0: rlm@0: // showLogin method: displays if necessariy that we are logged in rlm@0: function showLogin() { rlm@0: if (messageElement != false) rlm@0: { rlm@0: try { rlm@0: document.getElementById('message').removeChild(messageElement); rlm@0: } rlm@0: catch (e) { } rlm@0: } rlm@0: if (loggedIn) rlm@0: { rlm@0: showingLoggedIn = true; rlm@0: rlm@0: loginPanel = document.getElementById('login'); rlm@0: p = document.createElement('p'); rlm@0: pre = document.createTextNode('Logged in as '); rlm@0: strong = document.createElement('strong'); rlm@0: strong_text = document.createTextNode(fullname); rlm@0: strong.appendChild(strong_text); rlm@0: mid = document.createTextNode(' ['); rlm@0: a = document.createElement('a'); rlm@0: a.href='javascript:logout();'; rlm@0: a_text = document.createTextNode('logout'); rlm@0: a.appendChild(a_text); rlm@0: post = document.createTextNode(']'); rlm@0: rlm@0: p.appendChild(pre); rlm@0: p.appendChild(strong); rlm@0: p.appendChild(mid); rlm@0: p.appendChild(a); rlm@0: p.appendChild(post); rlm@0: rlm@0: messageP = document.getElementById('message'); rlm@0: loginPanel.removeChild(messageP); rlm@0: loginPanel.appendChild(p); rlm@0: rlm@0: messageElement = p; rlm@0: rlm@0: document.getElementById('username').disabled = 'disabled'; rlm@0: document.getElementById('password').disabled = 'disabled'; rlm@0: rlm@0: document.getElementById('comments').focus(); rlm@0: } rlm@0: else rlm@0: { rlm@0: messageElement = document.createElement('strong'); rlm@0: messageElement.appendChild(document.createTextNode(' ' + messages)); rlm@0: messageElement.style.color = '#ff0000'; rlm@0: document.getElementById('message').appendChild(messageElement); rlm@0: } rlm@0: } rlm@0: rlm@0: // logout method: prepares for a new login rlm@0: function logout() rlm@0: { rlm@0: resetLogin(); rlm@0: username = document.getElementById('username'); rlm@0: password = document.getElementById('password'); rlm@0: loginPanel = document.getElementById('login'); rlm@0: username.value = ''; rlm@0: password.value = ''; rlm@0: username.disabled = null; rlm@0: password.disabled = null; rlm@0: rlm@0: loginPanel.removeChild(messageElement); rlm@0: loginPanel.appendChild(messageP); rlm@0: rlm@0: messageElement = false; rlm@0: showingLoggedIn = false; rlm@0: rlm@0: username.focus(); rlm@0: } rlm@0: rlm@0: // setupLogin method: to be called on page load, sets up the login script rlm@0: function setupLogin() rlm@0: { rlm@0: username = document.getElementById('username'); rlm@0: password = document.getElementById('password'); rlm@0: addEvent(username, 'focus', focusField); rlm@0: addEvent(username, 'blur', blurField); rlm@0: addEvent(password, 'focus', focusField); rlm@0: addEvent(password, 'blur', blurField); rlm@0: } rlm@0: rlm@0: rlm@0: // function to add events to the page in a cross-browser manner rlm@0: function addEvent(objObject, strEventName, fnHandler) { rlm@0: // DOM-compliant way to add an event listener rlm@0: if (objObject.addEventListener) { rlm@0: objObject.addEventListener(strEventName, fnHandler, false); rlm@0: } rlm@0: // IE/windows way to add an event listener rlm@0: else if (objObject.attachEvent) { rlm@0: objObject.attachEvent('on' + strEventName, fnHandler); rlm@0: } rlm@0: } rlm@0: rlm@0: addEvent(window,'load',setupLogin);