function calcproductivity() {
  var workdays = document.getElementById('workdays').value;
  var totalemployees = document.getElementById('totalemployees').value;
  var hoursperemployee = document.getElementById('hoursperemployee').value;
  var compensation = document.getElementById('compensation').value;
  var productivity = document.getElementById('productivity').value;
  var unitcost = document.getElementById('unitcost').value;
  
  if (productivity<1||productivity>100) { return false;  }
  else if (workdays<1||workdays>366) { return false; }
  else if (totalemployees<1) { return false; }
  else if (hoursperemployee<1||hoursperemployee>24) { return false; }
  else if (unitcost<49) { return false; }
  else {
  employeegain = ((productivity/100)*hoursperemployee)*workdays/8;
  gaindays = employeegain*totalemployees;
  gaindollars = (employeegain*totalemployees)*(compensation/workdays);
  totalcost = unitcost*totalemployees;
  totalgaindollars = ((employeegain*totalemployees)*(compensation/workdays))-(unitcost*totalemployees);
  payback = (unitcost*totalemployees)/((employeegain*totalemployees)*(compensation/workdays))*workdays; 
 }
 
  document.productivity_calc.employeegain.value = employeegain;
  document.productivity_calc.gaindays.value = gaindays;
  document.productivity_calc.gaindollars.value = gaindollars;
  document.productivity_calc.totalcost.value = totalcost;
  document.productivity_calc.totalgaindollars.value = totalgaindollars;
  document.productivity_calc.payback.value = payback;

}

function checkRange(form) {
  var productivity = document.productivity_calc.productivity.value;
  if(productivity<1||productivity>100){
    alert('Enter a percentage between 1 and 100 for Productivity.\n\nClick OK to restore default value.');
    setTimeout(function(){
	document.productivity_calc.productivity.value = "12";
	document.productivity_calc.productivity.select();
	document.productivity_calc.productivity.focus()}, 10); return false;
  }
  var workdays = document.productivity_calc.workdays.value;
  if(workdays<1||workdays>366){
    alert('Enter a number between 1 and 366 for Workdays.\n\nClick OK to restore default value.');
    setTimeout(function(){
	document.productivity_calc.workdays.value = "225";
	document.productivity_calc.workdays.select();
	document.productivity_calc.workdays.focus()}, 10); return false;
  }
  var totalemployees = document.productivity_calc.totalemployees.value;
  if(totalemployees<1){
    alert('Enter a number of at least 1.\n\nClick OK to restore default value.');
    setTimeout(function(){
	document.productivity_calc.totalemployees.value = "500";
	document.productivity_calc.totalemployees.select();
	document.productivity_calc.totalemployees.focus()}, 10); return false;
  }
  var hoursperemployee = document.productivity_calc.hoursperemployee.value;
  if(hoursperemployee<1||hoursperemployee>24){
    alert('Enter a number between 1 and 24 for Hours per Employee.\n\nClick OK to restore default value.');
    setTimeout(function(){
	document.productivity_calc.hoursperemployee.value = "8";
	document.productivity_calc.hoursperemployee.select();
	document.productivity_calc.hoursperemployee.focus()}, 10); return false;
  }
  var unitcost = document.productivity_calc.unitcost.value;
  if(unitcost<50){
    alert('Enter a value of at least 50 for Cost of Ergonomic Furniture.\n\nClick OK to restore default value.');
	setTimeout(function(){
	document.productivity_calc.unitcost.value = "800";
	document.productivity_calc.unitcost.select();
	document.productivity_calc.unitcost.focus()}, 10);
  }
}

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Manzi Olivier :: http://www.imanzi.com/ */
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if ((cCode < 48) || (cCode > 57)) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
function formatNum(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(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);
}
