function isDigit(num) {
	if (num.length > 1) {
		return false;
	}
	var string = "1234567890";
	if (string.indexOf(num) != -1) {
		return true;
	}
	return false;
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

function calculate_price() {
	var amount = document.getElementById('calculator_amount').value;

	// validate string
	for (n = 0; n < amount.length; n++) {
		if (!isDigit(amount.charAt(n))) {
			alert("Bitte geben Sie nur Zahlen ein");
			return false;
		}
	}

	// calculate result
	var result = amount/1000 * 0.20;
	if (result > 3000) {
		result = 3000;
	}
	// round result
	result = result.toFixed(2);

	document.getElementById('calculator_result').value = addCommas(result) + " Euro";
}
