(function(){var cart=window.cart=function(){return new cart()};cart.tbl=new Array();cart.init=function(){var i=1;var j,k,basketCol,deleteCol;var buyBtn=document.getElementById('detailsBuyButton');if(buyBtn){var wareId=buyBtn.previousSibling.value;var inp=document.createElement('INPUT');inp.type='button';inp.value='КУПИТЬ';inp.className='btn_std';inp.style.marginTop='15px';inp.style.background='#f18000';inp.style.fontWeight=900;buyBtn.parentNode.appendChild(inp);buyBtn.parentNode.removeChild(buyBtn);first.addEvent(inp,'click',function(){cart.add(wareId);first.fader(document.getElementById('cart'),7)})}while(document.getElementById('grid'+i)){var tbl=document.getElementById('grid'+i);if(tbl)cart.tbl.push(tbl);i++}if(cart.tbl.length==0)return false;for(i=0;i<cart.tbl.length;i++){var tbody=cart.tbl[i].childNodes[1];var tr=tbody.childNodes[1];if(!tr)tr=tbody.childNodes[0];if(!tr)return false;for(k=0;k<tr.childNodes.length;k++){var td=tr.childNodes[k];if(td.getAttribute('name')=='to_basket')var basketCol=k;if(td.getAttribute('name')=='cart_delete')var deleteCol=k}cart.attachAddEvent(tbody,basketCol);cart.attachDeleteEvent(tbody,deleteCol)}return true};cart.attachDeleteEvent=function(tbody,deleteCol){if(!tbody||!deleteCol)return;for(var j=0;j<tbody.childNodes.length;j++){var tr=tbody.childNodes[j];var td=tbody.childNodes[j].childNodes[deleteCol];var el=td.firstChild;first.addEvent(el,'click',function(){document.location.href='http://'+window.location.host+'/lib/controller/actionController.php?controller=cart&mode=remove&id='+this.id.substr(10,this.id.length)})}};cart.attachAddEvent=function(tbody,basketCol){if(!tbody||!basketCol)return;for(j=0;j<tbody.childNodes.length;j++){var tr=tbody.childNodes[j];var el=tbody.childNodes[j].childNodes[basketCol];if(!el)continue;var anc=el.firstChild;if(!anc)continue;var temp=anc.childNodes[0];var parent=anc.parentNode;parent.removeChild(anc);parent.appendChild(temp);first.addEvent(temp,'click',(function(tr){return function(e){(e||event).cancelBubble=true;cart.add(tr.id);first.setBg(tr,'#f6b061');first.fader(document.getElementById('cart'),7)}})(tr))}};cart.add=function(id){first.ajax({type:'GET',url:'http://'+window.location.host+'/lib/controller/actionController.php',data:'controller=cart&mode=ajax_add&id='+id,success:function(html){var res=html.split('|');document.getElementById('cartTotal').innerHTML=res[0];document.getElementById('cartAmount').innerHTML=res[1]}})}})();
