
function compute_payment(balance, rate, num_payments, pay_per_year) {
	var payment;

	if (rate <= 0.0) {
		payment = balance * 1.0 / (num_payments);
	} else {
		payment = balance * (rate / 100.0 / pay_per_year) /
				  (1.0 - Math.pow(1.0 + rate / 100.0 / pay_per_year, -num_payments));
	}

	return Math.floor(payment * 100.0 + 0.5) / 100.0;
}

function goCalc() {
	var button = document.getElementById('CalcButton');
	button.disabled = true;
	var timeoutID = setTimeout('calculate()', 500);
}

function showHideText(txt) {
	var msgBox = document.getElementById('msg');
	msgBox.innerHTML = txt;
}


function formatAsMoney(mnt) {
	mnt -= 0;
	mnt = (Math.round(mnt * 100)) / 100;
	return (mnt == Math.floor(mnt)) ? mnt + '.00'
			: ( (mnt * 10 == Math.floor(mnt * 10)) ?
				mnt + '0' : mnt);
}

function toNumber(fnum) {
	var strBuffer = new String(fnum);
	var rString = '';
	var periodCount = 0;
	for (nPos = 0; nPos < strBuffer.length; nPos++) {
		if ((strBuffer.charAt(nPos) >= '0' && strBuffer.charAt(nPos) <= '9') ||
			strBuffer.charAt(nPos) == '.') {
			if (strBuffer.charAt(nPos) == '.') {
				periodCount++;
			}
			if (periodCount > 1) {
				return 1 * rString;
			}
			rString += strBuffer.charAt(nPos);
		}
	}
	return 1 * rString;
}

