<!--

/*

Loan Calulator
*/

function Begin() {
Recalc(document.LoanData)
if (document.LoanData) {
  if (document.LoanData.Amount) document.LoanData.Amount.focus();
}
}

function AddResultsSection() {
/*if (document.all) {
  document.writeln("<SPAN ID='ResultsSpan'></SPAN><BR>")
} else {
  document.writeln("<CENTER><TEXTAREA NAME='Results' ROWS='5' COLS='45' WRAP='VIRTUAL' onFocus='document.LoanData.Amount.focus()' onChange='Recalc(this.form)'>")
  document.writeln("</TEXTAREA></CENTER>")
}
*/
document.writeln("<td>&nbsp;</td><td>")
var agent = navigator.userAgent.toUpperCase()
if (agent.indexOf("AOL") > -1) {
  document.writeln("<INPUT TYPE='SUBMIT' VALUE='Calculate'></td>")
} else {
  document.writeln("<INPUT TYPE='BUTTON' VALUE='Calculate' onClick='CalcPayment(this.form,2)'>")
  document.writeln("</td></tr><tr><td colspan='2' style='text-align: center;'>")
  document.writeln("The Payment Schedule is shown in a separate browser window.<BR>")
  document.writeln("To print it, click File in the new window, then click Print.</td>")
}

}

function NewFraction(frm) {
var APR = frm.YearlyRate.value
var DecPos = APR.indexOf(".")
var NewDec = frm.Fraction.options[frm.Fraction.selectedIndex].value

if (NewDec == 0) NewDec = "";
if (DecPos == -1) {
  frm.YearlyRate.value = "" + APR + NewDec
} else {
  frm.YearlyRate.value = "" + APR.substring(0,DecPos) + NewDec
}
Recalc(frm)
}

function CheckDate(frm) {
var Today = new Date()
var yr = Today.getYear()
var strYr = "" + yr
if (strYr.length != 4) {
	if (strYr.length == 3) {
		strYr = "" + (yr+1900)
	} else {
		strYr = "" + (yr+2000)
	}
}
var DateStr = frm.StartDate.value
if (DateStr == "") DateStr = FormatDate(Today.getMonth()+1,Today.getDate(),strYr);
if (DateStr.indexOf("/") == DateStr.lastIndexOf("/")) DateStr += "/" + strYr;

var TstDate = new Date(DateStr)
var tstYr = TstDate.getYear()
var strTstYr = "" + tstYr
if (strTstYr.length != 4) {
	if (strTstYr.length == 3) {
		strTstYr = "" + (tstYr+1900)
	} else {
		strTstYr = "" + (tstYr+2000)
	}
}
DateStr = FormatDate(TstDate.getMonth()+1,TstDate.getDate(),strTstYr)
if (DateStr.indexOf("N",1) > -1) {
  // Error - return today's date
  DateStr = FormatDate(Today.getMonth()+1,Today.getDate(),strYr)
}

return DateStr

}

function YearsChanged(frm) {
frm.Years.value = NumberCheck(frm.Years.value)
frm.Months.value = Math.round(frm.Years.value * 12)
MonthsChanged(frm)
}

function MonthsChanged(frm) {
frm.Months.value = Math.round(NumberCheck(frm.Months.value))
frm.Years.value = Dollars(frm.Months.value / 12)
Recalc(frm)
}

function Recalc(frm) {

frm.Amount.value = Dsp(Dollars(NumberCheck(frm.Amount.value)))
frm.downpayment.value = Dsp(Dollars(NumberCheck(frm.downpayment.value)))
frm.YearlyRate.value = NumberCheck(frm.YearlyRate.value)
frm.AddlPrin.value = Dsp(Dollars(NumberCheck(frm.AddlPrin.value)))

frm.AnnualTax.value = Dsp(Dollars(NumberCheck(frm.AnnualTax.value)))
frm.AnnualPMI.value = Dsp(Dollars(NumberCheck(frm.AnnualPMI.value)))
frm.AnnualInsurance.value = Dsp(Dollars(NumberCheck(frm.AnnualInsurance.value)))
frm.AnnualDues.value = Dsp(Dollars(NumberCheck(frm.AnnualDues.value)))
CalcPayment(frm,1)
}

function Dsp(number) {
//This function formats a number for display with 2 decimals.

var x = number + ""
var DecPos = x.indexOf(".")
if (DecPos == -1) return x + ".00"

var Dec = x.substring(DecPos+1, DecPos+3) + "00" + ""
return x.substring(0,DecPos) + "." + Dec.substring(0,2)
}

function Dollars(number) {
// This function rounds the passed number to 2 decimal places for monetary display.
// JavaScript always rounds up at .5.

return Math.round(number * 100) / 100;
}

function NumberCheck(number) {
// This function makes sure a number was entered.  If not, it uses zero.
// If it is a number, its abolute value is used.

var x = parseFloat(number)
if (x != number) {
  x = 0
} else {
  x = Math.abs(number)
}
return x
}

function CalcPayment(frm, task) {

/*

Formula for periodic payment calculations:

                                      PeriodInterestRate
  Payment  =  Principal * -----------------------------------------
                          (                     1                  )
                          (1  -  --------------------------------  )
                          (      (1 + PeriodInterestRate)^Periods  )

*/

var Divisor = 1200
var NbrPeriods = frm.Months.value
var Schedule = frm.Period.options[frm.Period.selectedIndex].value
if (Schedule == "weekly") {
  Divisor = 5200
  NbrPeriods = Math.floor(NbrPeriods / 12 * 52)
}
if (Schedule == "biweekly") {
  Divisor = 2600
  NbrPeriods = Math.floor(NbrPeriods / 12 * 26)
}
if (Schedule == "bimonthly") {
  Divisor = 2400
  NbrPeriods = Math.floor(NbrPeriods / 12 * 24)
}
if (Schedule == "quarterly") {
  Divisor = 400
  NbrPeriods = Math.floor(NbrPeriods / 12 * 4)
}
if (Schedule == "semiannual") {
  Divisor = 200
  NbrPeriods = Math.floor(NbrPeriods / 12 * 2)
}
if (Schedule == "yearly") {
  Divisor = 100
  NbrPeriods = Math.floor(NbrPeriods / 12)
}

var PeriodInterestRate = frm.YearlyRate.value / Divisor
var PeriodsPerYear = Divisor / 100
var RateExponent = Math.pow(1+PeriodInterestRate,NbrPeriods)
var PeriodPayment = Dollars(frm.Amount.value * PeriodInterestRate / (1 - (1/RateExponent)))
var PeriodTax = Dollars(frm.AnnualTax.value / PeriodsPerYear)
var PeriodPMI = Dollars(frm.AnnualPMI.value / PeriodsPerYear)
var PeriodInsurance = Dollars(frm.AnnualInsurance.value / PeriodsPerYear)
var PeriodDues = Dollars(frm.AnnualDues.value / PeriodsPerYear)
var TotalPeriodPayment = Dollars(PeriodPayment + PeriodTax + PeriodPMI + PeriodInsurance + PeriodDues)

var AddlPrincipal = Dollars(frm.AddlPrin.value)
var AdjPeriodPayment = Dollars(PeriodPayment)
if (AddlPrincipal > 0) {
  AdjPeriodPayment = Dollars(PeriodPayment + AddlPrincipal)
  var Balance = Dollars(frm.Amount.value)
  var PmtCt = 0
  var AccumInt = 0
  while (Balance > 0) {
    var PerInt = Balance * PeriodInterestRate
    var PerPrin = AdjPeriodPayment - PerInt
    if (Balance + PerInt < AdjPeriodPayment) PerPrin = Balance;
    Balance -= PerPrin
    AccumInt += PerInt
    PmtCt += 1
  }
}

if (task == 1) {

  // Start of Section to update calculator results.

  var BegStrong = ""
  var EndStrong = ""
  if (document.all) {
    BegStrong = "<STRONG>"
    EndStrong = "</STRONG>"
  }

  var ResultsTxt = "The " + BegStrong + Schedule + " payment" + EndStrong + " for this loan would be " + BegStrong + "$" + Dsp(PeriodPayment) + EndStrong + ".  "
  var WithTxt = "With " + Schedule + " amounts for"
  var AndTxt = ""
  var Comma = ""
  var AddOns = Math.abs((PeriodTax > 0) + (PeriodPMI > 0) + (PeriodInsurance > 0) + (PeriodDues > 0))
  var AddedOn = 0
  if (PeriodTax > 0) {
    ResultsTxt += AndTxt + WithTxt + " property tax"
    WithTxt = ""
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (PeriodPMI > 0) {
    ResultsTxt += Comma + AndTxt + WithTxt + " mortgage insurance"
    WithTxt = ""
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (PeriodInsurance > 0) {
    ResultsTxt += Comma + AndTxt + WithTxt + " hazard insurance"
    WithTxt = ""
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (PeriodDues > 0) {
    ResultsTxt += Comma + AndTxt + WithTxt + " association dues"
    WithTxt = ""
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (AddOns > 0) {
    ResultsTxt += " added on, the " + Schedule + " total would be " + BegStrong + "$" + Dsp(TotalPeriodPayment) + EndStrong + ".  "
  }
  if (AddlPrincipal > 0) {
    ResultsTxt += "With " + Schedule + " additional payments of $" + Dsp(AddlPrincipal) + " the " + Schedule + " total becomes " + BegStrong + "$" + Dsp(TotalPeriodPayment + AddlPrincipal) + EndStrong + ".  "
  }
  if (AddOns > 0) ResultsTxt += "Note that";

  // Re-count the number of AddOns without including PMI.
  AddOns = Math.abs((PeriodTax > 0) + (PeriodInsurance > 0) + (PeriodDues > 0))
  AndTxt = ""
  Comma = ""
  AddedOn = 0
  if (PeriodTax > 0) {
    ResultsTxt += " property taxes"
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (PeriodInsurance > 0) {
    ResultsTxt += Comma + AndTxt + " hazard insurance"
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (PeriodDues > 0) {
    ResultsTxt += Comma + AndTxt + " association dues"
    AddedOn += 1
    if (AddedOn == AddOns - 1) AndTxt = " and";
    if (AddOns > 2) Comma = ",";
  }
  if (AddOns > 0) {
    ResultsTxt += " would probably increase over time"
  }
  if (PeriodPMI > 0) {
    if (AddOns > 0) ResultsTxt += ", and that"
    ResultsTxt += " mortgage insurance payments can usually be eliminated once your loan is 20% paid off"
    ResultsTxt += " or you have 20% equity in the assessed value of your home (check with the mortgage holder for details)"
  }
  if (AddOns > 0 || PeriodPMI > 0) ResultsTxt += ".  "
  ResultsTxt += "The " + BegStrong + "total principal plus interest" + EndStrong + " on this loan would "
  if (AddlPrincipal > 0) ResultsTxt += "normally ";
  ResultsTxt += "be " + BegStrong + "$" + Dsp(Dollars(NbrPeriods * PeriodPayment)) + EndStrong + ", of which " + BegStrong + "$" + Dsp(Dollars(NbrPeriods * PeriodPayment - frm.Amount.value)) + EndStrong + " would be " + BegStrong + "interest" + EndStrong + "."
  if (AddlPrincipal > 0) {
    ResultsTxt += "  With the " + BegStrong + "extra " + Schedule + " $" + Dsp(AddlPrincipal) + EndStrong + ", the loan would be " + BegStrong + "paid off in "
    var NbrYrs = parseInt(PmtCt/12)
    var NbrMths = PmtCt - (NbrYrs * 12)
    if (NbrYrs > 0) ResultsTxt += NbrYrs + " years";
    if (NbrYrs > 0 && NbrMths > 0) ResultsTxt += " and "
    if (NbrMths > 0) ResultsTxt += NbrMths + " months"
    ResultsTxt += "." + EndStrong + "  The interest paid would then be $" + Dsp(Dollars(AccumInt)) + " and you would " + BegStrong + "save $" + Dsp(Dollars(NbrPeriods * PeriodPayment - frm.Amount.value - AccumInt)) + "." + EndStrong
  }

  if (document.all) {
    document.all.ResultsSpan.innerHTML = ResultsTxt
  } else {
    frm.Results.value = ResultsTxt
  }

  // End of section to update calculator results.

} else {

  // Start of section to print amortization schedule.
  
  SchedWindow = window.open("","PaymentSchedule","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=300")
  SchedWindow.document.open()
  var LoanInfo = "<HTML><BODY BGCOLOR='#FFFFCC' LINK='#448844' VLINK='#AD0018' ALINK='#FFFFFF'>"

  LoanInfo += "<TABLE WIDTH='100%'><TR>"
  LoanInfo += "<TD VALIGN='TOP'><FONT FACE='Arial,Helvetica,Sans-serif'>"
  //LoanInfo += "<IMG SRC='tucslogo.gif' WIDTH='20' HEIGHT='30' BORDER='0' ALT='notalot.com' VSPACE=0 ALIGN='LEFT'>"
  //LoanInfo += "<IMG SRC='tucslogo.gif' WIDTH='20' HEIGHT='30' BORDER='0' ALT='notalot.com' VSPACE=0 ALIGN='RIGHT'>"
  LoanInfo += "<CENTER><STRONG>Loan Payment Schedule</STRONG><BR></CENTER>"
  LoanInfo += "</FONT></TD></TR></TABLE><BR><BR>"

  LoanInfo += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>"
  LoanInfo += "<TR><TD VALIGN='TOP'><PRE><STRONG>Loan Amount<BR>"
   LoanInfo += "Down Payment<BR>"
  LoanInfo += "Annual Interest Rate<BR>"
  LoanInfo += "Payment Frequency<BR>"
  LoanInfo += "Loan Length (Years)<BR>"
  LoanInfo += "Loan Length (Months)<BR>"
  if (frm.AddlPrin.value > 0) LoanInfo += "Additional Principal<BR>";
  if (frm.AnnualTax.value > 0) LoanInfo += "Annual Property Tax<BR>";
  if (frm.AnnualPMI.value > 0) LoanInfo += "Annual Mortgage Insurance<BR>";
  if (frm.AnnualInsurance.value > 0) LoanInfo += "Annual Hazard Insurance<BR>";
  if (frm.AnnualDues.value > 0) LoanInfo += "Annual Association Dues<BR>";
  LoanInfo += "</STRONG></PRE></TD>"

  LoanInfo += "<TD ALIGN='RIGHT' VALIGN='TOP'><PRE> $" + Dsp(Dollars(frm.Amount.value)) + "<BR>"
  LoanInfo += " $" + Dsp(Dollars(frm.downpayment.value)) + "<BR>"
  LoanInfo += " " + frm.YearlyRate.value + "%<BR>"
  LoanInfo += " " + Schedule + "<BR>"
  LoanInfo += " " + frm.Years.value + "<BR>"
  LoanInfo += " " + frm.Months.value + "<BR>"
  if (frm.AddlPrin.value > 0) LoanInfo += " " + Dsp(AddlPrincipal) + "<BR>";
  if (frm.AnnualTax.value > 0) LoanInfo += " " + Dsp(Dollars(frm.AnnualTax.value)) + "<BR>";
  if (frm.AnnualPMI.value > 0) LoanInfo += " " + Dsp(Dollars(frm.AnnualPMI.value)) + "<BR>";
  if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Dsp(Dollars(frm.AnnualInsurance.value)) + "<BR>";
  if (frm.AnnualDues.value > 0) LoanInfo += " " + Dsp(Dollars(frm.AnnualDues.value)) + "<BR>";
  LoanInfo += "</TD></TR></TABLE><BR><PRE>"
  SchedWindow.document.writeln(LoanInfo)
  LoanInfo = ""

  var ColHdr = "<STRONG><U>    Date</U> <U>  Principal</U>"
  if (frm.AddlPrin.value > 0) ColHdr += " <U>Addl Prin</U>";
  ColHdr += " <U>  Interest</U>"
  if (frm.AnnualTax.value > 0) ColHdr += " <U>      Tax</U>";
  if (frm.AnnualPMI.value > 0) ColHdr += " <U>      PMI</U>"
  if (frm.AnnualInsurance.value > 0) ColHdr += " <U>   Hazard</U>"
  if (frm.AnnualDues.value > 0) ColHdr += " <U>     Dues</U>"
  ColHdr += " <U>Total Payment</U> <U>Loan Balance</U></STRONG>"
  DspTotals = true  // Force first display of column headers

  var AdjustedAmount = frm.Amount.value - frm.downpayment.value
  var Balance = Dollars(AdjustedAmount)
  var AccumInt = 0
  var AccumPrin = 0
  var AccumAddlPrin = 0
  var AccumTax = 0
  var AccumPMI = 0
  var AccumInsurance = 0
  var AccumDues = 0
  var YrAccumInt = 0
  var YrAccumPrin = 0
  var YrAccumAddlPrin = 0
  var YrAccumTax = 0
  var YrAccumPMI = 0
  var YrAccumInsurance = 0
  var YrAccumDues = 0
  var PayDate = CheckDate(frm)
  var PmtCt = 0
  var ddOrig = PayDate.substring(3,5)
  if (ddOrig.substring(0,1) == "0") ddOrig = ddOrig.substring(1,2);
  ddOrig = parseInt(ddOrig)
  if (Schedule == "bimonthly") {
    ddOrig2 = ddOrig + 15
    if (ddOrig2 > 30) ddOrig2 -= 30;
  }

  var mm = PayDate.substring(0,2)
  if (mm.substring(0,1) == "0") mm = mm.substring(1,2);
  mm = parseInt(mm)
  var dd = ddOrig
  var yy = PayDate.substring(6,8)
  if (yy.substring(0,1) == "0") yy = yy.substring(1,2);
  yy = parseInt(yy)

  while (Balance > 0) {
    if (DspTotals) SchedWindow.document.writeln(ColHdr);
    var PerInt = Balance * PeriodInterestRate
    var PerPrin = AdjPeriodPayment - PerInt
    if (Balance + PerInt < AdjPeriodPayment) PerPrin = Balance;
    Balance -= PerPrin
    AccumInt += PerInt
    YrAccumInt += PerInt
    AccumPrin += PerPrin
    YrAccumPrin += PerPrin
    AccumAddlPrin += AddlPrincipal
    YrAccumAddlPrin += AddlPrincipal
    AccumTax += PeriodTax
    YrAccumTax += PeriodTax
    AccumPMI += PeriodPMI
    YrAccumPMI += PeriodPMI
    AccumInsurance += PeriodInsurance
    YrAccumInsurance += PeriodInsurance
    AccumDues += PeriodDues
    YrAccumDues += PeriodDues
    PmtCt += 1
    LoanInfo = ""
    if (PmtCt > NbrPeriods) LoanInfo += "<EM>";
    LoanInfo += PayDate + " " + Format(Dsp(Dollars(PerPrin)),11,"R"," ")
    if (AddlPrincipal > 0) LoanInfo += " " + Format(Dsp(AddlPrincipal),9,"R"," ");
    LoanInfo += " " + Format(Dsp(Dollars(PerInt)),10,"R"," ")
    if (frm.AnnualTax.value > 0) LoanInfo += " " + Format(Dsp(PeriodTax),9,"R"," ");
    if (frm.AnnualPMI.value > 0) LoanInfo += " " + Format(Dsp(PeriodPMI),9,"R"," ");
    if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Format(Dsp(PeriodInsurance),9,"R"," ");
    if (frm.AnnualDues.value > 0) LoanInfo += " " + Format(Dsp(PeriodDues),9,"R"," ");
    LoanInfo += " " + Format(Dsp(PerPrin+PerInt+PeriodTax+PeriodPMI+PeriodInsurance+PeriodDues),13,"R"," ")
    LoanInfo += " " + Format(Dsp(Dollars(Balance)),12,"R"," ")
    if (PmtCt > NbrPeriods) LoanInfo += "</EM>";
    SchedWindow.document.writeln(LoanInfo)

    // Get the next pay date.  Display totals if this is the end of a year.
    var DspTotals = false
    if (Balance > 0) {
      if (Schedule == "monthly") {
        dd = ddOrig
        mm += 1
        if (mm > 12) {
          mm -= 12
          yy += 1
          if (yy > 99) yy = 0;
          DspTotals = true
        }
        if (dd > 28 && mm == 2) dd = 28;
        if (dd > 30 && (mm == 4 || mm == 6 || mm == 9 || mm == 11)) dd = 30;
      }
      if (Schedule == "bimonthly") {
        if (PmtCt/2 != Math.floor(PmtCt/2)) {
           dd = ddOrig2
           if (ddOrig2 < ddOrig) mm += 1;
        } else {
           dd = ddOrig
           if (ddOrig < ddOrig2) mm += 1;
        }
        if (mm > 12) {
          mm -= 12
          yy += 1
          if (yy > 99) yy = 0;
          DspTotals = true
        }
        if (dd > 28 && mm == 2) dd = 28;
        if (dd > 30 && (mm == 4 || mm == 6 || mm == 9 || mm == 11)) dd = 30;
      }
      if (Schedule == "weekly") {
        for (var idx=1; idx<=7; idx++) {
          dd += 1
          var tstDate = new Date(yy,mm-1,dd)
          if (tstDate.getDate() != dd) {
            dd = 1
            mm += 1
            if (mm > 12) {
              mm -= 12
              yy += 1
              if (yy > 99) yy = 0;
              DspTotals = true
            }
          }
        }
      }
      if (Schedule == "biweekly") {
        for (var idx=1; idx<=14; idx++) {
          dd += 1
          var tstDate = new Date(yy,mm-1,dd)
          if (tstDate.getDate() != dd) {
            dd = 1
            mm += 1
            if (mm > 12) {
              mm -= 12
              yy += 1
              if (yy > 99) yy = 0;
              DspTotals = true
            }
          }
        }
      }
      if (Schedule == "quarterly") {
        mm += 3
        if (mm > 12) {
          mm -= 12
          yy += 1
          if (yy > 99) yy = 0;
          DspTotals = true
        }
        if (dd > 28 && mm == 2) dd = 28;
        if (dd > 30 && (mm == 4 || mm == 6 || mm == 9 || mm == 11)) dd = 30;
      }
      if (Schedule == "semiannual") {
        mm += 6
        if (mm > 12) {
          mm -= 12
          yy += 1
          if (yy > 99) yy = 0;
          DspTotals = true
        }
        if (dd > 28 && mm == 2) dd = 28;
        if (dd > 30 && (mm == 4 || mm == 6 || mm == 9 || mm == 11)) dd = 30;
      }
      if (Schedule == "yearly") {
        yy += 1
        if (yy > 99) yy = 0;
        if (dd > 28 && mm == 2) dd = 28;
      }
      PayDate = FormatDate(mm,dd,yy)
      if (DspTotals) {
        // Display the year's totals
        var DspYr = yy - 1
        if (DspYr < 0) DspYr = 99
        LoanInfo = "<STRONG>" + Format(DspYr,2,"R","0") + " Total " + Format(Dsp(Dollars(YrAccumPrin)),11,"R"," ")
        if (AddlPrincipal > 0) LoanInfo += " " + Format(Dsp(YrAccumAddlPrin),9,"R"," ");
        LoanInfo += " " + Format(Dsp(Dollars(YrAccumInt)),10,"R"," ")
        if (frm.AnnualTax.value > 0) LoanInfo += " " + Format(Dsp(YrAccumTax),9,"R"," ");
        if (frm.AnnualPMI.value > 0) LoanInfo += " " + Format(Dsp(YrAccumPMI),9,"R"," ")
        if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Format(Dsp(YrAccumInsurance),9,"R"," ")
        if (frm.AnnualDues.value > 0) LoanInfo += " " + Format(Dsp(YrAccumDues),9,"R"," ")
        LoanInfo += " " + Format(Dsp(YrAccumPrin+YrAccumInt+YrAccumTax+YrAccumPMI+YrAccumInsurance+YrAccumDues),13,"R"," ")
        LoanInfo += " " + Format(Dsp(Balance),12,"R"," ")
        SchedWindow.document.writeln(LoanInfo)
        YrAccumPrin = 0
        YrAccumAddlPrin = 0
        YrAccumInt = 0
        YrAccumTax = 0
        YrAccumPMI = 0
        YrAccumInsurance = 0
        YrAccumDues = 0

        // Display the totals for the loan to date
        LoanInfo = "Loan Tot " + Format(Dsp(Dollars(AccumPrin)),11,"R"," ")
        if (AddlPrincipal > 0) LoanInfo += " " + Format(Dsp(AccumAddlPrin),9,"R"," ");
        LoanInfo += " " + Format(Dsp(Dollars(AccumInt)),10,"R"," ")
        if (frm.AnnualTax.value > 0) LoanInfo += " " + Format(Dsp(AccumTax),9,"R"," ");
        if (frm.AnnualPMI.value > 0) LoanInfo += " " + Format(Dsp(AccumPMI),9,"R"," ")
        if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Format(Dsp(AccumInsurance),9,"R"," ")
        if (frm.AnnualDues.value > 0) LoanInfo += " " + Format(Dsp(AccumDues),9,"R"," ")
        LoanInfo += " " + Format(Dsp(AccumPrin+AccumInt+AccumTax+AccumPMI+AccumInsurance+AccumDues),13,"R"," ")
        LoanInfo += "</STRONG><BR><BR><HR><BR><BR>"
        SchedWindow.document.writeln(LoanInfo)
      }
    }
  }

  // Print final totals
  if (YrAccumPrin > 0) {
    LoanInfo = "<STRONG>" + Format(yy,2,"R","0") + " Total " + Format(Dsp(Dollars(YrAccumPrin)),11,"R"," ")
    if (AddlPrincipal > 0) LoanInfo += " " + Format(Dsp(YrAccumAddlPrin),9,"R"," ");
    LoanInfo += " " + Format(Dsp(Dollars(YrAccumInt)),10,"R"," ")
    if (frm.AnnualTax.value > 0) LoanInfo += " " + Format(Dsp(YrAccumTax),9,"R"," ");
    if (frm.AnnualPMI.value > 0) LoanInfo += " " + Format(Dsp(YrAccumPMI),9,"R"," ")
    if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Format(Dsp(YrAccumInsurance),9,"R"," ")
    if (frm.AnnualDues.value > 0) LoanInfo += " " + Format(Dsp(YrAccumDues),9,"R"," ")
    LoanInfo += " " + Format(Dsp(YrAccumPrin+YrAccumInt+YrAccumTax+YrAccumPMI+YrAccumInsurance+YrAccumDues),13,"R"," ")
    LoanInfo += " " + Format(Dsp(Balance),12,"R"," ")
    SchedWindow.document.writeln(LoanInfo)
  }

  if (AccumPrin > 0) {
    LoanInfo = "Loan Tot " + Format(Dsp(Dollars(AccumPrin)),11,"R"," ")
    if (AddlPrincipal > 0) LoanInfo += " " + Format(Dsp(AccumAddlPrin),9,"R"," ");
    LoanInfo += " " + Format(Dsp(Dollars(AccumInt)),10,"R"," ")
    if (frm.AnnualTax.value > 0) LoanInfo += " " + Format(Dsp(AccumTax),9,"R"," ");
    if (frm.AnnualPMI.value > 0) LoanInfo += " " + Format(Dsp(AccumPMI),9,"R"," ")
    if (frm.AnnualInsurance.value > 0) LoanInfo += " " + Format(Dsp(AccumInsurance),9,"R"," ")
    if (frm.AnnualDues.value > 0) LoanInfo += " " + Format(Dsp(AccumDues),9,"R"," ")
    LoanInfo += " " + Format(Dsp(AccumPrin+AccumInt+AccumTax+AccumPMI+AccumInsurance+AccumDues),13,"R"," ")
    LoanInfo += "</STRONG>"
    SchedWindow.document.writeln(LoanInfo)
  }

  SchedWindow.document.writeln("</PRE></BODY></HTML>")
  SchedWindow.document.close()

  // End of section to print amortization schedule.
}

}

function FormatDate(mm,dd,yy) {

return Format(mm,2,"R","0") + "/" + Format(dd,2,"R","0") + "/" + Format(yy,2,"R","0")  

}

function Format(value,lgth,just,fillchar) {

var FormatStr = value + ""
//if (FormatStr.length > lgth) return FormatStr;

if (FormatStr.length > lgth) {
  if (just == "L") {
    FormatStr =  FormatStr.substring(0,lgth)
  } else {
    FormatStr = FormatStr.substring(FormatStr.length-lgth,FormatStr.length)
  }
} else {
  var fill = ""
  for (var idx=0; idx < (lgth-FormatStr.length); idx++) {
    fill += fillchar
  }
  if (just == "L") {
    FormatStr += fill 
  } else {
    FormatStr = fill + FormatStr
  }
}
return FormatStr
}


// -->