/*   Note: This calculator has had a major
		overhaul from it's original version by Walter Hooker of Accu Knowledge, Inc.
		in early 2005. AKI's website is www.akinet.com. Come on by! The copyright is
		no longer valid by Infohiway but will be honored for their original effort.
		This version of mortCalc is a Copyright 2005 of Accu Knowledge, Inc.

     Original Copyright Notice: Cut-N-Paste JavaScript from mortCalc
     Toolbox Copyright 1996, Infohiway, Inc.  Restricted use is hereby
     granted (commercial and personal OK) so long as this code
     is not *directly* sold and the copyright notice is buried
     somewhere deep in your HTML document.  A link to our site
     http://www.infohiway.com is always appreciated of course,
     but is absolutely and positively not necessary. ;-)   */

var now;
var curMonth;
var curYear;
var theMonth;
var theYear;

var newLoanAmount;
var newP_I;
var newOrgP_I;

var newYearlyPrn;
var newYearlyInt;

var curPrincipal;
var curInterest;
var newPrincipal;
var newInterest;

var minDate = 0;
var maxDate = 0;
var minAmt;
var maxAmt;

var x_Date ;
var a_curPrincipal ;
var a_curInterest;
var a_curLoanAmount;
var a_newPrincipal;
var a_newInterest;
var a_newLoanAmount;

var fulltable;
var num;

var ppSchdStarted;
var P_I;
var orgP_I;
var Loan_Amount;
var Int_Rate;

var months;

var payoffYears;
var nls;

var rr="\r";
var b="                                                                                                       ";
var d="---------------------------------------------------"
+"--------------------------------------------------------";
var s="$";
var factor;

function checkpmireq(){
        //alert("checking req");
        ratio = ratio * 100
        if (document.forms["mortCalc"].fixadjust[0].checked){
                //alert("fixed Rate");
                //alert(eval(document.forms["mortCalc"].months.value/12));
                //alert(ratio);

                //alert(ratio);
                if ((document.forms["mortCalc"].months.value/12) > 25){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.32;
                        if (ratio>85&&ratio<=90)
                                factor=0.52;
                        if (ratio>90&&ratio<=95)
                                factor=0.78;
                        if (ratio>95)
                                factor=0.96;
                }
                if((document.forms["mortCalc"].months.value/12) > 20 && (document.forms["mortCalc"].months.value/12) <= 25){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.21;
                        if (ratio>85&&ratio<=90)
                                factor=0.41;
                        if (ratio>90&&ratio<=95)
                                factor=0.67;
                        if (ratio>95)
                                factor=0.85;
                }
                if((document.forms["mortCalc"].months.value/12) >= 15 && (document.forms["mortCalc"].months.value/12) <= 20){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.21;
                        if (ratio>85&&ratio<=90)
                                factor=0.41;
                        if (ratio>90&&ratio<=95)
                                factor=0.67;
                        if (ratio>95)
                                factor=0.85;
                }

        }else{
                if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="1"){
                if ((eval(document.forms["mortCalc"].months.value)/12) < 25 ){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.26;
                        if (ratio>85&&ratio<=90)
                                factor=0.54;
                        if (ratio>90&&ratio<=95)
                                factor=0.81;
                        if (ratio>95)
                                factor=1.1;
                }else{
                        if (eval(ratio)<=80)
                                factor=0;
                        if (eval(ratio)>80&&eval(ratio)<=85)
                                factor=0.37;
                        if (eval(ratio)>85&&eval(ratio)<=90)
                                factor=0.65;
                        if (eval(ratio)>90&&eval(ratio)<=95)
                                factor=0.92;
                        if (eval(ratio)>95)
                                factor=1.21;
                                //alert(factor);
                }}

                if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="3"){
                if ((document.forms["mortCalc"].months.value/12) < 25 ){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.22;
                        if (ratio>85&&ratio<=90)
                                factor=0.5;
                        if (ratio>90&&ratio<=95)
                                factor=0.77;
                        if (ratio>95)
                                factor=1.06;
                }else{
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.33;
                        if (ratio>85&&ratio<=90)
                                factor=0.61;
                        if (ratio>90&&ratio<=95)
                                factor=0.88;
                        if (ratio>95)
                                factor=1.17;
                }}

                if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="5"){
                if ((document.forms["mortCalc"].months.value/12) < 25 ){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.21;
                        if (ratio>85&&ratio<=90)
                                factor=0.41;
                        if (ratio>90&&ratio<=95)
                                factor=0.67;
                        if (ratio>95)
                                factor=0.85;
                }else{
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.32;
                        if (ratio>85&&ratio<=90)
                                factor=0.52;
                        if (ratio>90&&ratio<=95)
                                factor=0.78;
                        if (ratio>95)
                                factor=0.96;
                }}

                if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="7"){
                if ((document.forms["mortCalc"].months.value/12) < 25 ){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.21;
                        if (ratio>85&&ratio<=90)
                                factor=0.41;
                        if (ratio>90&&ratio<=95)
                                factor=0.67;
                        if (ratio>95)
                                factor=0.85;
                }else{
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.32;
                        if (ratio>85&&ratio<=90)
                                factor=0.52;
                        if (ratio>90&&ratio<=95)
                                factor=0.78;
                        if (ratio>95)
                                factor=0.96;
                }}
                if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="10"){
                if ((document.forms["mortCalc"].months.value/12) < 25 ){
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.21;
                        if (ratio>85&&ratio<=90)
                                factor=0.41;
                        if (ratio>90&&ratio<=95)
                                factor=0.67;
                        if (ratio>95)
                                factor=0.85;
                }else{
                        if (ratio<=80)
                                factor=0;
                        if (ratio>80&&ratio<=85)
                                factor=0.32;
                        if (ratio>85&&ratio<=90)
                                factor=0.52;
                        if (ratio>90&&ratio<=95)
                                factor=0.78;
                        if (ratio>95)
                                factor=0.96;
                }}
        if (document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].value=="0")
                alert("Please Select an ARM Type");
        }

}

function iA(){
 this.length=iA.arguments.length;
 for (var i=0;i<this.length;i++){
  this[i]=iA.arguments[i];
  }
 }
var pwr=new iA(10);
var dec=new iA(16);
pwr[0]=1;
for (var i=0;i<9;i++){
 pwr[i+1]=pwr[i]*10;
}
dec[0]=.1;
dec[1]=.01;
dec[2]=.001;
dec[3]=.0001;
dec[4]=.00001;
dec[5]=.000001;
dec[6]=.0000001;
dec[7]=.00000001;
dec[8]=.000000001;
dec[9]=.0000000001;
dec[10]=.00000000001;
dec[11]=.000000000001;
dec[12]=.0000000000001;
dec[13]=.00000000000001;
dec[14]=.000000000000001;
dec[15]=.0000000000000001;

var ns="01234567890";
var cr="";
var str="";

function stn(){
 num=0;
 pos=str.indexOf(".");
 sfx="";
 if (pos>-1){
  sfx=str.substring(pos+1,str.length);
  str=str.substring(0,pos);
  }
 strl=str.length;
 for (var i=strl-1;i>-1;i--){
  cr=str.substring(i,i+1);
  pos=ns.indexOf(cr);
  num+=pos*pwr[strl-i-1];
  }
  if (sfx!=""&&sfx.length>dp){
   pos=ns.indexOf(sfx.charAt(dp+1));
   if (pos>4){
    pos=ns.indexOf(sfx.charAt(dp));
    sfx=sfx.substring(0,dp-1)+(pos+1);
    }
   }
  if (sfx!=""){
   for (var i=0;i<dp;i++){
    cr=sfx.substring(i,i+1);
    pos=ns.indexOf(cr);
    num+=pos*dec[i];
    }
/*    sfx="";
    sfx+=num;
    pos=sfx.indexOf(".");
    sfx=sfx.substring(pos+1,sfx.length);
    if (sfx.charAt(dp+1)=="9"){
     num+=dec[sfx.length-2];
     } */
  }
 }

function calcResults(){

	 ppSchdStarted = 0;

	 newLoanAmount = 0;
	 curPrincipal = 0;
	 curInterest  = 0;
	 newPrincipal = 0;
	 newInterest  = 0;
	 P_I = 0;
	 newP_I = 0;
	 payoffYears = 0;
     newYearlyPrn = 0;
     newYearlyInt = 0;

	 minDate = 999999;
	 maxDate = 0;
	 minAmt  = 999999999.00;
	 maxAmt  = 0.00;

     x_Date = new Array();
     a_curPrincipal = new Array();
     a_curInterest = new Array();
     a_newPrincipal = new Array();
     a_newInterest = new Array();
	 a_curLoanAmount = new Array();
	 a_newLoanAmount = new Array();

     curMonth 	 = eval(document.forms["mortCalc"].Lsd_mm.value);
     curYear  	 = eval(document.forms["mortCalc"].Lsd_yy.value);
	 payoffYears = eval(strip(document.forms["mortCalc"].Payoff_Years.value));

     yearlyTax  = eval(strip(document.forms["mortCalc"].Yearly_Tax.value));
     yearlyIns  = eval(strip(document.forms["mortCalc"].Yearly_Ins.value));

     monthlyTax = yearlyTax / 12;
     monthlyIns = yearlyIns / 12;
     escrow = monthlyTax + monthlyIns;

     now = new Date();
     theMonth = now.getMonth() + 1;
     theYear  = now.getFullYear();
     monthsToGo = 0;
     yearsToGo = eval(document.forms["mortCalc"].months.value) / 12;
     yearsDone = theYear;
     monthsDone = theMonth;
     newTheYYMM = (theYear * 100) + theMonth;
     newCurYYMM = (curYear * 100) + curMonth;

     if ((curMonth != theMonth || curYear != theYear) && newCurYYMM < newTheYYMM) {
		yearsDone -= curYear;
		monthsDone -= curMonth;
		if (monthsDone < 0) {
	   		yearsDone--;
	   		monthsDone += 12;
		}

		yearsToGo -= yearsDone;
		if (monthsDone != 0) {
	   		yearsToGo--;
	   		monthsToGo += 12;
	   		monthsToGo -= monthsDone;
		}
     }

     if (yearsToGo <= payoffYears) {
     	alert('Payoff Mortgages Years is less or equal to the number of years to go on your mortgage.\n\nTry again!\n\nBe sure your Original Loan Start Date has a 2 digit month and a 4 digit year');
     	return;
     }

     s_yearsToGo = "";                        // setup yearsToGo
     s_yearsToGo += Math.round(yearsToGo);

     s_monthsToGo = "";                       // setup monthsToGo
     s_monthsToGo += Math.round(monthsToGo);


     // Loan Amount - Loan_Amount
     str=strip(document.forms["mortCalc"].Loan_Amount.value);
     fmtIt();
     bl=str.length+3;
     dp=2;
     stn();
     Loan_Amount=num;
     origLoan_Amount = num;

     // Property Value - prop_val
     str=strip(document.forms["mortCalc"].prop_val.value);
     fmtIt();
     bl=str.length+3;
     dp=2;
     stn();
     prop_val=num;

     // Loan to Property Value - ratio
     ratio = Loan_Amount/prop_val;
     if ((ratio*100) > 120)
            alert("The value of your property is lower than your loan amount. Is this correct?");

     // Interest Rate - Int_Rate
     str=document.forms["mortCalc"].Int_Rate.value;
     dp=4;
     stn();
     Int_Rate=num;

     // Number of months - months and term_yrs
     str=document.forms["mortCalc"].months.value;
     dp=0;
     stn();
     months=num;
     term_yrs = months.value/12;

     // If values are correct then compute the form with function computeForm
     if (months<1||months>999||Int_Rate<.0001||Int_Rate>99||Loan_Amount<1||Loan_Amount>pwr[9]){
        alrt();
      }
     else {
        computeForm();
     }
}

// calculate the monthly P and I - P_I
function computeForm(){
     ls="";
     i = Int_Rate/12/100;            // set month interest rate as a decimal value

 //       M = P * ( i / (1 - (1 + i)^-N))
 //       M = Monthly P and I
 //       P = Loan Amount
 //       i = monthly interest rate
 //       N = number of monthly payments

     tmp = Loan_Amount * (i / (1 - Math.pow((1 + i), -months)));
     P_I    = Math.round((tmp + .005) * 1000) / 1000;   // store P and I round in global variable
	 orgP_I = P_I;

     Total_Int  = ((months*P_I)-Loan_Amount);         // total interest due
     Total_Int += .005;
     Total_Int  = Math.round(Total_Int * 1000) / 1000;

     prtSched();
 }

// calculate the new monthly P and I
function computeNewPayment(){

     i = Int_Rate/12/100;            // set month interest rate as a decimal value

	 payoffMonths = payoffYears * 12;

//       M = P * ( i / (1 - (1 + i)^-N))
//       M = Monthly P and I
//       P = Loan Amount
//       i = monthly interest rate
//       N = number of monthly payments
     tmp = newLoanAmount * (i / (1 - Math.pow((1 + i), -payoffMonths)));
     newP_I    = Math.round((tmp + .005) * 1000) / 1000;   // store P and I round in global variable
	 newOrgP_I = newP_I;

     newTotalInt  = ((payoffMonths*newP_I)-newLoanAmount);         // total interest due
     newTotalInt += .005;
     newTotalInt  = Math.round(Total_Int * 1000) / 1000;

}

// rounds number to X decimal places, defaults to 2
function round(number,X) {
     X = (!X ? 2 : X);         // if x is zero make it 2 otherwise use input value
     return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

var newpmi;

// print the mortgage loan schedule in text area

function prtSched(){

     saveRatio = ratio * 100;
     if (saveRatio <=80){
             ratioline="No PMI Required. Your LTV is " + round((ratio * 100),2) + "% "
     }else{
             ratioline="PMI Required. Your LTV is " + round((ratio * 100),2) + "% "
     }
     now = new Date();
     theMonth = now.getMonth() + 1;
     theYear  = now.getFullYear();
     monthsToGo = 0;
     yearsToGo = eval(document.forms["mortCalc"].months.value) / 12;
     yearsDone = theYear;
     monthsDone = theMonth;
     newTheYYMM = (theYear * 100) + theMonth;
     newCurYYMM = (curYear * 100) + curMonth;

     if ((curMonth != theMonth || curYear != theYear) && newCurYYMM < newTheYYMM) {
		yearsDone -= curYear;
		monthsDone -= curMonth;
		if (monthsDone < 0) {
		   yearsDone--;
		   monthsDone += 12;
		}

		yearsToGo -= yearsDone;
		if (monthsDone != 0) {
		   yearsToGo--;
		   monthsToGo += 12;
		   monthsToGo -= monthsDone;
		}
     }
     s_yearsToGo = "";                       // setup yearsToGo
     s_yearsToGo += Math.round(yearsToGo);

     s_monthsToGo = "";                       // setup monthsToGo
     s_monthsToGo += Math.round(monthsToGo);


     if (monthsToGo == 0) {
     	if (document.forms["mortCalc"].fixadjust[0].checked){
             loanline="Your original loan has " + s_yearsToGo + " years to go at a fixed rate of " + Int_Rate + "%."
     	}else{
             loanline="You have " + s_yearsToGo + " years to go on your original "+document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].text+" starting at " + Int_Rate + "%."
    	 }
     } else {
     	if (document.forms["mortCalc"].fixadjust[0].checked){
             loanline="Your original loan has " + s_yearsToGo + " years and " + s_monthsToGo + " months to go at a fixed rate of " + Int_Rate + "%."
     	}else{
             loanline="You have " + s_yearsToGo + " years and " + s_monthsToGo + " months to go on your original "+document.forms["mortCalc"]['ARM-Adjust'][document.forms["mortCalc"]['ARM-Adjust'].selectedIndex].text+" starting at " + Int_Rate + "%."
    	 }
     }
     monthly_intrate=Int_Rate/12/100; // monthly interest rate

     // build first line thru end of headings for output

     ls=  "Original Amortization Schedule: " + document.forms["mortCalc"].months.value
     + " months to repay " + document.forms["mortCalc"].Loan_Amount.value
     + " at " + document.forms["mortCalc"].Int_Rate.value+"%." + rr 
     + "Your new Prepayment Schedule is for " + (eval(document.mortCalc.Payoff_Years.value) * 12) + " months." + rr + d + rr
     + loanline + rr + ratioline + rr ;

     s_escrow = dlrFmt(Math.round(escrow* 1000) / 1000);

     s_monthlyIns = dlrFmt(Math.round(monthlyIns  * 1000) / 1000);

     s_monthlyTax = dlrFmt(Math.round(monthlyTax  * 1000) / 1000);

     s_P_I = dlrFmt(Math.round(P_I  * 1000) / 1000);

     tmpvalue = P_I + escrow;
     s_totalPayment = dlrFmt(Math.round(tmpvalue  * 1000) / 1000);

     checkpmireq();                 // check to see if PMI is required

     if (saveRatio > 80){
        aPmi = (origLoan_Amount * factor * .01) / 12;
        s_aPmi = dlrFmt(Math.round((aPmi + .005)  * 100) / 100);
	   	ls += "      PMI Payment:" + b.substring(0,11-s_aPmi.length) + s_aPmi + " may be required for several payment periods." + rr;
     }

     ls += d + rr + "          -- - - - Current Payment Schedule - - - - --  - - - - Accelerated Payment Schedule - - - -" + rr
     			  + "Payment    Payment   Interest   Principal    Balance    Payment    Interest   Principal    Balance"
      	          + rr
     	          + " Date       Amount    Amount    Reduction      Due       Amount     Amount    Reduction      Due"
     + rr + d + rr;

     yearlyInt = 0;
     yearlyPrn = 0;
     yearlyPmi = 0;

     for (var j=0;j<months;j++){

         tmpvar = Loan_Amount/prop_val; // percent of property value to loan balance

         // set PMI if required
         if (tmpvar > 0.78){
                  newpmi = (eval(origLoan_Amount)*eval(factor)*.01)/12;
         } else {
                  newpmi=0;
         }

         newpmi = Math.round((newpmi + .005) * 100) / 100;
	 	 if (newpmi < .02) {
	  	   newpmi = 0;
	 	 }
	 	 yearlyPmi += newpmi;

		 if (curMonth == theMonth && curYear == theYear && j == 0) {
		 	newLoanAmount = Loan_Amount;
		 	computeNewPayment();
		 }

         // calculate current month interest
         monthly_interest = (Loan_Amount*monthly_intrate) + .005;
         monthly_interest = Math.round(monthly_interest * 1000) / 1000;            // round monthly interest

         // calculate current month principal
         monthly_principal = P_I - monthly_interest;
         if (monthly_principal > Loan_Amount){
            monthly_principal=Loan_Amount;
         }
         monthly_principal = Math.round((monthly_principal * 1000) + 1) / 1000;   // round monthly principal
         if (P_I != (monthly_principal + monthly_interest)) {
            monthly_interest = P_I - monthly_principal;
         }

		 aval  = curYear;
		 aval  = aval * 100;
		 aval += curMonth;

		 if (monthly_principal < .019) { monthly_principal = 0.00; }
		 if (monthly_interest < .019) { monthly_interest = 0.00; }

         if (minDate > aval) { minDate = aval; }
         if (maxDate < aval) { maxDate = aval; }
         if (minAmt > monthly_principal) { minAmt = monthly_principal; }
         if (maxAmt < monthly_principal) { maxAmt = monthly_principal; }
         if (minAmt > monthly_interest) { minAmt = monthly_interest;  }
         if (maxAmt < monthly_interest) { maxAmt = monthly_interest;  }

		 x_Date[j]  = aval;
	 	 yearlyPrn += monthly_principal;
	 	 yearlyInt += monthly_interest;
		 a_curPrincipal[j] = monthly_principal;
		 a_curInterest[j]  = monthly_interest;
		 a_newPrincipal[j] = null;
		 a_newInterest[j]  = null;

         s_monthly_interest = dlrFmt(monthly_interest);

         s_monthly_principal = dlrFmt(monthly_principal);

         Loan_Amount -= monthly_principal;    // Reduce loan balance
         if (Loan_Amount < .019) { Loan_Amount = 0.00; }

		 a_curLoanAmount[j] = Loan_Amount;

         s_Loan_Amount = dlrFmt(Math.round(Loan_Amount  * 1000) / 1000);

         // Is it the last payment?
         if (P_I > (monthly_interest + monthly_principal)){
             P_I = monthly_interest + monthly_principal;
         }

         fmtP_I = P_I + escrow;
         s_P_I = dlrFmt(fmtP_I);

         str = "";
         str += curMonth;     // rolling date
         s_curMonth = str;
         str = "";
         str += curYear;      // rolling date
         s_curYear = str;

         extraZero = "";
		 if (s_curMonth.length < 2) {
			 extraZero = "0";
			 }
		 s_curMonthYear = extraZero + s_curMonth + "/" + s_curYear;

         s_newpmi = dlrFmt(newpmi);
		 if (s_newpmi == "$0.00") {
				 s_newpmi = " ";
		 }
		 if (document.forms["mortCalc"].detlsumm[1].checked){
         	// set up body of print line
         	ls += b.substring(0,1) + s_curMonthYear
         	+ b.substring(0,11-s_P_I.length) + s_P_I
         	+ b.substring(0,11-s_monthly_interest.length) + s_monthly_interest
         	+ b.substring(0,11-s_monthly_principal.length) + s_monthly_principal
         	+ b.substring(0,13-s_Loan_Amount.length) + s_Loan_Amount;

         	if (newLoanAmount == 0) {
         		ls += rr;
         	}
         }

		 if (newLoanAmount != 0 ) {
         	    calcNewFields();
         	    a_newPrincipal[j] = newMonthlyPrincipal;
				a_newInterest[j]  = newMonthlyInterest;
			    a_newLoanAmount[j] = newLoanAmount;

				if (newMonthlyPrincipal < .019) { newMonthlyPrincipal = 0.00; }
		 		if (newMonthlyInterest < .019) { newMonthlyInterest = 0.00; }

				if (minAmt > newMonthlyPrincipal) { minAmt = newMonthlyPrincipal; }
				if (maxAmt < newMonthlyPrincipal) { maxAmt = newMonthlyPrincipal; }
				if (minAmt > newMonthlyInterest)  { minAmt = newMonthlyInterest;  }
				if (maxAmt < newMonthlyInterest)  { maxAmt = newMonthlyInterest;  }
         }


		 if (curMonth == 12) {
			total_ln();
		 }

		 curMonth++;
		 if (curMonth > 12) {
			 curMonth = 1;
			 curYear++;
		 }

		 // Is it time to start calculating the new term of the loan per payoff year request

		 if (curMonth == theMonth && curYear == theYear) {
		 	newLoanAmount = Loan_Amount;
		 	computeNewPayment();
		 }

	}                                     // end of for loop for main body of report

	if (curMonth != 1) {
		total_ln();
	}

	if (document.forms["mortCalc"].detlsumm[0].checked){
		ls += rr;
	}

	// set body of print in to textarea and put disclaimer at end of report

	document.forms["mortCalc"].sched.value = ls + d + rr
	 +      "  * Minor rounding errors may occur. DHSCH is not liable for any errors or"
	 + rr + "    for any actions taken in reliance thereon."
	 + rr + d + rr;

    tmpvalue = newOrgP_I + escrow;
    s_newTotalPayment = dlrFmt(Math.round(tmpvalue  * 1000) / 1000);

    tmpvalue = orgP_I + escrow;
    s_TotalPayment = dlrFmt(Math.round(tmpvalue  * 1000) / 1000);

	s_curInterest = dlrFmt(curInterest);

	s_newInterest = dlrFmt(newInterest);

	s_newP_IDiff = dlrFmt((newOrgP_I - orgP_I));

	s_newInterestDiff = dlrFmt((curInterest - newInterest));

	s_newP_I = dlrFmt(newOrgP_I);

	s_P_I = dlrFmt(orgP_I);

	ls ="";
	ls += "Current Payment (including escrow)    : "
       + b.substring(0,11-s_TotalPayment.length) + s_TotalPayment 
       + b.substring(0, 3) + "Total Interest Paid over life of Loan : "
       + b.substring(0,11-s_curInterest.length) + s_curInterest + rr
       +  "Accelerated Payment (including escrow): "
       + b.substring(0,11-s_newTotalPayment.length) + s_newTotalPayment 
       + b.substring(0, 3) + "Total Accelerated Interest Paid       : "
       + b.substring(0,11-s_newInterest.length) + s_newInterest + rr
       +  "Additional Monthly Payment Required   : "
       + b.substring(0,11-s_newP_IDiff.length) + s_newP_IDiff
       + b.substring(0, 3) + "Interest Savings                      : "
       + b.substring(0,11-s_newInterestDiff.length) + s_newInterestDiff + rr +rr;

//	s_P_I = dlrFmt(orgP_I);

//	s_newP_I = dlrFmt(newOrgP_I);

       	s_line1 = "Current Payment Break Down:";
	s_line2 = "      P&I:" + b.substring(0,11-s_P_I.length) + s_P_I;
	s_line3 = "   Escrow:" + b.substring(0,11-s_escrow.length) + s_escrow + "  (Tx:" + s_monthlyTax + " Ins:" + s_monthlyIns + ")";
	s_line4 = "  Total  :" + b.substring(0,11-s_totalPayment.length) + s_totalPayment;

    	ls +=  s_line1 + b.substring(0, 54-s_line1.length)
           + "Accelerated Payment Break Down:" + rr
           + s_line2 + b.substring(0, 54-s_line2.length)
	   + "      P&I:" + b.substring(0,11-s_newP_I.length) + s_newP_I + rr
	   + s_line3 + b.substring(0, 54-s_line3.length)
	   + "   Escrow:" + b.substring(0,11-s_escrow.length) + s_escrow + "  (Tx:" + s_monthlyTax + " Ins:" + s_monthlyIns + ")" + rr
	   + s_line4 + b.substring(0, 54-s_line4.length)
	   + "  Total  :" + b.substring(0,11-s_newTotalPayment.length) + s_newTotalPayment;

    document.forms["mortCalc"].calcReview.value = ls ;

}

// build new print fields for new payoff term
function calcNewFields() {
	if (newLoanAmount >= .019 || newMonthlyPrincipal >= .019) {
         // calculate current month interest
         newMonthlyInterest = (newLoanAmount*monthly_intrate) + .005;
         newMonthlyInterest = Math.round(newMonthlyInterest * 1000) / 1000;            // round monthly interest

         // calculate current month principal
         newMonthlyPrincipal = newP_I - newMonthlyInterest;
         if (newMonthlyPrincipal > newLoanAmount){
            newMonthlyPrincipal = newLoanAmount;
         }

         newMonthlyPrincipal = Math.round((newMonthlyPrincipal * 1000) + 1) / 1000;   // round monthly principal
         if (newP_I != (newMonthlyPrincipal + newMonthlyInterest) && newLoanAmount > .019) {
            newMonthlyInterest = newP_I - newMonthlyPrincipal;
         }
	 	 newYearlyPrn += newMonthlyPrincipal;
	 	 newYearlyInt += newMonthlyInterest;

         //    alert (P_I + " " + monthly_interest + " " + monthly_principal );
         s_newMonthlyInterest = dlrFmt(newMonthlyInterest);

         s_newMonthlyPrincipal = dlrFmt(newMonthlyPrincipal);

         newLoanAmount -= newMonthlyPrincipal;    // Reduce loan balance
		 if (newLoanAmount <= .019) { newLoanAmount = 0.00; }

         s_newLoanAmount = dlrFmt(Math.round(newLoanAmount  * 1000) / 1000);

         // Is it the last payment?
         if (newP_I > (newMonthlyInterest + newMonthlyPrincipal)){
             newP_I = newMonthlyInterest + newMonthlyPrincipal;
         }

         s_newP_I = dlrFmt((newP_I + escrow));

	 	 if (document.forms["mortCalc"].detlsumm[1].checked ){
         	// set up body of print line
         	ls += b.substring(0,11-s_newP_I.length) + s_newP_I
         	+ b.substring(0,11-s_newMonthlyInterest.length) + s_newMonthlyInterest
         	+ b.substring(0,11-s_newMonthlyPrincipal.length) + s_newMonthlyPrincipal
         	+ b.substring(0,13-s_newLoanAmount.length) + s_newLoanAmount + rr;
		 }

	} else {
			if (document.forms["mortCalc"].detlsumm[1].checked) {
				ls += rr;
			}
		newMonthlyPrincipal = 0.0;
		newMonthlyInterest = 0.0;

	}
}

function total_ln(){

    s_yearlyPrn = dlrFmt(Math.round(yearlyPrn  * 1000) / 1000);

    s_yearlyInt = dlrFmt(Math.round(yearlyInt  * 1000) / 1000);

    ls += b.substring(0,1) + "   Total " + s_curYear + ":"
       	+ b.substring(0,4)
       	+ b.substring(0,11-s_yearlyInt.length) + s_yearlyInt
       	+ b.substring(0,11-s_yearlyPrn.length) + s_yearlyPrn;

    if (document.forms["mortCalc"].detlsumm[0].checked){
		ls += b.substring(0,13-s_Loan_Amount.length) + s_Loan_Amount;
    }

	if (newYearlyPrn >= .019) {
		s_newYearlyPrn = dlrFmt(Math.round(newYearlyPrn  * 1000) / 1000);
		s_newYearlyInt = dlrFmt(Math.round(newYearlyInt  * 1000) / 1000);

	    if (document.forms["mortCalc"].detlsumm[1].checked){
			ls += b.substring(0, 24)
				+ b.substring(0,11-s_newYearlyInt.length) + s_newYearlyInt
				+ b.substring(0,11-s_newYearlyPrn.length) + s_newYearlyPrn;
		} else {
			ls += b.substring(0, 11)
				+ b.substring(0,11-s_newYearlyInt.length) + s_newYearlyInt
				+ b.substring(0,11-s_newYearlyPrn.length) + s_newYearlyPrn;
		}
		if (document.forms["mortCalc"].detlsumm[0].checked){
			ls += b.substring(0,13-s_newLoanAmount.length) + s_newLoanAmount;
		}

	}

    ls += rr;

    if (document.forms["mortCalc"].detlsumm[1].checked){
    	ls += rr;
    }

	curPrincipal += yearlyPrn;
	curInterest  += yearlyInt;
	if (newLoanAmount != 0 || newYearlyPrn > 0) {
		newPrincipal += newYearlyPrn;
		newInterest  += newYearlyInt;
		ppSchdStarted = 1;
	} else {
		if (ppSchdStarted == 0) {
			newPrincipal += yearlyPrn;
			newInterest  += yearlyInt;
	    }
	}

    yearlyPrn = 0;
    yearlyInt = 0;

    newYearlyPrn = 0;
    newYearlyInt = 0;
}
// format numeric fields changed to strings to have two decimals
function fmtIt(){
     pos = str.indexOf(".");

     if (pos == 0){
        str = "0" + str;
        pos++;
     }
     if (pos < 0){
        str += ".00";
        pos = str.indexOf(".");
     }
     str += "00";
     str = str.substring(0, pos+3);
}

function s_fmtIt(){
     pos = str.indexOf(".");

     if (pos == 0){
        str = "0" + str;
        pos++;
     }
     if (pos < 0){
        str += ".00";
        pos = str.indexOf(".");
     }
     str += "00";
     str = str.substring(0, pos+3);
     pos = str.indexOf(".");
     if (pos > 3) {
        str = str.substring(0, pos-3) + "," + str.substring(pos-3, pos+3);
     }
}
function dlrFmt(dlrInput) {
     str = "";                       // setup Total Interest
     str += dlrInput;
     s_fmtIt();

     return (s + str);
}

function alrt(){
     alert("The number of months must be between"
     + " 1 and 999. The loan amount must be between 1 and " + pwr[9]
     + " and the interest rate must be between .001 and 99%.");
}
function format(anum) {
  var negative = false;

  if (anum < 0) {
    anum = anum*-1;
    negative = true;
  }

  var thestring = new String(anum);
  var decindex = thestring.indexOf('.');
  var intstring = "";
  var decstring = "";
  var buildstring = "";
  var numstring = "";

  if (decindex > -1) {
        intstring = thestring.substring(0,decindex);
        decstring = thestring.substring(decindex,thestring.length);
  }else{
        intstring = thestring;
  }

  var numlen = intstring.length;

  var curidx = numlen;

        if (numlen > 3) {
           while (curidx > -1) {
                        buildstring = intstring.charAt(curidx) + buildstring;
                        numstring = intstring.charAt(curidx) + numstring;
                        curidx--;
                        if (numstring.length == 3) {

                                if (curidx != -1) {

                                buildstring = "," + buildstring;

                                numstring = "";
                            }
                        }
           }
           //prepend first digit
          // buildstring = intstring.charAt(0) + buildstring;
        }else{
          buildstring = intstring;
        }
  buildstring = "$" + buildstring + decstring;

  if (negative) {
     buildstring = "-" + buildstring;
  }

  return(buildstring);
}

function strip(astring) {

 var newstring = "";
 var achar = "XXX";

 for (i=0;i<astring.length;i++) {
    achar = astring.charAt(i,1);

    if (achar != "$" && achar != "," && achar != "%") {
        newstring += achar
    }
 }

 if (newstring == "") { newstring = "0"; }

 return (newstring);
}

function chartCalculate() {

  if (minDate == 0 && maxDate == 0) {
   		calcResults() }

  // browser detection code
  var bwr = navigator.appName
  var uagt = navigator.userAgent.toLowerCase()
  if (bwr=="Netscape") abwr = "ns"
	else if (bwr=="Microsoft Internet Explorer") abwr = "ie"
	else abwr = bwr;

  atch = "";
  if (abwr == "ie") {
    atch = "_parent"}

  gtype ="lne";						// set type of graph pix = pixel and lne = line

  var xc_prin = 0;					// cordinates of from point for lines
  var xc_int  = 0;
  var yc_prin = 0;
  var yc_int  = 0;
  var xcs_prin = 0;
  var ycs_prin = 0;
  var xcs_str  = "";
  var xn_prin = 0;
  var xn_int  = 0;
  var yn_prin = 0;
  var yn_int  = 0;
  var xns_prin = 0;
  var yns_prin = 0;
  var xns_str  = "";
  var xcsPass = 0;
  var xnsPass = 0;

  _DiagramTarget=window.open("",atch,
  			"width=700, height=500, menubar=no,toolbar=no, locationbar=yes,resizable=yes,status=yes,scrollbars=no");
  with (_DiagramTarget.document)
  { open();
   	write('<html><head><title>Dave Hughes Signature Custom Homes - Prepayment Amortization Calculator</title><BR>');
  	write('</head><body background=\"img/DHSCH_background.gif\">');
  	if (abwr == "ie") {
  		write('<A Href=\"javascript:history.go(-1)\">Return To Calculator</a>');
  	}
  	write('<TABLE border=\"0\">');
  	write('<TR><TD><img src=\"img/DHSCHLogoSmall.gif\"><BR><Div valign=\"left\" align=\"Center\"></td></tr><td><B>Visit out website at: <A Href=\"http://www.DKHughesHomes.com\" style=\"color:blue\">http://www.DKHughesHomes.com</A></B></DIV></TD>');
  	write('<TD>&nbsp;</TD></TR>');
  	write('<TR><TD colspan=\"2\">');

	var minyy = Math.round(minDate / 100);
	var minmm = Math.round(minDate - (minyy * 100)) - 1;
	var maxyy = Math.round(maxDate / 100);
	var maxmm = Math.round(maxDate - (maxyy * 100)) - 1;

	var smlAmt = Math.round(minAmt);
	var lrgAmt = Math.round(maxAmt);

    var dleft   = 80;
    var dtop    = 160;
    var dright  = 540;
    var dbottom = 460;

//	alert("minyy " + minyy + " minmm " + minmm + " maxyy " + maxyy + " maxmm " + maxmm);
//	alert(" minAmt " + smlAmt + " maxAmt " + lrgAmt);

	var Dcht = new Diagram();
	Dcht.SetFrame(dleft, dtop, dright, dbottom);

	Dcht.SetBorder(Date.UTC(minyy, minmm, 1, 0,0,0),
				   Date.UTC(maxyy, maxmm, 1, 0,0,0),
				   smlAmt, lrgAmt);

	Dcht.SetText("", " $", "<B>Mortgage Prepayment Calculation<BR /></B>");

	Dcht.XScale="2";
	Dcht.YScale="$"
	Dcht.YSubGrids=2;
	Dcht.SetGridColor("#dddddd", "#eeeeee");
	Dcht.Draw("#CCEEFF", "#000000", false);

	var i, j, k, av, xfwd, intPrn, intInt, m, x;
	x = Math.round(months);

	xFactor = minmm - 1;

	for (i = 0; i < x; i++)
	{
	  av = (dright-dleft) / x;              // refer to the SetFrame state above parameter 1 and 3
	  av2 = ((i+1)*av) + dleft;          // x distance plus the offeset of  parameter 1 of SetFrame
	  xfwd = Math.round(av2);

	  var xyy = Math.round(x_Date[i] / 100);
	  var xmm = Math.round(x_Date[i] - (xyy * 100)) - 1;
	  var xendmm = 11;

	  intPrn = Math.round(a_curPrincipal[i]);
	  intInt = Math.round(a_curInterest[i]);

	  j= Dcht.ScreenY(intPrn);
	  if (gtype == "pix") {
		  new Pixel(xfwd, j, "#FF0000");
	  	  xc_prin = xfwd;
	  	  yc_prin = j;
	  } else {
	  	if (i > 0 && xmm == xendmm) {
			str = graphNote("Year End: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
	  		new Line(xc_prin, yc_prin, xfwd, j, "#ff0000", 1, str);
	  		xc_prin = xfwd;
	  		yc_prin = j;
		}
		if (i == 0) {
	  		xc_prin = xfwd;
	  		yc_prin = j;
	  	}
	  }
	  if (xmm == xendmm) {
			str = graphNote("Year End: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
	  		new Dot(xfwd, j, 6, 6, "#FF0000", str);
	  }
	  if (a_curLoanAmount[i] < .019) {
			str = graphNote("The End: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
	  		new Dot(xfwd, j, 14, 'img/smile.gif', "", str);
	  }

	  j= Dcht.ScreenY(intInt);

	  if (gtype == "pix") {
		  new Pixel(xfwd, j, "#0000ff");
	  	  xc_int = xfwd;
	  	  yc_int = j;
	  } else {
	  	if (i > 0 && xmm == xendmm) {
			str = graphNote("Year End: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
	  		new Line(xc_int, yc_int, xfwd, j, "#0000ff", 1, str);
	  		xc_int = xfwd;
	  		yc_int = j;
	  		if (xcs_prin != 0 && xcsPass == 2) {
	  			new Dot(xcs_prin, ycs_prin, 14, 'img/smile.gif', "", xcs_str);
	  			xcs_prin = 0;
	  		}
	  		if (xcs_prin != 0) { xcsPass++; }
		}
		if (i == 0) {
	  		xc_int = xfwd;
	  		yc_int = j;
	  	}
	  }

	  if (xmm == xendmm) {
			str = graphNote("Year End: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
  			new Dot(xfwd, j, 6, 6, "#0000ff", str);
	  }

	  if (i > 0 && a_curPrincipal[i-1] < a_curInterest[i-1] && a_curPrincipal[i] > a_curInterest[i]) {
         //    alert (P_I + " " + monthly_interest + " " + monthly_principal );

			str = graphNote("P&I Cross: ",x_Date[i], a_curPrincipal[i], a_curInterest[i], a_curLoanAmount[i]);
	  		new Dot(xfwd, j, 14, 'img/smile.gif', "", str);
	  		xcs_prin = xfwd;
	  		ycs_prin = j;
	  		xcs_str = str;
	  }
	  intPrn = Math.round(a_newPrincipal[i]);
	  intInt = Math.round(a_newInterest[i]);
	  if (intPrn > 0) {
			j= Dcht.ScreenY(intPrn);

			if (gtype == "pix") {
				new Pixel(xfwd, j, "#00ff00");
				xn_prin = xfwd;
				yn_prin = j;
			} else {
				if (i > 0 && (xmm == xendmm || a_newLoanAmount[i] < .019)) {
					  if (xn_prin != 0) {
					  	str = graphNote("Year End: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
					  	new Line(xn_prin, yn_prin, xfwd, j, "#00ff00", 1, str);
					  }
					  xn_prin = xfwd;
					  yn_prin = j;
				}
				if (xn_prin == 0) {
					xn_prin = xfwd;
					yn_prin = j;
				}
			}
			if (xmm == xendmm) {
					str = graphNote("Year End: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
					new Dot(xfwd, j, 6, 6, "#00ff00", str);
			}
			if (a_newLoanAmount[i] < .019) {
				str = graphNote("The End: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
				new Dot(xfwd, j, 14, 'img/smile.gif', "", str)
			}

			j= Dcht.ScreenY(intInt);

			if (gtype == "pix") {
				new Pixel(xfwd, j, "#000000");
				xn_int = xfwd;
				yn_int = j;
			} else {
				if (i > 0 && (xmm == xendmm || a_newLoanAmount[i] < .019)) {
					  if (xn_int != 0) {
					  	str = graphNote("Year End: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
					  	new Line(xn_int, yn_int, xfwd, j, "#000000", 1, str);
					  }
					  xn_int = xfwd;
					  yn_int = j;
					  if (xns_prin != 0 && xnsPass == 2) {
						  new Dot(xns_prin, yns_prin, 14, 'img/smile.gif', "", xns_str);
						  xns_prin = 0;
					  }
					  if (xns_prin != 0) { xnsPass++; }
				}
				if (xn_int == 0) {
					xn_int = xfwd;
					yn_int = j;
				}
			}
			if (xmm == xendmm) {
					str = graphNote("Year End: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
					new Dot(xfwd, j, 6, 6, "#000000", str);
			}
			if (i > 0 && a_newPrincipal[i-1] < a_newInterest[i-1] && a_newPrincipal[i] > a_newInterest[i]) {
				str = graphNote("P&I Cross: ",x_Date[i], a_newPrincipal[i], a_newInterest[i], a_newLoanAmount[i]);
				new Dot(xfwd, j, 14, 'img/smile.gif', "", str)
	  			xns_prin = xfwd;
	  			yns_prin = j;
	  			xns_str  = str;
			}
	  }
	}
	new Bar(560, 175, 690, 195, "#ffffff", "Monthly", "#000000");
	new Bar(560, 200, 690, 220, "#0000ff", "Old Interest", "#FFFFFF");
	new Bar(560, 225, 690, 245, "#FF0000", "Old Principal", "#ffffff");
	new Bar(560, 280, 690, 300, "#000000", "New Interest", "#FFFFFF");
	new Bar(560, 305, 690, 325, "#00ff00", "New Principal", "#000000");

   	write('</TD></TR></TABLE>');
   	write('</body></html>');

   	close();

  }

}

function graphNote(xText, xDate, prinPay, intPay, loanAmt){

			x_dateStr1 = "";                            // format year
			x_dateStr1 += Math.round(xDate / 100);

			x_dateStr = x_dateStr1;
			if (xText != "Year End: ") {
			   x_dateStrMonth = "";
			   x_dateStrMonth = xDate - (Math.round(xDate / 100) * 100);
			   x_dateStr = "";
			   x_dateStr = x_dateStrMonth + "/" + x_dateStr1;
			}

			c_Principal = dlrFmt(prinPay);

			c_Interest = dlrFmt(intPay);

			c_LoanAmount = dlrFmt(Math.round(loanAmt  * 1000) / 1000);

			var bwrg = navigator.appName
			if (bwrg=="Netscape") this.bwrg = "ns"
				else if (bwrg=="Microsoft Internet Explorer") this.bwrg = "ie"
				else this.bwrg = bwrg;

			if (this.bwrg == "ie") {
			str =  xText + x_dateStr + "\n" +
				   "Loan    : " + c_LoanAmount + "\n" +
			       "P Pay   : " + c_Principal + "\n" +
			       "I Pay   : " + c_Interest;
			} else {
				str = xText + x_dateStr + ", " +
					  "Loan: " + c_LoanAmount + ", " +
				      "P Pay: " + c_Principal + ", " +
				      "I Pay: " + c_Interest;
			}
			return (str);
}
function printPage(){

  if (minDate == 0 && maxDate == 0) {
   		calcResults() }

   var fulltable1 = document.forms["mortCalc"].calcReview.value;
   var fulltable2 = document.forms["mortCalc"].sched.value;
   document.open();
   document.writeln('<html><head><title>Dave Hughes Signature Custom Homes - Prepayment Amortization Calculator</title></head><body><A Href=\"javascript:history.go(-1)\">Return To Calculator</a><BR>');
   document.writeln('<TABLE border=\"0\" background="img/DHSCH_background.gif">');
   document.writeln('<TR><TD><img src=\"img/DHSCHomesFullLogoAndName.gif\"><BR><Div align=\"Center\"></td></tr><td><B>Visit out website at: <A Href=\"http://www.DKHughesHomes.com\" style=\"color:blue\">http://www.DKHughesHomes.com</A></B></DIV></TD>');
   document.writeln('<TD>&nbsp;</TD></TR>');
   document.writeln('<TR><TD colspan=\"2\">');
   document.writeln('<pre>'+ fulltable1 +'</pre><br />');
   document.writeln('<pre>'+ fulltable2 +'</pre>');
   document.writeln('</TD></TR></TABLE>');
   document.writeln('<BR><A Href=\"javascript:history.go(-1)\">Return To Calculator</a></body></html>');
   print(document);
   document.close();
}
function printSumPage(){

  if (minDate == 0 && maxDate == 0) {
   		calcResults() }

   var fulltable2 = document.forms["mortCalc"].calcReview.value;
   document.open();
   document.writeln('<html><head><title>Dave Hughes Signature Custom Homes - Prepayment Amortization Calculator</title></head><body><A Href=\"javascript:history.go(-1)\">Return To Calculator</a><BR>');
   document.writeln('<TABLE border=\"0\" background="img/DHSCH_background.gif">');
   document.writeln('<TR><TD><img src=\"img/DHSCHLogoSmall.gif\"><BR><Div align=\"Center\"></td></tr><td><B>Visit out website at: <A Href=\"http://www.DKHughesHomes.com\" style=\"color:blue\">http://www.DKHughesHomes.com</A></B></DIV></TD>');
   document.writeln('<TD>&nbsp;</TD></TR>');
   document.writeln('<TR><TD colspan=\"2\">');
   document.writeln('<pre>'+ fulltable2 +'</pre>');
   document.writeln('</TD></TR></TABLE>');
   document.writeln('<BR><A Href=\"javascript:history.go(-1)\">Return To Calculator</a></body></html>');
   print(document);
   document.close();
}

function buildform(){

   now = new Date();
   curMonth = now.getMonth() + 1;
   curYear  = now.getFullYear();

//   document.forms["mortCalc"].Lsd_mm.value = curMonth;
//   document.forms["mortCalc"].Lsd_yy.value = curYear;
   s_line_month = curMonth + " size=\"2\">";
   s_line_year  = curYear  + " SIZE=\"4\"></td></tr>";
   document.write('<DIV align="center">');
   document.write('<FORM name="mortCalc">');
   document.write('<table border=1 bordercolor=black CELLPADDING="2" CELLSPACING="1" width="100%"><tr><td><TABLE border="0" width="100%" CELLPADDING="0" CELLSPACING="1"bordercolor=#cceeff bgcolor="#cceeff" align="center" style="font-size:10pt">');
   document.write('<TR><TD align="center"><img src="img/DHSCHLogoSmall.gif"></TD>');
   document.write('<td colspan="3"> Use this prepayment mortgage calculator to make an amortization schedule for a loan of any term, rate, and size. Do not use commas in the fields below.</td></TR><TR><TD colspan="4" height="3"><HR color="black" width="100%"></TD></TR>');
   document.writeln('<td colspan="1"><font style="font-size:9pt; font-weight : Bold; ">Estimated Property Value:');
   document.write('</font></td><td>&nbsp&nbsp&nbsp;<input type="text" name="prop_val" size="24" value="$250,000" onChange="document.mortCalc.prop_val.value = format(strip(document.mortCalc.prop_val.value))"></td></TR>');
   document.writeln('<TR><TD colspan="1"><font style="font-size:9pt; font-weight : Bold; ">Loan Type:</font>');
   document.writeln('&nbsp&nbsp<font style="font-size:9pt;"><input type="radio" name="fixadjust" value="FRM" onclick="document.forms[\'mortCalc\'][\'ARM-Adjust\'].disabled=true;" checked>Fixed&nbsp;Rate');
   document.write('<input type="radio" name="fixadjust" value="ARM" onclick="document.forms[\'mortCalc\'][\'ARM-Adjust\'].disabled=false;">Adjustable</font>');
   document.write('</td><td>&nbsp&nbsp&nbsp;<Select Name="ARM-Adjust" style="font-size:8pt" disabled><option value="0">If ARM Please Select</option><Option value="1">1/1 ARM</Option><Option value="3">3/1 ARM</Option><Option value="5">5/1 ARM</Option><Option value="7">7/1 ARM</Option><Option value="10">10/1 ARM</Option></SELECT></TD>')
   document.write('<TR valign="top">');
   document.write('<TR><TD>&nbsp;</TD><TD colspan="2">&nbsp;Month(mm) Year(yyyy)</TD></TR>');
   document.write('<TR><TD><font style="font-size:9pt; font-weight : Bold; ">Original Loan Start Date</font></TD>');
   document.writeln('<td colspan="2">&nbsp&nbsp&nbsp;<INPUT TYPE="text" style="text-align:right;" NAME="Lsd_mm" VALUE=')
   document.write(s_line_month);
   document.writeln('&nbsp&nbsp;/&nbsp&nbsp;<INPUT TYPE="text" style="text-align:right;" NAME="Lsd_yy" VALUE=');
   document.write(s_line_year);
   document.write('<TR valign="top">');
   document.write('<Td><font style="font-size:9pt; font-weight : Bold;">Interest Rate</font></td>');
   document.write('<td>&nbsp&nbsp&nbsp;<INPUT TYPE="text" style="text-align:right;" NAME="Int_Rate" VALUE="5.375" SIZE="6">%</td>');
   document.write('<td align="right"><font style="font-size:9pt; font-weight : Bold; ">Original Number of Payments&nbsp</font></td>');
   document.write('<td><INPUT TYPE="text" style="text-align:right;" NAME="months" VALUE="360" SIZE="3">&nbsp;Months</TD></tr>');
   document.write('<TR valign="top">');
   document.write('<Td><font style="font-size:9pt; font-weight : Bold;">Original Loan Amount</font></td>');
   document.write('<td colspan="1">&nbsp&nbsp&nbsp;<INPUT TYPE="text" NAME="Loan_Amount" VALUE="$200,000" SIZE="15" onChange="document.mortCalc.Loan_Amount.value = format(strip(document.mortCalc.Loan_Amount.value))"></TD>');
   document.write('<td align="right"><font style="font-size:9pt; font-weight : Bold; ">Payoff Mortgage in&nbsp</font></td>');
   document.write('<td><INPUT TYPE="text" style="text-align:right;" NAME="Payoff_Years" VALUE="15" SIZE="3">&nbsp;Years</TD></tr>');
   document.write('<TR valign="top">');
   document.write('<Td><font style="font-size:9pt; font-weight : Bold;">Estimated Yearly Property Tax</font></td>');
   document.write('<td colspan="1">&nbsp&nbsp&nbsp;<INPUT TYPE="text" NAME="Yearly_Tax" VALUE="$7,500" SIZE="10" onChange="document.mortCalc.Yearly_Tax.value = format(strip(document.mortCalc.Yearly_Tax.value))"></TD></TR>');
   document.write('<TR valign="top">');
   document.write('<Td><font style="font-size:9pt; font-weight : Bold;">Estimated Yearly Insurance Premium</font></td>');
   document.write('<td colspan="1">&nbsp&nbsp&nbsp;<INPUT TYPE="text" NAME="Yearly_Ins" VALUE="$1,500" SIZE="10" onChange="document.mortCalc.Yearly_Ins.value = format(strip(document.mortCalc.Yearly_Ins.value))"></TD>');
   document.write('<TR>');
   document.write('<TD colspan="4" align="center" valign="middle">');
   document.writeln('<font style="font-size:9pt;"><input type="radio" name="detlsumm" value="SUM" checked>Summary Report');
   document.write('<input type="radio" name="detlsumm" value="DTL">Detail Report</font>');
   document.write('<br /><INPUT TYPE="button" VALUE="Click To Calculate Mortgage" onClick="calcResults()">');
   document.write('<BR>');
   document.write('<DIV STYLE="text-align:center;">');
   document.write('<A Href="#" onclick="printPage();return false;">Printable Version</A>&nbsp - &nbsp<A Href="" onclick="chartCalculate();return false;">Chart Version</A><br />(You must have a schedule in the boxes below. Besure to select Landscape for best results.)');
   document.write('</DIV></TD></tr>');
   document.write('<TR>');
   document.write('<TD colspan="4" align="center" valign="middle"><font style="font-size:9pt; font-weight : Bold;">Mortgage Payoff Goal and Payment Break Down:</font></td></tr>');
   document.write('<TR>');
   document.write('<TD colspan="4" align="center" valign="middle">');
   document.write('<TEXTAREA NAME="calcReview" ROWS="8" COLS="108" style="font-size:8pt; font-family: monospace; background-color:#add8e6;"></TEXTAREA>');
   document.write('<A Href="#" onclick="printSumPage();return false;"><div align="center"><font style="font-size:10pt;">Print Summary Above</FONT></div></A>');
   document.write('</td></tr>');
   document.write('<TR><TD colspan="4" align="center" valign="middle">');
   document.write('<TEXTAREA NAME="sched" ROWS="14" COLS="108" style="font-size:8pt; font-family: monospace;"></TEXTAREA>');
   document.write('</TD></TR>');
   document.write('<TR><TD width="31%" height="1px">&nbsp;</TD><TD width="18%" height="1px">&nbsp;</TD><TD width="26%" height="1px">&nbsp;</TD><TD width="25%" height="1px">&nbsp;</TD></TR>');
   document.write('<TR>');
   document.write('<TD colspan="4" align="center" valign="middle" style="color:#000080">');
   document.writeln('Copyright &copy; 2004, DHSCH<small><small>&copy;</small></small>. All rights reserved.');
   document.write('</TD></TR>');
   document.write('</TABLE></td></tr></table>');
   document.write('');
   document.write('</FORM>');
   document.write('</DIV>');
   document.mortCalc.prop_val.select();
   document.mortCalc.prop_val.focus();
}
// <! -->