PageSourceSearch

https://www.gleim.com/misc/_js/forms.js?v=20190619

js gleim.com collected 2026-10-02 05:51:20 UTC 13,457 bytes, 318 lines download raw bytes

1// This is the "hash" that will hold the form's initial values when it was loaded
2var initialValues = new Object;
3
4// This is the global that gets set when the form's "real" submit button gets
5// clicked on.  This is needed to control which submit button(s) on forms with
6// multiple submit buttons actually trigger form validation.
7var validateAction;
8
9// This function preps the form fields so that they highlight on focus.
10// This used to also highlight on mouseover but Bryce felt that was
11// a bit too much so now it only highlights on focus.
12function prepFormFields() {
13   var htmlElements = Array('input', 'textarea');
14   var htmlTempArray;
15   for (var i = 0; i < htmlElements.length; i++) {
16      htmlTempArray = document.getElementsByTagName(htmlElements[i]);
17      for (var j = 0; j < htmlTempArray.length; j++) {
18         // Here we create an associative array of all of the select/input/textarea form fields
19         // on the page.  We use this in the validateForm function to revert the field back
20         // to its original value if there was an error.
21         initialValues[htmlTempArray[j].name] = htmlTempArray[j].value;
22         if (!htmlTempArray[j].getAttribute("nohilight") && !htmlTempArray[j].className) {
23            htmlTempArray[j].onfocus = function() {
24             this.className = "active";
25            }
26            htmlTempArray[j].onblur = function() {
27             this.className = "";
28            }
29         }
30      }
31   }
32}
33
34// This function returns whether the specified form element has an initial value
35// or not.
36function hasInitialValue(elem) {
37   if (initialValues[elem.name] != null && initialValues[elem.name].length > 0) {
38      return true;
39   }
40   else {
41      return false;
42   }
43}
44
45// This function returns whether the specified form element is currently empty
46// or not.
47function isNotEmpty(elem) {
48   var str = elem.value;
49   if(str == null || str.length == 0) {
50      return false;
51   }
52   else {
53      return true;
54   }
55}
56
57// THIS FUNCTION PERFORMS VALIDATION BASED ON A SET OF CUSTOM HTML ATTRIBUTES
58function validateForm(form) {
59   var attrVal, attrReg, attrEq, attrFail, disabledVal, strTemp;
60
61   if (validateAction) {
62      for (var i = 0; i < form.length; i++) {
63         attrVal = form[i].getAttribute("validate");
64         disabledVal = form[i].getAttribute("disabled");
65         if (attrVal != null && attrVal.length > 0 && (disabledVal == null || disabledVal.length == 0)) {
66            validations = attrVal.split('_');
67            for (var j = 0; j < validations.length; j++) {
68               alertMesg = '';
69               switch (validations[j]) {
70                  case 'required' :
71                     //required fields ignore the failure message and use the default here
72                     if (!isNotEmpty(form[i])) {
73                        alertMesg = 'You must complete all required form fields.';
74                        fieldName = form[i].getAttribute("displayName");
75                        if (fieldName != null && fieldName.length != 0) {
76                           alertMesg += ' "' + fieldName + '" was left blank.';
77                        }
78                        alert(alertMesg);
79                        form[i].focus();
80                        if (hasInitialValue(form[i])) {
81                           form[i].value = initialValues[form[i].name];
82                        }
83                        return false;
84                     }
85                     break;
86
87                  case 'regex' :
88                     if (isNotEmpty(form[i])) {
89                        attrReg = form[i].getAttribute("regex");
90                        if (attrReg != null && attrReg.length != 0) {
91                           var regex = new RegExp(attrReg);
92                           strTemp = form[i].value;
93                           if (!strTemp.match(regex)) {
94                              attrFail = form[i].getAttribute("failure");
95
96                              if (attrFail) {
97                                 alert(attrFail);
98                              }
99                              else {
100                                 fieldName = form[i].getAttribute("displayName");
101                                 if (fieldName != null && fieldName.length != 0) {
102                                    alert('Invalid data format detected in "' + fieldName + '".');
103                                 }
104                                 else {
105                                    alert('Invalid data format at field "' + form[i].name + '".');
106                                 }
107                              }
108                              form[i].focus();
109                              if (hasInitialValue(form[i])) {
110                                 form[i].value = initialValues[form[i].name];
111                              }
112                              return false;
113                           }
114                        }
115                     }
116                     break;
117
118                  case 'email' :
119                     if (isNotEmpty(form[i]) && window.RegExp) {
120                        var dotatom = '\\w!#$%&\'*+\\/=?^`{\\\\}~\\-';
121                        eval("var regex = /^["+dotatom+"\\.]+\\@[a-z\\d]["+dotatom+"]*(\\.[a-z\\d]["+dotatom+"]+)+$/i");
122                        strTemp = form[i].value;
123                        if (!strTemp.match(regex)) {
124                           attrFail = form[i].getAttribute("failure");
125
126                           if (attrFail) {
127                              alert(attrFail);
128                           }
129                           else {
130                              fieldName = form[i].getAttribute("displayName");
131                              if (fieldName != null && fieldName.length != 0) {
132                                 alert('"' + form[i].value + '" is not a valid email address at form field "' + fieldName + '".');
133                              }
134                              else {
135                                 alert(form[i].value + ' is not a valid email address.');
136                              }
137                           }
138                           form[i].focus();
139                           if (hasInitialValue(form[i])) {
140                              form[i].value = initialValues[form[i].name];
141                           }
142                           return false;
143                        }
144                     }
145                     break;
146
147                  case 'zipcode' :
148                     if (isNotEmpty(form[i])) {
149                        var regex = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
150                        strTemp = form[i].value.replace(/^\s+|\s+$/g,'');
151                        if (!strTemp.match(regex)) {
152                           attrFail = form[i].getAttribute("failure");
153
154                           if (attrFail) {
155                              alert(attrFail);
156                           }
157                           else {
158                              fieldName = form[i].getAttribute("displayName");
159                              if (fieldName != null && fieldName.length != 0) {
160                                 alert('"' + form[i].value + '" is not a valid US zip code at form field "' + fieldName + '".');
161                              }
162                              else {
163                                 alert(form[i].value + ' is not a valid US zip code.');
164                              }
165                           }
166                           form[i].focus();
167                           if (hasInitialValue(form[i])) {
168                              form[i].value = initialValues[form[i].name];
169                           }
170                           return false;
171                        }
172                     }
173                     break;
174
175                  case 'numeric' :
176                     if (isNotEmpty(form[i])) {
177                        var regex = /\D+/;
178                        strTemp = form[i].value;
179                        if (strTemp.match(regex)) {
180                           attrFail = form[i].getAttribute("failure");
181
182                           if (attrFail) {
183                              alert(attrFail);
184                           }
185                           else {
186                              fieldName = form[i].getAttribute("displayName");
187                              if (fieldName != null && fieldName.length != 0) {
188                                 alert('Field "' + fieldName + '" may only contain numbers (0-9).');
189                              }
190                              else {
191                                 alert('Field may only contain numbers (0-9).');
192                              }
193                           }
194                           form[i].focus();
195                           if (hasInitialValue(form[i])) {
196                              form[i].value = initialValues[form[i].name];
197                           }
198                           return false;
199                        }
200                     }
201                     break;
202
203                  case 'alpha' :
204                     if (isNotEmpty(form[i])) {
205                        var regex = /[^a-zA-Z]+/;
206                        strTemp = form[i].value;
207                        if (strTemp.match(regex)) {
208                           attrFail = form[i].getAttribute("failure");
209
210                           if (attrFail) {
211                              alert(attrFail);
212                           }
213                           else {
214                              fieldName = form[i].getAttribute("displayName");
215                              if (fieldName != null && fieldName.length != 0) {
216                                 alert('Field "' + fieldName + '" may only contain letters (A-Z).');
217                              }
218                              else {
219                                 alert('Field may only contain letters (A-Z).');
220                              }
221                           }
222                           form[i].focus();
223                           if (hasInitialValue(form[i])) {
224                              form[i].value = initialValues[form[i].name];
225                           }
226                           return false;
227                        }
228                     }
229                     break;
230
231                  case 'alphanumeric' :
232                     if (isNotEmpty(form[i])) {
233                        var regex = /[^A-Za-z0-9]+/;
234                        strTemp = form[i].value;
235                        if (strTemp.match(regex)) {
236                           attrFail = form[i].getAttribute("failure");
237
238                           if (attrFail) {
239                              alert(attrFail);
240                           }
241                           else {
242                              fieldName = form[i].getAttribute("displayName");
243                              if (fieldName != null && fieldName.length != 0) {
244                                 alert('Field "' + fieldName + '" may only contain letters or numbers (A-Z, 0-9).');
245                              }
246                              else {
247                                 alert('Field may only contain letters or numbers (A-Z, 0-9).');
248                              }
249                           }
250                           form[i].focus();
251                           if (hasInitialValue(form[i])) {
252                              form[i].value = initialValues[form[i].name];
253                           }
254                           return false;
255                        }
256                     }
257                     break;
258
259                  case 'equals' :
260                     attrEq = form[i].getAttribute("equals");
261                     var objEq = document.getElementById(attrEq);
262                     if (objEq) {
263                        if (form[i].value != objEq.value) {
264                           attrFail = form[i].getAttribute("failure");
265
266                           if (attrFail) {
267                              alert(attrFail);
268                           }
269                           else {
270                              alert('Form fields do not match');
271                           }
272                           form[i].focus();
273                           if (hasInitialValue(form[i])) {
274                              form[i].value = initialValues[form[i].name];
275                           }
276                           return false;
277                        }
278                     }
279                     break;
280               } //End switch
281            }  //End for
282         } //End if
283      } //End for
284   } //End if
285
286   return true;
287}
288
289document.ready = function() {
290   prepFormFields();
291
292   $(".maskPassword").click( function() {
293      var passBox = $(".passwordBox");
294      var type = passBox.prop("type");
295      var maskPassword = $(".maskPassword");
296      $.cookie("password_type", null);
297      if (type == "password") {
298         passBox.prop("type", "text");
299         maskPassword.text("Hide Characters");
300         $.cookie("password_type", "text");
301         return;
302      }
303      passBox.prop("type", "password");
304      maskPassword.text("Show Characters");
305      $.cookie("password_type", "password");
306   });
307
308   // For some mobile devices(iOS), where clicking on an element doesn't trigger hover.
309   $('.help-tip').on('touchstart click',function() {
310      $(this).focus();
311   });
312
313   $('body').on('touchstart click',function(e) {
314      if (!$(e.target).is('.help-tip')) {
315         $('.help-tip').blur();
316      }
317   });
318}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.