//Set up the function which will define each state's data
function stdatel(sname,resprice,comprice,indprice,co2lbs,noxlbs,so2lbs,hgmgs)
{
    this.sname = sname;
    this.resprice = resprice;
    this.comprice = comprice; 
    this.indprice = indprice;
    this.co2lbs = co2lbs;
    this.noxlbs = noxlbs;
    this.so2lbs = so2lbs;
    this.hgmgs = hgmgs;
   
}

//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.392, 0.002249, 0.006616, 0.018186);
States[1] = new stdatel("Alaska", 0.1330, 0.1156, 0.0929, 1.186, 0.003944, 0.001290, 0.000681);
States[2] = new stdatel("Arizona", 0.0886, 0.0740, 0.0585, 1.307, 0.001897, 0.001321, 0.006953);
States[3] = new stdatel("Arkansas", 0.0800, 0.0618, 0.0474, 1.372, 0.001850, 0.003622, 0.010260);
States[4] = new stdatel("California", 0.1251, 0.1192, 0.0955, 0.751, 0.000367, 0.000137, 0.000632);
States[5] = new stdatel("Colorado", 0.0906, 0.0762, 0.0574, 2.129, 0.003218, 0.002871, 0.005252);
States[6] = new stdatel("Connecticut", 0.1364, 0.1153, 0.0940, 0.808, 0.000775, 0.000535, 0.005495);
States[7] = new stdatel("Delaware", 0.0901, 0.0760, 0.0621, 1.934, 0.003240, 0.010563, 0.022319);
States[8] = new stdatel("District of Columbia", 0.0910, 0.0913, 0.1413, 3.874, 0.005409, 0.010184, 0.019742);
States[9] = new stdatel("Florida", 0.0962, 0.0816, 0.0646, 1.445, 0.002500, 0.004258, 0.005057);
States[10] = new stdatel("Georgia", 0.0864, 0.0767, 0.0528, 1.488, 0.001828, 0.009766, 0.013080);
States[11] = new stdatel("Hawaii", 0.2070, 0.1904, 0.1579, 1.774, 0.004028, 0.004492, 0.005689);
States[12] = new stdatel("Idaho", 0.0629, 0.0542, 0.0391, 0.154, 0.000159, 0.000199, 0.0);
States[13] = new stdatel("Illinois", 0.0834, 0.0775, 0.0461, 1.238, 0.001652, 0.004239, 0.020131);
States[14] = new stdatel("Indiana", 0.0750, 0.0657, 0.0442, 2.249, 0.003874, 0.014641, 0.019353);
States[15] = new stdatel("Iowa", 0.0927, 0.0695, 0.0456, 2.083, 0.004069, 0.006914, 0.025382);
States[16] = new stdatel("Kansas", 0.0790, 0.0660, 0.0485, 2.005, 0.004282, 0.005681, 0.010843);
States[17] = new stdatel("Kentucky", 0.0657, 0.0601, 0.0360, 2.199, 0.003767, 0.011713, 0.018428);
States[18] = new stdatel("Louisiana", 0.0887, 0.0856, 0.0671, 1.288, 0.001785, 0.002835, 0.005981);
States[19] = new stdatel("Maine", 0.1323, 0.1063, 0.0728, 0.827, 0.001031, 0.000946, 0.001118);
States[20] = new stdatel("Maryland", 0.0846, 0.0897, 0.0701, 1.386, 0.002653, 0.011830, 0.019742);
States[21] = new stdatel("Massachusetts", 0.1344, 0.1242, 0.0922, 1.314, 0.001411, 0.003758, 0.006856);
States[22] = new stdatel("Michigan", 0.0840, 0.0784, 0.0532, 1.514, 0.002333, 0.006357, 0.013372);
States[23] = new stdatel("Minnesota", 0.0828, 0.0659, 0.0502, 1.702, 0.003701, 0.004464, 0.013810);
States[24] = new stdatel("Mississippi", 0.0871, 0.0848, 0.0537, 1.510, 0.002704, 0.004709, 0.005884);
States[25] = new stdatel("Missouri", 0.0708, 0.0592, 0.0454, 2.017, 0.003168, 0.007096, 0.018915);
States[26] = new stdatel("Montana", 0.0810, 0.0743, 0.0483, 1.686, 0.003051, 0.001844, 0.001507);
States[27] = new stdatel("Nebraska", 0.0714, 0.0598, 0.0443, 1.611, 0.003287, 0.005201, 0.014199);
States[28] = new stdatel("Nevada", 0.1020, 0.0948,  0.0771, 1.686, 0.002695, 0.003121, 0.004522);
States[29] = new stdatel("New Hampshire", 0.1351, 0.1206, 0.1148, 0.835, 0.001053, 0.05146, 0.001167);
States[30] = new stdatel("New Jersey", 0.1174, 0.1061, 0.0976, 0.764, 0.001071, 0.002076, 0.005495);
States[31] = new stdatel("New Mexico", 0.0913, 0.0781, 0.0561, 2.135, 0.004875, 0.002503, 0.033503);
States[32] = new stdatel("New York", 0.1572, 0.1436, 0.0823, 0.972, 0.001135, 0.003726, 0.005495);
States[33] = new stdatel("North Carolina", 0.0865, 0.0686, 0.0504, 1.305, 0.002148, 0.008175, 0.012886);
States[34] = new stdatel("North Dakota", 0.0699, 0.0611, 0.0432, 2.558, 0.005357, 0.010279, 0.037928);
States[35] = new stdatel("Ohio", 0.0851, 0.0793, 0.0510, 1.907, 0.003955, 0.016171, 0.024604);
States[36] = new stdatel("Oklahoma", 0.0795, 0.0700, 0.0511, 1.850, 0.002938, 0.003726, 0.022465);
States[37] = new stdatel("Oregon", 0.0725, 0.0651, 0.0483, 0.489, 0.000566, 0.000577, 0.001605);
States[38] = new stdatel("Pennsylvania", 0.0986, 0.0850, 0.0629, 1.304, 0.002026, 0.010080, 0.024750);
States[39] = new stdatel("Rhode Island", 0.1304, 0.1171, 0.1001, 1.148, 0.000345, 0.000080, 0.000);
States[40] = new stdatel("South Carolina", 0.0867, 0.0739, 0.0455, 0.981, 0.001521, 0.004999, 0.006224);
States[41] = new stdatel("South Dakota", 0.0777, 0.0620, 0.0495, 1.303, 0.005117, 0.004287, 0.007537);
States[42] = new stdatel("Tennessee", 0.0698, 0.0717, 0.0473, 1.357, 0.002488, 0.006828, 0.011621);
States[43] = new stdatel("Texas", 0.1093, 0.0885, 0.0714, 1.578, 0.001222, 0.003361, 0.013810);
States[44] = new stdatel("Utah", 0.0752, 0.0607, 0.0424, 2.274, 0.004100, 0.002057, 0.003647);
States[45] = new stdatel("Vermont", 0.1296, 0.1133, 0.0777, 0.007, 0.000227, 0.000028, 0.00);
States[46] = new stdatel("Virginia", 0.0816, 0.0605, 0.0446, 1.298, 0.002131, 0.006226, 0.007731);
States[47] = new stdatel("Washington", 0.0654, 0.0633, 0.0427, 0.386, 0.000475, 0.000174, 0.003161);
States[48] = new stdatel("West Virginia", 0.0621, 0.0553, 0.0385, 2.131, 0.04202, 0.011463, 0.026014);
States[49] = new stdatel("Wisconsin", 0.0966, 0.0767, 0.0539, 1.836, 0.002887, 0.006912, 0.018672);
States[50] = new stdatel("Wyoming", 0.0748, 0.0617, 0.0399, 2.441, 0.004526, 0.004230, 0.019790);
States[51] = new stdatel("U.S. Average", 0.0945, 0.0867, 0.0573, 1.461, 0.002254, 0.005827, 0.013080);


//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 electric bill from form
var mybill = parseFloat(document.pollcalc.mybill.value);
if (isNaN(mybill)) { mybill=0; document.pollcalc.mybill.value = "0";}

var state = States[mystate];
var consumer = Customer[mycustomer];

if (consumer.custname == "Residential") 
     nokwh=((mybill/state.resprice)*12) 
else if (consumer.custname == "Commercial")
     nokwh=((mybill/state.comprice)*12)
else if (consumer.custname == "Industrial")
     nokwh=((mybill/state.indprice)*12);

var myco2 = nokwh*state.co2lbs;
var mynox = nokwh*state.noxlbs;
var myso2 = nokwh*state.so2lbs;
var myhg = nokwh*state.hgmgs;

document.pollcalc.nokwh.value = Math.round(nokwh);
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);

}