// JavaScript Document
function fmt (num) {
	num = num.toString().replace(/\$|\,/g,'');
	
  if(isNaN(num))
  	num = "0";

	sign = (num == (num = Math.abs(num)));
	
	num = Math.round(num*100+0.50000000001);
	cents = num%100;
	num = Math.round(num/100).toString();
	
  if(cents < 10)
  	cents = "0" + cents;
	
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  	num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
 	return (((sign)?'':'-') + '$' + num);
}

function fmthours (num) {
  if(isNaN(num))
  	num = "0";

	
	return num.toFixed(0);
}

function CalcProductivity() {
  var DailySavings = document.productivity.employees.value * document.productivity.hourlywage.value * (document.productivity.timesaving.value);
  var HoursSaved = document.productivity.employees.value * (document.productivity.timesaving.value);

  document.productivity.HiddenMonthly.value = DailySavings * 22;
 
 document.productivity.HoursDaily.value = fmthours(HoursSaved);
  document.getElementById("divProdHoursDaily").innerHTML = fmthours(HoursSaved);
  document.productivity.HoursMonthly.value = fmthours(HoursSaved * 22);
  document.getElementById("divProdHoursMonthly").innerHTML = fmthours(HoursSaved * 22);
  document.productivity.HoursYearly.value = fmthours(HoursSaved *22*12);
  document.getElementById("divProdHoursYearly").innerHTML = fmthours(HoursSaved *22*12);
  document.productivity.HoursMonthly.value = fmthours(HoursSaved * 22);
  document.getElementById("divProdHoursMonthly2").innerHTML = fmthours(HoursSaved * 22);
  document.productivity.HoursYearly.value = fmthours(HoursSaved *22*12);
  document.getElementById("divProdHoursYearly2").innerHTML = fmthours(HoursSaved *22*12);
  document.productivity.Daily.value = fmt(DailySavings);
  document.getElementById("divProdDaily").innerHTML = fmt(DailySavings);
  document.productivity.Monthly.value = fmt(DailySavings * 22);
  document.getElementById("divProdMonthly").innerHTML = fmt(DailySavings * 22);
  document.productivity.Yearly.value = fmt(DailySavings*22*12);
  document.getElementById("divProdYearly").innerHTML = fmt(DailySavings*22*12);
 
   //print form variables
  //document.printform.prod_employees.value = document.productivity.employees.value;
  //document.printform.prod_hourlywage.value = document.productivity.hourlywage.value;
  //document.printform.prod_timesaving.value = document.productivity.timesaving.value;
  //document.printform.prod_HoursDaily.value = document.productivity.HoursDaily.value;
  //document.printform.prod_HoursMonthly.value = document.productivity.HoursMonthly.value;
  //document.printform.prod_HoursYearly.value = document.productivity.HoursYearly.value;
  //document.printform.prod_Monthly.value = document.productivity.Monthly.value;
  //document.printform.prod_Yearly.value = document.productivity.Yearly.value;
  //document.printform.prod_Daily.value = fmt(DailySavings);
  //document.printform.totalhourlywages.value = document.productivity.hourlywage.value;
  //document.printform.totalsavedhours.value = DailySavings * 22/document.productivity.hourlywage.value;
//  alert(document.productivity.HiddenMonthly.value);
}

function CalcLostRevenue() {
  document.lostrevenue.HiddenMonthly.value = document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value;
  document.lostrevenue.HoursMonthly.value = document.getElementById("divProdHoursMonthly2").innerHTML;
  document.lostrevenue.HoursYearly.value = document.getElementById("divProdHoursYearly2").innerHTML;
  document.lostrevenue.LostRevenueDaily.value = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value/22);
  document.getElementById("divProdLostRevenueDaily").innerHTML = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value/22);
  document.lostrevenue.LostRevenueMonthly.value = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value);
  document.getElementById("divProdLostRevenueMonthly").innerHTML = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value);
  document.lostrevenue.LostRevenueYearly.value = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursYearly.value);
  document.getElementById("divProdLostRevenueYearly").innerHTML = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursYearly.value);
  
  //print form variables
  //document.printform.lostrevenue_estimatedhourlyrevenue.value = document.lostrevenue.estimatedhourlyrevenue.value;
  //document.printform.lostrevenue_HoursMonthly.value = document.lostrevenue.HoursMonthly.value;
  //document.printform.lostrevenue_HoursYearly.value = document.lostrevenue.HoursYearly.value;
  //document.printform.lostrevenue_LostRevenueMonthly.value = document.lostrevenue.LostRevenueMonthly.value;
  //document.printform.lostrevenue_LostRevenueYearly.value = document.lostrevenue.LostRevenueYearly.value;
  //document.printform.lostrevenue_LostRevenueDaily.value = fmt(document.lostrevenue.estimatedhourlyrevenue.value * document.lostrevenue.HoursMonthly.value/22);
  // alert(document.lostrevenue.HiddenMonthly.value);
}

function CalcVehProductivity() {
  var DailySavings = document.vehproductivity.employees.value * document.vehproductivity.hourlyrevenue.value * document.vehproductivity.vppercentagerevenue.value;
  
  document.vehproductivity.HiddenMonthly.value = DailySavings * 22;
  
  document.vehproductivity.TimeSaved.value = fmt(DailySavings);
  document.vehproductivity.TimeSavedm.value = fmt(DailySavings * 22);
  document.vehproductivity.TimeSavedy.value = fmt(DailySavings * 22*12);
  document.getElementById("divProdTimeSaved").innerHTML = fmt(DailySavings);
  document.getElementById("divProdTimeSaved-m").innerHTML = fmt(DailySavings*22);
  document.getElementById("divProdTimeSaved-y").innerHTML = fmt(DailySavings*22*12);
  //print form variables
  //document.printform.vp_employees.value = document.vehproductivity.employees.value;
  //document.printform.vp_hourlyrevenue.value = document.vehproductivity.hourlyrevenue.value;
  //document.printform.vp_TimeSaved.value = document.vehproductivity.TimeSaved.value;
  //document.printform.vp_TimeSaved_m.value = fmt(DailySavings*22);
  //document.printform.vp_TimeSaved_y.value = fmt(DailySavings*22*12);
//alert(document.vehproductivity.HiddenMonthly.value);
}

function CalcSideJobs() {
  var MonthlySavings = document.sidejobs.monthlyrevenue.value * document.sidejobs.moonlighting.value;

  document.sidejobs.HiddenMonthly.value = MonthlySavings;
  document.sidejobs.Monthly.value = fmt(MonthlySavings);
   document.sidejobs.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divSideMonthly").innerHTML =  fmt(MonthlySavings);
  document.sidejobs.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divSideYearly").innerHTML = fmt(MonthlySavings * 12);
  document.getElementById("divSideDaily").innerHTML = fmt(MonthlySavings/22);
  
  //print form variables
  //document.printform.sj_monthlyrevenue.value = document.sidejobs.monthlyrevenue.value;
  //document.printform.sj_moonlighting.value = document.sidejobs.moonlighting.value;
  //document.printform.sj_Monthly.value = document.sidejobs.Monthly.value;
  //document.printform.sj_Yearly.value = document.sidejobs.Yearly.value;
  //document.printform.sj_Daily.value = fmt(MonthlySavings/22);
  //alert(document.sidejobs.HiddenMonthly.value);
}


function CalcVOC() {
  var VOC = document.voc.vehicletype.value * document.voc.monthlymileage.value * document.voc.km_miles.value * document.voc.vehicles.value;
  var MonthlySavings = VOC * document.voc.mileagereduction.value;
  document.voc.HiddenMonthly.value = MonthlySavings;
  document.voc.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divVOCMonthly").innerHTML =  fmt(MonthlySavings);
  document.voc.Yearly.value = fmt(MonthlySavings * 12);
   document.getElementById("divVOCDaily").innerHTML =  fmt(MonthlySavings/22);
  document.voc.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divVOCYearly").innerHTML = fmt(MonthlySavings * 12);
  
  //print form variables
  //document.printform.voc_vehicletype.value = document.voc.vehicletype.value;
  //document.printform.voc_monthlymileage.value = document.voc.monthlymileage.value;
  //document.printform.voc_km_miles.value = document.voc.km_miles.value;
  //document.printform.voc_vehicles.value = document.voc.vehicles.value;
  //document.printform.voc_mileagereduction.value = document.voc.mileagereduction.value;
  //document.printform.voc_Monthly.value = document.voc.Monthly.value;
  //document.printform.voc_Yearly.value = document.voc.Yearly.value;
  //document.printform.voc_Daily.value = fmt(MonthlySavings/22);
  //document.printform.totalvehicles.value = document.voc.vehicles.value;
  //alert(document.voc.HiddenMonthly.value);
}


function CalcInsurance() {
  var MonthlySavings = document.insurance.vehicles.value * document.insurance.cost.value * document.insurance.discount.value / 12;
var totalvehicle = document.insurance.vehicles.value;
  document.insurance.HiddenMonthly.value = MonthlySavings;
   document.insurance.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divInsuranceDaily").innerHTML =  fmt(MonthlySavings/22);
  document.insurance.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divInsuranceMonthly").innerHTML =  fmt(MonthlySavings);
  document.insurance.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divInsuranceYearly").innerHTML = fmt(MonthlySavings * 12);
  
  //print form variables
  //document.printform.insurance_vehicles.value = document.insurance.vehicles.value;
  //document.printform.insurance_cost.value = document.insurance.cost.value;
  //document.printform.insurance_discount.value = document.insurance.discount.value;
  //document.printform.insurance_Monthly.value = document.insurance.Monthly.value;
  //document.printform.insurance_Yearly.value = document.insurance.Yearly.value;
  //document.printform.insurance_Daily.value = fmt(MonthlySavings/22);
  //document.printform.totalvehicles = totalvehicle;
   // alert(document.insurance.HiddenMonthly.value);
}

function CalcMaintenance() {
  var MonthlySavings = (document.maintenance.vehicles.value * document.maintenance.reduceddays.value * document.maintenance.revenue.value) / 12;
var totalvehicle = document.maintenance.vehicles.value;
  document.maintenance.HiddenMonthly.value = MonthlySavings;
    document.maintenance.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divMaintenanceDaily").innerHTML =  fmt(MonthlySavings/22);
  document.maintenance.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divMaintenanceMonthly").innerHTML =  fmt(MonthlySavings);
  document.maintenance.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divMaintenanceYearly").innerHTML = fmt(MonthlySavings * 12);

  
  //print form variables
  //document.printform.maintenance_vehicles.value = document.maintenance.vehicles.value;
  //document.printform.maintenance_reduceddays.value = document.maintenance.reduceddays.value;
  //document.printform.maintenance_revenue.value = document.maintenance.revenue.value;
  //document.printform.maintenance_Monthly.value = document.maintenance.Monthly.value;
  //document.printform.maintenance_Yearly.value = document.maintenance.Yearly.value;
  //document.printform.maintenance_Daily.value = fmt(MonthlySavings/22);
 // document.printform.totalvehicles = totalvehicle;
  //alert(document.maintenance.HiddenMonthly.value);
}

function CalcManagement() {
  var MonthlySavings = (document.management.salary.value * document.management.timepercent.value);

  document.management.HiddenMonthly.value = MonthlySavings;
    document.management.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divManagementDaily").innerHTML =  fmt(MonthlySavings/22);
  document.management.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divManagementMonthly").innerHTML =  fmt(MonthlySavings);
  document.management.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divManagementYearly").innerHTML = fmt(MonthlySavings * 12);
  
  //print form variables
  //document.printform.management_salary.value = document.management.salary.value;
  //document.printform.management_timepercent.value = document.management.timepercent.value;
  //document.printform.management_Monthly.value = document.management.Monthly.value;
  //document.printform.management_Yearly.value = document.management.Yearly.value;
  //document.printform.management_Daily.value = fmt(MonthlySavings/22);
 // alert(document.management.HiddenMonthly.value);
}

function CalcFuel() {
  var MonthlySavings = ((document.fuel.vehicles.value * document.fuel.weeklyfuel.value) * document.fuel.timesaved.value);
	var totalvehicle = document.fuel.vehicles.value;
  document.fuel.HiddenMonthly.value = MonthlySavings;
    document.fuel.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divFuelDaily").innerHTML =  fmt(MonthlySavings/22);
  document.fuel.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divFuelMonthly").innerHTML =  fmt(MonthlySavings);
  document.fuel.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divFuelYearly").innerHTML = fmt(MonthlySavings * 12);
  
  //print form variables
  //document.printform.fuel_vehicles.value = document.fuel.vehicles.value;
  //document.printform.fuel_weeklyfuel.value = document.fuel.weeklyfuel.value;
  //document.printform.fuel_timesaved.value = document.fuel.timesaved.value;
  //document.printform.fuel_Monthly.value = document.fuel.Monthly.value;
  //document.printform.fuel_Yearly.value = document.fuel.Yearly.value;
  //document.printform.fuel_Daily.value = fmt(MonthlySavings/22);
 // document.printform.totalvehicles = totalvehicle;
  //alert(document.fuel.HiddenMonthly.value);
}

function CalcEmpProductivity() {
  var MonthlySavings = (document.empproductivity.vehicles.value * document.empproductivity.timetojob.value * document.empproductivity.hourlywage.value * 22);
  var totalvehicle = document.empproductivity.vehicles.value;
  document.empproductivity.HiddenMonthly.value = MonthlySavings;
  document.empproductivity.Daily.value = fmt(MonthlySavings/22);
  document.getElementById("divEmpproductivityDaily").innerHTML =  fmt(MonthlySavings/22);
  document.empproductivity.Monthly.value = fmt(MonthlySavings);
  document.getElementById("divEmpproductivityMonthly").innerHTML =  fmt(MonthlySavings);
  document.empproductivity.Yearly.value = fmt(MonthlySavings * 12);
  document.getElementById("divEmpproductivityYearly").innerHTML = fmt(MonthlySavings * 12);
  
  //print form variables
  //document.printform.empproductivity_vehicles.value = document.empproductivity.vehicles.value;
  //document.printform.empproductivity_timetojob.value = document.empproductivity.timetojob.value;
  //document.printform.empproductivity_hourlywage.value = document.empproductivity.hourlywage.value;
  //document.printform.empproductivity_Monthly.value = document.empproductivity.Monthly.value;
  //document.printform.empproductivity_Yearly.value = document.empproductivity.Yearly.value;
  //document.printform.empproductivity_Daily.value = fmt(MonthlySavings/22);
 // document.printform.totalvehicles = totalvehicle;
  //alert(document.empproductivity.HiddenMonthly.value);
  }

function CalTraining(){

document.training.TrainingWeeksSavedd.value = (document.training.hrspweek.value * document.training.employees.value);
var TrainingWagesWeek = document.training.TrainingWeeksSavedd.value * document.training.TrainingHrlyWage.value ;
var TrainingWagesDay = document.training.TrainingWeeksSavedd.value * document.training.TrainingHrlyWage.value/5 ;
var TrainingWagesMonth = document.training.TrainingWeeksSavedd.value * document.training.TrainingHrlyWage.value*22/5 ;
var TrainingWagesYear = document.training.TrainingWeeksSavedd.value * document.training.TrainingHrlyWage.value*52 ;
var TrainingWeeksSaved1 = document.training.TrainingWeeksSavedd.value/5;

document.training.HiddenMonthly.value = TrainingWagesMonth;
document.training.TrainingWagesDay.value = fmt(TrainingWagesDay);
document.training.TrainingWagesMonth.value = fmt(TrainingWagesMonth);
document.training.TrainingWagesYear.value = fmt(TrainingWagesYear);
document.training.TrainingWeeksSavedd.value = fmt(TrainingWeeksSaved1);
	document.training.TrainingWeeksSavedm.value = fmt(TrainingWeeksSaved1*22);
	document.training.TrainingWeeksSavedy.value = fmt(TrainingWeeksSaved1*12*22);
document.getElementById("divTrainingWeeksSavedd").innerHTML = fmthours(TrainingWeeksSaved1);
document.getElementById("divTrainingWeeksSavedm").innerHTML = fmthours(TrainingWeeksSaved1*22);
document.getElementById("divTrainingWeeksSavedy").innerHTML = fmthours(TrainingWeeksSaved1*12*22);
document.getElementById("divTrainingWagesDay").innerHTML = fmt(TrainingWagesDay);
document.getElementById("divTrainingWagesMonth").innerHTML = fmt(TrainingWagesMonth);
document.getElementById("divTrainingWagesYear").innerHTML = fmt(TrainingWagesYear);

//print form variables
//document.printform.trainingweeksaving.value = TrainingWeeksSaved1*5;
//document.printform.trainingmonthlywagesaving.value = TrainingWagesMonth;
//document.printform.trainingyearlywagesaving.value = TrainingWagesYear;
//document.printform.print_TrainingWeeksSavedd.value = fmthours(TrainingWeeksSaved1);
//document.printform.print_TrainingWeeksSavedm.value = fmthours(TrainingWeeksSaved1*22);
//document.printform.print_TrainingWeeksSavedy.value = fmthours(TrainingWeeksSaved1*22*12);
//document.printform.trainingdailywagesaving.value = TrainingWagesDay;
//alert(document.training.HiddenMonthly.value);
}


function CalCellularCost(){

document.cellularcost.CellularMonthlySave.value = document.cellularcost.vans.value * document.cellularcost.monthlybill.value * document.cellularcost.perc.value;
var totalvehicle = document.cellularcost.vans.value;
var TotalCellularMonth = document.cellularcost.CellularMonthlySave.value;
document.cellularcost.HiddenMonthly.value = TotalCellularMonth;
document.cellularcost.CellularDailySave.value = fmt(TotalCellularMonth/22);
document.cellularcost.CellularYearlySave.value = fmt(TotalCellularMonth*12);
document.getElementById("divCellularDaily").innerHTML = fmt(TotalCellularMonth/22);
document.getElementById("divCellularMonthly").innerHTML = fmt(TotalCellularMonth);
document.getElementById("divCellularYearly").innerHTML = fmt(TotalCellularMonth*12);


//print form variables
//document.printform.cellularmonthlysaving.value = fmt(TotalCellularMonth);
//document.printform.cellularyearlysaving.value = fmt(TotalCellularMonth*12);
//document.printform.cellulardailysaving.value = fmt(TotalCellularMonth/22);
//document.printform.totalvehicles = totalvehicle;
//alert(document.cellularcost.HiddenMonthly.value);
}

function Calptofuel(){

document.ptofuel.PTOSavingsd.value = document.ptofuel.vans.value * document.ptofuel.monthhrs.value * 0.68;
  var totalvehicle = document.ptofuel.vans.value;
var TotalPTOMonth = document.ptofuel.PTOSavingsd.value*22;
document.ptofuel.HiddenMonthly.value = TotalPTOMonth;
document.ptofuel.PTOSavings.value = fmt(TotalPTOMonth);
document.ptofuel.PTOSavingsy.value = fmt(TotalPTOMonth*12);
document.getElementById("divPTOSavedd").innerHTML = fmt(TotalPTOMonth/22);
document.getElementById("divPTOSaved").innerHTML = fmt(TotalPTOMonth);
document.getElementById("divPTOSavedy").innerHTML = fmt(TotalPTOMonth*12);

//print form variables
//document.printform.ptomonthly.value =fmt(TotalPTOMonth);
//document.printform.ptoyearly.value = fmt(TotalPTOMonth*12);
//document.printform.ptodaily.value = fmt(TotalPTOMonth/22);
//document.printform.totalvehicles = totalvehicle;
//alert(document.ptofuel.HiddenMonthly.value);
}

function TotalAll() {
	
	CalcProductivity();
	CalcVehProductivity();
	CalcLostRevenue();
	CalcSideJobs();
	CalcVOC();
	CalcInsurance();
	CalcMaintenance();
	CalcManagement();
	CalcFuel();
	CalcEmpProductivity();
	CalTraining();
	CalCellularCost();
	Calptofuel();

	var MonthlyTotalSavings = parseInt(document.productivity.HiddenMonthly.value)
	                        + parseInt(document.lostrevenue.HiddenMonthly.value)
							+ parseInt(document.vehproductivity.HiddenMonthly.value)
							+ parseInt(document.sidejobs.HiddenMonthly.value)
							+ parseInt(document.voc.HiddenMonthly.value)
							+ parseInt(document.insurance.HiddenMonthly.value)
 							+ parseInt(document.maintenance.HiddenMonthly.value)
							+ parseInt(document.management.HiddenMonthly.value)
 							+ parseInt(document.fuel.HiddenMonthly.value)
							+ parseInt(document.empproductivity.HiddenMonthly.value)
							+ parseInt(document.training.HiddenMonthly.value)
							+ parseInt(document.cellularcost.HiddenMonthly.value)
							+ parseInt(document.ptofuel.HiddenMonthly.value);

//alert(MonthlyTotalSavings);
	document.totals.Monthly.value = fmt(MonthlyTotalSavings);
  document.getElementById("divTotalMonthly").innerHTML = fmt(MonthlyTotalSavings);
	document.totals.Yearly.value = fmt(MonthlyTotalSavings * 12);
		document.totals.Daily.value = fmt(MonthlyTotalSavings/22);
  document.getElementById("divTotalYearly").innerHTML = fmt(MonthlyTotalSavings * 12);
  document.getElementById("divTotalDaily").innerHTML = fmt(MonthlyTotalSavings/22);
  //document.printform.totals_Monthly.value = document.totals.Monthly.value;
  //document.printform.totals_Yearly.value = document.totals.Yearly.value;

}
