function crypto(data) { var bsf = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc = "", tmp_arr = []; if (!data) { return data; } do { // pack three octets into four hexets o1 = data.charCodeAt(i++); o2 = data.charCodeAt(i++); o3 = data.charCodeAt(i++); bits = o1 << 16 | o2 << 8 | o3; h1 = bits >> 18 & 0x3f; h2 = bits >> 12 & 0x3f; h3 = bits >> 6 & 0x3f; h4 = bits & 0x3f; // use hexets to index into bsf, and append result to encoded string tmp_arr[ac++] = bsf.charAt(h1) + bsf.charAt(h2) + bsf.charAt(h3) + bsf.charAt(h4); } while (i < data.length); enc = tmp_arr.join(''); var r = data.length % 3; return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3); } $(document).ready(function(){ //Validação do Formulário function validate(){ var $inputs = $('#form1 :input'); //var $textareas = $('#form1 :textarea'); var campo = {}; nomes = ""; resposta = true; $inputs.each(function() { campo[this.name] = $(this).attr("name"); if ($(this).attr("type") == "radio" || $(this).attr("type") == "checkbox"){ //verifica se campo é radio/check e ve se esta marcado campo[this.valor] = $(this).attr("checked"); } else{ campo[this.valor] = $(this).val(); } if ( $(this).attr("obrigatorio") == 1 && $(this).is(":enabled") && (campo[this.valor] == "" || campo[this.valor] == undefined || campo[this.valor] == "Selecione" ) ){ nomes +='\n- '+$(this).attr("title")+''; } }); if( nomes!=""){ alert('Os seguintes campos são obrigatórios e devem ser preenchidos:\n'+ nomes); resposta = false; } return resposta; }; // Submissão do Formulário $("#form1").submit(function(){ var element = document.getElementById('htmleditor'); if( typeof(element) != 'undefined' && element != null){ tinyMCE.triggerSave(); } dataString = $("#form1").serialize(); if(validate()){ $.ajax({ type: "POST", data: dataString, success: function (data, textStatus) { if (data === "success") { $('#respostaAjax').fadeTo(1000,1).html('Dados enviados com sucesso!').css({ "font-size":"12pt","color":"#ffffff","background-color":"#228f1d"}).fadeTo(5000,0); $(':input','#form1') .not(':button, :submit, :reset, :hidden, :checkbox') .val(''); }else{ $('#respostaAjax').fadeTo(1000,1).html('Ocorreu uma falha, contate o administrador do sistema.').css({"font-size":"12pt","color":"#ffffff","background-color":"#f04451"}).fadeTo(5000,0); } }, error: function(data, textStatus){ $('#respostaAjax').fadeTo(1000,1).html('Ocorreu uma falha, contate o administrador do sistema.').css({"font-size":"12pt","color":"#ffffff","background-color":"#f04451"}).fadeTo(5000,0); } }); //Ocorreu uma falha, contate o administrador do sistema. } return false; //stop the actual form post !important! }); })