//Set up the function which will define each state's data
function stdatel(sname,co2lbs,ch4lbs,n2olbs,so2lbs,noxlbs,hgmgs)
{
    this.sname = sname;
    this.co2lbs = co2lbs;
    this.ch4lbs = ch4lbs;
	this.n2olbs = n2olbs;
	this.so2lbs = so2lbs;
	this.noxlbs = noxlbs;
    this.hgmgs = hgmgs;
}


//Create the array with the name States
var States = new Object();
                 
//Define the members of the array
States[0] = new stdatel("U.S. Average", 1.676694473, 0.000038, 0.000021, 0.006495482, 0.002342508, 0.01167261);
States[1] = new stdatel("Alabama", 1.824658906, 0.000044, 0.000030, 0.010283949, 0.002871584, 0.018685783);
States[2] = new stdatel("Alaska", 1.557326429, 0.000043, 0.000009, 0.002689331, 0.006407162, 0);
States[3] = new stdatel("Arizona", 1.244731338, 0.000021, 0.000010, 0.000876323, 0.000988577, 0.004563366);
States[4] = new stdatel("Arkansas", 1.664912569, 0.000048, 0.000026, 0.00345647, 0.001923674, 0.010327618);
States[5] = new stdatel("California", 1.123738682, 0.000042, 0.000005, 0.000057186, 0.00029832, 0.000960709);
States[6] = new stdatel("Colorado", 1.700892305, 0.000023, 0.000022, 0.002131238, 0.002105716, 0.00557211);
States[7] = new stdatel("Connecticut", 1.566019866, 0.000082, 0.000018, 0.001448077, 0.001220392, 0.005379968);
States[8] = new stdatel("Delaware", 2.062769761, 0.000042, 0.000025, 0.007235829, 0.003287983, 0.01556348);
States[9] = new stdatel("District of Columbia", 2.575807289, 0.000111, 0.000022, 0.00856731, 0.003869374, 0);
States[10] = new stdatel("Florida", 1.464515987, 0.000050, 0.000015, 0.004017528, 0.002051495, 0.00273802);
States[11] = new stdatel("Georgia", 1.752249887, 0.000035, 0.000026, 0.0115431, 0.002455292, 0.010711901);
States[12] = new stdatel("Hawaii", 1.906993509, 0.000197, 0.000032, 0.004509116, 0.005642776, 0.005956394);
States[13] = new stdatel("Idaho", 0.692131901, 0.000076, 0.000015, 0.000862661, 0.000551315, 0);
States[14] = new stdatel("Illinois", 2.220806767, 0.000027, 0.000035, 0.007610398, 0.002935124, 0.039004771);
States[15] = new stdatel("Indiana", 2.245888547, 0.000027, 0.000036, 0.016145196, 0.003794821, 0.020222917);
States[16] = new stdatel("Iowa", 2.372175144, 0.000029, 0.000038, 0.007403575, 0.004331098, 0.025410744);
States[17] = new stdatel("Kansas", 2.49014912, 0.000039, 0.000037, 0.009451151, 0.00594565, 0.017629004);
States[18] = new stdatel("Kentucky", 2.238380342, 0.000027, 0.000037, 0.01259331, 0.003705971, 0.018013287);
States[19] = new stdatel("Louisiana", 1.371340719, 0.000029, 0.000011, 0.002069074, 0.001922932, 0.003410516);
States[20] = new stdatel("Maine", 1.33557956, 0.000280, 0.000039, 0.002777016, 0.001492131, 0.000672496);
States[21] = new stdatel("Maryland", 2.08043134, 0.000053, 0.000033, 0.018203363, 0.003976757, 0.026899842);
States[22] = new stdatel("Massachusetts", 1.372108494, 0.000048, 0.000013, 0.003497136, 0.000997684, 0.003650693);
States[23] = new stdatel("Michigan", 1.798486357, 0.000031, 0.000029, 0.00780303, 0.002543083, 0.017196685);
States[24] = new stdatel("Minnesota", 2.226947167, 0.000077, 0.000039, 0.006361095, 0.005433305, 0.013690098);
States[25] = new stdatel("Mississippi", 1.560613035, 0.000031, 0.000018, 0.004531249, 0.002803173, 0.005908358);
States[26] = new stdatel("Missouri", 2.151855912, 0.000027, 0.000033, 0.00838728, 0.003980146, 0.016235976);
States[27] = new stdatel("Montana", 2.923821905, 0.000080, 0.000053, 0.006488811, 0.003678225, 0.015419374);
States[28] = new stdatel("Nebraska", 2.300665004, 0.000031, 0.000031, 0.00628866, 0.004967875, 0.016956507);
States[29] = new stdatel("Nevada", 1.328357815, 0.000023, 0.000008, 0.000920801, 0.00141027, 0.00283409);
States[30] = new stdatel("New Hampshire", 1.44297868, 0.000067, 0.000017, 0.00663347, 0.001368969, 0.001008744);
States[31] = new stdatel("New Jersey", 1.551217905, 0.000038, 0.000018, 0.004807013, 0.002294747, 0.008982626);
States[32] = new stdatel("New Mexico", 1.568190922, 0.000026, 0.000011, 0.000681043, 0.002678211, 0.009270838);
States[33] = new stdatel("New York", 1.607305722, 0.000055, 0.000015, 0.004692853, 0.001719392, 0.005908358);
States[34] = new stdatel("North Carolina", 2.067280254, 0.000032, 0.000033, 0.012333961, 0.003285548, 0.020943448);
States[35] = new stdatel("North Dakota", 2.656929018, 0.000043, 0.000044, 0.011349303, 0.006046996, 0.038188168);
States[36] = new stdatel("Ohio", 2.10583675, 0.000026, 0.000034, 0.02193189, 0.004103096, 0.029349649);
States[37] = new stdatel("Oklahoma", 1.369956394, 0.000023, 0.000011, 0.001442146, 0.002186729, 0.005187827);
States[38] = new stdatel("Oregon", 1.058734721, 0.000045, 0.000012, 0.001202812, 0.001058576, 0.003170339);
States[39] = new stdatel("Pennsylvania", 1.954020839, 0.000037, 0.000027, 0.013159664, 0.002740904, 0.025266637);
States[40] = new stdatel("Rhode Island", 1.11545116, 0.000022, 0.000002, 8.48E-05, 0.000336762, 0);
States[41] = new stdatel("South Carolina", 1.864760589, 0.000030, 0.000027, 0.008157477, 0.002021525, 0.010039405);
States[42] = new stdatel("South Dakota", 2.355517603, 0.000031, 0.000032, 0.005873108, 0.007408129, 0.007637634);
States[43] = new stdatel("Tennessee", 2.171617488, 0.000028, 0.000037, 0.011672828, 0.003854336, 0.025362708);
States[44] = new stdatel("Texas", 1.205634965, 0.000022, 0.000006, 0.000661134, 0.000704659, 0.002113559);
States[45] = new stdatel("Utah", 1.947042771, 0.000026, 0.000026, 0.003077666, 0.004665425, 0.003506587);
States[46] = new stdatel("Vermont", 0.184227241, 0.001076, 0.000144, 0.000192103, 0.0028934, 0);
States[47] = new stdatel("Virginia", 1.707554686, 0.000058, 0.000026, 0.009285736, 0.002441736, 0.010856008);
States[48] = new stdatel("Washington", 1.314017472, 0.000076, 0.000023, 0.000405703, 0.001503145, 0.009366909);
States[49] = new stdatel("West Virginia", 2.081593698, 0.000024, 0.000035, 0.014295865, 0.004480311, 0.029157507);
States[50] = new stdatel("Wisconsin", 1.89503401, 0.000038, 0.000027, 0.005853305, 0.00268107, 0.011000114);
States[51] = new stdatel("Wyoming", 2.267570618, 0.000028, 0.000035, 0.002719194, 0.004298587, 0.017725074);


//Define the function which will calculate the pollution based on electricity usage.
//This function will be called every time there is a change to the input.

function gofigure()
{



//Get the state selected from form
var mystate = document.pollcalc.mystate.selectedIndex;

var state = States[mystate];

var mykwh = parseFloat(document.pollcalc.mykwh.value);
if (isNaN(mykwh)) { mykwh=0; document.pollcalc.mykwh.value = "0";}

//Get the monthly gas savings from form
var mytherms = parseFloat(document.pollcalc.mytherms.value);
if (isNaN(mytherms)) { mytherms=0; document.pollcalc.mytherms.value = "0";}

var nokwh = mykwh;
var therms = mytherms;
var mytotalghg = 0;

var myco2 = (nokwh*state.co2lbs)+(therms*11.76);
var mych4 = (nokwh*state.ch4lbs)+(therms*0.0023);
var myn2o = (nokwh*state.n2olbs)+(therms*0.0002);
var myso2 = (nokwh*state.so2lbs)+(therms*0.00006);
var mynox = (nokwh*state.noxlbs)+(therms*0.015);
var myhg = (nokwh*state.hgmgs)+(therms*0);
var mytotalghg = ((nokwh*state.co2lbs)+(therms*11.76)+(nokwh*state.ch4lbs)+(therms*0.0023)+(nokwh*state.n2olbs)+(therms*0.0002));


document.pollcalc.myco2.value = Math.round(myco2);
document.pollcalc.mych4.value = Math.round(mych4);
document.pollcalc.myn2o.value = Math.round(myn2o);
document.pollcalc.myso2.value = Math.round(myso2);
document.pollcalc.mynox.value = Math.round(mynox);
document.pollcalc.myhg.value = Math.round(myhg);
document.pollcalc.mytotalghg.value = Math.round(mytotalghg);

}
