var TodaysDate=new Date() var beloebMsg = 'Please input numbers only 0-9'; var verifyBoligPrisMsg = 'Loan amount must be between £10.000 and £100.000.000.'; var txt1 = 'Rate'; var txt2 = 'Loan duration (in years)'; var txt6 = 'Loan amount'; var txt7 = 'Calculate'; var txt11 = 'Calculated monthly repayment'; var txt12 = 'Calculated APR'; //Calculate functions function setfocus(){ if (navigator.appName == 'Netscape') { window.focus(); } } function getKeyCode(e){ var keynum var keychar var numcheck if(window.event) // IE { keynum = e.keyCode } else if(e.which) // Netscape/Firefox/Opera { keynum = e.which } //keychar = String.fromCharCode(keynum) return keynum } function verifyrange(tal, start, end, errormsg) { if ((tal < start) || (tal > end)) { alert(errormsg); return false; } return true; } function formatter(tal, decimaler) { var fudge = 0.0001; tal = parseFloat(tal+""); tal = tal * Math.pow(10,decimaler); tal = Math.round(tal); tal = tal / Math.pow(10,decimaler); tal = tal+fudge; var result = ""; var slutPotens = 0-decimaler; var potens = Math.floor(Math.log(tal) / Math.log(10)); if (potens < 0) potens = 0; while (potens >= slutPotens) { ciffer = Math.floor(tal / Math.pow(10,potens)); result = result + ciffer; if ((potens == 0) && (decimaler > 0)) result = result + "."; else if ((potens/3 == Math.floor(potens/3)) && (potens > 0)) result = result + "."; tal = tal - ciffer*Math.pow(10,potens); potens = potens-1; } return result; } function fjerntegn(tal, fjern) { var retval = ""; for (i=0; i= 0)) { lastnonws--; tegn = str.substring(lastnonws,lastnonws+1); } if (firstnonws > lastnonws) return ""; else return str.substring(firstnonws,lastnonws+1); } function parse2decimaler(tal, punktumok) { tal = trimws(tal); if (!punktumok && (tal.indexOf(".") != -1)) return null; tal = fjerntegn(tal, "."); var pos = tal.lastIndexOf(","); if (pos == -1) { if (characterCheck(tal, "n")) { return parseInt(tal,10); } else return null; } if (tal.indexOf(",") != tal.lastIndexOf(",")) return null; var cifreEfterKomma = tal.length - pos - 1; if (cifreEfterKomma > 2) { return null; } tal = fjerntegn(tal, ","); if (characterCheck(tal, "n")) { return (parseInt(tal,10) / Math.pow(10, cifreEfterKomma)); } else return null; } function characterCheck(str,type){ if((str == "") || (str == null)){ return false; } var validchars; if (type == "n"){ validchars = "0123456789"; } else if(type == "a") { validchars = "abcdefghijklmnopqrstuvwxyzæøå"; } for(j = 0; j < str.length; j++){ var ch = str.substring(j,j+1); if (validchars.indexOf(ch) == -1) { return false; } } return true; } function calcIntrest(nom){ i = (Math.pow((1+nom),(1/3)))-1; return i; } function retIntrest(nom){ i = ((Math.pow((nom+1),12))-1)*100; return i; } function retIntrestQuarter(nom){ i = ((Math.pow((nom+1),4))-1)*100; return i; } function vistabel(form) { var loebetid = form.loebetid.selectedIndex * 5 + 10; var rente = trimws(form.rente.value); rente = parse2decimaler(rente, false); if (rente == null) { alert(renteMsg); return; } var beloeb = trimws(form.BeloebOut.value); if (beloeb == "") { alert(nocalcMsg); return; } beloeb = parse2decimaler(beloeb, true); if (beloeb == null) { alert(beloebMsg); return; } var skattepct = trimws(form.skattepct.value); if(beloeb == "") { alert(skattepctMsg); return; } skattepct=parse2decimaler(skattepct,false); if(skattepct == null) { alert(skattepctMsg); return; } var tableurl = "/Link/AmortTable?openDocument&"; tableurl = tableurl + "skattepct="+skattepct+"&loebetid=" + loebetid + "&hovedstol=" + beloeb + "&rente=" + rente; window.location = location.protocol + '//' + location.host +tableurl; } //Calculate payments //function ydelsesforloeb(rente,loebetid,beloeb,fixrate,stdrate,brutto,bruttostd) { //årlig rente, løbetid i år, samlet beløb //var n = loebetid*12; //månedlige afdrag //var ydelse = brutto; //var ydelser = new Array(); //var m_rente = rente/12; //månedlig rente til tilskrivning af rente //var a_rente=0; //akkumuleret rente //var pris = 0; //var rest = beloeb; //var termin = 0; //while(rest > ydelse) { //if(fixrate>0 && termin == (fixrate*12)+1){ //var bruttostd = Calcpayment(rest, (n-termin)/12, stdrate); //bruttostd = "" + (bruttostd*100)/100 //var re = /\d*.\d\d/; //var arrValue = re.exec (bruttostd); //bruttostd = arrValue[0]; //bruttostd = Math.round(bruttostd*100)/100 //m_rente = stdrate/12; //ydelse = bruttostd //alert(bruttostd) //} //a_rente = a_rente + rest*(m_rente); //tilskriv rente // rest = rest - ydelse + a_rente; // ydelser[termin] = ydelse; //a_rente = 0; //termin = termin + 1; //} //a_rente = a_rente + rest*(m_rente); // rest = rest + a_rente; //ydelser[termin] = rest + 125; // return ydelser; //} function ydelsesforloeb(rente,loebetid,beloeb,brutto) { //årlig rente, løbetid i år, samlet beløb var n = 12*loebetid; //månedlige afdrag var m_rente = calcIntrest(rente/4); //månedlig rente til beregning af ydelse //var ydelse = ( m_rente / (1- Math.pow(1+m_rente,-n)))*beloeb; //ydelse = Math.ceil(ydelse); ComInt = (Math.pow((1+rente/4 ),(1/3))) - 1 ydelse = (beloeb*ComInt*(Math.pow((1+ComInt),(loebetid*12))))/((Math.pow((1+ComInt),(loebetid*12)))- 1) //ydelse = brutto var ydelser = new Array(); m_rente = rente/12; //månedlig rente til tilskrivning af rente var a_rente=0; //akkumuleret rente var pris = 0; var rest = beloeb; var termin = 0; while(rest > ydelse) { a_rente = a_rente + rest*(m_rente); if( (termin + 1) % 3 == 0) { //tilskriv rente //alert("Tilskriv! - Termin: " + termin+ " " + rest + " " + ydelse+ " " + a_rente); rest = rest - ydelse + a_rente; ydelser[termin] = ydelse; a_rente = 0; } else { //alert("Termin: " + termin+ " " + rest + " " + ydelse+ " " + a_rente); ydelser[termin] = ydelse; rest = rest - ydelse; } termin = termin + 1; } a_rente = a_rente + rest*(m_rente); rest = rest + a_rente; ydelser[termin] = rest+125; //alert(rest+125) return ydelser; } //Calculate APR function AOP(rente, loebetid, hovedstol,omkostninger,fixrate,stdrate,brutto) { var y = ydelsesforloeb(rente,loebetid,hovedstol,brutto); //binær søgning efter rente,r, så tilbagedisk(y,r,loebetid) = hovedstol var r1 = rente; var r2 = rente*2; var p1 = tilbagedisk(y,r1,loebetid); var p2 = tilbagedisk(y,r2,loebetid); while(p1 < (hovedstol-omkostninger)) { r1 = r1/2; p1 = tilbagedisk(y,r1,loebetid); } while(p2 > (hovedstol-omkostninger)) { r2 = r2*2; p2 = tilbagedisk(y,r2,loebetid); } var r = (r1 + r2)/2; var cont = true; while(cont) { r = (r1 + r2)/2; if(Math.round(tilbagedisk(y,r,loebetid)*1000000) == Math.round((hovedstol-omkostninger)*1000000)) cont = false; else { if(tilbagedisk(y,r,loebetid) < (hovedstol-omkostninger)) r2 = r; else r1 = r; } } //alert(r*100) return r*100; } function tilbagedisk(ydelsesforloeb, rente, loebetid) { //årlig rente, loebetid i år var n = 12*loebetid; //månedlige afdrag m_rente = (Math.pow((rente+1),(1/12)))-1; //alert('m_rente = ' + m_rente); var result = 0; //alert('ydelsesforloeb.length: ' + ydelsesforloeb.length); for(i = 0; i < ydelsesforloeb.length; i++) { //alert('i = ' + i); result = result + ydelsesforloeb[i]*Math.pow((1+m_rente),-(i+1)); //alert(ydelsesforloeb[i]*Math.pow((1+m_rente),-(i+1))); } return result; } //function Calcpayment(a, n, p){ //alert("a: " + a + " n: " + n + " p: " + p) //var acc=0; //n = n *12 // var base = 1 + p/12; // for (i=1;i<=n;i++) // { acc += Math.pow(base,-i); } // return a/acc; // //} function Calcpayment(a, n, p){ //alert("a: " + a + " n: " + n + " p: " + p) ComInt = (Math.pow((1+p/4 ),(1/3))) - 1 repay = (a*ComInt*(Math.pow((1+ComInt),(n*12))))/((Math.pow((1+ComInt),(n*12)))- 1) return repay; } function conv_number(expr, decplaces){ var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces)); while (str.length <= decplaces){ str = "0" + str; } var decpoint = str.length - decplaces; return (str.substring(0,decpoint) + "." + str.substring(decpoint,str.length)); } //Calculate mortgage loan function beregn(form,ad) { document.getElementById("resultavd").style.display = 'none'; var loebetid = parseInt(form.loebetidavd.value); var beloeb = parseInt(form.BeloebInavd.value); var PropValue = parseInt(form.PropValueavd.value); var exist = parseInt("0") //parseInt(form.ExistNBLoanavd.value); if(!PropValue || PropValue < 25000){ alert("Please enter a value of the property higher than €25000!") document.getElementById("lamtohighavd").innerHTML = '' document.getElementById("CalcCLTVavd").innerHTML = '0.00%' document.getElementById("PropValueavd").value = '' document.getElementById("PropValueavd").focus() return } if(!beloeb || beloeb < 10000){ alert("Loan amount must be £10000 or higher!") document.getElementById("lamtohighavd").innerHTML = '' document.getElementById("CalcCLTVavd").innerHTML = '0.00%' document.getElementById("BeloebInavd").value = '' document.getElementById("BeloebInavd").focus() return } if(!loebetid){ alert("Please enter a loan duration between 1 and 30 years!") document.getElementById("loebetidavd").value = '' document.getElementById("loebetidavd").focus() return } lammsgexist = ''; lamm = beloeb; if(exist > 0){ lamm = beloeb+exist lammsgexist = " and existing NB loan is £" + exist } if(lamm > (1*PropValue)){ if(exist > 0){maxlam = (1*PropValue)-exist; LTV = (exist/propval)*100} else {maxlam = (1*PropValue); LTV = 0} alert("Loan amount too high! Maximum LTV is 100%, maximum loan amount is £" + maxlam + " when property value is £" + PropValue + lammsgexist) document.getElementById("lamtohighavd").innerHTML = '' if(LTV > 100){ document.getElementById("lamtohighavd").innerHTML = "Too high! Max. 100% " } document.getElementById("CalcCLTVavd").innerHTML = formatter(LTV,2) + '%' document.getElementById("BeloebInavd").value = '' document.getElementById("BeloebInavd").focus() return } var re = /\d*.\d\d/; var fixrate = 0 var bruttostd = 0 var stdrate = parse2decimaler(standardrate, true) stdrate = stdrate/100 var fixedfee = parseInt(fixedfee) var arrfee = parseInt(arrangementfee) var MaxLTV = parseInt("1") var BaseRateECB = parse2decimaler(ECBBaseRate, true) //var Tier1 = parse2decimaler("0,75", true) //var Tier2 = parse2decimaler("0,94", true) //var Tier3 = parse2decimaler("1", true) //var Tier4 = parse2decimaler("1", true) var Margin1 = parse2decimaler("0,59", true) var Margin2 = parse2decimaler("0,99", true) var Margin3 = parse2decimaler("1,49", true) //var Margin4 = parse2decimaler("0,59", true) //var Band1 = PropValue*Tier1 //var Band2 = PropValue*Tier2 //var Band3 = PropValue*Tier3 //var Band4 = PropValue*Tier4 //var Band1Allowed = Band1 //var Band2Allowed = Band2-Band1 //var Band3Allowed = Band3-Band2 //var Band4Allowed = Band4-Band3 //var BandTotalAllowed = PropValue //var BandTotalBorrowing = exist+beloeb //var Band1Borrowing = Math.min(BandTotalBorrowing,Band1Allowed) //var Band2Borrowing = Math.min(BandTotalBorrowing-Band1Borrowing,Band2Allowed) //var Band3Borrowing = Math.min(BandTotalBorrowing-(Band1Borrowing+Band2Borrowing),Band3Allowed) //var Band4Borrowing = Math.min(BandTotalBorrowing-(Band1Borrowing+Band2Borrowing+Band3Borrowing),Band4Allowed) //var Band1Weight = Band1Borrowing/BandTotalBorrowing //var Band2Weight = Band2Borrowing/BandTotalBorrowing //var Band3Weight = Band3Borrowing/BandTotalBorrowing //var Band4Weight = Band4Borrowing/BandTotalBorrowing //var Band1Margin = Margin1*Band1Weight //var Band2Margin = Margin2*Band2Weight //var Band3Margin = Margin3*Band3Weight //var Band4Margin = Margin4*Band4Weight //var BandTotalMargin = Band1Margin+Band2Margin+Band3Margin //var ltvpropvalue = 0.8*PropValue //if(BandTotalBorrowing > ltvpropvalue){BandTotalMargin = Margin3;} ltvcalc =beloeb/PropValue if(ltvcalc<0.75){RateECB = BaseRateECB + Margin1;BandTotalMargin=Margin1;} if(ltvcalc>=0.75 && ltvcalc<0.95){RateECB = BaseRateECB + Margin2;BandTotalMargin=Margin2;} if(ltvcalc>=0.95){RateECB = BaseRateECB + Margin3;BandTotalMargin=Margin3;} //RateECB = BaseRateECB + BandTotalMargin var productrates = RateECB; pv = beloeb // hovedstol pmtloebetid = loebetid document.getElementById("ECBRefRate").innerHTML = formatter(BaseRateECB,2) + "%"; document.getElementById("ECBCustRate").innerHTML = formatter(productrates,2) + "%"; document.getElementById("ECBdiff").innerHTML = formatter(BandTotalMargin,2) + "%"; var rente = productrates rente = rente/100 var brutto; brutto = Calcpayment(beloeb, pmtloebetid, rente); //alert(brutto) brutto = "" + (brutto*100)/100 var arrValue = re.exec (brutto); brutto = arrValue[0]; //brutto = Math.round(brutto*100)/100 document.getElementById("ECBPmtavd").innerHTML = "£" + brutto; // beregn åop //alert(AOP(rente,pmtloebetid,pv,arrfee,fixrate,stdrate,brutto)) NewAPR = Math.round(AOP(rente,pmtloebetid,pv,arrfee,fixrate,stdrate,brutto)*10)/10 + "%"; document.getElementById("ECBAPRavd").innerHTML = NewAPR document.getElementById("resultavd").style.display = ''; } //Update fields function UpdateFields(Fid,event){ //alert(propertyvalue) wkey = getKeyCode(event) document.getElementById("resultavd").style.display = 'none'; chkcurval = document.getElementById(""+Fid).value if(wkey > 46){ if(!characterCheck(chkcurval,"n")){ alert(beloebMsg); document.getElementById(""+Fid).value = ''; document.getElementById(""+Fid).focus(); return; } } ad = "avd" existloan = 0; //existloan = parseInt(existloan) propval = document.getElementById("PropValueavd").value lam = document.getElementById("BeloebInavd").value //lam = parseInt(lam) if(propval != '' && propval > 0){ if(lam || existloan){calcLTV(propval,lam,existloan,ad,Fid)} } if(propval == ''){ document.getElementById("lamtohighavd").innerHTML = '' document.getElementById("CalcCLTVavd").innerHTML = '0.00%' } testdu = document.getElementById("loebetid"+ad).value if(testdu != '' && testdu < 1 || testdu > 30){ alert("Please enter a loan duration between 1 and 30 years") document.getElementById("loebetid"+ad).value = '' document.getElementById("loebetid"+ad).focus() return } } //CALC LTV function calcLTV(propval,lam,existloan,ad,Fid){ propval = parseInt(propval) if(lam){ lam = parseInt(lam) } if(existloan){ existloan = parseInt(existloan) } if(lam != '' && existloan != ''){lam = lam + existloan;} if(lam != '' && existloan == ''){lam = lam;} if(lam == '' && existloan != ''){lam = existloan;} //alert(lam) LTV = (lam/propval)*100 document.getElementById("lamtohighavd").innerHTML = '' if(LTV > 100){ document.getElementById("lamtohighavd").innerHTML = "Too high! Max. 100% " } document.getElementById("CalcCLTVavd").innerHTML = formatter(LTV,2) + '%' }