function requiredTextArea( fieldName, message ) {

   textArea = document.getElementById(fieldName);

   if( allTrim(textArea.value) == "" ) {

      alert( message );
      textArea.focus()
      return false;
   }

   return true;
}

function requiredText( fieldName, message ) {

   textBox = document.getElementById(fieldName);

   if( allTrim(textBox.value) == "" ) {

      alert( message );
      textBox.focus()
      return false;
   }

   return true;
}

function isNumeric( fieldName, message ) {

   var ValidChars = "0123456789.-";
   var Char;
   var Decimals=0

   textBox = document.getElementById(fieldName);

   for (i = 0; i < fieldName.length; i++)
      {

      Char = textBox.value.charAt(i);

      if (ValidChars.indexOf(Char) == -1)
         {
         alert( message );
         textBox.focus()
         return false;
         }
      }

   for (i = 0; i < fieldName.length; i++)
      {

      if (textBox.value.charAt(i) == ".") {
         Decimals = Decimals + 1
         }
      }

   if (Decimals > 1) {
      alert( message );
      textBox.focus()
      return false;
      }

   return true;
}

function numericLowRange( fieldName, lowValue, message ) {

   textBox = document.getElementById(fieldName);

   if( textBox.value < lowValue) {
      alert( message );
      textBox.focus()
      return false;
   }

   return true;
}


function requiredSelect( fieldName, message ) {

   textBox = document.getElementById(fieldName);

   if( textBox.value == "0" ) {

      alert( message );
      textBox.focus()
      return false;
   }

   return true;
}


function allTrim( sString) {

   while (sString.substring(0,1) == " ")
   {
      sString = sString.substring(1, sString.length);
   }

   while (sString.substring(sString.length-1, sString.length) == " ")
   {
      sString = sString.substring(0,sString.length-1);
   }

   return sString;

}

function editDate(inFieldName, inDate, inMessage) {

   var mm
   var dd
   var yy
   var SlashPosOne = new Number
   var SlashPosTwo = new Number
   var Rest

   cDate = allTrim(inDate)

   SlashPosOne = cDate.search("/")

   if (SlashPosOne < 1)
   {
      alert(inMessage+", it is not in mm/dd/yyyy format. Your first / is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   mm = cDate.substr(0,SlashPosOne)

   Rest = cDate.substr(SlashPosOne+1)

   SlashPosTwo = Rest.search("/")

   if (SlashPosTwo == -1)
   {
      alert(inMessage+", it is not in mm/dd/yyyy format. Your second / is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (SlashPosTwo+4 < Rest.length-1)
   {
      alert(inMessage+", the yyyy portion of mm/dd/yyyy is more than 4 digits long.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (SlashPosTwo+4 > Rest.length-1)
   {
      alert(inMessage+", the yyyy portion of mm/dd/yyyy is less than 4 digits long.");
      document.getElementById(inFieldName).focus()
      return false;
   }


   dd = Rest.substr(0,SlashPosTwo)
   yy = Rest.substr(SlashPosTwo+1,4)

   if ( isAnInteger(dd) == false )
   {
      alert(inMessage+", the dd portion of mm/dd/yyyy must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ( isAnInteger(mm) == false )
   {
      alert(inMessage+", the mm portion of mm/dd/yyyy must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ( isAnInteger(yy) == false )
   {
      alert(inMessage+", the yyyy portion of mm/dd/yyyy must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (mm < 1 | mm > 12)
   {
      alert(inMessage+", the mm portion of mm/dd/yyyy must be between 1 and 12.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (dd < 1)
   {
      alert(inMessage+", the dd portion of mm/dd/yyyy must be greater than 1.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (yy < 1 | yy > 3000)
   {
      alert(inMessage+", the yy portion of mm/dd/yyyy must be between 1 and 3000.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ((mm == 4 | mm == 6 | mm == 9 | mm == 11) && dd > 30)
   {
      alert(inMessage+", the dd portion of mm/dd/yyyy must be between 1 and 30.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ((mm == 1 | mm == 3 | mm == 5 | mm == 7 | mm == 8 | mm == 10 | mm == 12) && dd > 31)
   {
      alert(inMessage+", the dd portion of mm/dd/yyyy must be between 1 and 31.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (mm == 2)
   {
      if (yy % 4 == 0 && dd > 30)
      {
         alert(inMessage+", the dd portion of mm/dd/yyyy must be between 1 and 29.");
         document.getElementById(inFieldName).focus()
         return false;
      }
      else
      {
         if (dd > 29)
         {
            alert(inMessage+", the dd portion of mm/dd/yyyy must be between 1 and 28.");
            document.getElementById(inFieldName).focus()
            return false;
         }
      }
   }

   return true;

}

function isAnInteger( inNumber ) {

   var ValidChars = "0123456789";
   var Char;
   var Decimals=0

   for (i = 0; i < inNumber.length; i++)
      {

      Char = inNumber.charAt(i);

      if (ValidChars.indexOf(Char) == -1)
         {
         return false;
         }
      }

   for (i = 0; i < inNumber.length; i++)
      {

      if (inNumber.charAt(i) == ".") {
         Decimals = Decimals + 1
         }
      }

   if (Decimals > 1) {
      return false;
      }

   return true;
}


function isANumber( inNumber ) {

   var ValidChars = "0123456789.-";
   var Char;
   var Decimals=0

   for (i = 0; i < inNumber.length; i++)
      {

      Char = inNumber.charAt(i);

      if (ValidChars.indexOf(Char) == -1)
         {
         return false;
         }
      }

   for (i = 0; i < inNumber.length; i++)
      {

      if (inNumber.charAt(i) == ".") {
         Decimals = Decimals + 1
         }
      }

   if (Decimals > 1) {
      return false;
      }

   return true;
}

function editTime(inFieldName, inTime, inMessage) {

   var hh
   var mm
   var ss
   var AmPm
   var ColonPosOne
   var ColonPosTwo
   var BlankPos
   var Rest
   var cTime

   cTime = allTrim(inTime)

   ColonPosOne = cTime.search(":")

   if (ColonPosOne < 1)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. Your first : is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (ColonPosOne > 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. Your first : is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (ColonPosOne == 1)
   {
      hh = "0"+cTime.substr(0,1)
   }
   else
   {
   hh = cTime.substr(0,2)
   }

   Rest = cTime.substr(ColonPosOne+1)

   ColonPosOne = Rest.search(":")

   if (ColonPosOne < 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. Your second : is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (ColonPosOne > 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. Your seond : is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   mm = Rest.substr(0,2)

   Rest = Rest.substr(ColonPosOne+1)

   BlankPos = Rest.search(" ")

   if (BlankPos < 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. The blank after ss is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (BlankPos > 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. Your blank after ss is in the wrong spot.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   ss = Rest.substr(0,2)

   AmPm = Rest.substr(BlankPos+1)

   if (AmPm != "AM" && AmPm != "PM" && AmPm != "am" && AmPm != "pm")
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. The time must end in AM or PM.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (AmPm.length > 2)
   {
      alert(inMessage+", it is not in hh:mm:ss AM/PM format. The AM and/or PM parts are in the wrong place.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ( isAnInteger(hh) == false )
   {
      alert(inMessage+", the hh portion of hh:mm:ss AM/PM  must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ( isAnInteger(mm) == false )
   {
      alert(inMessage+", the mm portion of hh:mm:ss AM/PM  must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if ( isAnInteger(ss) == false )
   {
      alert(inMessage+", the ss portion of hh:mm:ss AM/PM  must numeric.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (hh < 1 | hh > 12)
   {
      alert(inMessage+", the hh portion of hh:mm:ss AM/PM must be between 1 and 12.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (mm < 0 | mm > 60)
   {
      alert(inMessage+", the mm portion of hh:mm:ss AM/PM must be between 0 and 60.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   if (ss < 0 | ss > 60)
   {
      alert(inMessage+", the ss portion of hh:mm:ss AM/PM must be between 0 and 60.");
      document.getElementById(inFieldName).focus()
      return false;
   }

   return true;

}


