New tests, updates
[mono.git] / mcs / class / System.Web / resources / WebUIValidation_2.0.js
index c7cc1bf1fa7859714d130bcfb1d0ff74c3fb4002..085f08d4a248cb4ec5c7927f94636401c6732039 100644 (file)
-/*\r
- * WebUIValidation.js\r
- *\r
- * Authors:\r
- *   Chris Toshok (toshok@ximian.com)\r
- *\r
- * (c) 2005 Novell, Inc. (http://www.novell.com)\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining\r
- * a copy of this software and associated documentation files (the\r
- * "Software"), to deal in the Software without restriction, including\r
- * without limitation the rights to use, copy, modify, merge, publish,\r
- * distribute, sublicense, and/or sell copies of the Software, and to\r
- * permit persons to whom the Software is furnished to do so, subject to\r
- * the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be\r
- * included in all copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-var have_validation_summaries = false;\r
-\r
-function ValidatorOnLoad ()\r
-{\r
-       if (typeof (Page_ValidationSummaries) != 'undefined' && Page_ValidationSummaries != null) {\r
-               have_validation_summaries = true;\r
-           for (var v in Page_ValidationSummaries) {\r
-                   var vs = Page_ValidationSummaries [v];\r
-                   if (vs.getAttribute ("validationgroup") == null)\r
-                           vs.setAttribute ("validationgroup", "");\r
-           }\r
-       }\r
-\r
-       for (var v in Page_Validators) {\r
-               var vo = Page_Validators [v];\r
-               var funcname = vo.getAttribute ("evaluationfunction");\r
-\r
-               func = this[funcname];\r
-\r
-               vo["evaluationfunction"] = func;\r
-\r
-               if (vo.getAttribute ("isvalid") == null)\r
-                       vo.setAttribute ("isvalid", "true");\r
-\r
-               if (vo.getAttribute ("enabled") == null)\r
-                       vo.setAttribute ("enabled", "true");\r
-\r
-               if (vo.getAttribute ("validationgroup") == null)\r
-                       vo.setAttribute ("validationgroup", "");\r
-\r
-               func = vo ["evaluationfunction"];\r
-       }\r
-\r
-       Page_ValidationActive = true;\r
-}\r
-\r
-var validation_result = true;\r
-\r
-function ValidationSummaryOnSubmit (group)\r
-{\r
-       /* handle validation summaries here */\r
-       if (validation_result == false && have_validation_summaries) {\r
-\r
-               for (var vi in Page_ValidationSummaries)  {\r
-                       var vs = Page_ValidationSummaries[vi];\r
-                   \r
-                   if(IsValidationGroupMatch(vs, group)) {\r
-\r
-                           var header = vs.getAttribute ("headertext");\r
-                           if (header == null)\r
-                                   header = "";\r
-\r
-                           attr = vs.getAttribute ("showsummary");\r
-                           if (attr == null || attr.toLowerCase() == "true") {\r
-                                   var displaymode = vs.getAttribute ("displaymode");\r
-                                   if (displaymode == null) displaymode = "Bulleted";\r
-\r
-                                   var html = "";\r
-\r
-                                   if (displaymode == "List") {\r
-                                           list_pre = "";\r
-                                           list_post = "";\r
-                                           item_pre = "";\r
-                                           item_post = "<br>";\r
-                                   }\r
-                                   else if (displaymode == "SingleParagraph") {\r
-                                           list_pre = "";\r
-                                           list_post = "<br>";\r
-                                           item_pre = "";\r
-                                           item_post = " ";\r
-                                   }\r
-                                   else {\r
-                                           list_pre = "<ul>";\r
-                                           list_post = "</ul>";\r
-                                           item_pre = "\n<li>";\r
-                                           item_post = "</li>";\r
-                                   }\r
-\r
-                                   html += header;\r
-                                   html += list_pre;\r
-                                   for (var v in Page_Validators) {\r
-                                           var vo = Page_Validators [v];\r
-\r
-                                           if (vo.getAttribute ("isvalid").toLowerCase() == "false") {\r
-                                                   var text = ValidatorGetErrorMessage (vo);\r
-                                                   if (text != null && text != "") {\r
-                                                           html += item_pre + text + item_post;\r
-                                                   }\r
-                                           }\r
-                                   }\r
-                                   html += list_post;\r
-\r
-                                   vs.innerHTML = html;\r
-                                   vs.style.display = "block";\r
-                           }\r
-\r
-                           attr = vs.getAttribute ("showmessagebox");\r
-                           if (attr != null && attr.toLowerCase() == "true") {\r
-                                   var v_contents = "";\r
-\r
-                                   for (var v in Page_Validators) {\r
-                                           var vo = Page_Validators [v];\r
-\r
-                                           if (vo.getAttribute ("isvalid").toLowerCase() == "false") {\r
-                                                   var text = ValidatorGetErrorMessage (vo);\r
-                                                   if (text != null && text != "") {\r
-                                                           v_contents += "-" + text + "\n";\r
-                                                   }\r
-                                           }\r
-                                   }\r
-\r
-                                   var alert_header = header;\r
-                                   if (alert_header != "")\r
-                                           alert_header += "\n";\r
-                                   summary_contents = alert_header + v_contents;\r
-                                   alert (summary_contents);\r
-                           }\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-function ValidatorCommonOnSubmit ()\r
-{\r
-       rv = validation_result;\r
-       validation_result = true;\r
-       return rv;\r
-}\r
-\r
-function ValidatorGetValue (controlname)\r
-{\r
-       var el = GetElement (controlname);\r
-\r
-       /* if the element has a 'value' attribute, return it */\r
-       if (typeof (el.value) != 'undefined' && el.value != null) {\r
-               return el.value;\r
-       }\r
-\r
-       /* if it's a select, loop over the options looking for the\r
-        * selected one. */\r
-       if (typeof (el.selectedIndex) != 'undefined') {\r
-               return el.options[el.selectedIndex].value;\r
-       }\r
-}\r
-\r
-function ValidatorTrim (s)\r
-{\r
-       s = s.replace (/^\s+/g, "");\r
-       s = s.replace (/\s+$/g, "");\r
-\r
-       return s;\r
-}\r
-\r
-function Page_ClientValidate(group)\r
-{\r
-       validation_result = true;\r
-\r
-       /* clear out the existing text from all our summaries */\r
-       if (have_validation_summaries) {\r
-               for (var vi in Page_ValidationSummaries) {\r
-                       var vs = Page_ValidationSummaries[vi];\r
-                       vs.style.display = "none";\r
-                       vs.innerHTML = "";\r
-               }\r
-       }\r
-\r
-       for (var v in Page_Validators) {\r
-               var vo = Page_Validators [v];\r
-               var evalfunc = vo["evaluationfunction"];\r
-               var result = false;\r
-\r
-               if (vo.getAttribute ("enabled").toLowerCase() == "false" || !IsValidationGroupMatch(vo, group)) {\r
-                       result = true;\r
-                       ValidatorSucceeded (vo);\r
-               }\r
-               else {\r
-                       result = evalfunc (vo);\r
-               }\r
-\r
-               if (!result)\r
-                       validation_result = false;\r
-\r
-               vo.setAttribute("isvalid", result ? "true" : "false");\r
-       }\r
-    ValidationSummaryOnSubmit(group);\r
-       return validation_result;\r
-}\r
-\r
-function IsValidationGroupMatch(vo, group) {\r
-    var valGroup = vo.getAttribute ("validationgroup");\r
-    if ((typeof(group) == "undefined") || (group == null)) {\r
-        return (valGroup == "");\r
-    }\r
-    return (valGroup == group);\r
-}\r
-\r
-/*******************/\r
-/* type converters */\r
-\r
-function ToInteger (s)\r
-{\r
-       if ((v = parseInt(s, 10)) != s - 0)\r
-               return null;\r
-       else\r
-               return v;\r
-}\r
-\r
-function ToString (s)\r
-{\r
-       return s;\r
-}\r
-\r
-function ToDouble (s)\r
-{\r
-       if ((v = parseFloat(s)) != s - 0)\r
-               return null;\r
-       else\r
-               return v;\r
-}\r
-\r
-function ToDate (s)\r
-{\r
-       /* NYI */\r
-       return null;\r
-}\r
-\r
-function ToCurrency (s)\r
-{\r
-       /* NYI */\r
-       return null;\r
-}\r
-\r
-/*******************/\r
-/* validators    */\r
-\r
-function CompareValidatorEvaluateIsValid (validator)\r
-{\r
-       var ControlToCompare = validator.getAttribute ("controltocompare");\r
-       var ValueToCompare = validator.getAttribute ("valuetocompare");\r
-       var Operator = validator.getAttribute ("operator").toLowerCase();\r
-       var ControlToValidate = validator.getAttribute ("controltovalidate");\r
-       var DataType = validator.getAttribute ("datatype");\r
-\r
-       var ctrl_value = ValidatorTrim (ValidatorGetValue (ControlToValidate));\r
-       var compare = (ControlToCompare != null && ControlToCompare != "") ? ValidatorTrim (ValidatorGetValue (ControlToCompare)) : ValueToCompare;\r
-\r
-       var left = Convert (ctrl_value, DataType);\r
-       if (left == null) {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-      \r
-       var right = Convert (compare, DataType);\r
-       if (right == null) {\r
-               ValidatorSucceeded (validator);\r
-                return true;\r
-       }\r
-\r
-       var result = false;\r
-   \r
-       if (Operator == "equal") {\r
-               result = (left == right);\r
-       }\r
-       else if (Operator == "notequal") {\r
-               result = (left != right);\r
-       }\r
-       else if (Operator == "lessthan") {\r
-               result = (left < right);\r
-       }\r
-       else if (Operator == "lessthanequal") {\r
-               result = (left <= right);\r
-       }\r
-       else if (Operator == "greaterthan") {\r
-               result = (left > right);\r
-       }\r
-       else if (Operator == "greaterthanequal") {\r
-               result = (left >= right);\r
-       }\r
-\r
-       if (result == false) {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-       else {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-}\r
-\r
-function RangeValidatorEvaluateIsValid (validator)\r
-{\r
-       var MinimumValue = parseInt (validator.getAttribute ("minimumvalue"));\r
-       var MaximumValue = parseInt (validator.getAttribute ("maximumvalue"));\r
-       var ControlToValidate = validator.getAttribute ("controltovalidate");\r
-       var DataType = validator.getAttribute ("datatype");\r
-\r
-       var ctrl_value = ValidatorTrim (ValidatorGetValue (ControlToValidate));\r
-\r
-       if (ctrl_value == "") {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-\r
-       var val = Convert (ctrl_value, DataType);\r
-       if (val == null || val < MinimumValue || val > MaximumValue) {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-       else {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-}\r
-\r
-function RegularExpressionValidatorEvaluateIsValid (validator)\r
-{\r
-       var ValidationExpression = validator.getAttribute ("validationexpression");\r
-       var ControlToValidate = validator.getAttribute ("controltovalidate");\r
-\r
-       var ctrl_value = ValidatorTrim (ValidatorGetValue (ControlToValidate));\r
-\r
-       if (ctrl_value == "") {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-\r
-       var r = new RegExp (ValidationExpression);\r
-       match = r.exec (ctrl_value);\r
-       if (match == null || match[0] == "") {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-       else {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-}\r
-\r
-function RequiredFieldValidatorEvaluateIsValid (validator)\r
-{\r
-       var InitialValue = validator.getAttribute ("initialvalue");\r
-       var ControlToValidate = validator.getAttribute ("controltovalidate");\r
-\r
-       var ctrl_value = ValidatorTrim (ValidatorGetValue (ControlToValidate));\r
-\r
-       if (ctrl_value == ValidatorTrim (InitialValue)) {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-       else {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-}\r
-\r
-function CustomValidatorEvaluateIsValid (validator)\r
-{\r
-       var InitialValue = validator.getAttribute ("initialvalue");\r
-       var ControlToValidate = validator.getAttribute ("controltovalidate");\r
-\r
-       if (!ControlToValidate) {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-\r
-       var evaluationfunc = validator.getAttribute ("clientvalidationfunction");\r
-\r
-       var ctrl_value = ValidatorTrim (ValidatorGetValue (ControlToValidate));\r
-\r
-       var result = true;\r
-\r
-       if (evaluationfunc && evaluationfunc != "") {\r
-               args = {Value:ctrl_value, IsValid:false};\r
-               eval (evaluationfunc + "(validator, args)");\r
-               result = args.IsValid;\r
-       }\r
-\r
-       if (result) {\r
-               ValidatorSucceeded (validator);\r
-               return true;\r
-       }\r
-       else {\r
-               ValidatorFailed (validator);\r
-               return false;\r
-       }\r
-}\r
-\r
-/*********************/\r
-/* utility functions */\r
-\r
-function Convert (s, ty)\r
-{\r
-       var cvt = this ["To" + ty];\r
-       if (typeof (cvt) == 'function')\r
-               return cvt (s);\r
-       else\r
-               return null;\r
-}\r
-\r
-function ValidatorUpdateDisplay (v, valid)\r
-{\r
-       var display = v.getAttribute ("display");\r
-\r
-       /* for validators that aren't displayed, do nothing */\r
-       if (display == "None") {\r
-               return;\r
-       }\r
-\r
-       v.style.visibility = (valid ? "hidden" : "visible");\r
-       if (display == "Dynamic") {\r
-               v.style.display = (valid ? "none" : "inline");\r
-       }\r
-}\r
-\r
-function ValidatorGetErrorMessage (v)\r
-{\r
-       var text = v.getAttribute ("errormessage");\r
-       if (text == null || text == "")\r
-               text = v.getAttribute ("text"); \r
-       if (text == null)\r
-               text = "";\r
-       return text;\r
-}\r
-\r
-function ValidatorGetText (v)\r
-{\r
-       var text = v.getAttribute ("text");     \r
-       if (text == null || text == "")\r
-               text = v.getAttribute ("errormessage");\r
-       if (text == null)\r
-               text = "";\r
-       return text;\r
-}\r
-\r
-function ValidatorFailed (v)\r
-{\r
-       var text = ValidatorGetText (v);\r
-       v.innerHTML = text;\r
-\r
-       ValidatorUpdateDisplay (v, false);\r
-}\r
-\r
-function ValidatorSucceeded (v)\r
-{\r
-       v.innerHTML = "";\r
-\r
-       ValidatorUpdateDisplay (v, true);\r
-}\r
-\r
-function GetElement(id)\r
-{\r
-       var x = document.getElementById ? document.getElementById (id) :\r
-                                         ((document.all) ? document.all [id] : null);\r
-       return x;\r
-}\r
+/*
+ * WebUIValidation.js
+ *
+ * Authors:
+ *   Chris Toshok (toshok@ximian.com)
+ *
+ * (c) 2005 Novell, Inc. (http://www.novell.com)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+function WebFormValidation_Initialize(webForm) {
+
+webForm.have_validation_summaries = false;
+
+webForm.HaveRegexp = function ()
+{
+  if (window.RegExp)
+    return true;
+  return false;
+}
+
+webForm.ValidatorOnLoad = function  ()
+{
+       if (typeof (webForm.Page_ValidationSummaries) != 'undefined' && webForm.Page_ValidationSummaries != null) {
+               webForm.have_validation_summaries = true;
+       }
+
+       for (var v = 0; v < webForm.Page_Validators.length; v++) {
+               var vo = webForm.Page_Validators [v];
+
+               if (typeof(vo.isvalid) == "string" && vo.isvalid == "False")
+                       vo._isvalid = false;
+               else
+                       vo._isvalid = true;
+
+               if (typeof(vo.enabled) == "string" && vo.enabled == "False")
+                       vo._enabled = false;
+               else
+                       vo._enabled = true;
+                       
+               if (typeof(vo.evaluationfunction) == "string")
+                       vo.evaluationfunction = webForm [vo.evaluationfunction];
+       }
+
+       webForm.Page_ValidationActive = true;
+}
+
+webForm.validation_result = true;
+
+webForm.ValidationSummaryOnSubmit = function (group)
+{
+       /* handle validation summaries here */
+       if (webForm.validation_result == false && webForm.have_validation_summaries) {
+
+         for (var vi = 0; vi < webForm.Page_ValidationSummaries.length; vi++) {
+                       var vs = webForm.Page_ValidationSummaries[vi];
+                   
+                   if(webForm.IsValidationGroupMatch(vs, group)) {
+
+                           var header = "";
+                           if(typeof(vs.headertext)=="string")
+                                   header = vs.headertext;
+
+                           if (vs.showsummary != "False") {
+                                       if (typeof(vs.displaymode) != "string")
+                                               vs.displaymode = "BulletList";
+
+                                   var html = "";
+
+                                   if (vs.displaymode == "List") {
+                                           list_pre = "";
+                                           list_post = "";
+                                           item_pre = "";
+                                           item_post = "<br>";
+                                   }
+                                   else if (vs.displaymode == "SingleParagraph") {
+                                           list_pre = "";
+                                           list_post = "<br>";
+                                           item_pre = "";
+                                           item_post = " ";
+                                   }
+                                   else {
+                                           list_pre = "<ul>";
+                                           list_post = "</ul>";
+                                           item_pre = "\n<li>";
+                                           item_post = "</li>";
+                                   }
+
+                                   html += header;
+                                   html += list_pre;
+                                               for (var v = 0; v < webForm.Page_Validators.length; v++) {
+                                     var vo = webForm.Page_Validators [v];
+
+                                           if (!vo._isvalid) {
+                                                   var text = vo.errormessage;
+                                                   if (text != null && text != "") {
+                                                           html += item_pre + text + item_post;
+                                                   }
+                                           }
+                                   }
+                                   html += list_post;
+
+                                   vs.innerHTML = html;
+                                   vs.style.display = "block";
+                           }
+
+                           if (vs.showmessagebox == "True") {
+                                   var v_contents = "";
+
+                                               for (var v = 0; v < webForm.Page_Validators.length; v++) {
+                                     var vo = webForm.Page_Validators [v];
+
+                                           if (!vo._isvalid) {
+                                                   var text = vo.errormessage;
+                                                   if (text != null && text != "") {
+                                                           v_contents += "-" + text + "\n";
+                                                   }
+                                           }
+                                   }
+
+                                   var alert_header = header;
+                                   if (alert_header != "")
+                                           alert_header += "\n";
+                                   summary_contents = alert_header + v_contents;
+                                   alert (summary_contents);
+                           }
+                       }
+               }
+       }
+}
+
+webForm.ValidatorCommonOnSubmit = function ()
+{
+       var rv = webForm.validation_result;
+       webForm.validation_result = true;
+       return rv;
+}
+
+webForm.ValidatorGetValue = function (controlname)
+{
+       var el = webForm.GetElement (controlname);
+
+       /* if the element has a 'value' attribute, return it */
+       if (typeof (el.value) != 'undefined' && el.value != null) {
+               return el.value;
+       }
+
+       /* if it's a select, loop over the options looking for the
+        * selected one. */
+       if (typeof (el.selectedIndex) != 'undefined') {
+               return el.options[el.selectedIndex].value;
+       }
+
+       return webForm.ValidatorGetValueRecursive(el);
+}
+
+webForm.ValidatorGetValueRecursive = function (el)
+{
+       if (typeof(el.value) == "string") {
+               if (el.type != "radio" || el.checked == true) return el.value;
+       }
+       for (var i = 0; i<el.childNodes.length; i++) {
+               var val = webForm.ValidatorGetValueRecursive(el.childNodes[i]);
+               if (val != "") return val;
+       }
+       return "";
+}
+
+webForm.ValidatorTrim = function (s)
+{
+       s = s.replace (/^\s+/g, "");
+       s = s.replace (/\s+$/g, "");
+
+       return s;
+}
+
+webForm.Page_ClientValidate = function (group)
+{
+       webForm.validation_result = true;
+
+       /* clear out the existing text from all our summaries */
+       if (webForm.have_validation_summaries) {
+         for (var vi = 0; vi < webForm.Page_ValidationSummaries.length; vi++) {
+                       var vs = webForm.Page_ValidationSummaries[vi];
+                       vs.style.display = "none";
+                       vs.innerHTML = "";
+               }
+       }
+       
+       var invalidControlHasBeenFocused = false;
+       for (var v = 0; v < webForm.Page_Validators.length; v++) {
+               var vo = webForm.Page_Validators [v];
+               var evalfunc = vo.evaluationfunction;
+               var result = false;
+
+               if (!vo._enabled || !webForm.IsValidationGroupMatch(vo, group)) {
+                       result = true;
+                       webForm.ValidatorSucceeded (vo);
+               }
+               else {
+                       result = evalfunc.call (this, vo);
+               }
+
+               if (!result) {
+                       webForm.validation_result = false;
+                       if (!invalidControlHasBeenFocused && typeof(vo.focusOnError) == "string" && vo.focusOnError == "t") {
+                               invalidControlHasBeenFocused = webForm.ValidatorSetFocus(vo);
+                       }
+               }
+               
+               vo._isvalid = result;
+       }
+    webForm.ValidationSummaryOnSubmit(group);
+       return webForm.validation_result;
+}
+
+webForm.IsValidationGroupMatch = function (vo, group) {
+    var valGroup = "";
+    if (typeof(vo.validationGroup) == "string")
+               valGroup = vo.validationGroup;
+    if ((typeof(group) == "undefined") || (group == null)) {
+        return (valGroup == "");
+    }
+    return (valGroup == group);
+}
+
+webForm.ValidatorSetFocus = function (val) {
+    var ctrl = webForm.GetElement(val.controltovalidate);
+       if ((typeof(ctrl) != "undefined") && (ctrl != null) &&
+               ((ctrl.tagName.toLowerCase() != "input") || (ctrl.type.toLowerCase() != "hidden")) &&
+               (typeof(ctrl.disabled) == "undefined" || ctrl.disabled == null || ctrl.disabled == false) &&
+               (typeof(ctrl.visible) == "undefined" || ctrl.visible == null || ctrl.visible != false) &&
+               (webForm.IsInVisibleContainer(ctrl))) {
+               if (ctrl.tagName.toLowerCase() == "table") {
+                       var inputElements = ctrl.getElementsByTagName("input");
+                       var lastInputElement  = inputElements[inputElements.length -1];
+                       if (lastInputElement != null) {
+                               ctrl = lastInputElement;
+                       }
+               }
+               if (typeof(ctrl.focus) != "undefined" && ctrl.focus != null) {
+                       ctrl.focus();
+                       return true;
+               }
+    }
+    return false;
+}
+
+webForm.IsInVisibleContainer = function (ctrl) {
+       if (typeof(ctrl.style) != "undefined" && 
+               ((typeof(ctrl.style.display) != "undefined" &&  ctrl.style.display == "none") ||
+               (typeof(ctrl.style.visibility) != "undefined" && ctrl.style.visibility == "hidden"))) {
+               return false;
+       }
+       else if (typeof(ctrl.parentNode) != "undefined" && ctrl.parentNode != null && ctrl.parentNode != ctrl) {
+               return webForm.IsInVisibleContainer(ctrl.parentNode);
+       }
+       return true;
+}
+
+/*******************/
+/* type converters */
+
+webForm.ToInteger = function  (s, validator)
+{
+       if (s.match(/^\s*[-\+]?\d+\s*$/) == null)
+               return null;
+       var v = parseInt(s, 10);
+       return (isNaN(v) ? null : v);
+}
+
+webForm.ToString = function (s, validator)
+{
+       return s;
+}
+
+webForm.ToDouble = function (s, validator)
+{
+       if ((v = parseFloat(s)) != s - 0)
+               return null;
+       else
+               return v;
+}
+
+webForm.ToDate = function (s, validator)
+{
+    if (!webForm.HaveRegexp ())
+        return null;
+    var m, day, month, year;
+    var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\s*$");
+    m = s.match(yearFirstExp);
+    if (m != null && (m[2].length == 4 || validator.dateorder == "ymd")) {
+        day = m[6];
+        month = m[5];
+        year = (m[2].length == 4) ? m[2] : webForm.GetFullYear(parseInt(m[3], 10), validator.cutoffyear)
+    }
+    else {
+        if (validator.dateorder == "ymd") return null;
+        var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
+        m = s.match(yearLastExp);
+        if (m == null) return null;
+        if (validator.dateorder == "mdy") {
+            day = m[3];
+            month = m[1];
+        }
+        else {
+            day = m[1];
+            month = m[3];
+        }
+        year = (m[5].length == 4) ? m[5] : webForm.GetFullYear(parseInt(m[6], 10), validator.cutoffyear)
+    }
+    month -= 1;
+    var date = new Date(year, month, day);
+    return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
+}
+
+webForm.ToCurrency = function (s, validator)
+{
+  if (!webForm.HaveRegexp ())
+    return null;
+  
+       var hasDigits = (validator.digits > 0);
+       var beginGroupSize, subsequentGroupSize;
+       var groupSizeNum = parseInt(validator.groupsize, 10);
+       if (!isNaN(groupSizeNum) && groupSizeNum > 0) {
+               beginGroupSize = "{1," + groupSizeNum + "}";
+               subsequentGroupSize = "{" + groupSizeNum + "}";
+       }
+       else {
+               beginGroupSize = subsequentGroupSize = "+";
+       }
+       var exp = new RegExp("^\\s*([-\\+])?((\\d" + beginGroupSize + "(\\" + validator.groupchar + "\\d" + subsequentGroupSize + ")+)|\\d*)"
+                                       + (hasDigits ? "\\" + validator.decimalchar + "?(\\d{0," + validator.digits + "})" : "")
+                                       + "\\s*$");
+       var m = s.match(exp);
+       if (m == null)
+               return null;
+       if (m[2].length == 0 && hasDigits && m[5].length == 0)
+               return null;
+       var cleanInput = (m[1] != null ? m[1] : "") + m[2].replace(new RegExp("(\\" + validator.groupchar + ")", "g"), "") + ((hasDigits && m[5].length > 0) ? "." + m[5] : "");
+       var num = parseFloat(cleanInput);
+       return (isNaN(num) ? null : num);
+}
+
+webForm.GetFullYear = function (year, maxYear)
+{
+    var twoDigitMaxYear = maxYear % 100;
+    var centure = maxYear - twoDigitMaxYear;
+    return ((year > twoDigitMaxYear) ? (centure - 100 + year) : (centure + year));
+}
+
+/*******************/
+/* validators    */
+
+webForm.CompareValidatorEvaluateIsValid = function (validator)
+{
+       var Operator = validator.operator.toLowerCase();
+       var ControlToValidate = validator.controltovalidate;
+       var DataType = validator.type;
+
+       var ctrl_value = webForm.ValidatorGetValue (ControlToValidate);
+       if (webForm.ValidatorTrim (ctrl_value) == "") {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+       
+       var left = webForm.Convert (ctrl_value, DataType, validator);
+       if (left == null) {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+       
+       if (Operator == "datatypecheck") {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+      
+       var compare = "";
+       if (typeof(validator.controltocompare) == "string" && document.getElementById(validator.controltocompare))
+               compare = webForm.ValidatorGetValue(validator.controltocompare);
+       else if (typeof(validator.valuetocompare) == "string")
+               compare = validator.valuetocompare;
+
+       var right = compare != null ? webForm.Convert (compare, DataType, validator) : null;
+       if (right == null) {
+               webForm.ValidatorSucceeded (validator);
+                return true;
+       }
+
+       var result = false;
+   
+       if (Operator == "equal") {
+               result = (left == right);
+       }
+       else if (Operator == "notequal") {
+               result = (left != right);
+       }
+       else if (Operator == "lessthan") {
+               result = (left < right);
+       }
+       else if (Operator == "lessthanequal") {
+               result = (left <= right);
+       }
+       else if (Operator == "greaterthan") {
+               result = (left > right);
+       }
+       else if (Operator == "greaterthanequal") {
+               result = (left >= right);
+       }
+
+       if (result == false) {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+       else {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+}
+
+webForm.RangeValidatorEvaluateIsValid = function (validator)
+{
+       var ControlToValidate = validator.controltovalidate;
+       var DataType = validator.type;
+
+       var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
+
+       if (ctrl_value == "") {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+
+       var MinimumValue = webForm.Convert (validator.minimumvalue, DataType, validator);
+       var MaximumValue = webForm.Convert (validator.maximumvalue, DataType, validator);
+       var val = webForm.Convert (ctrl_value, DataType, validator);
+       if (val == null || val < MinimumValue || val > MaximumValue) {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+       else {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+}
+
+webForm.RegularExpressionValidatorEvaluateIsValid = function (validator)
+{
+       var ValidationExpression = validator.validationexpression;
+       var ControlToValidate = validator.controltovalidate;
+
+       var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
+
+       if (ctrl_value == "") {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+
+  if (!webForm.HaveRegexp ())
+    return false;
+  
+       var r = new RegExp (ValidationExpression);
+       match = r.exec (ctrl_value);
+       if (match == null || match[0] != ctrl_value) {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+       else {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+}
+
+webForm.RequiredFieldValidatorEvaluateIsValid = function (validator)
+{
+       var InitialValue = validator.initialvalue;
+       var ControlToValidate = validator.controltovalidate;
+
+       var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
+
+       if (ctrl_value == webForm.ValidatorTrim (InitialValue)) {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+       else {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+}
+
+webForm.CustomValidatorEvaluateIsValid = function (validator)
+{
+       var ControlToValidate = validator.controltovalidate;
+       var evaluationfunc = validator.clientvalidationfunction;
+       var ctrl_value;
+
+       if (ControlToValidate) {
+           ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
+
+           if ((ctrl_value.length == 0) && ((typeof(validator.validateemptytext) != "string") || (validator.validateemptytext != "true"))) {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+           }
+       } else
+           ctrl_value = "";
+       var result = true;
+
+       if (evaluationfunc && evaluationfunc != "") {
+               args = {Value:ctrl_value, IsValid:true};
+               eval (evaluationfunc + "(validator, args)");
+               result = args.IsValid;
+       }
+
+       if (result) {
+               webForm.ValidatorSucceeded (validator);
+               return true;
+       }
+       else {
+               webForm.ValidatorFailed (validator);
+               return false;
+       }
+}
+
+/*********************/
+/* utility functions */
+
+webForm.Convert = function (s, ty, validator)
+{
+       var cvt = this ["To" + ty];
+       if (typeof (cvt) == 'function')
+               return cvt.call (this, s, validator);
+       else
+               return null;
+}
+
+webForm.ValidatorUpdateDisplay = function (v, valid)
+{
+       var display = v.display;
+
+       /* for validators that aren't displayed, do nothing */
+       if (display == "None") {
+               return;
+       }
+
+       v.style.visibility = (valid ? "hidden" : "visible");
+       if (display == "Dynamic") {
+               v.style.display = (valid ? "none" : "inline");
+       }
+}
+
+webForm.ValidatorFailed = function  (v)
+{
+       webForm.ValidatorUpdateDisplay (v, false);
+}
+
+webForm.ValidatorSucceeded = function  (v)
+{
+       webForm.ValidatorUpdateDisplay (v, true);
+}
+
+webForm.GetElement = function (id)
+{
+       var x = document.getElementById ? document.getElementById (id) :
+                                         ((document.all) ? document.all [id] : null);
+       return x;
+}
+
+
+}