/**
 * Handles email functionality like parsing addresses
 * and validation
 *
 * @author mmathews@oxygen.com
 * @author kfrank@oxygen.com
 * @version 1.0, 1 Jun 2001
 * @param emailStr A String with an email address like "name@host.com"
 */
function Email(emailStr) {
	if (emailStr) this.emailStr = emailStr
}

/**
 * A default value for emailStr
 */
Email.prototype.emailStr = null

Email.prototype.setEmailStr = function(newEmailStr) {
	this.emailStr = newEmailStr
}

/**
 * Parse this object's email string and return the host
 *
 * @return A String representing the host, like "name@<i>host.com</i>"
 */
Email.prototype.getHost = function() {
	var matches = new Array()
	matches = this.getAddress().match(/\@(\w+((\.|-)\w+)*\.\w+$)/)
	return matches[1]
}

/**
 * Parse this object's email string and return the username
 *
 * @return A String representing the users name, like "<i>name</i>@host.com" 
 */
Email.prototype.getUserName = function() {
	var matches = new Array()
	matches = this.getAddress().match(/(^\w+((-\w+)|(\.\w+))*)\@/)
	return matches[1]
}

/**
 * Checks if email string is a valid format like "name@host.com"
 *
 * @return true or false, if the email string is a valid format
 */
Email.prototype.isValid = function() {
	// some clients erroneously consider a comma to match \w, so check for commas explicitly
	if (this.getAddress().indexOf(",") != -1) return false
	
	return ((this.getAddress().search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/)) == 0)? true:false
}

/**
 * Accessor: getter for emailStr
 *
 * @return the value of the object property "emailStr"
 */
Email.prototype.getAddress = function() {
	return this.emailStr
}
