(function($){$.fn.saAjaxMail=function(k){var l={mensagem_sucesso:"Formulário enviado com sucesso!",mensagem_erro_campo:'O campo "{{campo}}" não foi preenchido corretamente!',mensagem_erro_arquivo:'O arquivo "{{campo}}" não foi enviado ou é inválido!'};if(k)$.extend(l,k);this.each(function(j){if($(this).attr("nodeName").toLowerCase()=="form"){l.id='ifrmajax_'+j+'_'+(new Date().getTime());$(this).attr('iframeid',l.id);$(this).bind("sendToIFrame",{'config':l},function(f){var g=f.data.config;$("iframe#"+g.id).remove();var h=$("<iframe name="+g.id+"/>").attr("id",g.id).attr("name",g.id).attr("src","").attr("width","0").attr("height","0").attr("marginWidth","0").attr("marginHeight","0");$("body").append(h);var i=new Date().getTime();$(this).attr("action",g.template+"?time="+i).attr("target",g.id);$(this).unbind("submit");$("iframe#"+g.id).load(function(){$("[iframeid="+g.id+"]").find("input, textarea, select").removeClass("erro");var d=$(this).contents().find("body > div#response > div");if(d.length==0&&$.trim($(this).contents().find("body > div#response").html())=="")$("form[iframeid="+g.id+"]").replaceWith("<div class='sucesso'>"+g.mensagem_sucesso+"</div>");else if(d.length>0){var e=d.length>1?"ERROS:\n":"ERRO:\n";d.each(function(a,b){switch($(b).attr("tipocampo")){case"campo":if(g.mensagem_erro_campo!==false)e=e+"\n"+(g.mensagem_erro_campo.replace('{{campo}}',$(b).html()));break;case"arquivo":if(g.mensagem_erro_arquivo!==false)e=e+"\n"+(g.mensagem_erro_arquivo.replace('{{campo}}',$(b).html()));break}var c=$(b).attr('focusid');$("form.email_ajax [name="+c+"]").addClass('erro')});alert(e)}else alert($(this).contents().find("body > div#response").html())});$(this).submit();$(this).bind("submit",function(){$(this).trigger("sendToIFrame");return false})});$(this).bind("submit",function(){$(this).trigger("sendToIFrame");return false})}});return this}})(jQuery);