// JavaScript Document
function validateEmpty(fld) {
    var error = "";
    var errcolor = 'FFFFCC';
	var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/; 
	
    if (fld.value.length == 0) {
        fld.style.background = errcolor;
        error = "The required field has not been filled in.\n"
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = errcolor;
        error = "The required field contains invalid characters.\n";
	} else {
        fld.style.background = 'White';
    }
    return error;   
}
function validateDropDown(fld) {
    var error = "";
    var errcolor = 'FFFFCC';
    if (fld.value == 'null') {
        fld.style.background = errcolor;
        error = "Please select an option from the list.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    var errcolor = 'FFFFCC';
    
    if (fld.value == "") {
        fld.style.background = errcolor;
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = errcolor;
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = errcolor;
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePassword(fld) {
    var error = "";
    //var illegalChars = /[\W_]/; // allow only letters and numbers
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; 
    var errcolor = 'FFFFCC';
     
    if (fld.value == "") {
        fld.style.background = errcolor;
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 6)) {
        error = "The password is to short. \n";
        fld.style.background = errcolor;
    } else if ((fld.value.length > 25)) {
	    error = "The password is to long. \n";
	    fld.style.background = errcolor;
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = errcolor;
    } else {
        fld.style.background = 'White';
    }
   return error;
}   

