path ='/cart/';
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 = number_format(fullprice, 2, ',', ' ');
	$('#fullprice').text(fullprice);
}
function number_format(number, decimals, dec_point, thousands_sep) {	// Format a number with grouped thousands

	var i, j, kw, kd, km;

	if( isNaN(decimals = Math.abs(decimals)) ){
		decimals = 2;
	}
	if( dec_point == undefined ){
		dec_point = ",";
	}
	if( thousands_sep == undefined ){
		thousands_sep = ".";
	}

	i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

	if( (j = i.length) > 3 ){
		j = j % 3;
	} else{
		j = 0;
	}

	km = (j ? i.substr(0, j) + thousands_sep : "");
	kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
	//kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
	kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");


	return km + kw + kd;
}

