/*Programming: 	Human Element
				Gregg Milligan
				March 26, 2009
				
All functions specific to the remote deposite capture (RDC) calculator end with '_RDC'.
All other functions are generic calculator functions and they come from CALC_FUNCTIONS.js*/		

//module level variables
var mDeptPerWeek;
var mMilesToBank;
var mDepositorsTimePerHour;
var mGasPrice;
var mTimeAtBank;

var mWeeklySavings;
var mYearlySavings;

var fieldWithFocus;

function calc_RDC()
{
	//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_RDC())
	{
		/*//get constant values (text box values)
		var AVG_SPEED = document.getElementById('avgSpeed').innerHTML;
		var AVG_MPG = document.getElementById('avgMPG').innerHTML;
		var MONTHLY_COST_FOR_RDC_SERVICE = document.getElementById('monthlyRDCServiceCost').innerHTML;*/
		
		//get constant values (text box values)
		var AVG_SPEED = 30;
		var AVG_MPG = 18;
		var MONTHLY_COST_FOR_RDC_SERVICE = 50;
		
		//calculate weekly savings
		mWeeklySavings = (((((mMilesToBank * 2) / AVG_SPEED) * mDepositorsTimePerHour) + (mTimeAtBank / 60 * mDepositorsTimePerHour) + ((mMilesToBank * 2) / AVG_MPG * mGasPrice)) * mDeptPerWeek) - (MONTHLY_COST_FOR_RDC_SERVICE * 12/52);
		
		//calculate yearly savings
		mYearlySavings = mWeeklySavings * 52;
		
		//round to the nearest 100th
		mWeeklySavings = roundNumToNearestPlace(mWeeklySavings,100);
		mYearlySavings = roundNumToNearestPlace(mYearlySavings,100);
		
		//display calculation results
		displayOutput_RDC();
	}
}

//make sure form values are valid before calculating
function validate_RDC()
{
		var valid = false;
		
		//get text box values
		var deptPerWeek = document.getElementById('deptPerWeek').value;
		var milesToBank = document.getElementById('milesToBank').value;
		var depositorsTimePerHour = document.getElementById('depositorsTimePerHour').value;
		var gasPrice = document.getElementById('gasPrice').value;
		var timeAtBank = document.getElementById('timeAtBank').value;
		
		//trim leading spaces
		deptPerWeek = deptPerWeek.trim();
		milesToBank = milesToBank.trim();
		depositorsTimePerHour = depositorsTimePerHour.trim();
		gasPrice = gasPrice.trim();
		timeAtBank = timeAtBank.trim();
		
		//validate
		if (validIfInteger('deptPerWeek'))
		{			
			//validate
			if (validIfNumber('milesToBank'))
			{
				//validate
				if (validIfNumber('depositorsTimePerHour'))
				{
					//validate
					if (validIfNumber('gasPrice'))
					{
						//validate
						if (validIfNumber('timeAtBank'))
						{							
							//the form values have passed the validation tests
							valid = true;
		
							//set the input values
							mDeptPerWeek = deptPerWeek;
							mMilesToBank = milesToBank;
							mDepositorsTimePerHour = depositorsTimePerHour;
							mGasPrice = gasPrice;
							mTimeAtBank = timeAtBank;
						}
					}
				}
			}
		}
		
		if (!valid)
		{
			clearOutput_RDC();
		}
		
		return valid;
}

function clearOutput_RDC()
{
	//make sure the output is clear of previous results 
	document.getElementById('weeklySavings').innerHTML = "";
	document.getElementById('yearlySavings').innerHTML = "";		
}

function displayOutput_RDC()
{
	document.getElementById('weeklySavings').innerHTML = '<strong>$' + mWeeklySavings + '</strong>';
	document.getElementById('yearlySavings').innerHTML = '<strong>$' + mYearlySavings + '</strong>';
}

//clear all non-static fields
function clearAll_RDC()
{		
		//clear input fields
		document.getElementById('deptPerWeek').value = "";
		document.getElementById('milesToBank').value = "";
		document.getElementById('depositorsTimePerHour').value = "";
		document.getElementById('gasPrice').value = "";
		document.getElementById('timeAtBank').value = "";
		
		//clear output fields
		document.getElementById('weeklySavings').innerHTML = "";
		document.getElementById('yearlySavings').innerHTML = "";

		//clear error messages
		document.getElementById('deptPerWeek_err').style.display = "none";
		document.getElementById('milesToBank_err').style.display = "none";
		document.getElementById('depositorsTimePerHour_err').style.display = "none";
		document.getElementById('gasPrice_err').style.display = "none";
		document.getElementById('timeAtBank_err').style.display = "none";

		//reset the focus to the first input field
		document.getElementById('deptPerWeek').focus();
}


