$(document).ready(function(){function h(t,e){return cases=[2,0,1,1,1,2],e[t%100>4&&20>t%100?2:cases[5>t%10?t%10:5]]}function x(t){y($(t).html())}function y(t){var e=window.open("","mydiv","width=1024,height=768");return e.document.write("Оформление заказа"),e.document.write(""),e.document.write(""),e.document.write(t),e.document.write(""),e.document.close(),e.focus(),e.print(),e.close(),!0}var t="Арт.: №",e="№",r="Категория",a="Название",c="Артикул",_="Дата",o="Кол-во",l="Цена",n="Удаление",s=".wc_col_4",d=new FormData,p=!1;for($(".wc_lightbox_form_count input").val("1"),$(".wc_lightbox_form_count input").attr("readonly","readonly"),$(".wc_lightbox_count_up").on("click",function(){999!=+$(".wc_lightbox_form_count input").val()&&$(".wc_lightbox_form_count input").val(+$(".wc_lightbox_form_count input").val()+1),999==+$(".wc_lightbox_form_count input").val()&&$(".wc_lightbox_form_count input").val("1"),$(".wc_lightbox_form_price input").val(+$(".wc_lightbox_form_count input").val()*+$(".wc_lightbox_form_price input").attr("data-price"))}),$(".wc_lightbox_count_down").on("click",function(){$(".wc_lightbox_form_count input").val(+$(".wc_lightbox_form_count input").val()-1),+$(".wc_lightbox_form_count input").val()<1&&$(".wc_lightbox_form_count input").val("999"),$(".wc_lightbox_form_price input").val(+$(".wc_lightbox_form_count input").val()*+$(".wc_lightbox_form_price input").attr("data-price"))}),$(".wc_lightbox_form_price input").attr("readonly","readonly"),i=0;i<$(".wc_card_container").length;i++)$(".wc_card_container").slice(i,i+1).attr("data-art-number",$.trim($(".wc_card_container").slice(i,i+1).attr("title").split("|")[0])),$(".wc_card_container").slice(i,i+1).attr("data-category",$.trim($(".wc_card_container").slice(i,i+1).attr("title").split("|")[1])),$(".wc_card_container").slice(i,i+1).attr("data-price",$.trim($(".wc_card_container").slice(i,i+1).attr("title").split("|")[2])),$(".wc_card_container").slice(i,i+1).removeAttr("title");$(".wc_card_container").on("click",function(){$(".wc_lightbox_form_count input").val("1"),$(".wc_lightbox_form_price input").val($(this).attr("data-price")),$(".wc_lightbox_form_price input").attr("data-price",$(this).attr("data-price")),$(".wc_lightbox_art_number p").text(t+$(this).attr("data-art-number")),$(".wc_lightbox_art_number p").attr("data-art-number",$(this).attr("data-art-number")),$(".wc_lightbox_category p").text($(this).attr("data-category")),$(".wc_lightbox_form_number input").val(t+$(this).attr("data-art-number")),$(".wc_lightbox_form_category input").val($(this).attr("data-category")),$(".wc_lightbox_title p").text($(this).find(".wc_card_title").text()),$(".wc_lightbox_form_title input").val($(this).find(".wc_card_title").text()),$(".wc_lightbox_img").css("background","url(assets/wc_img/wc_card_img_"+$(".wc_lightbox_art_number p").attr("data-art-number")+".jpg) no-repeat center center"),d.append("settings[0]",$(this).attr("data-art-number")),$.ajax({url:"assets/weddingcart.php",data:d,processData:!1,contentType:!1,type:"POST",success:function(t){$(".wc_lightbox_description").empty(),$(".wc_lightbox_description").append(t),d.append("settings[0]","")},error:function(){console.log("error")}})}),$(".wc_lightbox_button_rent").on("click",function(){if(0==p){$(".wc_lightbox_df_submit").click().mousedown().mouseup();var e=setInterval(function(){$(".wc_lightbox_df_submit").closest("form").hasClass("frm-subm-err-st")&&(clearInterval(e),$(".wc_lightbox_form_count input").val("1"),$(".wc_lightbox_form_price input").val($(".wc_lightbox_form_price input").attr("data-price")),$(".wc_lightbox_form_category input").val($(".wc_lightbox_category p").text()),$(".wc_lightbox_form_title input").val($(".wc_lightbox_title p").text()),$(".wc_lightbox_form_number input").val(t+$(".wc_lightbox_art_number p").attr("data-art-number")),$(".wc_lightbox_form_price input").val($(".wc_lightbox_form_price input").attr("data-price")),console.log("error. На сервере произошла ошибка. Форма НЕ отправлена.")),$(".wc_lightbox_df_submit").closest("form").hasClass("frm-sub-st")&&onsole.log("Идет отправка формы. Step 1 of 2"),$(".wc_lightbox_df_submit").closest("form").hasClass("frm-subm-ok-st")&&(clearInterval(e),$(".wc_lightbox_form_count input").val("1"),$(".wc_lightbox_form_price input").val($(".wc_lightbox_form_price input").attr("data-price")),$(".wc_lightbox_form_category input").val($(".wc_lightbox_category p").text()),$(".wc_lightbox_form_title input").val($(".wc_lightbox_title p").text()),$(".wc_lightbox_form_number input").val(t+$(".wc_lightbox_art_number p").attr("data-art-number")),$(".wc_lightbox_form_price input").val($(".wc_lightbox_form_price input").attr("data-price")),console.log("Форма отправлена. Step 2 of 2"))},500)}}),-1==window.location.href.indexOf("/cart")&&-1==window.location.href.indexOf("/thankyou")&&($(".wc_lightbox_form_date input").datepicker({minDate:new Date,autoClose:!0}),$(".datepickers-container").css("z-index","999999999")),$(".wc_lightbox_form_date input").on("mouseenter",function(){$(".wc_lightbox_form_date input").closest(".fld-grp").removeClass("fld-err-st")});var w=JSON.parse(localStorage.getItem("weddingcart")),u=0,f=0;for(var g in w)u++,f+=+w["tovar_"+u].count;var m=0;for(i=1;i<=u;i++)m+=+w["tovar_"+i].price;$(".wc_cart_ico_count p").text(f),$(".wc_cart_button_count").text(f),$(".wc_cart_button_sum").text(m),$(".wc_cart_button_text").text(h(f,["товар","товара","товаров"])),$(".wc_lightbox_button_add").on("click",function(){var t=JSON.parse(localStorage.getItem("weddingcart")),e=0,r=0;for(var a in t)e++,r+=+t["tovar_"+e].count;var c=0;for(i=1;i<=e;i++)c+=+t["tovar_"+i].price;""==$(".wc_lightbox_form_date input").val()&&$(".wc_lightbox_form_date input").closest(".fld-grp").addClass("fld-err-st"),0==$(".wc_lightbox_form_date input").closest(".fld-grp").hasClass("fld-err-st")&&(null===t&&(t={}),t["tovar_"+(+e+1)]={art:$(".wc_lightbox_art_number p").text(),category:$(".wc_lightbox_category p").text(),title:$(".wc_lightbox_title p").text(),date:$(".wc_lightbox_form_date input").val(),count:$(".wc_lightbox_form_count input").val(),price:$(".wc_lightbox_form_price input").val()},$(".wc_cart_ico_count p").text(+r+ +$(".wc_lightbox_form_count input").val()),$(".wc_cart_button_count").text(+r+ +$(".wc_lightbox_form_count input").val()),$(".wc_cart_button_sum").text(+c+ +$(".wc_lightbox_form_price input").val()),$(".wc_cart_button_text").text(h(+r+ +$(".wc_lightbox_form_count input").val(),["товар","товара","товаров"])),localStorage.setItem("weddingcart",JSON.stringify(t)),console.log(t)),$(".wc_lightbox_form_date input").val("")}),$(".wc_thankyou_order_number_block").css("opacity","0"),$(".wc_order_page_cart_container").append("
"),$(".wc_order_page_cart_wrapper").append("
"+e+"
"),$(".wc_order_page_cart_wrapper").append("
"+r+"
"),$(".wc_order_page_cart_wrapper").append("
"+a+"
"),$(".wc_order_page_cart_wrapper").append("
"+c+"
"),$(".wc_order_page_cart_wrapper").append("
"+_+"
"),$(".wc_order_page_cart_wrapper").append("
"+o+"
"),$(".wc_order_page_cart_wrapper").append("
"+l+"
"),$(".wc_order_page_cart_wrapper").append("
"+n+"
"),$(".wc_order_page_cart_wrapper").append("
");var b=1;for(var g in w)$(".wc_order_page_cart_wrapper").append("
"+b+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].category+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].title+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].art+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].date+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].count+"
"),$(".wc_order_page_cart_wrapper").append("
"+w["tovar_"+b].price+"
"),$(".wc_order_page_cart_wrapper").append("
Удалить
"),$(".wc_order_page_cart_wrapper").append("
"),b++;$("[data-delete-number]").on("mouseenter",function(){$("[data-tr='"+$(this).attr("data-delete-number")+"']").addClass("wc_tr_hover")}),$("[data-delete-number]").on("mouseleave",function(){$("[data-tr='"+$(this).attr("data-delete-number")+"']").removeClass("wc_tr_hover")}),$("[data-delete-number]").on("click",function(){var t={};delete w["tovar_"+$(this).attr("data-delete-number")],u=0;for(var e in w)t["tovar_"+(u+1)]=w[Object.keys(w)[u]],u++;for(w=t,localStorage.setItem("weddingcart",JSON.stringify(w)),u=Object.keys(w).length,f=0,i=1;i<=u;i++)f+=+w["tovar_"+i].count;for(m=0,i=1;i<=u;i++)m+=+w["tovar_"+i].price;for($(".wc_cart_button_count").text(f),$(".wc_cart_button_sum").text(m),$(".wc_cart_button_text").text(h(f,["товар","товара","товаров"])),$("[data-tr='"+$(this).attr("data-delete-number")+"']").remove(),$(this).remove(),i=1;i<=$("[data-delete-number]").length;i++)$(".wc_col_1[data-tr]").slice(i-1,i).text(i),$(".wc_col_1[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_2[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_3[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_4[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_5[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_6[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_7[data-tr]").slice(i-1,i).attr("data-tr",i),$(".wc_col_8[data-delete-number]").slice(i-1,i).attr("data-delete-number",i)}),d.append("settings[1]","wc_create_folder"),-1==document.location.href.indexOf("order_")&&$.ajax({url:"assets/weddingcart.php",data:d,processData:!1,contentType:!1,type:"POST",async:!1,success:function(t){d.append("settings[1]","")},error:function(){console.log("error"),d.append("settings[1]","")}}),document.location.href.indexOf("thankyou.html")>-1&&localStorage.removeItem("weddingcart");var v=!1;$(".wc_order_page_button_order").on("click",function(){var t={};t.name=$(".wc_order_page_form_name input").val(),t.phone=$(".wc_order_page_form_phone input").val(),t.count=f,t.sum=m,t.data=w,0==v&&(v=!0,$.ajax({url:"assets/weddingcart.php",data:{wc_order_number:JSON.stringify(t)},async:!1,dataType:"text",type:"POST",success:function(t){var e=window.location.protocol,r=window.location.host;if($(".wc_order_page_form_number input").val("Заказ №"+t),$(".wc_order_page_form_link input").val(e+"//"+r+"/assets/wc_orders/order_"+t+".html"),localStorage.setItem("wc_order_number",t),$(".wc_order_page_df_submit").click().mousedown().mouseup(),0==$(".wc_order_page_form_name").closest(".fld-grp").hasClass("fld-err-st")&&0==$(".wc_order_page_form_phone").closest(".fld-grp").hasClass("fld-err-st"))var a=setInterval(function(){$(".wc_order_page_df_submit").closest("form").hasClass("frm-subm-err-st")&&(clearInterval(a),alert("Ошибка при отправке. Обновите страницу.")),$(".wc_order_page_df_submit").closest("form").hasClass("frm-sub-st")&&console.log("Идет отправка формы. Шаг 1 из 2"),$(".wc_order_page_df_submit").closest("form").hasClass("frm-subm-ok-st")&&(console.log("Форма отправлена. Шаг 2 из 2"),clearInterval(a),localStorage.removeItem("weddingcart"),$(".wc_cart_button_count").text("0"),$(".wc_cart_button_sum").text("0"),$(".wc_cell").remove(),$(".wc_thankyou_order_number_block").css("opacity","1"),$(".wc_thankyou_order_number_count").text(localStorage.getItem("wc_order_number")))},200);(1==$(".wc_order_page_form_name").closest(".fld-grp").hasClass("fld-err-st")||1==$(".wc_order_page_form_phone").closest(".fld-grp").hasClass("fld-err-st"))&&(d.append("settings[2]",t),$.ajax({url:"assets/weddingcart.php",data:d,processData:!1,contentType:!1,type:"POST",async:!1,success:function(t){d.append("settings[2]","")},error:function(){console.log("error"),d.append("settings[2]","")}}))},error:function(){console.log("error")}})),v=!1}),""!=localStorage.getItem("wc_order_number")&&document.location.href.indexOf("thankyou.html")>=-1&&-1==window.location.href.indexOf("/cart")&&($(".wc_thankyou_order_number_block").css("opacity","1"),$(".wc_thankyou_order_number_count").text(localStorage.getItem("wc_order_number")),$(".wc_thankyou_order_number_block").length>0&&"1"==$(".wc_thankyou_order_number_block").css("opacity")&&localStorage.setItem("wc_order_number","")),$(".wc_order_list_this_delete").on("click",function(){d.append("settings[3]",$(".wc_order_list_title").attr("data-list-number")),$.ajax({url:"../weddingcart.php",data:d,processData:!1,contentType:!1,type:"POST",async:!1,success:function(t){d.append("settings[3]",""),alert("Страница удалена.\r\nПосле закрытия этого окна страница пропадет."),location.reload()},error:function(){console.log("error"),d.append("settings[3]","")}})}),$(".wc_order_list_all_delete").on("click",function(){d.append("settings[4]","all"),$.ajax({url:"../weddingcart.php",data:d,processData:!1,contentType:!1,type:"POST",async:!1,success:function(t){d.append("settings[4]",""),alert("Все страницы удалены.\r\nПосле закрытия этого окна страница пропадет."),location.reload()},error:function(){console.log("error"),d.append("settings[4]","")}})}),$(s).remove(),$(".wc_print").css("cursor","pointer"),$(".wc_print").on("click",function(){x(".wc_order_page_cart_container")})});