// business calculator javascript files

// Unit Distance Lists
var lookUpElec = new Array();
lookUpElec['UK'] = new Array('0.527');
lookUpElec['Australasia'] = new Array('1.02');
lookUpElec['US'] = new Array('0.606');
lookUpElec['Other'] = new Array('0.527');

var lookUpPetrol = new Array();
lookUpPetrol['kilometers'] = new Array('0.22');
lookUpPetrol['miles'] = new Array('0.352');

var lookUpDiesel = new Array();
lookUpDiesel['kilometers'] = new Array('0.19');
lookUpDiesel['miles'] = new Array('0.304');

var lookUpHybrid = new Array();
lookUpHybrid['kilometers'] = new Array('0.13');
lookUpHybrid['miles'] = new Array('0.208');

var lookUpDomestic = new Array();
lookUpDomestic['kilometers'] = new Array('0.16');
lookUpDomestic['miles'] = new Array('0.256');

var lookUpInternational = new Array();
lookUpInternational['kilometers'] = new Array('0.11');
lookUpInternational['miles'] = new Array('0.176');


function setLookUpElec()
  {
  locationSel = document.getElementById('location');
  lookUpElecSel = document.getElementById('lookUpElec');

  lookUpElecList = lookUpElec[locationSel.value];
  
  changeSelect(lookUpElecSel, lookUpElecList);
  }


function setLookUpPetrol()
  {
  unitSel = document.getElementById('unitPetrol');
  lookUpPetrolSel = document.getElementById('lookUpPetrol');

  lookUpPetrolList = lookUpPetrol[unitSel.value];
  
  changeSelect(lookUpPetrolSel, lookUpPetrolList);
  }


function setLookUpDiesel()
  {
  unitSel = document.getElementById('unitDiesel');
  lookUpDieselSel = document.getElementById('lookUpDiesel');

  lookUpDieselList = lookUpDiesel[unitSel.value];
  
  changeSelect(lookUpDieselSel, lookUpDieselList);
  }


function setLookUpHybrid()
  {
  unitSel = document.getElementById('unitHybrid');
  lookUpHybridSel = document.getElementById('lookUpHybrid');

  lookUpHybridList = lookUpHybrid[unitSel.value];
  
  changeSelect(lookUpHybridSel, lookUpHybridList);
  }


function setLookUpDomestic()
  {
  unitSel = document.getElementById('unitDomestic');
  lookUpDomesticSel = document.getElementById('lookUpDomestic');

  lookUpDomesticList = lookUpDomestic[unitSel.value];
  
  changeSelect(lookUpDomesticSel, lookUpDomesticList);
  }


function setLookUpInternational()
  {
  unitSel = document.getElementById('unitInternational');
  lookUpInternationalSel = document.getElementById('lookUpInternational');

  lookUpInternationalList = lookUpInternational[unitSel.value];
  
  changeSelect(lookUpInternationalSel, lookUpInternationalList);
  }


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);
    }
  }
