// JavaScript Document
/***************************
(c) 2008 www.TUFaT.com
All Rights Reserved. Please
do not re-sell/re-distribute
this software.
***************************/
function CalcEstate(form)
{
	var StrOut='';
	StrOut=StrOut+"<strong>Assumptions</strong>: ";
	StrOut=StrOut+"<ul><li>Your contributions increase with inflation since they are tied to your salary.";
	StrOut=StrOut+"<li>Your life insurance amount increases with inflation since it is often tied to your salary as well.";
	StrOut=StrOut+"<li>Cash and Personal Property increases with Inflation ";
	StrOut=StrOut+"<li>Car Equity stays the same since cars actually depreciate and get bought and sold alot over time. (i.e. it's too complicated!) Over time the value of your car becomes a trivial percent of most peoples' estates anyway.</ul>";
	StrOut=StrOut+"<table border='1' cellpadding='2' cellspacing='0'><tr><th>Year<th>IRA/401(k)<th>Other<br />Investments<th>Life<br />Insurance<th>Home Equity<th>Cash<th>Personal<br />Property<th>Car(s)<th>Total<th>Unified<br /> Credit<th>Estate<br />Tax";
	
	var td = form.TD.value;
	var ty = form.TY.value;
	var tc = form.TC.value;
	var at = form.ST.value;
	var sy = form.SY.value;
	var sc = form.SC.value;
	var li = form.LI.value;
	var hv = form.HV.value;
	var hl = form.HL.value;
	var hr = form.HR.value;
	var hp = form.HP.value;
	var hi = form.HI.value;
	var ha = form.HA.value;
	var cash = form.CH.value;
	var pp = form.PP.value;
	var av = form.AV.value;
	var al = form.AL.value;
	var inp = form.IN.value;
	
	
taurus = 20000;

ald = al/5;
inp = (1 + inp/100);
cars = av - al;
var t = "td align='right'";
var et = Array(675000,675000,700000,700000,850000,950000,1000000,1000000,1000000,1000000,1000000);
y0=0;
var lim=1000000;
var cage=0;
for (yr=0; yr<50; yr++)
{
  td = td * (1 + ty/100);
  td=eval(td)+eval(tc);
  tc = tc * inp;
  at = at * (1 + sy/100);
  at = eval(at) + eval(sc);
  cash = cash * inp;
  he = hv - hl;
  
  tot =  eval(td) + eval(at) + eval(li) + eval(he) + eval(cash) + eval(pp) + eval(cars);
  if (yr < 11 && yr>0) { lim = et[yr-1]; } else { lim = 1000000; }
  if(yr==0) lim=650000;
  if (tot > lim) 
  { 
    if (tot < 750000) { est = (tot - lim) * .37; }
    if (tot > 750000 && lim < 750000) 
    { est = (tot - lim) * .39 + (750000 - lim) * .37; }
    if (tot > 750000 && lim >= 750000) 
    { est = (tot - lim) * .39; }
    if (tot > 1000000 && lim < 750000) 
    { est = (tot -1000000) * .41 + 250000 * .39 + (750000-lim) * .37; }
    if (tot > 1000000 && lim > 750000 && lim < 1000000) 
    { est = (tot -1000000) * .41 + (1000000-lim)  * .39 ; }
    if (tot > 1000000 && lim >= 1000000)
    { est = (tot - lim) * .41; }
    if (tot > 1250000 && lim > 1250000) 
    { est = eval(est) +  (tot  - lim) * .02; } 
    if (tot > 1250000 && lim < 1250000) 
    { est = eval(est) +  (tot  - 1250000) * .02; } 
    if (tot > 1500000 && lim > 1500000) 
    { est = eval(est) +  (tot  - lim) * .02; } 
    if (tot > 1500000 && lim <= 1500000) 
    { est = eval(est) +  (tot  - 1500000) * .02; }

    if (tot > 2000000 && yr == 2)
    { est = eval(est) +  (tot - 2000000) * .05; } 
    if (tot > 2000000 && yr == 3)
    { est = eval(est) +  (tot - 2000000) * .04; } 
    if (tot > 2000000 && yr == 4)
    { est = eval(est) +  (tot - 2000000) * .03; } 
    if (tot > 2000000 && yr == 5)
    { est = eval(est) +  (tot - 2000000) * .02; } 
    if (tot > 2000000 && yr == 6)
    { est = eval(est) +  (tot - 2000000) * .01; } 

    if (tot > 2000000 && (yr == 1 | yr > 10)) 
    { est = eval(est) +  (tot  - 2000000) * .04; } 
    if (tot > 2500000 && (yr == 1 | yr > 10)) 
    { est = eval(est) +  (tot  - 2500000) * .04; } 
    if (tot > 3000000 && (yr == 1 | yr > 10)) 
    { est = eval(est) +  (tot  - 3000000) * .02; } 
  }
  else { est = 0; }
  if (yr == 10) { est = 0; }
  tabr = "<tr><"+t+">"+(1999+eval(yr))+"<"+t+">"+formatNumberDec(td,0,0)+"<"+t+">"+formatNumberDec(at,0,0)+"<"+t+">"+formatNumberDec(li,0,0)+"<"+t+">"+formatNumberDec(he,0,0)+"<"+t+">"+formatNumberDec(cash,0,0)+"<"+t+">"+formatNumberDec(pp,0,0)+"<"+t+">"+formatNumberDec(cars,0,0)+"<"+t+">"+formatNumberDec(tot,0,0)+"<"+t+">"+formatNumberDec(lim,0,0)+"<"+t+">"+formatNumberDec(est,0,0)+"</td></tr>";
  StrOut=StrOut+tabr;
  pp = pp * inp;
  sc = sc * inp;
  li = li * inp;
  taurus = taurus * inp;
  av = av * .9;
  al = al - ald;
  if (al < 0 ) { al = 0; }
  cage++;
  if (av < 1000 | cage > 10 ) 
  { cage = 0; av = taurus; al = .8 * taurus; }
  hv = hv * (1 + ha/100);
  hl = hl * (1 + hi/100) - 12 * hp;
  if (hl < 0) { hl = 0; }
  
}
document.getElementById("results").innerHTML=StrOut;
document.getElementById("results").style.display='block';

}
