function svea_reload_calculator(){var containers=document.getElementsByClassName('svea_calculator');var monthly_data=[{"id":105,"shop_id":16,"months":3,"price_limit":2000,"price_interest":19.95,"price_open":5,"price_monthly":0,"month_active":!0,"month_label":"","month_payments":0,"campaign_code":null,"start_limit":50,"payment_info":"Marinea laskulla 30 p\u00e4iv\u00e4\u00e4 kulutonta ja korotonta maksuaikaa!"},{"id":106,"shop_id":16,"months":6,"price_limit":2000,"price_interest":19.95,"price_open":5,"price_monthly":0,"month_active":!0,"month_label":"","month_payments":0,"campaign_code":null,"start_limit":50},{"id":108,"shop_id":16,"months":12,"price_limit":2000,"price_interest":19.95,"price_open":5,"price_monthly":0,"month_active":!0,"month_label":"","month_payments":0,"campaign_code":null,"start_limit":50},{"id":110,"shop_id":16,"months":24,"price_limit":2000,"price_interest":19.95,"price_open":5,"price_monthly":0,"month_active":!0,"month_label":"","month_payments":0,"campaign_code":null,"start_limit":100},{"id":111,"shop_id":16,"months":36,"price_limit":2000,"price_interest":19.95,"price_open":5,"price_monthly":0,"month_active":!0,"month_label":"","month_payments":0,"campaign_code":null,"start_limit":100}];var payment_info='';if(monthly_data[0].payment_info!=undefined){payment_info=monthly_data[0].payment_info;delete monthly_data[0].payment_info} if(monthly_data.length<=0){return} var load_css=containers[0].dataset.css;if(load_css!='false'){var css_link=document.createElement("link");css_link.setAttribute("rel","stylesheet");css_link.setAttribute("type","text/css");css_link.setAttribute("href","https:\/\/palvelut.svea.com\/eramaksulaskuri\/css\/svea20171221.css");document.head.appendChild(css_link)} for(var e=0;eprice&&monthly_data[i].start_limit!=0){continue} if(!monthly_data[i].month_active){continue} var monthly_price_limit=parseFloat(monthly_data[i].price_limit)||0;if(price>monthly_price_limit){continue} if(monthly_data[i].month_payments==0){monthly_data[i].month_payments=monthly_data[i].months} var monthly_payment=myTotMonthlyPayment(price,monthly_data[i].price_interest,monthly_data[i].month_payments,monthly_data[i].price_monthly,monthly_data[i].price_open) var total_loan_costs=monthly_payment*monthly_data[i].month_payments+monthly_data[i].price_open;var credit_costs=total_loan_costs-price;var arp=calculateAPR(price,monthly_data[i].month_payments,monthly_payment,monthly_data[i].price_open);var element=document.createElement('div');element.className='svea_month_data';var interest_text='Korko: '+monthly_data[i].price_interest.toFixed(2)+' % | Avausmaksu: '+monthly_data[i].price_open.toFixed(2)+' € | ';interest_text+='Kuukausimaksu: '+monthly_data[i].price_monthly.toFixed(2)+' € | Tod. vuosikorko: '+arp.toFixed(2)+' % | ';interest_text+='Luottokustannukset yht.: '+credit_costs.toFixed(2)+' € ';var total_sum=parseFloat(price)+credit_costs;interest_text+='Kokonaiskustannukset: '+total_sum.toFixed(2)+' €';element.innerHTML='';if(monthly_data[i].month_label.length>0){element.innerHTML+='
'+monthly_data[i].month_label+'
'} if(monthly_data[i].month_payments==1){element.innerHTML+='
'+monthly_payment.toFixed(2)+' €
'}else{element.innerHTML+='
'+monthly_payment.toFixed(2)+' €/kk
'} element.innerHTML+='
'+monthly_data[i].months+' kk maksuajalla
';element.innerHTML+='
'+interest_text+'
';parent_element.appendChild(element);parent_element.appendChild(document.createTextNode(" "));if(lowest_monthly===!1){lowest_monthly=monthly_payment} var lowest_text='';if(monthly_payment<=lowest_monthly){lowest_monthly=monthly_payment;lowest_id=i;lowest=!0;lowest_text=' Alk. '} if(lowest){lowest_html='
';lowest_html+=element.innerHTML;lowest_html+='
'} iteration++} if(lowest_html!=''){var lelement=document.createElement('div');lelement.className='svea_starting_price_container';lelement.innerHTML=lowest_html;container.appendChild(lelement);container.appendChild(parent_element);var lowest_container=document.getElementsByClassName('svea_'+lowest_id);if(lowest_container[0]!=undefined){lowest_container[0].innerText=lowest_text+lowest_container[0].innerText}} if(iteration==0){lowest_html='
';lowest_html+='
'+payment_info+'
';lowest_html+='
';container_html='
'+payment_info+'
';var lelement=document.createElement('div');lelement.className='svea_starting_price_container';lelement.innerHTML=lowest_html;container.appendChild(lelement);var conelement=document.createElement('div');conelement.className='svea_container';conelement.innerHTML=container_html;container.appendChild(conelement)}}} function myTotMonthlyPayment(sloan_amount,srate,snumpayments,smonthly_costs,sstarting_fee){var loan_amount=parseFloat(sloan_amount);var rate=parseFloat(srate);var numpayments=parseInt(snumpayments);var monthly_costs=smonthly_costs;var starting_fee=sstarting_fee;if(rate==0){rate=0.00000001} var decimal_rate=1+(rate/12/100);var calc_numpayments=numpayments+1;var nominator=(loan_amount)*(Math.pow(decimal_rate,numpayments)-(Math.pow(decimal_rate,calc_numpayments)));var denominator=1-Math.pow(decimal_rate,numpayments);var monthly_payment=nominator/denominator+monthly_costs;return monthly_payment} function calculateAPR(loanAmount,numPayments,monthlyPayment,startingFee){var firstPayment=1*monthlyPayment+1*startingFee;var error_limit=0.01;var infinite=1000;var diff=0.1;var curr_i=100;var min=0;var max=10000;while(diff>error_limit&&infinite){infinite--;var inner=1+curr_i;var f1=firstPayment/Math.pow(inner,1/12);var numer_left=Math.pow(inner,-2/12);var numer_power=(-1*numPayments-1)/12;var numer_right=Math.pow(inner,numer_power);var numerator=numer_left-numer_right;var nominator=1-Math.pow(inner,-1/12);var fn=monthlyPayment*numerator/nominator;var result=f1+fn;diff=Math.abs(result-loanAmount);if(diff