1function createCookie(name,value,days,options={}
2){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString()}
3else var expires="";var updatedCookie=name+"="+encodeURIComponent(value)+expires+"; path=/";for(let optionKey in options){updatedCookie+="; "+optionKey;let optionValue=options[optionKey];if(optionValue!==true){updatedCookie+="="+optionValue}
4}
5document.cookie=updatedCookie}
6function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)}
7return null}
8function eraseCookie(name){createCookie(name,"",-1)}
9var widgets=(function(){var widgets={preloaderURL:'/shared/images/preloader.gif',addToCart:function(shop_id,product_id,price,obj){var amount=1;product_id=Number(product_id);price=Number(price);$.post('/-/x-api/v1/public/?method=shop/getProduct',{'shop_id':shop_id,'product_id':product_id}
10,function(data){if(widgets.isEmptyObject(data)&&typeof obj.href=="string"){location.href=obj.href;return true}
11data=data.result;if(data&&data.product_price!=undefined){price=Number(data.product_price)}
12var result=true,amount_limit=amount;var has_amount_limit=(data.product_amount_limit=='1'?true:false);if(has_amount_limit){amount_limit=Number(data.product_amount);if(amount_limit<amount){amount=amount_limit}
13}
14if(!isNaN(shop_id)&&(shop_id>0)&&!isNaN(product_id)&&(product_id>0)&&!isNaN(price)&&!isNaN(amount)&&(amount>0)){var cart_new="",cart_item_split,found=false,total_amount=0,ta,e;var total=readCookie('CART_TOTAL_'+shop_id);var cart=unescape(readCookie('CART_'+shop_id));var cart_split=cart.split(';');if(isNaN(total))total=Number(total);for(var i=0;i<cart_split.length;i++){cart_item_split=cart_split[i].split("=");if(cart_item_split.length==2){if(!found&&cart_item_split[0]==product_id){if(!(has_amount_limit&&cart_item_split[1]>=amount_limit))total=Number(total)+price*amount;ta=amount+Number(cart_item_split[1]);if(has_amount_limit&&ta>amount_limit){ta=amount_limit;result=false;widgets.msg(window._s3Lang['JS_SHOP_PRODUCT_AMOUNT_TOTAL']+': '+amount_limit,obj)}
15found=true;if(cart_new!="")cart_new=cart_new+";";cart_new=cart_new+product_id+"="+ta;total_amount+=ta}
16else{if(cart_new!="")cart_new=cart_new+";";cart_new=cart_new+cart_item_split[0]+"="+cart_item_split[1];total_amount+=Number(cart_item_split[1])}
17}
18}
19if(!found){if(cart_new!="")cart_new=cart_new+";";cart_new=cart_new+product_id+"="+amount;total=Number(total)+price*amount;total_amount+=amount}
20total=Math.round(total*100)/100;createCookie('CART_'+shop_id,cart_new,10);createCookie('CART_TOTAL_'+shop_id,total,10);createCookie('CART_TOTAL_AMOUNT_'+shop_id,total_amount,10);e=document.getElementById('cart_total');if(e)e.innerHTML=total;e=document.getElementById('cart_total_amount');if(e)e.innerHTML=total_amount;if(result)widgets.msg(window._s3Lang['JS_ADDED'],obj);return true}
21}
22,'json');return false}
23,formatPrice:function(str,ts,dot){if(typeof str!='string')str=String(str);if(ts==null)ts=' ';if(dot==null)dot='.';if(dot!='.')str=str.replace('.',dot);var parts=str.split(dot),res=[],i;if(parts[0].length>=4){for(i=(parts[0].length-1),j=1;i>=0;--i,++j){res.unshift(parts[0].charAt(i));if(j%3==0&&i>0)res.unshift(ts)}
24return res.join('')+(parts[1]?dot+parts[1]:'')}
25return str}
26,addOnloadEvent:function(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func}
27else{window.onload=function(){if(oldonload){oldonload()}
28func()}
29}
30}
31,msg:function(text,obj,className){if(!obj)return;var pos=findPos(obj);var d=document.createElement("DIV");if(d){d.style.position='absolute';d.innerHTML=text;d.style.display='block';d.className=className?className:'added-to-cart';d.style.left=(pos.x+obj.offsetWidth)+'px';d.style.top=(pos.y+obj.offsetHeight)+'px';try{if($(window).width()<=(parseInt(d.style.left)+120)){d.style.left=(pos.x-80)+'px';d.style.top=(pos.y+obj.offsetHeight)+'px'}
32}
33catch(e){}
34document.body.appendChild(d);window.setTimeout(function(){if(d&&d.parentNode)d.parentNode.removeChild(d);delete d}
35,1500)}
36}
37,createPreloader:function(node){var pos=findPos(node);var div=document.createElement('div');with(div.style){position='absolute';display='block';left=(pos.x+node.offsetWidth)+'px';top=(pos.y+node.offsetHeight)+'px';width=32;height=32;background="url("+this.preloaderURL+") center center no-repeat transparent";zIndex=2000}
38return div}
39,addEvent:function(elem,evType,fn){if(elem.addEventListener){elem.addEventListener(evType,fn,false)}
40else if(elem.attachEvent){elem.attachEvent('on'+evType,fn)}
...
</html>