(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);
			$('#'+campo).focus();
		},

		cadastrarEmail : function(e){
			var me = this;
			var nome = me.pegarCampo(e, "nome");
			var veiculo = me.pegarCampo(e, "veiculo");
			var idade = me.pegarCampo(e, "idade");
			var nascimento = me.pegarCampo(e, "nascimento");
			if(nome != ""){
				if(me.validarEmail(e)){
					if(veiculo != ""){
						if(nascimento != ""){
							var m1 = me.pegarCampo(e, "m1");
							$.get('informativo',{m1:m1,nome:nome,veiculo:veiculo,idade:idade,nascimento:nascimento},function(msg){
								alert(msg); // alerta a mensagem de erro ou de sucesso
							});
						} else {
							me.emitirAlerta('Informe a data do seu nascimento', "m1");
						}
					} else {
						me.emitirAlerta('Informe o veículo onde trabalha', "m1");
					}
				} else {
					me.emitirAlerta('Digite o seu email corretamente', "m1");
				}
			} else {
				me.emitirAlerta('Digite o seu nome', "nome");
			}
		},

		initConfig: function() {
			
		}

	}
})(jQuery);

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