
	//santizes an input
	function sanitizeInput(str)
	{
		if (str == "" || str == null) return "";
		return trim( str );
	}
	
	//checks is username is valid
	function isValidUsername(username, forename, surname)
	{
		var username = sanitizeInput(username).toLowerCase();
		if(username == "") return false;
		var forename = sanitizeInput(forename).toLowerCase();
		var surname = sanitizeInput(surname).toLowerCase();
		if( username.indexOf("user") != -1 || username.indexOf("pass") != -1 || username.indexOf(forename) != -1 ||  
			username.indexOf(surname) != -1 || username.indexOf("admin") != -1 || username.length < 8 )
			return false;
		return true;
	}
	
	//checks if password is valid
	function isValidPassword(password, forename, surname)
	{
		var password = sanitizeInput(password).toLowerCase();
		if(password == "") return false;
		var forename = sanitizeInput(forename).toLowerCase();
		var surname = sanitizeInput(surname).toLowerCase();
		if( password.indexOf("user") != -1 || password.indexOf("pass") != -1 || password.indexOf(forename) != -1 ||  
			password.indexOf(surname) != -1 || password.indexOf("admin") != -1 || password.length < 6 )
			return false;
		return true;
	}
	
	//takes a string and returns the string with no white-space on either side (string can still contain white-space between characters)
	function trim(str)
	{
		if (str == "" || str == null) return "";
		return lTrim( rTrim(str) );
	}
	
	//takes a string and returns the string with no white-space on the left side
	function lTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		for(var i=0; i < str.length; i++)
		{
			//if charAt i is not whitespace, return substring from i to end
			if( whitespace.indexOf( str.charAt(i) ) == -1 )
			return str.substring(i, str.length);
		}
		return "";
	}

	//takes a string and returns the string with no white-space on the right side	
	function rTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		for(var i=str.length - 1; i >= 0; i--)
		{
			//if charAt i is not whitespace, return substring from start to i
			if( whitespace.indexOf( str.charAt(i) ) == -1 )
			return str.substring(0, i + 1);
		}
		return "";
	}
	
	<!-- Checks if the e-mail contains one or more characters, followed by @ character followed by 	
	//one or more characters, followed by a dot and a 2 char country code or 3 character code such
	//as com and only one @ symbol
	function isValidEmail(email)
	{	if( sanitizeInput(email) == '') return false;
		//checks for any @ symbols after the first
		var onlyOneAtSymbol = (email.indexOf("@", (email.indexOf("@"))+1) == -1);
		var filter=/^.+@.+\..{2,3}$/
		if (filter.test(email) && onlyOneAtSymbol)
			return true;
		return false;
	}
	//-->
	
	function isValidDate(dateStr) 
	{
		if(trim(dateStr) == "") return false;
		// Checks for the following valid date formats:
		// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
		// Also separates date into month, day, and year variables
		
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
		
		// To require a 4 digit year entry, use this line instead:
		// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
		//alert("Date is not in a valid format.")
		return false;
		}
		day = matchArray[1]; // parse date into variables
		month = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12) { // check month range
		//alert(("Month must be between 1 and 12.");
		return false;
		}
		if (day < 1 || day > 31) {
		//alert(("Day must be between 1 and 31.");
		return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert(("Month "+month+" doesn't have 31 days!")
		return false
		}
		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
		//alert(("February " + year + " doesn't have " + day + " days!");
		return false;
		   }
		}
		return true;  // date is valid
	}