// validator.js
     
// The event handler function for the first text box

function chkFirst() {
  var myFirst = document.getElementById("first");

// Test the format of the input first name text box 

  var pos = myFirst.value.search(
            /[A-Za-z]+/);

  if (pos != 0) {
    alert("The name you entered (" + myFirst.value + 
          ") is not in the correct form. \n" +
          "Please re-enter your first name");
    myFirst.focus();
    myFirst.select();
    return false;
  } else
    return true;
}

// The event handler function for the last name text box

function chkLast() {
  var myLast = document.getElementById("last");

// Test the format of the input last name 

  var pos = myLast.value.search(
            /[A-Za-z]+/);

  if (pos != 0) {
    alert("The name you entered (" + myLast.value + 
          ") is not in the correct form. \n" +
          "Please re-enter your last name");
    myLast.focus();
    myLast.select();
    return false;
  } else
    return true;
}


// The event handler function for the street text box

function chkStreet() {
  var myStreet = document.getElementById("street");

// Test the format of the input street 

  var pos = myStreet.value.search(/[A-Za-z]+/);

  if (pos != 0) {
    alert("The Street Address you entered (" + myStreet.value +
          ") is not in the correct form. \n" +
          "Please re-enter your Street Address");
    myStreet.focus();
    myStreet.select();
    return false;
  } else
    return true;
}

// The event handler function for the suburb text box

function chkSuburb() {
  var mySuburb = document.getElementById("suburb");

// Test the format of the input suburb

  var pos = mySuburb.value.search(/[A-Za-z]+/);

  if (pos != 0) {
    alert("The Information you entered (" + mySuburb.value +
          ") is not in the correct form. \n" +
          "Please re-enter your Suburb");
    mySuburb.focus();
    mySuburb.select();
    return false;
  } else
    return true;
}


// The event handler function for the state text box

function chkState() {
  var myState = document.getElementById("state");

// Test the format of the input state

  var pos = myState.value.search(/[A-Za-z]+/);

  if (pos != 0) {
    alert("The Information you entered (" + myCity.value +
          ") is not in the correct form. \n" +
          "Please re-enter your State");
    myState.focus();
    myState.select();
    return false;
  } else
    return true;
}

// The event handler function for the postcode text box

function chkPcode() {
  var myPcode = document.getElementById("pcode");

// Test the format of the input pcode

  var pos = myPcode.value.search(/^\d{4}/);

  if (pos != 0) {
    alert("The Information you entered (" + myPcode.value +
          ") is not in the correct form. \n" +
          "Please re-enter your Postcode");
    myPcode.focus();
    myPcode.select();
    return false;
  } else
    return true;
}

// The event handler function for the phone number text box

function chkPhone() {
  var myPhone = document.getElementById("phone");

// Test the format of the input phone number

  var pos = myPhone.value.search(/^\d{10}/);

  if (pos != 0) {
    alert("The phone number you entered (" + myPhone.value +
          ") is not in the correct form. \n" +
          "Please re-enter your phone number");
    myPhone.focus();
    myPhone.select();
    return false;
  } else
    return true;
}

// The event handler function for the fax number text box

function chkFax() {
  var myFax = document.getElementById("fax");

// Test the format of the input fax number

  var pos = myFax.value.search(/^\d{10}/);

  if (pos != 0) {
    alert("The phone number you entered (" + myFax.value +
          ") is not in the correct form. \n" +
          "Please re-enter your fax number");
    myFax.focus();
    myFax.select();
    return false;
  } else
    return true;
}


// The event handler function for the organisation text box

function chkOrg() {
  var myOrg = document.getElementById("org");

// Test the format of the input organisation

  var pos = myOrg.value.search(/[A-Za-z]+/);

  if (pos != 0) {
    alert("The phone number you entered (" + myOrg.value +
          ") is not in the correct form. \n" +
          "Please re-enter your organisation");
    myOrg.focus();
    myOrg.select();
    return false;
  } else
    return true;
}

// The event handler function for the email text box

function chkEmail() {
  var myEmail = document.getElementById("email");

// Test the format of the email address

  var pos = myEmail.value.search(/\w+\@\w+/);

  if (pos != 0) {
    alert("The email address you entered (" + myEmail.value +
          ") is not in the correct form. \n" +
          "The correct form is: username@domain \n" +
          "Please re-enter your email address");
    myEmail.focus();
    myEmail.select();
    return false;
  } else
    return true;
}


