// Было...
function common_AddGoodInBasket( goodId )
{
	ajax_basketAdd(goodId);
	document.getElementById('basket_' + goodId).style.display='none';
	document.getElementById('baskets_' + goodId).style.display='none';
	document.getElementById('baskett_' + goodId).style.display='inline';
}

function common_DeleteGoodFromBasket( goodId )
{
	document.getElementById('baskett_' + goodId).style.display='none';
	document.getElementById('basket_' + goodId).style.display='inline';
	ajax_basketDelete( goodId );
}


function common_ShowBasketTips( goodId )
{
	if ( document.getElementById('baskett_' + goodId).style.display == 'none')  {
		document.getElementById('basket_' + goodId).style.display='none';
		document.getElementById('baskets_' + goodId).style.display='inline';
	}
}

function common_HideBasketTips(goodId)
{
	if ( document.getElementById('baskett_' + goodId).style.display == 'none')  {
		document.getElementById('baskets_' + goodId).style.display='none';
		document.getElementById('basket_' + goodId).style.display='inline';
	}
}

// Стало
$(document).ready(function() {

	// Обработчик одновременно используется и на странице со списком товаров,
	// и на странице непосредственно товара
	$(".add-to-basket").click(function(e) {
		var link = $(this),
			id = link.attr("id").match(/^.+_([0-9]+)/)[1],
			target_is_text = $(e.target).hasClass("title");

		if (link.hasClass("not-favorited")) {
			link.removeClass("not-favorited").addClass("favorited")
				.children(".title").text("в избранном");

			ajax_basketAdd(id);

			return false;
		}
		else {
			if (!link.hasClass("js-changes-title") || (link.hasClass("js-changes-title") && !target_is_text)) {
				link.addClass("not-favorited").removeClass("favorited")
					.children(".title").text("в избранноe");

				ajax_basketDelete(id);

				return false;
			}
		}
	});
});

