
// lamp types, wattages, efficiencies - 3 dimensional array!
var lamps = new Array()
for(x=0;x<9;x++)
  {
  lamps[x] = new Array()
  for(y=0;y<10;y++)
    {
    lamps[x][y] = new Array();
    for(z=0;z<2;z++)
      {
      lamps[x][y][z] = new Array();
      lamps[x][y][z] = 0;
      }
    }
  }
// array structure is:
// [x] = lamp type name
// [y] = wattages
// [z] = circuit wattages & mean lumens

// some lamp data from IDA Info sheet titled:
// Initial Rated Light Output of Various Lamps

// types and their data are:
lamps[0][0][0] = "Incandescent";
// data for circuit wattages is estimated at 110% of rated wattage
  lamps[0][1][0] = 25;
  lamps[0][1][1] = 27;
  lamps[0][1][2] = 235;
  lamps[0][2][0] = 40;
  lamps[0][2][1] = 44;
  lamps[0][2][2] = 375;
  lamps[0][3][0] = 60;
  lamps[0][3][1] = 66;
  lamps[0][3][2] = 890;
  lamps[0][4][0] = 100;
  lamps[0][4][1] = 110;
  lamps[0][4][2] = 1800;
  lamps[0][5][0] = 150;
  lamps[0][5][1] = 165;
  lamps[0][5][2] = 2850;
lamps[1][0][0] = "Fluorescent";
// data for circuit wattages is estimated at approx. 110% of rated wattage
  lamps[1][1][0] = 7;
  lamps[1][1][1] = 8;
  lamps[1][1][2] = 400;
  lamps[1][2][0] = 13;
  lamps[1][2][1] = 15;
  lamps[1][2][2] = 900;
  lamps[1][3][0] = 22;
  lamps[1][3][1] = 24;
  lamps[1][3][2] = 1200;
  lamps[1][4][0] = 28;
  lamps[1][4][1] = 32;
  lamps[1][4][2] = 1600;
  lamps[1][5][0] = 40;
  lamps[1][5][1] = 44;
  lamps[1][5][2] = 3150;
lamps[2][0][0] = "Quartz Halogen";
// data for circuit wattages is estimated at approx. 110% of rated wattage
  lamps[2][1][0] = 42;
  lamps[2][1][1] = 46;
  lamps[2][1][2] = 665;
  lamps[2][2][0] = 52;
  lamps[2][2][1] = 57;
  lamps[2][2][2] = 885;
  lamps[2][3][0] = 72;
  lamps[2][3][1] = 80;
  lamps[2][3][2] = 1300;
  lamps[2][4][0] = 300;
  lamps[2][4][1] = 330;
  lamps[2][4][2] = 6000;
  lamps[2][5][0] = 500;
  lamps[2][5][1] = 550;
  lamps[2][5][2] = 10500;
  lamps[2][6][0] = 1000;
  lamps[2][6][1] = 1100;
  lamps[2][6][2] = 21000;
lamps[3][0][0] = "Low Pressure Sodium";
  lamps[3][1][0] = 18;
  lamps[3][1][1] = 30;
  lamps[3][1][2] = 1800;
  lamps[3][2][0] = 35;
  lamps[3][2][1] = 60;
  lamps[3][2][2] = 4800;
  lamps[3][3][0] = 55;
  lamps[3][3][1] = 80;
  lamps[3][3][2] = 8000;
  lamps[3][4][0] = 90;
  lamps[3][4][1] = 125;
  lamps[3][4][2] = 13500;
  lamps[3][5][0] = 135;
  lamps[3][5][1] = 180;
  lamps[3][5][2] = 22500;
  lamps[3][6][0] = 180;
  lamps[3][6][1] = 220;
  lamps[3][6][2] = 33000;
lamps[4][0][0] = "High Pressure Sodium";
  lamps[4][1][0] = 35;
  lamps[4][1][1] = 46;
  lamps[4][1][2] = 2025;
  lamps[4][2][0] = 50;
  lamps[4][2][1] = 66;
  lamps[4][2][2] = 3600;
  lamps[4][3][0] = 70;
  lamps[4][3][1] = 88;
  lamps[4][3][2] = 5670;
  lamps[4][4][0] = 100;
  lamps[4][4][1] = 130;
  lamps[4][4][2] = 8550;
  lamps[4][5][0] = 150;
  lamps[4][5][1] = 193;
  lamps[4][5][2] = 14400;
  lamps[4][6][0] = 200;
  lamps[4][6][1] = 246;
  lamps[4][6][2] = 19800;
  lamps[4][7][0] = 250;
  lamps[4][7][1] = 294;
  lamps[4][7][2] = 25700;
  lamps[4][8][0] = 400;
  lamps[4][8][1] = 465;
  lamps[4][8][2] = 45000;
lamps[5][0][0] = "Metal Halide";
  lamps[5][1][0] = 32;
  lamps[5][1][1] = 43;
  lamps[5][1][2] = 1900;
  lamps[5][2][0] = 50;
  lamps[5][2][1] = 62;
  lamps[5][2][2] = 2500;
  lamps[5][3][0] = 70;
  lamps[5][3][1] = 88;
  lamps[5][3][2] = 4000;
  lamps[5][4][0] = 100;
  lamps[5][4][1] = 115;
  lamps[5][4][2] = 6400;
  lamps[5][5][0] = 150;
  lamps[5][5][1] = 184;
  lamps[5][5][2] = 8700;
  lamps[5][6][0] = 175;
  lamps[5][6][1] = 215;
  lamps[5][6][2] = 10350;
  lamps[5][7][0] = 250;
  lamps[5][7][1] = 295;
  lamps[5][7][2] = 17000;
  lamps[5][8][0] = 400;
  lamps[5][8][1] = 456;
  lamps[5][8][2] = 28800;
  lamps[5][9][0] = 1000;
  lamps[5][9][1] = 1070;
  lamps[5][9][2] = 88000;
lamps[6][0][0] = "Mercury Vapor";
  lamps[6][1][0] = 100;
  lamps[6][1][1] = 135;
  lamps[6][1][2] = 3230;
  lamps[6][2][0] = 175;
  lamps[6][2][1] = 205;
  lamps[6][2][2] = 7140;
  lamps[6][3][0] = 250;
  lamps[6][3][1] = 285;
  lamps[6][3][2] = 10540;
  lamps[6][4][0] = 400;
  lamps[6][4][1] = 455;
  lamps[6][4][2] = 18570;
  lamps[6][5][0] = 700;
  lamps[6][5][1] = 765;
  lamps[6][5][2] = 29850;
  lamps[6][6][0] = 1000;
  lamps[6][6][1] = 1090;
  lamps[6][6][2] = 46200;
lamps[7][0][0] = "Pulse-start Metal Halide (EM ballast)";
  lamps[7][1][0] = 50;
  lamps[7][1][1] = 65;
  lamps[7][1][2] = 2550;
  lamps[7][2][0] = 70;
  lamps[7][2][1] = 90;
  lamps[7][2][2] = 4200;
  lamps[7][3][0] = 100;
  lamps[7][3][1] = 127;
  lamps[7][3][2] = 6800;
  lamps[7][4][0] = 150;
  lamps[7][4][1] = 190;
  lamps[7][4][2] = 11300;
  lamps[7][5][0] = 175;
  lamps[7][5][1] = 208;
  lamps[7][5][2] = 14000;
  lamps[7][6][0] = 250;
  lamps[7][6][1] = 288;
  lamps[7][6][2] = 16200;
  lamps[7][7][0] = 400;
  lamps[7][7][1] = 448;
  lamps[7][7][2] = 33900;
lamps[8][0][0] = "Pulse-start M-H (Electronic ballast)";
  lamps[8][1][0] = 70;
  lamps[8][1][1] = 78;
  lamps[8][1][2] = 4200;
  lamps[8][2][0] = 100;
  lamps[8][2][1] = 110;
  lamps[8][2][2] = 6800;
  lamps[8][3][0] = 150;
  lamps[8][3][1] = 168;
  lamps[8][3][2] = 11300;
  
function tRound(val,prec)
  {
  // round to specified number of decimal places
  val = val * Math.pow(10,prec);
  val = Math.round(val);
  val = val / Math.pow(10,prec);
  return val;
  }

function populate(sel)
  {
  // populate the wattage list
  var a = parseInt(sel)-1;
  for(d=0;d<document.lightcost.wattage.options.length;d++)
    {
    document.lightcost.wattage.options[d] = null;
    }
// bug -- have to clear the list twice for some reason
  for(d=0;d<document.lightcost.wattage.options.length;d++)
    {
    document.lightcost.wattage.options[d] = null;
    }
  document.lightcost.wattage.options[0] = new Option("Choose one     ", 0, true, true);
  for(b=1;b<10;b++)
    {
    if(lamps[a][b][0] != 0)
      {
      var newOpt = new Option(lamps[a][b][0])
      document.lightcost.wattage.options[b] = newOpt;
      }
    }
//  document.lightcost.wattage.options[0] = null;
//  document.lightcost.wattage.options[0].selected = true;
  }

function calcForm(frm)
  {
  // do the calculation
  var selectedLamp = frm.lType.selectedIndex-1;
  var selWatt = lamps[selectedLamp][frm.wattage.selectedIndex][0];
  var numLights = parseInt(frm.numLights.value);
  var circuitWatt = lamps[selectedLamp][frm.wattage.selectedIndex][1];
  var meanLumen = lamps[selectedLamp][frm.wattage.selectedIndex][2];
  var selLampText = lamps[selectedLamp][0][0];
  // now determine the elec. rate selected
  if(frm.elec.options[0].selected)
    {
    // first item is "Choose one" so invalid
    alert("Please choose an electric rate")
    return false
    }
  else if(frm.elec.options[frm.elec.options.length-1].selected)
    {
    // last item is "Other" so invalid
    rate = parseFloat(frm.otherRate.value)/100;
    if(isNaN(rate)) rate = .0958;
    }
  else
    {
    for(e=1;e<frm.elec.options.length-1;e++)
      {
      if(frm.elec.options[e].selected)
        {
        var rate = parseFloat(frm.elec.options[e].value)/100;  // in cents
        }
      }
    }

  for(f=0;f<frm.hours.length;f++)
    {
    if(frm.hours[f].checked)
      {
      var hrPerYr = frm.hours[f].value;
      }
    }
  if(hrPerYr==0)
    {
    hrPerYr = parseFloat(frm.numHours.value)*365.25;
    if(isNaN(hrPerYr)) hrPerYr = 4170;
    }
  var cost = tRound(((circuitWatt * rate * hrPerYr)/1000),2);
  
  // calculate air pollution emissions
  // from www.magnaray.com
  // 1.3077 lbs of CO2, 1.923 grams of SO2, and 1.623 grams of NO per kw used
  // from icole report, delivered kwh, accounting for line losses
  // 2.419 lbs of CO2, 0.01582 lbs of SO2, NO is 0.00965, and 0.00006 lbs of mercury per kwh
  var co2 = circuitWatt * hrPerYr*2.419 / 1000;
  var so2 = circuitWatt * hrPerYr*.01582 / 1000;
  var nox = circuitWatt * hrPerYr*.00965 / 1000;
  var merc = circuitWatt * hrPerYr*.00006 / 1000;
  
  var output = new Object();
  output.selWatt = selWatt;
  output.circuitWatt = circuitWatt;
  output.selLampText = selLampText;
  output.numLights = numLights;
  output.meanLumen = meanLumen;
  output.hrPerYr = hrPerYr;
  output.rate = rate;
  output.cost = cost;
  output.co2 = co2;
  output.so2 = so2;
  output.nox = nox;
  output.merc = merc;
  window.lamp = output;
  var outWin = window.open("lcreport.html", "outWin", "height=520,width=630,resizable,toolbar,location,scrollbars,status,menubar,top=25,left=50");
  }

