//  Fujilives ROI Calculator V1.0
/*-----------------------------------------------------------------------------------------------*/


	//This code disables the enter key from refreshing the page
	function kH(e) {
	var pK = e ? e.which : window.event.keyCode;
	return pK != 13;
	}
	document.onkeypress = kH;
	if (document.layers) document.captureEvents(Event.KEYPRESS);
	
	
	//Code to make the enter key be reccognized - find the element 'btnsearch' and click it when enter is pressed
	function searchKeyPress(e)
	{
			// look for window.event in case event isn't passed in
			if (window.event) { e = window.event; }
			if (e.keyCode == 13)
			{
					document.getElementById('btnSearch').click();
			}
	}


	//Currency Format Function
	function formatCurrency(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 + '.' + cents);
	};
	
	
	//ROI Calculator - Waste Oil Value Calculator - whatever you want to call it
	function computeROI(ROI)
	{    
		var a = parseFloat(ROI.wt.value);
		var c = 0; //method of current heating and associated value per BTU
		var e = 0; //total annual value of waste oil PLUS the total disposal value (plus or minus depending on disposalprice radial button)
		var f = 0;
		
		for(i = 0; i < ROI.method.length; i++)
		
		if(ROI.method[i].checked)
			{
				c = parseFloat(ROI.method[i].value);
			}
	
		if(a > 0.0) 
			{
				f = parseFloat(a * c);
				
				var TotalSavingsDiv = document.getElementById("TotalSavingsDiv");
				TotalSavingsDiv.innerHTML = 
				'<div style="position:relative; margin:10px 0px 2px 0px;">'+
				'<div style="font-size:18px; font-weight:bold; overflow:hidden;">'+
				'Estimated Total Yearly Savings:'+
				'</div>'+
				'</div>'+
				'<div style="position:relative; margin:10px 0px 2px 10px;">'+
				formatCurrency(f)+
				' Saved Every Year!'+
				'</div>';
			}
			
		else
			{
				var TotalSavingsDiv = document.getElementById("TotalSavingsDiv");
				TotalSavingsDiv.innerHTML = 
				'<div style="position:relative; margin:10px 0px 2px 0px;">'+
				'<div style="font-size:18px; font-weight:bold; overflow:hidden;">'+
				'<i><small>Please make sure all of the required fields are filled</small></i>'+
				'</div>'+
				'</div>';	
			};
			
	};