function addOnloadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function enhanceCheckboxes()
{
  var ar = document.getElementsByTagName('input');
  for(var i=0; i < ar.length; i++) {
    if (ar[i].type == 'checkbox') {
      ar[i].style.display = 'none';
      var img = document.createElement('img');
      img.align = 'absmiddle';
      if (ar[i].checked) {
        img.src   = 'img/checkbox_checked.gif';
        img.title = 'Checked';
      } else {
        img.src   = 'img/checkbox_unchecked.gif';
        img.title = 'Unchecked';
      }
      img.onclick = toggleCheckbox;
      ar[i].parentNode.insertBefore(img, ar[i]);
    }
  }
}

function toggleCheckbox()
{
  if (this.title == 'Checked') {
    this.src                 = 'img/checkbox_unchecked.gif';
    this.title               = 'Unchecked';
    this.nextSibling.checked = false;
  } else {
    this.src                 = 'img/checkbox_checked.gif';
    this.title               = 'Checked';
    this.nextSibling.checked = true;
  }
}

function initAnfahrt()
{
  var anfahrt_s = document.getElementById('anfahrtbutton');
  var anfahrt_b = document.getElementById('anfahrt');
  if (anfahrt_s) {
    anfahrt_s.onclick = function() {
      document.getElementById('anfahrt').style.display = 'block';
    }
  }
  if (anfahrt_b) {
    anfahrt_b.onclick = function() {
      this.style.display = 'none';
    }
  }
}

addOnloadEvent(enhanceCheckboxes);
addOnloadEvent(initAnfahrt);