const copyToClipboard=str=>{const el=document.createElement('textarea');el.value=str;el.setAttribute('readonly','');el.style.position='absolute';el.style.left='-9999px';document.body.appendChild(el);const selected=document.getSelection().rangeCount>0?document.getSelection().getRangeAt(0):false;el.select();document.execCommand('copy');document.body.removeChild(el);if(selected){document.getSelection().removeAllRanges();document.getSelection().addRange(selected);}};function setCookie(cname,cvalue,exdays){var d=new Date();d.setTime(d.getTime()+(exdays*24*60*60*1000));var expires="expires="+d.toUTCString();document.cookie=cname+"="+cvalue+";"+expires+";path=/";}
$(document).ready(()=>{$('.lazy').Lazy();moment.locale('en');moment().format();$('#database_switch').click(function(){setCookie('search_new_db',($('#database_switch').attr('data-status')==1?0:1),1);location.reload();});$('.voteup').click((e)=>{let id=$(e).parent().data('voteid');$.post("/rating?go=up",{productId:$(e.target).parent().data('voteid')},(data)=>{if(data.success){let value=$(e.target).parent().closest("div").children('.voted_up');value.text(parseInt(value.text())+1);$(e.target).parent().replaceWith('<span clsss="text-muted">You voted</span>');}});});$('.votedown').click((e)=>{let id=$(e).parent().data('voteid');$.post("/rating?go=down",{productId:$(e.target).parent().data('voteid')},(data)=>{if(data.success){let value=$(e.target).parent().closest("div").children('.voted_down');value.text(parseInt(value.text())+1);$(e.target).parent().replaceWith('<span clsss="text-muted">You voted</span>');}});});$('#yes_change_db').click((e)=>{if($('[name="lang"]:checked').val()=='on'){$('#radio_lang_en[name="lang"]').trigger('click');$('[type="submit"]').trigger('click');console.log('#radio_lang_en[name="lang"]');}else{$('#radio_lang_ru[name="lang"]').trigger('click');$('[type="submit"]').trigger('click');console.log('#radio_lang_ru[name="lang"]');}});$('.rem_noex').click(function(){$.post("/favorite?go=delete",{productId:$(this).attr('data-product')},(data)=>{if(data.success){$(this).replaceWith('<span class="text-muted ml-2">Removed</span>');}else{$(this).replaceWith('<span class="text-muted ml-2">Error remove</span>');}});});if(location.pathname=='/feedback'){$('#feedback_send').click(function(){if($('#g-recaptcha-response').val()){if(document.getElementById('name').checkValidity()&&document.getElementById('message').checkValidity()&&document.getElementById('email').checkValidity()){$.post("/feedback?go=send",{name:$('#name').val(),message:$('#message').val(),email:$('#email').val(),'g-recaptcha-response':$('#g-recaptcha-response').val()},(data)=>{if(data.success){$('#captcha_alert').hide();$('.card-body').hide();$('#send_alert').show();}});}}else $('#captcha_alert').show();});}
if($('.progress-bar').is(":visible")){let update=setInterval(()=>{try{$.ajax({url:'//'+location.host+"/update.json?"+new Date().getTime(),}).done(function(msg){console.log(msg.percent)
$('.progress-bar').text(msg.percent);if(msg.percent=='Update in progress... 100%'){clearInterval(update);setTimeout(()=>location.reload(),5000);}});}catch{}},10000);}
$('#price_filter').change(function(){if(this.checked){$('#max_price').prop('disabled',false);$('#min_price').prop('disabled',false);}else{$('#max_price').prop('disabled',true);$('#min_price').prop('disabled',true);}});$('#orders_order').change(function(){if(this.checked){$('[for="orders_order"]').text("Orders ascending");}else{$('[for="orders_order"]').text("Orders descending");}});$('#abuse_rating_filter').change(function(){if(this.checked){$('#abuse_rating').prop('disabled',false);}else{$('#abuse_rating').prop('disabled',true);}});$('#cashback_desc_asc').change(function(){if(this.checked){$('[for="cashback_desc_asc"]').text("Cashbask percent ascending");}else{$('[for="cashback_desc_asc"]').text("Cashbask percent descending");}});$('#abuse_rating').change(function(){if(this.checked){$('[for="abuse_rating"]').text("Abuse rating ascending");}else{$('[for="abuse_rating"]').text("Abuse rating descending");}});$('.add_favorite').click(function(){if(!user_auth.logged){var scroll_save=$('html, body').scrollTop();$("#navbarsExampleDefault").collapse('toggle');$('html, body').animate({scrollTop:0},200);setTimeout(()=>{var enjoyhint_instance=new EnjoyHint({onSkip:function(){$("#navbarsExampleDefault").collapse('toggle');$('html, body').animate({scrollTop:scroll_save},200);}});var enjoyhint_script_steps=[{'click #vk_auth':'Please sign in to use favorite'}];enjoyhint_instance.set(enjoyhint_script_steps);enjoyhint_instance.run();},205)}else{var fav_act='';if($(this).children().hasClass('typcn-star-outline')){fav_act='add';}else if($(this).children().hasClass('typcn-star-full-outline')){fav_act='delete';}
$.post("/favorite?go="+fav_act,{productId:$(this).attr('data-productId')},(data)=>{if(data.success){if($(this).children().hasClass('typcn-star-outline')){$(this).children().removeClass('typcn-star-outline');$(this).children().addClass('typcn-star-full-outline');$("#fav_cnt").text(parseInt($("#fav_cnt").text())+1);}else if($(this).children().hasClass('typcn-star-full-outline')){$(this).children().addClass('typcn-star-outline');$(this).children().removeClass('typcn-star-full-outline');$("#fav_cnt").text(parseInt($("#fav_cnt").text())-1);}}});}});$('#orders_order_en').change(function(){if(this.checked){$('#orders_order').prop('disabled',false);}else{$('#orders_order').prop('disabled',true);}});});