// JavaScript Document


var QCalc = {
	
	calculate:function(){
		
		var industry = detailedIndustry[document.forms["quick_calc"].elements["industry"].value];
		var state = document.forms["quick_calc"].elements["state"].value;
		var num_emp = document.forms["quick_calc"].elements["employees"].value;
		var sq_ft = document.forms["quick_calc"].elements["sq_ft"].value;
		
		if(num_emp == "" || num_emp <= 0){
			alert('Please enter the number of employees.');
			document.forms["quick_calc"].elements["employees"].focus();
			return false;
		}
		
		if(sq_ft == "" || sq_ft <= 0){
			alert('Please enter the square feet of office space you use.');
			document.forms["quick_calc"].elements["sq_ft"].focus();
			return false;
		}
		
		var co2 = 0;
		//electric average
			co2 += sq_ft * KwhByIndustry[industry] * StateElecAves[state] * 1.08;	
					
		//heating averages
			co2 += sq_ft * CfSqFtByIndustry[industry] * 0.12;
	
		//commute averages
			co2 += ((num_emp * 30 * 260) / 21) * 19.56;
		
		//update forms and total
			document.getElementById("footprint").innerHTML = QCalc.number_format(Math.round(co2/2000)) + ' tons of CO<sup>2</sup>';
		
		//var wind = Math.ceil(Math.round(co2/2));
		//var farm = Math.floor(Math.round(co2/2));
		
		document.getElementById("ot_wind_qty").value = Math.round(co2/2000) + ' tons of CO<sup>2</sup>'

						
	},
	offset:function(){
		var form = document.forms["OneTime"];
			form.submit();	
	},
	number_format:function(num){
		var nosign = true;
		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;
		if(cents == '00') cents = '';
		else cents = '.' + 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));
		var ds = nosign ? '' : '$';
		return (((sign)?'':'-') + ds + num  + cents);	
	}

}


/// switch order and update function to return the right value
var detailedIndustry = {
	
			"Education":"Education",
			"Food Sales":"Food Sales",
			"Grocery of Food Market":"Food Sales",
			"Convenience Store":"Food Sales",
			"Food Service":"Food Service",			
			"Health Care":"Health Care",
			"Health Care (Inpatient)":"Health Care (Inpatient)",
			"Health Care (Outpatient)":"Health Care (Outpatient)",
			"Veterinarian":"Health Care (Outpatient)",			
			"Lodging":"Lodging",
			"Dormitory, fraternity or sorority":"Lodging",
			"Nursing home, assisted living":"Lodging",			
			"Retail":"Retail",
			"Retail (other than mall)":"Retail",
			"Retail (enclosed and strip mall)":"Retail",
			"Office":"Office",
			"Office, administrative or professional":"Office",
			"Office, government":"Office",
			"Office, mixed-use":"Office",
			"Office, bank or other financial institution":"Office",
			"Office, Information Technology":"Office",
			"Office, medical":"Office",
			"Office, contractor (e.g. plumbing, construction, HVAC":"Office",
			"Office, non-profit or social services":"Office",
			"Office, call center":"Office",
			"Public Assembly":"Public Assembly",
			"Public Assembly, social or meeting (community center, lodge, town hall)":"Public Assembly",
			"Public Assembly, recreation (gymnasium, health club, blowing alley, ice rink)":"Public Assembly",
			"Public Assembly, entertainment (theatre, museum, cinema, club, casino)":"Public Assembly",
			"Public Assembly, other (library, funeral home, student center)":"Public Assembly",		
			"Public Order and Safety":"Public Order and Safety",
			"Public Order and Safety (police or fire station, jail, courthouse)":"Public Order and Safety",
			"Religious Worship":"Religious Worship",
			"Service":"Service",
			"Service, auto related (vehicle server, repair, storage)":"Service",
			"Service, personal (beauty or barber shop, tanning salon, cleaners, photo shop)":"Service",
			"Warehouse and Storage":"Warehouse and Storage",
			"Other (airplan hangar, crematorium, laratory, agricultural, industrial)":"Other"
}

var KwhByIndustry = {
	"Education":"11.0",
	"Food Sales":"49.4",
	"Food Service":"38.4",
	"Health Care":"22.9",
	"Health Care (Inpatient)":"27.5",
	"Health Care (Outpatient)":"16.1",
	"Lodging":"13.5",
	"Retail":"14.3",
	"Office":"17.3",
	"Public Assembly":"12.5",
	"Public Order and Safety":"15.3",
	"Religious Worship":"4.9",
	"Service":"11.0",
	"Warehouse and Storage":"7.6",
	"Other":"22.5"
	
}

var CfSqFtByIndustry = {
	"Education":"36.9",
	"Food Sales":"50.2",
	"Food Service":"141.2",
	"Health Care":"92.5",
	"Health Care (Inpatient)":"109.8",
	"Health Care (Outpatient)":"50.2",
	"Lodging":"48.9",
	"Retail":"30.9",
	"Office":"31.8",
	"Public Assembly":"36.4",
	"Public Order and Safety":"43.7",
	"Religious Worship":"30.3",
	"Service":"54.1",
	"Warehouse and Storage":"23.4",
	"Other":"67.6"
}


var StateElecAves = {
			"Alabama":"1.3",
			"Alaska":"1.11",
			"Arizona":"1.22",
			"Arkansas":"1.28",
			"California":"0.7",
			"Colorado":"1.99",
			"Connecticut":"0.75",
			"Delaware":"1.8",		
			"District of Columbia":"2.45",
			"Florida":"1.35",
			"Georgia":"1.39",
			"Hawaii":"1.65",
			"Idaho":"1.44",		
			"Illinois":"1.15",
			"Indiana":"2.1",
			"Iowa":"1.94",
			"Kansas":"1.87",
			"Kentucky":"2.05",
			"Louisiana":"1.2",		
		    "Maine":"0.77",
		    "Maryland":"2.45",
			"Massachusetts":"1.23",
			"Michigan":"1.41",
			"Minnesota":"1.59",
			"Mississippi":"1.41",		
			"Missouri":"1.41",
			"Montana":"1.59",
			"Nebraska":"1.5",
			"Nevada":"1.57",
		    "New Hampshire":"0.78",
			"New Jersey":"0.71",
			"New Mexico":"1.99",
			"New York":"0.91",
			"North Carolina":"1.22",
			"North Dakota":"2.39",
		    "Ohio":"1.78",		
			"Oklahoma":"1.73",
			"Oregon":"0.46",
			"Pennsylvania":"1.22",
			"Rhode Island":"1.07",
			"South Carolina":"0.91",		
			"South Dakota":"1.22",
			"Tennessee":"1.27",
			"Texas":"1.47",
			"Utah":"2.12",
		    "Vermont":"0.01",
			"Virginia":"1.21",		
		    "Washington":"0.36",
			"West Virginia":"1.99",
			"Wisconsin":"1.71",
			"Wyoming ":"2.28"		
}

	