path ='/korzina/';
function purchaseItem(id) {
	$.get(path, {
		itemId :id,
		action :'new'
	}, function(xml) {
		$('.basket').removeClass('emptyBasket').addClass('fullBasket');
		var orderCount = 0;
		$('count', xml).each( function() {
			orderCount += parseInt($(this).text());
		});
		$('#orderCount').text(orderCount);
	}, 'xml');
	return false;
}
function purchasePlus(id) {
	$.get(path, {
		itemId :id,
		action :'plus'
	}, function(xml) {
		$('#cnt' + id).text($('item[id=' + id + ']>count', xml).text());
		setFullprice(xml);
	}, 'xml');
	return false;
}
function purchaseMinus(id) {
	$.get(path, {
		itemId :id,
		action :'minus'
	}, function(xml) {
		$('#cnt' + id).text($('item[id=' + id + ']>count', xml).text());
		setFullprice(xml);
	}, 'xml');
	return false;
}
function setFullprice(xml) {
	var fullprice = 0;
	$('item', xml).each(
			function() {
				//alert($(this).find('price').text());
				fullprice += parseInt($(this).find('count').text())	* $(this).find('price').text();
			});
	//alert(fullprice);
	fullprice = moneyFormat(fullprice);
	$('#fullprice').text(fullprice);
}
function moneyFormat(money) {
	var moneyStr = money.toString();
	if (moneyStr.indexOf(".") != -1) 
	intMoneyStr = moneyStr.substr(0, moneyStr.indexOf("."));
	else intMoneyStr = moneyStr;
	
	if ((intMoneyStr >= 1000) && (intMoneyStr < 1000000))
		intVal = intMoneyStr.substr(0, intMoneyStr.length - 3) + ' ' + intMoneyStr.substr(-3);
	if ((intMoneyStr >= 1000000) && (intMoneyStr < 1000000000))
		intVal = intMoneyStr.substr(0, intMoneyStr.length - 6) + ' ' + ' ' + intMoneyStr.substr(-6, 3) + ' ' + intMoneyStr.substr(-3);
	if (intMoneyStr < 1000) intVal = intMoneyStr;
	if (moneyStr.indexOf(".") != -1) {
		floatVal = moneyStr.substr(moneyStr.indexOf(".") + 1, moneyStr.length);
		if (floatVal.length == 1)
			floatVal += '0';
	} else {
		floatVal = '00';
	}

	money = intVal + ',' + floatVal;
	// alert(money);
//	money = money.replace(" ", "");
//	money = money.replace(",", ".");
	//money = parseFloat(money);
	//alert(money);
	return money;
}