var ef=jQuery; ef.noConflict(); ef(document).foundation(); /*-------------------------------------------------------*/ /*------------------- Main Variables --------------------*/ /*-------------------------------------------------------*/ /* To top */ var $totop = true; /*-------------------------------------------------------*/ /*-------------------------------------------------------*/ /*-------------------------------------------------------*/ ef(document).ready(function() { if (ef.fn.cssOriginal!=undefined) ef.fn.css = ef.fn.cssOriginal; /* Replace *.svg to *.png in browsers that doesn't support svg */ if(!Modernizr.svg) { ef('img[src*="svg"]').attr('src', function() { return ef(this).attr('src').replace('.svg', '.png'); }); } /*Select2*/ ef("#Pet_Tipo").select2({ width: 'resolve' }); ef("#Pet_Raca").select2({ width: 'resolve' }); ef("#Pet_Sexo").select2({ width: 'resolve' }); ef("#Pet_Tamanho").select2({ width: 'resolve' }); ef("#Pet_Pedigree").select2({ width: 'resolve' }); ef("#User_Sexo").select2({ width: 'resolve' }); /*Validation*/ ef.validator.messages.required = 'Campo necessário'; ef.validator.messages.email = 'O e-mail deve ser válido'; ef.validator.messages.equalTo = 'Repetição não confere'; ef.validator.messages.digits = 'Somente números'; ef.validator.messages.remote = ef.validator.format("esse email já está sendo utilizado, favor escolher outro"); ef.validator.addMethod("exactlength", function(value, element, param) { return this.optional(element) || value.length == param; }, ef.format("Somente {0} números. Ex. 1975")); ef.validator.addMethod("exactcep", function(value, element, param) { return this.optional(element) || value.length == param; }, ef.format("Somente números. Ex. 04533005")); ef('#add-pet').validate({ submitHandler: function(form) { if(grecaptcha.getResponse() == "") { ef(".form-msg-error").html('Favor validar o campo Não sou um Robô!'); ef(".form-msg-error").show(); } else { form.submit(); } }, invalidHandler: function(event, validator) { // 'this' refers to the form var errors = validator.numberOfInvalids(); if (errors) { var message = errors == 1 ? 'Favor preencher corretamente o campo destacado em Vermelho' : 'Favor preencher corretamente os ' + errors + ' campos destacados em Vermelho'; ef(".form-msg-error").html(message); ef(".form-msg-error").show(); //console.log(grecaptcha.getResponse()); //console.log(1); } else { ef(".form-msg-error").hide(); } }, rules:{ User_Senha2:{ equalTo: '#User_Senha' }, User_Email2:{ equalTo: '#User_Email' }, User_Email:{ email: true, "remote":{ url: "email", type: "post", data:{ email: function(){ return ef('#User_Email').val(); } } } }, User_Telefone:{ // digits: true }, User_Nasc:{ exactlength: 4, digits: true }, Pet_Ano:{ exactlength: 4, digits: true }, Pet_CEP:{ exactcep: 8, digits: true }, Pet_Outra:{ required: { depends: function(element){ if( ef("#Pet_Raca").val()=="44" || ef("#Pet_Raca").val()=="68" || ef("#Pet_Raca").val()=="69" || ef("#Pet_Raca").val()=="86" || ef("#Pet_Raca").val()=="102" || ef("#Pet_Raca").val()=="104" ) return true; } } } } }); /*CEP*/ ef('#Pet_CEP').focusout(function () { ef('#FeedbackCEP').html(""); //ef('#FeedbackCEP').html("
Carregando cidade à partir do CEP...
Dica.: Se demorar muito pode continuar preenchendo o formulário, não se preocupe com isso.
Seu pet reside em " + unescape(obj.localidade) + " - " + unescape(obj.uf) + "
\n"; ef('#Pet_Cidade').val(unescape(obj.localidade)); ef('#Pet_Estado').val(unescape(obj.uf)); ef('#FeedbackCEP').html(msgCEP); }else{ msgCEP = "CEP inválido. Verifique se os números estão corretos. Se o erro persistir, por favor, nos mande um email
\n"; ef('#Pet_CEP').val(''); //ef('#Pet_CEP').focus(); ef('#Pet_Cidade').val(''); ef('#Pet_Estado').val(''); ef('#FeedbackCEP').html(msgCEP); */ /*ef.ajax({ url: "https://correiosapi.apphb.com/cep/"+cep, dataType: 'jsonp', crossDomain: true, contentType: "application/json", statusCode: { 200: function(data) { // Ok console.log(data); msgCEP = "Seu pet reside em " + unescape(data.cidade) + " - " + unescape(data.estado) + "
\n"; ef('#Pet_CEP').val(cep); ef('#Pet_Cidade').val(unescape(data.cidade)); ef('#Pet_Estado').val(unescape(data.estado)); ef('#FeedbackCEP').html(msgCEP); } ,400: function(msg) { console.log(msg); } // Bad Request ,404: function(msg) { console.log("CEP não encontrado!!"); } // Not Found } });*/ ef.get("https://cruzapet.com.br/api/cep-search.php?cep=" + cep).done(function(data) { console.log(data); if(typeof data.uf !== 'object'){ msgCEP = "Seu pet reside em " + unescape(data.cidade) + " - " + unescape(data.uf) + "
\n"; ef('#Pet_CEP').val(cep); ef('#Pet_Cidade').val(unescape(data.cidade)); ef('#Pet_Estado').val(unescape(data.uf)); ef('#FeedbackCEP').html(msgCEP); } else{ console.log("CEP não encontrado!!") } }); /* } } }); */ }); /* Show Continuar */ ef('#contButton').click(function () { ef('#contPouco').hide() ef('#contDiv').show() ef('html,body').animate({ scrollTop: ef('#contDiv').offset().top }, 1200); return false; }); /* plupload */ ef(function() { var rand = function() { return Math.random().toString(36).substr(2); // remove `0.` }; var token = rand() + rand(); // to make it longer ef('#file_token').val(token); var uploader = new plupload.Uploader({ runtimes : 'html5,html4', url : 'https://pets-cruzapet.s3.amazonaws.com/', browse_button : 'pickfiles', // you can pass an id... container: 'file_container', // ... or DOM Element itself multipart: true, multipart_params: { 'key': '${filename}', // use filename as a key 'Filename': '${filename}', // adding this to keep consistency across the runtimes 'acl': 'public-read', 'Content-Type': 'image/jpeg', 'AWSAccessKeyId' : 'AKIAIZ3RUUU5PUH3UWCA', 'policy': 'eyJleHBpcmF0aW9uIjoiMjAyNS0wNC0wM1QwNDo1NDo1MC4wMDBaIiwiY29uZGl0aW9ucyI6W3siYnVja2V0IjoicGV0cy1jcnV6YXBldCJ9LHsiYWNsIjoicHVibGljLXJlYWQifSxbInN0YXJ0cy13aXRoIiwiJGtleSIsIiJdLFsic3RhcnRzLXdpdGgiLCIkQ29udGVudC1UeXBlIiwiaW1hZ2VcLyJdLFsic3RhcnRzLXdpdGgiLCIkbmFtZSIsIiJdLFsic3RhcnRzLXdpdGgiLCIkRmlsZW5hbWUiLCIiXV19', 'signature': 'cJpxWPqXqZA3oaf9M5WQsLq3zBw=' }, // !!!Important!!! // this is not recommended with S3, since it will force Flash runtime into the mode, with no progress indication resize : {width : 800, height : 600}, // Resize images on clientside, if possible // optional, but better be specified directly file_data_name: 'file', filters : { // Maximum file size max_file_size : '10mb', // Specify what files to browse for mime_types: [ {title : "Somente Imagens", extensions : "jpg,gif,png,jpeg"} ] }, preinit : { UploadFile: function(up, file) { console.log(file); var filename = file.id + '__' + rand() + '.' + file.name.split('.').pop(); up.settings.multipart_params.key = filename; file.filename = filename; } }, init: { PostInit: function() { // document.getElementById('filelist').innerHTML = ''; ef('#filelist').html(''); }, FilesAdded: function(up, files) { plupload.each(files, function(file) { // document.getElementById('filelist').innerHTML += 'Carregando...