
// Lump Sum Investment Calculation Script


function LSCalculate(inputForm)
{
	var charges = inputForm.charges.value - 0;
	var amount = inputForm.amount.value;
	var yield = inputForm.yield.value - 0;
	var period = inputForm.period.value - 0;
	var tmp;
	
	amount = amount.replace(/\,/g,"");
	amount = amount - 0;
	
	yield = yield / 100;
	
	if(charges == 0)
	{
		// No charges so calculate interest annually.
		
		tmp = Math.pow(1 + yield, period);
		tmp = tmp * amount;
		tmp = Math.round(tmp);
		
		document.getElementById('resultbox').style.visibility = 'visible';
		document.getElementById('resulttxt').innerHTML = "<strong>The expected return is £" + tmp + "</strong><br/>* This calculation is based upon annualised compound interest.  It does not take into account and fees or charges that are associated with certain types of investment.";
		
	}
	else
	{
		// Charges apply so therefore we must calculate everything daily.
		
		var i,j;
		var totalRet = amount;
		var chargeToday, intToday;
		
		var dailyInt = Math.pow(1 + yield, 1/365) - 1;
		var dailyCharge = charges / 36500;		
		
		for(i = 1; i <= period; i++)
		{
			for(j = 1; j <= 365; j++)
			{
				totalRet += dailyInt * totalRet;
				totalRet -= dailyCharge * totalRet;
			}
		}
		
		document.getElementById('resultbox').style.visibility = 'visible';
		document.getElementById('resulttxt').innerHTML = "<strong>The expected return is £" + Math.round(totalRet) + "</strong><br/>* Interest and charges have been calculated daily";
		
	}
}
