$(document).ready(function() { /* botão deixe depoimento */ $(".bt-depoimento").click(function () { $.post("/depoimentos/main/formAjax", {}, function (retorno) { $("body").append(retorno); $("#frm_depoimento").css({ position:"absolute", left:"50%", marginLeft:"-290px", top:"250px", zIndex:"55" }); addSubmitForm(); //Adciona evento para fechar form $("#frm_depoimento a.bt-fechar").click(function () { $("#frm_depoimento").fadeOut(300, function () { $("#frm_depoimento").remove(); }); return false; }); $("#frm_depoimento").fadeIn(300); }); return false; }); }); function addSubmitForm() { $("#frm_depoimento").submit(function () { submitContato(); return false; }); } $("#frm_depoimento").ready(function() {addSubmitForm();}); function submitContato() { $("#frm_depoimento fieldset #msg_sucesso").remove(); $("#frm_depoimento fieldset #msg_erro").remove(); $("#frm_depoimento fieldset").append("

enviando...

"); $("#frm_depoimento input.bt").attr("disabled","disabled"); $("#frm_depoimento input.bt").addClass("disabled"); var params = $('#frm_depoimento').serialize(); $.getJSON("/depoimentos/main/enviarAjax", params, function(retorno) { if (retorno.err_nome) $('#err_nome').html(decodeText(retorno.err_nome)); else $('#err_nome').html(""); if (retorno.err_local) $('#err_local').html(decodeText(retorno.err_local)); else $('#err_local').html(""); if (retorno.err_email) $('#err_email').html(decodeText(retorno.err_email)); else $('#err_email').html(""); if (retorno.err_depoimento) $('#err_depoimento').html(decodeText(retorno.err_depoimento)); else $('#err_depoimento').html(""); if (retorno.msg_erro) $("#frm_depoimento fieldset").append('
' + decodeText(retorno.msg_erro) + '
'); else $("#frm_depoimento fieldset #msg_erro").remove(); if (retorno.msg_sucesso) { $("#frm_depoimento").fadeOut(300, function () { $("#frm_depoimento").remove(); }); $("body").append('
' + decodeText(retorno.msg_sucesso) + 'Fechar
'); $("#msg_sucesso").css({ position:"absolute", left:"50%", marginLeft:"-210px", top:"250px", zIndex:"55" }).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300); $("#msg_sucesso a.bt-fechar").click(function () { $("#msg_sucesso").fadeOut(300, function () { $("#msg_sucesso").remove(); }); return false; }); } else { $("#frm_depoimento fieldset #msg_sucesso").remove(); } $("#frm_depoimento fieldset p.c_loading").remove(); $("#frm_depoimento input.bt").removeAttr("disabled"); $("#frm_depoimento input.bt").removeClass("disabled"); $("#frm_depoimento input.bt").focus(); }); } function decodeText(txt) { txt = txt.replace(/\+/g," "); return unescape(txt); }