(function () {
	var $ = jQuery;
	window.Contato = {
		init: init,
		fadeInOut: fadeInOut,
		validacao: validacao
	}
	
	function init(){
		validacao();	
	}
	
	function validacao() {
		jQuery(function($){
		   $("#telefone").mask("(99) 9999-9999",{placeholder:" "});
		});
		$('#contato_form').submit(function(){	 
			var reEmail = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
			
			var nome = $('#nome');
			var telefone = $('#telefone');
			var email = $('#email');
			var mensagem = $('#li_e_concordo');
			var msg = '';
	
			nome.css('background-color','#FFF');
			email.css('background-color','#FFF');
			telefone.css('background-color','#FFF');
			mensagem.css('background-color','#FFF');
			$("#msg").css('color','red');
			
			if(nome.val() == ''){		
				msg = '- Por favor, informe o seu nome.';
				nome.css('background-color','#CCC');
				nome.focus();
			} else if(!reEmail.test(email.val())){		
				msg = '- Email inválido! Por favor, informe o email corretamente.';
				email.css('background-color','#CCC');
				email.val('');
				email.focus();		
			} else if (telefone.val() == ''){		
				msg = '- Por favor, informe o telefone.';
				telefone.css('background-color','#CCC');
				telefone.focus();
			}/*else if (mensagem.val == 0){		
				msg = '- Por favor, escreva a mensagem.';
			}*/

			// Exibe erros
			if(msg == ''){
				//Zera erros
				fadeInOut('msg', '');
				return true;	
			} else{
				fadeInOut('msg', '<img src="/public/imagens/icons/error.png" /> ' + msg);
				return false;
			}
		});	
	}
	
	function fadeInOut(id, msg){
		$('#'+ id).fadeOut('slow',function(){
					$('#'+ id).html(msg);
				});
		$('#'+ id).fadeIn('slow');
	}
})();
jQuery(Contato.init);
