﻿<!-- UNAUTHORIZED COPYING OF THIS DOCUMENT, AND/OR COPYRIGHT INFRINGEMENT IS PROHIBITED BY LAW. WE WILL VIGOROUSLY PROSECUTE THE OFFENDERS.-->
function reCalculateKt(changedObj) {ktArray = new Array();refreshVariables();ktArray["summary"] = new Array();displayValues();}function displayValues() {for (var fieldId in ktArray["summary"]) {var fieldObj = document.getElementById(fieldId);if (fieldObj && ktArray["summary"][fieldId]) {fieldObj.innerHTML = numberFormat(ktArray["summary"][fieldId], fieldObj.getAttribute("valuetype"), fieldObj.getAttribute("valueformat"));}}}function stripnumb(numb) {var lespercent;var lesdollar;var lesspace;var lescomma;var lesnumamt = numb.length;if(lesnumamt > 0) {numb=numb.toString();lespercent = numb.indexOf("%");if(lespercent >= 0) {numb=numb.substring(0,lespercent) + "" + numb.substring(lespercent + 1,lesnumamt);lesnumamt=numb.length;}lesdollar = numb.indexOf("$");if(lesdollar >= 0) {numb=numb.substring(0,lesdollar) + "" + numb.substring(lesdollar + 1,lesnumamt);lesnumamt=numb.length;}lesspace = numb.indexOf(" ");if(lesspace >= 0) {numb=numb.substring(0,lesspace) + "" + numb.substring(lesspace + 1,lesnumamt);lesnumamt=numb.length;}lescomma = numb.indexOf(",");if(lescomma >= 0) {while(lescomma >=1) {numb=numb.substring(0,lescomma) + "" + numb.substring(lescomma + 1,lesnumamt);lesnumamt=numb.length;lescomma = numb.indexOf(",");}}numb = eval(numb);} else {numb = 0;}return numb;}function formatnumb(numb) {var negative=0;if(numb < 0) {numb=numb*-1;negative=1;}zeronumb=Math.round(numb*100)/100;integer=Math.floor(zeronumb);if (Math.ceil(zeronumb) == integer) {decimal="00";} else{decimal=Math.round((zeronumb-integer)*100)}decimal=decimal.toString();if (decimal.length<2) decimal="0"+decimal;integer=integer.toString();var tempnumb="";var tempinteger="";var x=0;for (z=integer.length;z>0;z--) {tempnumb=tempnumb+integer.charAt(z-1);x=x+1;if (x==3 & z>1) {tempnumb=tempnumb+",";x=0;}}for (z=tempnumb.length;z>0;z--) {tempinteger=tempinteger+tempnumb.charAt(z-1);}finalnumb=tempinteger+"."+decimal;if(negative == 1) {finalnumb = "-" + finalnumb;}return finalnumb;}function calculateform(form) {if(form.monrent.value == "" || form.monrent.value == 0) {alert("Please enter the amount of your monthly rent payment.");form.monrent.focus();} else if(form.purprice.value == "" || form.purprice.value == 0) {alert("Please enter the purchase price of the home.");form.purprice.focus();} else if(form.numbyears.value == "" || form.numbyears.value == 0) {alert("Please enter the number of years you are financing the home for.");form.numbyears.focus();} else if(form.annualrate.value == "" || form.annualrate.value == 0) {alert("Please enter the mortgage's annual interest rate.");form.annualrate.focus();} else if(form.livintime.value == "" || form.livintime.value == 0) {alert("Please enter the number of years you plan to stay in this property.");form.annualrate.focus();} else {var monrentvar = stripnumb(form.monrent.value);var totalrentvar = 0;var monrentinsvar = stripnumb(form.monrentins.value);if(monrentinsvar == "" || monrentinsvar == 0) {monrentinsvar = 0}var anninflationvar = stripnumb(form.anninflation.value);if(anninflationvar == "" || anninflationvar == 0) {anninflationvar = 0} else if(anninflationvar >= 1) {anninflationvar = anninflationvar / 100;}anninflationvar = eval(anninflationvar) + eval(1);var livintimevar = stripnumb(form.livintime.value);var livinmonvar = livintimevar * 12;var countit = 0;var int = stripnumb(form.annualrate.value);if (int > 1.0) {int = int / 100.0;}int /= 12;var purpricevar = stripnumb(form.purprice.value);var numbyearsvar = stripnumb(form.numbyears.value);var dpamtvar = stripnumb(form.dpamt.value);var loanprincvar = eval(purpricevar) - eval(dpamtvar);var intamt = 0;var accumintvar = 0;var prinamt = 0;var principal = loanprincvar;function floor(number){return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);}var numbmon = numbyearsvar * 12;var pow = 1;for (var k = 0; k < numbmon; k++)pow = pow * (1 + int);var monpmt = (loanprincvar * pow * int) / (pow - 1);var expectappvar = stripnumb(form.expectapp.value);if(expectappvar == "" || expectappvar == 0) {expectappvar = 0;} else if(expectappvar >= 0) {expectappvar = expectappvar / 100;}expectappvar = eval(expectappvar) + eval(1);var accumappvar = purpricevar * expectappvar;var mtginsvar = stripnumb(form.mtgins.value);if(mtginsvar == 0 || mtginsvar == "") {mtginsvar = 0;} else if(mtginsvar >= .01) {mtginsvar = mtginsvar / 100;}mtginsvar = mtginsvar / 12;var mtginskt = 0;var accunmtginsvar = 0;var dppercentage = dpamtvar / purpricevar;if(dppercentage < .20) {mtginskt = 1;accunmtginsvar = 0;}if(mtginskt == 1) {accunmtginsvar = eval(accunmtginsvar) + eval(mtginsvar * principal);mtginsurance = eval(mtginsvar * principal);}if(mtginskt == 0) {mtginsurance = 0;}var origfeevar = stripnumb(form.origfee.value);if(origfeevar == 0 || origfeevar == "") {origfeevar = 0;} else if(origfeevar >= 1 ) {origfeevar = origfeevar / 100;}var feeamtvar = loanprincvar * origfeevar;var discpointvar = stripnumb(form.discpoint.value);if(discpointvar == 0 || discpointvar == "") {discpointvar = 0;} else if(discpointvar >= 1 ) {discpointvar = discpointvar / 100;}var discpointamtvar = loanprincvar * discpointvar;var othercostvar= stripnumb(form.othercost.value);if(othercostvar == 0 || othercostvar == "") {othercostvar = 0;}var closefeesvar= stripnumb(form.closefees.value);if(closefeesvar == 0 || closefeesvar == "") {closefeesvar = 0;}var closecostvar = eval(discpointamtvar) + eval(feeamtvar) + eval(othercostvar) + eval(closefeesvar);var invinterestvar = 0;var invprincipalvar = eval(dpamtvar) + eval(closecostvar);var earnedinterest = stripnumb(form.savintrate.value);if (earnedinterest >= 1.0) {earnedinterest = earnedinterest / 100.0;}earnedinterest /= 12;var inflatinterestvar = 1;while(countit < livinmonvar) {if(countit > 0 && countit % 12 == 0) {accumappvar = accumappvar * expectappvar;monrentvar = monrentvar * anninflationvar;inflatinterestvar = inflatinterestvar * anninflationvar;}totalrentvar = eval(totalrentvar) + eval(monrentvar);totalrentvar = eval(totalrentvar) + eval(monrentinsvar);if(countit < numbmon) {intamt = principal * int;accumintvar = eval(accumintvar) + eval(intamt);prinamt = eval(monpmt) - eval(intamt);principal = eval(principal) - eval(prinamt);}invinterestvar = earnedinterest * invprincipalvar;invprincipalvar = eval(invprincipalvar) + eval(invinterestvar);countit = eval(countit) + eval(1);}var assocduesvar = stripnumb(form.associationdues.value);if(assocduesvar == "" || assocduesvar == 0) {assocduesvar = 0;}var assocduetot = assocduesvar * 12 * livintimevar * inflatinterestvar;var proptaxvar = stripnumb(form.annualproptax.value);if(proptaxvar == "" || proptaxvar == 0) {proptaxvar = 0;}var totproptaxvar = proptaxvar * livintimevar * inflatinterestvar;var maintenvar = form.monmainten.value;if(maintenvar == "" || maintenvar == 0) {maintenvar = 0;}var totmaintcostvar = maintenvar * 12 * livintimevar * inflatinterestvar;var hminsratevar = stripnumb(form.hminsrate.value);if(hminsratevar == 0 || hminsratevar == "") {hminsratevar = 0;} else if(hminsratevar >= .01) {hminsratevar = hminsratevar / 100;}hminsratevar = hminsratevar / 12;var hminstotvar = hminsratevar * purpricevar * livintimevar * inflatinterestvar;var homenetgainvar = eval(accumappvar) - eval(purpricevar);var tottaxdedvar = eval(accumintvar) + eval(totproptaxvar) + eval(feeamtvar);var incomtaxvar = stripnumb(form.incomtax.value);if(incomtaxvar == 0 || incomtaxvar == "") {incomtaxvar = 0;} else if(incomtaxvar >= 1) {incomtaxvar = incomtaxvar / 100;}var tottaxsavvar = incomtaxvar * tottaxdedvar;var realcommvar = stripnumb(form.realtorcom.value);if(realcommvar == 0 || realcommvar == "") {realcommvar = 0;} else if(realcommvar >= 1) {realcommvar = realcommvar / 100;}var sell_costvar = accumappvar * realcommvar;var remodvar = form.remod.value;if(remodvar == "" || remodvar == 0) {remodvar = 0;}var leasepricevar = form.leaseprice.value;if(leasepricevar == "" || leasepricevar == 0) {leasepricevar = 0;}var lp = leasepricevar;var lp_accumappvar = lp * expectappvar;var monrc = stripnumb(form.monrentcredit.value);if(monrc == "" || monrc == 0) {monrc = 0;}var mrc = monrc;var lease_option_fee = (form.leaseoptfee.value);if(lease_option_fee == "" || lease_option_fee == 0) {lease_option_fee = 0;}var lof = lease_option_fee;var lease_option_yrs = (form.lease_optionyrs.value);if(lease_option_yrs == "" || lease_option_yrs == 0) {lease_option_yrs = 0;}var lo_yrs = lease_option_yrs;var lp_appmonamt = lp_accumappvar - lp;var lp_appamt = lp_appmonamt * lo_yrs;form.lp_appamt.value = formatnumb(lp_appamt);var lo_mos = 12 * lo_yrs;var accrufund = eval(lof) + eval(mrc) * eval(lo_mos);form.accrufund.value = formatnumb(accrufund);var yearrentcredit = floor(mrc * 12);form.yearrentcredit.value = yearrentcredit;var renewal = stripnumb(form.renewal.value);form.renewal.value = renewal;var assignment = stripnumb(form.assignment.value);form.assignment.value = formatnumb(assignment);var assignprice = stripnumb(form.assignprice.value);form.assignprice.value = formatnumb(assignprice);var assignprofit = stripnumb(form.assignprofit.value);form.assignprofit.value = assignprofit;var titlesearch = stripnumb(form.titlesearch.value);form.titlesearch.value = titlesearch;var attorneyfees = stripnumb(form.attorneyfees.value);form.attorneyfees.value = attorneyfees;var homeinspection = stripnumb(form.homeinspection.value);form.homeinspection.value = homeinspection;var monmaintence = stripnumb(form.monmaintence.value);form.monmaintence.value = monmaintence;var lo_maintence = monmaintence * lo_mos;var lpothercost = stripnumb(form.lpothercost.value);form.lpothercost.value = lpothercost;var investedearnvar = eval(invprincipalvar) - eval(dpamtvar) - eval(closecostvar);form.renttot.value = totalrentvar;form.mon_pmt.value = monpmt;form.accum_int.value = accumintvar;form.close_cost.value = closecostvar;form.totprop_tax.value = totproptaxvar;form.totmain_cost.value = totmaintcostvar;form.tothmins_cost.value = hminstotvar;form.home_netgain.value = homenetgainvar;form.mtgins_cost.value = accunmtginsvar;form.invested_earn.value = investedearnvar;form.aasoc_duetot.value = assocduetot;form.tottax_sav.value = tottaxsavvar;form.sell_cost.value = sell_costvar;var totrent_costvar = totalrentvar;form.totrent_cost.value = totrent_costvar;var totrent_benevar = investedearnvar;form.totrent_bene.value = totrent_benevar;var totbuy_costvar = eval(accumintvar) + eval(closecostvar) + eval(totproptaxvar) + eval(totmaintcostvar) + eval(hminstotvar) + eval(accunmtginsvar) + eval(assocduetot) + eval(sell_costvar) + eval(remodvar);form.totbuy_cost.value = totbuy_costvar;var totbuy_benevar = eval(homenetgainvar) + eval(tottaxsavvar);form.totbuy_bene.value = totbuy_benevar;var netbuy_costvar = eval(totbuy_costvar) - eval(totbuy_benevar);form.netbuy_cost.value = "$" + formatnumb(netbuy_costvar);if(lp == 0 || lp == "") {lp = 0;} else if(lp >= 1 ) {lp = lp / 100;}var lo_yrsprofit = mrc * lo_mos;var finalpurprice = (leasepricevar) - (lo_yrsprofit) - (lof) + (renewal) + (assignment) + (titlesearch) + (attorneyfees) + (homeinspection) + (lp_appamt) + (lpothercost);form.finalpurprice.value = "$" + formatnumb(finalpurprice);var leasecostratio = (finalpurprice) / (form.monrent.value);form.lcr.value = formatnumb(leasecostratio);var yrrentins = monrentinsvar * 12;var lo_yrrentins = yrrentins * lo_yrs;var yrrent = form.monrent.value * 12;var lo_yrrent = yrrent * lo_yrs;var lpcost = eval(leasepricevar) + lo_yrrent + lo_yrrentins + eval(lof) + eval(renewal) + eval(assignment) + eval(titlesearch) + eval(attorneyfees) + eval(homeinspection) + eval(lp_appamt) + (lpothercost) + (lo_maintence);form.lpcost.value = "$" + formatnumb(lpcost);var lo_yrrent_infl = lo_maintence + lo_yrrentins + lo_yrrent * anninflationvar;form.loyrrentinfl.value = formatnumb(lo_yrrent_infl);var netlease_costvar = lo_yrrent + lo_yrrentins + eval(lof) + eval(renewal) + eval(assignment) + eval(titlesearch) + eval(attorneyfees) + eval(homeinspection) + eval(lp_appamt) + (lpothercost) + (lo_maintence);form.netlease_cost.value = "$" + formatnumb(netlease_costvar);var lp_value = lp_appamt + finalpurprice;form.lp_value.value = formatnumb(lp_value);var assignprofit = assignprice - lpcost;if(assignprice == "" || assignprice == 0) {assignprofit = 0;}form.assignprofit.value = formatnumb(assignprofit);var assignratio = lpcost / assignprofit;if(assignprice == "" || assignprice == 0) {assignratio = 0;}form.assignratio.value = formatnumb(assignratio);var monthlyint = form.annualrate.value / 1200;var base = 1;var mbase = 1 + monthlyint;for (i=0; i<form.numbyears.value * 12; i++){base = base * mbase}var princ_interest = floor(loanprincvar * monthlyint / ( 1 - (1/base)));var maintenece = floor(maintenvar);var assdues = floor(assocduesvar);var mon_tax = floor(proptaxvar / 12);var monthlyins = hminsratevar * purpricevar;var dasum = loanprincvar * monthlyint / ( 1 - (1/base)) + mon_tax + monthlyins + eval(maintenvar) + eval(mtginsurance) + eval(assocduesvar);form.totalpmt.value = floor(dasum);var moncollect =  stripnumb(form.monrent.value) - dasum;form.moncollect.value = floor(moncollect);var yearcollect =  moncollect * 12;form.yearcollect.value = floor(yearcollect);var buycost = eval(closecostvar) + eval(remodvar) + eval(purpricevar);var costvalue = (buycost)/(lp);form.ctv.value = formatnumb(costvalue);var optionprofit = eval(finalpurprice) - eval(purpricevar);form.optionprofit.value = "$" + formatnumb(optionprofit);var totalprofit = eval(optionprofit) + eval(yearcollect) + eval(lof) - eval(closecostvar) - eval(sell_costvar) - eval(remodvar);form.totalprofit.value = "$" + formatnumb(totalprofit);}}var helpTexts = new Array();helpTexts["pur_price"] = "Total purchase price of the house to buy and lease to tenant/buyer's -- not including closing costs.";helpTexts["dp_amt"] = "Enter the amount you will have available to put down on the house after you have set aside the cash you will need to pay the closing costs.";helpTexts["mtg_term"] = "Enter the number of years you are financing the house for.";helpTexts["mtgrate"] = "Enter the annual interest rate of the mortgage. Enter 8% as simply 8 (do not include percent sign).";helpTexts["disc_point"] = "Discount points are paid up front in order to reduce the interest rate of your mortgage. Each point represents 1% of your mortgage balance. Enter 1% as simply 1 (do not include percent sign).";helpTexts["orig_fee"] = "The percentage (often as high as 1% of the loan amount) that a lending institution charges for processing and originating a loan.";helpTexts["other_cost"] = "The total of other loan related costs, such as credit report, filing fees, appraiser fees, etc.";helpTexts["close_fees"] = "The title company and/or attorney closing fees, such as document review, recording, filing, stamp fees, etc.";helpTexts["mtg_ins"] = "If your down payment is less than 20% of the value of the home you are buying, you may be required to pay mortgage insurance of somewhere between 0.2% and 0.5% of your principal balance each month. Enter .04% simply as .4 (do not include percent sign).";helpTexts["owner_ins"] = "Your homeowner's insurance rate -- entered as a percentage of your home's value. Typical rate is 0.5%. Enter .5% simply as .5 (do not include percent sign).";helpTexts["assoc_due"] = "If there is a homeowner or condo association, enter the monthly dues in this field.";helpTexts["re_mod"] = "The total fix-up costs, such as clean-up, yard-work, painting, flooring, fencing, roofing, insulation, etc.";helpTexts["maint"] = "Enter the amount you expect to spend on repairing and maintaining the house each month.";helpTexts["annual_tax"] = "Enter the amount of property taxes required each year.";helpTexts["inc_tax"] = "Enter your combined state and federal income tax percentage rate. Enter 28% simply as 28 (do not include percent sign).";helpTexts["earn_int"] = "Enter the annual interest rate you expect to earn on the down payment and closing costs you will invest if you decide not to buy and lease to tenant/buyer's. Enter 7% simply as 7 (do not include percent sign).";helpTexts["expect_app"] = "Enter the percentage amount you expect the house to appreciate each year. Enter 3% simply as 3 (do not include percent sign).";helpTexts["liv_in"] = "Enter the number of years you expect to own the property you are considering.";helpTexts["commish"] = "Enter the percentage of the home's selling price that you expect to pay a real estate agent or broker when it's time to sell your home. Enter 7% simply as 7 (do not include percent sign).";helpTexts["cost_value"] = "The maximum cost to value ratio should be no greater than 70% to minimize your investment risk.";helpTexts["total_pmt"] = "Total monthly expenses -- interest, property taxes, maintenance, mortgage insurance, homeowners insurance, and homeowner or condo association dues.";helpTexts["mon_collect"] = "Monthly profit amount from the tenant/buyer's payment minus the seller/leasor property expenses, or combined monthly payments.";helpTexts["year_collect"] = "Yearly profit amount from the tenant/buyer's payment minus the seller/leasor property expenses, or combined yearly payments.";helpTexts["option_profit"] = "Profit received from final sale. The final purchase price minus the house buy price.";helpTexts["net_buy_cost"] = "Net cost of buying. Total house costs minus the tax savings and appreciation benefits.";helpTexts["total_profit"] = "Profit received from final sale. The final purchase price minus the house buy price, purchase option fee, monthly lease credit, closing cost, selling cost, and remodeling or repair cost.";helpTexts["lease_price"] = "This is the purchase price of the home sold to the tenant/buyer. Buyer and seller may agree to a purchase price now or the buyer may agree to pay market value at the time the option is exercised, it's negotiable. Most buyers want to lock in the future purchase price upon inception of the option.";helpTexts["lease_optfee"] = "Option money is usually negotiable but nonrefundable. Tenant/buyer's pay a sum to the seller at the beginning of the lease. This money is typically applied to the purchase price of the home if the option is exercised. The option money is forfeited to the seller/leasor if the tenant/buyer's don't go through with the purchase.";helpTexts["mo_rent"] = "Enter the amount of the monthly lease payment. Every month a portion of the lease payment (typically $100-$500) is credited towards the sales price or down payment. ";helpTexts["lease_option_yrs"] = "Typical lease length before the purchase is 12 to 24 months, but anything may be agreed upon. This gives tenant/buyer's a chance to prepare for a traditional mortgage and build equity. Usually the home can be bought at any time during the contract but, the tenant/buyer's have a contract to buy the home when the lease is up.";helpTexts["renewal_option"] = "This is a lease extension fee to add to the term of the lease to purchase contract.";helpTexts["title_search"] = "Title searches look for proof that encumbrances are paid off, and they look at easements, rights-of-way, CC&Rs, marriage records, death certificates, tax sales, etc.";helpTexts["attorney_fees"] = "Title agents and Attorney's can help with title defects or unrecorded documents, incorrect signatures, forgery, fraud, defects, restrictive covenants, encumbrances or judgments, mechanic's liens, unrecorded liens, unrecorded easements, access rights, etc.";helpTexts["home_inspection"] = "An inspection should check the existing condition of all systems and equipment, the general quality and condition of the structure, and routine repair and maintenance items. This should include -- doors, stairs and walkways, drainage, fireplace, floors, foundation, heating and cooling, improvements, appliances, insulation, lead, gas leaks, pests, plumbing, roof, walls, ceilings, windows, wiring, etc.";helpTexts["mo_rent_ins"] = "Lease insurance usually covers tenant/buyer's against losses to belongings occurring as a result of fire and theft, including personal liability coverage for injuries or damage caused. Most lease policies include deductible amounts of $250 or $500.";helpTexts["mon_maintence"] = "Enter a monthly maintenance amount required for general upkeep.";helpTexts["lp_other_cost"] = "Enter any monthly miscellaneous costs.";helpTexts["mon_rentcredit"] = "The monthly portion of lease payment credited toward the purchase price or down payment at the end of the lease. Rent credit is non-refundable if the purchase option is not excercised.";helpTexts["year_rentcredit"] = "The yearly total of lease payment credited toward the purchase price or down payment at the end of the lease. Rent credit is non-refundable if the purchase option is not excercised.";helpTexts["accru_fund"] = "The purchase option fee and portion of rent credited toward the purchase price at the end of the lease option agreement. Since the sales price is typically locked in before closing, any increase in property value will mean the tenant/buyer's equity is increasing in the home.";helpTexts["annual_inf"] = "Enter the annual inflation rate. This is used to inflate the costs of lease, insurance, maintenance, dues and property taxes. Most times, this will be between 1-5%.";helpTexts["lp_app_amt"] = "The expected appreciation amount of the house for the lease term.";helpTexts["lp_appvalue"] = "The expected appreciated value of the house for the lease term. Although the lease payments may exceed market rent, the tenant/buyer's are building equity and banking that the house will appreciate beyond the agreed upon purchase price.";helpTexts["assignment_option"] = "This is an option fee for an assignment contract when tenant/buyer's negotiate a sales contract with someone to purchase the house. Once the contract is properly executed, the contract can be sold to someone that will take possession of the property.";helpTexts["assign_price"] = "The sale price for an assignment contract when negotiated with someone to purchase the house.";helpTexts["assign_profit"] = "The profit from an assignment contract when negotiated with someone to purchase the house. Assignment contracts are probably the simplest and least complex profit generators of real estate.";helpTexts["assign_ratio"] = "This value is the profit from an assignment contract divided by the total cost of the house.";helpTexts["lcratio"] = "The lease cost ratio is the final sales price divided by the monthly lease amount. This value can be used when comparing property to purchase.";helpTexts["lo_yr_rent_infl"] = "Comparable lease or rent cost for the stated lease payment, insurance, maintenance and annual inflation rate during the contract period.";helpTexts["net_lease_cost"] = "Total leasing cost of the contract period for lease option fee, lease payment, insurance, maintenance, title, attorney, inspection, assignment, renewal, other cost and annual inflation.";helpTexts["lp_cost"] = "Lease purchase price plus total leasing cost of the contract period for lease option fee, lease payment, insurance, maintenance, title, attorney, inspection, assignment, renewal, other cost and annual inflation.";helpTexts["final_purprice"] = "The appreciated lease purchase price plus any fee's -- title, attorney, inspection, assignment, renewal, other costs -- minus rent credit and purchase option fee equal tenant/buyer's final purchase price.";var ktArray = new Array();function kt_init() {var kt = document.getElementById("kt");if (kt) {var inputs=kt.getElementsByTagName("input"), selects=kt.getElementsByTagName("select"), el, int=0;while (el = inputs[int++]) {el.onchange = function () {reCalculateKt(this);}}int = 0;while (el = selects[int++]) {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, int=0;ktArray["vars"] = new Array();while (el = inputs[int++]) {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"));}}}int = 0;while (el = selects[int++]) {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 addCommas(nStr){nStr += '';z = nStr.split('.');x1 = z[0];x2 = z.length > 1 ? '.' + z[1] : '';var rgx = /(\d+)(\d{3})/;while (rgx.test(x1)) {x1 = x1.replace(rgx, '$1' + ',' + '$2');}return x1 + x2;}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+20)+"px";help_box.style.left = (field_left-10)+"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.z) curleft += obj.z;return curleft;}function findPosY(obj) {var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent) {curtop += obj.offsetTop;obj = obj.offsetParent;}} else if (obj.x) curtop += obj.x;return curtop;}
