function update ()
{
	 
 if ( document.compare.MONTH.value > 12 ) {
    document.compare.AMONTH.value = document.compare.MONTH.value * 3;
 } else {
    document.compare.AMONTH.value = 36
 }
 //document.compare.ALABOR.value = document.compare.LABOR.value;
 //document.compare.ADOWNTM.value = document.compare.DOWNTM.value;
 //document.compare.AFLEETNUM.value = document.compare.FLEETNUM.value;
 //document.compare.AOPERATE.value = document.compare.OPERATE.value;
}


function dosum()
{
  update();
  var re = /,/g //remove any commas entered 
  var months = Math.floor(document.compare.MONTH.value.replace(re,""));
  var amonths = Math.floor(document.compare.AMONTH.value.replace(re,""));
  var part = Math.floor(document.compare.PART.value.replace(re,""));
  var apart = Math.floor(document.compare.APART.value.replace(re,""));
  var labor = Math.floor(document.compare.LABOR.value.replace(re,""));
  var downtm = Math.floor(document.compare.DOWNTM.value.replace(re,""));
  var operate = Math.floor(document.compare.OPERATE.value.replace(re,""));  
  var fleetnum = Math.floor(document.compare.FLEETNUM.value.replace(re,""));

  var total1 = (part + labor + downtm) * (36 / months) ;
  document.compare.TOTAL1.value = /*"$" + */ addCommas(total1.toFixed(0));

  var atotal = (apart + labor + downtm) * (36 / amonths);
  document.compare.ATOTAL.value = /*"$" + */ addCommas(Math.round(atotal));

  //var total1 = (part + labor + downtm) * fleetnum * months ;
  //document.compare.TOTAL1.value = /*"$" + */ addCommas(total1.toFixed(0));

 // var atotal = (apart + labor + downtm) * fleetnum * amonths;
  //document.compare.ATOTAL.value = /*"$" + */ addCommas(Math.round(atotal));

  var total2 =  total1 / (operate * 3);
  document.compare.TOTAL2.value = /*"$" + */ total2.toFixed(3);
  
  var atotal2 = atotal/(operate * 3);
  document.compare.ATOTAL2.value = /*"$" + */ atotal2.toFixed(3);
  
  var totalSavings = (total1 - atotal) * fleetnum;
  document.compare.TOTALSAVINGS.value= /*"$" + */ addCommas(Math.round(totalSavings));
  
  var permile = (total2 - atotal2) * 3;
  document.compare.SAVINGSPERMILE.value= /*"$" + */ permile.toFixed(3);
  
  //var totalSavings = total1 - atotal;
  //document.compare.TOTALSAVINGS.value= /*"$" + */ addCommas(Math.round(totalSavings));
  
 //var permile = totalSavings/(operate * fleetnum);
  //document.compare.SAVINGSPERMILE.value= /*"$" + */ permile.toFixed(3);
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

