/* bar and restaurant constant values */
var cpp = "1.89";      //Containers per pound
var cp = ".048";       //Comingled pounds
var sv = ".102";       //Segregated value
var ppp= ".04210";    //Process payment per pound
var af = ".0075";      //Administration Fee (a reverse tax of sorts)
var lbs = "0";         //Pounds of non-crushed bottles
var crv = "0";         //CRV value elegibility
var pp = "0";          //Processing Payment
var afv = "0";         //Administration Fee Value
var total_crv = "0";   //Total CRV Value of Bottles
var rpcy = "600";      //Removal per cubic yard
var acfwm = "0";       //Avoided cost for waste management

/* consumer calculator constant values */
var con_alum_cpp = "29.3";
var con_alum_rvsp = "1.55";
var con_glass_cpp="1.89";
var con_glass_rvsp = ".102";
var con_pet_cpp="13.7";
var con_pet_rvsp=".89";
var con_hdpe_cpp = "5.9";
var con_hdpe_rvsp = ".51";

function ConsumerCalculate() {
	form = document.forms["form1"];
	
	containers = form.containers.value;
	containers = Math.round(containers.replace(/[^\d.]/g, ""));
	form.containers.value = containers;
	
	container_type = form.container_type.value;

	if (containers == "0") {
		form.containers.value = "";
		alert("Please enter the number of CRV containers you will be recycling");
		form.containers.focus();
		document.getElementById('container_calculation').innerHTML = "<b>Cash Back from Recycling Containers: $.00</b>";
		return false;
	}
	
	if (container_type == "aluminum")  {
		cpp= con_alum_cpp; 
		rsvp= con_alum_rvsp; 
	} else if (container_type == "glass") {
		cpp = con_glass_cpp; 
		rsvp = con_glass_rvsp; 
	} else if (container_type == "pet") {
		cpp = con_pet_cpp;
		rsvp = con_pet_rvsp; 
	} else if (container_type == "hdpe") {
		cpp = con_hdpe_cpp; 
		rsvp = con_hdpe_rvsp; 
	}

	consumer_savings = (containers/cpp)*rsvp;
	consumer_savings = consumer_savings.toFixed(2);
	
	document.getElementById('container_calculation').innerHTML = "<b>Cash Back from Recycling Containers: $" + consumer_savings + "</b>";

}


function RestaurantCalculate() {
	form = document.forms["form2"];
	
	num_bottles = form.bottles.value;
	num_bottles = Math.round(num_bottles.replace(/[^\d.]/g, ""));
	form.bottles.value = num_bottles;
		
	cost_per_yard = form.cost.value;
	cost_per_yard = cost_per_yard.replace(/[^\d.]/g, "");
	cost_per_yard = parseFloat(cost_per_yard);
	cost_per_yard = cost_per_yard.toFixed(2);
	form.cost.value = "$" + cost_per_yard;

	if (num_bottles == "0") {
		form.bottles.value = "";
		alert("Please enter the number of bottles you throw away");
		form.bottles.focus();
		document.getElementById('cost_calculation').innerHTML = "<b>Cash back from recycling bottles: $.00<br />Cost savings on Waste Removal: $.00</b>";
		return false;
	}

	if (cost_per_yard == "0.00") {
		form.cost.value = "";
		alert("Please enter the cost per cubic yard to empty dumpster");
		form.cost.focus();
		document.getElementById('cost_calculation').innerHTML = "<b>Cash back from recycling bottles: $.00<br />Cost savings on Waste Removal: $.00</b>";
		return false;
	}
	
	lbs = num_bottles / cpp;   //calculates pounds of non-crushed bottles  
	crv = lbs * cp;                            //calculates CRV value eligibility
	pp = ((cp/sv) * lbs) * ppp;            //calculates Processing Payment
	afv = crv * af;                            //calculates Administration Fee Value
	total_crv = crv + pp + afv;
	acfwm = (lbs/600) * cost_per_yard;
	
	//consumer_savings = Math.round(((containers/cpp)*rsvp) * 100) / 100;
	acfwm = acfwm.toFixed(2);
	crv = crv.toFixed(2);
	
	document.getElementById('cost_calculation').innerHTML = "<b>Cash back from recycling bottles: $" + crv + "<br />Cost savings on Waste Removal: $" + acfwm + "</b>";

}
