slitaz-pizza view web/lib/functions.js @ rev 95

lib/functions.js: @ and . are valid email characters (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 14 09:09:14 2013 +0100 (2013-03-14)
parents 5fc8986fd0a0
children
line source
1 // SliTaz Pizza Javascript functions.
2 //
4 function charactersOK(field, name, str) {
5 if(document.forms["pizza"][field].value == "") {
6 alert("Please enter the "+name);
7 document.forms["pizza"][field].focus();
8 return false;
9 }
10 for (var i = 0; i < document.forms["pizza"][field].value.length; i++) {
11 if (str.indexOf(document.forms["pizza"][field].value.charAt(i)) != -1) {
12 alert ("Invalid "+name+".\n Please remove special characters.");
13 document.forms["pizza"][field].focus();
14 return false;
15 }
16 }
17 return true;
18 }
20 // Check form to avoid empty values and bad email.
21 function checkForm() {
22 if (!charactersOK("flavor", "pizza flavor name",
23 "`!@#$%^&*()+=[]\\\';,./{}|\":<>?"))
24 return false;
25 if (!charactersOK("desc", "flavor description",
26 "`!@#$%^&*()+=[]\\\';,./{}|\":<>?"))
27 return false;
28 if (!charactersOK("mail", "email address", "$`\\"))
29 return false;
30 var x=document.forms["pizza"]["mail"].value;
31 var atpos=x.indexOf("@");
32 var dotpos=x.lastIndexOf(".");
33 if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
34 {
35 alert("Missing or not a valid email address");
36 return false;
37 }
38 }
40 // Notification messages
41 function setOpacity(notifyId, opacityLevel) {
42 var notifyStyle = document.getElementById(notifyId).style;
43 notifyStyle.opacity = opacityLevel / 100;
44 notifyStyle.filter = 'alpha(opacity='+opacityLevel+')';
45 }
47 function fadeNotify(notifyId, startOpacity, stopOpacity, duration) {
48 var speed = Math.round(duration / 100);
49 var timer = 2000;
50 for (var i=startOpacity; i>=stopOpacity; i--) {
51 setTimeout("setOpacity('"+notifyId+"',"+i+")", timer * speed);
52 timer++;
53 }
54 }
56 function hideNotify() {
57 document.getElementById('notify').style.display = 'none';
58 }