
function thousandFormat(theNumber) {
	theNumber = "" + theNumber;
	var newNumber = ""
	var threeCounter = 0;
	if (theNumber.indexOf('.') != -1) {
		newNumber = theNumber.substring(theNumber.indexOf('.'),theNumber.length);
		theNumber = theNumber.substring(0,theNumber.indexOf('.'));
	}
	for (counter=(theNumber.length)-1;counter > -1;counter--) {
		if (threeCounter == 3 && theNumber.charAt(counter) != '-') {
			newNumber = "," + newNumber;
			threeCounter = 0;
		}	
		newNumber = theNumber.charAt(counter) + newNumber;
		threeCounter ++;
	}
	if (newNumber.indexOf('.') == -1) newNumber += ".00";
	if ((newNumber.length - newNumber.indexOf('.')) != 3 && newNumber.indexOf('.') != -1) {
		newNumber += "0";
	}
	return newNumber;
}

function stripCrap(theValue) {
	var newValue = "";
	var permitted = "0123456789.";
	for (counter=0;counter <= theValue.length;counter++) {
		if (permitted.indexOf(theValue.charAt(counter)) == -1) {
			// do nutin'
		} else {
		newValue = newValue + theValue.charAt(counter);
		}
	}
	return newValue-0;
}
 
function basiccalc() {

	LoanAmt 	= stripCrap(document.calcform.LoanAmt.value);
	DwnPay  	= 0;
	inInterest 	= stripCrap(document.calcform.Intrate.value);
	Years		= stripCrap(document.calcform.No_of_yrs.value);

	AnnualIntrate = inInterest/100;
	MonthRate=AnnualIntrate/12
	NumPayments=Years*12
	FortRate=AnnualIntrate/26
	NumPayments3=Years*26
	WeekRate=AnnualIntrate/52
	NumPayments2=Years*52
	Prin=LoanAmt-DwnPay
	MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100
	FortPayment=Math.floor((Prin*FortRate)/(1-Math.pow((1+FortRate),(-1*NumPayments3)))*100)/100
	WeekPayment=Math.floor((Prin*WeekRate)/(1-Math.pow((1+WeekRate),(-1*NumPayments2)))*100)/100
   
	document.calcform.No_of_Pay.value	= thousandFormat(NumPayments);
	document.calcform.MnthPay.value		= thousandFormat(MonthPayment);
	document.calcform.fortPay.value		= thousandFormat(FortPayment);
	document.calcform.weekPay.value		= thousandFormat(WeekPayment);
}
