
var confirmyes =  'n'
var cashcontrib = 'n'

<!-- hide this script tag's contents from old browsers ---  >

// compute form

function computeForm(form)
{
//-- edit fields

 var yrs, empe, empr, anninc, moGross, currBal;

  if ((form.interestC.value.length == 0) ||
     (form.interestM.value.length == 0)   ||
     (form.interestA.value.length == 0))
         {
     alert("All Interest boxes must contain a non-zero value.");
    document.form.interestC.focus();    
return;
          }
    if (isNum(form.years.value)) {
        yrs = eval(form.years.value)
}                                 
  else
      {
     alert("Your entry of " + form.years.value + " in Years of Future Contributions must be a number representing whole years."); 
    document.form.years.focus();
return;     
}
 //-- check and translate number strings

   //-- years of future contributions
  if (isMoneyFormat(form.years.value)){
    yrs = moneyFormatAmt
                                    }
  else
      {
     alert("Your entry of " + form.years.value + " in Years of future contributions is not a valid number.");
    document.form.years.focus();
     return; 
      }

// this checks to see the percentage values do not exceed limits

var empettl, emprttl, ttlcontrib;

empettl = form.empePct.value
emprttl = form.emprPct.value
ttlContrib = (empettl - 0) + (emprttl - 0)

//if (confirmyes == 'n') {
//if (ttlContrib>25) {
 //     confirmyes = 'y';       
 //if(confirm("Your Total Contributions percentage of " + ttlContrib + " percent exceeds the 401(k) limit of 25 percent of Gross Salary.\n\n Click OK to proceed and overide \n\n Click CANCEL to not proceed and then view information on Contribution Limits")){
                
        //      }
///else {
//              document.form.empePct.focus();
//              msgWindow=window.open("contribution.shtml","displayWindow","menubar=yes,scrollbars=yes,status=yes");
//              confirmyes = 'n';
//              return;
//}
        
//}

//}

  if (yrs<0 || 100<yrs) {
     alert("Years of future contributions must be in the range of 0 to 100");
        document.form.years.focus();     
        return;
              }
 //-- employee percent
 
  if (isMoneyFormat(form.empePct.value)){
    empe = moneyFormatAmt;
                                   }
  else
      {
     alert("Your entry of " + form.empePct.value + " in YOUR monthly contributions is not a valid percent.");
        document.form.empePct.focus();     
        return; 
      }
 
  if (empe<0 || 100<empe) {
     alert("YOUR monthly contribution must be a percent in the range of 0 to 100");
    document.form.empePct.focus();
 return;
              }
              
  //-- employer percent
 
  if (isMoneyFormat(form.emprPct.value)){
    empr = moneyFormatAmt
                                    }
  else
      {
     alert("Your entry of " + form.emprPct.value + " in EMPLOYER monthly contributions is not a valid percent.");
        document.form.emprPct.focus();     
return; 
      }
 
  if (empr<0 || 100<empr) {
     alert("Your monthly EMPLOYER contribution must be a percent in the range of 0 to 100");
        document.form.emprPct.focus();     
return;
              }
              
    //-- annual percentage increase
 
  if (isMoneyFormat(form.annInc.value)){
    annInc = moneyFormatAmt;
                                    }
  else
      {
     alert("Your entry of " + form.annInc.value + " in Average Annual Increase is not a valid percent.");
    document.form.annInc.focus(); 
        return; 
      }
 
  if (annInc<0 || 100<annInc) {
     alert("Your entry of " + form.annInc.value + " in Average Annual Increase must be a percent in the range of 0 to 100");
    document.form.annInc.focus(); 
     return;
              }            
       //-- monthly gross 
 
  if (isMoneyFormat(form.moGross.value)){
    moGross = moneyFormatAmt;
    form.moGross.value = currency(moGross)}
  else
      {
     alert("Your entry of " + form.moGross.value + " in Monthly Gross Salary is not a valid dollar figure.");
    document.form.moGross.focus(); 
     return; 
      }
 
  if (moGross<0) {
     alert("Your entry of " + form.moGross.value + " in Monthly Gross Salary must be a dollar figure greater than or equal to 0");
    document.form.moGross.focus();
     return;
              } 
var ttlCashContrib = (((moGross * empe) * 12 )/100)
if (cashcontrib == 'n'){
//if (ttlCashContrib>10500){
//cashcontrib = 'y'
        //if (confirm("You are exceeding the 401(k) annual contribution limit of $10,500 \n\n Currently your projected Annual Contribution is:  $" + ttlCashContrib + " . \n\n Click OK to proceed and overide. \n\n Click CANCEL to not proceed and then view information on Contribution Limits.")){
        //      }
        //else {
    //  cashcontrib = 'n'
        //      document.form.empePct.focus();
        //      msgWindow=window.open("contribution.shtml","displayWindow","menubar=yes,scrollbars=yes,status=yes");
                
    //  return;
    //}                        
//}
}

       //-- curr balance 
  if (isMoneyFormat(form.balance.value)){
    currBal = moneyFormatAmt;
     form.balance.value = currency(currBal)}
  else
      {
     alert("Your entry of " + form.balance.value + " in Current Total Balance is not a valid dollar figure.");
    document.form.balance.focus();
     return; 
      }
 
  if (currBal<0) {
     alert("Your entry of " + form.balance.value + " in Current Total Balance must be a dollar figure greater than or equal to 0");
    document.form.balance.focus();
     return;
              } 
                         
   //    c o m p u t e   f u t u r e   v a l u e s
                                   
  var iC = eval(form.interestC.value);
  var iM = eval(form.interestM.value);
  var iA = eval(form.interestA.value);
  var i  = 0;                                 // variable interest rate
  var balC = 0;
  var balM = 0;
  var balA = 0;
  var bal =  0;
  var icnt = 0;                 // for interest type looping
  var ycnt = 0;                 // for year looping
  var mcnt = 0;                     // for month looping
  var newMoSal  = 0.00;         // Monthly salary       
  var newMoDep = 0.00;          // monthly deposit amount
 
// compute interest rates and round them

// if (iC > 1.0) {iC = iC / 100 / 12 } else {iC = iC / 12};
//  if (iM > 1.0) {iM = iM / 100 / 12 } else {iM = iM / 12};
//  if (iA > 1.0) {iA = iA / 100 / 12 } else {iA = iA / 12};

//  was having an error if 1% was used we were trying to handle if someone put in
//   .5 to treat it as 50% but now we will treat it as 5% that makes more sense anyway
//
     iC = iC / 100 / 12;
     iM = iM / 100 / 12;
     iA = iA / 100 / 12;

  iC = Math.round(iC*10000000)/10000000;   //--   precsion at 7 digits, matching the mainframe
  iM = Math.round(iM*10000000)/10000000;   //--   precsion at 7 digits, matching the mainframe
  iA = Math.round(iA*10000000)/10000000;   //--   precsion at 7 digits, matching the mainframe  

// loop for each interest rate (conservative, moderate, agressive)

  for(icnt = 1; icnt <= 3; icnt++) {
 
        if (icnt == 1) {i = iC};            
        if (icnt == 2) {i = iM};
        if (icnt == 3) {i = iA};
        bal = parseFloat(currBal);
        newMoSal  = moGross;
        newMoDep = newMoSal * ((empe + empr) / 100);

// loop for each year of investing

        for(ycnt = 1; ycnt <= yrs; ycnt++) {

// loop for each month of investing

                for(mcnt = 1; mcnt <= 12; mcnt++) {

                        moint = bal * i;        
                        if (moint < 0.0) {moint = 0};
                        bal = bal + moint + newMoDep;

                                                 } // -- month loop - mcnt

                newMoSal = newMoSal * (1 + (annInc / 100));
                newMoDep = newMoSal * ((empe + empr) / 100);

                                              }  // -- year loop - ycnt
        if (icnt == 1) {balC = bal};
        if (icnt == 2) {balM = bal};
        if (icnt == 3) {balA = bal};

                      } // -- interest loop - icnt


  
             
  form.fvC.value = currency(balC);      
  form.fvM.value = currency(balM);      
  form.fvA.value = currency(balA);      


 }
// end of compute form function

// misc functions

//-- convert number to currency notation for display 

function currency(anynum) {
       //-- Returns passed number as string in $xxx,xxx.xx format.
       anynum=eval(anynum)
       workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
       if (workStr.indexOf(".")==-1){workStr+=".00"}
       dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
       pStr=workStr.substr(workStr.indexOf("."))
       while (pStr.length<3){pStr+="0"}

       //--- Adds comma in thousands place.
       if (dNum>=1000) {
          dLen=dStr.length
          dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
       }

       //-- Adds comma in millions place.
       if (dNum>=1000000) {
          dLen=dStr.length
          dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
       }
       retval =  "$" + dStr + pStr 
       //-- Put numbers in parentheses if negative.
       if (anynum<0) {retval="("+retval+")"}
        return retval
    }
 
//-- validate and convert currency string to numbers for calculations
 function isMoneyFormat(str) {
    moneyFormatAmt = 0.00;
    if(!str) return false;
    str = "" + str; // force string
    // strip dollar sign    
      var dollarsign = '';
      if (str.length > 1) {
        dollarsign = str.substring(0,1);
       if (dollarsign == '$') 
          str = str.substring(1);        
                      } 
    //   number validation
    for ( var i=0; i<str.length;i++) {
       var ch = str.charAt(i);
       if ("0123456789,.-".indexOf(ch) ==-1) return false
                                }
   //    strip sign character
    var sign = 1;
    var signChar = '';
    if (str.length > 1) {
       signChar = str.substring(0,1);
       if (signChar == '-' || signChar == '+' ) {
          if (signChar == '-') sign = -1;         
          str = str.substring(1);
       }
       else signChar = '';
    }
    var decimalPoint = '.';
    var thDelim = ',';
    test1 = str.split(decimalPoint);
    if (test1.length == 2) { // Decimals found
       if (test1[1].length > 2) return false; // more than 2 decimals
       if (isNum(test1[1])) {
          if (test1[1] < 9 && test1[1].charAt(0) > 0) test1[1] = new String(test1[1]+"0");
       }
       else return false; 
    }
    else test1[1] = "00"; // force decimals
    if (test1[0] == '') test1[0] = 0;
    if (test1[0] && test1[0].indexOf(thDelim) != -1) {
       test2 = test1[0].split(thDelim);  
       if (test2.length >= 2) { // thousands found
          var thError = false;
          for (var i=0;i<test2.length;i++) {
             if (test2[i].length < 3 && i != 0) { thError = true; break; } // all thousands exept the first.
             if (!isNum(test2[i])) { thError = true; break; } // all numbers
          }
          if (thError) return false;
          test1[0] = test2.join('')
       }
    }
    moneyFormatAmt = (parseInt(test1[0]) + parseFloat('.'+test1[1]))*sign;
   return true;
 } 
 
function isNum(str) {
   if(!str) return false;
   for(var i=0; i<str.length; i++){
     var ch=str.charAt(i);
     if ("0123456789".indexOf(ch) ==-1) return false;
   }
   return true;
 } 
 
 
 function clearForm(form)
 { 
        form.reset();
 }


<!-- done hiding from old browsers -->
