1 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2 and is published under the AGPL license. */
4 document.observe("dom:loaded", function() {
5 var currentmail = $("account_email").value, form = $("accountform");
9 form.observe('submit', function(evt) {
10 var control, errorElements;
12 $$('.error').invoke('remove');
14 errorElements = $$('#account_email, #account_password').findAll(
16 return (!elt.check(function() {
17 return !this.value.strip().empty();
18 }, SyjStrings.notEmptyField));
22 if (!errorElements.length) {
23 control = $("account_password");
24 if (!control.check(function() {
25 return this.value.length >= 6;
26 }, SyjStrings.passwordLenghtWarn)) {
27 errorElements.push(control);
31 if (!errorElements.length) {
32 control = $("account_password");
33 if (!control.check(function() {
34 return this.value === $("account_password_confirm").value;
35 }, SyjStrings.passwordNoMatchWarn)) {
36 errorElements.push(control);
40 if (!errorElements.length) {
41 control = $("account_email");
42 if (!control.check(function() {
43 return this.value !== currentmail || $("account_password").value !== $("account_password_current").value;
44 }, SyjStrings.nochangeWarn)) {
45 errorElements.push(control);
50 * if there are errors, cancel submission
52 if (errorElements.length) {
53 errorElements[0].highlight('#F08080').focus();
54 errorElements[0].select();