//====================== Browser checks
var Opera = window.opera ? true : false;
var IE = (document.all && document.getElementById && !Opera) ? true:false;
var noresizing = false;
//====================== 
//====================== Initialiseer de volgende functies
function init(){

  //voegt mouseover/mouseouts fases en css voor wetkalender toe
  //zonder js zijn alle fases gewoon onder elkaar te zien
  faseOver();
/*  var head = document.getElementsByTagName("head")[0];
  var stylesheet = document.createElement("link");
  stylesheet.setAttribute("type","text/css");
  stylesheet.setAttribute("rel","stylesheet");
  stylesheet.setAttribute("media","screen");
  stylesheet.setAttribute("href","../css/wetkalender.css");
  head.appendChild(stylesheet); */

  if(IE && !noresizing){ 
    //MinimumSize(); 
  }
  
  //alleen uitvoeren op foto-module pagina
  if(document.getElementById("foto-module")) {
    startFotoModule();
    //toon bladeren functie
    toonBladeren();
  }
  
  /*tekstGrootte(); */
  _printKnop();
  faseOver();
  initAankeilers();
  initUitklapSubnavigatie();
  initFormulierBevestiging();
/*  externalLinks(); NIET openen in nieuw window */
  try { initPage(); }
  catch(e) {}
  try { initPageType(); }
  catch(e) {}
  
  if (is.ns4comp) document.captureEvents(Event.MOUSEMOVE)
  document.onmousemove = getMousePos;
}

//onderaan js file:

//====================== voegt rollover en click functie toe aan class="aankeiler"
function externalLinks() {
  var extLinks = getElementsByClassName("extern");
  for (var i=0; i<extLinks.length; i++) {
    if (extLinks[i].getAttribute("href") && extLinks[i].getAttribute("href").indexOf("script:") == -1) extLinks[i].setAttribute("target","_blank");
  }
}
//====================== 

//====================== voegt rollover en click functie toe aan class="aankeiler"
function initUitklapSubnavigatie() {
  var subnavs = new Array("uitklapnavigatie_onderwerpen","uitklapnavigatie_normaal","uitklapnavigatie_subtype");
  for (var s=0; s<subnavs.length; s++) {
    navRoot = document.getElementById(subnavs[s]);
    for (i=0; IE && navRoot && navRoot.childNodes && i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          delayedOver(this,true)
        }
        node.onmouseout=function() {
          delayedOver(this,false)
        }
      }
    }
  }
}

//====================== bekijkt of er een formulier bestaat waarvoor gebruiker bevestigingsvinkje moet zetten
function initFormulierBevestiging() {
  checkboxconfirm =  document.getElementById("gebruikersbevestiging");
  if (checkboxconfirm)
  {
    verzendknop =  document.getElementById("verzenden");
    verzendknop.disabled = true;
    checkboxconfirm.onclick = function() {
      if (checkboxconfirm.checked == true)
	  {
	    verzendknop.disabled = false;
	  }
	  else
	  {
	    verzendknop.disabled = true;
	  }
    }
  }
}

var overTimer;
var overObj;

function delayedOver(obj,show) {
  if (overTimer) {
    clearTimeout(overTimer);
  }
  if (show) {
    if (overObj) removeClass(overObj,"over");
    addClass(obj,"over");
    overObj = obj;
  }
  else {
    overTimer = window.setTimeout('removeOverClass()',512);
  }
}

function removeOverClass() {
  if (overTimer) {
    clearTimeout(overTimer);
  }
  removeClass(overObj,"over");
}

//====================== 

//====================== voegt rollover en click functie toe aan class="aankeiler"
function initAankeilers() {
  var aankeilers = getElementsByClassName("aankeiler");
  for (var i=0; i<aankeilers.length; i++) {
    var anchors = aankeilers[i].getElementsByTagName("a");
    if (anchors.length > 0) {
      var anchor = anchors[anchors.length-1];
      aankeilers[i].setAttribute("title",anchor.getAttribute("title"));
      aankeilers[i].ref = anchor.getAttribute("href");
      
      if (anchor.className.indexOf("extern") != -1) {
        anchor.ref = anchor.getAttribute("href");
        anchor.href = "javascript:void(0);";
        anchor.onmouseover = function() {
          window.status = this.ref;
        }
        anchor.onmouseout = function() {
          window.status = "";
        }
        addClass(aankeilers[i],"extern");
      }
      
      aankeilers[i].onclick = function() {
        this.className.indexOf("extern") != -1?window.open(this.ref):document.location.href = this.ref;
      }
      aankeilers[i].onmouseover = function() {
        window.status = this.ref;
        addClass(this,"over");
      }
      aankeilers[i].onmouseout = function() {
        window.status = "";
        removeClass(this,"over");
      }
    }
  }
}
//====================== 

//====================== voegt rollover functie toe aan span class="fase"
function faseOver()
{
  if(document.getElementById("wetkalender") && IE)
  {
    var ul = document.getElementById("wetkalender");
    var spans = ul.getElementsByTagName("span");
    for(var i=0; i<spans.length; i++){
      if(spans[i].className.indexOf("fase ") !=-1 && spans[i].className.indexOf("huidige") ==-1) {
        spans[i].onmouseover = function () { toggleFaseToelichting(this, 'toon'); };
        spans[i].onmouseout = function () { toggleFaseToelichting(this, 'verberg'); };      
      }
    }
  } 
}
//====================== 

//====================== voegt rollover functie voor toelichting
function toggleFaseToelichting(item, status) {
  var spans = item.getElementsByTagName("span");
  for(var i=0; i<spans.length; i++){
    if(spans[i].className.indexOf("toelichting") !=-1) {
      if(status=="toon") {
        spans[i].style.display = 'block'; 
        item.className = item.className + " over";
      }
      else if(status=="verberg") {
        spans[i].style.display = 'none'; 
        item.className = item.className.replace(" over", "");
      }
    }
  }
  return false;
 }
//====================== 

//====================== Aanroep functies bij Onload-event
window.onload = function() {
  init(); 
}
//====================== 
//====================== Aanroep functies bij Onresize-event
window.onresize = function() {
  if(IE){ 
    //MinimumSize(); 
    
  } 
}
//====================== 
//====================== Zet print-knop visibility en functionaliteit
function _printKnop() {
  // bestaat de print-knop?
  var pk = document.getElementById('print-knop');
  if (!pk) {
    return false;
  }
  else {
    // laat ons de print-knop zien!
    pk.style.display = 'inline';
    plink = pk.getElementsByTagName("A")[0];
    // print deze pagina
    this.plink.onclick = function () {
      window.print();
          return false;
    }
  }
}
// <li id="print-knop"><a href="#">Print</a></li>
function printKnop() {
  if (document.getElementsByTagName && window.print && document.getElementById("voet-zone") && document.getElementById("naarboven-knop")) {
    var pk = document.createElement("li");
    pk.setAttribute("id","print-knop");
    var pk_a = document.createElement("a");
    pk_a.setAttribute("href","#");
    pk_a.onclick = function () {
      window.print();
          return false;
    }
    var pk_text = document.createTextNode("Print");
    pk_a.appendChild(pk_text);
    pk.appendChild(pk_a);
    var vz_menu = document.getElementById("voet-zone").getElementsByTagName("ul")[0];
    var naar_boven = document.getElementById("naarboven-knop");
    vz_menu.insertBefore(pk,naar_boven);
  }
}

//====================== Zet mouseover/mouseout functionaliteit op knoppen (buttons)
function knopMuisOver()
{
  var alleInputTags=document.getElementsByTagName('input');
  for(var i=0;i<alleInputTags.length;i++)
    {
    if(alleInputTags[i].className.indexOf('zoek') != -1 || alleInputTags[i].className.indexOf('toon') != -1 || alleInputTags[i].className.indexOf('knop') != -1)
    {
      //mouseover toevoegen
      alleInputTags[i].onmouseover = function () { veranderKlasse(this,  this.className + " muisOver"); };
      //mouseout toevoegen (verwijder " muisOver")
      alleInputTags[i].onmouseout = function () { veranderKlasse(this,  this.className.substring(0, this.className.length - 9)); };
    }
    }
 }
 
 /* hulpfunctie voor knopMuisOver() */
 function veranderKlasse(item, klasse)
 {
  item.className = klasse;
  return false;
 }

/* toon bladeren ul */
function toonBladeren() {
  var alleOngeordendeLijsten = document.getElementsByTagName("ul");
  for(var i=0; i<alleOngeordendeLijsten.length; i++){
    if(alleOngeordendeLijsten[i].className.indexOf("bladeren") !=-1) alleOngeordendeLijsten[i].style.display = "block";
  }
}

/* general helper functions */

// adds css rule
function cssAddRule(selector, declaration) {
  if (document.all)
    document.styleSheets[0].addRule(selector, declaration);
  else
    document.styleSheets[0].insertRule(selector + "{" +declaration + "}", 0)
}

// removes css rule
function cssRemoveRule(selector) {
  var mysheet = document.styleSheets[0];
  for (var i=0; i<mysheet.rules.length; i++) {
    if (mysheet.rules[i].selectorText == selector) {
      if (document.all)
        mysheet.removeRule(i);
      else
        mysheet.deleteRule(i);
    }
  }
}

// returns array of elements with class classname
function getElementsByClassName(classname) {
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = document.all?document.all:document.getElementsByTagName("*");
  for(var i=0,j=els.length; i<j; i++)
    if(re.test(els[i].className))a.push(els[i]);
  return a;
}

// returns text value of an element
getValue = function(el) {
  if (el && el.firstChild)
    return el.firstChild.nodeValue;
  else
    return "";
}

// add & remove css classes
function addClass(el,clName) {
  if (el) {
    if (el.className.indexOf(clName) < 0)
      el.className += " "+clName;
  }
}
function removeClass(el,clName) {
  if (el)
    el.className = el.className.replace(clName,"");
}