
// Regular Savings Calculator


function MSCalculate(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;

	var i,j,k;
	var totalRet = 0;
	var chargeToday, intToday;
 	var periodInt;
 	var periodCharge;
		
	if(charges == 0)
	{
		// No charges so calculate interest monthly.
		
		periodInt = Math.pow(1 + yield, 1/12) - 1;
		periodCharge = charges / 1200;
		
		for(i = 1; i <= period; i++)
		{
			for(j = 0; j < 12; j++)
			{
				totalRet += amount;
			
				totalRet += periodInt * totalRet;
				totalRet -= periodCharge * totalRet;
			}
		}
		
		document.getElementById('resultbox2').style.visibility = 'visible';
		document.getElementById('resulttxt2').innerHTML = "<strong>The expected return is £" + Math.round(totalRet) + "</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.
				
		periodInt = Math.pow(1 + yield, 1/365) - 1;
		periodCharge = charges / 36500;
		var months = new Array (31,28,31,30,31,30,31,31,30,31,30,31);

		for(i = 1; i <= period; i++)
		{
			for(j = 0; j < 12; j++)
			{
				totalRet += amount;
			
				for(k = 1; k <= months[j]; k++)
				{
					totalRet += periodInt * totalRet;
					totalRet -= periodCharge * totalRet;
				}
			}
		}
		
		document.getElementById('resultbox2').style.visibility = 'visible';
		document.getElementById('resulttxt2').innerHTML = "<strong>The expected return is £" + Math.round(totalRet) + "</strong><br/>* Interest and charges have been calculated daily.";
		
		
		
	}
}
