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

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