//Set up the function which will define each state's data
function stdatel(sname,reskwhprice,comkwhprice,indkwhprice,resngprice,comngprice,indngprice,co2lbs,noxlbs,so2lbs,hgmgs,co2ng,noxng,so2ng,hgng)
{
    this.sname = sname;
    this.reskwhprice = reskwhprice;
    this.comkwhprice = comkwhprice;
    this.indkwhprice = indkwhprice;
    this.resngprice = resngprice;
    this.comngprice = comngprice;
    this.indngprice = indngprice;
    this.co2lbs = co2lbs;
    this.noxlbs = noxlbs;
    this.so2lbs = so2lbs;
    this.hgmgs = hgmgs;
    this.co2ng = co2ng;
    this.noxng = noxng;
    this.so2ng = so2ng;
    this.hgng = hgng;
   
}

//Set up the function which will define each customer type
function custtype(custname)
{
    this.custname = custname;
    
}

//Create the array with the name Customer
var Customer = new Object();
                 
//Define the members of the array
Customer[0] = new custtype("Residential");
Customer[1] = new custtype("Commercial");
Customer[2] = new custtype("Industrial");

//Create the array with the name States
var States = new Object();

//Define the members of the array
States[0] = new stdatel("Alabama", 0.0800, 0.0750, 0.0452, 1.998, 1.712, 0.991, 1.811, 0.002849, 0.008581, 0.017991, 11.708, 0.0150, 0.0000600, 0.0);
States[1] = new stdatel("Alaska", 0.1330, 0.1156, 0.0929, 0.723, 0.648, 0.401, 1.540, 0.006220, 0.002572, 0.00, 11.708, 0.0150, 0.0000600, 0.0);
States[2] = new stdatel("Arizona", 0.0886, 0.0740, 0.0585, 1.717, 1.267, 1.043, 1.657, 0.001523, 0.000956, 0.003404, 11.708, 0.0150, 0.0000600, 0.0);
States[3] = new stdatel("Arkansas", 0.0800, 0.0618, 0.0474, 1.485, 1.125, 1.002, 1.947, 0.002328, 0.003876, 0.008266, 11.708, 0.0150, 0.0000600, 0.0);
States[4] = new stdatel("California", 0.1251, 0.1192, 0.0955, 1.241, 1.086, 0.969, 1.343, 0.000464, 0.000069, 0.000000, 11.708, 0.0150, 0.0000600, 0.0);
States[5] = new stdatel("Colorado", 0.0906, 0.0762, 0.0574, 1.173, 0.988, 1.142, 1.788, 0.002311, 0.002063, 0.004376, 11.708, 0.0150, 0.0000600, 0.0);
States[6] = new stdatel("Connecticut", 0.1364, 0.1153, 0.0940, 1.849, 1.428, 1.142, 1.901, 0.001332, 0.001483, 0.000486, 11.708, 0.0150, 0.0000600, 0.0);
States[7] = new stdatel("Delaware", 0.0901, 0.0760, 0.0621, 1.930, 1.683, 1.349, 1.809, 0.003009, 0.009145, 0.019450, 11.708, 0.0150, 0.0000600, 0.0);
States[8] = new stdatel("District of Columbia", 0.0910, 0.0913, 0.1413, 1.781, 1.520, 1.355, 3.874, 0.005409, 0.010184, 0.030148, 11.708, 0.0150, 0.0000600, 0.0);
States[9] = new stdatel("Florida", 0.0962, 0.0816, 0.0646, 2.310, 1.450, 1.236, 1.601, 0.002429, 0.004380, 0.002918, 11.708, 0.0150, 0.0000600, 0.0);
States[10] = new stdatel("Georgia", 0.0864, 0.0767, 0.0528, 1.951, 1.442, 0.967, 1.999, 0.002949, 0.013881, 0.013615, 11.708, 0.0150, 0.0000600, 0.0);
States[11] = new stdatel("Hawaii", 0.2070, 0.1904, 0.1579, 3.732, 3.068, 1.938, 1.820, 0.005459, 0.004989, 0.005835, 11.708, 0.0150, 0.0000600, 0.0);
States[12] = new stdatel("Idaho", 0.0629, 0.0542, 0.0391, 1.338, 1.227, 1.057, 0.710, 0.000501, 0.000794, 0.0, 11.708, 0.0150, 0.0000600, 0.0);
States[13] = new stdatel("Illinois", 0.0834, 0.0775, 0.0461, 1.179, 1.151, 0.992, 2.391, 0.003267, 0.008430, 0.043763, 11.708, 0.0150, 0.0000600, 0.0);
States[14] = new stdatel("Indiana", 0.0750, 0.0657, 0.0442, 1.371, 1.212, 0.983, 2.306, 0.004154, 0.015361, 0.018478, 11.708, 0.0150, 0.0000600, 0.0);
States[15] = new stdatel("Iowa", 0.0927, 0.0695, 0.0456, 1.306, 1.089, 0.883, 2.564, 0.005178, 0.008861, 0.027716, 11.708, 0.0150, 0.0000600, 0.0);
States[16] = new stdatel("Kansas", 0.0790, 0.0660, 0.0485, 1.386, 1.318, 0.687, 2.528, 0.005641, 0.009681, 0.013129, 11.708, 0.0150, 0.0000600, 0.0);
States[17] = new stdatel("Kentucky", 0.0657, 0.0601, 0.0360, 1.566, 1.389, 0.984, 2.286, 0.003749, 0.013296, 0.018964, 11.708, 0.0150, 0.0000600, 0.0);
States[18] = new stdatel("Louisiana", 0.0887, 0.0856, 0.0671, 1.550, 1.204, 0.806, 1.455, 0.002067, 0.002339, 0.003404, 11.708, 0.0150, 0.0000600, 0.0);
States[19] = new stdatel("Maine", 0.1323, 0.1063, 0.0728, 1.876, 1.644, 1.511, 1.009, 0.001424, 0.002476, 0.000486, 11.708, 0.0150, 0.0000600, 0.0);
States[20] = new stdatel("Maryland", 0.0846, 0.0897, 0.0701, 1.721, 1.389, 1.355, 2.112, 0.004244, 0.019568, 0.030148, 11.708, 0.0150, 0.0000600, 0.0);
States[21] = new stdatel("Massachusetts", 0.1344, 0.1242, 0.0922, 1.831, 1.624, 1.540, 1.529, 0.001294, 0.003836, 0.003890, 11.708, 0.0150, 0.0000600, 0.0);
States[22] = new stdatel("Michigan", 0.0840, 0.0784, 0.0532, 1.224, 1.111, 1.049, 2.115, 0.003180, 0.009043, 0.018478, 11.708, 0.0150, 0.0000600, 0.0);
States[23] = new stdatel("Minnesota", 0.0828, 0.0659, 0.0502, 1.220, 1.026, 0.877, 2.186, 0.006522, 0.007718, 0.016533, 11.708, 0.0150, 0.0000600, 0.0);
States[24] = new stdatel("Mississippi", 0.0871, 0.0848, 0.0537, 1.541, 1.189, 0.964, 1.901, 0.003473, 0.006089, 0.004376, 11.708, 0.0150, 0.0000600, 0.0);
States[25] = new stdatel("Missouri", 0.0708, 0.0592, 0.0454, 1.500, 1.380, 1.260, 2.275, 0.003623, 0.008812, 0.018964, 11.708, 0.0150, 0.0000600, 0.0);
States[26] = new stdatel("Montana", 0.0810, 0.0743, 0.0483, 1.189, 1.184, 0.990, 2.511, 0.004356, 0.002834, 0.000486, 11.708, 0.0150, 0.0000600, 0.0);
States[27] = new stdatel("Nebraska", 0.0714, 0.0598, 0.0443, 1.197, 1.019, 0.835, 2.456, 0.004761, 0.009398, 0.021395, 11.708, 0.0150, 0.0000600, 0.0);
States[28] = new stdatel("Nevada", 0.1020, 0.0948, 0.0771, 1.503, 1.272, 1.260, 1.400, 0.001691, 0.001249, 0.001945, 11.708, 0.0150, 0.0000600, 0.0);
States[29] = new stdatel("New Hampshire", 0.1351, 0.1206, 0.1148, 1.760, 1.526, 1.305, 1.427, 0.001396, 0.006785, 0.000973, 11.708, 0.0150, 0.0000600, 0.0);
States[30] = new stdatel("New Jersey", 0.1174, 0.1061, 0.0976, 1.605, 1.401, 1.053, 1.548, 0.002379, 0.005199, 0.004863, 11.708, 0.0150, 0.0000600, 0.0);
States[31] = new stdatel("New Mexico", 0.0913, 0.0781, 0.0561, 1.314, 1.106, 0.962, 1.762, 0.003603, 0.001307, 0.015074, 11.708, 0.0150, 0.0000600, 0.0);
States[32] = new stdatel("New York", 0.1572, 0.1436, 0.0823, 1.710, 1.262, 1.234, 1.810, 0.002114, 0.006141, 0.005835, 11.708, 0.0150, 0.0000600, 0.0);
States[33] = new stdatel("North Carolina", 0.0865, 0.0686, 0.0504, 1.764, 1.456, 0.876, 2.127, 0.003630, 0.012795, 0.021395, 11.708, 0.0150, 0.0000600, 0.0);
States[34] = new stdatel("North Dakota", 0.0699, 0.0611, 0.0432, 1.277, 1.031, 0.687, 2.796, 0.007870, 0.015727, 0.036469, 11.708, 0.0150, 0.0000600, 0.0);
States[35] = new stdatel("Ohio", 0.0851, 0.0793, 0.0510, 1.507, 1.349, 1.190, 2.191, 0.004590, 0.022355, 0.034038, 11.708, 0.0150, 0.0000600, 0.0);
States[36] = new stdatel("Oklahoma", 0.0795, 0.0700, 0.0511, 1.582, 1.305, 1.180, 1.618, 0.002585, 0.002332, 0.007294, 11.708, 0.0150, 0.0000600, 0.0);
States[37] = new stdatel("Oregon", 0.0725, 0.0651, 0.0483, 1.526, 1.284, 0.962, 1.193, 0.001308, 0.001325, 0.002918, 11.708, 0.0150, 0.0000600, 0.0);
States[38] = new stdatel("Pennsylvania", 0.0986, 0.0850, 0.0629, 1.727, 1.502, 1.261, 2.104, 0.003099, 0.015604, 0.027716, 11.708, 0.0150, 0.0000600, 0.0);
States[39] = new stdatel("Rhode Island", 0.1304, 0.1171, 0.1001, 1.846, 1.674, 1.399, 1.251, 0.000479, 0.000103, 0.000, 11.708, 0.0150, 0.0000600, 0.0);
States[40] = new stdatel("South Carolina", 0.0867, 0.0739, 0.0455, 1.857, 1.414, 0.964, 1.953, 0.003187, 0.011871, 0.012643, 11.708, 0.0150, 0.0000600, 0.0);
States[41] = new stdatel("South Dakota", 0.0777, 0.0620, 0.0495, 1.173, 0.998, 0.985, 2.553, 0.006786, 0.005565, 0.000000, 11.708, 0.0150, 0.0000600, 0.0);
States[42] = new stdatel("Tennessee", 0.0698, 0.0717, 0.0473, 1.533, 1.349, 1.025, 2.247, 0.004431, 0.016584, 0.024799, 11.708, 0.0150, 0.0000600, 0.0);
States[43] = new stdatel("Texas", 0.1093, 0.0885, 0.0714, 1.353, 1.063, 0.714, 1.434, 0.000867, 0.000825, 0.001945, 11.708, 0.0150, 0.0000600, 0.0);
States[44] = new stdatel("Utah", 0.0752, 0.0607, 0.0424, 1.157, 1.008, 0.842, 2.154, 0.005542, 0.004984, 0.005349, 11.708, 0.0150, 0.0000600, 0.0);
States[45] = new stdatel("Vermont", 0.1296, 0.1133, 0.0777, 1.488, 1.169, 0.963, 0.255, 0.002974, 0.000478, 0.000000, 11.708, 0.0150, 0.0000600, 0.0);
States[46] = new stdatel("Virginia", 0.0816, 0.0605, 0.0446, 1.844, 1.304, 1.128, 2.058, 0.003176, 0.010827, 0.012643, 11.708, 0.0150, 0.0000600, 0.0);
States[47] = new stdatel("Washington", 0.0654, 0.0633, 0.0427, 1.404, 1.257, 1.004, 1.643, 0.001848, 0.000708, 0.010211, 11.708, 0.0150, 0.0000600, 0.0);
States[48] = new stdatel("West Virginia", 0.0621, 0.0553, 0.0385, 1.662, 1.642, 0.933, 2.152, 0.004545, 0.015017, 0.026258, 11.708, 0.0150, 0.0000600, 0.0);
States[49] = new stdatel("Wisconsin", 0.0966, 0.0767, 0.0539, 1.300, 1.085, 1.004, 2.211, 0.003963, 0.009299, 0.016533, 11.708, 0.0150, 0.0000600, 0.0);
States[50] = new stdatel("Wyoming", 0.0748, 0.0617, 0.0399, 1.193, 1.027, 0.915, 2.480, 0.005170, 0.003290, 0.019450, 11.708, 0.0150, 0.0000600, 0.0);
States[51] = new stdatel("U.S. Average", 0.0945, 0.0867, 0.0573, 1.445, 1.257, 0.828, 1.838, 0.002692, 0.007469, 0.012643, 11.708, 0.0150, 0.0000600, 0.0);


//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 customer type selected from form
var mycustomer = document.pollcalc.mycustomer.selectedIndex;

//Get the state selected from form
var mystate = document.pollcalc.mystate.selectedIndex;

//Get the monthly kwh savings from form
var kwhsaved = parseFloat(document.pollcalc.kwhsaved.value);
if (isNaN(kwhsaved)) { kwhsaved=0; document.pollcalc.kwhsaved.value = "0";}

//Get the monthly gas savings from form
var therms = parseFloat(document.pollcalc.therms.value);
if (isNaN(therms)) { therms=0; document.pollcalc.therms.value = "0";}

var state = States[mystate];
var consumer = Customer[mycustomer];

if (consumer.custname == "Residential") 
         var costsave = ((kwhsaved*state.reskwhprice)+(therms*state.resngprice)); 
else if (consumer.custname == "Commercial")
         var costsave = ((kwhsaved*state.comkwhprice)+(therms*state.comngprice));
else if (consumer.custname == "Industrial")
         var costsave = ((kwhsaved*state.indkwhprice)+(therms*state.indngprice));

var myco2 = (kwhsaved*state.co2lbs)+(therms*state.co2ng);
var mynox = (kwhsaved*state.noxlbs)+(therms*state.noxng);
var myso2 = (kwhsaved*state.so2lbs)+(therms*state.so2ng);
var myhg = (kwhsaved*state.hgmgs)+(therms*state.hgng);

document.pollcalc.costsave.value = Math.round(costsave);
document.pollcalc.myco2.value = Math.round(myco2);
document.pollcalc.mynox.value = Math.round(mynox);
document.pollcalc.myso2.value = Math.round(myso2);
document.pollcalc.myhg.value = Math.round(myhg);

}