// JavaScript Documentfunction test(form){	alert("ok I'm testing this freaking box");}function fieldCheck(input, min, max, msg){    msg = msg + " input value Error: " + input.value;    var str = input.value;    for (var i = 0; i < str.length; i++) {        var ch = str.substring(i, i + 1)        if ((ch < "0" || "9" < ch) && ch != '.') {            alert(msg);            return false;        }    }    var num = parseFloat(str)    if (num < min || max < num) {        alert(msg + " not in range [" + min + ".." + max + "]");        return false;    }    input.value = str;    return true;}function computeField(input){    if (input.value != null && input.value.length != 0)    	input.value = "" + eval(input.value);    computeForm1(input.form);}function computeForm1(form){    if ((form.pcPayPerYr.value == null || form.pcPayPerYr.value.length == 0) ||        (form.pcNumYrs.value == null || form.pcNumYrs.value.length == 0) ||        (form.pcAnnIntRate.value == null || form.pcAnnIntRate.value.length == 0) ||        (form.pcAmountMort.value == null || form.pcAmountMort.value.length == 0)) {        return;    }    if (!fieldCheck(form.pcPayPerYr, 1, 480, "Number of payments") ||        !fieldCheck(form.pcNumYrs, 1, 100, "Number of years") ||        !fieldCheck(form.pcAnnIntRate, .001, 99, "Interest rate") ||        !fieldCheck(form.pcAmountMort, 100, 10000000, "Mortgage amount")) {        form.pcPayTotal.value = "Invalid";        return;    }    var interest = form.pcAnnIntRate.value;     var yearlyPay = form.pcPayPerYr.value;    var noYrs = form.pcNumYrs.value;	    var mort = form.pcAmountMort.value;	    if (interest > 1.0)    {        interest = interest / 100.0;        form.pcAnnIntRate.value = interest;		    }	    var f = 1+(interest/yearlyPay);    var totYearly = noYrs*yearlyPay;    var incRate = 1; var g = 0;	    for (var i = 0; i < totYearly; i++)    {      incRate = incRate * f;      g = 1+g*f;    }    incRate = incRate * mort;	    form.pcPayTotal.value = Math.round(incRate/g);}function clearForm1(form){    form.pcPayPerYr.value = "";    form.pcNumYrs.value = "";    form.pcAnnIntRate.value = "";    form.pcAmountMort.value = "";}//Form 2function fieldCheck2(input, min, max, msg){    msg = msg + " field has invalid data: " + input.value;    var str = input.value;    for (var i = 0; i < str.length; i++) {        var ch = str.substring(i, i + 1)        if ((ch < "0" || "9" < ch) && ch != '.') {            alert(msg);            return false;        }    }    var num = 0 + str    if (num < min || max < num) {        alert(msg + " not in range [" + min + ".." + max + "]");        return false;    }    input.value = str;    return true;}function computeField2(input){    if (input.value != null && input.value.length != 0)        input.value = "" + eval(input.value);    computeForm2(input.form);}function computeForm2(form){    if ((form.lccNumPayA.value == null || form.lccNumPayA.value.length == 0) ||        (form.lccIntRateA.value == null || form.lccIntRateA.value.length == 0) ||        (form.lccPrincA.value == null || form.lccPrincA.value.length == 0)) {        return;    }    if (!fieldCheck2(form.lccNumPayA, 1, 480, "Number of payments") ||        !fieldCheck2(form.lccIntRateA, .001, 99, "Interest amount") ||        !fieldCheck2(form.lccPrincA, 100, 10000000, "Principal")) {        form.lccTotIntA.value = "Invalid";        return;    }   var i = form.lccIntRateA.value;    if (i > 1.0) {        i = i / 100.0;        form.lccIntRateA.value = i;    }    i /= 12;    var pow = 1;    for (var j = 0; j < form.lccNumPayA.value; j++)        pow = pow * (1 + i);    form.lccMoPayA.value = (form.lccPrincA.value * pow * i) / (pow - 1);		form.lccTotIntA.value = (form.lccMoPayA.value * form.lccNumPayA.value) - form.lccPrincA.value;}function clearForm2(form){    form.lccNumPayA.value = "";    form.lccIntRateA.value = "";    form.lccPrincA.value = "";}//Form 3function computeForm3(form) {    var pmt1 = form.mrcMoMortPay.value;    var prin1 = form.mrcPrincBalMort.value;    var intPort1 = 0;    var prinPort1 = 0;    var accumInt1 = 0;    var accumPrin1 = 0;    var i1 = form.mrcCurMortIntRate.value;    if (i1 > 1.0) {        i1 = i1 / 100.0;        form.mrcCurMortIntRate.value = i1;    }    var i1  = i1  / 12;    var i2 = form.mrcRefiIntRate.value;       if (i2 > 1.0) {           i2 = i2 / 100.0;           form.mrcRefiIntRate.value = i2;       }       var i2  = i2  / 12;    var count1 = 0;    while(prin1 > 0) {        intPort1 = prin1 * i1;        prinPort1 = pmt1 - intPort1;        prin1 = prin1 - prinPort1;        accumPrin1 = accumPrin1 + prinPort1;        accumInt1 = accumInt1 + intPort1;        count1 = count1 + 1;        if(count1 > 600) {break; } else {continue; }       }    form.mrcIntCurMortPlan.value = "$" + parseInt(accumInt1,10);    var pow = 1;    for (var j = 0; j < form.mrcNumYrsRef.value *12; j++)        pow = pow * (1 + i2);    var fpayment2 = (form.mrcPrincBalMort.value * pow * i2) / (pow - 1);    form.mrcNewMoPay.value = "$" + parseInt(fpayment2,10) + "." + parseInt(fpayment2 % 1 * 100,10);   var fmoSave = form.mrcMoMortPay.value - fpayment2;   form.mrcNewMoSave.value = "$" + parseInt(fmoSave,10) + "." + parseInt(fmoSave % 1 *100,10);		var ftotInt2 = (fpayment2 * form.mrcNumYrsRef.value *12) - form.mrcPrincBalMort.value;   form.mrcIntRefiMortPlan.value = "$" + parseInt(ftotInt2,10);   var fintSave = accumInt1 - ftotInt2;    form.mrcIntSaveRefi.value = "$" + parseInt(fintSave,10);    form.mrcNumMoEven.value = parseInt(form.mrcClosingCost.value / fmoSave,10);   var fnetSave = fintSave - form.mrcClosingCost.value;   form.mrcNetRefiSave.value = "$" + parseInt(fnetSave,10);    form.mrcMsg.value = "If you refinance your current " + parseInt(form.mrcCurMortIntRate.value *100,10) + "." + parseInt(form.mrcCurMortIntRate.value *100 % 1 *100,10) + "% mortgage to a " + parseInt(form.mrcRefiIntRate.value *100,10) + "." + parseInt(form.mrcRefiIntRate.value *100 % 1 *100,10) + "% mortgage, your monthly payment will drop by " + form.mrcNewMoSave.value + " and you will save " + form.mrcIntSaveRefi.value + " in interest charges over the life of the mortgage.  However, in order for this refinancing to yield any savings at all you will need to stay in your current home for at least " + form.mrcNumMoEven.value + " months.  That's how long it will take for your monthly payment savings to offset the closing costs attributable to refinancing.";}function clearForm3(form){    form.mrcPrincBalMort.value = "";    form.mrcMoMortPay.value = "";    form.mrcCurMortIntRate.value = "";    form.mrcRefiIntRate.value = "";    form.mrcNumYrsRef.value = "";    form.mrcClosingCost.value = "";    form.mrcNewMoPay.value = "";    form.mrcNewMoSave.value = "";    form.mrcNumMoEven.value = "";    form.mrcIntSaveRefi.value = "";    form.mrcIntCurMortPlan.value = "";    form.mrcNetRefiSave.value = "";    form.mrcIntRefiMortPlan.value = "";    form.mrcMsg.value = "";}//Form 4function computeForm4(form) {    var pmt1 = form.bmcMoMortPay.value;    var pmt2 = form.bmcMoMortPay.value / 2;    var prin1 = form.bmcPrincBalMort.value;    var prin2 = form.bmcPrincBalMort.value;    var intPort1 = 0;    var intPort2 = 0;    var prinPort1 = 0;    var prinPort2 = 0;    var accumInt1 = 0;    var accumPrin1 = 0;    var accumInt2 = 0;    var accumPrin2 = 0;    var i = form.bmcCurIntRate.value;    if (i > 1.0) {        i = i / 100.0;        form.bmcCurIntRate.value = i;    }    var i1  = i  / 12;    var i2 = i / 26;    var count1 = 0;    var count2 = 0;    while(prin1 > 0) {        intPort1 = prin1 * i1;        prinPort1 = pmt1 - intPort1;        prin1 = prin1 - prinPort1;        accumPrin1 = accumPrin1 + prinPort1;        accumInt1 = accumInt1 + intPort1;        count1 = count1 + 1;     if(count1 > 600) {       break;       } else {       continue;       }    }if(count1 > 600) { alert("Using your entered terms you will never pay off this amount.  Please either lower the principal amount, lower the interest rate, or increase the payment amount.;")        form.bmcIntPayCurMortPlan.value = "";        form.bmcIntPayBiweek_plan.value = "";        form.bmcMortIntSave.value = "";        form.bmcMsg.value = "";        } else {    form.bmcIntPayCurMortPlan.value = "$" + parseInt(accumInt1,10);    while(prin2 > 0) {        intPort2 = prin2 * i2;        prinPort2 = pmt2 - intPort2;        prin2 = prin2 - prinPort2;        accumPrin2 = accumPrin2 + prinPort2;        accumInt2 = accumInt2 + intPort2;        count2 = count2 + 1;        if(count1 > 600) {break; } else {continue; }       }       form.bmcIntPayBiweek_plan.value = "$" + parseInt(accumInt2,10);    form.bmcMortIntSave.value = "$" + parseInt(accumInt1 - accumInt2,10);    form.bmcMsg.value = "In essence, what you are really 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 coughing up and extra $" + parseInt(pmt1 / 26,10) + " every two weeks you will pay off your mortgage in " + parseInt(count2 /26*12,10) + " months instead of the current " + count1 + " months, and save $" + parseInt(accumInt1 - accumInt2) + " in mortgage interest in the process.  Now I ask you, is there anything else you would rather spend your $" + parseInt(accumInt1 - accumInt2) + " on besides interest?";   }	}function clearForm4(form){    form.bmcPrincBalMort.value = "";    form.bmcMoMortPay.value = "";    form.bmcCurIntRate.value = "";    form.bmcMortIntSave.value = "";    form.bmcIntPayCurMortPlan.value = "";    form.bmcIntPayBiweek_plan.value = "";    form.bmcMsg.value = "";}//FORM 5function computeForm5(form) {var i = form.epcAnnIntRate.value;    if (i > 1.0) {        i = i / 100.0;        form.epcAnnIntRate.value = i;    }     i /= 12;  var prin1 = eval(form.epcPrincOwed.value);   var prin2 = eval(form.epcPrincOwed.value);   var pmt1 = form.epcCurMoPay.value;   var pmt2 = eval(form.epcCurMoPay.value) + eval(form.epcAddMoPay.value);   var prinPort1 = 0;   var prinPort2 = 0;   var intPort1 = 0;   var intPort2 = 0;   var count1 = 0;   var count2 = 0;     while(prin1 > 0) {                   intPort1 = eval(i * prin1);                   prinPort1 = eval(pmt1 - intPort1);                   prin1 = eval(prin1 - prinPort1);                   count1 = count1 + 1                   if(count1 > 600) { break; } else { continue;}                   }   while(prin2 > 0) {                   intPort2 = eval(i * prin2);                   prinPort2 = eval(pmt2 - intPort2);                   prin2 = eval(prin2 - prinPort2);                   count2 = count2 + 1                   if(count2 > 600) { break;} else {continue;}                   }      form.epcIntSave.value = (count1 * pmt1) - (count2 * pmt2);     form.epcAnnReturnInvest.value = (form.epcIntSave.value / (count2 * form.epcAddMoPay.value)) / (count2 / 12);     var timSave = (count1 - count2);      form.epcMsg.value = ("If you add $" + form.epcAddMoPay.value + " to your monthly payment, you will pay off this debt in " + count2 + " payments instead of " + count1 + ", and you will save $" + parseInt(form.epcIntSave.value,10) + " in interest charges.  This savings translates into a guaranteed, tax-free, average annual return of " + parseInt(form.epcAnnReturnInvest.value * 100,10) + "%.  And that's not even considering the emotional returns you'll get when you pay off this debt " + timSave + "-months (" + parseInt(timSave /12,10) + " years, " + (timSave %12) + " months) ahead of schedule!");}function clearForm5(form){    form.epcPrincOwed.value = "";    form.epcAnnIntRate.value = "";    form.epcCurMoPay.value = "";    form.epcAddMoPay.value = "";    form.epcIntSave.value = "";    form.epcAnnReturnInvest.value = "";    form.epcMsg.value = "";}
