// JavaScript Document

function safetyrewards()
{
	var num_lost_current = parseInt(document.getElementById('annual_lostworkdays_current').value);
	var num_lost_goal = parseInt(document.getElementById('annual_lostworkdays_goal').value);
	var total_lostdays_current = parseInt(document.getElementById('totallostdays_current').value);
	var total_lostdays_goal = parseInt(document.getElementById('totallostdays_goal').value);
	var error = 0;

	if( isNaN(num_lost_current) )
	{
		alert("Please provide the annual number of lost work day cases.");
		document.getElementById('annual_lostworkdays_current').focus();
		error = 1;
	}
	else if( isNaN(num_lost_goal) )
	{
		alert("Please provide the annual number of lost work day cases.(Goal)");
		document.getElementById('annual_lostworkdays_goal').focus();
		error = 1;
	}
	else if( isNaN(total_lostdays_current) )
	{
		alert("Please provide the total number of days lost to accidents.");
		document.getElementById('totallostdays_current').focus();
		error = 1;
	}
	else if( isNaN(total_lostdays_goal) )
	{
		alert("Please provide the total number of days lost to accidents.(Goal)");
		document.getElementById('totallostdays_goal').focus();
		error = 1;
	}

	if( !error )
	{
		var costofinjury_current = 0;
		var costofinjury_goal = 0;
		var costofdays_current = 0;
		var costofdays_goal = 0;
		var totalcost_accidents_current = 0;
		var totalcost_accidents_goal = 0;
		var savings_fromcurrent = 0;

		if( (num_lost_current > 0) )
		{
			costofinjury_current = (num_lost_current) * 14000;
		}
		
		if( (num_lost_goal > 0) )
		{
			costofinjury_goal = (num_lost_goal) * 14000;
		}
		
		if( (total_lostdays_current > 0) )
		{
			costofdays_current = (total_lostdays_current) * 14000;
		}
		
		if( (total_lostdays_goal > 0) )
		{
			costofdays_goal = (total_lostdays_goal) * 14000;
		}
		
		totalcost_accidents_current = (costofinjury_current + (costofdays_current) );
		totalcost_accidents_goal = (costofinjury_goal + (costofdays_goal) );

		document.getElementById('costofinjury_current').innerHTML=costofinjury_current.toFixed(0);
		document.getElementById('costofinjury_goal').innerHTML=costofinjury_goal.toFixed(0);
		
		document.getElementById('costofdays_current').innerHTML=costofdays_current.toFixed(0);
		document.getElementById('costofdays_goal').innerHTML=costofdays_goal.toFixed(0);
		
		document.getElementById('totalcost_accidents_current').innerHTML=totalcost_accidents_current.toFixed(0);
		document.getElementById('totalcost_accidents_goal').innerHTML=totalcost_accidents_goal.toFixed(0);
		
		savings_fromcurrent = (totalcost_accidents_current - (totalcost_accidents_goal) );
		document.getElementById('savingsfromcurrently').innerHTML=savings_fromcurrent.toFixed(0);	
	}
}
