(function($){
	$.Informativo = {

		__constructor : function(){
			var me = this;
			me.initConfig();

			// targets (bind em elementos passando o evento)
			$('.informativo_remover').click(function(e){
				me.removerEmail(e);
				return false;
			});
			
			$('.informativo_cadastrar').click(function(e){
				me.cadastrarEmail(e);
				return false;
			});

		},

		pegarCampo : function(e, campo){
			var me = this;
			return $(e.target).parents('form').find('input[name="'+campo+'"]').val();
		},

		validarEmail : function(e){
			var me = this;
			var email = me.pegarCampo(e, "m1");
			return validarEmail(email) && email != "digite seu e-mail";
		},

		emitirAlerta : function(mensagem, campo){
			alert(mensagem); // mostra a mensagem de erro. Nao deve ser apagada
			$('#'+campo).focus();
		},

		removerEmail : function(e){
			var me = this;
			var nome = me.pegarCampo(e, "nome");
			if(nome != "" && nome != "digite seu nome"){
				if(me.validarEmail(e)){
					var m1 = me.pegarCampo(e, "m1");
					$.get('informativo',{m1:m1, nome:nome, acao:"remover"},function(msg){
						alert(msg); // alerta a mensagem de erro ou de sucesso
					});
				} else {
					me.emitirAlerta('Digite o seu email corretamente', "m1");
				}
			}
		},

		cadastrarEmail : function(e){
			var me = this;
			var nome = me.pegarCampo(e, "nome");
			if(nome != "" && nome != "digite seu nome"){
				if(me.validarEmail(e)){
					var m1 = me.pegarCampo(e, "m1");
					$.get('informativo',{m1:m1, nome:nome,acao:"cadastrar"},function(msg){
						alert(msg); // alerta a mensagem de erro ou de sucesso
					});
				} else {
					me.emitirAlerta('Digite o seu email corretamente', "m1");
				}
			} else {
				me.emitirAlerta('Digite o seu nome', "nome");
			}
		},

		initConfig: function() {
			//
		}

	}
})(jQuery);

$(function(){
	$.Informativo.__constructor();
})
