source: MondoRescue/branches/stable/website/js/functions.js@ 798

Last change on this file since 798 was 358, checked in by bcornec, 18 years ago

Website rewrite begins

File size: 4.7 KB
Line 
1function domTableEnhance() {
2 if(document.getElementById && document.getElementsByTagName) {
3 var tableClass='enhanced';
4 var colourClass='enhancedtablecolouredrow';
5 var hoverClass='enhancedtablerowhover';
6 var alltables,bodies,i,j,addclass,trs,c;
7 alltables=document.getElementsByTagName('table');
8
9 for (i=0;i<alltables.length;i++) {
10 if(alltables[i].className.match(tableClass)) {
11 bodies=alltables[i].getElementsByTagName('tbody');
12
13 for (i=0;i<bodies.length;i++) {
14 trs=bodies[i].getElementsByTagName('tr')
15
16 for (j=0;j<trs.length;j++) {
17 if(trs[j].getElementsByTagName('td').length>0) {
18 addClass=j%2==0?' '+colourClass:'';
19 trs[j].className=trs[j].className+addClass;
20 trs[j].c=hoverClass;
21
22 trs[j].onmouseover=function() {
23 this.className=this.className+' '+this.c;
24 }
25
26 trs[j].onmouseout=function() {
27 this.className=this.className.replace(''+this.c,'');
28 }
29 }
30 }
31 }
32 }
33 }
34 }
35}
36
37function domCheckboxEnhance() {
38 var els=document.getElementsByTagName("input");
39 for(var i=0; i < els.length; i++) {
40 if (els[i].type=='checkbox') { // its a checkbox
41 els[i].style.display='none'; // hide the original checkbox control:
42 var img = document.createElement("img"); // create the graphical alternative:
43
44 // initial state of graphical checkbox
45 // is the same as the original checkbox:
46
47 if (els[i].checked) {
48 img.src="images/theme-default_form-checkbox-checked.png";
49 img.title="Checked";
50
51 } else {
52 img.src="images/theme-default_form-checkbox-unchecked.png";
53 img.title="Unchecked";
54
55 }
56
57 img.onclick= toggleCheckbox;
58 img.onmouseover= mouseoverCheckbox;
59 img.onmouseout= mouseoutCheckbox;
60
61 // insert the new, clickable image into the DOM
62 // infront of the original checkbox:
63
64 els[i].parentNode.insertBefore(img, els[i]);
65 }
66 }
67}
68
69
70function toggleCheckbox() {
71
72// graphical checkbox onclick event handler
73
74 // toggle the checkbox state:
75
76 if (this.title == "Checked") {
77
78 // toggle the image and title:
79 this.src="images/theme-default_form-checkbox-unchecked.png";
80 this.title="Unchecked";
81
82 // update the hidden real checkbox to match the state of the graphical
83 // version:
84 this.nextSibling.checked=false;
85
86 } else {
87
88 // toggle the image and title:
89 this.src="images/theme-default_form-checkbox-checked.png";
90 this.title="Checked";
91
92 // update the hidden real checkbox to match the state of the graphical
93 // version:
94 this.nextSibling.checked=true;
95 }
96}
97
98function mouseoverCheckbox() {
99// graphical checkbox onmouseover event handler
100 this.src="images/theme-default_form-checkbox-uncheckedhover.png";
101}
102
103function mouseoutCheckbox() {
104// graphical checkbox onmouseout event handler
105 // toggle the checkbox state:
106 if (this.title == "Checked") {
107 this.src="images/theme-default_form-checkbox-checked.png";
108 } else {
109 this.src="images/theme-default_form-checkbox-unchecked.png";
110 }
111}
112
113function loadjs() {
114// Loads startup functions
115 // domCheckboxEnhance();
116 domTableEnhance();
117}
118
119window.onload=loadjs;
120
121
122
123
124/* Form validation stuff */
125function IsEmpty(aTextField) {
126 if ((aTextField.value.length==0) || (aTextField.value==null)) {
127 return true;
128 }
129 else {
130 return false;
131 }
132}
133
134function IsEmail(str) {
135 var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
136 if (filter.test(str)) {
137 return true
138 } else {
139 return false
140 }
141}
142
143function checkServerForm(form) {
144 if((IsEmpty(form.servername)) || (form.servername.value == "Add your server here")) {
145 alert('You must provide a valid server name') ;
146 form.servername.focus();
147 return false;
148 }
149
150 if((isNaN(parseInt(form.serverport.value))) || (form.serverport.value>65535) || (form.serverport.value<1)){
151 alert('The "port" field must be a valid number (1-65535).');
152 form.serverport.focus();
153 return false;
154 }
155 return true;
156}
157
158function checkFeedbackForm(form) {
159 if(IsEmpty(form.name)) {
160 alert('You must provide your name') ;
161 form.name.focus();
162 return false;
163 }
164
165 if((IsEmpty(form.email)) || (!IsEmail(form.email.value))) {
166 alert('You must provide a valid email address (it will NOT appear in clear spammable form on the site)') ;
167 form.email.focus();
168 return false;
169 }
170
171 if(IsEmpty(form.text)) {
172 alert('You forgot to type in your message') ;
173 form.text.focus();
174 return false;
175 }
176
177 return true;
178}
Note: See TracBrowser for help on using the repository browser.