function cadastrarEmail(email) {
	var valores = 'email='+email+'&mode=adicionar&ajax=true';
	
	$.ajax({
		type: 'post',
		dataType: 'json',
		url: SITE_URL+'/app/newsletter.php',
		data: valores,
		success: function(data) {
			if(data) {
				if(data.success) {
					alertar('Seu e-mail foi cadastrado com sucesso. Voc&ecirc; receber&aacute; um email de valida&ccedil;&atilde;o em breve!');
				} else {
					alertar(data.error);
				}
			} else {
				alertar('Houve um erro ao tentar cadastrar seu e-mail.');
			}
		}
	});
}

/**
 * Verifica se o email esta no formato login@domain.com
 * @param email object
 * @return bool
 */
function validaEmail(email) {
	if(/(?:[a-zA-Z0-9\.\-\_]+)\@(?:[a-zA-Z0-9\.\-\_]+)\.(?:[a-zA-Z0-9]+)/.test(email.val()) == false) {
		return false;	
	}
	return true;
}

function alertar(msg, callback, titulo, destroy) {
	var t;
	var kill;
	
	if(titulo != '' && titulo != null && titulo != 'undefined' && titulo != false) {
		t = titulo;
	} else {
		t = 'Alerta';
	}
	
	if(destroy === false) {
		kill = false;
	} else {
		kill = true;
	}
	
	$('<div></div>').html(msg).dialog({modal: true, 
										title: t, 
										buttons: { "OK" : function() {
																if(callback != null && callback != 'undefined') {
																	callback();
																}
																if(kill)
																	$(this).remove();
															} 
													}
										});
}
