
<!-- Begin

function calculate(formObj)
{
    var startMoney = parseFloat(formObj.startMoney.value);
    var annualReturn = parseFloat(formObj.annualReturn.value);
    var monthlySavings = parseFloat(formObj.monthlySavings.value);
    
		var totalAssets = startMoney;
		
		if ( Math.round(startMoney) >= 1000000 )
			alert("You are already a millionaire. You don't need to play with the calculator.");
		else if ( annualReturn == 0.0 && monthlySavings == 0.0 && Math.round(startMoney) < 1000000 )
			alert("With " +  annualReturn + "% return and no monthly savings, it's impossible to grow your money. Try again.");
		else
		{
			for ( var i = 1; ; i++ )
			{
					totalAssets = (totalAssets+monthlySavings*12.0)*(1+annualReturn/100.0);
				
					if ( totalAssets >= 1000000.0) 
						break;
			}
					 
			totalAssets = Math.round((totalAssets)*100.0)/100.0;
 			 
			formObj.totalAssets.value = totalAssets;
			formObj.totalYears.value = i;  
    	    	                                                         
 			if ( i >= 60 )
 				alert("Well, you can forget about being a millionaire (in " + i + " years?) unless you save a lot more than you do now." );    
 			else if ( i >= 50 && i < 60 )
 				alert("What! You want to be a millionaire in " + i + " years? That's too slow! Hurry up!!!" );    
 			else if ( i >= 30 && i < 50 )
 				alert("OK, you have the chance to have $1M in " + i + " years. Do you know if you save a little more, you can get there faster?" );    
 			else if ( i >= 20 && i < 30 )
 				alert("Becoming a millionaire in " + i + " years is Awesome! Great job!!!" );    
 			else if ( i < 20 )
 			alert("Wow! Can't believe you will have a million dollars in just " + i + " years! Congratulations!!!" );    
 		}
			
    return;
}

// End -->