/**** INICIALIZACOES ***/ $(document).ready( function() { createExternalLinks(); if ($("a.contato").length > 0) { addContatoEvent(); } /* Enter da barra de navegação das páginas */ $('.inputPagina').unbind('keypress').keypress(function(evt) { if (evt.keyCode=='13') { window.location.href = "/home/produtos/listarProdutos?restoreList=true&pagina=" + (parseInt($(this).val())-1); return false; } return true; }); }); /**** FIM INICIALIZACOES ***/ /*** ENVIAR 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("

enviando...

"); $("#frm_contato input.bt_enviar").attr("disabled","disabled"); $("#frm_contato input.bt_enviar").addClass("disabled"); var params = $('#frm_contato').serialize(); $.getJSON("/home/contato/enviarAjax", params, function(retorno) { /** rotina para quando o usuario focar no campo a **/ /** mensagem de erro desaparece **/ $("#frm_contato input:not(.bt_enviar)").focus( function() { var classe = $(this).attr("name"); $("#frm_contato ."+classe+" .erro").html(""); }); $("#frm_contato textarea").focus( function(){ $("#frm_contato #err_msg").html(""); }); if (retorno.err_nome) $("#err_nome").html(decodeText(retorno.err_nome)); else $('#err_nome').html(""); if (retorno.err_empresa) $("#err_empresa").html(decodeText(retorno.err_empresa)); else $('#err_empresa').html(""); if (retorno.err_endereco) $("#err_endereco").html(decodeText(retorno.err_endereco)); else $('#err_endereco').html(""); if (retorno.err_cidade) $("#err_cidade").html(decodeText(retorno.err_cidade)); else $('#err_cidade').html(""); if (retorno.err_estado) $("#err_estado").html(decodeText(retorno.err_estado)); else $('#err_estado').html(""); if (retorno.err_cep) $("#err_cep").html(decodeText(retorno.err_cep)); else $('#err_cep').html(""); if (retorno.err_fone) $('#err_fone').html(decodeText(retorno.err_fone)); else $('#err_fone').html(""); if (retorno.err_fax) $('#err_fax').html(decodeText(retorno.err_fax)); else $('#err_fax').html(""); if (retorno.err_email) { $('#err_email').html(decodeText(retorno.err_email)); } else $('#err_email').html(""); if (retorno.err_assunto) $('#err_assunto').html(decodeText(retorno.err_assunto)); else $('#err_assunto').html(""); if (retorno.err_msg) $('#err_msg').html(decodeText(retorno.err_msg)); else $('#err_msg').html(""); if (retorno.msg_erro) $("#frm_contato fieldset").append('
' + decodeText(retorno.msg_erro) + '
'); else $("#frm_contato fieldset .msg_erro").remove(); if (retorno.msg_sucesso) { $("#id_nome").val(""); $("#id_empresa").val(""); $("#id_endereco").val(""); $("#id_cidade").val(""); $("#id_estado").val(""); $("#id_cep").val(""); $("#id_fone").val(""); $("#id_fax").val(""); $("#id_email").val(""); $("#id_assunto").val(""); $("#id_msg").val(""); $("#frm_contato fieldset").append('
Fechar
' + decodeText(retorno.msg_sucesso) + '
'); $("#frm_contato .msg_sucesso a.bt_fechar_msg").click( function() { $(".msg_sucesso").remove(); }); } else { $("#frm_contato fieldset .msg_sucesso").remove(); $("#frm_contato .erro").css("display","block"); } $("#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(); }); } function addContatoEvent() { $("a.contato").click( function(){ if ($("#overlay").length == 0) $("body").append("
"); $("#overlay").css("height",$(document).height() + "px"); $("#overlay").slideDown(400, function() { $.post("/home/contato/inputAjax", { }, function(data) { $("body").append(data); var hwindow = $(window).height(); var himg_ampliada = $("#contato").outerHeight(); var wwindow = $(window).width(); var wfrm = $("#contato").width(); var pos_form = (wwindow-wfrm)/2; /**** centraliza o formulario ****/ $("#contato").css("left",pos_form); if (hwindow <= himg_ampliada) $("#contato").css("top",$(document).scrollTop()+15 + "px"); else $("#contato").css("top",$(document).scrollTop()+((hwindow-himg_ampliada)/2) + "px"); $("#contato").fadeIn(300); $(".bt_fechar").click( function() { $("#contato").fadeOut(300, function(){ $("#overlay").slideUp(400); $("#contato").remove(); }); return false; }); addSubmitContatoEvent(); }); }); return false; }); } /******* FIM CONTATO ********/ function openPopup() { if ($("#overlay").length == 0) $("body").append("
"); $("#overlay").css("height",$(document).height() + "px"); $("#overlay").slideDown(400, function() { $.post("/views/home/popup-home.php", { }, function(data) { $("body").append(data); var hwindow = $(window).height(); var himg_ampliada = $("#popup").outerHeight(); var wwindow = $(window).width(); var wfrm = $("#popup").width(); var pos_form = (wwindow-wfrm)/2; /**** centraliza o formulario ****/ $("#popup").css("left",pos_form); if (hwindow <= himg_ampliada) $("#popup").css("top",$(document).scrollTop()+15 + "px"); else $("#popup").css("top",$(document).scrollTop()+((hwindow-himg_ampliada)/2) + "px"); $("#popup").fadeIn(300); $(".bt_fechar").click( function() { $("#popup").fadeOut(300, function(){ $("#overlay").slideUp(400); $("#popup").remove(); }); return false; }); }); }); } function decodeText(txt) { txt = txt.replace(/\+/g," "); return unescape(txt); } function excluir(msg) { return confirm("Tem certeza que deseja excluir este item '" + msg + "'? Este é um processo irreversível. Clique em OK para confirmar."); } function confirma(msg) { return confirm("Tem certeza que deseja " + msg + "? Este é um processo irreversível. Clique em OK para confirmar."); } function toggleSB(id_sb, op) { $(op).toggleClass("aberto"); $("#" + id_sb).toggle(); } function createExternalLinks() { $("a[rel='externo']").attr("target","_blank"); $("a[rel='externo']").attr("title",$("a[rel='externo']").attr("title") + " (abrirá em nova janela)"); } function getVarLink(str_link, var_name) { var valor = str_link.substring(str_link.indexOf(var_name + "=")); if (valor.search(/&/) != -1) { valor = valor.substring(valor.indexOf(var_name + "="),valor.indexOf("&")); } eval ("var " + valor); return eval(var_name); }