Project

General

Profile

1 3005 costa
<%@ page language="java"%>
2
3
<!--
4
/**
5
  *  '$RCSfile$'
6
  *      Authors:     Duane Costa
7
  *      Copyright:   2005 University of New Mexico and
8
  *                   Regents of the University of California and the
9
  *                   National Center for Ecological Analysis and Synthesis
10
  *      For Details: http://www.nceas.ucsb.edu/
11
  *
12
  *   '$Author$'
13
  *     '$Date$'
14
  * '$Revision$'
15
  *
16
  * This program is free software; you can redistribute it and/or modify
17
  * it under the terms of the GNU General Public License as published by
18
  * the Free Software Foundation; either version 2 of the License, or
19
  * (at your option) any later version.
20
  *
21
  * This program is distributed in the hope that it will be useful,
22
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
  * GNU General Public License for more details.
25
  *
26
  * You should have received a copy of the GNU General Public License
27
  * along with this program; if not, write to the Free Software
28
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
  *
30
  */
31
-->
32
33
<%@ include file="settings.jsp"%>
34
<%@ include file="session_vars.jsp"%>
35
36
<html>
37
38
  <head>
39
    <link href="<%=relativeRoot%>/lter.css" rel="stylesheet" type="text/css">
40
    <title>
41
      LTER Data Catalog Login
42
    </title>
43
    <%
44
      String loginFailure = (String) request.getParameter("loginFailure");
45
      String loginFailureMessage = "";
46
47
      if ((loginFailure != null) && (loginFailure.equals("true"))) {
48
        loginFailureMessage = "<p class=\"emphasis\">" +
49
                              "Login failed. " +
50
                              "Please enter a valid Username, Organization, and Password." +
51
                              "</p>";
52
      }
53
    %>
54
  </head>
55
56
  <body>
57
    <form name="loginForm" method="POST" action="<%=relativeRoot%>/metacatloginforward.jsp" target="_top" onsubmit="return validateLoginForm(this)">
58
      <table cellpadding="4" cellspacing="0">
59
        <tr>
60
          <td colspan="3" align="left">
61
            <h2>
62
              LTER Data Catalog Login
63
            </h2>
64
            Logging into your account enables you to search any additional, non-public data for which you may have access privileges.
65
            <br />
66
            <%=loginFailureMessage%>
67
          </td>
68
          <td>
69
            &nbsp;
70
          </td>
71
        </tr>
72
73
        <tr>
74
          <td align="right">
75
            Username:
76
          </td>
77
          <td align="left">
78
            <input type="text" name="username" maxlength="15" size="15" value="">
79
          </td>
80
          <td>
81
            <a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?cfg=lter">
82
              Create a new account
83
            </a>
84
          </td>
85
        </tr>
86
87
        <tr>
88
          <td align="right">
89
            Organization:
90
          </td>
91
          <td align="left">
92
            <select name="organization">
93
              <option value="KU">
94
                KU
95
              </option>
96
              <option value="LTER" selected="selected">
97
                LTER
98
              </option>
99
              <option value="NCEAS">
100
                NCEAS
101
              </option>
102
              <option value="OBFS">
103
                OBFS
104
              </option>
105 3027 sgarg
              <option value="OSUBS">
106
                OSUBS
107
              </option>
108 3005 costa
              <option value="PISCO">
109
                PISCO
110
              </option>
111
              <option value="SDSC">
112
                SDSC
113
              </option>
114
              <option value="UCNRS">
115
                UCNRS
116
              </option>
117
              <option value="unaffiliated">
118
                unaffiliated
119
              </option>
120
            </select>
121
          </td>
122
          <td>
123
            <a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?stage=resetpass&cfg=lter">
124
              Forgot your password?
125
            </a>
126
          </td>
127
        </tr>
128
129
        <tr>
130
          <td align="right">
131
            Password:
132
          </td>
133
          <td align="left">
134
            <!-- Don't redisplay password for security reasons -->
135
            <input type="password" name="password" maxlength="15" size="15" value="">
136
          </td>
137
          <td>
138
            <a target="_top" href="http://knb.ecoinformatics.org/cgi-bin/ldapweb.cgi?stage=changepass&cfg=lter">
139
              Change your password
140
            </a>
141
          </td>
142
        </tr>
143
144
        <tr>
145
          <td>
146
            &nbsp;
147
          </td>
148
          <td align="left">
149
            <input type="submit" value="Login">
150
            &nbsp;&nbsp;
151
            <input type="reset" value="Reset">
152
          </td>
153
          <td>
154
            &nbsp;
155
          </td>
156
        </tr>
157
      </table>
158
    </form>
159
160
    <script type="text/javascript" language="JavaScript">
161
    <!--
162
    var focusControl = document.forms["loginForm"].elements["username"];
163
164
    if (focusControl.type != "hidden" && !focusControl.disabled) {
165
      focusControl.focus();
166
    }
167
    // -->
168
  </script>
169
170
    <script type="text/javascript" language="Javascript1.1">
171
    <!-- Begin
172
173
    var bCancel = false;
174
175
    function validateLoginForm(form) {
176
      if (bCancel)
177
        return true;
178
      else
179
        var formValidationResult;
180
        formValidationResult = validateRequired(form) && validateMinLength(form);
181
        return (formValidationResult == 1);
182
    }
183
184
    function loginForm_required () {
185
      this.a0 = new Array("username", "Username is required.", new Function ("varName", " return this[varName];"));
186
      this.a1 = new Array("password", "Password is required.", new Function ("varName", "this.minlength='3';  return this[varName];"));
187
    }
188
189
    function loginForm_minlength () {
190
      this.a0 = new Array("password", "Password can not be less than 3 characters.", new Function ("varName", "this.minlength='3';  return this[varName];"));
191
    }
192
193
    /**
194
    * Check to see if fields are in a valid float range.
195
    * Fields are not checked if they are disabled.
196
    * <p>
197
    * @param form The form validation is taking place on.
198
    */
199
    function validateFloatRange(form) {
200
        var isValid = true;
201
        var focusField = null;
202
        var i = 0;
203
        var fields = new Array();
204
        var formName = form.getAttributeNode("name");
205
206
        oRange = eval('new ' + formName.value + '_floatRange()');
207
        for (x in oRange) {
208
            var field = form[oRange[x][0]];
209
210
            if ((field.type == 'hidden' ||
211
                field.type == 'text' || field.type == 'textarea') &&
212
                (field.value.length > 0)  &&
213
                 field.disabled == false) {
214
215
                var fMin = parseFloat(oRange[x][2]("min"));
216
                var fMax = parseFloat(oRange[x][2]("max"));
217
                var fValue = parseFloat(field.value);
218
                if (!(fValue >= fMin && fValue <= fMax)) {
219
                    if (i == 0) {
220
                        focusField = field;
221
                    }
222
                    fields[i++] = oRange[x][1];
223
                    isValid = false;
224
                }
225
            }
226
        }
227
        if (fields.length > 0) {
228
            focusField.focus();
229
            alert(fields.join('\n'));
230
        }
231
        return isValid;
232
    }
233
234
235
  /**
236
  * This is a place holder for common utilities used across the javascript validation
237
  *
238
  **/
239
240
    /**
241
    * Check to see if fields are a valid byte.
242
    * Fields are not checked if they are disabled.
243
    * <p>
244
    * @param form The form validation is taking place on.
245
    */
246
    function validateByte(form) {
247
        var bValid = true;
248
        var focusField = null;
249
        var i = 0;
250
        var fields = new Array();
251
        var formName = form.getAttributeNode("name");
252
        oByte = eval('new ' + formName.value + '_ByteValidations()');
253
254
        for (x in oByte) {
255
            var field = form[oByte[x][0]];
256
257
            if ((field.type == 'hidden' ||
258
                field.type == 'text' ||
259
                field.type == 'textarea' ||
260
                field.type == 'select-one' ||
261
                field.type == 'radio')  &&
262
                field.disabled == false) {
263
264
                var value = '';
265
                // get field's value
266
                if (field.type == "select-one") {
267
                    var si = field.selectedIndex;
268
                    if (si >= 0) {
269
                        value = field.options[si].value;
270
                    }
271
                } else {
272
                    value = field.value;
273
                }
274
275
                if (value.length > 0) {
276
                    if (!isAllDigits(value)) {
277
                        bValid = false;
278
                        if (i == 0) {
279
                            focusField = field;
280
                        }
281
                        fields[i++] = oByte[x][1];
282
283
                    } else {
284
285
                        var iValue = parseInt(value);
286
                        if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
287
                            if (i == 0) {
288
                                focusField = field;
289
                            }
290
                            fields[i++] = oByte[x][1];
291
                            bValid = false;
292
                        }
293
                    }
294
                }
295
296
            }
297
        }
298
        if (fields.length > 0) {
299
           focusField.focus();
300
           alert(fields.join('\n'));
301
        }
302
        return bValid;
303
    }
304
305
306
    /**
307
    * A field is considered valid if less than the specified maximum.
308
    * Fields are not checked if they are disabled.
309
    * <p>
310
    * <strong>Caution:</strong> Using <code>validateMaxLength</code> on a password field in a
311
    *  login page gives unnecessary information away to hackers. While it only slightly
312
    *  weakens security, we suggest using it only when modifying a password.</p>
313
    * @param form The form validation is taking place on.
314
    */
315
    function validateMaxLength(form) {
316
        var isValid = true;
317
        var focusField = null;
318
        var i = 0;
319
        var fields = new Array();
320
        var formName = form.getAttributeNode("name");
321
322
        oMaxLength = eval('new ' + formName.value + '_maxlength()');
323
        for (x in oMaxLength) {
324
            var field = form[oMaxLength[x][0]];
325
326
            if ((field.type == 'hidden' ||
327
                field.type == 'text' ||
328
                field.type == 'password' ||
329
                field.type == 'textarea') &&
330
                field.disabled == false) {
331
332
                var iMax = parseInt(oMaxLength[x][2]("maxlength"));
333
                if (field.value.length > iMax) {
334
                    if (i == 0) {
335
                        focusField = field;
336
                    }
337
                    fields[i++] = oMaxLength[x][1];
338
                    isValid = false;
339
                }
340
            }
341
        }
342
        if (fields.length > 0) {
343
           focusField.focus();
344
           alert(fields.join('\n'));
345
        }
346
        return isValid;
347
    }
348
349
350
    /**
351
    *  Check to see if fields must contain a value.
352
    * Fields are not checked if they are disabled.
353
    * <p>
354
    * @param form The form validation is taking place on.
355
    */
356
    function validateRequired(form) {
357
        var isValid = true;
358
        var focusField = null;
359
        var i = 0;
360
        var fields = new Array();
361
        var formName = form.getAttributeNode("name");
362
363
        oRequired = eval('new ' + formName.value + '_required()');
364
365
        for (x in oRequired) {
366
            var field = form[oRequired[x][0]];
367
368
            if ((field.type == 'hidden' ||
369
                field.type == 'text' ||
370
                field.type == 'textarea' ||
371
                field.type == 'file' ||
372
                field.type == 'checkbox' ||
373
                field.type == 'select-one' ||
374
                field.type == 'password') &&
375
                field.disabled == false) {
376
377
                var value = '';
378
                // get field's value
379
                if (field.type == "select-one") {
380
                    var si = field.selectedIndex;
381
                    if (si >= 0) {
382
                        value = field.options[si].value;
383
                    }
384
                } else if (field.type == 'checkbox') {
385
                    if (field.checked) {
386
                        value = field.value;
387
                    }
388
                } else {
389
                    value = field.value;
390
                }
391
392
                if (trim(value).length == 0) {
393
394
                    if (i == 0) {
395
                        focusField = field;
396
                    }
397
                    fields[i++] = oRequired[x][1];
398
                    isValid = false;
399
                }
400
            } else if (field.type == "select-multiple") {
401
                var numOptions = field.options.length;
402
                lastSelected=-1;
403
                for(loop=numOptions-1;loop>=0;loop--) {
404
                    if(field.options[loop].selected) {
405
                        lastSelected = loop;
406
                        value = field.options[loop].value;
407
                        break;
408
                    }
409
                }
410
                if(lastSelected < 0 || trim(value).length == 0) {
411
                    if(i == 0) {
412
                        focusField = field;
413
                    }
414
                    fields[i++] = oRequired[x][1];
415
                    isValid=false;
416
                }
417
            } else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) {
418
                isChecked=-1;
419
                for (loop=0;loop < field.length;loop++) {
420
                    if (field[loop].checked) {
421
                        isChecked=loop;
422
                        break; // only one needs to be checked
423
                    }
424
                }
425
                if (isChecked < 0) {
426
                    if (i == 0) {
427
                        focusField = field[0];
428
                    }
429
                    fields[i++] = oRequired[x][1];
430
                    isValid=false;
431
                }
432
            }
433
        }
434
        if (fields.length > 0) {
435
           focusField.focus();
436
           alert(fields.join('\n'));
437
        }
438
        return isValid;
439
    }
440
441
    // Trim whitespace from left and right sides of s.
442
    function trim(s) {
443
        return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
444
    }
445
446
447
    /**
448
    * Check to see if fields are a valid integer.
449
    * Fields are not checked if they are disabled.
450
    * <p>
451
    * @param form The form validation is taking place on.
452
    */
453
    function validateInteger(form) {
454
        var bValid = true;
455
        var focusField = null;
456
        var i = 0;
457
        var fields = new Array();
458
        var formName = form.getAttributeNode("name");
459
460
        oInteger = eval('new ' + formName.value + '_IntegerValidations()');
461
        for (x in oInteger) {
462
            var field = form[oInteger[x][0]];
463
464
            if ((field.type == 'hidden' ||
465
                field.type == 'text' ||
466
                field.type == 'textarea' ||
467
                field.type == 'select-one' ||
468
                field.type == 'radio') &&
469
                field.disabled == false) {
470
471
                var value = '';
472
                // get field's value
473
                if (field.type == "select-one") {
474
                    var si = field.selectedIndex;
475
                    if (si >= 0) {
476
                        value = field.options[si].value;
477
                    }
478
                } else {
479
                    value = field.value;
480
                }
481
482
                if (value.length > 0) {
483
484
                    if (!isAllDigits(value)) {
485
                        bValid = false;
486
                        if (i == 0) {
487
                            focusField = field;
488
                        }
489
                        fields[i++] = oInteger[x][1];
490
491
                    } else {
492
                        var iValue = parseInt(value);
493
                        if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
494
                            if (i == 0) {
495
                                focusField = field;
496
                            }
497
                            fields[i++] = oInteger[x][1];
498
                            bValid = false;
499
                       }
500
                   }
501
               }
502
            }
503
        }
504
        if (fields.length > 0) {
505
           focusField.focus();
506
           alert(fields.join('\n'));
507
        }
508
        return bValid;
509
    }
510
511
    function isAllDigits(argvalue) {
512
        argvalue = argvalue.toString();
513
        var validChars = "0123456789";
514
        var startFrom = 0;
515
        if (argvalue.substring(0, 2) == "0x") {
516
           validChars = "0123456789abcdefABCDEF";
517
           startFrom = 2;
518
        } else if (argvalue.charAt(0) == "0") {
519
           validChars = "01234567";
520
           startFrom = 1;
521
        } else if (argvalue.charAt(0) == "-") {
522
            startFrom = 1;
523
        }
524
525
        for (var n = startFrom; n < argvalue.length; n++) {
526
            if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
527
        }
528
        return true;
529
    }
530
531
532
    /**
533
    * Check to see if fields are a valid date.
534
    * Fields are not checked if they are disabled.
535
    * <p>
536
    * @param form The form validation is taking place on.
537
    */
538
    function validateDate(form) {
539
       var bValid = true;
540
       var focusField = null;
541
       var i = 0;
542
       var fields = new Array();
543
       var formName = form.getAttributeNode("name");
544
545
       oDate = eval('new ' + formName.value + '_DateValidations()');
546
547
       for (x in oDate) {
548
           var field = form[oDate[x][0]];
549
           var value = field.value;
550
           var datePattern = oDate[x][2]("datePatternStrict");
551
           // try loose pattern
552
           if (datePattern == null)
553
               datePattern = oDate[x][2]("datePattern");
554
           if ((field.type == 'hidden' ||
555
                field.type == 'text' ||
556
                field.type == 'textarea') &&
557
               (value.length > 0) && (datePattern.length > 0) &&
558
                field.disabled == false) {
559
                 var MONTH = "MM";
560
                 var DAY = "dd";
561
                 var YEAR = "yyyy";
562
                 var orderMonth = datePattern.indexOf(MONTH);
563
                 var orderDay = datePattern.indexOf(DAY);
564
                 var orderYear = datePattern.indexOf(YEAR);
565
                 if ((orderDay < orderYear && orderDay > orderMonth)) {
566
                     var iDelim1 = orderMonth + MONTH.length;
567
                     var iDelim2 = orderDay + DAY.length;
568
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
569
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
570
                     if (iDelim1 == orderDay && iDelim2 == orderYear) {
571
                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
572
                     } else if (iDelim1 == orderDay) {
573
                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
574
                     } else if (iDelim2 == orderYear) {
575
                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
576
                     } else {
577
                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
578
                     }
579
                     var matched = dateRegexp.exec(value);
580
                     if(matched != null) {
581
                        if (!isValidDate(matched[2], matched[1], matched[3])) {
582
                           if (i == 0) {
583
                               focusField = field;
584
                           }
585
                           fields[i++] = oDate[x][1];
586
                           bValid =  false;
587
                        }
588
                     } else {
589
                        if (i == 0) {
590
                            focusField = field;
591
                        }
592
                        fields[i++] = oDate[x][1];
593
                        bValid =  false;
594
                     }
595
                 } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
596
                     var iDelim1 = orderDay + DAY.length;
597
                     var iDelim2 = orderMonth + MONTH.length;
598
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
599
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
600
                     if (iDelim1 == orderMonth && iDelim2 == orderYear) {
601
                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
602
                     } else if (iDelim1 == orderMonth) {
603
                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
604
                     } else if (iDelim2 == orderYear) {
605
                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
606
                     } else {
607
                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
608
                     }
609
                     var matched = dateRegexp.exec(value);
610
                     if(matched != null) {
611
                         if (!isValidDate(matched[1], matched[2], matched[3])) {
612
                             if (i == 0) {
613
                         focusField = field;
614
                             }
615
                             fields[i++] = oDate[x][1];
616
                             bValid =  false;
617
                          }
618
                     } else {
619
                         if (i == 0) {
620
                             focusField = field;
621
                         }
622
                         fields[i++] = oDate[x][1];
623
                         bValid =  false;
624
                     }
625
                 } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
626
                     var iDelim1 = orderYear + YEAR.length;
627
                     var iDelim2 = orderMonth + MONTH.length;
628
                     var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
629
                     var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
630
                     if (iDelim1 == orderMonth && iDelim2 == orderDay) {
631
                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
632
                     } else if (iDelim1 == orderMonth) {
633
                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
634
                     } else if (iDelim2 == orderDay) {
635
                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
636
                     } else {
637
                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
638
                     }
639
                     var matched = dateRegexp.exec(value);
640
                     if(matched != null) {
641
                         if (!isValidDate(matched[3], matched[2], matched[1])) {
642
                             if (i == 0) {
643
                                 focusField = field;
644
                             }
645
                             fields[i++] = oDate[x][1];
646
                             bValid =  false;
647
                         }
648
                     } else {
649
                          if (i == 0) {
650
                              focusField = field;
651
                          }
652
                          fields[i++] = oDate[x][1];
653
                          bValid =  false;
654
                     }
655
                 } else {
656
                     if (i == 0) {
657
                         focusField = field;
658
                     }
659
                     fields[i++] = oDate[x][1];
660
                     bValid =  false;
661
                 }
662
          }
663
       }
664
       if (fields.length > 0) {
665
          focusField.focus();
666
          alert(fields.join('\n'));
667
       }
668
       return bValid;
669
    }
670
671
    function isValidDate(day, month, year) {
672
        if (month < 1 || month > 12) {
673
            return false;
674
        }
675
        if (day < 1 || day > 31) {
676
            return false;
677
        }
678
        if ((month == 4 || month == 6 || month == 9 || month == 11) &&
679
            (day == 31)) {
680
            return false;
681
        }
682
        if (month == 2) {
683
            var leap = (year % 4 == 0 &&
684
               (year % 100 != 0 || year % 400 == 0));
685
            if (day>29 || (day == 29 && !leap)) {
686
                return false;
687
            }
688
        }
689
        return true;
690
    }
691
692
693
    /**
694
    * Check to see if fields are a valid creditcard number based on Luhn checksum.
695
    * Fields are not checked if they are disabled.
696
    * <p>
697
    * @param form The form validation is taking place on.
698
    */
699
    function validateCreditCard(form) {
700
        var bValid = true;
701
        var focusField = null;
702
        var i = 0;
703
        var fields = new Array();
704
        var formName = form.getAttributeNode("name");
705
706
        oCreditCard = eval('new ' + formName.value + '_creditCard()');
707
708
        for (x in oCreditCard) {
709
            if ((form[oCreditCard[x][0]].type == 'text' ||
710
                 form[oCreditCard[x][0]].type == 'textarea') &&
711
                (form[oCreditCard[x][0]].value.length > 0)  &&
712
                 form[oCreditCard[x][0]].disabled == false) {
713
                if (!luhnCheck(form[oCreditCard[x][0]].value)) {
714
                    if (i == 0) {
715
                        focusField = form[oCreditCard[x][0]];
716
                    }
717
                    fields[i++] = oCreditCard[x][1];
718
                    bValid = false;
719
                }
720
            }
721
        }
722
        if (fields.length > 0) {
723
            focusField.focus();
724
            alert(fields.join('\n'));
725
        }
726
        return bValid;
727
    }
728
729
    /**
730
     * Checks whether a given credit card number has a valid Luhn checksum.
731
     * This allows you to spot most randomly made-up or garbled credit card numbers immediately.
732
     * Reference: http://www.speech.cs.cmu.edu/~sburke/pub/luhn_lib.html
733
     */
734
    function luhnCheck(cardNumber) {
735
        if (isLuhnNum(cardNumber)) {
736
            var no_digit = cardNumber.length;
737
            var oddoeven = no_digit & 1;
738
            var sum = 0;
739
            for (var count = 0; count < no_digit; count++) {
740
                var digit = parseInt(cardNumber.charAt(count));
741
                if (!((count & 1) ^ oddoeven)) {
742
                    digit *= 2;
743
                    if (digit > 9) digit -= 9;
744
                };
745
                sum += digit;
746
            };
747
            if (sum == 0) return false;
748
            if (sum % 10 == 0) return true;
749
        };
750
        return false;
751
    }
752
753
    function isLuhnNum(argvalue) {
754
        argvalue = argvalue.toString();
755
        if (argvalue.length == 0) {
756
            return false;
757
        }
758
        for (var n = 0; n < argvalue.length; n++) {
759
            if ((argvalue.substring(n, n+1) < "0") ||
760
                (argvalue.substring(n,n+1) > "9")) {
761
                return false;
762
            }
763
        }
764
        return true;
765
    }
766
767
768
    /**
769
    * Check to see if fields is in a valid integer range.
770
    * Fields are not checked if they are disabled.
771
    * <p>
772
    * @param form The form validation is taking place on.
773
    */
774
    function validateIntRange(form) {
775
        var isValid = true;
776
        var focusField = null;
777
        var i = 0;
778
        var fields = new Array();
779
        var formName = form.getAttributeNode("name");
780
781
        oRange = eval('new ' + formName.value + '_intRange()');
782
        for (x in oRange) {
783
            var field = form[oRange[x][0]];
784
            if (field.disabled == false)  {
785
                var value = '';
786
                if (field.type == 'hidden' ||
787
                    field.type == 'text' || field.type == 'textarea' ||
788
                    field.type == 'radio' ) {
789
                    value = field.value;
790
                }
791
                if (field.type == 'select-one') {
792
                    var si = field.selectedIndex;
793
                    if (si >= 0) {
794
                        value = field.options[si].value;
795
                    }
796
                }
797
                if (value.length > 0) {
798
                    var iMin = parseInt(oRange[x][2]("min"));
799
                    var iMax = parseInt(oRange[x][2]("max"));
800
                    var iValue = parseInt(value);
801
                    if (!(iValue >= iMin && iValue <= iMax)) {
802
                        if (i == 0) {
803
                            focusField = field;
804
                        }
805
                        fields[i++] = oRange[x][1];
806
                        isValid = false;
807
                    }
808
                }
809
            }
810
        }
811
        if (fields.length > 0) {
812
            focusField.focus();
813
            alert(fields.join('\n'));
814
        }
815
        return isValid;
816
    }
817
818
819
    /**
820
    *  Check to see if fields are a valid short.
821
    * Fields are not checked if they are disabled.
822
    * <p>
823
    * @param form The form validation is taking place on.
824
    */
825
    function validateShort(form) {
826
        var bValid = true;
827
        var focusField = null;
828
        var i = 0;
829
        var fields = new Array();
830
        var formName = form.getAttributeNode("name");
831
832
        oShort = eval('new ' + formName.value + '_ShortValidations()');
833
834
        for (x in oShort) {
835
            var field = form[oShort[x][0]];
836
837
            if ((field.type == 'hidden' ||
838
                field.type == 'text' ||
839
                field.type == 'textarea' ||
840
                field.type == 'select-one' ||
841
                field.type == 'radio')  &&
842
                field.disabled == false) {
843
844
                var value = '';
845
                // get field's value
846
                if (field.type == "select-one") {
847
                    var si = field.selectedIndex;
848
                    if (si >= 0) {
849
                        value = field.options[si].value;
850
                    }
851
                } else {
852
                    value = field.value;
853
                }
854
855
                if (value.length > 0) {
856
                    if (!isAllDigits(value)) {
857
                        bValid = false;
858
                        if (i == 0) {
859
                            focusField = field;
860
                        }
861
                        fields[i++] = oShort[x][1];
862
863
                    } else {
864
865
                        var iValue = parseInt(value);
866
                        if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
867
                            if (i == 0) {
868
                                focusField = field;
869
                            }
870
                            fields[i++] = oShort[x][1];
871
                            bValid = false;
872
                        }
873
                   }
874
               }
875
            }
876
        }
877
        if (fields.length > 0) {
878
           focusField.focus();
879
           alert(fields.join('\n'));
880
        }
881
        return bValid;
882
    }
883
884
885
    /**
886
    * Check to see if fields are a valid float.
887
    * Fields are not checked if they are disabled.
888
    * <p>
889
    * @param form The form validation is taking place on.
890
    */
891
    function validateFloat(form) {
892
        var bValid = true;
893
        var focusField = null;
894
        var i = 0;
895
        var fields = new Array();
896
         var formName = form.getAttributeNode("name");
897
898
        oFloat = eval('new ' + formName.value + '_FloatValidations()');
899
        for (x in oFloat) {
900
            var field = form[oFloat[x][0]];
901
902
            if ((field.type == 'hidden' ||
903
                field.type == 'text' ||
904
                field.type == 'textarea' ||
905
                field.type == 'select-one' ||
906
                field.type == 'radio') &&
907
                field.disabled == false) {
908
909
                var value = '';
910
                // get field's value
911
                if (field.type == "select-one") {
912
                    var si = field.selectedIndex;
913
                    if (si >= 0) {
914
                        value = field.options[si].value;
915
                    }
916
                } else {
917
                    value = field.value;
918
                }
919
920
                if (value.length > 0) {
921
                    // remove '.' before checking digits
922
                    var tempArray = value.split('.');
923
                    //Strip off leading '0'
924
                    var zeroIndex = 0;
925
                    var joinedString= tempArray.join('');
926
                    while (joinedString.charAt(zeroIndex) == '0') {
927
                        zeroIndex++;
928
                    }
929
                    var noZeroString = joinedString.substring(zeroIndex,joinedString.length);
930
931
                    if (!isAllDigits(noZeroString)) {
932
                        bValid = false;
933
                        if (i == 0) {
934
                            focusField = field;
935
                        }
936
                        fields[i++] = oFloat[x][1];
937
938
                    } else {
939
                    var iValue = parseFloat(value);
940
                    if (isNaN(iValue)) {
941
                        if (i == 0) {
942
                            focusField = field;
943
                        }
944
                        fields[i++] = oFloat[x][1];
945
                        bValid = false;
946
                    }
947
                    }
948
                }
949
            }
950
        }
951
        if (fields.length > 0) {
952
           focusField.focus();
953
           alert(fields.join('\n'));
954
        }
955
        return bValid;
956
    }
957
958
959
    /**
960
    * Check to see if fields are a valid email address.
961
    * Fields are not checked if they are disabled.
962
    * <p>
963
    * @param form The form validation is taking place on.
964
    */
965
    function validateEmail(form) {
966
        var bValid = true;
967
        var focusField = null;
968
        var i = 0;
969
        var fields = new Array();
970
        var formName = form.getAttributeNode("name");
971
972
973
        oEmail = eval('new ' + formName.value + '_email()');
974
975
        for (x in oEmail) {
976
            var field = form[oEmail[x][0]];
977
            if ((field.type == 'hidden' ||
978
                 field.type == 'text' ||
979
                 field.type == 'textarea') &&
980
                (field.value.length > 0) &&
981
                field.disabled == false) {
982
                if (!checkEmail(field.value)) {
983
                    if (i == 0) {
984
                        focusField = field;
985
                    }
986
                    fields[i++] = oEmail[x][1];
987
                    bValid = false;
988
                }
989
            }
990
        }
991
        if (fields.length > 0) {
992
            focusField.focus();
993
            alert(fields.join('\n'));
994
        }
995
        return bValid;
996
    }
997
998
    /**
999
     * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
1000
     * http://javascript.internet.com
1001
     */
1002
    function checkEmail(emailStr) {
1003
       if (emailStr.length == 0) {
1004
           return true;
1005
       }
1006
       var emailPat=/^(.+)@(.+)$/;
1007
       var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
1008
       var validChars="\[^\\s" + specialChars + "\]";
1009
       var quotedUser="(\"[^\"]*\")";
1010
       var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
1011
       var atom=validChars + '+';
1012
       var word="(" + atom + "|" + quotedUser + ")";
1013
       var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
1014
       var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
1015
       var matchArray=emailStr.match(emailPat);
1016
       if (matchArray == null) {
1017
           return false;
1018
       }
1019
       var user=matchArray[1];
1020
       var domain=matchArray[2];
1021
       if (user.match(userPat) == null) {
1022
           return false;
1023
       }
1024
       var IPArray = domain.match(ipDomainPat);
1025
       if (IPArray != null) {
1026
           for (var i = 1; i <= 4; i++) {
1027
              if (IPArray[i] > 255) {
1028
                 return false;
1029
              }
1030
           }
1031
           return true;
1032
       }
1033
       var domainArray=domain.match(domainPat);
1034
       if (domainArray == null) {
1035
           return false;
1036
       }
1037
       var atomPat=new RegExp(atom,"g");
1038
       var domArr=domain.match(atomPat);
1039
       var len=domArr.length;
1040
       if ((domArr[domArr.length-1].length < 2) ||
1041
           (domArr[domArr.length-1].length > 3)) {
1042
           return false;
1043
       }
1044
       if (len < 2) {
1045
           return false;
1046
       }
1047
       return true;
1048
    }
1049
1050
1051
    /**
1052
    * Check to see if fields are a valid using a regular expression.
1053
    * Fields are not checked if they are disabled.
1054
    * <p>
1055
    * @param form The form validation is taking place on.
1056
    */
1057
    function validateMask(form) {
1058
        var isValid = true;
1059
        var focusField = null;
1060
        var i = 0;
1061
        var fields = new Array();
1062
        var formName = form.getAttributeNode("name");
1063
1064
        oMasked = eval('new ' + formName.value + '_mask()');
1065
        for (x in oMasked) {
1066
            var field = form[oMasked[x][0]];
1067
1068
            if ((field.type == 'hidden' ||
1069
                field.type == 'text' ||
1070
                 field.type == 'textarea' ||
1071
                 field.type == 'file') &&
1072
                 (field.value.length > 0) &&
1073
                 field.disabled == false) {
1074
1075
                if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
1076
                    if (i == 0) {
1077
                        focusField = field;
1078
                    }
1079
                    fields[i++] = oMasked[x][1];
1080
                    isValid = false;
1081
                }
1082
            }
1083
        }
1084
1085
        if (fields.length > 0) {
1086
           focusField.focus();
1087
           alert(fields.join('\n'));
1088
        }
1089
        return isValid;
1090
    }
1091
1092
    function matchPattern(value, mask) {
1093
       return mask.exec(value);
1094
    }
1095
1096
1097
    /**
1098
    * A field is considered valid if greater than the specified minimum.
1099
    * Fields are not checked if they are disabled.
1100
    * <p>
1101
    * <strong>Caution:</strong> Using <code>validateMinLength</code> on a password field in a
1102
    *  login page gives unnecessary information away to hackers. While it only slightly
1103
    *  weakens security, we suggest using it only when modifying a password.</p>
1104
    * @param form The form validation is taking place on.
1105
    */
1106
    function validateMinLength(form) {
1107
        var isValid = true;
1108
        var focusField = null;
1109
        var i = 0;
1110
        var fields = new Array();
1111
        var formName = form.getAttributeNode("name");
1112
1113
1114
        oMinLength = eval('new ' + formName.value + '_minlength()');
1115
1116
        for (x in oMinLength) {
1117
            var field = form[oMinLength[x][0]];
1118
1119
            if ((field.type == 'hidden' ||
1120
                field.type == 'text' ||
1121
                field.type == 'password' ||
1122
                field.type == 'textarea') &&
1123
                field.disabled == false) {
1124
1125
                var iMin = parseInt(oMinLength[x][2]("minlength"));
1126
                if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
1127
                    if (i == 0) {
1128
                        focusField = field;
1129
                    }
1130
                    fields[i++] = oMinLength[x][1];
1131
                    isValid = false;
1132
                }
1133
            }
1134
        }
1135
        if (fields.length > 0) {
1136
           focusField.focus();
1137
           alert(fields.join('\n'));
1138
        }
1139
        return isValid;
1140
    }
1141
1142
1143
    //End -->
1144
  </script>
1145
1146
  </body>
1147
1148
</html>