var Purchase_class=CatalogItem_class.extend({id:null,initialize:function(id,elem){this.parent(id,elem);Cart.addEvent('actionCompleteForPurchase'+this.id,this.onActionComplete.bind(this))},Delete:function(){Cart['delete'](this.id)},Edit:function(initiator){Cart['edit'](this.id,initiator.value)},getProperty:function(name){if((Cart.getPurchase(this.id))){return Cart.getPurchase(this.id)[name]}else{this.elem.addClass('hidden')}},setActive:function(elem,param){if(!$defined(param.event))param.event='click';switch(param.event){case'change_quantity':{elem.old_value=elem.value;elem.addEvent('keydown',function(){elem.old_value=elem.value});elem.addEvent('keyup',function(){if(/^(0|[1-9][0-9]{0,}|[1-9]*)$/.exec(elem.value)==null){elem.value=Cart.getPurchase(this.id).quantity}else if(elem.old_value!=elem.value&&elem.value!=''){if(elem.value!=0||!$defined(param.confirm_tpl)||confirm(App.getHTML(param.confirm_tpl,this))){this.fireEvent('onActionStart',{action:param.action,initiator:elem});this[param.action](elem)}else{elem.value=elem.old_value}}}.bind(this));break}default:{this.parent(elem,param)}}}});var CartList=new Catalog_class(Purchase_class,'cart_item');CartList.setOptions({activeElements:{quantity:{event:'change',action:'Edit'},'delete':{action:'Delete',confirm_tpl:'Товар: «${Cart.getPurchase(id).goods.title}» будет удален из корзины покупок!'}},dynamicElements:{cost:'<span class="price">${getProperty("cost")}</span>'},onActionStart:function(){this.elem.processStart(process_tpl)},onActionComplete:function(){this.elem.processStop();if(Cart.empty())location.reload();if(Cart.getPurchase(this.id)===null){this['delete']()}}});CartList.updateBind(Cart);App.addOnDomReady(function(){Cart.addEvent('update',function(){if($('cart_total')&&Cart.empty()!==null){$('cart_total').innerHTML=Cart.S.total}})});
