function calculateOrder() {
	orderTotal = 0;
	taxTotal = 0;
	currentItem = 1;
	orderValid = false;
	for (repetition = 1; repetition <= entryCount; repetition++) {
		theQuantity = document.getElementById('quantity_' + repetition).value;
		theQuantity = Math.round(theQuantity);
		document.getElementById('quantity_' + repetition).value = theQuantity;
		theAmountInclusive = document.getElementById('product_inclusive_' + repetition).value;
		theTax = document.getElementById('product_tax_' + repetition).value;
		theSubtotal = theQuantity * theAmountInclusive;
		orderTotal = orderTotal + theSubtotal;
		document.getElementById('subtotal_' + repetition).innerHTML = roundAndPad(theSubtotal);
		if (document.getElementById('quantity_' + repetition).value >= 1) {
			document.getElementById('item_name_' + repetition).name = 'item_name_' + currentItem;
			document.getElementById('quantity_' + repetition).name = 'quantity_' + currentItem;
			document.getElementById('amount_' + repetition).name = 'amount_' + currentItem;
			taxTotal = taxTotal + (theQuantity * theTax);
			orderValid = true;
			currentItem ++;
		} else {
			document.getElementById('item_name_' + repetition).name = '';
			document.getElementById('quantity_' + repetition).name = '';
			document.getElementById('amount_' + repetition).name = '';
		}
	}
	if (document.getElementById('shipping_choice').checked == true) {
		shippingExclusive = parseFloat(document.getElementById('shipping_exclusive').value);
		shippingInclusive = parseFloat(document.getElementById('shipping_inclusive').value);
		shippingTax = parseFloat(document.getElementById('shipping_tax').value);
		document.getElementById('no_shipping').value = 2;
		document.getElementById('shipping_1').value = shippingExclusive;
		document.getElementById('shipping_shown').innerHTML = roundAndPad(shippingInclusive);
	} else {
		shippingExclusive = 0;
		shippingInclusive = 0;
		shippingTax = 0;
		document.getElementById('no_shipping').value = 1;
		document.getElementById('shipping_1').value = 0;
		document.getElementById('shipping_shown').innerHTML = '0.00';
	}
	orderTotal = orderTotal + shippingInclusive;
	taxTotal = taxTotal + shippingTax;
	document.getElementById('tax_cart').value = roundAndPad(taxTotal);
	document.getElementById('total').innerHTML = roundAndPad(orderTotal);
}

function payOrder() {
	calculateOrder(true);
	if (orderValid) {
		return true;
	} else {
		alert('Please enter a quantity for each item you want to order.');
		return false;
	}
}

function roundAndPad(theNumber) {
	theInflatedNumber = Math.round(theNumber * 100)
	theRoundedNumber = theInflatedNumber / 100;
	theNumberString = theInflatedNumber.toString();
	if (theRoundedNumber == 0) {
		thePaddedNumber = '0.00';
	} else if (theNumberString.substr(theNumberString.length - 2,2) == '00') {
		thePaddedNumber = theRoundedNumber.toString() + '.00';
	} else if (theNumberString.substr(theNumberString.length - 1,2) == '0') {
		thePaddedNumber = theRoundedNumber.toString() + '0';
	} else {
		thePaddedNumber = theRoundedNumber;
	}
	return thePaddedNumber;
}