function setSection(chapter,section) {

  for (var i=1; i < sections.length; i++) {
    for (var j=0; j < sections[i].length; j++) {
      sections[i][j].style.visibility = 'hidden';
      sections[i][j].style.position   = 'absolute';
    }
  }

  sections[chapter][0].style.visibility       = 'inherit';
  sections[chapter][0].style.position         = 'inherit';
  sections[chapter][section].style.visibility = 'inherit';
  sections[chapter][section].style.position   = 'inherit';

}

function setStep(indexNr) {

  for (var i=1; i < steps.length; i++) {
    steps[i].style.visibility = 'hidden';
    steps[i].style.position   = 'absolute';
  }

  steps[indexNr].style.visibility = 'inherit';
  steps[indexNr].style.position   = 'inherit';

}

function hideField(idString) {
  var o = document.getElementById(idString);
  o.style.visibility = 'hidden';
  o.style.position   = 'absolute';
}


function showField(idString) {
  var o = document.getElementById(idString);
  o.style.visibility = 'inherit';
  o.style.position   = 'inherit';
}

function addInterface() {
  if (document.getElementById('interface_action').value == "") { alert('Sie müssen eine eindeutige Bezeichnung für diese Aktion festlegen.'); return false; }
  var o = document.getElementById('interface');
  var newInterface = "";

  newInterface += document.getElementById('interface_action').value + ',';
  newInterface += document.getElementById('interface_type').value + ',';
  if (document.getElementById('interface_mode_1').checked)
  newInterface += document.getElementById('interface_mode_1').value + ',';
  else
  newInterface += document.getElementById('interface_mode_0').value + ',';
  newInterface += document.getElementById('interface_template').value + ',';
  newInterface += document.getElementById('interface_insert').value + ',';
  newInterface += document.getElementById('interface_permission').value + "\n";

  o.value += newInterface;

  addToPreview(newInterface);

}

function addToPreview(entry) {
  var preview = document.getElementById('interface_preview');
  document.getElementById('table_preview').style.visibility = 'inherit';
  var mytr   = new Object();
  var mytd   = new Object();
  var mytext = new String();

  var entries = entry.split("\n");
  for (var i=0; i<entries.length; i++) {
    entries[i] = (entries[i]).split(",");

    if (entries[i][0]) {
      mytr   = document.createElement('tr');
  
      for (var j=0; j<(entries[i]).length; j++) {
  
        mytd   = document.createElement('td');
  
        if (j==2) {
          if (entries[i][j]==1)
          mytext = document.createTextNode('abgesichert');
          else
          mytext = document.createTextNode('default');
        } else {
          mytext = document.createTextNode(entries[i][j]);
        }
        mytd.appendChild(mytext);
        mytr.appendChild(mytd);
  
      }
  
      preview.appendChild(mytr);
    }

  }
  
}

function setInterfaceTemplate(entry) {
  var o = document.getElementById('interface');
  var myName = document.getElementById('input_name').value;

  var entries = entry.split("\n");
  for (var i=0; i<entries.length; i++) {
    entries[i] = (entries[i]).split(",");
    if (entries[i][0]) {
      entries[i][0] = myName + '_' + entries[i][1] + '_' + entries[i][0];
      entries[i] = (entries[i]).join(",");
    }
  }

  entry = entries.join("\n");

  o.value = entry;
  addToPreview(entry);

}