// public transport javascript


//Look-up Table Lists
var lookUpBus = new Array();

lookUpBus['Diesel Long Haul'] = new Array('0.05');
lookUpBus['Diesel Urban'] = new Array('0.19');
lookUpBus['Natural Gas'] = new Array('0.14');


var typeTrain = new Array();

typeTrain['USA'] = new Array('electric(commuter)');
typeTrain['UK'] = new Array('electric(commuter)', 'electric(high speed)');
typeTrain['Australasia'] = new Array('electric(commuter)');
typeTrain['Other'] = new Array('electric(commuter)', 'electric(high speed)');


var lookUpTrain = new Array();

lookUpTrain['USA'] = new Array();
lookUpTrain['USA']['electric(commuter)'] = new Array('0.18');

lookUpTrain['Australasia'] = new Array();
lookUpTrain['Australasia']['electric(commuter)'] = new Array('0.23');

lookUpTrain['UK'] = new Array();
lookUpTrain['UK']['electric(commuter)'] = new Array('0.06');
lookUpTrain['UK']['electric(high speed)'] = new Array('0.10');

lookUpTrain['Other'] = new Array();
lookUpTrain['Other']['electric(commuter)'] = new Array('0.06');
lookUpTrain['Other']['electric(high speed)'] = new Array('0.10');


function setBusLookUp()
  {
  typeBusSel = document.getElementById('typeBus');
  lookUpBusSel = document.getElementById('lookUpBus');

  lookUpBusList = lookUpBus[typeBusSel.value];
  
  changeSelect(lookUpBusSel, lookUpBusList);
  }


function setTrainLookUp()
  {
  locationTrainSel = document.getElementById('trainLocation');
  typeTrainSel = document.getElementById('typeTrain');
  lookUpTrainSel = document.getElementById('lookUpTrain');

  lookUpTrainList = lookUpTrain[locationTrainSel.value][typeTrainSel.value];
  
  changeSelect(lookUpTrainSel, lookUpTrainList);
  }


function setTypeTrain()
  {
  trainLocationSel = document.getElementById('trainLocation');
  typeTrainSel = document.getElementById('typeTrain');

  typeTrainList = typeTrain[trainLocationSel.value];
  
  changeSelect(typeTrainSel, typeTrainList);
  }






function changeSelect(fieldObj, valuesAry, optTextAry, selectedValue) 
  {
  //Clear the select list
  fieldObj.options.length = 0;

  //Set the option text to the values if not passed
  optTextAry = (optTextAry)?optTextAry:valuesAry;

  //Itterate through the list and create the options
  for (i in valuesAry) 
    {
    selectFlag = (selectedValue && selectedValue==valuesAry[i])?true:false;
    fieldObj.options[fieldObj.length] = new Option(optTextAry[i], valuesAry[i], false, selectFlag);
    }
  }
