// comparison of text inputs
function isSame(strng, strngTwo, fieldStr) {
var error = "";
  if (strng != strngTwo) {
     error = 'The ' + fieldStr +' fields do not match.\n'
  }
return error;	  
}


// email
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// password - between 4-20 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 4) || (strng.length > 20)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
 return error;    
}    


// username - 4-20 chars, and underscore only.
function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a screen name.\n";
}
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 20)) {
       error = "The screen name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The screen name contains illegal characters.\n";
    } 
return error;
}       

// non-empty textbox
function isEmpty(strng, fieldStr) {
var error = "";
  if (strng.length == 0) {
     error = "The " + fieldStr + " field has not been filled in.\n"
  }
return error;	  
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}
