var Step3ModelPropertyValidator = (function() {
    function fnStep3ModelPropertyValidatorConstructor(oNewModel) {
        /****************************************************/
		/*                                                  */
		/*                                                  */
		/*                 Private Variables                */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		var oModel;
		var hErrorLists;
		
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*            Class Level Private Methods           */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		function processValidationError(aErrors, bValid, sMessage) {
			if (!bValid) {
				aErrors.push(sMessage);
			}
		}
		
		function validateRequiredValue(sValue) {
			try {
				sValue = sValue.replace(/^\s|\s$/, "");
				return sValue.length > 0;
			}
			catch (eException) {
				return false;
			}
		}
		
		function validateEmailAddress(sValue) {
			try {
				var oRegularExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				return oRegularExpression.test(sValue);
			}
			catch (eException) {
				return false;
			}
		}
		
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*          Class Level Priveleged Methods          */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		//this.validate
		
		this.getAllErrors = function() {
		    return hErrorLists.clone();
		}
		
		this.initializeErrorList = function() {
			hErrorLists = $H();
			hErrorLists.set("Recipient Email Address", new Array());
			hErrorLists.set("Sender Email Address", new Array());
		}
		
		this.isValid = function() {
		    var bValid = true;
			
			var sRecipientEmailAddress = oModel.getRecipientEmailAddress();
			var sSenderEmailAddress = oModel.getSenderEmailAddress();
			if (!sRecipientEmailAddress || sRecipientEmailAddress.length == 0 || !sSenderEmailAddress || sSenderEmailAddress.length == 0)
			    bValid = false;
			else {
			    hErrorLists.each(function(oPair) {
			        if (oPair.value.length > 0) {
			            bValid = false;
			            throw $break;
			        }
			    });
			}
			
			return bValid;
		}
		
		this.validateRecipientEmailAddress = function() {
		    var aErrors = new Array();
		    processValidationError(aErrors,	validateRequiredValue(oModel.getRecipientEmailAddress()), "Required");
		    processValidationError(aErrors,	validateEmailAddress(oModel.getRecipientEmailAddress()), "Invalid Format");
		    hErrorLists.set("Recipient Email Address", aErrors);
		}
		
		this.validateSenderEmailAddress = function() {
		    var aErrors = new Array();
		    processValidationError(aErrors,	validateRequiredValue(oModel.getSenderEmailAddress()), "Required");
		    processValidationError(aErrors,	validateEmailAddress(oModel.getSenderEmailAddress()), "Invalid Format");
		    hErrorLists.set("Sender Email Address", aErrors);
		}
		
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*                 Initialize Class                 */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		oModel = oNewModel;
		this.initializeErrorList();
		
    }
    
    return fnStep3ModelPropertyValidatorConstructor;
})();