/*Programming: 	Human Element
				Gregg Milligan
				March 30, 2009
				
All functions specific to the remote cash capture (RCC) calculator end with '_RCC'.
All other functions are generic calculator functions and they come from CALC_FUNCTIONS.js*/		

//module level variables
var mRCC_LaborHrsPerDay;
var mRCC_HourlyRate;
var mRCC_DailyGrossSales;

var mRCC_TotalDailyLaborSavings;
var mRCC_DailyCashShrinkageSavings;
var mRCC_MonthlySavings;
var mRCC_AnnualSavings;

function calc_RCC()
{
	//set the focus indicator to none of the input fields
	fieldWithFocus = "-1";
	
	//if the form input is valid initialize the module level variables for calculation
	if (validate_RCC())
	{
		//get constant values (text box values)
		
		//calculations
		mRCC_TotalDailyLaborSavings = (mRCC_LaborHrsPerDay - 2) * mRCC_HourlyRate;
		mRCC_DailyCashShrinkageSavings = mRCC_DailyGrossSales * .015 * 0.4 * 0.25;
		mRCC_MonthlySavings = (mRCC_TotalDailyLaborSavings + mRCC_DailyCashShrinkageSavings) * 20;
		mRCC_AnnualSavings = mRCC_MonthlySavings * 12; 

		
		//round to the nearest 100th
		mRCC_TotalDailyLaborSavings = roundNumToNearestPlace(mRCC_TotalDailyLaborSavings,100);
		mRCC_DailyCashShrinkageSavings = roundNumToNearestPlace(mRCC_DailyCashShrinkageSavings,100);
		mRCC_MonthlySavings = roundNumToNearestPlace(mRCC_MonthlySavings,100);
		mRCC_AnnualSavings = roundNumToNearestPlace(mRCC_AnnualSavings,100);

		//display calculation results
		displayOutput_RCC();
	}
}

//make sure form values are valid before calculating
function validate_RCC()
{
		var valid = false;
		
		//get text box values
		var RCC_LaborHrsPerDay = document.getElementById('RCC_LaborHrsPerDay').value;
		var RCC_HourlyRate = document.getElementById('RCC_HourlyRate').value;
		var RCC_DailyGrossSales = document.getElementById('RCC_DailyGrossSales').value;
		
		//trim leading spaces
		RCC_LaborHrsPerDay = RCC_LaborHrsPerDay.trim();
		RCC_HourlyRate = RCC_HourlyRate.trim();
		RCC_DailyGrossSales = RCC_DailyGrossSales.trim();
		
		//validate
		if (validIfNumber('RCC_LaborHrsPerDay'))
		{			
			//validate
			if (validIfNumber('RCC_HourlyRate'))
			{
				//validate
				if (validIfNumber('RCC_DailyGrossSales'))
				{
					//the form values have passed the validation tests
					valid = true;
		
					//set the input values
					mRCC_LaborHrsPerDay = RCC_LaborHrsPerDay;
					mRCC_HourlyRate = RCC_HourlyRate;
					mRCC_DailyGrossSales = RCC_DailyGrossSales;
				}
			}
		}
		
		if (!valid)
		{
			clearOutput_RCC();
		}
		
		return valid;
}

function clearOutput_RCC()
{
	//make sure the output is clear of previous results 
	document.getElementById('RCC_TotalDailyLaborSavings').innerHTML = "";
	document.getElementById('RCC_DailyCashShrinkageSavings').innerHTML = "";
	document.getElementById('RCC_MonthlySavings').innerHTML = "";
	document.getElementById('RCC_AnnualSavings').innerHTML = "";		
}

function displayOutput_RCC()
{
	document.getElementById('RCC_TotalDailyLaborSavings').innerHTML = '<strong>$' + mRCC_TotalDailyLaborSavings + '</strong>';
	document.getElementById('RCC_DailyCashShrinkageSavings').innerHTML = '<strong>$' + mRCC_DailyCashShrinkageSavings + '</strong>';
	document.getElementById('RCC_MonthlySavings').innerHTML = '<strong>$' + mRCC_MonthlySavings + '</strong>';
	document.getElementById('RCC_AnnualSavings').innerHTML = '<strong>$' + mRCC_AnnualSavings + '</strong>';
}

//clear all non-static fields
function clearAll_RCC()
{		
		//clear input fields
		document.getElementById('RCC_LaborHrsPerDay').value = "";
		document.getElementById('RCC_HourlyRate').value = "";
		document.getElementById('RCC_DailyGrossSales').value = "";
		
		//clear output fields
		document.getElementById('RCC_TotalDailyLaborSavings').innerHTML = "";
		document.getElementById('RCC_DailyCashShrinkageSavings').innerHTML = "";
		document.getElementById('RCC_MonthlySavings').innerHTML = "";
		document.getElementById('RCC_AnnualSavings').innerHTML = "";

		//clear error messages
		document.getElementById('RCC_LaborHrsPerDay_err').style.display = "none";
		document.getElementById('RCC_HourlyRate_err').style.display = "none";
		document.getElementById('RCC_DailyGrossSales_err').style.display = "none";

		//reset the focus to the first input field
		document.getElementById('RCC_LaborHrsPerDay').focus();
}


