function validateBulletinForm(theForm) {
  var reason = "";

  reason += validateFullName(theForm.name);
  reason += validateEmail(theForm.email);
  //reason += validateOldPassword(theForm.oldpasswd);
  reason += validatePassword(theForm.passwd);
  reason += validatePasswordVerify(theForm.passwd, theForm.passwd2);
  reason += validateSMJGARelationship(theForm.relationship)
  reason += validateSMJGAUsername(theForm.smjgauname)
  reason += validateSMJGAPassword(theForm.smjgapasswd)
  if (reason != "") {
    alert("Correction:\n" + reason);
    return false;
  }

  return true;
}
function validateFullName(fld) {
  var error = "";
  //var illegalChars = /\W/; // allow letters, numbers, and underscores

  //alert('validateFullName');
  if (fld.value == "") {
      fld.style.background = 'Yellow';
      error = "Please enter a full name.\n";
  //} else if (illegalChars.test(fld.value)) {
  //    fld.style.background = 'Yellow';
  //    error = "The full name contains illegal characters.\n";
  }else if (!(fld.value.search(/(0-9)+/))) {
      error = "The full name must not contain numbers.\n";
      fld.style.background = 'Yellow';
  } else {
      fld.style.background = 'White';
  }
  return error;
}
function validateEmail(fld) {
   var error = "";
   var len = fld.value.length;         // get length of the email string
   //alert('validateEmail');
   //if email field is empty - warning displays and return false
   if (fld.value == ""){
       error = "Please enter your email.\n";
       fld.style.background = 'yellow';
   }else if((fld.value.charAt(0)=='@')||(fld.value.charAt(0)=='.')){           //'@' and '.' must NOT be at the beginning
       error = "Invalid email: the @ and/or the '.' must not be at the beginning.";
       fld.style.background = 'Yellow';
   }else if((fld.value.charAt(len-1)=='@')||(fld.value.charAt(len-1)=='.')){   // @ and '.' must NOT be at the end of string.
       error = "Invalid email: the @ and/or '.' must not be at the end."
       fld.style.background = 'Yellow';
   }else{
       //count number of @ occurrences and number of dot occurrences
       var count = 0;
       var dotcount = 0;
       for (i=0; i< fld.value.length; i++)
       {
        if(fld.value.charAt(i) == '@')
               count++;
        if(fld.value.charAt(i) == '.')
               dotcount++;
       }
       //if @ or dot occurs not once display warning and return false
       //if((count !=1)||(dotcount !=1)){
       if (dotcount == 0){
           error = "Invalid email. The '.' must occur at least once, example: myemail@mysite.com";
           fld.style.background = 'Yellow';
           return error;
       }
       if (count != 1){
           //error = "Invalid email. The @ and/or '.' must occur once, example: myemail@mysite.com";
           error = "Invalid email. The '@' must occur once, example: myemail@mysite.com";
           fld.style.background = 'Yellow';
           return error;
      }
   }
   return error;
}
function validateOldPassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers
    //alert('validateOldPassword');
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter your old password.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        error = "The old password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The old password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers
    //alert('validatePassword');
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter a password.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}
function validatePasswordVerify(fld1, fld2) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers
    //alert('validatePasswordVerify');
    if (fld2.value == "") {
        fld2.style.background = 'Yellow';
        error = "Please enter a password verification.\n";
    } else if ((fld2.value.length < 5) || (fld2.value.length > 15)) {
        error = "The password verification is the wrong length. \n";
        fld2.style.background = 'Yellow';
    } else if (fld1.value != fld2.value){
        error = "The password and the verified password does not match!\n";
        fld1.style.background = 'Yellow';
        fld2.style.background = 'Yellow';
    } else {
        fld1.style.background = 'White';
        fld2.style.backgroung = 'White';
    }
   return error;
}
function validateSMJGARelationship(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    //alert('validateSMJGARelationship');
    if (fld.value == "default") {
        fld.style.background = 'Yellow';
        error = "Please choose a SMJGA relationship.\n";
    }
    return error;
}
function validateSMJGAUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    //alert('validateSMJGAUsername');
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter a SMJGA username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow';
        error = "The SMJGA username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow';
        error = "The SMJGA username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateSMJGAPassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers
    //alert('validateSMGJAPassword');
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter a SMJGA password.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        error = "The SMJGA password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The SMJGA password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}

