/*
CARBON FOOTPRT CALCULATOR
Written by Adam Lacoste
Last updated 16 December 2008
*/

function calcAll() {
	//Get input source
	var inForm = document.getElementById('frmCalc');
	
	//Declare variables
	var inRooms = inForm.txtRooms.value; //# of rooms
	var inOcc = inForm.txtOcc.value; //% occupancy
	var inLinen = inForm.txtLinen.value; //lbs of linadj produced
	var inWCost = inForm.txtWCost.value; //$ cost of water
	var inGCost = inForm.txtGCost.value; //$ cost of gas
	var inWUnit = inForm.txtWUnit.value; //water units
	
	//method of calculation
	if (document.getElementById('rdoMethod1').checked) {
		var inMeth = 1;
	} else if (document.getElementById('rdoMethod2').checked) {
		var inMeth = 2;
	} else {
		var inMeth = 1;
	} //end if
	
	//term of linen production
	if (document.getElementById('rdoLTermDay').checked) {
		inLTerm = 1;
	} else if (document.getElementById('rdoLTermWeek').checked) {
		inLTerm = 2;
	} else if (document.getElementById('rdoLTermYear').checked) {
		inLTerm = 3;
	} else {
		inLTerm = 1;
	} //end if
	
	//type of hotel
	if (document.getElementById('rdoHotelLux').checked) {
		var inHotel = 1;
	} else if (document.getElementById('rdoHotelMid').checked) {
		var inHotel = 2;
	} else if (document.getElementById('rdoHotelEcon').checked) {
		var inHotel = 3;
	} else {
		var inHotel = 1;
	} //end if
	
	//type of industry
	if (document.getElementById('rdoIndHosp').checked) {
		var inInd = 1;
	} else if (document.getElementById('rdoIndHlth').checked) {
		var inInd = 2;
	} else {
		var inInd = 1;
	} //end if
	
	//production cycle
	if (document.getElementById('rdoProd1').checked) {
		var inProd = 1;
	} else if (document.getElementById('rdoProd2').checked) {
		var inProd = 2;
	} else {
		var inProd = 1;
	} //end if
	
	//water metric
	if (document.getElementById('rdoWMetGal').checked) {
		var inWMet = 1;
	} else if (document.getElementById('rdoWMetCF').checked) {
		var inWMet = 2;
	} else {
		var inWMet = 1;
	} //end if
	
	//gas metric
	if (document.getElementById('rdoGMetTherm').checked) {
		var inGMet = 1;
	} else if (document.getElementById('rdoGMetMCF').checked) {
		var inGMet = 2;
	} else if (document.getElementById('rdoGMetCCF').checked) {
		var inGMet = 3;
	} else {
		var inGMet = 1;
	} //end if
	
	var wcadj, gcadj, linadj, hwgal, hwlbs, hwbtu, hwcfp, hours, glwhs, glwls;
	
	var outWater = 0;
	var outWyear = 0;
	var outWyear = 0;
	var outNlcfp = 0;
	var outNlcfy = 0;
	var outGlcfp = 0;
	var outGlcfy = 0;
	var outCapnd = 0;
	var outGlwts = 0;
	var outGlwty = 0;
	var outGlwsv = 0;
	var outGlwsy = 0;
	var outTcnlw = 0;
	var outTcnwy = 0;
	var outTcglw = 0;
	var outTcgwy = 0;
	var outTsglw = 0;
	var outTsgwy = 0;
	var outTcnlg = 0;
	var outTcngy = 0;
	var outTcglg = 0;
	var outTcggy = 0;
	var outTsglg = 0;
	var outTsggy = 0;
	var outTsave = 0;
	var outTsavy = 0;
	var outErrorText = "";
	
	//Validation
	if (inMeth == null) { inMeth = 1; }
	if (inHotel == null) { inHotel = 1; }
	if (inRooms == null) { inRooms = 0; }
	if (inOcc == null) { inOcc = 0; }
	if (inLinen == null) { inLinen = 0; }
	if (inLTerm == null) { inLTerm = 1; }
	if (inInd == null) { inInd = 1; }
	if (inProd == null) { inProd = 1; }
	if (inWCost == null) { inWCost = 0; }
	if (inWMet == null) { inWMet = 1; }
	if (inGCost == null) { inGCost = 0; }
	if (inGMet == null) { inGMet = 1; }
	if (inWUnit == null && inWMet == 2) { inWUnit = 1000; }
	
	if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inRooms)) {
		inRooms = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Number of rooms\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else if (!isNumeric(inWCost)) {
		inWCost = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Water cost\&quot;.";
	} else if (!isNumeric(inGCost)) {
		inGCost = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Natural gas cost\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else if (inWCost < 0) {
		inWCost = 0;
		outErrorText = "ERROR: Dollar value outside acceptable range.";
	} else if (inGCost < 0) {
		inGCost = 0;
		outErrorText = "ERROR: Dollar value outside acceptable range.";
	} else if (inWUnit < 0) {
		inWUnit = 0;
		outErrorText = "ERROR: Numeric outside acceptable range.";
	} else {
		outErrorText = "";
	} //end if
	
	//Data preparation
	inRooms = Math.round(inRooms);  //round rooms to whole number
	switch (inWMet) {  //adjusted water cost per gallon
		case 1:
			wcadj = inWCost / 1000;
			break;
		case 2:
			wcadj = inWCost * 0.133680556 / inWUnit;
			break;
	} //end switch
	switch (inGMet) {  //adjusted gas cost per therm
		case 1:
			gcadj = inGCost;
			break;
		case 2:
			gcadj = inGCost / 10.27;
			break;
		case 3:
			gcadj = inGCost / 1.027;
			break;
	} //end switch
	
	//Calculations
	switch (inMeth) { //method of calculation
		case 1: // estimate
			switch (inHotel) {  //lbs of linen produced per day
				case 1:  //luxury
					linadj = 40 * inRooms * inOcc / 100;
					break;
				case 2:  //mid-scale
					linadj = 22.5 * inRooms * inOcc / 100;
					break;
				case 3:  //economy
					linadj = 10 * inRooms * inOcc / 100;
					break;
			} //end switch
			break;
		case 2: //calc
			switch (inLTerm) {  //lbs of linen produced per day
				case 1: //day
					linadj = inLinen;
					break;
				case 2: //week
					linadj = inLinen / 7;
					break;
				case 3: //year
					linadj = inLinen / 365.25;
					break;
			} //end switch
			break;
	} //end switch
	
	outWater = linadj * 3;  //gallons of water needed to wash linen  **OUTPUT**
	outWyear = outWater * 365.25;  //gallons of water needed to wash linen, yearly  **OUTPUT**
	hwgal = outWater * 0.7;  //gallons of hot water needed to wash linen
	hwlbs = hwgal * 8.3452641;  //weight of hot water
	hwbtu = hwlbs * 100;  //BTUs needed to heat water
	hwcfp = hwbtu * 0.00011708;  //Carbon footprint of water heating
	outNlcfp = hwcfp * 2;  //carbon footprint of normal laundry system  **OUTPUT**
	outNlcfy = outNlcfp * 365.25; //carbon footprint of normal laundry system, yearly  **OUTPUT**
	outGlcfp = outNlcfp * 0.3;  //carbon footprint of green laundry system  **OUTPUT**
	outGlcfy = outGlcfp * 365.25; //carbon footprint of green laundry system, yearly **OUTPUT**

	hours = inProd * 8;  //production cycle hours

	switch (inInd) {  //washer capacity needed  **OUTPUT**
		case 0:  //none selected
			outCapnd = 0;
			break;
		case 1:  //hospitality
			outCapnd = linadj / hours / 1.25;
			break;
		case 2:  //healthcare
			outCapnd = linadj / hours;
			break;
	} //end switch

	outGlwts = outWater * 0.35;  //total gallons of water used by green laundry system  **OUTPUT**
	outGlwty = outGlwts * 365.25;  //total gallons of water used by green laundry system, yearly  **OUTPUT**
	outGlwsv = outWater * 0.65;  //total gallons of water saved by using green laundry system  **OUTPUT**
	outGlwsy = outGlwsv * 365.25;  //total gallons of water saved by using green laundry system, yearly  **OUTPUT**

	outTcnlw = outWater * wcadj;  //total cost of water per day for normal laundry system  **OUTPUT**
	outTcnwy = outTcnlw * 365.25;  //total cost of water per year for normal laundry system  **OUTPUT**
	outTcglw = outGlwts * wcadj;  //total cost of water per day for green laundry system  **OUTPUT**
	outTcgwy = outTcglw * 365.25;  //total cost of water per year for green laundry system  **OUTPUT**
	outTsglw = outTcnlw - outTcglw;  //total water cost savings per day with green laundry system  **OUTPUT**
	outTsgwy = outTsglw * 365.25;  //total water cost savings per year with green laundry system  **OUTPUT**

	outTcnlg = hwbtu * 2 / 100000 * gcadj;  //total cost of gas per day for normal laundry system  **OUTPUT**
	outTcngy = outTcnlg * 365.25;  //total cost of gas per year for normal laundry system  **OUTPUT**
	outTcglg = outTcnlg * 0.3;  //total cost of gas per day for green laundry system  **OUTPUT**
	outTcggy = outTcglg * 365.25;  //total cost of gas per year for green laundry system **OUTPUT**
	outTsglg = outTcnlg - outTcglg;  //total gas cost savings per day with green laundry system  **OUTPUT**
	outTsggy = outTsglg * 365.25;  //total gas cost per year with green laundry system  **OUTPUT**
	
	outTsave = outTsglw + outTsglg;  //total savings on water and gas per day with green laundry system  **OUTPUT**
	outTsavy = outTsave * 365.25;  //total savings on water and gas per year with green laundry system  **OUTPUT**

	//Output
	document.getElementById('out_errortext').innerHTML = outErrorText;
	document.getElementById('out_nlcfp').innerHTML = outFormat(outNlcfp,1);
	document.getElementById('out_nlcfy').innerHTML = outFormat(outNlcfy,1);
	document.getElementById('out_glcfp').innerHTML = outFormat(outGlcfp,1);
	document.getElementById('out_glcfy').innerHTML = outFormat(outGlcfy,1);
	document.getElementById('out_capnd').innerHTML = outFormat(outCapnd,1);
	document.getElementById('out_water').innerHTML = outFormat(outWater,1);
	document.getElementById('out_wyear').innerHTML = outFormat(outWyear,1);
	document.getElementById('out_glwts').innerHTML = outFormat(outGlwts,1);
	document.getElementById('out_glwty').innerHTML = outFormat(outGlwty,1);
	document.getElementById('out_glwsv').innerHTML = outFormat(outGlwsv,1);
	document.getElementById('out_glwsy').innerHTML = outFormat(outGlwsy,1);
	document.getElementById('out_tcnlw').innerHTML = outFormat(outTcnlw);
	document.getElementById('out_tcnwy').innerHTML = outFormat(outTcnwy);
	document.getElementById('out_tcglw').innerHTML = outFormat(outTcglw);
	document.getElementById('out_tcgwy').innerHTML = outFormat(outTcgwy);
	document.getElementById('out_tsglw').innerHTML = outFormat(outTsglw);
	document.getElementById('out_tsgwy').innerHTML = outFormat(outTsgwy);
	document.getElementById('out_tcnlg').innerHTML = outFormat(outTcnlg);
	document.getElementById('out_tcngy').innerHTML = outFormat(outTcngy);
	document.getElementById('out_tcglg').innerHTML = outFormat(outTcglg);
	document.getElementById('out_tcggy').innerHTML = outFormat(outTcggy);
	document.getElementById('out_tsglg').innerHTML = outFormat(outTsglg);
	document.getElementById('out_tsggy').innerHTML = outFormat(outTsggy);
	document.getElementById('out_tsave').innerHTML = outFormat(outTsave);
	document.getElementById('out_tsavy').innerHTML = outFormat(outTsavy);
} //end function calcAll()

function calcCapacity() {
	//Get input source
	var inForm = document.getElementById('frmCalc');
	//Declare variables
	var inRooms = inForm.txtRooms.value; //# of rooms
	var inOcc = inForm.txtOcc.value; //% occupancy
	var inLinen = inForm.txtLinen.value; //lbs of linadj produced
	
	//method of calculation
	if (document.getElementById('rdoMethod1').checked) {
		var inMeth = 1;
	} else if (document.getElementById('rdoMethod2').checked) {
		var inMeth = 2;
	} else {
		var inMeth = 1;
	} //end if
	
	//term of linen production
	if (document.getElementById('rdoLTermDay').checked) {
		inLTerm = 1;
	} else if (document.getElementById('rdoLTermWeek').checked) {
		inLTerm = 2;
	} else if (document.getElementById('rdoLTermYear').checked) {
		inLTerm = 3;
	} else {
		inLTerm = 1;
	} //end if
	
	//type of hotel
	if (document.getElementById('rdoHotelLux').checked) {
		var inHotel = 1;
	} else if (document.getElementById('rdoHotelMid').checked) {
		var inHotel = 2;
	} else if (document.getElementById('rdoHotelEcon').checked) {
		var inHotel = 3;
	} else {
		var inHotel = 1;
	} //end if
	
	//var inInd =  inForm.rdoInd.value;
	if (document.getElementById('rdoIndHosp').checked) {
		inInd = 1;
	} else if (document.getElementById('rdoIndHlth').checked) {
		inInd = 2;
	} else {
		inInd = 1;
	} //end if
	
	//var inProd =  inForm.rdoProd.value;
	if (document.getElementById('rdoProd1').checked) {
		inProd = 1;
	} else if (document.getElementById('rdoProd2').checked) {
		inProd = 2;
	} else {
		inProd = 1;
	} //end if
	
	var wcadj, gcadj, linadj, hwgal, hwlbs, hwbtu, hwcfp, hours;
	
	var outWater = 0;
	var outWyear = 0;
	var outNlcfp = 0;
	var outNlcfy = 0;
	var outGlcfp = 0;
	var outGlcfy = 0;
	var outCapnd = 0;
	var outErrorText = "";
	
	//Validation
	if (inMeth == null) { inMeth = 1; }
	if (inHotel == null) { inHotel = 1; }
	if (inRooms == null) { inRooms = 0; }
	if (inOcc == null) { inOcc = 0; }
	if (inLinen == null) { inLinen = 0; }
	if (inLTerm == null) { inLTerm = 1; }
	if (inInd == null) { inInd = 1; }
	if (inProd == null) { inProd = 1; }
	
	if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inRooms)) {
		inRooms = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Number of rooms\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else {
		outErrorText = "";
	} //end if
	
	//Data preparation
	inRooms = Math.round(inRooms);  //round rooms to whole number
	
	///Calculations
	switch (inMeth) { //method of calculation
		case 1: // estimate
			switch (inHotel) {  //lbs of linen produced per day
				case 1:  //luxury
					linadj = 40 * inRooms * inOcc / 100;
					break;
				case 2:  //mid-scale
					linadj = 22.5 * inRooms * inOcc / 100;
					break;
				case 3:  //economy
					linadj = 10 * inRooms * inOcc / 100;
					break;
			} //end switch
			break;
		case 2: //calc
			switch (inLTerm) {  //lbs of linen produced per day
				case 1: //day
					linadj = inLinen;
					break;
				case 2: //week
					linadj = inLinen / 7;
					break;
				case 3: //year
					linadj = inLinen / 365.25;
					break;
			} //end switch
			break;
	} //end switch
	
	outWater = linadj * 3;  //gallons of water needed to wash linen  **OUTPUT**
	outWyear = outWater * 365.25;  //gallons of water needed to wash linen, yearly  **OUTPUT**
	hwgal = outWater * 0.7;  //gallons of hot water needed to wash linadj
	hwlbs = hwgal * 8.3452641;  //weight of hot water
	hwbtu = hwlbs * 100;  //BTUs needed to heat water
	hwcfp = hwbtu * 0.00011708;  //Carbon footprint of water heating
	outNlcfp = hwcfp * 2;  //carbon footprint of normal laundry system  **OUTPUT**
	outNlcfy = outNlcfp * 365.25; //carbon footprint of normal laundry system, yearly  **OUTPUT**
	outGlcfp = outNlcfp * 0.3;  //carbon footprint of green laundry system  **OUTPUT**
	outGlcfy = outGlcfp * 365.25; //carbon footprint of green laundry system, yearly **OUTPUT**

	hours = inProd * 8;  //production cycle hours

	switch (inInd) {  //washer capacity needed  **OUTPUT**
		case 0:  //none selected
			outCapnd = 0;
			break;
		case 1:  //hospitality
			outCapnd = linadj / hours / 1.25;
			break;
		case 2:  //healthcare
			outCapnd = linadj / hours;
			break;
	} //end switch

	//Output
	document.getElementById('out_errortext').innerHTML = outErrorText;
	document.getElementById('out_capnd').innerHTML = outFormat(outCapnd,1);
} //end function calcCapacity()

function calcCarbon() {
	//Get input source
	var inForm = document.getElementById('frmCalc');
	//Declare variables
	var inRooms = inForm.txtRooms.value; //# of rooms
	var inOcc = inForm.txtOcc.value; //% occupancy
	var inLinen = inForm.txtLinen.value; //lbs of linadj produced
	
	//method of calculation
	if (document.getElementById('rdoMethod1').checked) {
		var inMeth = 1;
	} else if (document.getElementById('rdoMethod2').checked) {
		var inMeth = 2;
	} else {
		var inMeth = 1;
	} //end if
	
	//term of linen production
	if (document.getElementById('rdoLTermDay').checked) {
		inLTerm = 1;
	} else if (document.getElementById('rdoLTermWeek').checked) {
		inLTerm = 2;
	} else if (document.getElementById('rdoLTermYear').checked) {
		inLTerm = 3;
	} else {
		inLTerm = 1;
	} //end if
	
	//type of hotel
	if (document.getElementById('rdoHotelLux').checked) {
		var inHotel = 1;
	} else if (document.getElementById('rdoHotelMid').checked) {
		var inHotel = 2;
	} else if (document.getElementById('rdoHotelEcon').checked) {
		var inHotel = 3;
	} else {
		var inHotel = 1;
	} //end if
	
	var wcadj, gcadj, linadj, hwgal, hwlbs, hwbtu, hwcfp;
	
	var outWater = 0;
	var outWyear = 0;
	var outNlcfp = 0;
	var outNlcfy = 0;
	var outGlcfp = 0;
	var outGlcfy = 0;
	var outErrorText = "";
	
	//Validation
	if (inMeth == null) { inMeth = 1; }
	if (inHotel == null) { inHotel = 1; }
	if (inRooms == null) { inRooms = 0; }
	if (inOcc == null) { inOcc = 0; }
	if (inLinen == null) { inLinen = 0; }
	if (inLTerm == null) { inLTerm = 1; }
	
	if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inRooms)) {
		inRooms = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Number of rooms\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else {
		outErrorText = "";
	} //end if
	
	//Data preparation
	inRooms = Math.round(inRooms);  //round rooms to whole number
	
	///Calculations
	switch (inMeth) { //method of calculation
		case 1: // estimate
			switch (inHotel) {  //lbs of linen produced per day
				case 1:  //luxury
					linadj = 40 * inRooms * inOcc / 100;
					break;
				case 2:  //mid-scale
					linadj = 22.5 * inRooms * inOcc / 100;
					break;
				case 3:  //economy
					linadj = 10 * inRooms * inOcc / 100;
					break;
			} //end switch
			break;
		case 2: //calc
			switch (inLTerm) {  //lbs of linen produced per day
				case 1: //day
					linadj = inLinen;
					break;
				case 2: //week
					linadj = inLinen / 7;
					break;
				case 3: //year
					linadj = inLinen / 365.25;
					break;
			} //end switch
			break;
	} //end switch
	
	outWater = linadj * 3;  //gallons of water needed to wash linen  **OUTPUT**
	outWyear = outWater * 365.25;  //gallons of water needed to wash linen, yearly  **OUTPUT**
	hwgal = outWater * 0.7;  //gallons of hot water needed to wash linen
	hwlbs = hwgal * 8.3452641;  //weight of hot water
	hwbtu = hwlbs * 100;  //BTUs needed to heat water
	hwcfp = hwbtu * 0.00011708;  //Carbon footprint of water heating
	outNlcfp = hwcfp * 2;  //carbon footprint of normal laundry system  **OUTPUT**
	outNlcfy = outNlcfp * 365.25; //carbon footprint of normal laundry system, yearly  **OUTPUT**
	outGlcfp = outNlcfp * 0.3;  //carbon footprint of green laundry system  **OUTPUT**
	outGlcfy = outGlcfp * 365.25; //carbon footprint of green laundry system, yearly **OUTPUT**

	//Output
	document.getElementById('out_errortext').innerHTML = outErrorText;
	document.getElementById('out_nlcfp').innerHTML = outFormat(outNlcfp,1);
	document.getElementById('out_nlcfy').innerHTML = outFormat(outNlcfy,1);
	document.getElementById('out_glcfp').innerHTML = outFormat(outGlcfp,1);
	document.getElementById('out_glcfy').innerHTML = outFormat(outGlcfy,1);
} //end function calcCarbon()

function calcGas() {
	//Get input source
	var inForm = document.getElementById('frmCalc');
	//Declare variables
	var inRooms = inForm.txtRooms.value; //# of rooms
	var inOcc = inForm.txtOcc.value; //% occupancy
	var inLinen = inForm.txtLinen.value; //lbs of linadj produced
	var inGCost =  inForm.txtGCost.value;
	
	//method of calculation
	if (document.getElementById('rdoMethod1').checked) {
		var inMeth = 1;
	} else if (document.getElementById('rdoMethod2').checked) {
		var inMeth = 2;
	} else {
		var inMeth = 1;
	} //end if
	
	//term of linen production
	if (document.getElementById('rdoLTermDay').checked) {
		inLTerm = 1;
	} else if (document.getElementById('rdoLTermWeek').checked) {
		inLTerm = 2;
	} else if (document.getElementById('rdoLTermYear').checked) {
		inLTerm = 3;
	} else {
		inLTerm = 1;
	} //end if
	
	//type of hotel
	if (document.getElementById('rdoHotelLux').checked) {
		var inHotel = 1;
	} else if (document.getElementById('rdoHotelMid').checked) {
		var inHotel = 2;
	} else if (document.getElementById('rdoHotelEcon').checked) {
		var inHotel = 3;
	} else {
		var inHotel = 1;
	} //end if
	
	//var inGMet =  inForm.rdoGMet.value;
	if (document.getElementById('rdoGMetTherm').checked) {
		inGMet = 1;
	} else if (document.getElementById('rdoGMetMCF').checked) {
		inGMet = 2;
	} else if (document.getElementById('rdoGMetCCF').checked) {
		inGMet = 3;
	} else {
		inGMet = 1;
	} //end if
	
	var wcadj, gcadj, linadj, hwgal, hwlbs, hwbtu, hwcfp;
	
	var outWater = 0;
	var outWyear = 0;
	var outNlcfp = 0;
	var outNlcfy = 0;
	var outGlcfp = 0;
	var outGlcfy = 0;
	var outTcnlg = 0;
	var outTcngy = 0;
	var outTcglg = 0;
	var outTcggy = 0;
	var outTsglg = 0;
	var outTsggy = 0;
	var outErrorText = "";
	
	//Validation
	if (inMeth == null) { inMeth = 1; }
	if (inHotel == null) { inHotel = 1; }
	if (inRooms == null) { inRooms = 0; }
	if (inOcc == null) { inOcc = 0; }
	if (inLinen == null) { inLinen = 0; }
	if (inLTerm == null) { inLTerm = 1; }
	if (inGCost == null) { inGCost = 0; }
	if (inGMet == null) { inGMet = 1; }
	
	if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inRooms)) {
		inRooms = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Number of rooms\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else if (!isNumeric(inGCost)) {
		inGCost = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Natural gas cost\&quot;.";
	} else if (inGCost < 0) {
		inGCost = 0;
		outErrorText = "ERROR: Dollar value outside acceptable range.";
	} else {
		outErrorText = "";
	} //end if
	
	//Data preparation
	inRooms = Math.round(inRooms);  //round rooms to whole number
	switch (inGMet) {  //adjusted gas cost per therm
		case 1:
			gcadj = inGCost;
			break;
		case 2:
			gcadj = inGCost / 10.27;
			break;
		case 3:
			gcadj = inGCost / 1.027;
			break;
	} //end switch
	
	///Calculations
	switch (inMeth) { //method of calculation
		case 1: // estimate
			switch (inHotel) {  //lbs of linen produced per day
				case 1:  //luxury
					linadj = 40 * inRooms * inOcc / 100;
					break;
				case 2:  //mid-scale
					linadj = 22.5 * inRooms * inOcc / 100;
					break;
				case 3:  //economy
					linadj = 10 * inRooms * inOcc / 100;
					break;
			} //end switch
			break;
		case 2: //calc
			switch (inLTerm) {  //lbs of linen produced per day
				case 1: //day
					linadj = inLinen;
					break;
				case 2: //week
					linadj = inLinen / 7;
					break;
				case 3: //year
					linadj = inLinen / 365.25;
					break;
			} //end switch
			break;
	} //end switch
	
	outWater = linadj * 3;  //gallons of water needed to wash linen  **OUTPUT**
	outWyear = outWater * 365.25;  //gallons of water needed to wash linen, yearly  **OUTPUT**
	hwgal = outWater * 0.7;  //gallons of hot water needed to wash linen
	hwlbs = hwgal * 8.3452641;  //weight of hot water
	hwbtu = hwlbs * 100;  //BTUs needed to heat water
	hwcfp = hwbtu * 0.00011708;  //Carbon footprint of water heating
	outNlcfp = hwcfp * 2;  //carbon footprint of normal laundry system  **OUTPUT**
	outNlcfy = outNlcfp * 365.25; //carbon footprint of normal laundry system, yearly  **OUTPUT**
	outGlcfp = outNlcfp * 0.3;  //carbon footprint of green laundry system  **OUTPUT**
	outGlcfy = outGlcfp * 365.25; //carbon footprint of green laundry system, yearly **OUTPUT**

	outTcnlg = hwbtu * 2 / 100000 * gcadj;  //total cost of gas per day for normal laundry system  **OUTPUT**
	outTcngy = outTcnlg * 365.25;  //total cost of gas per year for normal laundry system  **OUTPUT**
	outTcglg = outTcnlg * 0.3;  //total cost of gas per day for green laundry system  **OUTPUT**
	outTcggy = outTcglg * 365.25;  //total cost of gas per year for green laundry system **OUTPUT**
	outTsglg = outTcnlg - outTcglg;  //total gas cost savings per day with green laundry system  **OUTPUT**
	outTsggy = outTsglg * 365.25;  //total gas cost per year with green laundry system  **OUTPUT**

	//Output
	document.getElementById('out_errortext').innerHTML = outErrorText;
	document.getElementById('out_tcnlg').innerHTML = outFormat(outTcnlg);
	document.getElementById('out_tcngy').innerHTML = outFormat(outTcngy);
	document.getElementById('out_tcglg').innerHTML = outFormat(outTcglg);
	document.getElementById('out_tcggy').innerHTML = outFormat(outTcggy);
	document.getElementById('out_tsglg').innerHTML = outFormat(outTsglg);
	document.getElementById('out_tsggy').innerHTML = outFormat(outTsggy);
} //end function calcGas()

function calcWater() {
	//Get input source
	var inForm = document.getElementById('frmCalc');
	//Declare variables
	var inRooms = inForm.txtRooms.value; //# of rooms
	var inOcc = inForm.txtOcc.value; //% occupancy
	var inLinen = inForm.txtLinen.value; //lbs of linadj produced
	var inWCost =  inForm.txtWCost.value;
	var inWUnit =  inForm.txtWUnit.value;
	
	//method of calculation
	if (document.getElementById('rdoMethod1').checked) {
		var inMeth = 1;
	} else if (document.getElementById('rdoMethod2').checked) {
		var inMeth = 2;
	} else {
		var inMeth = 1;
	} //end if
	
	//term of linen production
	if (document.getElementById('rdoLTermDay').checked) {
		inLTerm = 1;
	} else if (document.getElementById('rdoLTermWeek').checked) {
		inLTerm = 2;
	} else if (document.getElementById('rdoLTermYear').checked) {
		inLTerm = 3;
	} else {
		inLTerm = 1;
	} //end if
	
	//type of hotel
	if (document.getElementById('rdoHotelLux').checked) {
		var inHotel = 1;
	} else if (document.getElementById('rdoHotelMid').checked) {
		var inHotel = 2;
	} else if (document.getElementById('rdoHotelEcon').checked) {
		var inHotel = 3;
	} else {
		var inHotel = 1;
	} //end if
	
	//var inWMet =  inForm.rdoWMet.value;
	if (document.getElementById('rdoWMetGal').checked) {
		inWMet = 1;
	} else if (document.getElementById('rdoWMetCF').checked) {
		inWMet = 2;
	} else {
		inWMet = 1;
	} //end if
	
	var wcadj, gcadj, linadj, hwgal, hwlbs, hwbtu, hwcfp, hours, glwhs, glwls;
	
	var outWater = 0;
	var outWyear = 0;
	var outNlcfp = 0;
	var outNlcfy = 0;
	var outGlcfp = 0;
	var outGlcfy = 0;
	var outGlwts = 0;
	var outGlwty = 0;
	var outGlwsv = 0;
	var outGlwsy = 0;
	var outTcnlw = 0;
	var outTcnwy = 0;
	var outTcglw = 0;
	var outTcgwy = 0;
	var outTsglw = 0;
	var outTsgwy = 0;
	var outErrorText = "";
	
	//Validation
	if (inMeth == null) { inMeth = 1; }
	if (inHotel == null) { inHotel = 1; }
	if (inRooms == null) { inRooms = 0; }
	if (inOcc == null) { inOcc = 0; }
	if (inLinen == null) { inLinen = 0; }
	if (inLTerm == null) { inLTerm = 1; }
	if (inWCost == null) { inWCost = 0; }
	if (inWMet == null) { inWMet = 1; }
	if (inWUnit == null && inWMet == 2) { inWUnit = 1000; }
	
	if (!isNumeric(inOcc)) {
		inOcc = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Occupancy\&quot;.";
	} else if (!isNumeric(inLinen)) {
		inLinen = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Linen\&quot;.";
	} else if (!isNumeric(inRooms)) {
		inRooms = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Number of rooms\&quot;.";
	} else if (inOcc < 0) {
		inOcc = 0;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inOcc > 100) {
		inOcc = 100;
		outErrorText = "ERROR: Percentage value outside acceptable range.";
	} else if (inLinen < 0) {
		inLinen = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else if (!isNumeric(inWCost)) {
		inWCost = 0;
		outErrorText = "ERROR: Please input a numeric value for \&quot;Water cost\&quot;.";
	} else if (inWCost < 0) {
		inWCost = 0;
		outErrorText = "ERROR: Dollar value outside acceptable range.";
	} else if (inWUnit < 0) {
		inWUnit = 0;
		outErrorText = "ERROR: Numeric value outside acceptable range.";
	} else {
		outErrorText = "";
	} //end if
	
	//Data preparation
	inRooms = Math.round(inRooms);  //round rooms to whole number
	switch (inWMet) {  //adjusted water cost per gallon
		case 1:
			wcadj = inWCost / 1000;
			break;
		case 2:
			wcadj = inWCost * 0.133680556 / inWUnit;
			break;
	} //end switch
	
	///Calculations
	switch (inMeth) { //method of calculation
		case 1: // estimate
			switch (inHotel) {  //lbs of linen produced per day
				case 1:  //luxury
					linadj = 40 * inRooms * inOcc / 100;
					break;
				case 2:  //mid-scale
					linadj = 22.5 * inRooms * inOcc / 100;
					break;
				case 3:  //economy
					linadj = 10 * inRooms * inOcc / 100;
					break;
			} //end switch
			break;
		case 2: //calc
			switch (inLTerm) {  //lbs of linen produced per day
				case 1: //day
					linadj = inLinen;
					break;
				case 2: //week
					linadj = inLinen / 7;
					break;
				case 3: //year
					linadj = inLinen / 365.25;
					break;
			} //end switch
			break;
	} //end switch
	
	outWater = linadj * 3;  //gallons of water needed to wash linen  **OUTPUT**
	outWyear = outWater * 365.25;  //gallons of water needed to wash linen, yearly  **OUTPUT**
	hwgal = outWater * 0.7;  //gallons of hot water needed to wash linen
	hwlbs = hwgal * 8.3452641;  //weight of hot water
	hwbtu = hwlbs * 100;  //BTUs needed to heat water
	hwcfp = hwbtu * 0.00011708;  //Carbon footprint of water heating
	outNlcfp = hwcfp * 2;  //carbon footprint of normal laundry system  **OUTPUT**
	outNlcfy = outNlcfp * 365.25; //carbon footprint of normal laundry system, yearly  **OUTPUT**
	outGlcfp = outNlcfp * 0.3;  //carbon footprint of green laundry system  **OUTPUT**
	outGlcfy = outGlcfp * 365.25; //carbon footprint of green laundry system, yearly **OUTPUT**

	outGlwts = outWater * 0.35;  //total gallons of water used by green laundry system  **OUTPUT**
	outGlwty = outGlwts * 365.25;  //total gallons of water used by green laundry system, yearly  **OUTPUT**
	outGlwsv = outWater * 0.65;  //total gallons of water saved by using green laundry system  **OUTPUT**
	outGlwsy = outGlwsv * 365.25;  //total gallons of water saved by using green laundry system, yearly  **OUTPUT**

	outTcnlw = outWater * wcadj;  //total cost of water per day for normal laundry system  **OUTPUT**
	outTcnwy = outTcnlw * 365.25;  //total cost of water per year for normal laundry system  **OUTPUT**
	outTcglw = outGlwts * wcadj;  //total cost of water per day for green laundry system  **OUTPUT**
	outTcgwy = outTcglw * 365.25;  //total cost of water per year for green laundry system  **OUTPUT**
	outTsglw = outTcnlw - outTcglw;  //total water cost savings per day with green laundry system  **OUTPUT**
	outTsgwy = outTsglw * 365.25;  //total water cost savings per year with green laundry system  **OUTPUT**

	//Output
	document.getElementById('out_errortext').innerHTML = outErrorText;
	document.getElementById('out_water').innerHTML = outFormat(outWater,1);
	document.getElementById('out_wyear').innerHTML = outFormat(outWyear,1);
	document.getElementById('out_glwts').innerHTML = outFormat(outGlwts,1);
	document.getElementById('out_glwty').innerHTML = outFormat(outGlwty,1);
	document.getElementById('out_glwsv').innerHTML = outFormat(outGlwsv,1);
	document.getElementById('out_glwsy').innerHTML = outFormat(outGlwsy,1);
	document.getElementById('out_tcnlw').innerHTML = outFormat(outTcnlw);
	document.getElementById('out_tcnwy').innerHTML = outFormat(outTcnwy);
	document.getElementById('out_tcglw').innerHTML = outFormat(outTcglw);
	document.getElementById('out_tcgwy').innerHTML = outFormat(outTcgwy);
	document.getElementById('out_tsglw').innerHTML = outFormat(outTsglw);
	document.getElementById('out_tsgwy').innerHTML = outFormat(outTsgwy);
} //end function calcWater()

function changeMethod() {
	var m1 = document.getElementById('rdoMethod1');
	var m2 = document.getElementById('rdoMethod2');
	var c1 = document.getElementById('calcmethod1');
	var c2 = document.getElementById('calcmethod2');
	
	if (m1.checked) {
		c1.style.display = "block";
		c2.style.display = "none";
	} else if (m2.checked) {
		c1.style.display = "none";
		c2.style.display = "block";
	} else {
		c1.style.display = "none";
		c2.style.display = "none";
	} //end if
} //end function changeMethod()

function isNumeric(number) {
	if (number != parseFloat(number)) {
		return false;
	} else {
		return true;
	} //end if
} //end function isNumeric()

function outFormat(number,type) {
	if (type == 1) {
		//adapted from code by William Bontrager
		var delimiter = ","; // replace comma if desired
		var i = parseInt(number);
		if(isNaN(i)) { return ''; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3)
		{
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if(n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		number = minus + n;
	} else {
		number = CurrencyFormatted(number);
		number = CommaFormatted(number);
	} //end if
	
	return number;
} //end function outFormat()

//Currency and Comma Formatting
//Courtesy of William Bontrager
function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
} // end of function CurrencyFormatted()

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
} // end of function CommaFormatted()