// Calculations for Millennia Logix retirement savings calculator
// Copyright 2005 Millennia Logix, Inc., by John B Lisle
function calcul8cs() {

// Check if data has been entered correctly then do the calculation.

	if (document.calculator.InitDeposit.value == "") { 
		alert("Please enter the initial deposit. If it is 0, enter 0.");
		document.calculator.InitDeposit.focus();
		return false
		}

	if (document.calculator.savingsTerm.value == "" || document.calculator.savingsTerm.value == "0" ) {
		alert("Please enter the length of time you wish to be in this savings program.");
		document.calculator.savingsTerm.focus();
		return false
		}

	if (document.calculator.IntRate.value == "" || document.calculator.IntRate.value == "0" ) {
		alert("Please enter the Interest or Dividend rate you expect for the savings program.");
		document.calculator.IntRate.focus();
		return false
		}

	var calcType = getRadioButtonValue(document.calculator.calcType)

	var numMonths = document.calculator.savingsTerm.value
	var perUnit = getRadioButtonValue(document.calculator.savingsTermUnit)
	if ( perUnit == "year" ) { numMonths = numMonths * 12 }

	var rRateFactor = document.calculator.IntRate.value / 1200.
	var rInitDep = document.calculator.InitDeposit.value
	var Factor = Math.pow( (1. + rRateFactor), numMonths )

	if ( calcType != "monthlySavings" ) {
		if (document.calculator.savingsGoal.value == "" || document.calculator.savingsGoal.value == "0" ) {
			alert("Please enter the enter your savings goal.");
			document.calculator.savingsGoal.focus();
			return false
			}
		document.calculator.amountSaved.value = document.calculator.savingsGoal.value
		var rGoal = document.calculator.savingsGoal.value - (rInitDep * Factor)
		var rdepAmt = (rRateFactor * rGoal) / ( Factor - 1. )
		document.calculator.depAmount.value = Round2Dollars(rdepAmt)		
		}
	else {
		if (document.calculator.depositAmount.value == "" || document.calculator.depositAmount.value == "0" ) {
			alert("Please enter the amount you would like to deposit each month in your savings program.");
			document.calculator.depositAmount.focus();
			return false
			}
		document.calculator.depAmount.value = document.calculator.depositAmount.value
		var rPrincipal = document.calculator.depositAmount.value
		var rSaveTotal = (rInitDep * Factor) + ( rPrincipal / rRateFactor ) * ( Factor - 1. )
		document.calculator.amountSaved.value = Round2Dollars(rSaveTotal)
		}

	bCalc = true
	return true
	
	}
