$(document).ready(function(){
	$("#nome, #email").focus(function(){
		if( $(this).val() == $(this).attr('id') )
			$(this).val(''); 
	});
	$("#nome, #email").blur(function(){
		if( $(this).val() == '' )
			$(this).val($(this).attr('id')); 
	});
	$("#newsletter_form").submit(function(){
		var data = $("#newsletter_form").serialize();
		var error = false;
		$("#nome, #email").each(function(){
			if( $(this).val() == '' )
				error = true;
		});
		
		if( !error ){
			$("#status_newsletter").text('Aguarde, enviando...');
			$.ajax({
				data: data,
				url: webroot + 'home/cadastra_newsletter',
				dataType: 'json',
				type: 'post',
				success: function(retorno){
					if( retorno.result == true ){
						$("#status_newsletter").html('Newsletter cadastrado <br>com sucesso.').css('color','#F7921E');
						$("#nome, #email, #envia").css('visibility','hidden');
					}else{
						for( i in retorno ){
							$("#status_newsletter").text(retorno[i]).css('color','#F7921E');
						}
					}
				}
			})
		}
		
		return false;
	});
});
