const api={};api.router={};api.router.cart_ajax='https://infotel.ua/ajax/cart_ajax.php';api.router.wishlist_ajax='https://infotel.ua/ajax/wishlist.php';api.router.wishlist_ajax_amp='https://infotel.ua/ajax/wishlist_amp.php';api.router.comparison_ajax='https://infotel.ua/ajax/comparison.php';api.router.ajax_product_rating='https://infotel.ua/ajax/rating';api.router.ajax_search='https://infotel.ua/ajax/search_products';api.change_payment_method=function(){let delivery_input=$('input[name="delivery_id"]:checked');let current_payment_id=$('input[name="payment_method_id"]:checked').val();let delivery_id=delivery_input.val();let payments_ids=new Array();if(String(delivery_input.data('payment_method_ids')).length>0){payments_ids=String(delivery_input.data('payment_method_ids')).split(',')} $(".fn_payment_method__item").hide().find('input[name="payment_method_id"]').prop('disabled',!0);$(".fn_payment_method__item").find('input[name="payment_method_id"]').prop('checked',!1);if(payments_ids.length>0){payments_ids.forEach(function(payment_id,i,arr){let payment_block=$(".fn_payment_method__item_"+payment_id);let payment_input=payment_block.find('input[name="payment_method_id"]');let currency_id=payment_input.data('currency_id');payment_block.show();payment_block.find('.fn_payment_price').text(api.convert(delivery_input.data('total_price'),currency_id));payment_input.prop('disabled',!1)});$('.fn_payments_block').show();if($('input[name="payment_method_id"][value="'+current_payment_id+'"]').is(':disabled')){$(".fn_payment_method__item:visible").first().find('input[name="payment_method_id"]').prop('checked',!0).trigger('click')}}else{$('.fn_payments_block').hide()} api.update_cart_total_price();$('input[name="delivery_id"]').parent().removeClass('active');$('#deliveries_'+delivery_id).parent().addClass('active')};api.update_cart_total_price=function(){let delivery_input=$('input[name="delivery_id"]:checked');$('#fn_cart_total_price').text(api.convert(delivery_input.data('total_price')));$('#fn_total_purchases_price').text(api.convert($('.fn_purchases_wrap').data('total_purchases_price'),null,!0,!0));if(delivery_input.data('is_free_delivery')){$('#fn_total_free_delivery').show();$('#fn_total_delivery_price').hide()}else{$('#fn_total_free_delivery').hide();$('#fn_total_delivery_price').text(api.convert(delivery_input.data('delivery_price'),null,!0,!0)).show()} if(delivery_input.data('separate_payment')==!0&&delivery_input.data('is_free_delivery')==!1){$('#fn_total_separate_delivery').show()}else{$('#fn_total_separate_delivery').hide()}};api.convert=function(price,currencyId=null,format=!0,withCurrency=!1){if(currencyId===null){currencyId=4} let currencies=Object.create(null);currencies[4]={'rate_from':'1.00','rate_to':'1.00','cents':'0','sign':'грн',};currencies[1]={'rate_from':'1.00','rate_to':'1.00','cents':'0','sign':'$',};let currency=currencies[currencyId];if(typeof currency=="undefined"){console.error('currency ID='+currencyId+' is not defined');return'currency error'} let decimal=currency.cents;let dec_point='.';let separator=' ';let res=parseFloat(price*currency.rate_from/currency.rate_to);if(format===!0){res=Number(res).toFixed(decimal).toString().split('.');let b=res[0].replace(/(\d{1,3}(?=(\d{3})+(?:\.\d|\b)))/g,"\$1"+separator);res=(res[1]?b+dec_point+res[1]:b);if(withCurrency===!0){res+=' '+currency.sign}}else{res=Number(res).toFixed(decimal)} return res}