// ************************************
// Form verification functions
// ************************************

function veriFormOne(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;

  msg = "The form could not be processed because of the following.\n";
  msg += "Please correct the entries and re-submit.\n\n";

  if (isNaN(fin.numtapes.value)) {
    founderr = true;
    msg += " Invalid number of tapes " + fin.numtapes.value + "\n";
  } else {
    if (fin.numtapes.value<1) {
      founderr = true;
      msg += " You selected this tape type but number of tapes is less than 1.\n";
    }
  }

  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

function veriFormTwo(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;

  msg = "The form could not be processed because of the following.\n";
  msg += "Please correct the entries and re-submit.\n\n";

  if (isNaN(fin.numtapes.value)) {
    founderr = true;
    msg += " Invalid number of tapes " + fin.numtapes.value + "\n";
  } else {
    if ((fin.numtapessml.value<1) && (fin.numtapes.value<1)) {
      founderr = true;
      msg += " You selected these tape types but total number of both types of tape is less than 1.\n";
    }
  }

  if (isNaN(fin.numtapessml.value)) {
    founderr = true;
    msg += " Invalid number of tapes " + fin.numtapessml.value + "\n";
  }

  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

function veriFormTwoA(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;

  msg = "The form could not be processed because of the following.\n";
  msg += "Please correct the entries and re-submit.\n\n";

  if (isNaN(fin.numtapes.value)) {
    founderr = true;
    msg += " Invalid number of VCR tapes " + fin.numtapes.value + "\n";
  } else {

    if (isNaN(fin.numtapessml.value)) {
      founderr = true;
      msg += " Invalid number of VCR-LP tapes " + fin.numtapessml.value + "\n";
    } else {

      if (isNaN(fin.numtapesvr.value)) {
        founderr = true;
        msg += " Invalid number of SVR tapes " + fin.numtapesvr.value + "\n";
      } else {

        if ((fin.numtapessml.value<1) && (fin.numtapes.value<1) && (fin.numtapesvr.value<1)) {
          founderr = true;
          msg += " You selected these tape types but the total number of all types of tape is less than 1.\n";
        }
      }
    }
  }


  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

function veriFormThree(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;
//
// the following regular expression (I've used it before) came from www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=87256B280015193F87256C40004CC8C6
//
  var valid_eml_fmt = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

  msg = "The form could not be processed because of the following.\n";
  msg += "Please correct the entries and re-submit.\n\n";

  if (!valid_eml_fmt.test(fin.emladdr.value)) {
    founderr = true;
    msg += " invalid email address " + fin.emladdr.value + "\n";
  }

  if (fin.postaddr.value == "") {
    founderr = true;
    msg += " you did not fill in your postal address\n";
  }

  if (fin.cusname.value == "") {
    founderr = true;
    msg += " you did not fill in your name\n";
  }

  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

function veriFormFour(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;

  msg = "The form could not be processed because of the following.\n";
  msg += "Please correct the entries and re-submit.\n\n";

  if (isNaN(fin.numcc.value) || isNaN(fin.nummc.value) || isNaN(fin.numuc.value) || isNaN(fin.numdcc.value) || isNaN(fin.numdat.value) || isNaN(fin.numrr.value) || isNaN(fin.num8t.value) || isNaN(fin.nummd.value) || isNaN(fin.numbeta.value)) {
    founderr = true;
    msg += "One of the numbers of tapes is not valid\n";
  } else {
    if (fin.numcc.value<1 && fin.nummc.value<1 && fin.numuc.value<1 && fin.numdcc.value<1 && fin.numdat.value<1 && fin.numrr.value<1 && fin.num8t.value<1 && fin.nummd.value<1 && fin.numbeta.value<1 ) {
      founderr = true;
      msg += " You selected this tape type but the total number of tapes is less than 1.\n";
    }
  }

  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

function veriFormTape(fin) {

  var msg;
  var empty_field = "";
  var founderr = false;
  var i;
  var j = 0;

  msg = "The form could not be processed because you did not select a tape type.\n";
  msg += "Please correct and re-submit.\n\n";


  for  ( i=0; i<17; i++) {
    if (fin.tapetype[i].checked == false) {
      j++;
    }
  }


  if (j==17) {
    founderr = true;
  }


  if (founderr) {
    alert(msg);
    return false;
  } else {
    return true;
  }

}

