function addToCart(tovar_id, format_id)
{
	ShowIndicator('Добавление товара в корзину');
	var req = new JsHttpRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) {
			if (req.responseJS.aOrder)
			{
				aOrder = req.responseJS.aOrder;
				jQuery('b.small_cart_tovars_pcs').html(aOrder.order_pcs);
				jQuery('b.small_cart_tovars_price').html(aOrder.order_amount);
				timeout = false;
			}
			
			if (req.responseJS.aMessages.length && req.responseJS.aMessages.length > 0) {
				ShowMessages(req.responseJS.aMessages);
			} else {
				setTimeout('HideIndicator()', 1000);
			}
		}
	}
	req.caching = false;
	req.open('POST', cfg_path_web+'/modules/shop/loaders/add_to_cart.loader.php', true);
	req.send( { tovar_id: tovar_id, format_id: format_id } );
}

function recalculateCart(form_data)
{
	ShowIndicator('Выполняется пересчёт');
	var req = new JsHttpRequest();
	req.onreadystatechange = function()
	{
		if (req.readyState == 4) {
			if (req.responseJS.aTovars)
			{
				var aTovars = req.responseJS.aTovars;
				
				var temp_container = jQuery('<table></table>');
				
				var table_header = jQuery('<tr></tr>').addClass('header');
				table_header.html(jQuery('tr.header').html());
				
				var table_footer = jQuery('<tr></tr>').addClass('footer');
				table_footer.html(jQuery('tr.footer').html());
				
				var tr_post_amount = jQuery('<tr></tr>').addClass('total_amount').addClass('post_amount');
				tr_post_amount.html(jQuery('tr.post_amount').html());
				
				var tr_cart_amount = jQuery('<tr></tr>').addClass('total_amount').addClass('cart_amount');
				tr_cart_amount.html(jQuery('tr.cart_amount').html());
				
				table_header.appendTo(temp_container);
				
				var total_price = 0;
				
				for (var i = 0; i < aTovars.length; i++)
				{
					var tr_tovar = jQuery('<tr></tr>').addClass('tovar');
					
					var td_title = jQuery('<td></td>').addClass('title');
					var link = jQuery('<a href="'+cfg_path_web+'/shop/tovar/'+aTovars[i].tovar_id+'/">'+aTovars[i].tovar_title+'</a>')
					td_title.html(link);

					var td_format = jQuery('<td></td>').addClass('format');
					td_format.html(aTovars[i].format_title);
					
					var td_price = jQuery('<td></td>').addClass('price');
					td_price.html(aTovars[i].cart_price);
					
					total_price = total_price + aTovars[i].cart_price;
					
					var td_delete = jQuery('<td></td>').addClass('delete');
					var del_input = jQuery('<input type="checkbox" name="delete_from_cart['+aTovars[i].tovar_id+']" value="'+aTovars[i].format_id+'">')
					td_delete.html(del_input);

					td_title.appendTo(tr_tovar);
					td_format.appendTo(tr_tovar);
					td_price.appendTo(tr_tovar);
					td_delete.appendTo(tr_tovar);
					
					tr_tovar.appendTo(temp_container);
				}
				
				tr_post_amount.appendTo(temp_container);
				tr_cart_amount.appendTo(temp_container);
				table_footer.appendTo(temp_container);
				
				jQuery('table.cart').html(temp_container.html());
			}

			if (!req.responseJS.aCart) {
				jQuery('#order_form').hide();
				jQuery('b.small_cart_tovars_pcs').html('0');
				jQuery('b.small_cart_tovars_price').html('0');
			}
			else {
				var aCart = req.responseJS.aCart;
				jQuery('b.small_cart_tovars_pcs').html(aCart.order_pcs);
				jQuery('b.small_cart_tovars_price').html(aCart.order_amount);
				jQuery('b.cart_amount_with_post_exp').html(aCart.cart_amount_with_post_exp);
			}
			
			if (req.responseJS.aMessages.length && req.responseJS.aMessages.length > 0) {
				ShowMessages(req.responseJS.aMessages);
			} else {
				setTimeout('HideIndicator()', 1000);
			}
		}
	}
	req.caching = false;
	req.open('POST', cfg_path_web+'/modules/shop/loaders/recalculate_cart.loader.php', true);
	req.send( { q: form_data } );
}