// JavaScript Document
/***************************
(c) 2008 www.TUFaT.com
All Rights Reserved. Please
do not re-sell/re-distribute
this software.
***************************/
function saving(form)
{

	var amt = eval (form.s1.value);
	var dep = eval (form.s2.value);
	var int = eval (form.s3.value);
	var yrs = eval (form.s4.value);
	var finalText='';
	var tsav=0;
	var cmp = form.cmp.value;
	var py = 12;
	var cmptext='Monthly';
  	if (cmp == '2') { 
		py = 4; 
		cmptext='Quarterly';
	}
  	if (cmp == '3') { 
		py = 2; 
		cmptext='Semiannualy';
	}
  	if (cmp == '4') { 
		py = 1; 
		cmptext='Annualy';
	}
	finalText = finalText + "<center><strong>Your Monthly Deposit for "+yrs+" Years of $ "+formatNumberDec(dep,2,1)+"<br/><br/>";
	finalText = finalText + "for an Interest Rate of "+formatNumberDec(int,3,1)+"% compounded "+cmptext+"<br/><br/>";
	finalText = finalText + "With an Initial Amount of $ "+formatNumberDec(amt,2,1)+":</strong></center>";
	mi = int / (py * 100); 
	sav = amt; 
	tcont = amt;
	finalText=finalText + '<table width="60%" align="center" cellspacing="0" cellpadding="2" border="1"><tr><td>Year</td><td>Balance</td></tr>';
	for (i = 1; i <= yrs; i++)
  	{
		for (j=0; j<12; j++)
		{
			tsav = eval(tsav) +eval(sav);
			if (py == 12) 
			{ 
				sav = sav * (1 + eval(mi)); 
				asav = tsav; 
			}
			
			if (py == 4 && (j == 2 | j == 5 | j == 8 | j == 11)) { 
				asav = tsav/3+eval(dep); 
				sav = eval(sav) +eval(asav * mi); 
				tsav = 0; 
			}
			
			if (py == 2 && (j == 5 | j == 11)) { 
				asav = tsav/6+eval(dep*2.5); 
				sav = eval(sav) +eval(asav * mi); 
				tsav = 0; 
			}
			
			if (py == 1 && j == 11) { 
				asav = tsav/12+eval(dep*5.5); 
				sav = eval(sav) +eval(asav * mi); 
				tsav = 0; 
			}
			
			sav = eval(sav) + eval(dep); 
			tcont = eval(tcont) + eval(dep); 
		}
		finalText = finalText + "<tr><td>"+i+"</td><td>"+formatNumberDec(sav,2,1)+"</td></tr>";
  }
  finalText = finalText + "</table><br/><strong>Final Savings Balance: $ "+formatNumberDec(sav,2,1)+" </strong>";
document.getElementById("results").innerHTML=finalText;
document.getElementById("results").style.display='block';
}
