Initial add of defaria.com
[clearscm.git] / defaria.com / cvsadm / CVSAdmUtils.js
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File:        CVSAdmUtils.js
4 // Description: JavaScript routines for CVSAdm
5 // Author:      Andrew@DeFaria.com
6 // Created:     Wed May 12 13:47:39 PDT 2004
7 // Modified:
8 // Language:    JavaScript
9 //
10 // (c) Copyright 2005, Andrew@DeFaria.com, all rights reserved.
11 // 
12 ////////////////////////////////////////////////////////////////////////////////
13 function trim_trailing_spaces (str) {
14   // Strip trailing spaces
15   while (str.value.substr (str.value.length - 1) == " ") {
16     str.value = str.value.substr (0, (str.value.length - 1));
17   } // while
18
19   return str;
20 } // trim_trailing_spaces
21
22 function valid_email_address (email) {
23   var email_regex = /.+@.+\..+/;
24
25   return email_regex.test (email.value);
26 } // valid_email_address
27
28 function validate_login (login) {
29   with (login) {
30     userid = trim_trailing_spaces (userid);
31
32     if (userid.value == "") {
33       alert ("You must specify your Username!");
34       userid.focus ();
35       return false;
36     } // if
37   } // with
38
39   return true;
40 } // validate_login
41
42 function validate_group (group) {
43   with (group) {
44     group = trim_trailing_spaces (group);
45
46     if (group.value == "") {
47       alert ("You must specify a group!");
48       group.focus ();
49       return false;
50     } // if
51   } // with
52
53   return true;
54 } // validate_group
55
56 function validate_sysuser (sysuser) {
57   with (sysuser) {
58     sysuser = trim_trailing_spaces (sysuser);
59
60     if (sysuser.value == "") {
61       alert ("You must specify a sysuser!");
62       sysuser.focus ();
63       return false;
64     } // if
65   } // with
66
67   return true;
68 } // validate_sysuser
69
70 function validate_user (user) {
71   with (user) {
72     if (typeof username != "undefined") {
73       if (username.value == "") {
74         alert ("You must specify a Username");
75         username.focus ();
76         return false;
77       } // if
78     } // if
79
80     var password_msg = 
81       "To change your password specify both your old and new passwords then\n" +
82       "repeat your new password in the fields provided.\n\n" +
83       "To leave your password unchanged leave old, new and repeated\n" +
84       "password fields blank.";
85
86     if (typeof old_password != "undefined") {
87       if (old_password.value != "") {
88         if (new_password.value == "") {
89           alert (password_msg);
90           new_password.focus ();
91           return false;
92         } else {
93           if (new_password.value.length < 6) {
94             alert ("Passwords must be greater than 6 characters.");
95             new_password.focus ();
96             return false;
97           } // if
98         } // if
99         if (repeated_password.value == "") {
100           alert (password_msg);
101           repeated_password.focus ();
102           return false;
103         } else {
104           if (repeated_password.value.length < 6) {
105             alert ("Passwords must be greater than 6 characters.");
106             repeated_password.focus ();
107             return false;
108           } // if
109         } // if
110         if (new_password.value != repeated_password.value) {
111           alert ("Sorry but the new password and repeated password are not the same!");
112           new_password.focus ();
113           return false;
114         } // if
115       } else {
116         if (new_password.value != "") {
117           alert (password_msg);
118           new_password.focus ();
119           return false;
120         } // if
121         if (repeated_password.value != "") {
122           alert (password_msg);
123           repeated_password.focus ();
124           return false;
125         } // if
126       } // if
127     } // if
128
129     fullname = trim_trailing_spaces (fullname);
130     if (fullname.value == "") {
131       alert ("Full name is required!");
132       fullname.focus ();
133       return false;
134     } // if
135
136     email = trim_trailing_spaces (email);
137     if (email.value == "") {
138       alert ("We need your email address - in case you forget your password\nand we need to send it to you.");
139       email.focus ();
140       return false;
141     } else {
142       if (!valid_email_address (email)) {
143         alert ("That email address is invalid!\nMust be <username>@<domainname>\nFor example: Andrew@DeFaria.com.");
144         return false;
145       } // if
146     } // if
147   } // with
148
149   return true;
150 } // validate_user
151
152 function AreYouSure (message) {
153   return window.confirm (message);
154 } // AreYouSure