/************************************************************************************************************
(C) Budco Health Services Solutions, January 2008

Author: David LeDuc (www.pillartechnology.com) 

Terms of use:
This script is property of Budco Health Service Solutions. This script may not be used without permission from Budco Health Service Soutions. This script is copyright with all rights reserved. You may not redistribute, sell or repost it without our permission.

Budco Health Service Solutions

************************************************************************************************************/


function calculate() {
	//input fields:
	numDep = parseInt(document.savingsCalculator.numDep.value);
	depCost = parseInt(document.savingsCalculator.depCost.value);
	attrition = parseInt(document.savingsCalculator.attrition.value) /100;
	inflation = parseInt(document.savingsCalculator.inflation.value) / 10;
	inel = parseInt(document.savingsCalculator.inel.value) /100;

	////Calculate Ineligible dependents
	if (numDep && inel) {
		var numberIneligibleDependents = Math.round( (numDep * inel));
		writit(  addCommas( numberIneligibleDependents) , 'ineligibleDependents' );
	}
	else {
		writit('','ineligibleDependents');
		var numberIneligibleDependents = 0;
	}
	

	
	////calculate year 1 savings average cost per dependent	
	if (depCost) {
		if (inflation){
	  		writit('$' +  addCommas(  Math.round((depCost * (inflation * .05))) + depCost  ), '0615');
			var depsavingsone = Math.round((depCost * (inflation * .05))) + depCost;
		}
		else {
			writit(addCommas(depCost), '0615');
			var depsavingsone = depCost;
		}
	}
	else writit('','0615'); //clear the field is no required values


	////calculate year 2 savings average cost per dependent	
	if (depCost) {
		if (inflation){
	  		writit('$' + addCommas(  Math.round( (Math.round((depCost * (inflation * .05))) + depCost) * (1 + inflation *.05))  ), '0715');
			var depsavingstwo = Math.round( (Math.round((depCost * (inflation * .05))) + depCost) * (1 + inflation *.05));
		}
		else {
			writit(addCommas(  depCost  ), '0715');
			var depsavingstwo = depCost;			
		}
	}
	else writit('','0715'); //clear the field is no required values


	////calculate year 3 savings average cost per dependent	
	if (depCost) {
		if (inflation){
			var year2Value = Math.round(  (Math.round(  (depCost * (inflation * .05))  ) + depCost) * (1 + inflation *.05));
	  		writit('$' +  addCommas(  Math.round(year2Value  * (1 + inflation *.05))  ), '0815');
			var depsavingsthree = Math.round(year2Value  * (1 + inflation *.05));
		}
		else {
			writit(addCommas(  depCost  ), '0815');
			var depsavingsthree = depCost;
		}
	}
	else writit('','0815'); //clear the field is no required values


	////calculate year 4 savings average cost per dependent	
	if (depCost) {
		if (inflation){
			var year3Value = Math.round(year2Value  * (1 + inflation *.05));
	  		writit('$' + addCommas(   Math.round(year3Value  * (1 + inflation *.05))  ), '0915');
			var depsavingsfour = Math.round(year3Value  * (1 + inflation *.05));
		}
		else {
			writit(addCommas(  depCost  ), '0915');
			var depsavingsfour = depCost;
		}
	}
	else writit('','0915'); //clear the field is no required values


	////calculate year 5 savings average cost per dependent	
	if (depCost) {
		if (inflation){
			var year4Value = Math.round(year3Value  * (1 + inflation *.05));
	  		writit('$' + addCommas(   Math.round(year4Value  * (1 + inflation *.05))  ), '1015');
			var depsavingsfive = Math.round(year4Value  * (1 + inflation *.05));
		}
		else {
			writit(addCommas(  depCost  ), '1015');
			var depsavingsfive = depCost;
		}
	}
	else writit('','1015'); //clear the field is no required values




	////calcualte Annual Savings Year 1
	if (numberIneligibleDependents && depsavingsone) {
		var annualSavingsOne = ( (numberIneligibleDependents * depsavingsone) +  Math.round((((numDep * attrition) * inel))*depsavingsone));
		writit(addCommas( '$' + annualSavingsOne ), '0604');
		
	}
	else writit('', '0604');

	////calcualte Annual Savings Year 2
	if (numberIneligibleDependents && depsavingstwo) {
		var annualSavingsTwo = ( (numberIneligibleDependents * depsavingstwo) +  Math.round((((numDep * attrition) * inel))*depsavingstwo));
		writit(addCommas( '$' +  annualSavingsTwo ), '0605');
	}
	else writit('', '0605');


	////calcualte Annual Savings Year 3
	if (numberIneligibleDependents && depsavingsthree) {
		var annualSavingsThree = ( (numberIneligibleDependents * depsavingsthree) +  Math.round((((numDep * attrition) * inel))*depsavingsthree));
		writit(addCommas( '$' + annualSavingsThree ), '0606');
	}
	else writit('', '0606');


	////calcualte Annual Savings Year 4
	if (numberIneligibleDependents && depsavingsfour) {
		var annualSavingsFour = ( (numberIneligibleDependents * depsavingsfour) +  Math.round((((numDep * attrition) * inel))*depsavingsfour));
		writit(addCommas( '$' + annualSavingsFour ), '0607');
	}
	else writit('', '0607');


	////calcualte Annual Savings Year 5
	if (numberIneligibleDependents && depsavingsfive) {
		var annualSavingsFive = ( (numberIneligibleDependents * depsavingsfive) +  Math.round((((numDep * attrition) * inel))*depsavingsfive));
		writit(addCommas( '$' + annualSavingsFive ), '0608');
	}
	else writit('', '0608');


	////calcualte total 5 year Savings
	if (annualSavingsOne) {
		theTotalSavings = addCommas( annualSavingsOne + annualSavingsTwo + annualSavingsThree + annualSavingsFour + annualSavingsFive );
		writit('$' + theTotalSavings, '1104');
	}
	else writit('', '1104');

}
