jQuery.Class("Atoms_MSmtp",{},{

	registerRedirectModule: function(){
		var form = jQuery("#massEmailForm");
		if(form.length){
			var prev_module = form.find("input[name='module']").val();
			var source_module = form.find( "input[name='source_module']" ).val();
			if(prev_module == 'Emails' ){
				var html = '<div class="row "><div class="col-lg-12"><div class="col-lg-2"><span class="pull-right">Subject&nbsp;<span class="redColor">*</span></span></div><div class="col-lg-6"><input type="text" name="subject" value="" data-rule-required="true" id="subject" spellcheck="true" class="inputElement"></div><div class="col-lg-4"></div></div></div>'
				var params = {
					'module' : 'AtomsMSmtp',
					'action': 'getServerSelectHtml'
				};
				app.request.post({'data' : params}).then(
					function(err, data) {
						if(err === null){
							jQuery(data).insertBefore('.toEmailField');	
							jQuery("#serverMSId").select2({});
						}
					}
				);
				form.find("input[name='module']").val('AtomsMSmtp');
			}
		}
	},	

	registerEvents : function(){
		var thisInstance = this;
		thisInstance.registerRedirectModule();
	}
});

jQuery(document).ready(function(e){
                var instance = new Atoms_MSmtp();
                instance.registerEvents();
		$( document ).ajaxComplete(function() {
                	var instance = new Atoms_MSmtp();
                	instance.registerEvents();
		});
});
