function calcIT()
{
	var theint=document.Calc.myint.value;
	theint /= 12;
	var thebal=document.Calc.mybal.value;
	thebal=thebal*(1-document.Calc.DownPayment.value);
	var theterm=document.Calc.myterm.value;
	var EXP = 1;
 	for(x = 1; x <= theterm; x++) 
    	{
     		EXP = EXP * (1+theint);
    	}
	var thepay = thebal * theint * EXP / (EXP - 1);
	thepay=decimalPlaces(thepay,2);
	thepay=addCommas(thepay);
	document.Calc.payment.value="$"+thepay;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function decimalPlaces(val, places)
{
	// This function returns the value
	// with the number of decimal places requested
	factor = 1;
	for (i=0; i<places; i++)
	{	factor *= 10; }
	val *= factor;
	val = Math.round(val);
	val /= factor;
	return val;
}
