    var missing;
    var invalid;
    var f_error;
    var extra = '';
    var nc;

    function is_blank(s)
    {
      for(var i = 0; i < s.length; i++)
      {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t'))
          return false;
      }
      return true;
    }

    function validate_field(form, field, name, type)
    {
      var e = form[field];
      var valid = true;
      var emsg;
      switch (type)
      {
        case "phone":
          var re = /^[-+.() 0-9a-zA-Z]*$/;
          valid = re.test(e.value);
          emsg  = '[' + field +': field must contain only phone characters]\n';
          break;
        case "integer":
          var re = /\D/;
          valid = !re.test(e.value);
          emsg  = '\nfield must contain only integers ';
          break;
        case "email":
          var re = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
          valid = re.test(e.value);
          emsg  = '';
          break;
        case "data":
          var re = /^[a-zA-Z0-9]*$/;
          valid = re.test(e.value);
          emsg  = '[' + field + ': no spaces or special characters are allowed]\n';
          break;
        case "date":
          break;
        default:
          break;
      }
      if (!valid) 
      {
        invalid[invalid.length] = name;
        extra = extra + emsg;
      }
      f_error[field] = !valid;
    }

    function check_field(form, field, name)
    {
      var e = form[field];
      if ((e.value == null) || (e.value == "") || is_blank(e.value))
      {
        missing[missing.length] = name;
        f_error[field] = true;
      }
    }

    function required_fields(t)
    {
     // if (nc == 1)
     //   return true;

      missing = new Array();
      invalid = new Array();
      f_error = new Array();

      check_field(t, "FIRST_NAME", "First Name");
      check_field(t, "LAST_NAME", "Last Name");
      check_field(t, "PHONE", "Phone");
      validate_field(t, "EMAIL", "Email Address","email");


      for (f in f_error)
      {
        // alert("[[" + f + "]] [[" + f_error[f] + "]]");
        // var text = document.getElementsByName("text_" + f);
        // if (text.length)
          // text[0].className = f_error[f] ? "labelcell_error" : "labelcell";
        var input = document.getElementById("input_" + f);
        if (input)
          input.className = f_error[f] ? "fieldcell_error" : "fieldcell";
      }

      if (missing.length == 0 && invalid.length == 0)
        return true;

      var msg = "";

      if (missing.length > 0)
      {
        var plural = missing.length > 1;
        var msg = msg +
                  missing.join(", ") +
                  (plural ? " are" : " is a") +
                  " required field" +
                  (plural ? "s" : "") +
                  "!";
        if (invalid.length)
          msg = msg + "\n";
      }

      if (invalid.length > 0)
      {
        var plural = invalid.length > 1;
        var msg = msg +
                  invalid.join(", ") +
                  (plural ? " are" : " is an") +
                  " invalid field" +
                  (plural ? "s" : "") +
                  "! \n" + extra;
      }

      alert(msg);
      extra = '';
      return false;
    }