/* ======================================================================
DESC: Waste Control Systems' Savings Calculator JavaScript

PLATFORMS: IE3 through IEx

USAGE NOTES: Calculates savings with an In-Drum Compactor
====================================================================== */
function cli() {
	tthree.innerHTML = '$' + roundOff(totalThree(), 2);
	checkForm();
	tfour.innerHTML = '$' + roundOff(totalFour(), 2);
	tone.innerHTML = '$' + roundOff(totalOne(), 2);
	tfive.innerHTML = Math.round(totalFive());
}

   function totalOne() {
   totalone = document.saveform.drumPerYear.value*document.saveform.disposeFee.value+document.saveform.drumPerYear.value*document.saveform.purchasePrice.value
   return totalone
}
   function totalTwo() {
   totaltwo = totalOne()/document.saveform.ratio.value
   return totaltwo
}
   function totalThree() {
   totalthree = document.saveform.drumPerYear.value/document.saveform.ratio.value*document.saveform.disposeFee.value+document.saveform.drumPerYear.value/document.saveform.ratio.value*document.saveform.purchasePrice.value
   return totalthree
}
   function totalFour() {
   totalfour = totalOne()-totalThree()
   return totalfour
}

	function totalFive() {
	totalfive = document.saveform.drumPerYear.value/document.saveform.ratio.value
	return totalfive
}

function checkForm() {
	if ( document.saveform.ratio.value == "default" ) {
		alert ("You have not specified a waste stream");
		document.saveform.ratio.focus();
		}
   
}
function roundOff(value, precision){
        value = "" + value //convert value to string
        precision = parseInt(precision);
        var whole = "" + Math.round(value * Math.pow(10, precision));
        var decPoint = whole.length - precision;        if(decPoint != 0)
        {                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);        }
        else        {                result = whole;        }
        return result;}