
function validateMaxTextAreaLength(source, arguments) {
   if (arguments.Value.length <= source.attributes("MaxLength").value)
      arguments.IsValid = true;
   else
      arguments.IsValid = false;
}
function isWhitespace(s) {
   var re = /^\s+$/;
   return (re.test(s) || (s == "")) ? true : false;
}

/************* -- Page IsDirty Validation -- *******************/
// Allows determination of modified form values.
var dirtyValidationModuleList = new Array();
var doNotCauseDirtyValidationId;
var dirtyValidationMessage = "You have unsaved changes.";
var isDirtyModuleId
function confirmDirtyNavigation() {
   if (doNotCauseDirtyValidationId == null) {
      doNotCauseDirtyValidationId = document.activeElement.getAttribute("doNotCauseDirtyValidationId")

      if ((document.activeElement.type == "radio" || document.activeElement.type == "checkbox") &&
        (doNotCauseDirtyValidationId == null)) {
         doNotCauseDirtyValidationId = document.activeElement.parentElement.getAttribute("doNotCauseDirtyValidationId")

         if (doNotCauseDirtyValidationId == null) {
            doNotCauseDirtyValidationId = document.activeElement.parentElement.offsetParent.getAttribute("doNotCauseDirtyValidationId")
         }
      }
   }
   if (pageIsDirty()) {
      return dirtyValidationMessage;
   }
}
function registerDirtyValidationModule(moduleId) {
   dirtyValidationModuleList[dirtyValidationModuleList.length] = moduleId;
}
function cancelDirtyValidation(moduleId) {
   doNotCauseDirtyValidationId = moduleId;
}
function forceIsDirty(moduleId) {
   isDirtyModuleId = moduleId
}
function pageIsDirty() {
   if (doNotCauseDirtyValidationId == 0) { return false; }

   //If not validating one module then another one must be dirty so change the message
   if (doNotCauseDirtyValidationId != null) {
      dirtyValidationMessage = "You have other unsaved changes on the page."
   }

   if (dirtyValidationModuleList.length > 0) {
      var itemIndex
      var moduleId
      for (itemIndex in dirtyValidationModuleList) {
         moduleId = dirtyValidationModuleList[itemIndex]
         if (moduleId != doNotCauseDirtyValidationId) {
            if (isDirtyModuleId == moduleId) {
               return true;
            }
            else if (objectIsDirty(moduleId)) {
               return true;
            }
         }
      }
      return false;
   }
   else {
      return false;
   }
}
function checkIgnoreDirty(sourceObject, stopObjectId) {
   while (sourceObject.id != stopObjectId) {
      if (sourceObject.getAttribute("IgnoreIsDirtyValidation") != null) { return true; }

      sourceObject = sourceObject.parentElement;
   }
   return false;
}
function objectIsDirty(objectId) {
   var bIsDirty = false;
   var ctl;
   var tagName;
   var inputName;
   var oParent = document.getElementById(objectId);

   for (i = 0; i < oParent.all.length; i++) {
      ctl = oParent.all[i]
      tagName = ctl.tagName

      if (tagName == "INPUT" || tagName == "SELECT" || tagName == "TEXTAREA") {
         //Check for ignoreDirtyValidation attribute on individual element.
         if (checkIgnoreDirty(ctl, objectId) == false) {

            if ((ctl.getAttribute("isDirty") != null) && (ctl.getAttribute("isDirty") == "true")) {
               bIsDirty = true;
               break;
            }
            else {
               if (tagName == "INPUT") {
                  if (((ctl.type == "checkbox") || (ctl.type == "radio")) && ctl.checked != ctl.defaultChecked) {
                     bIsDirty = true;
                     break;
                  }
                  else if (ctl.type == "text" && ctl.value != ctl.defaultValue) {
                     bIsDirty = true;
                     break;
                  }
               }
               else if (tagName == "SELECT") {
                  for (j = 0; j < ctl.options.length; j++) {
                     if (ctl.options[j].defaultSelected) {
                        if (ctl.options[j].value != ctl.value) {
                           bIsDirty = true;
                           break;
                        }
                     }
                  }
               }
               else if (tagName == "TEXTAREA") {
                  if (ctl.value != ctl.defaultValue) {
                     bIsDirty = true;
                     break;
                  }
               }
            }
         }
      }
   }
   return bIsDirty;
}
/****************************************************************/