function validateUsername()
{
	var u = this.get().toLowerCase();
	this.set(u);
	if(u.length > 15){ this.message = "Username cannot be longer than 15 characters."; return false; }
	if(u.length < 2){ this.message = "Username must be at least 2 characters long."; return false; }
	if(LOWERALPHA.indexOf(u.charAt(0)) == -1){ this.message = "Username must begin with a letter."; return false; }
	if(u != extract(u, LOWERALPHA + NUMERIC)){ this.message = "Username can only contain letters and numbers."; return false; }
	return true;
}
function validatePassword()
{
	var p = this.get();
	if(p.length < 2) { this.message = "Password must be at least 6 characters long."; return false;}
	if(p.length > 8) { this.message = "Password cannot be longer than 8 characters"; return false;}
	if(ALPHA.indexOf(p.charAt(0)) == -1) { this.message = "Password must begin with a letter."; return false;}
	if(p != extract(p, ALPHANUMERIC)) { this.message = "Password can only contain letters and numbers"; return false;}
	return true;
}
function validatePassword2(){
	if(this.get() != getElement(this.password).get()) { this.message = "Confirmation password must be exactly the same as password."; return false;}
	if(this.get() == "") { this.message = "Confirmation password cannot be empty."; return false;}
	return true;
}
function validateEmail()
{
	var e = this.get(), atSign, before, after, dot;
	var validChars = ALPHANUMERIC + ".-_@";
	atSign = e.indexOf("@");
	if(atSign == -1) { this.message = "Email addresses must contain an @"; return false;}
	before = e.substring(0, atSign);
	after = e.substring(atSign + 1, e.length);
	if(before.length == 0) { this.message = "@ cannot be the first character in an email address."; return false;}
	if(after.length == 0) { this.message = "@ cannot be the last character in an email address."; return false;}
	if(after.indexOf("@") != -1) { this.message = "Email address cannot contain two @ characters."; return false;}
	var SectionCount = 1, SectionLength = 0, i;
	for(i = 0; i < after.length; i++)
		if(after.charAt(i) == '.'){
			if(SectionLength < 2) { this.message = "Email address has periods in the wrong places"; return false;};
			SectionCount++
			SectionLength = 0;
		}else
			SectionLength++;
	if(SectionCount < 2) { this.message = "Email domain after the @ is too short."; return false;}
	if(SectionLength < 2) { this.message = "Email address has periods in the wrong places."; return false;}
	if(e != extract(e, validChars)) { this.message = "Email address contains invalid characters."; return false;}
	return true;
}

function validateSSN(){
	var cleanStr = extract(this.get(), NUMERIC);
	if(cleanStr.length == 9){
		this.set(cleanStr.substring(0, 3) + '-' +
				 cleanStr.substring(3, 5) + '-' +
				 cleanStr.substring(5, 9));
		return true;
	}
	this.message = "Social security numbers and EIN's must be exactly 9 digits long";
	return false;
}

function validateNoSpaces(){
	var p = this.get();
	var invalid = " "; 		// Invalid character is a space
	/* < */ if (p.indexOf(invalid) > -1)
			{
				this.message = "Spaces NOT allowed in the field";
				return false;
			}
			else
			{
				return true;
			}
}