/* 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;
}
function remBrowser() {
	if (document.login.onthoud.checked){
		if (!confirm("Door deze optie te kiezen, wordt u iedere keer automatisch ingelogd\nwanneer u deze site bezoekt.\n\nGebruik deze optie NOOIT in publieke gelegenheden, zoals bibliotheken,\nInternet café\'s en op publiek toegankelijke computers.\n\nLet op: wilt u volgende keer automatisch inloggen druk niet op Logoff. \nIn dat geval wordt u namelijk de volgende keer alsnog\nniet automatisch ingelogd en dient u opnieuw uw logingegevens in te vullen."))
	  	{ document.login.onthoud.checked = false; }
	}
}
function errorDialogClose(id){
	var dialog =  element(id);
	if(dialog) dialog.style.display = 'none';
}
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(listitem.parentNode.className == menuid){
				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;
					};
					// onmouseout function
					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);
}

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;
}

function giveLiHover(strId) {
	var liholder = element(strId);
	if(liholder){
		var listitems = liholder.getElementsByTagName('li');
		if(listitems){
			for(var i=0; i<listitems.length; i++){
				listitems[i].onmouseover = function (e) {
					if(this.className.indexOf('archive') == -1) {
						if(this.className.indexOf('active last') != -1) { this.className = 'active last hover'; }
						else if(this.className.indexOf('active') != -1) { this.className = 'active hover'; }
						else if(this.className.indexOf('last') != -1) { this.className = 'last hover'; }
						else { this.className = 'hover'; }
					}
				}
				listitems[i].onmouseout = function (e) {
					if(this.className.indexOf('archive') == -1) {
						if(this.className.indexOf('active last') != -1) { this.className = 'active last'; }
						else if(this.className.indexOf('active') != -1) { this.className = 'active'; }
						else if(this.className.indexOf('last') != -1) { this.className = 'last'; }
						else { this.className = ''; }
					}
				}
			}
		}
	}
}

function stepForm() {
	var objPartnermee = element('partnerIk neem mijn partner mee.');
	var objHTMLPartner = element('htmlPartner');
	if(objHTMLPartner){ objHTMLPartner.style.display = 'none'; }
	if(objPartnermee) {
		objPartnermee.onclick = function() {
			if(objPartnermee.checked) { if(objHTMLPartner) objHTMLPartner.style.display = 'block'; }
			else { if(objHTMLPartner) objHTMLPartner.style.display = 'none'; }
		}
	}
}

function user_response(){
	var msg = '';
	for( var i = 0; i < arguments.length; i++) {
		if(document.getElementById(arguments[i]).value == '') { msg += ' - '+document.getElementById(arguments[i]).title+'\n'; }
	}
	if(msg != '' && msg != 'undefined') {
		msg = 'De volgende velden mogen niet leeg zijn:\n' + msg;
		alert(msg);
		return false;
	}else{ return true; }
}

function initLiHovers(){
	giveLiHover('newsBox');
	giveLiHover('agendaBox');
}
addEvent(window, 'load', initLiHovers);
addEvent(window, 'load', stepForm);