<!-- Begin to hide script contents from old browsers.

///////////////////////////////////////////////////////////////////////////////
//
// ValidDate
//
// Check if object is a valid date
//
// Valid formats:  MM (or) M / DD (or) D / Y (or) YY (or) YYYY
//                 YY > 40 should be 19YY
//                 YY <= 40 should be 20YY
// 
// Input:          obj     - form object
//                 minDate - Minimum date (MM/DD/YYYY)
//
// Return:         true / false
//                 change obj.value to (MM/DD/YYYY) if it is valid, otherwise
//                 clear obj.value
//
///////////////////////////////////////////////////////////////////////////////

function ValidDate(obj,minDate) {
  obj.value = RemoveSpaces(obj.value);
  var strBuffer= new String(obj.value);
  var cDelimiter='';
  var strMonth=0, strDay=0, strYear=0;
  var nPos=-1;

  if (IsEmpty(strBuffer))
    return true;
  if (IsWhitespace(strBuffer)) {
    obj.value = '';
    return false;
  }

  // Get the delimiter used
  if (Occurs('/', strBuffer) == 2)
    cDelimiter = '/';
  else if (Occurs('-', strBuffer) == 2)
    cDelimiter = '-';

  // If no '/' or '-' found return false
  if (cDelimiter == '') {
    obj.value = '';
    return false;
  }

  // validate month, date, and year (Y, YY, YYYY are valid year formats)
  nPos = strBuffer.indexOf(cDelimiter);
  strMonth = strBuffer.substring(0, nPos);
  if (strMonth.length > 2 || !IsDigit(strMonth)) {
    obj.value = '';
    return false;
  }

  strBuffer = strBuffer.substring(nPos+1);
  nPos = strBuffer.indexOf(cDelimiter);
  strDay = strBuffer.substring(0, nPos);
  if (strDay.length > 2 || !IsDigit(strDay)) {
    obj.value = '';
    return false;
  }

  strBuffer = strBuffer.substring(nPos+1);
  strYear = strBuffer;
  if ((strYear.length > 4) || (strYear.length == 3) || !IsDigit(strYear)) {
    obj.value = '';
    return false;
  }

  // if YY < 40 then YYYY=20YY, else if YY >= 40 then YYYY=19YY
  var iYear = parseInt(strYear,10);
  if (iYear < 40)
    strYear = "20" + (iYear < 10 ? '0' + iYear:iYear);
  else if (iYear >= 40 && iYear < 100)
    strYear = "19" + strYear;

  // Pad month if less than 10
  var iMon = parseInt(strMonth,10);
  strMonth = (iMon < 10 ? '0' + iMon:iMon);

  // Pad days if less than 10
  var iDay = parseInt(strDay,10);
  strDay = (iDay < 10 ? '0' + iDay:iDay);

  strBuffer = strMonth + '/' + strDay + '/' + strYear;

  // validate date
  var dBuffer = new Date(strBuffer);
  if (dBuffer.getDate() != parseInt(strDay,10) ||
        dBuffer.getMonth()+1 != parseInt(strMonth,10) ||
        dBuffer.getFullYear() != parseInt(strYear,10)) {
    obj.value = '';
    return false;
  }

  // Check to see if the date is before the minimum date if one is specified
  if ( minDate != '' ) {
    var minStrBuffer= new String(minDate);

    // validate month, date, and year (Y, YY, YYYY are valid year formats)
    nPos = minStrBuffer.indexOf('/');
    minStrMonth = minStrBuffer.substring(0, nPos);

    minStrBuffer = minStrBuffer.substring(nPos+1);
    nPos = minStrBuffer.indexOf('/');
    minStrDay = minStrBuffer.substring(0,nPos);

    minStrBuffer = minStrBuffer.substring(nPos+1);
    minStrYear = minStrBuffer;

    if ( strYear < minStrYear ) {
      obj.value = '';
      return false;
    } else if ( strYear == minStrYear ) {
      if ( strMonth < minStrMonth ) {
        obj.value = '';
        return false;
      } else if ( strMonth == minStrMonth ) {
        if ( strDay < minStrDay ) {
          obj.value = '';
          return false;
        }
      }
    }
  }

  obj.value = strBuffer;
  return true;
}

