/* Programmed by A. P. Power */
/* This script is copyrighted (c) 2000 by DSSResources.COM */
/* All rights reserved */

/* This script is used with Cost Benefit Analysis cbanalysis.html */

/* Declares local variables */

var i,k,totcost,totbenefit,disccost,discbenefit,iserror;

function costbenefit(form) {
/* Confirms all input fields were filled in */
iserror=0
  for(i=1; i<11; i++)
	{if ((eval("document.form.dc"+i+".value") == "") ||
	(eval("document.form.idc"+i+".value") == "") ||
	(eval("document.form.db"+i+".value") == "") ||
	(eval("document.form.idb"+i+".value") == "") ) {
	iserror=1;
         }
}
  if (document.form.discrate.value == "" || iserror==1) {
     alert ("All input fields must have a value");
         } 

var discrate = eval(document.form.discrate.value)
totcost = 0;
totbenefit = 0;
disccost = 0;
discbenefit = 0;
/* Increments the 4 variables to get the total value and discounted present value */
/* k is used to sum up the 10 years of values */
  for(k=1; k<11; k++)
  {totcost +=eval(eval("document.form.dc"+k+".value"))+eval(eval("document.form.idc"+k+".value"));
   totbenefit += eval(eval("document.form.db"+k+".value"))+eval(eval("document.form.idb"+k+".value"));
   disccost += (eval(eval("document.form.dc"+k+".value"))+eval(eval("document.form.idc"+k+".value")))/Math.pow((1+(discrate/100)),k);
   discbenefit += (eval(eval("document.form.db"+k+".value"))+eval(eval("document.form.idb"+k+".value")))/Math.pow((1+(discrate/100)),k);
}
benefcost = discbenefit / disccost
/* Sets output in document */
document.form.totbenefit.value = totbenefit;
document.form.totcost.value = totcost;
document.form.disccost.value = round(disccost);
document.form.discbenefit.value = round(discbenefit);
document.form.benefcost.value = round(benefcost);
}



