-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascripts.js
190 lines (156 loc) · 6.5 KB
/
javascripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!--
function pulisci_input_type(theField) {
if (theField.defaultValue==theField.value)
theField.value = ""
}
function menu_a_discesa( targ, selObj, restore ){
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
// Check that the number of characters in a string is between a max and a min
function isValidLength(string, min, max) {
if (string.length < min || string.length > max) return false;
else return true;
}
// Check that an email address is valid based on RFC 821 (?)
function isValidEmail(address) {
if (address.indexOf('@') < 3) return false;
var name = address.substring(0, address.indexOf('@'));
var domain = address.substring(address.indexOf('@') + 1);
if (name.indexOf('(') != -1 || name.indexOf(')') != -1 || name.indexOf('<') != -1 || name.indexOf('>') != -1 || name.indexOf(',') != -1 || name.indexOf(';') != -1 || name.indexOf(':') != -1 || name.indexOf('\\') != -1 || name.indexOf('"') != -1 || name.indexOf('[') != -1 || name.indexOf(']') != -1 || name.indexOf(' ') != -1) return false;
if (domain.indexOf('(') != -1 || domain.indexOf(')') != -1 || domain.indexOf('<') != -1 || domain.indexOf('>') != -1 || domain.indexOf(',') != -1 || domain.indexOf(';') != -1 || domain.indexOf(':') != -1 || domain.indexOf('\\') != -1 || domain.indexOf('"') != -1 || domain.indexOf('[') != -1 || domain.indexOf(']') != -1 || domain.indexOf(' ') != -1) return false;
return true;
}
// Check that a US zip code is valid
function isValidZipcode(zipcode) {
zipcode = removeSpaces(zipcode);
if (!(zipcode.length == 5) || !isNumeric(zipcode)) return false;
return true;
}
// Check that a Canadian postal code is valid
function isValidPostalcode(postalcode) {
if (postalcode.search) {
postalcode = removeSpaces(postalcode);
if (postalcode.length == 6 && postalcode.search(/^\w\d\w\d\w\d$/) != -1) return true;
else if (postalcode.length == 7 && postalcode.search(/^\w\d\w\-d\w\d$/) != -1) return true;
else return false;
}
return true;
}
// Check that a string contains only letters and numbers
function isAlphanumeric(string, ignoreWhiteSpace) {
if (string.search) {
if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false;
}
return true;
}
// Check that a string contains only letters
function isAlphabetic(string, ignoreWhiteSpace) {
if (string.search) {
if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false;
}
return true;
}
// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
if (string.search) {
if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
}
return true;
}
// Remove characters that might cause security problems from a string
function removeBadCharacters(string) {
if (string.replace) {
string.replace(/[<>\"\'%;\)\(&\+]/, '');
}
return string;
}
// Remove all spaces from a string
function removeSpaces(string) {
var newString = '';
for (var i = 0; i < string.length; i++) {
if (string.charAt(i) != ' ') newString += string.charAt(i);
}
return newString;
}
// Remove leading and trailing whitespace from a string
function trimWhitespace(string) {
var newString = '';
var substring = '';
beginningFound = false;
// copy characters over to a new string
// retain whitespace characters if they are between other characters
for (var i = 0; i < string.length; i++) {
// copy non-whitespace characters
if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {
// if the temporary string contains some whitespace characters, copy them first
if (substring != '') {
newString += substring;
substring = '';
}
newString += string.charAt(i);
if (beginningFound == false) beginningFound = true;
}
// hold whitespace characters in a temporary string if they follow a non-whitespace character
else if (beginningFound == true) substring += string.charAt(i);
}
return newString;
}
// Returns a checksum digit for a number using mod 10
function getMod10(number) {
// convert number to a string and check that it contains only digits
// return -1 for illegal input
number = '' + number;
number = removeSpaces(number);
if (!isNumeric(number)) return -1;
// calculate checksum using mod10
var checksum = 0;
for (var i = number.length - 1; i >= 0; i--) {
var isOdd = ((number.length - i) % 2 != 0) ? true : false;
digit = number.charAt(i);
if (isOdd) checksum += parseInt(digit);
else {
var evenDigit = parseInt(digit) * 2;
if (evenDigit >= 10) checksum += 1 + (evenDigit - 10);
else checksum += evenDigit;
}
}
return (checksum % 10);
}
function setPointer(theCel, thePointerColor)
{
if (thePointerColor == '' || typeof(theCel.style) == 'undefined') {
return false;
}
theCel.style.backgroundColor = thePointerColor;
return true;
}
status_text();
function status_text() {
window.status="";
setTimeout("status_text()",1);
}
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var EnableRightClick = 0;
if(isNS) document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
if(EnableRightClick==1){ return true; }
else {return false; }
}
function mousehandler(e){
if(EnableRightClick==1){ return true; }
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
function keyhandler(e) {
var myevent = (isNS) ? e : window.event;
if (myevent.keyCode==96)
EnableRightClick = 1;
return;
}
document.oncontextmenu = mischandler;
document.onkeypress = keyhandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
-->