function validateFormOnSubmit(theForm) {
var reason = "";
    
  
  reason += validateFName(Form1.txtFirst);
  reason += validateLName(Form1.txtLast);
  reason += validateEmpty(Form1.txtQualifications);
  reason += validateEmpty(Form1.txtExperience);
  reason += validateEmpty(Form1.txtSkillSet);
  reason += validateEmpty(Form1.txtPhone);
  reason += validateEmpty(Form1.txtAttachment);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateFName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter your first name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your first name contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}

function validateLName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter your last name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your last name contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}

