wFORMS.showAlertOnError = false; /* switch off wForms error popup */
wFORMS.preventSubmissionOnEnter = false; /* Enable the enter key to submit in forms */
/*
wFORMS.behaviors['validation'].errMsg_required = "";
wFORMS.behaviors['validation'].errMsg_alpha = "";
wFORMS.behaviors['validation'].errMsg_email = "";
wFORMS.behaviors['validation'].errMsg_integer = "";
wFORMS.behaviors['validation'].errMsg_float = "";
wFORMS.behaviors['validation'].errMsg_alphanum = "";
wFORMS.behaviors['validation'].errMsg_date = "";
wFORMS.behaviors['validation'].errMsg_custom = "";
wFORMS.behaviors['validation'].errMsg_notification = "%% error(s) detected. Your form has not been submitted yet.\nPlease check the information you provided."; // %% will be replaced by the actual number of errors
*/
// ------------------------------------------------------------------------------------------
// Form Validation Behavior
// ------------------------------------------------------------------------------------------
if(wFORMS) {
   wFORMS.behaviors['validation'].showError = function (element,errorMsg) {
      // remove existing error message if any.
      wFORMS.behaviors['validation'].removeErrorMessage(element);

      if (!element.id) element.id = wFORMS.helpers.randomId(); // we'll need an id here.
      // Add error flag to the field
      element.className += " " + wFORMS.className_validationError_fld;
      // Find error message placeholder.
      var fe = document.getElementById(element.id +  wFORMS.idSuffix_fieldError);
      if(!fe) { // create placeholder.
         fe = document.createElement("div");
         fe.setAttribute('id', element.id +  wFORMS.idSuffix_fieldError);
         // attach the error message after the field label if possible
         var fl = document.getElementById(element.id +  wFORMS.idSuffix_fieldLabel);
         if(fl) fl.parentNode.insertBefore(fe,fl.nextSibling);
      else
         // otherwise, attach it after the field tag.
         element.parentNode.insertBefore(fe,element.nextSibling);
      }
      // Finish the error message.
      fe.innerHTML = errorMsg;
      fe.parentNode.className += " " + wFORMS.className_validationError_msg;
   };
   wFORMS.behaviors['validation'].removeErrorMessage = function(element) {
      if(wFORMS.helpers.hasClass(element,wFORMS.className_validationError_fld)) {
         var rErrClass = new RegExp(wFORMS.className_validationError_fld,"gi");
         element.className = element.className.replace(rErrClass,"");
         rErrClass = new RegExp(wFORMS.className_validationError_msg,"gi");
         element.parentNode.className = element.parentNode.className.replace(rErrClass,"");
         var errorMessage  = document.getElementById(element.id + wFORMS.idSuffix_fieldError);
         if(errorMessage)  {
            errorMessage.innerHTML="";
         }
      }
   };
}

$(document).ready(function() {
   // Set focus to first form field on page load
   if (typeof formFocus == 'undefined') {
     $("input[type='text'],textarea").eq(0).focus();
   }
   // For <a>'s with a class of blank, open in new window
   $("a.blank").click(function(){
      window.open(this.href);
      return false;
   });
   // For <a>'s with a class of print, call window.print
   $("a.print").click(function(){
      window.print();
      return false;
   });
   // For <a>'s with a class of delete, confirm before deleting
   $("a.delete").click(function(){
      var text = 'Are you sure you want to delete this item?';
      if (confirm(text)) {
         return true;
      } else {
         return false;
      }
   });
   // Apply button styling
   $("button,input:submit,a.button").button();
   // Show popup dialog
   $('a.popup').click(function() {
      var popid = "#content" + $(this).attr('id');
      $(popid).dialog({
         bgiframe: true,
         autoOpen: true,
         width: 520,
         modal: true,
         resizable: false,
         buttons: {
            Close: function() {
               $(this).dialog('close');
            }
         }
      });
      return false;
   });
});

