<!--
// -----------------------------------------------------------------------------
// Filename   : pdsforms.js
// Description: Definitions of all Forms Related Functions
// -----------------------------------------------------------------------------
// Author     : Gary Javier
// Version    : 1.00.00
// Update History:
//    Date              Description                                   Author
//    ----------------- --------------------------------------------- ----------
//
// -----------------------------------------------------------------------------
// Copyright @ 2000-2003 by Progressive Data Systems
// -----------------------------------------------------------------------------
// This Code is licensed by Progressive Data System and are not for re-use or
// distribution usage unless approved by PDS Software
// -----------------------------------------------------------------------------


// -----------------------------------------------------------------------------
// Used to create a highlight effects on the fields
// -----------------------------------------------------------------------------
// Add >>onKeyUp="highlight(event)" onClick="highlight(event)"<< on the forms statement
// i.e. <form method="POST" onsubmit="return FormsValidate(this)" onKeyUp="highlight(event)" onClick="highlight(event)" name="Form1">
// -----------------------------------------------------------------------------

var highlightcolor = "cyan";
var ns6            = document.getElementById && !document.all;
var previous       = '';
var eventobj;

// Regular expression to highlight only form elements
var intended = /INPUT|TEXTAREA|SELECT|OPTION/;

//Function to check whether element clicked is form element

function checkel(which){
   if (which.style && intended.test(which.tagName)) {
      if (ns6 && eventobj.nodeType == 3) {
          eventobj=eventobj.parentNode.parentNode;
      }
      return true;
   }
   else {
      return false;
   }
}

//Function to highlight form element

function highlight(e) {
   eventobj = ns6 ? e.target : event.srcElement;
   if (previous != ''){
      if (checkel(previous)) {
         previous.style.backgroundColor = '';
      }
      previous = eventobj;
      if (checkel(eventobj)) {
         eventobj.style.backgroundColor = highlightcolor;
      }
   }
   else {
      if (checkel(eventobj)) {
          eventobj.style.backgroundColor = highlightcolor;
      }
      previous=eventobj;
   }
}

// -----------------------------------------------------------------------
// Clearing the Default Value of the text
// -----------------------------------------------------------------------
// i.e. <input type="text" value="Search this site" onFocus="clearText(this)">
function fClearText(thefield){
   if (thefield.defaultValue==thefield.value) {
      thefield.value = ""
   }
}

// ---------------------------------------------------------------------
// Applies the auto leave of the field when the user entered the max.
// length of the field.
// ---------------------------------------------------------------------
// i.e. <input type="text" name="first" size=4 onKeyup="autotab(this, document.sampleform.second)" maxlength=3>

function fAutotab(original,destination){
   if (original.getAttribute&&original.value.length == original.getAttribute("maxlength")) {
      destination.focus()
   }
}

function frequired(FormHandle) {
   var lNoError = true;
   var cErrorField = "";
   var ErrField;
   if (document.images) {
      for (i = 0; i < FormHandle.length; i++){
         var FieldObj = FormHandle.elements[i];
         if (FieldObj.name.substring(0,4) == "req_") {
            if (((FieldObj.type == "text" || FieldObj.type == "password" || FieldObj.type == "textarea") && FieldObj.value == '') || (FieldObj.type.toString().charAt(0) == "s" && FieldObj.selectedIndex == -1)) {
               lNoError = false;
               cErrorField = FieldObj.name.substring(4);
               ErrField = FieldObj;
               break;
            }
         }
      }
   }
   if (!lNoError) {
      alert(cErrorField + " is a required. field.  Please enter " + cErrorField + " before proceeding.");
      ErrField.focus();
      return false;
   }
   else {
      return true;
   }
}

function fmaxlength(FieldObj,MaxLength) {
   if (FieldObj.value.length >= MaxLength) {
      return false;
   }
   else {
      return true;
   }
}

function fcompare(FieldObj1,FieldObj2) {
   if (FieldObj1.value != FieldObj2.value) {
      return false;
   }
   else {
      return true;
   }
}

function fvalidemail(emails) {
   var lReturn = true;
   if (emails != "") {
      var cActual = new String(emails);
      var cLists  = new String();
      var cEmails = new String();
      cLists = cActual.split(";");
      if (cLists.length >= 1) {
         lLoop:
         for (i=0;i <= (cLists.length - 1);i++) {
           cTmpEmails = new String(cLists[i]);
           cEmails = cTmpEmails.split('@');
           if (cEmails.length <= 1) {
              lReturn = false;
              return false;
              break lLoop;
           }
           else if (cEmails[0] == "") {
              lReturn = false;
              return false;
              break lLoop;
           }
           else {
              cTmpAddress = cEmails[1];
              cTmpAddress = cTmpAddress.split(".");
              if (cTmpAddress.length <= 1) {
                 lReturn = false;
                 return false;
                 break lLoop;
              }
              else if ((cTmpAddress[0] == "") || (cTmpAddress[1] == "")) {
                 lReturn = false;
                 return false;
                 break lLoop;
              }
           }
         }
         return lReturn;
      }
      else {
         return false;
      }
   }
   else {
      return false;
   }
}


// ----------------------------------------------------------------------
// Displays the current time and date in the status bar
// ----------------------------------------------------------------------

function fStatusDateTime() {
   window.setTimeout("fStatusDateTime()",1000);
   today = new Date();
   self.status = today.toString();
}


// ----------------------------------------------------------------------
// Clears the default value of the fill-in once the focus has been placed
// in the fill-in
// ----------------------------------------------------------------------
// i.e. <input type="text" value="Search this site" onFocus="clearText(this)">

// function fClearText(thefield){
//    if (thefield.defaultValue == thefield.value) {
//       thefield.value = "";
//    }
// }

function fReturnText(thefield) {
   if (thefield.value == "") {
      thefield.value = thefield.defaultValue;
   }
}


// -----------------------------------------------------------------------
// Allows the User to leave the field with an enter key pressed
// -----------------------------------------------------------------------
// i.e. <input type="text" value="Search this site" onkeyup="fEnterKeyL(this.form,this)">
/*
function fEnterKeyL(form,field) {
   var next=0,found=false;
   var f=form;
   if(event.keyCode != 13) {
     return;
   }
   for(var i=0;i<f.length;i++) {
      if (field.name == f.item(i).name) {
         next  = i+1;
         found = true;
         break;
      }
   }
   while(found)  //Infinite loop	{
      if ((f.item(next).disabled == false) && (f.item(next).type != 'hidden')) {
         if.item(next).focus();
         break;
      }
      else {
         if(next < f.length - 1) {
            next = next + 1;
         }
         else {
            break;
         }
      }
   }
}
*/
// -->
