﻿var Step3ViewHelper = (function() {
	function fnStep3ViewHelperConstructor(oNewView) {
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*                 Private Variables                */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		var oView;
		var bValidated = false;
		
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*          Class Level Priveleged Methods          */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		this.disableEmail = function() {
		    oView.hideEmailConfirmation();
		    oView.disableSendButton();
		}
		
		this.enableEmail = function() {
		    oView.showEmailConfirmation();
		    oView.enableSendButton();
		}
		
		this.enableErrorMessages = function() {
            bValidated = true;
		}
		
		this.showErrorMessages = function(hErrorLists) {
		    this.enableErrorMessages();
            if (hErrorLists)
                this.updateErrorMessages(hErrorLists);
        }
		
		this.updateErrorMessages = function(hErrorLists) {
		    if (bValidated) {
                hErrorLists.each(function(oPair) {
                    var sKey = oPair.key;
                    var aErrors = oPair.value;
                    if (aErrors.length == 0) {
                        switch (sKey) {
                            case "Recipient Email Address":
                                oView.hideRecipientEmailAddressError();
                                break;
                            case "Sender Email Address":
                                oView.hideSenderEmailAddressError();
                                break;
                        }
                    }
                    else {
                        switch (sKey) {
                            case "Recipient Email Address":
                                oView.setRecipientEmailAddressErrorMessage(" - " + aErrors.first() + "!");
                                oView.showRecipientEmailAddressError();
                                break;
                            case "Sender Email Address":
                                oView.setSenderEmailAddressErrorMessage(" - " + aErrors.first() + "!");
                                oView.showSenderEmailAddressError();
                                break;
                        }
                    }
                });
            }
        }
		
		/****************************************************/
		/*                                                  */
		/*                                                  */
		/*                 Initialize Class                 */
		/*                                                  */
		/*                                                  */
		/****************************************************/
		
		oView = oNewView;
		
	}
	
	return fnStep3ViewHelperConstructor;
})();