(function($){
	$.Informativo = {

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

			// targets (bind em elementos passando o evento)
			$('.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 != "Informativo por e-mail";
		},

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

		cadastrarEmail : function(e){
			var me = this;
			var nome = me.pegarCampo(e, "nome");
			if(nome != "" && nome != "Seu nome"){
				if(me.validarEmail(e)){
					var m1 = me.pegarCampo(e, "m1");
					$.get('informativo',{m1:m1, nome:nome},function(msg){
						msg = msg.split(',');
						alert(msg[1]); // alerta a mensagem de erro ou de sucesso
						if(parseInt(msg[0])==1) $('.fechar-divopen').click();
					});
				} else {
					me.emitirAlerta('Digite o seu email corretamente', "m1");
				}
			} else {
				me.emitirAlerta('Digite o seu nome', "nome");
			}
		},

		initConfig: function() {
			
		}

	}
})(jQuery);

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