]> dev.renevier.net Git - syj.git/blob - public/js/contact.js
version 0.1
[syj.git] / public / js / contact.js
1 /*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2     and is published under the AGPL license. */
3
4 document.observe("dom:loaded", function() {
5     var form = $("contactform");
6     form.focus();
7
8     form.observe('submit', function(evt) {
9         var control, errorElements;
10
11         $$('.error').invoke('remove');
12
13         errorElements = $$('input:not([type="submit"]),textarea').findAll(
14             function(elt) {
15                 return (!elt.check(function() {
16                     return !this.value.strip().empty();
17                 }, SyjStrings.notEmptyField));
18             });
19
20         if (!errorElements.length) {
21             control = $("contact_email");
22             if (!control.check(function() {
23                 return this.value.match(/^[A-Z0-9._\-]+@[A-Z0-9][A-Z0-9.\-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i);
24               }, SyjStrings.invalidMail)) {
25                 errorElements.push($("contact_email"));
26             }
27         }
28
29         /*
30          * if there are errors, cancel submission
31          */
32         if (errorElements.length) {
33             errorElements[0].focus();
34             errorElements[0].select();
35             evt.stop();
36         }
37     });
38
39 });