]> dev.renevier.net Git - syj.git/blob - public/js/newpwd.js
version 0.1
[syj.git] / public / js / newpwd.js
1 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2     and is published under the AGPL license. */
3 function insertErrorBefore(elt, messageError) {
4     var message = new Element("div", {className: 'error'}).update(messageError);
5     elt.insert({before: message});
6 }
7
8 document.observe("dom:loaded", function() {
9     var errors, tofocus;
10
11     errors = $$('.error');
12     tofocus = null;
13     if (errors.length) {
14         tofocus = $('newpwd_email');
15     } else {
16         tofocus = $$('form input:not([readonly],[disabled])')[0];
17     }
18     if (tofocus) {
19         tofocus.focus();
20         tofocus.select();
21     }
22
23     $("newpwdform").observe('submit', function(evt) {
24         $$('.error').invoke('remove');
25         if ($('newpwd_email').value.strip().empty()) {
26             insertErrorBefore($('newpwdform').select('table')[0], SyjStrings.notEmptyField);
27             $('newpwd_email').focus();
28             $('newpwd_email').select();
29             evt.stop();
30         }
31     });
32
33 });