function addOption(selectbox,text,value ) {
  var optn = document.createElement("option");
  optn.text = text;
  optn.value = value;
  selectbox.options.add(optn);
}

function changeOptions(){

  var cat = 0;
  for (var i=1; i<6; i++) {
    var thisCategory = document.getElementById('cat'+i);
    if (thisCategory.checked) {
       cat = i;
    }
  }

  desiredValues = new Array();

  switch(cat) {
    case 1:
      desiredValues = Array ("Approximate Social Grade",
                       "Economic Activity",
                       "Hours Worked",
                       "NS SeC",
                       "Occupation",
                       "Qualifications",
                       "Sex And Approximate Social Grade By Age",
                       "Sex And Economic Activity By Living Arrangements",
                       "Students Economic Activity");
    break;
    case 2:
     desiredValues = Array ("Mid Year Head Count Estimates 2004 2005",
                      "Mid Year Head Count Estimates 2006 2007",
                      "Total Adults",
                      "Total Households",
                      "Total Population");
    break;
    case 3:
     desiredValues = Array ("General Health",
                      "Limiting Long Term Illness",
                      "Provision Of Unpaid Care",
                      "Sex And Age By General Health And Limiting Long Term Illness");
    break;
    case 4:
     desiredValues = Array ("Accomodation Type By Household",
                      "Car Ownership",
                      "Household Composition Households",
                      "Number Of Rooms In Household",
                      "People In Households",
                      "Tenure By Household");
    break;
    case 5:
     desiredValues = Array ("Age 5year Bands",
                      "Age And Dependent Children By Household Type",
                      "Age By Sex",
                      "Alternative Household Composition People",
                      "Ethnic Group",
                      "Family Composition And Number Of Children By Economic Activity",
                      "Household Composition People",
                      "Marital Status",
                      "Sex",
                      "Tenure By Population");
    break;
  }

  selectbox=document.getElementById('variableSelector');

  for ( var i=selectbox.options.length-1;i>=0;i--) {selectbox.remove(i);}

  for(i=0;i<desiredValues.length;i++) {
    addOption(selectbox, desiredValues[i], desiredValues[i]);
  }

  selectbox.disabled = false;

  var gobutton = document.getElementById('previewandbuy');
  gobutton.disabled=false;

}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    obj['on'+evType]=fn;
    return true;
  }
}


document.getElementById('variableSelector').disabled = true;
document.getElementById('previewandbuy').disabled = true;


for (var i=1; i<6; i++) {
  var selector = document.getElementById('cat'+i);
  addEvent(selector,'click',changeOptions,false);
}