function Validate (frmMainForm, objValidate , objSingle) {
  var forFocus = "";
  var strMessage="";
  var IsValid = true;
  var FailureList = "Please correct the following...\n\n";
  if (objSingle) {
    obj=objSingle;

    if (isBlank(frmMainForm[obj].value)){
      return false;}

      if (objValidate[obj].type == 'text') {
        if (!TextValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          strMessage=objValidate[obj].valtext;
          window.status=strMessage;
          frmMainForm[obj].focus();
        }
      } else
      if (objValidate[obj].type == 'textonly') {
        if (!TextOnlyValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          strMessage=objValidate[obj].valtext;
          window.status=strMessage;
          frmMainForm[obj].focus();
        }
      }
      else
      if (objValidate[obj].type == 'date') {
        if (!DateValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          strMessage = frmMainForm[obj].value + ' is not valid\n' + objValidate[obj].valtext;
          alert(strMessage);
          frmMainForm[obj].focus();
          window.status=strMessage;
        }
      }
      else
      if (objValidate[obj].type == 'email') {
        if (!MailValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          strMessage = frmMainForm[obj].value + ' is not valid\n' + objValidate[obj].valtext;
          alert(strMessage);
          frmMainForm[obj].focus();
        }
      }
      else
      if (objValidate[obj].type == 'number') {
        if (!NumberValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          strMessage = frmMainForm[obj].value + ' is not valid\n' + objValidate[obj].valtext;
          alert(strMessage);
          frmMainForm[obj].focus();
        }
      }

  } else {

    for (var obj in objValidate) {
      if (objValidate[obj].type == 'text') {
        if (!TextValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          FailureList += "    " + objValidate[obj].valtext + "\n";
          if (forFocus=="") forFocus=frmMainForm[obj];
        }
      }
      else if (objValidate[obj].type == 'textonly') {
        if ((!TextOnlyValidate(frmMainForm[obj], objValidate[obj]))||(!TextValidate(frmMainForm[obj], objValidate[obj]))) {
          IsValid = false;
          FailureList += "    " + objValidate[obj].valtext + "\n";
          if (forFocus=="") forFocus=frmMainForm[obj];
        }
      }
      else if (objValidate[obj].type == 'date') {
        if (!DateValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          FailureList += "    " + objValidate[obj].valtext + "\n";
          if (forFocus=="") forFocus=frmMainForm[obj];
        }
      }
      else if (objValidate[obj].type == 'email') {
        if (!MailValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          FailureList += "    " + objValidate[obj].valtext + "\n";
          if (forFocus=="") forFocus=frmMainForm[obj];
        }
      }
      else if (objValidate[obj].type == 'number') {
        if (!NumberValidate(frmMainForm[obj], objValidate[obj])) {
          IsValid = false;
          FailureList += "    " + objValidate[obj].valtext + "\n";
          if (forFocus=="") forFocus=frmMainForm[obj];
        }
      }
    }
  }

  if (!IsValid){
    if (!objSingle) {
      alert(FailureList);
      forFocus.focus();
      forFocus="";
      return false;
    }
    else {
      return false;}
  }
  else {
    if (!objSingle)
    return true;
    else

    window.status="";
  }

}

function TextValidate(objText, objValidate) {
  if (isBlank(objText.value))
  return(objValidate.blank);

  if (typeof(objText.value) == 'string') {
    return true;
  }
  else
  return false;
}


function TextOnlyValidate(objText, objValidate) {
  if (isBlank(objText.value))
  return(objValidate.blank);

  if (isAlphabeticString (objText.value)) {
    return true;
  }
  else
  return false;
}

function NumberValidate(objNumber, objValidate) {
  if (isBlank(objNumber.value))
  return(objValidate.blank);

  if (isNumberString(objNumber.value)) {
    return(objNumber.value >= objValidate.lower && objNumber.value <= objValidate.upper);
  }
  else {
    return(false);
  }
}

function DateValidate(objDate, objValidate) {
  if (isBlank(objDate.value))
  return(objValidate.blank);

  if (typeof(objDate.value) == 'string') {

    var dt = Date.parse(CheckDate(objDate.value));
    var lower = Date.parse(objValidate.lower);
    var upper = Date.parse(objValidate.upper);
    if (dt != 0) {
      return(dt >= lower && dt <= upper);
    }
  }

  return(false);
}

function MailValidate(objMail, objValidate) {
  if(isBlank(objMail.value))
  return(objValidate.blank);
  if (typeof(objMail.value) == 'string') {
    if (objMail.value.search(/.+\@.+\..+/) != -1)
    return true;
    else
    return false;
  }
  return (false);
}

function CheckDate(strDate) {

  var datebits = parser(strDate, '/');
  if (datebits.length != 3)
  return (0);

  var day = datebits[1];
  var mon = datebits[2];
  var year = datebits[3];
  if (mon < 1 || mon > 12)
  return(0);

  var maxday = 0;
  if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
  maxday = 30;
  else if (mon == 2) {
    if (year % 4 == 0) {
      if (year % 100 == 0) {
        if (year % 400 == 0) {
          maxday = 29;
        }
        else
        maxday = 28;
      }
      else
      maxday = 29;
    }
    else
    maxday = 28;
  }
  else
  maxday = 31;

  if (day < 1 || day > maxday)
  return(0);

  var strUSDate = mon + "/" + day + "/" + year;
  return(strUSDate);
}

