/*****CONTATO*****/
function addSubmitContatoEvent() {
	$("#frm_contato").submit(function () {
		submitContato();
		return false;
	});
}
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").attr("disabled","disabled");
	$("#frm_contato input.bt").addClass("disabled");
	
	$.ajax({
		contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
		url : ABS_URL_CONTATO,
		type: 'post',
		data: $('#frm_contato').serialize(),
		datatype: 'json',
		success: function(data) {
			var retorno = eval('('+data+')');
			if (retorno.err_nome)
				$("#err_nome").html(retorno.err_nome);
			else
				$('#err_nome').html("");
			if (retorno.err_email)
				$('#err_email').html(retorno.err_email);
			else
				$('#err_email').html("");
			if (retorno.err_assunto)
				$('#err_assunto').html(retorno.err_assunto);
			else
				$('#err_assunto').html("");
			if (retorno.err_mensagem)
				$('#err_mensagem').html(retorno.err_mensagem);
			else
				$('#err_mensagem').html("");
				
			if (retorno.msg_erro)
				$("#frm_contato fieldset").append('<div class="msg_erro">' + retorno.msg_erro + '</div>');
			else
				$("#frm_contato fieldset .msg_erro").remove();
			if (retorno.msg_sucesso) {
				$("#nome").val("");
				$("#email").val("");
				$("#assunto").val("");
				$("#mensagem").val("");
				$("#frm_contato fieldset").append('<div class="msg_sucesso">' + retorno.msg_sucesso + '</div>');
				$("#frm_contato fieldset .msg_sucesso").click(function() {
					$(this).remove();
				});
				if (retorno.link_produto) {
					document.location.href = retorno.link_produto;
				}
			}
			else {
				$("#frm_contato fieldset .msg_sucesso").remove();
			}
			$("#frm_contato fieldset p.c_loading").remove();
			$("#frm_contato input.bt").removeAttr("disabled");
			$("#frm_contato input.bt").removeClass("disabled");
			$("#frm_contato input.bt").focus();
	}});
}

/*****FIM CONTATO*****/

///*** LINKS EXTERNOS ***///
function createExternalLinks() {
	$("a[rel='externo'], a[class*='externo']").attr("target","_blank").attr("title",function () {
				this.title += " (abrirá em nova janela)";
			});
}


$(document).ready(function() {
	createExternalLinks();
});
