//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.407778, 0.000029, 0.000022, 0.005569, 0.002051, 0.013065637);
States[1] = new stdatel("Alabama", 1.419618, 0.000027, 0.000024, 0.007190, 0.002133, 0.019118102);
States[2] = new stdatel("Alaska", 1.154092, 0.000026, 0.000006, 0.001144, 0.003513, 0.000816602);
States[3] = new stdatel("Arizona", 1.226936, 0.000016, 0.000017, 0.001111, 0.001711, 0.007109244);
States[4] = new stdatel("Arkansas", 1.301754, 0.000034, 0.000024, 0.003152, 0.001684, 0.010231547);
States[5] = new stdatel("California", 0.571926, 0.000032, 0.000005, 0.000144, 0.000236, 0.00096070);
States[6] = new stdatel("Colorado", 2.023625, 0.000025, 0.000031, 0.002684, 0.003095, 0.007877811);
States[7] = new stdatel("Connecticut", 0.851353, 0.000072, 0.000014, 0.000579, 0.000637, 0.007589598);
States[8] = new stdatel("Delaware", 2.137103, 0.000039, 0.000028, 0.008469, 0.003526, 0.019118102);
States[9] = new stdatel("District of Columbia", 2.575807, 0.000111, 0.000022, 0.008567, 0.003869, 0);
States[10] = new stdatel("Florida", 1.419633, 0.000048, 0.000019, 0.004117, 0.002239, 0.004995685);
States[11] = new stdatel("Georgia", 1.485290, 0.000023, 0.000025, 0.010015, 0.001837, 0.013161708);
States[12] = new stdatel("Hawaii", 1.833144, 0.000175, 0.000032, 0.004413, 0.004109, 0.00557211);
States[13] = new stdatel("Idaho", 0.141618, 0.000020, 0.000004, 0.000186, 0.000148, 0);
States[14] = new stdatel("Illinois", 1.192431, 0.000014, 0.000020, 0.003826, 0.001451, 0.020511129);
States[15] = new stdatel("Indiana", 2.210930, 0.000026, 0.000037, 0.014251, 0.003483, 0.021615944);
States[16] = new stdatel("Iowa", 2.019769, 0.000024, 0.000033, 0.006641, 0.003648, 0.024257893);
States[17] = new stdatel("Kansas", 2.006721, 0.000025, 0.000033, 0.006305, 0.004155, 0.021327732);
States[18] = new stdatel("Kentucky", 2.178837, 0.000026, 0.000037, 0.010908, 0.003628, 0.018013287);
States[19] = new stdatel("Louisiana", 1.244848, 0.000027, 0.000014, 0.002616, 0.001726, 0.0061005);
States[20] = new stdatel("Maine", 0.783292, 0.000243, 0.000034, 0.001294, 0.001088, 0.001344992);
States[21] = new stdatel("Maryland", 1.432049, 0.000037, 0.000024, 0.011583, 0.002607, 0.018637748);
States[22] = new stdatel("Massachusetts", 1.337418, 0.000072, 0.000018, 0.003732, 0.001175, 0.007157279);
States[23] = new stdatel("Michigan", 1.427050, 0.000031, 0.000025, 0.006799, 0.002204, 0.014890984);
States[24] = new stdatel("Minnesota", 1.688755, 0.000041, 0.000030, 0.004226, 0.003542, 0.01388224);
States[25] = new stdatel("Mississippi", 1.298087, 0.000028, 0.000018, 0.003630, 0.002076, 0.006292642);
States[26] = new stdatel("Missouri", 1.955899, 0.000023, 0.000033, 0.006878, 0.002996, 0.0206072);
States[27] = new stdatel("Montana", 1.685979, 0.000021, 0.000029, 0.001650, 0.003093, 0.017388826);
States[28] = new stdatel("Nebraska", 1.700648, 0.000020, 0.000028, 0.004995, 0.003643, 0.010663866);
States[29] = new stdatel("Nevada", 1.525792, 0.000021, 0.000019, 0.002772, 0.002377, 0.007157279);
States[30] = new stdatel("New Hampshire", 0.834784, 0.000065, 0.000016, 0.004791, 0.000997, 0.001200886);
States[31] = new stdatel("New Jersey", 0.760970, 0.000032, 0.000011, 0.002034, 0.001044, 0.006340677);
States[32] = new stdatel("New Mexico", 2.050123, 0.000025, 0.000032, 0.001849, 0.004600, 0.030694641);
States[33] = new stdatel("New York", 0.877200, 0.000039, 0.000011, 0.002598, 0.000939, 0.005283898);
States[34] = new stdatel("North Carolina", 1.297243, 0.000021, 0.000023, 0.008333, 0.001889, 0.013017602);
States[35] = new stdatel("North Dakota", 2.462340, 0.000027, 0.000040, 0.009212, 0.005113, 0.034345334);
States[36] = new stdatel("Ohio", 1.876373, 0.000022, 0.000032, 0.015062, 0.003513, 0.023153078);
States[37] = new stdatel("Oklahoma", 1.654964, 0.000023, 0.000022, 0.003277, 0.002629, 0.013305815);
States[38] = new stdatel("Oregon", 0.425131, 0.000018, 0.000005, 0.000553, 0.000471, 0.001729276);
States[39] = new stdatel("Pennsylvania", 1.317921, 0.000027, 0.000022, 0.009688, 0.001791, 0.023441291);
States[40] = new stdatel("Rhode Island", 1.021634, 0.000020, 0.000002, 0.000058, 0.000225, 0);
States[41] = new stdatel("South Carolina", 0.946603, 0.000016, 0.000016, 0.004673, 0.001149, 0.005716216);
States[42] = new stdatel("South Dakota", 1.251155, 0.000015, 0.000020, 0.003722, 0.004807, 0.006821031);
States[43] = new stdatel("Tennessee", 1.333352, 0.000017, 0.000023, 0.005852, 0.002258, 0.013642063);
States[44] = new stdatel("Texas", 1.435378, 0.000021, 0.000016, 0.003185, 0.001045, 0.011768681);
States[45] = new stdatel("Utah", 2.227041, 0.000026, 0.000037, 0.002054, 0.003929, 0.003650693);
States[46] = new stdatel("Vermont", 0.004927, 0.000094, 0.000013, 0.000018, 0.000215, 0);
States[47] = new stdatel("Virginia", 1.266614, 0.000043, 0.000023, 0.006104, 0.001895, 0.007637634);
States[48] = new stdatel("Washington", 0.350646, 0.000017, 0.000006, 0.000094, 0.000449, 0.003170339);
States[49] = new stdatel("West Virginia", 2.041876, 0.000023, 0.000035, 0.010683, 0.003673, 0.025698956);
States[50] = new stdatel("Wisconsin", 1.821616, 0.000027, 0.000030, 0.006506, 0.002547, 0.017869181);
States[51] = new stdatel("Wyoming", 2.384293, 0.000027, 0.000039, 0.004196, 0.004248, 0.019550421);


//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 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 = Math.round(mytotalghg);

}
