function confirmPasswords() {
    if (($('strNewPassword').value == $('strConfirmPassword').value) && $('strNewPassword').value.length > 0) {
        turnOffError($('strNewPassword'));
        turnOffError($('strConfirmPassword'));
    } else {
        turnOnError($('strConfirmPassword'),"Passwords do not match.");
        turnOnError($('strNewPassword'),"Passwords do not match.");
    }
}

function turnOnError(fld,text) {
        fld.style.borderColor = "#af2b19";
        fld.style.backgroundPosition = "right -28px"; 
        fld.title = text;
}

function turnOffError(fld) {
        fld.style.borderColor = "#9dc28b";
        fld.style.backgroundPosition = "right top"; 
        fld.title = "";
}
    
function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        turnOnError(fld);
    } else {
        turnOffError(fld);
    }
    return error;   
}

function validateAlphaNumerics(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

    if (fld.value == "") {
        turnOffError(fld)
    } else if (isNaN(parseInt(stripped))) {
        turnOnError(fld)
    } else if (!(stripped.length > 9)) {
        turnOnError(fld)
    } else {
        turnOffError(fld)
    }
    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= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        turnOffError(fld)
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        turnOnError(fld)
    } else if (fld.value.match(illegalChars)) {
        turnOnError(fld)
    } else {
        turnOffError(fld)
    }
    return error;
}