// browser sniffer
function Browser(){
  this.iE = navigator.appName.toLowerCase().indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 1 : 0;
  this.win = navigator.userAgent.toLowerCase().indexOf('windows') != -1 ? 1 : 0;
  this.safari =  navigator.userAgent.toLowerCase().indexOf('safari') != -1 ? 1 : 0;
  this.opera =  navigator.userAgent.toLowerCase().indexOf('opera') != -1 ? 1 : 0;    
  this.mozilla = navigator.appName.toLowerCase().indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
}
var browser = new Browser();

// handy timer
var animTimer;
animTimer = [];

// framebuster
if (window!= top)top.location.href=location.href;

// getElementById
function getEl(el){
  return document.getElementById(el);
}

//top nav
var activeMenu;
var active;
active = function(id) {
var nav = document.getElementById(id);
if (!nav){return;}
var e = nav.getElementsByTagName("LI");
for (var i=0; i<e.length; i++) {
	e[i].onmouseover=function() {
     if (activeMenu){activeMenu.onmouseout();}
     activeMenu = this;
		this.className+=" active";}
	e[i].onmouseout=function() {
		this.className=this.className.replace(/active/g, '');}
	}
	navFocus(id,true);
}

//focus nav on tab
var navFocus;
navFocus = function(id,mouseOverMenu){
  var subnav = document.getElementById(id);
   if (!subnav){return;}  
   var list = subnav.getElementsByTagName("A");
   for (var i = 0; i < list.length; i++){
      var e = list[i];
      if (e.parentNode.parentNode.id == id){
		  if (mouseOverMenu){
		    e.onfocus = function(){this.parentNode.onmouseover();}
		  }
		  else {
		    e.onfocus = function(){this.parentNode.onclick();}
		  }
      }
    }
	if (list.length == 0){return;}
   var lastSub = list[list.length-1];
   if (lastSub.parentNode.parentNode.id == id){return;}
    lastSub.onblur = function(){
     this.parentNode.parentNode.parentNode.onmouseout();
  }
}

// tabbed simple
if (document.getElementById && document.getElementsByTagName && document.createElement) {
	document.write('<style type="text/css">#tabs #agenda{ display: none; }</style>');
}
function setTab() {
	var as = document.getElementById('toggle').getElementsByTagName('a');
	for (var i = 0; i < as.length; i++) {
		as[i].onclick = function() {
			toggle(this);
			return false;
		}
	}
	toggle(as[0]);
}
function toggle(s) {
	var id = s.href.match(/#(\w.+)/)[1];
	s.parentNode.parentNode.parentNode.className = id;
	  if(id == 'nieuws') {
	  	document.getElementById('agenda').style.display = 'none';
	  	document.getElementById(id).style.display = 'block';
	  }
	  else if(id == 'agenda') {
	  	document.getElementById('nieuws').style.display = 'none';
	  	document.getElementById(id).style.display = 'block';
	 }
}

// setClassName
function setClassName(el,className){
  if (!className){
    return;
  }
  if (el.getAttribute('className') != null){
    el.setAttribute('className',className);
  }
  else {
    el.setAttribute('class',className);
  }
}

// getClassName
function getClassName(el){
  var cN;
  if (el.getAttribute('className') != null){
    cN = el.getAttribute('className');
  }
  else {
    cN = el.getAttribute('class');
  }
  return cN ? cN : '';
}

// set external links
var setExternalLinks = function(){
  var localDomain = (location.href.split('/')[2]);
    
    var localExtensionsInNewWindow = Array('doc','xls','pdf');
    
    var list = document.getElementsByTagName('A');
    for (var i = 0; i < list.length; i++){
      var aEl = list[i];
      var aElHref = aEl.href;
      
      // check for extensions
      var extension = (aElHref.substring(aElHref.length - 4,aElHref.length)).toLowerCase();
      var foundExtension = false;
      for (var j = 0; j < localExtensionsInNewWindow.length; j++){
        if (extension == '.' + localExtensionsInNewWindow[j]){
          foundExtension = true;
          break;
        }
      }
      
      // open in new window if conditions are right
      if ((aElHref.split('/')[2] != localDomain && aElHref.indexOf('mailto:') == -1 && aElHref.indexOf('javascript:') == -1) || foundExtension){
        aEl.onclick = function(){
        window.open(this.href);
        return false;
      }
    }
  }
};

//hover form buttons
var setHover = function(){
var hbg = document.getElementsByTagName('input');
	for (var i = 0; i < hbg.length; i++) {		
		if(hbg[i].getAttribute('type')=='submit' || hbg[i].getAttribute('type')=='reset' || hbg[i].getAttribute('type')=='button' || hbg[i].getAttribute('type')=='file') {
			hbg[i].onmouseover=function(){
				this.className = 'buttonhover';
			}
			hbg[i].onmouseout=function(){
				this.className = 'button';
				}
			}
		}
	}
//color test
var setColor = function(){
var c = document.getElementById('colors');
var d = c.getElementsByTagName('A');
	for (var i = 0; i < d.length; i++) {		
		d[i].onmouseover=function(){
			document.getElementsByTagName('body')[0].className = this.parentNode.className;
		}
	}
}
//keuzes div:hover for IE
var setKeuzes = function(){
var k = document.getElementById('keuzes');
var l = k.getElementsByTagName('DIV');
	for (var i = 0; i < l.length; i++) {		
	if (l[i].className=='block'){
		l[i].onmouseover=function(){
			this.className = 'active';
			//this.className += ' active';
		}
		l[i].onmouseout=function(){
			this.className = 'block';
			//this.className = this.className.replace(/\s*active/, "");
			}
		}
	}
}

//toggle
function showhide(id) {
	var el = document.getElementById(id).style; 
	  if(el.display == "none") {
	  el.display = "block";}
	  else if(el.display == "block") {
	  el.display = "none";}
} 
//layout case switcher 
var currentLarge = 1;
function checkWindowWidth() {
	var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 960) || document.body.clientWidth < 960);
	if (smaller) {
		if (currentLarge == 0){
			return;
		}
		currentLarge = 0;
		//document.getElementsByTagName('body')[0].className = 'small';
		getEl('framework').className = 'small';
	}
	else {
		if (currentLarge == 1){
			return;
		}
		currentLarge = 1;
		//document.getElementsByTagName('body')[0].className = '';
		getEl('framework').className = '';
		}
	}

function setupSubNav() {
  var n = getEl('subnavlist');
  var nl = n.getElementsByTagName('span');
  for (var i = 0, l = nl.length; i < l; i++) {
    if (nl[i].parentNode.getElementsByTagName("ul").length > 0) {
      nl[i].onclick = function() {
        if (this.parentNode.className.indexOf('active') > -1)
          this.parentNode.className = 'haschildren';
        else
          this.parentNode.className = 'haschildren active';
      };
    }
  }
}

window.onload = function(){
	checkWindowWidth();
	if (getEl('nav'))active('nav');
	if (getEl('keuzes'))setKeuzes();
	if (getEl('colors'))setColor();
	if (getEl('tabs'))setTab();
	if (getEl('subnavlist'))setupSubNav();
}
window.onresize = function(){
	checkWindowWidth();
}

function PositionPopup(popup) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
	popup.style.left = ( (myWidth / 2) - (350 / 2) ) + 'px';
	popup.style.top = ( (myHeight / 2) - (400 / 2) + scrOfY) + 'px';
}

/* lock_website()
 * Kan worden gebruikt om de website helemaal af te schermen.
 */
function lock_website(noScroll)
{
	var lock = document.getElementById('lock_website');

	if(lock.style.display == 'none')
	{
		var content_height	= document.body.scrollHeight;
		if (content_height < document.body.clientHeight) {
			website_height = document.body.clientHeight;	
		} else  {
			website_height = content_height;
		}
		
		var client_width = get_window_size();
		if (client_width < 1324) {
			//lock.style.width	= client_width
			document.getElementById('lock_website').style.width = (client_width-20) + 'px';
		} else {
			//lock.style.width	= 1324;
			document.getElementById('lock_website').style.width = '1324px';
		}
		
		hideDropdowns();

		//lock.style.height		= website_height;
		document.getElementById('lock_website').style.height = website_height + 'px';
		lock.style.display	= '';

		if (!noScroll) {
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
			if (scrOfY > 140) window.scrollTo(scrOfX,0);
		}
	}
	else
	{
		lock.style.display = 'none';
		showDropdowns();
	}
}

/* show_popup()
 * Laat soort van pop up zien als tabel over de website heen.
 * Is dus geen nieuw venster.
 * Heeft wel CSS nodig om te functioneren (position: absolute; z-index: 1; etc..)
 */
function show_popup(element_id)
{
	document.currentPopup = element_id;

	var popup_container	= document.getElementById('popup_container');
	var el		= document.getElementById(element_id);
	var div_el	= document.getElementsByTagName('div');
	/* Open dan eventueel een nieuwe popup
	 */
	
	if(el.style.display == 'none')
	{
		/*
		 Geef het element weer
		*/
		popup_container.style.display = '';
		el.style.display	= '';

		hideDropdowns();
	}
	else
	{
		popup_container.style.display = 'none';
		el.style.display = 'none';	

		showDropdowns();
	}
	
	/* Sluit eerst
	 * alle huidige popups
	 */
	for(var i = 0; i < div_el.length; i++)
	{
		/* Als 'popup' 
		 * in de class naam voorkomt
		 * moet het (meestal) element worden aangepast.
		 * Met uitzondering van de container en element id.
		 */
		 
		if(div_el[i].className.indexOf('popup') != -1)
		{
			/* Sluit alleen 
			 * de popups die open zijn.
			 */
			 
			if(div_el[i].style.display != 'none' && div_el[i].id != element_id && div_el[i].id != 'popup_container' && div_el[i].className != 'popup_product_enlarge')
			{
				div_el[i].style.display = 'none';
			}
		}
	}
}

function close_message_popup()
{
	var div_el	= document.getElementsByTagName('div');

	/* Sluit eerst
	 * alle huidige popups
	 */
	for(var i = 0; i < div_el.length; i++)
	{
		/* Als 'popup' 
		 * in de class naam voorkomt
		 * moet het (meestal) element worden aangepast.
		 * Met uitzondering van de container en element id.
		 */
		 
		if(div_el[i].className.indexOf('popup') != -1)
		{
			/* Sluit alleen 
			 * de popups die open zijn.
			 */
			 
			if(div_el[i].style.display != 'none' && div_el[i].id != 'popup_container' && div_el[i].className != 'popup_product_enlarge')
			{
				div_el[i].style.display = 'none';
			}
		}
	}
	lock_website();
}

/* get_window_size()
 * Functie om de grootte van het scherm te bepalen. Niet de resolutie maar het scherm.
 * Dit is dus variabel.
 */
 
function get_window_size() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth + 21;  /* Afwijking? */
  }
 return myWidth;
}

function showPopup() {

PositionPopup(document.getElementById('popup_message'));

document.getElementById('popup_container').style.display = '';
document.getElementById('popup_message').style.display = '';

lock_website(true);

}

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}
// hide dropdowns if IE6 or below
function hideDropdowns() {
	if ( (navigator.appName == 'Microsoft Internet Explorer') && (getIEVersionNumber() < 7) ) {
		hideAllByTag('select');
	}
}
function showDropdowns() {
	if ( (navigator.appName == 'Microsoft Internet Explorer') && (getIEVersionNumber() < 7) ) {
		showAllByTag('select','inline');
	}
}
function showAllByTag(tagName,dispType) {
        var elements = document.getElementsByTagName(tagName);
        var i = 0;
        if (dispType == "") {
                dispType = inline;
        }
        while (i < elements.length) {
		if (elements[i].style)
	                elements[i].style.display = dispType;
                i++;
                }
}
function hideAllByTag(tagName) {
        var elements = document.getElementsByTagName(tagName);
        var i = 0;
        while (i < elements.length) {
		if (elements[i].style)
	                elements[i].style.display = "none";
                i++;
                }
}

