function ShowAjaxModal(n,t){$(globalSpinner).appendTo("#"+t+" .modal-content");$.ajax({type:"GET",url:n,success:function(n){$("#"+t).html(n);$("#"+t).modal({backdrop:"static",keyborard:!1});$("#"+t).modal("show");initMasks();$.validator.unobtrusive.parse($("#"+t))},error:function(){$("#"+t+" .modal-content .spinner-parent").remove()}})}function getCookie(n){var t=document.cookie.match("(^|;) ?"+n+"=([^;]*)(;|$)");return t?t[2]:null}function AjustarFonteProduto(){var n,t;if($(".product-title").css("font-size",""),n=$(".product-title").get(0),n){for(t=30;n.offsetWidth12;)t=t-1,$(n).css("font-size",t+"px");t<13&&$(n).css("white-space","normal")}AjustarPaddingItemModal()}function CarregarItemDetalhes(n){var t=$("#btnItemSubmit").attr("disabled");$("#btnItemSubmit").attr("disabled","disabled");$("#itemModal .modal-content #etapa1detalhes").html('
<\/i><\/div>').load("/pedido/cardapioitemdetalhes/"+n,function(n,i){i==="success"?($.validator.unobtrusive.parse(this),t||$("#btnItemSubmit").removeAttr("disabled")):($.notify('<\/i> Não foi possível carregar este item, por favor, tente novamente.'),$("#itemModal").modal("hide"))})}function AjustarPaddingItemModal(){if(window.matchMedia("(max-width: 767px)").matches){var n=$("#itemModal .modal-header").outerHeight(!0)||67;$("#itemModal .modal-body").css("padding-top",n+0+"px")}else $("#itemModal .modal-body").css("padding-top","")}function validarPergunta(n){var t=null,o=n.data("id"),i=$("[data-parent="+o+"]"),r,u,f,e;return i.filter('input[type="radio"]').length>0?(r=i.filter('input[type="radio"]:checked').length,r0&&r>n.data("opc-max")&&(t="Selecione no máximo "+n.data("opc-max"))):i.filter('input[type="checkbox"]').length>0?(u=i.filter('input[type="checkbox"]:checked').length,u0&&u>n.data("opc-max")&&(t="Selecione no máximo "+n.data("opc-max"))):(f=0,e=0,i.filter('input[type="number"]').each(function(){var n=parseInt($(this).val())||0;e+=n;n>0&&f++}),f0&&f>n.data("opc-max")&&(t="Selecione no máximo "+n.data("opc-max")),e0&&e>n.data("item-max")&&(t="Escolha no máximo "+n.data("item-max"))),t?(ExibirErro(o,t),!1):!0}function OnBeginAdd(){var n=!0;if($("[data-pergunta]").each(function(){var t=validarPergunta($(this));if(!t)return n=!1,!1}),!n)return!1;if(!JSON.parse(unescape(decodeURI(getCookie("MdCurLoc")))))return $modalPendente=$(this).parents(".modal"),$clickPendente=$(this).find(":submit"),$modalPendente&&$modalPendente.modal("hide"),ShowAjaxModal("/endereco/listarendereco","cepModal"),!1;$(globalSpinner).appendTo("#itemModal .modal-content")}function OnSuccessAdd(n){if(n){if(n.status)if(n.status===201||n.status===200)atualizarCarrinho(),$("#itemModal").modal("hide");else if(n.status===409){$.notify("<\/i> "+n.message);var t;t=$('input[name*="CodigoTamanhoSelecionado"]:checked').length>0?$('input[name*="CodigoTamanhoSelecionado"]:checked').data("uuid"):$("#Produto_CodigoGuid").val();CarregarItemDetalhes(t)}else(n.status===400||n.status===500)&&(n.id?ExibirErro(n.id,n.message):$.notify("<\/i> "+n.message));else $("#etapa1").hide(),$("#etapa2").html(n).show(),$("#btnItemSubmit i").toggleClass("fa-arrow-right",!1),$("#btnItemSubmit i").toggleClass("fa-plus",!0);$("#itemModal .modal-content .spinner-parent").remove()}}function ExibirErro(n,t){var i=$("[value="+n+"]").parents(".panel"),r,u;$("#itemModal .modal-body").scrollTop($("#itemModal .modal-body").scrollTop()+i.offset().top-70);i.find("input:visible:first").focus();i.animo({animation:"shake"});r=i.closest("form").validate();u=$('input[value="'+n+'"]');r.showErrors(JSON.parse('{ "'+$(u).attr("name")+'": "'+t+'"}'))}function atualizarCarrinho(){$("#carrinho").append(globalSpinner).load("/pedido/carrinho?resume=true",function(){$.validator.unobtrusive.parse(this);$("[data-cart-open]").html($("#carrinho a").html());$(" Ver carrinho<\/span>").insertAfter("#verCarrinho a em");$(".carrinho-qtd").parent().animo({animation:"tada"});$("#verCarrinho").toggleClass("hide",!(Number($(".carrinho-qtd").html())>0))});$("#pedidoModal .modal-content").append(globalSpinner).load("/pedido/carrinho",function(){$.validator.unobtrusive.parse(this)});$("[data-load]").each(function(){$(this).append(globalSpinner).load($(this).data("load"),function(){$.validator.unobtrusive.parse(this)})})}function initAutocomplete(){$("#HabilitarGoogleAutocomplete")&&$("#HabilitarGoogleAutocomplete").val()==="True"&&!autocomplete&&(document.getElementById("Logradouro")===null||document.getElementById("Logradouro").disabled||(autocomplete=new google.maps.places.Autocomplete(document.getElementById("Logradouro")),autocomplete.addListener("place_changed",fillInAddress)))}function fillInAddress(){var n=autocomplete.getPlace(),f,o,r,u,s,h,t,i,e;for(u=$("#Estabelecimento.EndEstado").val(),n.types[0]!=="route"&&(h=n.place_id),t=0;t<\/option>").val(r).text(r)),e.attr("value",e.val()),$("#Cidade").val(r),$("#Estado").val(u),$("#Estado").attr("value",u),$("#Bairro").val(o),$("#Cep").val(s),$("#PlaceIdGoogle").val(h),$("#Numero").focus()):($("#Logradouro").val(null),$("#Cidade").val(null),$("#Estado").val(null),$("#Bairro").val(null),$("#Cep").val(null),$("#PlaceIdGoogle").val(null),$("#EnderecoCompletoGoogle").val(null))}function OnBeginSpinner(){$(globalSpinner).appendTo($(this))}function OnSuccessBuscarCep(n){$("#cepModal").html(n);initMasks();$.validator.unobtrusive.parse($("#cepModal"))}function OnBeginCompletarEndereco(){var n=$(this).validate();if($("#Complemento").val()===""&&!$("#chkComplemento").prop("checked"))return n.showErrors({Complemento:"Informe um complemento ou marque 'Não tenho'."}),$("#Complemento").focus(),!1;$(globalSpinner).appendTo($(this))}function OnSuccessCompletarEndereco(n){n&&(n===!0?(atualizarCarrinho(),$("#cepModal").modal("hide"),$("#cepModal .modal-content .spinner-parent").remove(),$clickPendente&&$clickPendente.parents(".modal").modal("show")):($("#cepModal").html(n),initMasks(),$.validator.unobtrusive.parse($("#cepModal"))))}function OnSuccessAgendamento(n){$("#agendamentoPedido").html(n);$("#agendamentoModal").modal("hide")}function GetURLParameter(n){for(var i,u=window.location.search.substring(1),r=u.split("&"),t=0;t0&&(t===0?n=parseFloat($("input[name*=CodigoTamanhoSelecionado]:checked").data("precovenda")):(u=$("#CobrarPeloMaiorValor").val()==="true",r=[],$("input[name*=CodigosPartesSelecionadas]:checked").each(function(){r.push(parseFloat($(this).data("precovenda")))}),u?n=Math.max.apply(Math,r):(n=0,$.each(r,function(){n+=this/t}))));i=0;$("#itemModal input[type=number][data-precovenda]").each(function(){var r=parseInt($(this).val())||0,n;r>0&&(n=parseFloat($(this).data("precovenda")),this.name.indexOf("PartesSelecionadas")>-1&&(n=n/t),i+=$(this).val()*n)});$("#itemModal input[type=checkbox][name*=PerguntasSelecionadas][data-precovenda]:checked").each(function(){var n=parseFloat($(this).data("precovenda"));i+=n});$("#itemModal input[type=radio][name*=PerguntasSelecionadas][data-precovenda]:checked").each(function(){var n=parseFloat($(this).data("precovenda"));this.name.indexOf("PartesSelecionadas")>-1&&(n=n/t);i+=n});$("#PrecoTotal").text("R$ "+Number(f*(n+i)).toFixed(2).replace(".",",")).animo({animation:"tada"});$("#produtoModalNome").text(function(){var n=$("#Produto_NomeProdutoCompleto").val();return t>1&&(n=$("#Produto_NomePersonalizado").val(),$("input[name*=CodigoTamanhoSelecionado]:checked").length&&(n+=" "+$("input[name*=CodigoTamanhoSelecionado]:checked").data("nome"))),n});window.matchMedia("(max-width: 767px)").matches&&$("#itemModal .modal-body").scroll()},o)}function s(){$("#notfound").removeClass("hidden");$(".categories > li").each(function(){$(this).children(".products").children("li:not(.hidden)").length>0?($(this).removeClass("hidden"),$("#notfound").addClass("hidden")):$(this).addClass("hidden")})}var e,o,n;$(document).on("show.bs.modal",".modal",function(){var n=1040+10*$(".modal:visible").length;$(this).css("z-index",n);setTimeout(function(){$(".modal-backdrop").not(".modal-stack").css("z-index",n-1).addClass("modal-stack")},0)});$(".modal").on("shown.bs.modal",function(){$("html").addClass("freezePage");$("body").addClass("freezePage")});$(".modal").on("hidden.bs.modal",function(){$("html").removeClass("freezePage");$("body").removeClass("freezePage")});$(document).on("click",'a[href="#"]',function(n){n.preventDefault?n.preventDefault():n.returnValue=!1});$("form.navbar-form").submit(function(n){n.preventDefault();$("html, body").animate({scrollTop:$(".cardapio-body").offset().top},500)});jQuery.expr[":"].contains=jQuery.expr.createPseudo(function(n){return function(t){return jQuery(t).text().toUpperCase().indexOf(n.toUpperCase())>=0}});var t=0,i=0,u=0,f=0;$(document).on("touchstart",".modal-content",function(n){t=n.originalEvent.changedTouches[0].screenX;u=n.originalEvent.changedTouches[0].screenY});$(document).on("touchend",".modal-content",function(n){i=n.originalEvent.changedTouches[0].screenX;f=n.originalEvent.changedTouches[0].screenY;Math.abs(i-t)>Math.abs(f-u)&&Math.abs(f-u)<50&&Math.abs(i-t)>50&&(i>t?$(this).parents(".modal").modal("hide"):i0?$('input[name*="CodigoTamanhoSelecionado"]:checked').data("uuid"):$("#Produto_CodigoGuid").val();n&&CarregarItemDetalhes(n);$("#itemModal .modal-body").on("scroll",function(){var n=$(this).scrollTop();$("#itemModal .modal-header").toggleClass("header-shrink",n>80)});$("#itemModal .modal-header").on("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",function(){AjustarPaddingItemModal()})})))});$("#itemModal").on("shown.bs.modal",function(){AjustarFonteProduto()});$(document).on("change","input[name*=CodigoTamanhoSelecionado]",function(){CarregarItemDetalhes($('input[name*="CodigoTamanhoSelecionado"]:checked').data("uuid"));r()});$(document).on("change","input[name*=CodigosPartesSelecionadas]",function(){var t=$('input[name*="CodigoTamanhoSelecionado"]:checked').data("qtdmaximapartes"),n=$("input[name*=CodigosPartesSelecionadas]:checked").length;n===1?($(".meioameio").toggleClass("hide",!0),$("#Quantidade").data("val-range-max",$("#Quantidade").data("val-range-max-old")),$("#Quantidade").removeData("val-range-max-old")):n>t?($(this).prop("checked",!1),$(this).parent().animo({animation:"shake"}),$("#QuantidadeMaximaPartes").parent().animo({animation:"shake"})):$(".meioameio").removeClass("hide");r()});$(document).on("change","#Quantidade",function(){var n=parseFloat($("#Quantidade").val()||1);!n||n<$("#Quantidade").data("val-range-min")?(n=$("#Quantidade").data("val-range-min"),$("#Quantidade").val(n)):n>$("#Quantidade").data("val-range-max")&&(n=$("#Quantidade").data("val-range-max"),$("#Quantidade").val(n));r()});$(document).on("change","input[type=checkbox][data-parent],input[type=radio][data-parent]",function(){var n=$(this).data("parent"),t=$('[data-id="'+n+'"]'),i=$('input[type="checkbox"][data-parent="'+n+'"]:checked,input[type="radio"][data-parent="'+n+'"]:checked').length;t.data("opc-max")>0&&i>t.data("opc-max")&&($(this).prop("checked",!1),$(this).parent().animo({animation:"shake"}),$(this).parents(".panel").children(".panel-heading").animo({animation:"shake"}));r()});$(document).on("change","input[type=number][data-precovenda]",function(){var n=parseInt($(this).val())||0,u=parseInt($(this).data("old")||$(this).data("val-range-min"))||0,t;if(Number.isNaN(parseInt($(this).val()))||n<$(this).data("val-range-min")?(n=$(this).data("val-range-min"),$(this).val(u)):n>$(this).data("val-range-max")&&(n=$(this).data("val-range-max"),$(this).val(u)),t=$(this).data("parent"),t){var i=$('[data-id="'+t+'"]'),f=!0,e=0,o=0;$('input[type="number"][data-parent="'+t+'"]').each(function(){var n=parseInt($(this).val())||0;o+=n;n>0&&e++});i.data("opc-max")>0&&e>i.data("opc-max")?f=!1:i.data("item-max")>0&&o>i.data("item-max")&&(f=!1);f||($(this).val(u),$(this).parent().animo({animation:"shake"}),$(this).parents(".panel").children(".panel-heading").animo({animation:"shake"}))}$(this).data("old",$(this).val());r()});o=500;$("#search").on("input propertychange paste",function(){$(".products > li").removeClass("hidden");$(".products .name").find("mark").contents().unwrap();var n=$(this).val();n!==""&&n.length>2&&n.split(" ").forEach(function(n){if(n.length>2){$('.products > li:not(:contains("'+n+'"))').addClass("hidden");var t=new RegExp("("+n.trim().split(/\s+/).join("|")+")(?!([^<]+)?>)","gi");$(".products .name").html(function(n,i){return i.replace(t,"$1<\/mark>")})}});s()});$(document).on("click","#agendamentoCancelar",function(){$.post("/pedido/RemoverAgendamento",null,function(n){$("#agendamentoPedido").html(n)})});$(document).on("click",".btn-minus",function(){var n=$(this).parent().siblings("input"),t=parseInt($(n).val())-1;$(n).val(t).change()});$(document).on("click",".btn-plus",function(){var n=$(this).parent().siblings("input"),t=parseInt($(n).val())+1;$(n).val(t).change()});$(document).on("click",".btnRemover",function(n){n.preventDefault();n.stopPropagation();var t=$(this).closest("tr");$.post("/pedido/delitem",{codigoPedidoItem:$(this).data("id")},function(n){$.notify("<\/i> "+n.message);atualizarCarrinho()});t.hide("slow",function(){t.remove()})});$(document).on("click",".btnRemoverTodos",function(n){n.preventDefault();n.stopPropagation();$.post("/pedido/delallitem",null,function(n){$.notify("<\/i> "+n.message);atualizarCarrinho()})});$(document).on("click",".cboTipoEntrega",function(n){if(n.preventDefault(),n.stopPropagation(),$(this).hasClass("active"))$("#cepModal").modal("hide");else{var t=$(this).data("id");t===1?ShowAjaxModal("/endereco/definirdelivery","cepModal"):$.post("/pedido/definirretirarnoestabelecimento",{codigoTipoEntrega:t},function(n){$("#cepModal").modal("hide");$.notify("<\/i> "+n.message);atualizarCarrinho()})}});atualizarCarrinho();$(document).on("click","[data-cart-open]",function(n){n.preventDefault();n.stopPropagation();$("#carrinho > a").trigger("click")});$("#carrinho").on("hidden.bs.dropdown",function(){$(".navbar-collapse").collapse("hide")});n=!1;$(document).on("hide.bs.modal",function(t){n?n=!1:history.pushState({show:!1,modal:t.target.id},t.target.id,location.href)});$(document).on("show.bs.modal",function(t){n&&(n=!1);var i=null;t.relatedTarget&&t.relatedTarget.dataset?i=t.relatedTarget.dataset.uuid:history.pushState({show:!0,modal:t.target.id,uuid:i},t.target.id,location.href)});$(window).on("popstate",function(t){n=!0;var i=t.originalEvent.state;i?i.modal&&(i.show?i.uuid?$("a[data-uuid='"+i.uuid+"']").trigger("click"):$("#"+i.modal).modal("show"):($("#"+i.modal).data("bs.modal")||{}).isShown&&($("#"+i.modal).modal("hide"),$("body").removeClass("modal-open"),$(".modal-backdrop").remove())):($(".modal").data("bs.modal")||{}).isShown&&($(".modal").modal("hide"),$("body").removeClass("modal-open"),$(".modal-backdrop").remove())});$(document).on("click",".btnTipoEntrega",function(){$(".btnTipoEntrega").toggleClass("active",!1);$("#TipoEntrega_Codigo").val($(this).data("id"));$("#divEnderecoEstabelecimento").toggleClass("hide",$(this).data("id")===1);$(this).toggleClass("active",!0)});$(document).on("change","#chkComplemento",function(){this.checked?($("#Complemento").val(""),$("#Complemento").prop("readonly",!0)):$("#Complemento").prop("readonly",!1)});$(document).on("change","#Cidade",function(){$(this).attr("value",$(this).val())});$(document).on("change","#Estado",function(){$(this).attr("value",$(this).val());$.post("/endereco/carregarcidades",{estado:$(this).val()},function(n){var t=$("#Cidade");t.empty();t.append($("