function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if (fld.value.length < 8) {
        error = "Minimum password length is 8 characters\n";
        fld.style.background = 'Yellow';
    } else if (fld.value.length > 16) {
        error = "Maximum password length is 16 characters\n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } 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 = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
function validateUserID(fld) {
    var error = "";
    var illegalChars = /[^A-Za-z0-9_@\.]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a user name.\n";
    } else if ((fld.value.length < 4 ) || (fld.value.length > 20)) {
        error = "The user name must have between 4 and 20 characters\n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The user name contains illegal characters. Only A-z, a-z, 0-9, _,@ and . are allowed\n";
        fld.style.background = 'Yellow';

    } else {
        fld.style.background = 'White';
    }
   return error;
}  


function validateFormOnSubmit(theForm) {
var reason = "";
  reason += validatePassword(theForm.new_ldap_password);
  reason += validatePassword(theForm.verify_ldap_password);
        
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateRegFormOnSubmit(theForm) {
var reason = "";
  reason = validateEmpty(theForm.givenName);
  if (reason != "") {
    alert(reason);
    return false;
  }
  reason = validateEmpty(theForm.surName);
    if (reason != "") {
    alert(reason);
    return false;
  }
  reason = validateEmpty(theForm.eMail);
    if (reason != "") {
    alert(reason);
    return false;
  }
  reason = validateUserID(theForm.uid);
    if (reason != "") {
    alert(reason);
    return false;
  }
  reason = validateEmpty(theForm.captchastring);
  
    if (reason != "") {
    alert(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 showFeedback(theForm) {
window.title = 'Load OK';
if ( document.getElementById("FEEDBACK_MSG") ) {

    if (document.getElementById("FEEDBACK_MSG").value.length > 0 ) {

         alert(document.getElementById("FEEDBACK_MSG").value);
         document.getElementById("FEEDBACK_MSG").value = '';        

         return true;


    }
}
}
