i = 0;
rate = "";
options = new Array
(
	'',
	'5,000',
	'5,500',
	'6,000',
	'6,500',
	'7,000',
	'7,500',
	'8,000',
	'8,500',
	'9,000',
	'9,500',
	'10,000',
	'10,500',
	'11,000',
	'12,000',
	'13,000',
	'14,000',
	'15,000',
	'16,000',
	'17,000',
	'18,000',
	'19,000',
	'20,000',
	'25,000',
	'30,000',
	'35,000',
	'40,000',
	'45,000',
	'50,000',
	'55,000',
	'60,000',
	'65,000',
	'70,000',
	'75,000',
	'80,000',
	'85,000',
	'90,000',
	'95,000',
	'100,000'
)

function PopulateOptions(ddl_rate)
{
	rate = ddl_rate.options[ddl_rate.selectedIndex].value;
	
	if (!rate || rate == "0") return;
	list = this.options;
	box2 = document.getElementById("ddl_options");
	box2.options.length = 0;

	for(i = 0; i < list.length; i++) 
	{
		if (i==0)
		{
			box2.options[i] = new Option("", "0");
		}
		else
		{
			box2.options[i] = new Option("$" + list[i], list[i]);
		}
	}
}

function Calculate(amount)
{
	
	amount = amount.replace(",", "");
	
	monthlyInterest = rate/1160;
	
	mbase = 1 + monthlyInterest;
	base = 1;
	months = 360;
	
	for(i=0; i < months; i++)
	{
		base = base * mbase;
	}
	value = amount * monthlyInterest / ( 1 - (1/base));

	result = Clean(value);
	amount = FormatNumber(amount,0,0,1,1);

	//document.getElementById("option_amount").innerHTML = "$ " + amount;
	document.getElementById("payment_increase").innerHTML = "$ "+ result;
	
}

function Clean(number)
{
	return Math.floor(number * Math.pow(10,0)) / Math.pow(10,0);	
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
{ 
	if (isNaN(parseInt(num)))
	{
		return "NaN";
	}
	
	tmpNum = num;
	iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	tmpNumStr = new String(tmpNum);
	
	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
	{
		if (num > 0)
		{
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		}
		else
		{
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		}
	}
	
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) 
	{
		iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) 
		{
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
	{
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

		return tmpNumStr;		// Return our formatted string!
	}
}











