/************************************************************
 * Author: Jeremiah Weaver									*
 * Date: 23-MAR-2004										*
 * Class: EmailValidator (EmailValidator.class.js)			*
 * Language: JavaScript										*
 * Version: 1.0.0											*
 * Dependencies: Validator (Validator.class.js)				*
 * Special: NONE											*
 ************************************************************
 * CHANGE LOG												*
 ************************************************************
 * 23-MAR-2004 - initial writting							*
 ************************************************************/
 
var JW_INVALID_EMAIL_ERROR = 500;

/*******************
 * ::CONSTRUCTOR:: *
 *******************/
 
 	function EmailValidator () {
 	
 		this.init();
 	}
 
	EmailValidator.prototype = new Validator();
	
/************************
 * ::CLASS PROPERTIES:: *
 ************************/ 

/**********************
 * ::INITIALIZATION:: *
 **********************/

	EmailValidator.prototype.init = function () {
	};

/**********************
 * ::STATIC METHODS:: *
 **********************/
 
/**********************
 * ::PUBLIC METHODS:: *
 **********************/
 
 	EmailValidator.prototype.execute = function (value) {
 	
 		// check for required value
 		if(this.isRequired() && !this.validateRequired(value)) {
 		
 			this.setError(JW_REQUIRED_VALUE_ERROR);
 			return false;
 		}

		// check if email address is well-formed
		if (!new RegExp(/^[a-z0-9\-\._]+@[a-z0-9]([0-9a-z\-]*[a-z0-9]\.){1,}[a-z]{2,7}$/i).test(value) &&
            !new RegExp(/^[a-z0-9\-\._]+@(([0-9]){1,3}\.){3}[0-9]{1,3}$/i).test(value)) {
            
            this.setError(JW_INVALID_EMAIL_ERROR);
            return false;
		}
		
		// all is good
		return true;
 	}

/*************************
 * ::PROTECTED METHODS:: *
 *************************/

/***********************
 * ::PRIVATE METHODS:: *
 ***********************/
  
/**********************
 * ::EVENT HANDLERS:: *
 **********************/