﻿function textFieldFocus(object, defaultValue) {
  if (object.value == defaultValue) {
    object.value = "";
  }
}

function textFieldBlur(object, defaultValue) {
  if (object.value == "") {
    object.value = defaultValue;
  }
}

function setNavMargin() {
  document.getElementById('nav').style.marginLeft = (document.getElementById('top').offsetWidth - document.getElementById('nav').offsetWidth) / 2 + "px";
}

function toggle(id) {
  var d = document.getElementById(id)
  if (d) {
    if (d.style.display == "block") 
    {
      d.style.display = "none";
    }
    else
    {
      d.style.display = "block";
    }
  }else if (id) {
    if (id.style.display == "block") 
    {
      id.style.display = "none";
    }
    else
    {
      id.style.display = "block";
    }
  }
}

function uitklapBG(img) {
  //
  if (img.src.indexOf('uitklappen') > -1)
  {
    img.src = "/interface/images/btn_inklappen.gif";
  }
  else
  {
    img.src = "/interface/images/btn_uitklappen.gif";
  }
}

function twoCols(src, type) {
  type = "UL";
  var origList = document.getElementById('sitemap').childNodes[0];

  var leftList = document.createElement(type);
  var rightList = document.createElement(type);
  var junk = document.createElement(type);
  var container = document.createElement('div');
  
  var items = origList.getElementsByTagName('LI');

  var childs = origList.childNodes;
  var count = 0;
  for (i = 0; i < childs.length; i++) {
    if (childs[i].tagName == "LI") {
      count = count + 1;
    }
  }

  var left = 0;
  var right = 0;
  if (count % 2 == 0)
  {
    left = count /2;
    right = count /2;
  }
  else
  {
    left = count /2;
    right = count /2 - 1;
  }
  

  var itemsLength = left;
  for (i = 0; i < itemsLength; i++) {
    leftList.appendChild(items[0]);
  }

  itemsLength = right;
  for (i = 0; i < itemsLength; i++) {
    rightList.appendChild(items[0]);
  }
  
  container.appendChild(leftList);
  container.appendChild(rightList);

  leftList.setAttribute('class', 'left');
  rightList.setAttribute('class', 'right');
  container.setAttribute('class','twocol');
  if (document.all) {
    leftList.setAttribute('className', 'left');
    rightList.setAttribute('className', 'right');
    container.setAttribute('className','twocol');
  }
  
  if (type == 'ol') {
    rightList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1 );
  }
  origList.parentNode.replaceChild(container, origList);
  document.getElementById('sitemap').style.display = "block";
}

function allTwoCols (whichclass, type) {
  var uls = document.getElementsByTagName(type);
  for (var i=0; i< uls.length; i++) {
    if (uls[i].getAttribute('class') == whichclass || uls[i].getAttribute('className') == whichclass) {
      twoCols(uls[i], type.toLowerCase());
    }
  }
}
