function changeCount(dect_sep, tho_sep, vat_prices, res) {
	var fullPrice = 0;
	var vat = 0;
	if (vat_prices) {
		vat = Math.round(parseFloat($('vat_input').value) * 100) / 100
	}
	
	for (var i = 0; i < res.length; i++) {
		var countTag = $(i + '_count');
		var count = res[i].count;
		var discount = res[i].discount;
		var singlePrice = Math.round(parseFloat($(i + '_singleprice').value) * 100) / 100;
		var cumulativePrice = singlePrice * count * (1 - discount);

		if ($(i + '_discount') != null) {
			$(i + '_discount').innerHTML = number_format(discount * 100, 1, dect_sep, tho_sep) + '%';
		}
		$(i + '_price').innerHTML = number_format(cumulativePrice, 2, dect_sep, tho_sep);
		fullPrice += cumulativePrice;
	}
	var priceexclvat = fullPrice;
	if (vat_prices) {
		priceexclvat = priceexclvat/vat;
	}
	var vatpart = fullPrice - priceexclvat;
	
	$('priceexclvat').innerHTML = number_format(priceexclvat, 2, dect_sep, tho_sep);
	if ($('vat') != null) {
		$('vat').innerHTML = number_format(vatpart, 2, dect_sep, tho_sep);
	}
	$('full_price').innerHTML = number_format(fullPrice, 2, dect_sep, tho_sep);
}

function updateCount(dect_sep, tho_sep, vat_prices) {
	for (var i = 0; $(i + '_count') != null; i++) {
		var countTag = $(i + '_count');
		var count = parseInt(countTag.value);
		if (isNaN(count) || count < 1) {
			countTag.value = 1;
		}
		if (count > 999) {
			countTag.value = 999;
		}
	}
	var frm = Form.serialize($(document.forms[0]),true);
	frm.s = 31000;
	new Ajax.Request('index.php',
		{
			method: 'post',
			parameters: frm,
//			postBody: Object.toJSON(frm),
	    onSuccess: function(xmlHttpRequest) {
	    	var res = xmlHttpRequest.responseText.evalJSON(true);
				changeCount(dect_sep, tho_sep, vat_prices, res)
	    },
	    onFailure: function(xmlHttpRequest) {
	    	window.alert(
	    		'Fehler beim Berechnen der Artikelmenge!\n' +
	    		'Grund: ' +
	    		xmlHttpRequest.status + ' - ' +
	    		xmlHttpRequest.statusText
	    	);
				return false;
	    },
	    onComplete: function(xmlHttpRequest) {
//	    	window.alert(xmlHttpRequest.responseText);
	    }
	  }
	);
	return true;
}
