///*** LINKS EXTERNOS ***///
function createExternalLinks() {
	$("a[rel='externo']").attr("target","_blank");
	$("a[rel='externo']").attr("title",function () {
				this.title += " (abrirá em nova janela)";
			});
}
///*** GERAIS ***///
function decodeText(txt) {
	txt = txt.replace(/\+/g," ");
	return unescape(txt);
}


/*****CONTATO*****/
function submitContato() {
	$("#frm_contato fieldset .msg_sucesso").remove();
	$("#frm_contato fieldset .msg_erro").remove();
	//$("#frm_contato fieldset").append("<p class=\"c_loading\">enviando...</p>");
	$("#frm_contato input.bt_enviar").attr("disabled","disabled");
	$("#frm_contato input.bt_enviar").addClass("disabled");
	var params = $('#frm_contato').serialize();
	var url_submit = $('#frm_contato').attr("action") + "Ajax";
	
	$.getJSON(url_submit,
				params,
				function(retorno) {
					if (retorno.err_nome)
						$("#err_nome").html(decodeText(retorno.err_nome));
					else
						$('#err_nome').html("");
					if (retorno.err_email)
						$('#err_email').html(decodeText(retorno.err_email));
					else
						$('#err_email').html("");
					if (retorno.err_msg)
						$('#err_msg').html(decodeText(retorno.err_msg));
					else
						$('#err_msg').html("");
						
					if (retorno.msg_erro)
						$("#frm_contato fieldset").append('<div class="msg_erro">' + decodeText(retorno.msg_erro) + '</div>');
					else
						$("#frm_contato fieldset .msg_erro").remove();
					if (retorno.msg_sucesso) {
						$("#id_nome").val("");
						$("#id_email").val("");
						$("#id_msg").val("");
						
						$("#frm_contato fieldset").prepend('<div class="msg_sucesso">' + decodeText(retorno.msg_sucesso) + '</div>');
						$("#frm_contato fieldset").append('<a class="msg_sucesso">fechar</a>');

						$("#frm_contato .msg_sucesso").click(function() {
							$("#frm_contato .msg_sucesso").remove();
							return false;
						});
					}
					else {
						$("#frm_contato fieldset .msg_sucesso").remove();
					}
					
					$("label .erro, .msg_erro, .msg_sucesso").fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200);
					$("#frm_contato fieldset p.c_loading").remove();
					$("#frm_contato input.bt_enviar").removeAttr("disabled");
					$("#frm_contato input.bt_enviar").removeClass("disabled");
					$("#frm_contato input.bt_enviar").focus();
					
					
				});
}
/*****FIM CONTATO*****/

// INICIALIZACOES
$(document).ready(function() {
	createExternalLinks();
	if ($("#b_contato").length == 1) {
		$("#frm_contato").submit(function () {
			submitContato();
			return false;
		});
	}
	
	if ($("#b_cardapio").length == 1) {
		$("#imagens a").lightBox();
	}
	
});
///*** FIM LINKS EXTERNOS ***///