function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
function reset_form_a(){ 
		document.form_a.a.value=""; 
		document.form_a.b.value=""; 
		document.form_a.c.value=""; 
		document.form_a.d.value="";
}
function submit_form_a(){ 
		a = document.form_a.a.value; 
		b = document.form_a.b.value * 12; 
		c = document.form_a.c.value / 12; 
		d = 1 + c/100;
		document.form_a.d.value = CommaFormatted(CurrencyFormatted(a * Math.pow(d,b)));
		document.form_a.a.value = CommaFormatted(CurrencyFormatted(a));
} 
function reset_form_b(){ 
		document.form_b.a.value=""; 
		document.form_b.b.value=""; 
		document.form_b.c.value=""; 
		document.form_b.d.value="";
}
function submit_form_b(){ 
		fg = 0;
		a = document.form_b.a.value; 
		b = document.form_b.b.value * 12; 
		c = document.form_b.c.value / 12; 
		d = 1 + c/100;
		for (i=1;i<=b;i++)
		{
			fg = fg + Math.pow(d,i);
		}
		
		
		document.form_b.d.value = CommaFormatted(CurrencyFormatted(a * fg));
		document.form_b.a.value = CommaFormatted(CurrencyFormatted(a));
} 
function reset_form_c(){ 
		document.form_c.a.value=""; 
		document.form_c.b.value=""; 
		document.form_c.c.value=""; 
		document.form_c.d.value="";
		document.form_c.d2.value="";
}
function submit_form_c(){ 
		fg = 0;
		a = document.form_c.a.value; 
		b = document.form_c.b.value * 12; 
		c = document.form_c.c.value / 12; 
		d = 1 + c/100;
		
		
		document.form_c.d.value = CommaFormatted(CurrencyFormatted((a /Math.pow(d,b))));
		
		
		for (i=1;i<=b;i++)
		{
			fg = fg + Math.pow(d,i);
		}
		
		document.form_c.d2.value = CommaFormatted(CurrencyFormatted(a / fg));

		document.form_c.a.value = CommaFormatted(CurrencyFormatted(a));
} 


