<!--
//------------------------------------------------------------------------------
// trim - Trims all leading and trailing spaces from a string
//------------------------------------------------------------------------------

function trim( strTarget ) {

  var sidx = 0;
  var eidx = strTarget.length - 1;

  while ( (strTarget.charAt( sidx ) == ' ') && (sidx < strTarget.length) ) sidx++;

  while ( (strTarget.charAt( eidx ) == ' ') && (eidx >= 0) ) eidx--;

  // If eidx became negative, it means the whole string is blanks; if this is
  // the case, the substring function will switch sidx and eidx (go figure), so
  // we check for this condition and return an empty string if necessary

  strTarget = (eidx < 0) ? "" : strTarget.substring(sidx, eidx+1);

  return strTarget;
  }


//------------------------------------------------------------------------------
// isInteger - Determines if the value passed is an integer
//------------------------------------------------------------------------------

function isInteger( strValue ) {
  var i;

  // Check the length of the value passed in; if it's zero, that's not a number

  if ( (strValue = trim(strValue)).length == 0 ) return false;

  // Now check that each character in the string is a digit

  for ( i=0; i < strValue.length; i++ )
    if ( (strValue.charAt(i) < "0") || (strValue.charAt(i) > "9") )
      return false;

  return true;
  }


//------------------------------------------------------------------------------
// inRange - Determines if the value passed is within the specified range
//------------------------------------------------------------------------------

function inRange( vntValue, vntLL, vntUL ) {

  if ( (vntValue < vntLL) || (vntValue > vntUL) )
    return false;

  return true;
  }


//------------------------------------------------------------------------------
// strToInt - Converts the string representation of an integer to an integer
//------------------------------------------------------------------------------

function strToInt( strValue ) {

  var i;
  var intValue;
  var strIntNoZeros = '';

  // convert strValue to a non-zero leading value since this is interpreted as
  // octal by Jscript

  for ( i=0; i < strValue.length; i++ )
    if ( strValue.substring( i, i+1 ) != '0' ) {
      strIntNoZeros += strValue.substring( i, strValue.length + 1 );
      break;
      }

  // convert strIntNoZeros to integer if the value is a valid integer value

  if ( isInteger(strIntNoZeros) )
    intValue = parseInt( strIntNoZeros );
  else
    intValue = 0;

  return intValue;
  }


//------------------------------------------------------------------------------
// isDecimal - Determines if the value passed is decimal
//------------------------------------------------------------------------------

function isDecimal( strValue, intPrec, intScale ) {
  var i;
  var intCount;
  var intLen;
  var intPos;

  // Check the length of the value passed in; if it's zero, it's not a decimal

  if ( (intLen = (strValue = trim(strValue)).length) == 0 )
    return false;

  // Now check that each character in the string is a digit (or a period)

  for ( i=0; i < strValue.length; i++ )
    if ( (strValue.charAt(i) != ".") &&
         ((strValue.charAt(i) < "0") || (strValue.charAt(i) > "9")) )
      return false;

  // Now check if we have more than one decimal point

  if ( (intCount = countChars(strValue, ".")) > 1 )
    return false;

  // Now check the precision and scale

  if ( intCount == 1 ) {
    intPos = strValue.indexOf( "." );
    if ( (intPos >= (intPrec - intScale)) || ((intLen - intPos - 1) > intScale) ) return false;
    }
  else
    if ( intLen >= (intPrec - intScale) ) return false;

  return true;
  }


//------------------------------------------------------------------------------
// countChars - Counts the number of occurrences of a character within a given
//              string
//------------------------------------------------------------------------------

function countChars( strValue, strChar ) {
  var i;
  var intCount = 0;

  // Search for each occurrence of sChar within sValue

  for ( i=0; i < strValue.length; i++ )
    if ( strValue.charAt(i) == strChar ) intCount++;

  return intCount;
  }
  
//------------------------------------------------------------------------------
// sCharStrip - strips all occurrences of a character within a given
//              string
//------------------------------------------------------------------------------

function sCharStrip( strValue, strChar ) {
  var i;
  var intCount = 0;
  var strLeft
  var strRight
  for ( i=0; i < strValue.length; i++ )
    if ( strValue.charAt(i) == strChar )  {
     strRight = strValue.slice(i + 1);
     strLeft = strValue.slice(0, i);
     strValue = strLeft + strRight
     
     intCount++;
    }
  return strValue;
  }


/*------------------------------------------------------------------------------
 * bIsDate - Checks the passed value to determine if it is a valid date in the
 *           form mm/dd/yyyy
 *----------------------------------------------------------------------------*/

function bIsDate( sDate ) {
  var i = 0;
  var nPos = 0;
  var nPrevPos = 0;
  var sMonth;
  var nMonth;
  var sDay;
  var nDay;
  var sYear;
  var nYear;
  var bDateVvalid;
  var nLength;
  var anDaysInMonth = new Array(13);

  anDaysInMonth[1] = 31;
  anDaysInMonth[2] = 28;
  anDaysInMonth[3] = 31;
  anDaysInMonth[4] = 30;
  anDaysInMonth[5] = 31;
  anDaysInMonth[6] = 30;
  anDaysInMonth[7] = 31;
  anDaysInMonth[8] = 31;
  anDaysInMonth[9] = 30;
  anDaysInMonth[10] = 31;
  anDaysInMonth[11] = 30;
  anDaysInMonth[12] = 31;

  // If a null string passed, return false now

  if ( (nLength = sDate.length) == 0 ) return false;

  //----------------------------------------------------------------------------
  // Locate the first "/" and pick off the month value
  //----------------------------------------------------------------------------

  nPos = sDate.indexOf( "/", nPrevPos );

  // nPos must be greater than nPrevPos for there to have been at least one
  // character before the "/"

  bDateValid = false;

  if ( nPos > nPrevPos ) {
    sMonth = sDate.substring( nPrevPos, nPos );
    nMonth = strToInt( sMonth );
    if ( (nMonth >= 1) && (nMonth <= 12) ) {
      nPrevPos = nPos + 1;

      // We shouldn't be at the end of the string yet

      if ( nPrevPos < nLength ) bDateValid = true;

      }
    }

  if ( ! bDateValid ) return false;

  //----------------------------------------------------------------------------
  // Locate the next "/" and pick off the day value
  //----------------------------------------------------------------------------

  nPos = sDate.indexOf( "/", nPrevPos );

  // nPos must be greater than nPrevPos for there to have been at least one
  // character before the "/"

  bDateValid = false;

  if ( nPos > nPrevPos ) {
    sDay = sDate.substring( nPrevPos, nPos );
    nDay = strToInt( sDay );
    if ( (nDay >= 1) && (nDay <= 31) ) {

      nPrevPos = nPos + 1;

      // We shouldn't be at the end of the string yet

      if ( nPrevPos < nLength ) bDateValid = true;

      }
    }

  if ( ! bDateValid ) return false;

  //----------------------------------------------------------------------------
  // Get the remaining characters in the date string and check these for a
  // valid year
  //----------------------------------------------------------------------------

  sYear = sDate.substring( nPrevPos, nLength );

  nYear = strToInt( sYear );

  if ( (nYear < 1900) || (nYear > 2037) )           // SQL server limitations
    return false;

  //----------------------------------------------------------------------------
  // Now that we have some sort of valid date, we need to check that the date
  // is real.  i.e that it exists in a non leap year, that the day is correct
  // for the month etc.
  //
  // First we'll determine if the year is a leap year and set february's days
  // Next, we'll check the day value against the anDaysInMonth array
  //----------------------------------------------------------------------------

  if ( (((nYear % 4) == 0) && ((nYear % 100) != 0)) || ((nYear % 400) == 0) )
    anDaysInMonth[2] = 29;

  if ( nDay <= anDaysInMonth[nMonth] ) return true;               // Valid date

  return false;
  }  
//-->
  