// This script and many more are available free online at -->
// The JavaScript Source!! http://javascript.internet.com -->
// Created by: Jeremy Zongker: http://www.creditorweb.com/content/ -->


function cwCalc()
{
if (cwBalance.value=='') {alert('Please enter your credit card balance.'); return;}
if (cwRate.value=='') {alert('Please enter your credit card\'s interest rate.'); return;}
if ( (cwMonthlyAmount.value=='' && cwDesiredMonths.value=='') || (cwMonthlyAmount.value!='' && cwDesiredMonths.value!='') ) {alert('Please enter either a payment amount or desired months.'); return;}

var mRate=(cwRate.value/100)/12;

if (cwMonthlyAmount.value=='')
{
	var payment=cwBalance.value*(mRate)/( 1-Math.pow((1+mRate),(-cwDesiredMonths.value)) );
	payment=Math.round(payment*100)/100;
	cwResult.innerHTML="It will cost <B>$" + payment.toFixed(2) + " a month</B> to pay off this card and will cost you a total of <B>$" + (payment*cwDesiredMonths.value).toFixed(2) + "</B>.";
} else {
	var remainingBalance=cwBalance.value;
	var minPayment=mRate*cwBalance.value;
	var months=0;
	var lastPayment;
	if (minPayment>cwMonthlyAmount.value) {alert ('Your monthly payment is less than the monthly interest charged by this card.');return;}
	while (remainingBalance>0)
	{
		months++;
		remainingBalance=remainingBalance*(1 + mRate)-cwMonthlyAmount.value;
	}
	cwResult.innerHTML="It will take <B>" + months + " months</B> to pay off this card and will cost you a total of <B>$" + (cwMonthlyAmount.value*months).toFixed(2) + "</B>.";
}
}
