// JavaScript Document


function calculator ()
{
	var amount = document.getElementById ('amount').value;
	var percent = document.getElementById ('percent').value;
	var year = document.getElementById ('years').value;
	var result = document.getElementById ('result');


	if(!validateNumeric( removeCommas(amount)))
		{
			alert ('Please enter a numerical value\nfor Amount of Income desired');
		}
	else
	if(!validateNumeric( removeCommas(percent)))
		{
			alert ('Please enter a numerical value\nfor Assumed rate of return on insurance proceeds');
		}
	else
	if(!validateNumeric( removeCommas(year)))
		{
			alert ('Please enter a numerical value\nfor Number of years survivors will need this income');
		}
	else
		{
		amount = removeCommas(amount);
		
		var percentOne = 1 + (percent/100);
		var income = amount;
		var vznos;
		var vznosAll = 0;
		
		for (i=1; i<=year; i++)
			{
			vznos = income/percentOne;
			vznosAll = vznosAll + vznos;
			income = vznos;
			}
			
		vznosAll = Math.round(vznosAll*100)/100;
		vznosAll = vznosAll.toString();
		
		result.value = "Sum needed from insurance proceeds: $ " + addCommas(vznosAll);
		}
}
