<!--


var valueInterestPaidNorm;
var valueInterestPaidAccl;
var valueTotalPaidNorm;
var valueTotalPaidAccl;
var valueNumPaymentsNorm;
var valueNumPaymentsAccl;

function CompareLoanAccel()
{

var prin = parseFloat(document.compareform.prin.value);
var months = parseFloat(document.compareform.months.value);
var normalPay = parseFloat(document.compareform.normalPay.value);
var accelPay = parseFloat(document.compareform.accelPay.value);

var normalInterestRate = 1;
var accelInterestRate = 1;

var theButton = document.getElementById('ShowButtonTop');


    if (accelPay <= normalPay)
    {
        document.compareform.accelPay.style.background = '#F99';

        document.compareform.normalInterestRate.value = '';
        document.compareform.accelInterestRate.value = '';

        document.compareform.normalInterestPaid.value = '';
        document.compareform.accelInterestPaid.value = '';
        document.compareform.normalTotalPaid.value = '';
        document.compareform.accelTotalPaid.value = '';
        document.compareform.normalNumPayments.value = '';
        document.compareform.accelNumPayments.value = '';

        theButton.style.display = 'none';
    }
    else
    {
        document.compareform.accelPay.style.background = '#FFF';

        normalInterestRate = parseFloat(FindInterestRate(prin, months, normalPay));
        accelInterestRate  = parseFloat(ConvertMonthlyRateToAnnual(normalInterestRate));
        document.compareform.normalInterestRate.value = formatCurrency(normalInterestRate);
        document.compareform.accelInterestRate.value = formatCurrency(accelInterestRate);

        CalculateLoanAccelAmortization();

        document.compareform.normalInterestPaid.value = formatCurrency(valueInterestPaidNorm);
        document.compareform.accelInterestPaid.value = formatCurrency(valueInterestPaidAccl);
        document.compareform.normalTotalPaid.value = formatCurrency(valueTotalPaidNorm);
        document.compareform.accelTotalPaid.value = formatCurrency(valueTotalPaidAccl);
        document.compareform.normalNumPayments.value = valueNumPaymentsNorm;
        document.compareform.accelNumPayments.value = valueNumPaymentsAccl;

        theButton.style.display = 'block';
    }
}

function CalculateLoanAccelAmortization()
{

var prin = parseFloat(document.compareform.prin.value);
var rate = parseFloat(document.compareform.normalInterestRate.value);
var months = parseFloat(document.compareform.months.value);
var amountNorm = parseFloat(document.compareform.normalPay.value);
var amountAccl = parseFloat(document.compareform.accelPay.value);
var startMonth = parseFloat(document.compareform.startmonth.value);

var termRate = 1;
var index = 1;

var termPrinNorm;
var termPrinAccl;
var termPrinTotalNorm = prin;
var termPrinTotalAccl = prin;
var termIntNorm;
var termIntAccl;
var termIntTotalNorm = 0;
var termIntTotalAccl = 0;

var termPrinTotal;

var newTBody;
var newTR;
var newTD;
var txt = 'Text';
var newTxt;
var theSchedule = document.getElementById('StartSchedule');
var theTable = document.getElementById('StartScheduleTable');

    var oldTBody = document.getElementById("AmortBodyContent");
    if (oldTBody)
    {
        theTable.removeChild(oldTBody);
    }

    termRate = parseFloat(rate / 1200);

    newTBody = document.createElement("tbody");
    newTBody.id = 'AmortBodyContent';

    for (index = 1; index <= months; index++)
    {
        // normal schedule
        // don't pay more than the loan requires
        if (termPrinTotalNorm <= amountNorm)
        {
            if (termPrinTotalNorm > 0)
            {
                termIntNorm = FindMonthlyInterest(termPrinTotalNorm, rate, index, termPrinTotalNorm);
                valueNumPaymentsNorm = index;     // save off in global variable how many payments it took for this loan
            }
            else
            {
                termIntNorm = 0;
            }
            termPrinNorm = termPrinTotalNorm;
            termPrinTotalNorm = 0;
        }
        // calculate only if there is some loan principal left
        if (termPrinTotalNorm > 0)
        {
            termIntNorm = FindMonthlyInterest(termPrinTotalNorm, rate, index, amountNorm);
            termIntTotalNorm = parseFloat(termIntTotalNorm + termIntNorm);
            
            termPrinNorm = parseFloat(amountNorm - termIntNorm);
            termPrinTotalNorm = parseFloat(termPrinTotalNorm - termPrinNorm);
        }

        if (index >= startMonth)
        {
            // accelerated schedule
            // don't pay more than the loan requires
            if (termPrinTotalAccl <= amountAccl)
            {
                if (termPrinTotalAccl > 0)
                {
                    termIntAccl = FindMonthlyInterest(termPrinTotalAccl, rate, index, termPrinTotalAccl);
                    valueNumPaymentsAccl = index;     // save off in global variable how many payments it took for this loan
                }
                else
                {
                    termIntAccl = 0;
                }
                termPrinAccl = termPrinTotalAccl;
                termPrinTotalAccl = 0;
            }
            // calculate only if there is some loan principal left
            if (termPrinTotalAccl > 0)
            {
                termIntAccl = FindMonthlyInterest(termPrinTotalAccl, rate, index, amountAccl);
                termIntTotalAccl = parseFloat(termIntTotalAccl + termIntAccl);

                termPrinAccl = parseFloat(amountAccl - termIntAccl);
                termPrinTotalAccl = parseFloat(termPrinTotalAccl - termPrinAccl);
            }
        }
        else
        {
            termIntAccl = termIntNorm;
            termIntTotalAccl = termIntTotalNorm;

            termPrinAccl = termPrinNorm;
            termPrinTotalAccl = termPrinTotalNorm;
        }

        newTR = document.createElement("tr");

        // first cell
        newTD = AddTableData(index, newTR, 'border-right: 1px solid black; text-align: right; padding-right: 0.5em;');

        AddTableData(formatCurrency(termPrinNorm), newTR, 'text-align: right; padding-right: 0.5em;');
        AddTableData(formatCurrency(termIntNorm), newTR, 'text-align: right; padding-right: 0.5em;');
        AddTableData(formatCurrency(termPrinTotalNorm), newTR, 'text-align: right; padding-right: 0.5em;');
        AddTableData(formatCurrency(termPrinAccl), newTR, 'border-left: 1px solid green; text-align: right; padding-right: 0.5em;');
        AddTableData(formatCurrency(termIntAccl), newTR, 'text-align: right; padding-right: 0.5em;');
        AddTableData(formatCurrency(termPrinTotalAccl), newTR, 'text-align: right; padding-right: 0.5em;');

        // after final cell
        if ((index % 2) == 0)
        {
            newTR.style.background = '#DDD';
        }
        newTBody.appendChild(newTR);
    }


    newTR = document.createElement("tr");

    // first cell
    AddTableData('Total', newTR, 'border-right: 1px solid black; text-align: right; padding-right: 0.5em;');

    AddTableData(formatCurrency(prin), newTR, 'text-align: right; padding-right: 0.5em;');
    AddTableData(formatCurrency(termIntTotalNorm), newTR, 'text-align: right; padding-right: 0.5em;');
    AddTableData(formatCurrency(0), newTR, 'text-align: right; padding-right: 0.5em;');
    AddTableData(formatCurrency(prin), newTR, 'background: #BFB; border-left: 1px solid green; text-align: right; padding-right: 0.5em;');
    AddTableData(formatCurrency(termIntTotalAccl), newTR, 'background: #BFB; text-align: right; padding-right: 0.5em;');
    AddTableData(formatCurrency(0), newTR, 'background: #BFB; text-align: right; padding-right: 0.5em;');

    // after final cell
    newTR.style.fontWeight = 'bold';
    newTBody.appendChild(newTR);
    theTable.appendChild(newTBody);

    // Update global variables with final results
    valueInterestPaidNorm = termIntTotalNorm;
    valueInterestPaidAccl = termIntTotalAccl;

    valueTotalPaidNorm = prin + termIntTotalNorm;
    valueTotalPaidAccl = prin + termIntTotalAccl;
}


function AddTableData(value, row, styleText)
{

var newTD;
var newTxt;
var tempText;

    newTD = document.createElement("td");
    tempText = value;
    newTxt = document.createTextNode(tempText);

    newTD.appendChild(newTxt);

//    if (navigator.appName == 'Microsoft Internet Explorer')
//    {
        newTD.style.cssText = styleText;
//    }
//    else
//    {
//        newTD.style = styleText;
//    }
    row.appendChild(newTD);

    return newTD;
}

function ToggleLoanAccelAmortization()
{

var theButtonT = document.getElementById('ShowButtonTop');

    if (theButtonT.value == 'Show Amortization')
    {
        ShowLoanAccelAmortization();
    }
    else
    {
        HideLoanAccelAmortization();
    }
}

function ShowLoanAccelAmortization()
{

var theSchedule = document.getElementById('StartSchedule');
var theTable = document.getElementById('StartScheduleTable');
var theButtonT = document.getElementById('ShowButtonTop');
var theButtonB = document.getElementById('HideButtonBottom');

    theSchedule.style.display = 'block';
    theTable.style.display = 'block';
    theButtonB.style.display = 'block';
    theButtonT.value = 'Hide Amortization';
}

function HideLoanAccelAmortization()
{

var theSchedule = document.getElementById('StartSchedule');
var theTable = document.getElementById('StartScheduleTable');
var theButtonT = document.getElementById('ShowButtonTop');
var theButtonB = document.getElementById('HideButtonBottom');

    theSchedule.style.display = 'none';
    theTable.style.display = 'none';
    theButtonB.style.display = 'none';
    theButtonT.value = 'Show Amortization';
}


//-->


