function addBasket(id){
  if($('#basket_status')){
    $('#basket_status').html('<img src="../img/load.gif">');
  }
  $.post('index.php?p=ajax',{addB:1,id:id},function(data){
     if(data == 1){
     	$('#basket_status').html('<div>Успішно відкладено</div>').css('color','#14D33A');
        updateBasketStatus();
       document.location.href="../basket.html";
      } else $('#basket_status').html('<div>Виникли помилка. Спробуйте ще раз</div>').css('color','red');
   }
  );
}
function updateBasketStatus(){
  $.post('./ajax.html',{basket_status:1},function(data){
    $('#basket_summ').text(data['sum']);
    $('#basket_amount').text(data['cnt']);
    if(data['cnt']>0){
    	$('#basket_button').html('<a href="../basket.html" title="Оформити замовлення">Замовити</a>');
    }else{
        $('#basket_button').html('');
    }
  },'json');
}


function counterCnt(id){
        var amount = $('#price'+id).text();
        var cnt    = $('#cnt'+id).val();
        var sumas  = amount*cnt;
        sumas      = Math.floor(sumas*100)/100;
		if(isNaN(sumas))return false;
		$('#lastprice'+id).text(sumas);
		counterALL();
    }

    function counterALL(){
       allSUM = 0;
       for(i in arrayIDS){
         var xdf = $('#basketBarrow'+i).css('display');
         if(xdf != 'none'){
         	allSUM += parseFloat($('#lastprice'+i).text());
         }
       }

	   allSUM     = Math.floor(allSUM*100)/100;
	   if(isNaN(allSUM))return false;
       $('#total_sum').text(allSUM);
    }



    function delInBasket(id){
      titleTovar = $('#title'+id).text();
      var answer = confirm ('Ви дійсно бажаєте видалити '+titleTovar+' з кошика?');
      if(!answer)return false;
      $.post('index.php?p=ajax',{id:id,delcookie:1},function(data){
         $('#basketBarrow'+id).hide();
         $('#basketBarrow'+id).html('');
         counterALL();
         updateBasketStatus();
        }
       );
    }
