/* Utility functions */
function addEvent(obj, evType, fn) {
  /* adds an eventListener for browsers which support it Written by Scott Andrew */
  if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
  else if (obj.attachEvent) { var r = obj.attachEvent("on"+evType, fn); return r; }
  else { return false; }
}
function element(id) {
  var e = false;
  if (document.getElementById) { e = document.getElementById(id); }
  else if (document.all) { e = document.all(id); }
  return e;
}
// login
function toPassword(objOldInput) {
	var objNewElement = document.createElement('input');
	objNewElement.setAttribute('type', 'password');
    objNewElement.setAttribute('name', objOldInput.name);
	objOldInput.parentNode.replaceChild(objNewElement, objOldInput);
	toPassword.el = objNewElement;
	setTimeout('toPassword.el.focus()',100);
	return true;
}
// menu functions
function hasULchildren(linode) {
	var uls = linode.getElementsByTagName('ul')[0];
	if(uls) return true;
	return false;
}
function efMenu(menuid, menutype) {
	var menudiv = element(menuid);
	var listitems = menudiv.getElementsByTagName('li');
	if(listitems){
		for(var i=0; i<listitems.length; i++){
			var listitem = listitems[i];
			if(hasULchildren(listitem)) {
				listitem.onmouseover = function (e) {
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1) { this.firstChild.className = 'active mouse'; }
						else { this.firstChild.className = 'mouse'; }
					}
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {child.style.visibility = 'visible'; }
					}
					return false;
				};
				listitem.onmouseout = function (e) {
					for (var i=0; i < this.childNodes.length; i++) {
						var child = this.childNodes[i];
						if (child.nodeName.toUpperCase() == 'UL') {	child.style.visibility = 'hidden';}
					}
					if (this.firstChild.nodeName.toUpperCase() == 'A') {
						if(this.firstChild.className.indexOf('active') != -1){ this.firstChild.className = 'active'; }
						else { this.firstChild.className = ''; }
					}
					return false;
				};
			}
		}
	}
	return void(0);
}
// de functie displayResultBox wordt ook gebruikt in xdis.js
function displayResultBox(string){
	var objResultBox = element('results');
	if(objResultBox) objResultBox.innerHTML = string;
}
// config for EFbox
function EFdata(){
	this.href = '';
	this.title = '';
	this.content = '';
	this.hideble = false;
}
// config for google maps
function classConfig(){
	this.host = '';
	this.search = '';
}
var popup = '';
function openPopup(url, name, w, h, menubar, scroll){
	var centerX, centerY, windowLeft, windowTop;
	if(document.getElementById) {
		centerX = parseInt(screen.width / 2);
		centerY = parseInt(screen.height / 2);
	} else {
		centerX = parseInt(screen.availWidth / 2);
		centerY = parseInt(screen.availHeight / 2);
	}
	windowLeft = centerX - parseInt(w/2);
	windowTop = centerY - parseInt(h/2);
	var parameters  = 'toolbar=no,location=no,resizable=yes,menubar=' + menubar;
	parameters += ',width=' + w + ',height=' + h + ',top=' + windowTop + ',left=' + windowLeft;
	if(scroll != null) parameters += ',scrollbars=yes';
	if (!popup.closed && popup.location) {
  		popup.location.href = url;
 	} else {
 		popup = window.open(url, name, parameters);
  		if(!popup.opener) popup.opener = self;
 	}
	if (window.focus) {popup.focus()}
	return false;
}


/* Better(?) Image cross fader (C)2004 Patrick H. Lauke aka redux */
var	previousImage, currentImage, galleryImages, gallery, galleryId = 'gallery'; /* general variables */
function preInit() { /* hide the image gallery list before even onload is triggered */
	if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
		gallery.style.visibility = "hidden";
		clearTimeout(preInitTimer);
	} else { preInitTimer = setTimeout("preInit()",2); }
}
function fader(imageNumber,opacity) {
	var obj=galleryImages[imageNumber];
	if (obj.style.MozOpacity!=null) { obj.style.MozOpacity = (opacity/100) - .001; }
	else if (obj.style.opacity!=null) { obj.style.opacity = (opacity/100) - .001; }
	else if (obj.style.filter!=null) { obj.style.filter = "alpha(opacity="+opacity+")"; }
}
function fadeInit() {
	if (document.getElementById) { //preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		gallery=document.getElementById(galleryId);
		if(gallery){
			galleryImages = gallery.childNodes; /* get all child nodes... */
			for(i=0;i<galleryImages.length;i++) {
				galleryImages[i].style.position='absolute';
				galleryImages[i].style.top=0;
				galleryImages[i].style.zIndex=0;
				fader(i,0); /* set their opacity to transparent */
			}
			gallery.style.visibility = 'visible'; /* make the list visible again */
			currentImage=0; /* initialise a few parameters to get the cycle going */
			previousImage=galleryImages.length-1;
			opacity=100;
			fader(currentImage,100);
			window.setTimeout("crossfade(100)", 2500); /* start the whole crossfade process after a second's pause */
			return void(0);
		}
		else { return false; }
	}
	else { return false; }
}
function crossfade(opacity) {
    if (opacity < 101) {
        fader(currentImage,opacity);
        opacity += 5;
        window.setTimeout("crossfade("+opacity+")", 100);
    } else {
        fader(previousImage,0);
        previousImage=currentImage;
        currentImage+=1;
        if (currentImage>=galleryImages.length) { currentImage=0; }
        galleryImages[previousImage].style.zIndex = 0;
        galleryImages[currentImage].style.zIndex = 10;
        opacity=0;
        window.setTimeout("crossfade("+opacity+")", 2500);
    }
}
/* initialise fader by hiding image object first */
addEvent (window,'load',fadeInit);
