// Upon initial startup, load default values
// Company Profile defaults
  var revenue = 25000000;
  var employees = 130;
  var pctProfit = 10;
  var overhead = 30;
  var curProfit = 2500000;
// Manufacturing Engineering defaults
  var ppUseyn = true;
  var ppHeads = 2;
  var ppCostYr = 40000;
  var ppCostTot = 80000;
  var ppImp = 5;
  var ppSavings = 4000;
// Time Generation defaults
  var tgUseyn = true;
  var tgHeads = 1;
  var tgCostYr = 40000;
  var tgCostTot = 40000;
  var tgImp = 5;
  var tgSavings = 2000;
// Machine Shop defaults
  var msUseyn = true;
  var meSavings = 6000;
// Production defaults
  var deHeads = 80;
  var deCostYr = 25000;
  var deCostTot = 2000000;
  var dePpSavings = 20000;
  var deTgSavings = 20000;
  var deSavings = 40000;
  var pcCostTot = 13000000;
  var pcPpSavings = 130000;
  var pcTgSavings = 130000;
  var pcSavings = 260000;
  var prodSavings = 300000;
  var deTgImp = 1;
  var dePpImp = 1;
  var pcTgImp = 1;
  var pcPpImp = 1;
// Cost Estimating defaults
  var ceUseyn = true;
  var ceHeads = 2;
  var ceCostYr = 40000;
  var ceCostTot = 80000;
  var ceSavings = 8000;
  var esPct = 10;
  var nwPct = 50;
  var cePctSav = 10;
  var cePctImp = 1;
  var estSavings = 125000;
  var bceSavings = 133000;
// Design defaults
  var desUseyn = true;
  var desHeads = 4;
  var desCostTot = 15000000;
  var desPct = 2;
  var desSavings = 300000;
// Purchasing defaults
  var purUseyn = true;
  var purHeads = 2;
  var purPct = 20;
  var purCostTot = 3000000;
  var purPctSav = 5;
  var purSavings = 150000;
// Total savings
  var totSavings = 889000;

function getSummary() {
// When Summary page loads, populate fields with stored values
  getCompany();
  getMfg();
  getProd();
  getCE();
  getDes();
  getPur();
  getTotSaving();
}
function getCompany() {
  document.profile.revenue.value = revenue;
  document.profile.employees.value = employees;
  document.profile.pctProfit.value = pctProfit;
  document.profile.overhead.value = overhead;
  document.profile.curProfit.value = curProfit;
}
function putCompany() {
  revenue = document.profile.revenue.value;
  employees = document.profile.employees.value;
  pctProfit = document.profile.pctProfit.value;
  overhead = document.profile.overhead.value;
  document.profile.curProfit.value = String(Number(revenue) * .01 * Number(pctProfit));
  curProfit = document.profile.curProfit.value;
  putTotSaving();
}
function getMfg() {
  document.profile.ppUseyn.checked = ppUseyn;
  document.profile.ppHeads.value = ppHeads;
  document.profile.ppCostYr.value = ppCostYr;
  document.profile.ppCostTot.value = ppCostTot;
  document.profile.ppSavings.value = ppSavings;
  document.profile.ppImp.value = ppImp;
  document.profile.tgUseyn.checked = tgUseyn;
  document.profile.tgHeads.value = tgHeads;
  document.profile.tgCostYr.value = tgCostYr;
  document.profile.tgCostTot.value = tgCostTot;
  document.profile.tgImp.value = tgImp;
  document.profile.tgSavings.value = tgSavings;
  document.profile.meSavings.value = meSavings;
}
function putPP() {
  ppUseyn = document.profile.ppUseyn.checked;
  ppHeads =document.profile.ppHeads.value;
  ppCostYr = document.profile.ppCostYr.value;
  ppImp = document.profile.ppImp.value;
  if (ppUseyn) {
    ppCostTot = String(Number(ppHeads) * Number(ppCostYr));
    ppSavings = String(Number(ppImp) * .01 * Number(ppCostTot));
  }
  else {
    ppCostTot = "0";
    ppSavings = "0";
  }
  meSavings = String(Number(ppSavings) + Number(tgSavings));
  putTotSaving();
}
function putTG() {
  tgUseyn = document.profile.tgUseyn.checked;
  tgHeads =document.profile.tgHeads.value;
  tgCostYr = document.profile.tgCostYr.value;
  tgImp = document.profile.tgImp.value;
  if (tgUseyn) {
    tgCostTot = String(Number(tgHeads) * Number(tgCostYr));
    tgSavings = String(Number(tgImp) * .01 * Number(tgCostTot));
  }
  else {
    tgCostTot = "0";
    tgSavings = "0";
  }
  meSavings = String(Number(ppSavings) + Number(tgSavings));
  putTotSaving();
}
function getProd() {
  document.profile.deHeads.value = deHeads;
  document.profile.deCostYr.value = deCostYr;
  document.profile.deCostTot.value = deCostTot;
  document.profile.dePpSavings.value = dePpSavings;
  document.profile.deTgSavings.value = deTgSavings;  
  document.profile.deSavings.value = deSavings;
  document.profile.pcCostTot.value = pcCostTot;
  document.profile.pcPpSavings.value = pcPpSavings;
  document.profile.pcTgSavings.value = pcTgSavings;
  document.profile.pcSavings.value = pcSavings;
  document.profile.prodSavings.value = prodSavings;
  document.profile.deTgImp.value = deTgImp;
  document.profile.dePpImp.value = dePpImp;
  document.profile.pcTgImp.value = pcTgImp;
  document.profile.pcPpImp.value = pcPpImp;
}
function putProd() {
  deTgImp = document.profile.deTgImp.value;
  dePpImp = document.profile.dePpImp.value;
  pcTgImp = document.profile.pcTgImp.value;
  pcPpImp = document.profile.pcPpImp.value;
  deHeads = document.profile.deHeads.value;
  deCostYr = document.profile.deCostYr.value;

  deCostTot = String(Number(deHeads) * Number(deCostYr));
  dePpSavings = String(Number(dePpImp) *.01 * Number(deCostTot));
  deTgSavings = String(Number(deTgImp) *.01 * Number(deCostTot));
  deSavings = String(Number(dePpSavings) + Number(deTgSavings));

  var revenue2 = Number(revenue);
  var profit = Number(curProfit);
  var overhead2 = .01 * Number(overhead) * revenue2;
  var decost = Number(deCostTot);

  pcCostTot = String(revenue2 - profit - overhead2 - decost);
  pcPpSavings = String(Number(pcPpImp) *.01 * Number(pcCostTot));
  pcTgSavings = String(Number(pcTgImp) *.01 * Number(pcCostTot));
  pcSavings = String(Number(pcPpSavings) + Number(pcTgSavings));
  prodSavings = String(Number(deSavings) + Number(pcSavings));

  putTotSaving();
}
function getCE() {
  document.profile.ceUseyn.checked = ceUseyn;
  document.profile.ceHeads.value = ceHeads;
  document.profile.ceCostYr.value = ceCostYr;
  document.profile.ceCostTot.value = ceCostTot;
  document.profile.ceSavings.value = ceSavings;
  document.profile.estSavings.value = estSavings;
  document.profile.esPct.value = esPct;
  document.profile.nwPct.value = nwPct;
  document.profile.bceSavings.value = bceSavings;
  document.profile.cePctSav.value = cePctSav;
  document.profile.cePctImp.value = cePctImp;
}
function putCE() {
  cePctSav = document.profile.cePctSav.value;
  cePctImp = document.profile.cePctImp.value;
  ceSav = .01 * Number(cePctSav);
  ceUseyn = document.profile.ceUseyn.checked;
  ceHeads =document.profile.ceHeads.value;
  ceCostYr = document.profile.ceCostYr.value;
  if (ceUseyn) {
    ceCostTot = String(Number(ceHeads) * Number(ceCostYr));
    ceSavings = String(ceSav * Number(ceCostTot));
  }
  else {
    ceCostTot = "0";
    ceSavings = "0";
  }
  bceSavings = String(Number(ceSavings) + Number(estSavings));
  putTotSaving();
}
function putES() {
  esPct = document.profile.esPct.value;
  nwPct = document.profile.nwPct.value;
  ceImp = Number(cePctImp);
  profit = Number(curProfit);
  hitrate = .01 * Number(esPct);
  newWork = .01 * Number(nwPct);
  if (ceUseyn) {
    estSavings = String(ceImp * profit * hitrate * newWork);
  }
  else {
    estSavings = "0";
  }
  bceSavings = String(Number(ceSavings) + Number(estSavings));
  putTotSaving();
}
function getDes() {
  document.profile.desUseyn.checked = desUseyn;
  document.profile.desHeads.value = desHeads;
  document.profile.desCostTot.value = desCostTot;
  document.profile.desPct.value = desPct;
  document.profile.desSavings.value = desSavings;
  document.profile.desSavings2.value = desSavings;
}
function putDes() {
  desUseyn = document.profile.desUseyn.checked;
  desHeads = document.profile.desHeads.value;
  desPct = document.profile.desPct.value;
  desSav = .01 * Number(desPct);
  var revenue2 = Number(revenue);
  var profit2 = Number(curProfit);
  var overhead2 = .01 * Number(overhead2) * revenue2;
  var desCostTot2 = String(revenue2 - overhead2 - profit2);
  if (desUseyn) {
    desSavings = String(Number(desSav) * Number(desCostTot));
  }
  else {
    desSavings = "0";
  }
  putTotSaving();
}
function getPur() {
  document.profile.purUseyn.checked = purUseyn;
  document.profile.purHeads.value = purHeads;
  document.profile.purPct.value = purPct;
  document.profile.purCostTot.value = purCostTot;
  document.profile.purSavings.value = purSavings;
  document.profile.purSavings2.value = purSavings;
  document.profile.purPctSav.value = purPctSav;
}
function putPur() {
  purUseyn = document.profile.purUseyn.checked;
  purHeads = document.profile.purHeads.value;
  purPct = document.profile.purPct.value;
  purPctSav = document.profile.purPctSav.value;
  var purSav = .01 * Number(purPctSav);
  if (purUseyn) {
    var pcost2 = Number(desCostTot);
    var pctPur2 = .01 * Number(purPct);
    purCostTot = String(pcost2 * pctPur2);
    purSavings = String(purSav * Number(purCostTot));
  }
  else {
    purCostTot = "0";
    purSavings = "0";
  }
  putTotSaving();
}
function putTotSaving() {
  meSavings = Number(meSavings);
  prodSavings = Number(prodSavings);
  bceSavings = Number(bceSavings);
  desSavings = Number(desSavings);
  purSavings = Number(purSavings);
  totSavings = String(meSavings + prodSavings + bceSavings + desSavings + purSavings);
}
function getTotSaving() {
  document.profile.totSavings.value = totSavings;
}

function updateCompany() {
  putCompany();
  getCompany();
  putProd();
  getProd();
  putES();
  getCE();
  putDes();
  getDes();
  getTotSaving();
}
function updatePP() {
  putPP();
  getMfg();
  getTotSaving();
}
function updateTG() {
  putTG();
  getMfg();
  getTotSaving();
}
function updateProd() {
  putProd();
  getProd();
  getTotSaving();
}
function updateCE() {
  putCE();
  putES();
  getCE();
  getTotSaving();
}
function updateDes() {
  putDes();
  getDes();
  getTotSaving();
}
function updatePur() {
  putPur();
  getPur();
  getTotSaving();
}

function putCEVars() {
 var str = revenue + "<br>$ ";
      str += curProfit + "<br> ";
      str += esPct + "%<br>";
      str += nwPct + "%<br>$ ";
 var pppp = String(Number(estSavings) / Number(cePctImp));
      str += pppp;
  document.write(str);
}

function putDesVars() {
	var str5 = revenue + "<br>$ ";
      str5 += curProfit + "<br> ";
      str5 += overhead + "%<br>$ ";
	 var  ohValue5 = Number(overhead) * .01 * Number(revenue);
      str5 += String(ohValue5) + "<br><br>$ ";
      str5 += desCostTot;
  document.write(str5);
}

function putPurVars() {
  var str = revenue + "<br>$ ";
      str += curProfit + "<br> ";
      str += overhead + "%<br>$ ";
 var ohValue = Number(overhead) * .01 * Number(revenue);
      str += String(ohValue) + "<br><br>$ ";
      str += desCostTot + "<br>" + purPct + "%<br><br>$ ";
      str += String(Number(desCostTot) * Number(purPct) * .01);
  document.write(str);
}