// JavaScript Document
// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// 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 = "Your email address is not valid.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Your email address contains illegal characters.\n";
       }
    }
return error;    
}


// password - between 4-15 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 > 15)) {
       error = "Your password must be 4-15 characters.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "Your password contains illegal characters.\n";
    } 
return error;    
}    


// username - 4-15 chars, uc, lc, and underscore only.

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

    var illegalChars = /\W/; // allow letters, numbers, and underscores
    
	if ((strng.length < 4) || (strng.length > 15)) {
       error = "Your username must be 4-15 characters.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Your username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng, fieldname) {
var error = "";
  if (strng.length == 0) {
     error = fieldname+" has not been filled in.\n";
  }
return error;	  
}

// double entry check
function doubleentry(element1, element2){
var error="";
	if (element1!=element2){
	error = "Your email addresses do not match.\n";
	}
return error;
}