function valid()
{
	var strEmail = this.address
	var invalidChars = " /:;,'|+=()*&^%$#!~{}?";				// email address invalid chars
				
	if(strEmail.length >0)
	{
		// email validation - cannot contain any invalid characters
		for (i=0; i < invalidChars.length; i++)
		{	
			badChar = invalidChars.charAt(i);
			if (strEmail.indexOf(badChar, 0) > -1)
				{
					this.error = "The following characters (/:;,'|+=()*&^%$#!~{}?) and spaces are not allowed in the email.";
					return false;
				}
		}
		
		// email validation - there must be one "@" symbol
		atPos = strEmail.indexOf("@");
		if (atPos == 0)
			{
				this.error = "A user name or mailbox must appear before the \"@\" symbol.";
				return false;
			}
		if (atPos == -1)
			{
				this.error = "There must at least one \"@\" symbol in an email address.";
				return false;
			}

		// email validation - and only one "@" symbol
		if (strEmail.indexOf("@", atPos+1) != -1)
			{
				this.error = "There can be no more than one \"@\" symbol in an email address.";
				return false;
			}	
				
		// email validation - at least one period after the "@"
		periodPos = strEmail.indexOf(".", atPos);
		if	((periodPos - atPos) < 2)
			{
				this.error = "You have not entered a Domain Name.  (The Domain Name appears between the \"@\" symbol and the period.)"
				return false;
			}	
		if (periodPos == -1)
			{
				this.error = "There must at least one '.' symbol in email address.";
				return false;
			}
							
		// email validation - must be at least 2 characters after the "."
		if (periodPos + 3 > strEmail.length)
			{
				this.error = "There must at least two characters after the period.";
				return false;
			}
	}
	else
	{
		this.error = "No email address was entered."
		return false
	}
	return true;
}

function toUpper()
{
	return this.address.toUpperCase()
}

function substring(x,y)
{
	return this.address.substring(x,y)
}
function toLower()
{
	return this.address.toLowerCase()
}

function length()
{
	return this.address.length
}

function Email(email)
{
	this.address = new String(email)
	this.valid = valid
	this.toUpper = toUpper
	this.toLower = toLower
	this.length = length
	this.error = ""
	this.substring = substring
}



