// Create Figures for IFC Calculator

totalprice = 0;
totalmonthly12 = 0;
totalmonthly18 = 0;
totalmonthly24 = 0;
totalmonthly36 = 0;
totalmonthly48 = 0;
totalmonthly2_12 = 0;
totalmonthly2_18 = 0;
totalmonthly2_24 = 0;
totalmonthly2_36 = 0;
totalmonthly2_48 = 0;
deposit = 0;

function fcalc(price){
if (!(price)) price = 0;

if (price > 490) deposit = fixDP(price/10,2);
else deposit = fixDP(49,0);

totalprice = price-deposit;
totalmonthly12 = fixDP(totalprice/12,0);
totalmonthly18 = fixDP(totalprice/18,0);
totalmonthly24 = fixDP(totalprice/24,0);
totalmonthly36 = fixDP(totalprice/36,0);
totalmonthly48 = fixDP(totalprice/48,0);
totalmonthly2_12 = fixDP(totalprice/12,0);
totalmonthly2_18 = fixDP(totalprice/18,0);
totalmonthly2_24 = fixDP(totalprice/24,0);
totalmonthly2_36 = fixDP(totalprice/36,0);
totalmonthly2_48 = fixDP(totalprice/48,0);
totalprice = price;
}

function fixDP(n,p){ // p=0 no rounding - p=2 with rounding
var integer = Math.floor(n);
if (p == 0) var dec = Math.floor((n - integer )*100);
else var dec = Math.round(((n - integer )*100));
var decStr = dec + '';
if (decStr.length == 1) {decStr = '0' + dec;}
var result = integer + '.' + decStr;
return result;
}
