<!--
/////////////////////////////////////
//  FSA Calculator v1.0
//  Developed by Chad Matthews
//  August 2001
/////////////////////////////////////

  var ti            = new Array();
  ti['single']      = new Array();
  ti['married']     = new Array();
  ti['single']['bracket1']  = 22.7; // $0 - $25,250
  ti['single']['bracket2']  = 35.7; // $25,251 - $43,850
  ti['single']['bracket3']  = 35.7; // $43,851 - $63,550
  ti['single']['bracket4']  = 38.7; // $63,551 - $76,200
  ti['single']['bracket5']  = 32.5; // $76,201 - $105,950
  ti['single']['bracket6']  = 32.5; // $105,951 - $132,600 
  ti['single']['bracket7']  = 37.5; // $132,601 - $161,450
  ti['single']['bracket8']  = 37.5; // $161,451 - $288,350
  ti['single']['bracket9']  = 41.6; // $288,351 and up

  ti['married']['bracket1'] = 22.7; // $0 - $25,250
  ti['married']['bracket2'] = 22.7; // $25,251 - $43,850
  ti['married']['bracket3'] = 35.7; // $43,851 - $63,550
  ti['married']['bracket4'] = 35.7; // $63,551 - $76,200
  ti['married']['bracket5'] = 29.5; // $76,201 - $105,950
  ti['married']['bracket6'] = 32.5; // $105,951 - $132,600
  ti['married']['bracket7'] = 32.5; // $132,601 - $161,450
  ti['married']['bracket8'] = 37.5; // $161,451 - $288,350
  ti['married']['bracket9'] = 41.6; // $288,351 and up

/////////////////////////////////////
//  Converts user input into proper
//  currency while stripping all none
//  numeric input.  Adds first 7 inputs
//  to give total one.
/////////////////////////////////////

function totalOne() {
  var fform      = document.fsaform;
  var firstTotal = fform.total1.value
  var firstTotal = null;
  var a = stadm2(fform.deductibles.value,0);
  var b = stadm2(fform.copay.value,0);
  var c = stadm2(fform.prescriptionDrugs.value,0);
  var d = stadm2(fform.visionCare.value,0);
  var e = stadm2(fform.dental.value,0);
  var f = stadm2(fform.medicalEquip.value,0);
  var g = stadm2(fform.otherNotcovered.value,0);

  fform.deductibles.value       = toCurrency(a);
  fform.copay.value             = toCurrency(b);
  fform.prescriptionDrugs.value = toCurrency(c);
  fform.visionCare.value        = toCurrency(d);
  fform.dental.value            = toCurrency(e);
  fform.medicalEquip.value      = toCurrency(f);
  fform.otherNotcovered.value   = toCurrency(g);
  var firstTotal                = round(a + b + c + d + e + f + g);
  fform.total1.value            = toCurrency(firstTotal);
}

function indivPrem() {
  var fform      = document.fsaform;
  var indivPrem  = stadm2(fform.individualPrem.value,0);
  var indivPrem  = round(indivPrem);
  fform.individualPrem.value = toCurrency(indivPrem);
}

function totalTwo() {
  var fform       = document.fsaform;

  var i = stadm2(fform.dayCare.value,'0');
  var j = stadm2(fform.homeCare.value,'0');
  var k = stadm2(fform.preSchool.value,'0');
  var l = stadm2(fform.schoolCare.value,'0');
  var m = stadm2(fform.auPair.value,'0');
  var n = stadm2(fform.dayCamp.value,'0');
  var o = stadm2(fform.ElderdayCare.value,'0');
  var p = stadm2(fform.ElderhomeCare.value,'0');

  var secondTotal           = round(i + j + k + l + m + n + o + p);

  fform.dayCare.value       = toCurrency(i);
  fform.homeCare.value      = toCurrency(j);
  fform.preSchool.value     = toCurrency(k);
  fform.schoolCare.value    = toCurrency(l);
  fform.auPair.value        = toCurrency(m);
  fform.dayCamp.value       = toCurrency(n);
  fform.ElderdayCare.value  = toCurrency(o);
  fform.ElderhomeCare.value = toCurrency(p);

  if (secondTotal <= 5000){
    fform.total2.value        = toCurrency(secondTotal);
  }
  else {
    alert('The Individual Dependent Care total provided\nduring a taxable year shall not exceed \$5,000\n\(\$2,500 in the case of a separate return by a\nmarried individual\).  A default value of \$5,000\nwill be used.'); 
    fform.total2.value        = toCurrency(5000);
  }
}

function bracket() {
  var fform        = document.fsaform;
  var preTaxIncome = stadm2(fform.income2.value,0);
  var state        = document.fsaform.state.options[document.fsaform.state.selectedIndex].value;
  var marb         = document.fsaform.marital.options[document.fsaform.marital.selectedIndex].value;
  fform.income.value = '';

  if (preTaxIncome >= 0 && preTaxIncome <= 25250) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket1";
  }
  else if (preTaxIncome >= 25251 && preTaxIncome <= 43850) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket2";
  }
  else if (preTaxIncome >= 43851 && preTaxIncome <= 63550) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket3";
  }
  else if (preTaxIncome >= 63551 && preTaxIncome <= 76200) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket4";
  }
  else if (preTaxIncome >= 76201 && preTaxIncome <= 105950) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket5";
  }
  else if (preTaxIncome >= 105951 && preTaxIncome <= 132600) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket6";
  }
  else if (preTaxIncome >= 132601 && preTaxIncome <= 161450) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket7";
  }
  else if (preTaxIncome >= 161451 && preTaxIncome <= 288350) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket8";
  }
  else if (preTaxIncome >= 288351) {
    fform.income2.value = toCurrency(preTaxIncome);
    fform.income.value = "bracket9";
  }
}

function calculate() {
  var fform      = document.fsaform;
  var incomeb    = fform.income.value;
  var income     = stadm2(fform.income2.value);
  var marb       = document.fsaform.marital.options[document.fsaform.marital.selectedIndex].value;
  var state      = parseFloat(document.fsaform.state.options[document.fsaform.state.selectedIndex].value);
  var total1     = stadm2(fform.total1.value,0);
  var total2     = stadm2(fform.total2.value,0);
  var indivPrems = stadm2(fform.individualPrem.value,0);
  var paidyearly = parseFloat(stadm2(fform.paidyearly.value,0));
 
  if (incomeb <= 0 || incomeb == null || incomeb == ''){
    alert('Please enter your approximate\nhousehold income, before taxes.');
    fform.income2.focus();
  }
  else if (paidyearly <= 0 || paidyearly == null || paidyearly == ''){
    alert('Please enter how often\nyou are paid yearly.');
    fform.paidyearly.focus();
  }

  else {
  ftax = ti[marb][incomeb];
  ftax += (state + 7.65);
  indivPremb = indivPrems;
  indivPrems = indivPrems * 12;
  indivPremz = toCurrency(indivPrems);
  total5     = round(income/12);
  total6     = round(total2/12);
  total7     = round(total1/12);
  total8     = round(total5 - total6 - total7 - indivPremb);
  total9     = round(total5 * ftax) / 100;
  total10    = round(total8 * ftax) / 100;
  total11    = (total5 - total9 - total6- total7 - indivPremb);
  total12    = (total8 - total10);
  total13    = (total12 - total11);
  annTaxSav  = (total13 * 12);

  fform.total1b.value     = fform.total1.value;
  fform.premiums.value    = indivPremz;
  fform.total2b.value     = fform.total2.value;
  fform.taxrate.value     = ftax +'%';
  ftax                    = (ftax * (total1 + indivPrems + total2)) / 100;

//  paycon                  = (ftax / paidyearly);



  paycon                  = (total1 + total2) / paidyearly;

  fform.paycontrib.value  = toCurrency(paycon);
  fform.taxsavings.value  = toCurrency(ftax);
  fform.total5.value      = toCurrency(total5);
  fform.total5b.value     = toCurrency(total5);
  fform.total5c.value     = toCurrency(total5);
  fform.total6.value      = toCurrency(total6);
  fform.total6b.value     = toCurrency(total6);
  fform.total7.value      = toCurrency(total7);
  fform.total7b.value     = toCurrency(total7);
  fform.total8.value      = toCurrency(total8);
  fform.total9.value      = toCurrency(total9);
  fform.total10.value     = toCurrency(total10);
  fform.total11.value     = toCurrency(total11);
  fform.total12.value     = toCurrency(total12);
  fform.total13.value     = toCurrency(total13);
  fform.annTaxSav.value   = toCurrency(annTaxSav);
  fform.premConver.value  = toCurrency(indivPremb);//
  fform.premConver2.value = toCurrency(indivPremb);//
  fform.zero0.value 	  = "$0.00";
  fform.zero.value  	  = "$0.00";
  }
}

function stadm2(x,def){
  x = x.replace(/[^\.0-9]/g, '');
  if (x == null || x == '') {
    x = def; 
  }
  if (x != null && x != '') x=parseFloat(x);
  return x;
}

function round(x) {
  return Math.round(x*100)/100;
}

function round3(x) {
  return Math.round(x*1000)/1000;
}

function toCurrency(n) {
  var dec, dollars, cents, result;
  result= "" + round(n );
  dec = result.indexOf(".");
  cents = ((dec > 0) ? result.substring(dec,result.length) : ".00");
  if (cents.length == 2) cents += "0";
  dollars = insComma("" + parseInt(result));
  return "$" + dollars + cents;
}

function insComma(data) {
  var l, i = 0;
  var result = "";
  l = data.length-1;
  if (l<=2) return data;
  result=data.charAt(0);
  for (i = 1; i <= l; i++) {
    if ( (( l-i+1 ) % 3) == 0 )
    result += ",";
    result += data.charAt(i);
  }
  return result;
}
//  End --> 