
  function country_select() {
    var valc = gbi('country');
    if (valc.value=='US') {
      setdivdisplay('AmericanState','block');
      setdivdisplay('NonAmericanState','none');
    } else {
      setdivdisplay('AmericanState','none');
      setdivdisplay('NonAmericanState','block');
    }
  }

  var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,3}$/;

  var validate_name = /^[A-z]/

  var vp = /^[0-9A-z]+$/

  function validate_email() {
    if (rev=document.getElementById('email_address')) {
      if (emailRegxp.test(rev.value))
        return true;
      alert("Please enter a correct email address");
      rev.focus();
      rev.select();
      return false;
    } return true;
  }

  function validate_names() {
    if (first_name=gbi('first_name'))
      if (last_name=gbi('last_name')) {
        if (first_name.value.length == 0) {
          alert("Your first name cannot be empty. Please use a pseudonym if you are concerned about privacy issues.");
          return false;
        }
        if (last_name.value.length == 0) {
          alert("Your last name cannot be empty. Please use a pseudonym if you are concerned about privacy issues.");
          return false;
        }
        if (validate_name.test(first_name)) {
          if (validate_name.test(first_name)) {
            return true;
          } else
            alert("Please enter a correct last name. Use A-z characters only");
        } else
          alert("Please enter a correct first name. Use A-z characters only");
      return false;
    }

  }

  function validate_password() {
    var p = gbi('passwordtype');
    if (p.value==1) {
      var pw = gbi('password');
      //alert(pw.value.length);
        if (pw.value.length < 8) {
          alert("A valid password must be at least 8 characters in length for your security");
          pw.value = "";
          pw.focus();
          pw.select();
          return false;
        }
        if (vp.test(pw.value))
          return true;
        alert('Password must only contain following characters: 0-9, A-z');
        return false;
    }
    return true;
  }

  function validate_bio() {

    return true; // no longer checks the length of the bio

    var bio = gbi('bio');
    if (bio.value.length < 500) {
      alert('your biography must contain at least 500 characters. You have ' + (500 - bio.value.length) + ' to go!');
      return false;
    }
    return true;
  }

  function validate_birthdate() {

    var bd = gbi('bdday');
    var by = gbi('bdyear');
    var bm = gbi('bdmonth');
    var day = bd.value;
    var year = by.value;

    if (bm.value==0) {
      alert('Please choose birthdate month');
      return false;
    }

    if (isnumeric(day) && day > 0 && day < 32) {
      if (isnumeric(year) && year >= 1900 && year <= 2000) {
      } else {
        alert('Please enter correct birthdate; year must be a number between 1900 and 1990');
        by.focus();
        by.select();
        return false;
      }
    } else {
      alert('Please enter correct birthdate; day must be a number between 1-31');
      bd.focus();
      bd.select();
      return false;
    }

    return true;
  }

  // not yet used.
  function validate_country() {
    var c = gbi('country');
    return true;
  }

  function validate_information() {
    if (validate_email())
      if (validate_names())
        if (validate_birthdate())
          if (validate_password())
            if (validate_bio())
              return true;
    return false;
  }

  function update_display_name() {
    var fn = gbi('first_name');
    var ln = gbi('last_name');
    var a = new Array(fn.value,ln.value);
    for (i=0;i<2;i++) {

      var s = a[i];

      if (s.length==1)
        s.toUpperCase();
      else
        if (s.length > 1) {
          var p1 = s.substring(0, 1).toUpperCase();
          var p2 = s.substring(1,s.length);
          a[i] = p1 + p2;
      }
    }

    var dn = a[0] + " " + a[1];
    var d = gbi('display_name');
    d.value = dn;
  }