﻿function jumpBox(list) {location.href = list.options[list.selectedIndex].value}function computeForm(form) {if(form.prinbal.value == "" || form.prinbal.value == 0) {alert("Please enter the principal balance of your current mortgage.");form.prinbal.focus();}  else if(form.onepay.value == "" || form.onepay.value == 0) {alert("Please enter the mount of your monthly mortgage payment.");form.onepay.focus();}  else if(form.rate1.value == "" || form.rate1.value == 0) {alert("Please enter your mortgage's current interest rate.");form.rate1.focus();}  else if(form.rate2.value == "" || form.rate2.value == 0) {alert("Please enter the interest rate you will be refinancing at.");form.rate2.focus();}  else if(form.noyear.value == "" || form.noyear.value == 0) {alert("Please enter the number of years you will be refinancing for.");form.noyear.focus();}  else if(form.ccrefi.value == "" || form.ccrefi.value == 0) {alert("Please enter the closing costs that will be required for refinancing.");form.ccrefi.focus();}var int1 = 0;var int2 = 0;var intrate1 = 0;var origprinc = 0;var pmt = form.onepay.value;var intamou = form.prinbal.value;var dtno = form.rate1.value;if (dtno > 1.0) {dtno = dtno / 100.0;form.rate1.value = dtno;}var dtno  = dtno / 12;var opprn = form.rate2.value;if (opprn > 1.0)  {opprn = opprn / 100.0;form.rate2.value = opprn;}var opprn  = opprn / 12;var counter = 0;while(intamou > 0)  {intrate1 = intamou * dtno;origprinc = pmt - intrate1;intamou = intamou - origprinc;int2 = int2 + origprinc;int1 = int1 + intrate1;counter = counter + 1;if(counter > 600) {break;  } else {continue;  }}form.curint.value = "$" + parseInt(int1, 10);var pow = 1;for (var j = 0; j < form.noyear.value *12; j++)pow = pow * (1 + opprn);var twopays = (form.prinbal.value * pow * opprn) / (pow - 1);form.twopay.value = "$" + parseInt(twopays, 10) + "." + parseInt(twopays % 1 * 100, 10);var savmos = form.onepay.value - twopays;form.savmo.value = "$" + parseInt(savmos, 10) + "." + parseInt(savmos % 1 *100, 10);var refiints = (twopays * form.noyear.value *12)- form.prinbal.value;form.refiint.value = "$" + parseInt(refiints, 10);var refisavs = int1 - refiints;form.refisav.value = "$" + parseInt(refisavs, 10);form.breve.value = parseInt(form.ccrefi.value / savmos, 10);var totsavs = refisavs - form.ccrefi.value;form.totsav.value = "$" + parseInt(totsavs, 10);form.tipres.value = "Refinancing to " + parseInt(form.rate2.value *100, 10) + "." + parseInt(form.rate2.value *100 % 1 *100, 10) + "% from " + parseInt(form.rate1.value *100, 10) + "." + parseInt(form.rate1.value *100 % 1 *100, 10) + "% lowers the monthly payment " + form.savmo.value + " and saves " + form.refisav.value + " in interest over the loan term. It will take " + form.breve.value + " months to recoup the closing costs for refinance.";}function clearForm(form){form.prinbal.value = "";form.onepay.value = "";form.rate1.value = "";form.rate2.value = "";form.noyear.value = "";form.ccrefi.value = "";form.twopay.value = "";form.savmo.value = "";form.breve.value = "";form.refisav.value = "";form.curint.value = "";form.totsav.value = "";form.refiint.value = "";form.tipres.value = "";}function reCalculateKt(changedObj) {}var helpTexts = new Array();helpTexts["prinbal"] = "Enter the existing pricipal balance of your current mortgage.";helpTexts["onepay"] = "Enter the amount of your monthly mortgage payment.";helpTexts["rate1"] = "Enter the interest rate of your current mortgage.";helpTexts["rate2"] = "Enter the interest rate you would like to refinance your mortgage.";helpTexts["noyear"] = "Enter the number of years you are financing the home for (typically 30 or 15).";helpTexts["ccrefi"] = "Enter the closing costs required for refinancing (lender origination, discount points, pre-paids, etc.";helpTexts["savmo"] = "Estimated monthly savings, if you refinance your loan.";helpTexts["twopay"] = "Your monthly mortgage payment, if you refinance your loan.";helpTexts["breve"] = "Number of months to break even on the closing costs if you refinance (factors like income tax deductions are not considered for this calculation).";helpTexts["curint"] = "How much interest you will pay under your current monthly plan.";helpTexts["refiint"] = "How much interest you will pay under your refinanced monthly plan.";helpTexts["refisav"] = "How much interest you will save over time if you refinance.";helpTexts["totsav"] = "Net refinancing savings (interest savings less closing costs).";var ktArray = new Array();function kt_init() {var kt = document.getElementById("kt");if (kt) {var inputs=kt.getElementsByTagName("input"), selects=kt.getElementsByTagName("select"), el, i=0;while (el = inputs[i++]) {el.onchange = function () {reCalculateKt(this);}}i = 0;while (el = selects[i++]) {el.onchange = function () {reCalculateKt(this);}}}refreshVariables();reCalculateKt();applyHelpPopups();}function refreshVariables() {var kt = document.getElementById("kt");if (kt) {var inputs=kt.getElementsByTagName("input"), selects=kt.getElementsByTagName("select"), el, i=0;ktArray["vars"] = new Array();while (el = inputs[i++]) {if (el.id) {ktArray["vars"][el.id] = $(el.id, el.getAttribute("valuetype"));if (el.getAttribute("valuetype")!="raw") {el.value = numberFormat(ktArray["vars"][el.id], el.getAttribute("valuetype"), el.getAttribute("valueformat"));}}}i = 0;while (el = selects[i++]) {if (el.id) ktArray["vars"][el.id] = $(el.id, el.getAttribute("valuetype"));}}}function numberFormat(value, valuetype, valueformat) {if (value || value==0) {var formatparts = new Array();if (valueformat) formatparts = valueformat.split(".");var decimals = formatparts[1] ? formatparts[1] : 2;switch(valuetype) {case "money":if (value===0) {value = "";for (iii=0; iii<decimals; iii++) {if (!value) value += ".";value += "0";}value = "$0"+value;} else {value = value.toFixed(decimals);value = addCommas(value);value = "$"+value;}break;case "percent":value = value.toFixed(decimals)+"%";break;case "number":if (value===0) {value = "";for (iii=0; iii<decimals; iii++) {if (!value) value += ".";value += "0";}value = "0"+value;} else {value = value.toFixed(decimals);value = value;}break;}} else {value = "";}return value;}function $(id, type) {if (!type) type = "number";var returnVar = document.getElementById(id).value;if (type!="raw") {returnVar = returnVar.replace("$", "");returnVar = returnVar.replace("%", "");returnVar = returnVar.replace(/,/g, "");}if (type!="date" && type!="raw") returnVar = parseFloat(returnVar);return returnVar;}function applyHelpPopups() {if (!helpTexts) return 0;for (var fieldId in helpTexts) {var fieldObj = document.getElementById(fieldId);fieldObj.onmouseover = function () {hideHelp();};if (!fieldObj) continue;if (fieldId.indexOf("help_")==0) {var prevSibling = fieldObj;} else {if (fieldObj.tagName=="INPUT" || fieldObj.tagName=="SELECT") {var fieldParent = fieldObj.parentNode;} else {var fieldParent = fieldObj;}if (!fieldParent) continue;var prevSibling = fieldParent.previousSibling;if (!prevSibling) continue;if (prevSibling.tagName!="DIV") prevSibling = prevSibling.previousSibling;if (!prevSibling) continue;}prevSibling.style.position = "relative";if (fieldId.indexOf("help_")==0) {var reddot = document.createElement("img");reddot.src="../media/question_icon.gif";reddot.className = "kt_reddot_img";} else {var reddot = document.createElement("div");reddot.className = "kt_reddot";}prevSibling.appendChild(reddot);prevSibling.setAttribute("help_id", fieldId);prevSibling.onclick = function () {showHelp(this, this.getAttribute("help_id"));};prevSibling.onmouseout = function () {setTimeout("hideHelp('"+this.getAttribute('help_id')+"')", 500);}}return 1;}var overHelp = 0;function showHelp(fieldObj, help_id) {if (!fieldObj || !help_id || !helpTexts[help_id]) return 0;var help_box = document.getElementById("help_box");if (!help_box) {help_box = document.createElement("div");help_box.id = "help_box";help_box.className = "help_box";help_box.onmouseover = function () {overHelp = 1;};help_box.onmouseout = function () {overHelp = 0;};document.body.appendChild(help_box);help_box = document.getElementById("help_box");}var field_top = findPosY(fieldObj);var field_left = findPosX(fieldObj);help_box.innerHTML = helpTexts[help_id];help_box.style.top = (field_top+10)+"px";help_box.style.left = (field_left+50)+"px";help_box.style.display = "block";help_box.setAttribute("help_id", help_id);}function hideHelp(help_id) {if (overHelp) return 1;var help_box = document.getElementById("help_box");if (help_box) {if (help_id && help_box.getAttribute("help_id")!=help_id) return 0;help_box.style.display = "none";}return 1;}function findPosX(obj) {var curleft = 0;if (obj.offsetParent) {while (obj.offsetParent) {curleft += obj.offsetLeft;obj = obj.offsetParent;}} else if (obj.x) curleft += obj.x;return curleft;}function findPosY(obj) {var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent) {curtop += obj.offsetTop;obj = obj.offsetParent;}} else if (obj.y) curtop += obj.y;return curtop;}

