function print_r(taV)
{
  alert(getProps(taV));
}

/**
 * возвращает список атрибутов объекта и значения
 * @param {Element/Object} toObj - ссылка на объект
 * @param {String} tcSplit - строка разделитель строк
 * @return {String} - строку со списком атрибутов объекта
 * и значениями атрибутов
 */
function getProps(toObj, tcSplit)
{
  if (!tcSplit) tcSplit = '\n';
  var lcRet = '';
  var lcTab = '    ';

    for (var i in toObj) // обращение к свойствам объекта по индексу
      lcRet += lcTab + i + " : " + toObj[i] + tcSplit;

    lcRet = '{' + tcSplit + lcRet + '}';

  return lcRet;
}


var frontEndBasket = {
	replaceBasket: function (id) {		
		/* location.reload(); */		
		return function (e) {						
			var cvet;
			var text, rem_item = true, item_total_price;
			var add_basket_button_text = 'купить';
			var detect_options = {};		
			if (e.summary.amount > 0) {
				text = e.summary.price.actual + ' ' + e.summary.price.suffix + '.';
				for (var i in e.items.item) {				
					var item = e.items.item[i];
					if (item.id == id) {					
						rem_item = false;						
						item_total_price = item["total-price"].actual + ' ' + item["total-price"].suffix + '.';
					}
					if (item.page.id == id) {
						if (detect_options.amount) {
							detect_options.amount = detect_options.amount + item.amount;
						}
						else detect_options = {'id':id, 'amount':item.amount};
					}
				}
				if (detect_options.amount) {
					var add_basket_button = jQuery('#add_basket_' + detect_options.id);
					/* if (add_basket_button[0].tagName.toUpperCase() == 'A') {
						add_basket_button.text(add_basket_button_text + ' (' + detect_options.amount + ')');
						add_basket_button.text(add_basket_button_text);
					}
					else add_basket_button.val(add_basket_button_text + ' (' + detect_options.amount + ')');
					else add_basket_button.val(add_basket_button_text); */
				}
				if (rem_item) {
					if (jQuery('.cart_item_' + id)) {
						jQuery('.cart_item_' + id).remove();
						jQuery('.cart_summary').text(text);
					}
				}
				else {
					jQuery('.cart_item_color_' + id).text(item_color);
					jQuery('.cart_summary').text(text);
				}
			 	text = "Товаров: <b><a href='emarket/cart/'>" + e.summary.amount + " шт</a></b><br />\n Сумма: <b><a href='emarket/cart/'>" + text + "</a></b>";	
				
			}
			else {
				text = '0 товаров';
				if (jQuery('.basket')) {
					jQuery('.basket').text(text);
				}
			}			
			jQuery('.basket_info_summary').html(text);
			jQuery('.basket_info_summary').html(text);
		}; 
	},
	add: function (id, form, popup) {	
		var e_name, options = {};		
		if (form) {		
			var elements = jQuery(':input.sup, :radio:checked', form);
			
			for (var i = 0; i < elements.length; i++) {
				e_name = elements[i].name.replace(/^options\[/, '').replace(/\]$/, '');				
				options[e_name] = elements[i].value;								
			}
					
			/* var result="";
			for (var i in elements) // обращение к свойствам объекта по индексу
				result += elements + "." + i + " = " + elements[i] + "<br />\n";
			alert(result); */
			
		}
		basket.putElement(id, options, frontEndBasket.replaceBasket(id));		
		if (popup) jQuery('#add_options').remove();
		
		MessagePopup({id: 'add_options'});
	},
	addFromList: function (id, is_options) {	
		  if (is_options) {		  
			if (jQuery('#add_options').length == 0) {			
				jQuery.ajax({					
					url: '/upage//' + id + '?transform=modules/catalog/popup-add-options.xsl',
					dataType: 'html',
					success: function (data) {						
						frontPopup({
							id: 'add_options',
							header: 'Выбор опций',
							width: '200',
							content: data
						});						
					}
				});
			}		
		}
		else {  
			frontEndBasket.add(id);
	 	} 	
	},
	modify: function (id, amount_new, amount_old) {
		if (amount_new.replace(/[\d]+/) == 'undefined' && amount_new != amount_old) {
			basket.modifyItem(id, { amount: amount_new }, frontEndBasket.replaceBasket(id));
		}
	},
	remove: function (id) {
		basket.removeItem(id, frontEndBasket.replaceBasket(id));
	}
};
