function calcForm(form) {

    var mp1 = form.mortgage_payment.value;

    var mp2 = form.mortgage_payment.value / 2;

    var p1 = form.mortgage_principal.value;

    var p2 = form.mortgage_principal.value;

    var ic1 = 0;

    var ic2 = 0;

    var pc1 = 0;

    var pc2 = 0;

    var dmpInt1 = 0;

    var dmp1 = 0;

    var dmpInt2 = 0;

    var dmp2 = 0;

    var mir = form.mortgage_intRate.value;

    if (mir > 1.0) {

        mir = mir / 100.0;

        form.mortgage_intRate.value = mir;

    }

    var mir1  = mir  / 12;

    var mir2 = mir / 26;

    var crunch1 = 0;

    var crunch2 = 0;

    while(p1 > 0) {

        ic1 = p1 * mir1;

        pc1 = mp1 - ic1;

        p1 = p1 - pc1;

        dmp1 = dmp1 + pc1;

        dmpInt1 = dmpInt1 + ic1;

        crunch1 = crunch1 + 1;

     if(crunch1 > 600) {
        break;
        } else {
        continue;
        }

       }

if(crunch1 > 600) {
 alert("You can not pay off this amount by using the numbers provided.  Either lower the interest rate, lower the principal amount, or increase the payment amount.");
        form.currentInt.value = "";
        form.biweeklyInt.value = "";
        form.intSaved.value = "";
        form.answer.value = "";
        } else {

    form.currentInt.value = parseInt(dmpInt1,10);

    while(p2 > 0) {

        ic2 = p2 * mir2;

        pc2 = mp2 - ic2;

        p2 = p2 - pc2;

        dmp2 = dmp2 + pc2;

        dmpInt2 = dmpInt2 + ic2;

        crunch2 = crunch2 + 1;

        if(crunch1 > 600) {break; } else {continue; }

       }
    
    form.biweeklyInt.value = parseInt(dmpInt2,10);

    form.intSaved.value = parseInt(dmpInt1 - dmpInt2,10);

    form.answer.value = "What we are doing is adding a 13th payment to your annual number of payments, and splitting it up between 26 bi-weekly payments. Which in your case means that by spending an extra $" + parseInt(mp1 / 26,10) + " every two weeks you will pay off your mortgage in " + parseInt(crunch2 /26*12,10) + " months instead of the current " + crunch1 + " months, and save $" + parseInt(dmpInt1 - dmpInt2) + " in mortgage interest in the process.  Wouldn't you rather spend your $" + parseInt(dmpInt1 - dmpInt2) + " on something else besides interest?";

   }
		
}



function clearForm(form)

{

    form.mortgage_principal.value = "";

    form.mortgage_payment.value = "";

    form.mortgage_intRate.value = "";

    form.intSaved.value = "";

    form.currentInt.value = "";

    form.biweeklyInt.value = "";

    form.answer.value = "";

}
