var secl = new Array();

function init_page() {
  try {
    initialize_calendar();
  } catch(e) {;}
  center_content();
  startList();
}

function get_page(art_no)
{
  my_form = document.getElementById('myfrm');
  document.getElementById('start').value=parseInt(art_no);
  my_form.submit();
}

function initialize_calendar() {
  var now = new Date();
  var day = now.getDate();
  var month = now.getMonth()+1;
  var year = now.getYear()+1900;
  if (document.all)
    year = now.getYear();

  smnth = document.getElementById('selectedmonth').childNodes.item(0).data.split(',');
  var syear = parseInt(smnth[0]);
  var smonth = parseInt(smnth[1]);
  var currentmonth = false;
  //alert(month+' '+smonth+' '+year+' '+syear);
  if (month == smonth && year == syear)
    currentmonth = true;

  //Initialize the calendarclicks etc.
  cells = document.getElementsByTagName('td');
  for (ix=0;ix < cells.length;ix++) {
    mycell = cells.item(ix);
    if (mycell.className == 'calday' || mycell.className == 'calweday') {
      if (document.all)
        mycell.style.cursor = 'hand';
      else
        mycell.style.cursor = 'pointer';
      if (currentmonth) {
        if (mycell.childNodes.length > 0) {
          myday = mycell.childNodes.item(0).data;
          if (day == myday) {
            mycell.className='current';
            mycell.setAttribute('className', 'current');
          }
        }
      }
      addEvent(mycell, 'click', date_clicked, true);
    }
    if (mycell.className == 'calhead') {
      if (document.all)
        mycell.style.cursor = 'hand';
      else
        mycell.style.cursor = 'pointer';
      if (mycell.id == 'titlehead') {
        addEvent(mycell, 'click', month_clicked, true);
      }else{
        addEvent(mycell, 'click', head_clicked, true);
      }
    }
  }
}
function date_clicked(evt) {
  evt = (evt) ? evt : ((event) ? event : null);
  target = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  day = target.childNodes.item(0).data;
  mnt = document.getElementById('selectedmonth').childNodes.item(0).data.split(',');
  loc = window.location.href;
//  alert(loc.split('?')[0]+'?year='+mnt[0]+'&month='+mnt[1]+'&day='+day);
  window.location.href = loc.split('?')[0]+'?year='+mnt[0]+'&month='+mnt[1]+'&day='+day;
}
function head_clicked(evt) {
  evt = (evt) ? evt : ((event) ? event : null);
  target = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  nw_arr = target.id.split(',');
  loc = window.location.href;
//  alert(loc);
  window.location.href = loc.split('?')[0]+'?year='+nw_arr[0]+'&month='+nw_arr[1];
}
function month_clicked(evt) {
  evt = (evt) ? evt : ((event) ? event : null);
  target = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  mnt = document.getElementById('selectedmonth').childNodes.item(0).data.split(',');
  loc = window.location.href;
//  alert(loc);
  window.location.href = loc.split('?')[0]+'?year='+mnt[0]+'&month='+mnt[1];
}

/* Centreer content */
center_content = function() {
  var ch = 0;
  var cw = 0;
  cwidth = 761;
  thecontent = document.getElementById('contentbox');

  if (self.innerHeight) // all except Explorer
  {
    cw = self.innerWidth;
    ch = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    cw = document.documentElement.clientWidth;
    ch = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    cw = document.body.clientWidth;
    ch = document.body.clientHeight;
  }

  leftpos = (cw - cwidth) / 2;
  thecontent.style.left = leftpos + 'px';

  thecontent.style.visibility = 'visible';
}

/* Patch voor Internet Explorer CSS2 :hover werkt hier niet TC */
startList = function() {
  if (document.all&&document.getElementById) {
    navRoot = document.getElementById("nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          this.className+=" over";
        }
        node.onmouseout=function() {
          this.className=this.className.replace(" over", "");
        }
      }
    }
  }
  document.getElementById('xxmenu').style.display='block';
  document.getElementById('xxmenu').style.visibility='visible';
}

function show_photo(url)
{
/*
  newwindow = window.open(url,'name','height=600,width=800,top=0,left=0');
  if (window.focus) {
    newwindow.focus()
  }
*/
  window.location.href=url;
}
/* HILITEWORD */
function highlightWord(word, color, element)
{
    var i;
    for (i = 0; i < element.childNodes.length; i++)
    {
        childNode = element.childNodes[i];
        if (childNode.nodeType == 3 /*childNode.TEXT_NODE*/)
        {
            var j;
            while ((j = childNode.data.toLowerCase().indexOf(word.toLowerCase())) != -1)
            {
                continuingText = childNode.data.substr(j + word.length, childNode.data.length);
                originalWordStuff = childNode.data.substr(j, word.length);
                childNode.data = childNode.data.substr(0, j);

                newNode = document.createElement("font");
                newNode.style.background = color;
                newNode.appendChild(document.createTextNode(originalWordStuff));
                continuingNode = document.createTextNode(continuingText);

                // insert continuingNode first, and then insertBefore it newNode.
                if (i == (element.childNodes.length - 1))
                    element.appendChild(continuingNode);
                else
                    element.insertBefore(continuingNode, element.childNodes[i+1]);
                element.insertBefore(newNode, continuingNode);

                i += 2;

                childNode = continuingNode;
            }
        }
        else if (typeof childNode.htmlFor != "undefined")
        {
            // script element, ignore.
        }
        else if (childNode.getAttribute && childNode.getAttribute("color") == color)
        {
            // already coloured, probably.
        }
        else if (childNode.childNodes.length)
        {
            highlightWord(word, color, childNode);
        }
    }
}
onload=init_page;
onresize=center_content;