function validate_num(){
var key = window.event.keyCode
if (key < 48 || key > 57)
  {
  window.event.returnValue = false
  }
}

// format number n as string width w with 2 decimal places
function MakeMoney(StrIn)
{
   var sl, StrOut;
   StrOut = StrIn.toString();
   sl=StrOut.length;


   if (StrOut.indexOf(".") == (-1)){
     StrOut = StrOut + ".00";
     }
   else{
     if (StrOut.indexOf(".") == (sl-4)){
//       Truncate
       }
     else{
       if (StrOut.indexOf(".") == (sl-2)){
         StrOut = StrOut + "0";
       }
     }
   }

   return StrOut;
}


function shout(MyVar){
  var AnswerIs, intCounter;
  if (document.form1.Age.value != "" && document.form1.BaseSalary.value != ""){
    AnswerIs = Math.floor((parseFloat(document.form1.BaseSalary.value) + 995)/1000);
    if (MyVar == "N"){
      for(intCounter=0;intCounter<5;intCounter++){
        if (document.form1.R1[intCounter].checked){
          document.form1.Coverage.value = ((AnswerIs + 2) * 1000) * (intCounter + 1);
        }//end if checked 
      }//end for
    }// else "N"
    else{
      document.form1.Coverage.value = ((AnswerIs + 2) * 1000) * parseFloat(MyVar);
    }//end else "N"
  intCounter = parseFloat(document.form1.Age.value);
  if (intCounter<40) {
    document.form1.Age.value = "40";
    document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .006) /100.00);
  }
  else{
    if ((intCounter>40) && (intCounter<45)){
      document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .006) /100.00);
    }
    else{
      if ((intCounter>=45) && (intCounter<50)){
        document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .010) /100.00);
      }
      else{
        if ((intCounter>=50) && (intCounter<55)){
          document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .015) /100.00);
        }
        else{
          if ((intCounter>=55) && (intCounter<60)){
            document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .031) /100.00);
          }
          else{
            if ((intCounter>=60) && (intCounter<65)){
              document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .070) /100.00);
            }
            else{
              if ((intCounter>=65) && (intCounter<70)){
                document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .090) /100.00);
              }
              else{// >70!
                document.form1.Cost.value = MakeMoney(Math.round(parseFloat(document.form1.Coverage.value) * .140) /100.00);
              }//end else >=65 <70
            }// end else >=60 <65
          }// end else >=55 <60
        }// end else >=50 <55
      }//end else >=45 <50
    }//end else >=40 <45
  }//end else <40


  }//end if do anything
}// end function


function doTotal(){
var longString = "";
var Age, CYears;
var Cost45= 0;
var Cost50= 0;
var Cost55 = 0;
var Cost60 = 0;
var Cost65 = 0;
shout('N');
Age = parseFloat(document.form1.Age.value);
if (Age < 45){
  CYears = 45 - Age;
  Cost45 = Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.006) / 100.00;
  longString = "Years " + Age.toString() + " through 44: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.06) /1000.00)) + " = $" + MakeMoney(Cost45) + String.fromCharCode(10);
}

if (Age < 50){
  if (Age > 45) {
    CYears = 50 - Age;
    Cost50= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.010) /100.00;
    longString = longString + "Years " + Age.toString() + " through 49: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.10) /1000.00)) + " = $" + MakeMoney(Cost50) + String.fromCharCode(10);
  }
  else{
    CYears = 5;
    Cost50= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.010) /100.00;
    longString = longString + "Years 45 through 49: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.10) /1000.00)) + " = $" + MakeMoney(Cost50) + String.fromCharCode(10);
  }
}

if (Age < 55){
  if (Age > 50) {
    CYears = 55 - Age;
    Cost55= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.015) /100.00;
    longString = longString + "Years " + Age.toString() + " through 54: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.15) /1000.00)) + " = $" + MakeMoney(Cost55) + String.fromCharCode(10);
  }
  else{
    CYears = 5;
    Cost55= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.015) /100.00;
    longString = longString + "Years 50 through 54: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.15) /1000.00)) + " = $" + MakeMoney(Cost55) + String.fromCharCode(10);
  }
}

if (Age < 60){
  if (Age > 55) {
    CYears = 60 - Age;
    Cost60= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.031) /100.00;
    longString = longString + "Years " + Age.toString() + " through 59: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.31) /1000.00)) + " = $" + MakeMoney(Cost60) + String.fromCharCode(10);
  }
  else{
    CYears = 5;
    Cost60= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.031) /100.00;
    longString = longString + "Years 55 through 59: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.31) /1000.00)) + " = $" + MakeMoney(Cost60) + String.fromCharCode(10);
  }
}

if (Age < 65){
  if (Age > 60) {
    CYears = 65 - Age;
    Cost65= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.070) /100.00;
    longString = longString + "Years " + Age.toString() + " through 64: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.70) /1000.00)) + " = $" + MakeMoney(Cost65) + String.fromCharCode(10);
  }
  else{
    CYears = 5;
    Cost65= Math.floor(CYears * 26 * parseFloat(document.form1.Coverage.value) * 0.070) /100.00;
    longString = longString + "Years 60 through 64: " + (CYears * 26).toString() + " payments times $" + MakeMoney((Math.floor(parseFloat(document.form1.Coverage.value) * 0.70) /1000.00)) + " = $" + MakeMoney(Cost65) + String.fromCharCode(10);
  }
}

longString = longString + String.fromCharCode(10);

longString = longString + "FEGLI Total Cost through Age 64: $" + MakeMoney(Cost45 + Cost50 + Cost55 + Cost60 + Cost65);
document.form1.outputbox.value = longString;
}

