function chk_valid(input, min, max, msg) { msg = "The " + msg + " value"; var value_string = input.value; for (var i = 0; i < value_string.length; i++) { var ch = value_string.substring(i, i + 1) if ((ch < "0" || "9" < ch) && ch != '.') { alert(msg); return false; } } var num = 0 + value_string if (num < min || max < num) { alert(msg + " needs to be between " + min + " and " + max + "."); return false; } input.value = value_string; return true; } function calcForm(form) { if ((form.Income.value == null || form.Income.value.length == 0) || (form.YearsToGo.value == null || form.YearsToGo.value.length == 0) || (form.Years.value == null || form.Years.value.length == 0) || (form.Inflation.value == null || form.Inflation.value.length == 0) || (form.Rate.value == null || form.Rate.value.length == 0)){ return; } if (!chk_valid(form.Income, 1, 10000000, "Income") || !chk_valid(form.YearsToGo, 1, 100, "Years To Go") || !chk_valid(form.Years, 1, 100, "Years") || !chk_valid(form.Inflation, 0, 99, "Inflation") || !chk_valid(form.Rate, .001, 99, "Interest Rate")) { form.Income.value = "Invalid"; return; } income = parseInt(form.Income.value) int_rate = parseFloat(form.Rate.value) inf_rate = parseFloat(form.Inflation.value) yearsTogo = parseInt(form.YearsToGo.value) Years = parseInt(form.Years.value) Total = 0 parent.left.Income=income parent.left.YearsToGo=yearsTogo parent.left.Years=Years parent.left.Inflation=inf_rate parent.left.Rate=int_rate inf_ratio = 1 + inf_rate/100 // inflation ratio fut_inc = income * Math.pow(inf_ratio, yearsTogo) // future income parent.left.FutureV=roundDollarC(fut_inc) r_iy = int_rate/100; r_oinc = fut_inc; if (inf_rate > 0) { fut_inc = fut_inc * Math.pow(inf_ratio, Years) } for (i=0; i 0) { fut_inc = fut_inc/ (1 + inf_rate/100); } Total = Total / (1 + r_iy) + fut_inc; } parent.left.Total=roundDollarC(Total) } function calcNestEgg(form) { if ((form.myIncome.value == null || form.myIncome.value.length == 0) || (form.spIncome.value == null || form.spIncome.value.length == 0) || (form.PV.value == null || form.PV.value.length == 0)){ return; } if (!chk_valid(form.myIncome, 1, 10000000, "Your Annual Income") || !chk_valid(form.spIncome, 0, 10000000, "Partners' Annual Income") || !chk_valid(form.PV, 0, 10000000, "Investment Current Value")) { form.myIncome.value = "Invalid"; return; } yearsTogo = parseInt(form.YearsToGo.value) income = parseInt(form.Income.value) int_rate = parseFloat(form.Rate.value) inf_rate = parseFloat(form.Inflation.value) Total = trimString(parent.left.Total) myIncome = parseInt(form.myIncome.value) spIncome = parseInt(form.spIncome.value) PV = parseInt(form.PV.value) FV = 0 Payment = 0 p_ATI = 0 parent.left.Income=income parent.left.myIncome=myIncome parent.left.spIncome=spIncome parent.left.YearsToGo=yearsTogo parent.left.Inflation=inf_rate parent.left.Rate=int_rate parent.left.Years = parseInt(form.Years.value) parent.left.PV = roundDollarC(PV) FV=PV*Math.pow((1+int_rate/36500),(yearsTogo*365)) goal = Total - FV CompoundInterest=int_rate/100; Payment=goal*CompoundInterest/(Math.pow((1+CompoundInterest),(yearsTogo))-1) if (Payment < 0) {Payment = 0} parent.left.Y_inv=roundDollarC(Payment) p_ATI=Payment/(myIncome+spIncome) p_ATI*=100 parent.left.p_ATI=Math.round(p_ATI) } function calcDetail(form) { if ((form.Income.value == null || form.Income.value.length == 0) || (form.YearsToGo.value == null || form.YearsToGo.value.length == 0) || (form.Years.value == null || form.Years.value.length == 0) || (form.Inflation.value == null || form.Inflation.value.length == 0) || (form.Rate.value == null || form.Rate.value.length == 0)){ return; } if (!chk_valid(form.Income, 1, 10000000, "Income") || !chk_valid(form.YearsToGo, 1, 100, "Years To Go") || !chk_valid(form.Years, 1, 100, "Years") || !chk_valid(form.Inflation, 0, 99, "Inflation") || !chk_valid(form.Rate, .001, 99, "Interest Rate")) { form.Income.value = "Invalid"; return; } income = parseInt(form.Income.value) int_rate = parseFloat(form.Rate.value) inf_rate = parseFloat(form.Inflation.value) yearsTogo = parseInt(form.YearsToGo.value) Years = parseInt(form.Years.value) Total = 0 parent.left.Income=income parent.left.YearsToGo=yearsTogo parent.left.Years=Years parent.left.Inflation=inf_rate parent.left.Rate=int_rate inf_ratio = 1 + inf_rate/100 // inflation ratio fut_inc = income * Math.pow(inf_ratio, yearsTogo) // future income parent.left.FutureV=roundDollarC(fut_inc) r_iy = int_rate/100; r_oinc = fut_inc; if (inf_rate > 0) { fut_inc = fut_inc * Math.pow(inf_ratio, Years) } for (i=0; i 0) { fut_inc = fut_inc/ (1 + inf_rate/100); } Total = Total / (1 + r_iy) + fut_inc; } parent.left.Total=roundDollarC(Total) fut_inc = r_oinc; DetailWindow = window.open('', 'DetailWin', 'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=450,height=350') DetailWindow.document.writeln("Retirement Details<\/TITLE><\/HEAD><BODY BGCOLOR=\"#FFFFFF\" LINK=\"#0000FF\" VLINK=\"#800080\" TEXT=\"#000000\" onLoad=\"document.closeForm.closeButton.focus();\" TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR VALIGN=TOP ALIGN=LEFT><TD WIDTH=10 HEIGHT=10><IMG SRC=\"clearpixel.gif\" WIDTH=10 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=129><IMG SRC=\"clearpixel.gif\" WIDTH=129 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=58><IMG SRC=\"clearpixel.gif\" WIDTH=58 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=24><IMG SRC=\"clearpixel.gif\" WIDTH=24 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=60><IMG SRC=\"clearpixel.gif\" WIDTH=60 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=132><IMG SRC=\"clearpixel.gif\" WIDTH=132 HEIGHT=1 BORDER=0><\/TD><TD WIDTH=10><IMG SRC=\"clearpixel.gif\" WIDTH=10 HEIGHT=1 BORDER=0><\/TD><\/TR><TR VALIGN=TOP ALIGN=LEFT><TD COLSPAN=2><\/TD><TD WIDTH=142 COLSPAN=3><FORM NAME=\"closeForm\" ACTION=\"\" METHOD=POST><TABLE ID=\"Table2\" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=142><TR><TD WIDTH=142 HEIGHT=24><P><DIV ALIGN=\"CENTER\"><TABLE WIDTH=61 BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><INPUT TYPE=BUTTON NAME=\"closeButton\" VALUE=\"Close\" onClick=\"javascript:self.close()\" onBlur=\"javascript:self.close()\"><\/TD><\/TR><\/TABLE><\/DIV><\/TD><\/TR><\/TABLE><\/CENTER><\/FORM><\/TD><TD COLSPAN=2><\/TD><\/TR><TR VALIGN=TOP ALIGN=LEFT><TD COLSPAN=7 HEIGHT=20><\/TD><\/TR><TR VALIGN=TOP ALIGN=LEFT><TD><\/TD><TD WIDTH=403 COLSPAN=5><TABLE ID=\"Table3\" BORDER=0 CELLSPACING=3 CELLPADDING=1 WIDTH=403><TR><TD WIDTH=25 BGCOLOR=\"#99CCFF\"><P ALIGN=CENTER><B><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">Year<\/FONT><\/B><\/TD><TD WIDTH=75 BGCOLOR=\"#99CCFF\"><P ALIGN=CENTER><B><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">Beg Bal<\/FONT><\/B><\/TD><TD WIDTH=75 BGCOLOR=\"#99CCFF\"><P ALIGN=CENTER><B><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">Withdraw<\/FONT><\/B><\/TD><TD WIDTH=75 BGCOLOR=\"#99CCFF\"><P ALIGN=CENTER><B><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">Interest<\/FONT><\/B><\/TD><TD WIDTH=75 BGCOLOR=\"#99CCFF\"><P ALIGN=CENTER><B><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">End Bal<\/FONT><\/B><\/TD><\/TR>") for (i=1; i<=Years; i++) { bbal = Total; Total = Total - fut_inc; earn = Total * int_rate/100; Total = Total + earn; DetailWindow.document.writeln("<TR><TD WIDTH=25 BGCOLOR=\"#CCCCCC\"><P ALIGN=RIGHT><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">"+i+"<\/FONT><\/TD><TD WIDTH=75 BGCOLOR=\"#FFFFCC\"><P ALIGN=RIGHT><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">$"+roundDollarC(bbal)+"<\/FONT><\/TD><TD WIDTH=75 BGCOLOR=\"#FFFFCC\"><P ALIGN=RIGHT><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">$"+roundDollarC(fut_inc)+"<\/FONT><\/TD><TD WIDTH=75 BGCOLOR=\"#FFFFCC\"><P ALIGN=RIGHT><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">$"+roundDollarC(earn)+"<\/FONT><\/TD><TD WIDTH=75 BGCOLOR=\"#FFFFCC\"><P ALIGN=RIGHT><FONT SIZE=\"-1\" FACE=\"Verdana,Tahoma,Arial,Helvetica\">$"+roundDollarC(Total)+"<\/FONT><\/TD><\/TR>"); if (inf_rate > 0) { fut_inc = fut_inc * (1 + inf_rate/100); } } DetailWindow.document.write("<\/TABLE><\/TD><TD><\/TD><\/TR><TR VALIGN=TOP ALIGN=LEFT><TD COLSPAN=7 HEIGHT=15><\/TD><\/TR><TR VALIGN=TOP ALIGN=LEFT><TD COLSPAN=3><\/TD><TD WIDTH=24><P>  <\/TD><TD COLSPAN=3><\/TD><\/TR><\/TABLE><\/BODY><\/HTML>") DetailWindow.document.close() } function roundDollarC(amount) { var s = ""; var t = ""; var comma; var i; amount = parseFloat(amount); if (!(isNaN(amount))) { // round to nearest dollar amount = Math.round(amount); amount = new String(amount); // format the output if (amount.length > 3) { comma = 0 for (i = (amount.length - 1); i >= 0; i--) { s += amount.charAt(i) comma++ mod=comma%3; if (mod == 0 && i != (amount.length - 1) && i != 0) { s += ","; } } for (i = (s.length - 1); i >= 0; i--) { t += s.charAt(i); } } else { t = amount } } else { // not a number so return zero t = "0.00"; } return t; } function trimString(inString) { var outString = ""; var i; var ch; // where do we start? for (i = 0; i < inString.length; i++) { ch = inString.charAt(i); // alert("ch = "+ch) if (ch != ",") { outString += inString.charAt(i); // alert("outString = "+outString); } } return outString; } function calcHelp(what) { info = "../calculators/help/help_"+what+".html" HelpWindow = window.open(info, 'HelpWin', 'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=550,height=550') }