<!--
function format (expr, decPlaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decPlaces))
	while (str.length <= decPlaces) {
		str = "0" + str;
	}
	var decPoint = str.length - decPlaces;
	return str.substring(0,decPoint) + "." + str.substring(decPoint,str.length);
}
function isPosInteger (inputVal) {
	inputStr = inputVal.toString();
	if (inputStr.length == 0) return false;
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}
function trim(s) {
	while (s.substr(0, 1) == ' ') {
		s = s.substr(1);
		}
	while (s.substr(s.length-1) == ' ') {
		s = s.substr(0, s.length-1);
		}
	return s;
}
function calcPrice () {
	if (trim(document.forms[0].coupon.value) != couponCode) {
		document.forms[0].whatChanged.value = "coupon";
		document.forms[0].action = document.forms[0].action + '#order';
		document.forms[0].submit();
	}
	else {
		var i, total, price = prices[prices.length-1];
		var ncopies = trim(document.forms[0].nCopies.value);
		if (!isPosInteger(ncopies))
			price = total = "";
		else {
			if (couponPrice > 0)
				price = couponPrice;
			else {
				for (i = 0; i < upperRange.length - 1; i++)
					if (ncopies <= upperRange[i]) {
						price = prices[i];
						break;
					}
			}
			total = format(price * ncopies, 2);
			price = format(price, 2);
		}
		document.forms[0].priceEach.value = price;
		document.forms[0].total.value = total;
	}
}
function changeCurrency () {
	document.forms[0].whatChanged.value = "currency";
	document.forms[0].action = document.forms[0].action + '#currency';
	document.forms[0].submit();
}
function pageLoaded () {
	calcPrice ();
}
//-->
