function validatelogin(theForm) {
var reason = "";

  reason += validateUsername(theForm.username);
  reason += validatePassword(theForm.password);



      
  if (reason != "") {
    alert("" + reason);
    return false;
  }


}


function validateUsername(fld) {
    var error = "";
    var illegalChars = []; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#f6f6f6'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 15)) {
        fld.style.background = '#f6f6f6'; 
        error = "The username must be 6-15 characters.\n";
    }  else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePassword(fld) {
    var error = "";
     var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#f6f6f6';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 15)) {
        error = "The password must be at least 6 characters. \n";
        fld.style.background = '#f6f6f6';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters. Letters and Numbers are only allowed.\n";
        fld.style.background = '#f6f6f6';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = '#f6f6f6';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  



