function updatePaymentAmount()
{
	class_of = document.getElementById('class_of');
	quantity = document.getElementById('quantity');
	payment_amount = document.getElementById('payment_amount');
	
	total = 0.0;
	
	var qty = parseInt(quantity.value);
	if (isFinite(quantity.value)) {
		switch (class_of.value)
		{
			case 'class_of_1992':
				if (qty > 4) {
					qty = 4;
					quantity.value = 4;
				}
				total += qty * 60.00;
				if (qty > 1) total -= 5;
				break;
		}
	}
	
	donate = document.getElementsByName('donate[]')[0];
	donation_amount = document.getElementById('donation_amount').value.replace(',', '');
	if (donate.checked && isFinite(parseFloat(donation_amount))) {
		total += parseFloat(donation_amount);
	}
	
	payment_amount.value = formatCurrency(total);
}

function enablePaymentAmount()
{
	document.getElementById('payment_amount').disabled = '';
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if (isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length-(4 * i + 3));
		
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
