//
  function Supermarket_Good_AddToBasket(good_id, old_count, new_count, type, position)
  {
//    alert(document.cookie);
    old_count = parseInt(old_count);
    new_count = parseInt(new_count);
    
    var d = document;
    var objGoodPrice = d.getElementById('Supermarket_Good_PriceRub' + good_id);


    
    var good_price = 0;

    if (objGoodPrice)
    {
    	good_price = parseFloat(objGoodPrice.innerHTML);
    	if (isNaN(good_price))
    	{
    		good_price = 0;
    	}
    }

    var objGoodCount =  d.getElementById('Supermarket_Good_Count' + good_id);
    
    if (!objGoodCount)
    {
    	alert('No GoodCount!');
    	return;
    }
    
    if (isNaN(new_count) || new_count < 0)
    {
      objGoodCount.value = old_count;
      return;
    }
    
    var objTotalGoodsCount = d.getElementById('Supermarket_TotalGoodsCount');
    var objTotalAmount = d.getElementById('Supermarket_TotalAmount');


		if (!objTotalGoodsCount)
		{
			alert('No objTotalGoodsCount!');
			return;
		}

		var noMoney = false;

		if (!objTotalAmount)
		{
			noMoney = true;
		}
		var old_total_goods_count = parseInt(objTotalGoodsCount.innerHTML);
		if (isNaN(old_total_goods_count))
		{
			old_total_goods_count = 0;
		}

    objTotalGoodsCount.innerHTML  = old_total_goods_count + (new_count - old_count); 
		
		if (!noMoney)
		{
			var old_total_amount = parseFloat(objTotalAmount.innerHTML);

			if (isNaN(old_total_amount))
			{
				old_total_amount = 0;
			}

			var new_total_amount = old_total_amount   + (new_count - old_count) * good_price;   

	    if (isNaN(new_total_amount))
  	  {
    		new_total_amount = 0;
	    }
    
    
  	  objTotalAmount.innerHTML = zeros4Money(Money_Round(new_total_amount, 2));
    
    	Supermarket_Budget_SetRest(new_total_amount);

    }
    
    Cookie(good_id + ':' + new_count, 'Supermarket_Cart_Goods', (new_count > 0 ? true : false), 'add'); 

    GetFull('Supermarket_Cart_Goods', 'Supermarket_Cart_Img', '/images/supermarket/icons/cart.gif', '/images/supermarket/icons/cart_full.gif');

    objGoodCount.value = new_count;

    if (type == 4)
    {
      var span 	= d.getElementById("Supermarket_SpanForGood" + good_id);
      var table = d.getElementById("Supermarket_TableForGood" + good_id);
      var tr 		= d.getElementById("Supermarket_TrForGood" + good_id);
      
      var re = new RegExp('cell4Good' + good_id + '_(\.)', 'i'); 
      
      if (new_count > 0)
      {
        if (span)
        {
	        span.style.display = 'none';
	      }
	      if (table)
	      {
	        table.style.display = '';
        }	
        if (tr)
          tr.className = 'Supermarket_RowSelected';

        
        var tds = document.getElementsByTagName("td");
      
        for(var i = 0; i < tds.length; i++)
        {

          var td = tds[i];

          if (td.id.match(re))
          {
            td.className = 'Supermarket_CellSelected';
          }
        }


      }
      else
      {
        if (span)
        {
	        span.style.display = '';
	      }
	      if (table)
	      {
	        table.style.display = 'none';
	      }

        var tds = document.getElementsByTagName("td");
      

        
        for(var i = 0; i < tds.length; i++)
        {

          var td = tds[i];

          if (td.id.match(re))
          {

            ms = td.id.match(re);
            td.className = 'Supermarket_Row' + ms[1];
          }
        }

        
        
        if (tr)
        {
          if (position % 2 == 1)
          {
  
            tr.className = 'Supermarket_Row1';
          }
          else
          {
            tr.className = 'Supermarket_Row0';
          }
        }
      }
    }

  }
//
	function Supermarket_Good_IncToBasket(good_id, type, position)
	{
	  var d = document;

    var objGoodCount =  d.getElementById('Supermarket_Good_Count' + good_id);
    
    if (!objGoodCount)
    {
    	return;
    }
    var old_count = parseInt(objGoodCount.value);
    if (isNaN(old_count))
    {
    	old_count = 0;
    }
  	var new_count = old_count + 1;

  	Supermarket_Good_AddToBasket(good_id, old_count, new_count, type, position)
	}
//
	function Supermarket_Good_DecToBasket(good_id, type, position)
	{
	  var d = document;
	      
    var objGoodCount =  d.getElementById('Supermarket_Good_Count' + good_id);
    
    if (!objGoodCount)
    {
    	return;
    }
    var old_count = parseInt(objGoodCount.value);
    if (isNaN(old_count))
    {
    	old_count = 0;
    }
  	var new_count = old_count - 1;

  	if (new_count < 0)
  	{
  		new_count = 0;
  	}

  	Supermarket_Good_AddToBasket(good_id, old_count, new_count, type, position)
	}
//
	function Supermarket_Good_ZeroToBasket(good_id, type, position)
	{
	  var d = document;

    var objGoodCount =  d.getElementById('Supermarket_Good_Count' + good_id);
    
    if (!objGoodCount)
    {
    	return;
    }
    var old_count = parseInt(objGoodCount.value);
    if (isNaN(old_count))
    {
    	old_count = 0;
    }
  	var new_count = 0;

  	Supermarket_Good_AddToBasket(good_id, old_count, new_count, type, position)
	}
