//-- Browsercheck
function BrowserCheck()
{
	var v;
	this.opera = navigator.userAgent.indexOf('Opera') > -1;
	this.konqueror = navigator.userAgent.indexOf('Konqueror') > -1;
	this.mac = navigator.userAgent.indexOf('Macintosh') > -1;
	this.ie = !this.opera && !!document.all && !!(v = navigator.userAgent.match(/MSIE (\d(\.\d)?)/));
	if (this.ie) this.ieversion = parseFloat(v[1]);
}
var is = new BrowserCheck();

var banner = null, bannerhide = 0, sky = null, quicksearch = null, qshide = 0;

function init_banner()
{
	if ((banner = document.getElementById('mainbanner')))
	{
		if (	(is.ie && /<(object|select|embed|applet)/i.test(banner.innerHTML)) ||
			(	(	(is.ie && is.ieversion < 5.5) ||
					is.opera ||
					is.konqueror
				) &&
				/<iframe/i.test(banner.innerHTML)
			)
		)
		{
			banner.left = getOffsetLeft(banner);
			banner.top = getOffsetTop(banner);
			bannerhide = 1;
		}
	}
}

function show_banner()
{
	if (banner && bannerhide) banner.style.display = 'block';
	if (quicksearch && qshide) quicksearch.style.display = 'block';
}

function hide_banner(submenu)
{
	if (bannerhide || qshide)
	{
		if (!submenu.left)
		{
			submenu.left = getOffsetLeft(submenu)
			submenu.top = getOffsetTop(submenu);
		}

		if (banner && bannerhide)
		{
			if (!(submenu.left > banner.left + banner.clientWidth || submenu.left + submenu.clientWidth < banner.left ||
				submenu.top > banner.top + banner.clientHeight || submenu.top + submenu.clientHeight < banner.top)) banner.style.display = 'none';
		}
	
		if (quicksearch && qshide)
		{
			if (!(submenu.left > quicksearch.left + quicksearch.clientWidth || submenu.left + submenu.clientWidth < quicksearch.left ||
				submenu.top > quicksearch.top + quicksearch.clientHeight || submenu.top + submenu.clientHeight < quicksearch.top)) quicksearch.style.display = 'none';
		}
	}
}

function init_sky()
{
	if ((sky = document.getElementById('skyscraper')))
	{
		var w = getDocumentProperty('clientWidth');
		var h = getDocumentProperty('scrollHeight');
		var o = document.getElementById('layout').offsetLeft + sky.offsetLeft + sky.clientWidth;

		if (w > o && h > skytop + 600)
		{
			if ((w - o) > 40)
			{
				//-- extra breed
				google_ad_width = 160;
				google_ad_format = '160x600_as';
				sky.style.width = '168px';
			}

			document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>');

			sky.style.position = 'absolute';
			sky.style.top = skytop + 'px';
			sky.style.visibility = 'visible';
		}
		else
		{
			sky.style.display = 'none';
			sky = null;
		}
	}
}

function show_sky()
{
	if (sky) sky.style.display = 'block';
}

function hide_sky(code)
{
	var left = getOffsetLeft(code), top = getOffsetTop(code);
	if (sky)
	{
		var skyleft = getOffsetLeft(sky), skytop = getOffsetTop(sky);
		if (!(left > skyleft + sky.clientWidth || left + code.clientWidth < skyleft ||
			top > skytop + sky.clientHeight || top + code.clientHeight < skytop)) sky.style.display = 'none';
	}
}

//-- skyscraper slide
var skymove = null;
var scrolltop = -1;
var skytop = 120;
function movesky()
{
	if (sky)
	{
                if (animate)
                {
                        if (skymove) clearTimeout(skymove);
                        skymove = setTimeout('slidesky()', 300);
                }
                else
                {
                        sky.style.top = (getDocumentProperty('scrollTop') + skytop) + 'px';
                }
	}
}

function slidesky()
{
	scrolltop = getDocumentProperty('scrollTop');
	var curtop = sky.offsetTop;

	if (curtop + 600 < scrolltop) curtop = scrolltop - 600;
	else if (curtop > scrolltop + getDocumentProperty('clientHeight')) curtop = getDocumentProperty('clientHeight');
	var diff = scrolltop + 50 - curtop;
	if (diff > 60) diff = 60;
	if (diff < -60) diff = -60;
	var newtop = curtop + Math.round(diff / 3);
	if (newtop < skytop)
	{
		newtop = skytop;
		diff = 0;
	}
	sky.style.top = newtop + 'px';
	if (diff) skymove = setTimeout('slidesky()', 30);
	else skymove = null;
}

function qs_init()
{
	quicksearch = document.getElementById('quicksearch');
	if (quicksearch)
	{
		quicksearch.left = getOffsetLeft(quicksearch);
		quicksearch.top = getOffsetTop(quicksearch);
		qshide = is.ie;
	}
}

var adsense_target = null;
function google_ad_request_done(google_ads)
{
	var el = adsense_target && document.getElementById('as_'+adsense_target), l;

	if (!el) return false;

	if ((l = google_ads.length) == 0)
	{
		el.style.display = 'none';
		return false;
	}

	var s = [], i = 0, google_ad;
	var feedbackurl = 'http://services.google.com/feedback/abg?url='+encodeURIComponent(adsense_page_url)+'&hl=nl&client='+google_ad_client;

	if (!window.defaultStatus) window.defaultStatus = '';

	while ((google_ad = google_ads[i++]))
	{
		feedbackurl += '&adU='+google_ad.visible_url+'&adT='+encodeURIComponent(google_ad.line1).replace(/%20/g, '+');

		if (is.ie)
		{
			google_ad.line1 = IE_EuroFix(google_ad.line1);
			google_ad.line2 = IE_EuroFix(google_ad.line2);
			google_ad.line3 = IE_EuroFix(google_ad.line3);
		}

		s.push('<div class="ga n' + l + '">'
			+ '<a href="' + google_ad.url + '" onmouseover="window.status=\'ga naar ' + google_ad.visible_url + '\';return true" onmouseout="window.status=window.defaultStatus;return true"'+(external?' target="_blank"':'')+'>'
			+ '<span class="firstline">' + google_ad.line1 + '</span>'
			+ '<span class="nextlines">' + google_ad.line2 + '</span>'
			+ (google_ad.line3 ? ' <span class="nextlines">' + google_ad.line3 + '</span>' : '')
			+ '<span class="link">' + google_ad.visible_url + '</span>'
			+ '</a></div>');
	}

	s.push('<div class="left"><a href="'+feedbackurl+'&done=1"'+(external?' target="_blank"':'')+'>Ads door Google</a></div>'
		+ '<div class="right"><a href="https://adwords.google.com/select/OnsiteSignupLandingPage?client='+google_ad_client+'&referringUrl='+encodeURIComponent(adsense_page_url)+'&hl=nl&gl=NL"'+(external?' target="_blank"':'')+'>Adverteer hier</a></div>'
		+ '<div class="clear"><hr></div>');

	el.innerHTML = s.join('');

	return true;
}

function IE_EuroFix(text)
{
	for (var i = 0, replaced = ''; i < text.length; i++)
	{
		switch (text.charCodeAt(i))
		{
			case 128:
				replaced += '&euro;';
				break;
			case 381:
				replaced += '&acute;';
				break;
			default:
				replaced += text.charAt(i);
		}
	}

	return replaced;
}

if (window.bc) window.onload = function()
{
	var foo = new Image();
	foo.src = board_template_url + 'html/bc.php?check=' + (Math.floor(Math.random() * 100000000) * 11 + (banner && banner.childNodes.length > 1 ? 5 : 0));
}

//-- Menu
var nav_current = [], nav_hide_delay = [];

function init_menu()
{
	var li = first_child(document.getElementById('sitenav'));
	while (li)
	{
		li.menuid = 'mainmenu';
		li.onmouseover = siteNavHover;
		li.onmouseout = siteNavHideCurrentSetDelay;
		li.submenu = init_submenu(li, 'mainmenu');

		li = node_after(li);
	}
}

function unload_menu()
{
	var li = first_child(document.getElementById('sitenav'));
	while (li)
	{
		li.submenu = null;
		li = node_after(li);
	}
}
window.onunload = unload_menu;

function init_submenu(menuitem, menuid)
{
	var submenu = first_child(menuitem);
	while (submenu)
	{
		if (submenu.tagName.toLowerCase() == 'div')
		{
			submenu.menuid = menuid;
			submenu.onmouseover = siteNavHideClearDelay;
			submenu.onmouseout = siteNavHideCurrentDelay;
			if (menueffect != 'nopacity')
			{
				setOpacity(submenu, 0.95);
			}
	
			return submenu;
		}
	
		submenu = node_after(submenu);
	}

	return null;
}

function siteNavHover()
{
	if (this.menuid)
	{
		var submenu = this.submenu;
		var menuid = this.menuid;

		siteNavHideCurrent(menuid, submenu);

		if (submenu)
		{
			hide_banner(submenu);
			nav_current[menuid] = submenu;
			submenu.style.visibility = 'visible';
		}
	}
}

function siteNavHideCurrent(menuid, submenu)
{
	siteNavHideClearDelay(0, menuid);

	if (nav_current[menuid] && nav_current[menuid] != submenu)
	{
		nav_current[menuid].style.visibility = 'hidden';
		nav_current[menuid] = null;
		show_banner();
	}
}

function siteNavHideCurrentFade(menuid)
{
	if (nav_current[menuid])
	{
		var opacity = nav_current[menuid].opacity - 0.05;
		if (opacity <= 0)
		{
			siteNavHideCurrent(menuid);
		}
		else
		{
			setOpacity(nav_current[menuid], opacity);
			nav_hide_delay[menuid] = setTimeout('siteNavHideCurrentFade(\''+menuid+'\')', 50);
		}
	}
}

function siteNavHideCurrentDelay()
{
	if (this.submenu)
	{
		siteNavHideCurrentSetDelay(0, this.menuid);
		return true;
	}

	return false;
}

function siteNavHideCurrentSetDelay(e, menuid)
{
	if (!menuid && this) menuid = this.menuid;

	if (menuid)
	{
		if (menueffect == 'fade' && !is.opera && !(is.ie && is.ieversion < 5.5))
		{
			nav_hide_delay[menuid] = setTimeout('siteNavHideCurrentFade(\''+menuid+'\')', 500);
		}
		else
		{
			nav_hide_delay[menuid] = setTimeout('siteNavHideCurrent(\''+menuid+'\')', 500);
		}
	}
}

function siteNavHideClearDelay(e, menuid)
{
	if (!menuid && this) menuid = this.menuid;

	if (menuid && nav_hide_delay[menuid])
	{
		clearTimeout(nav_hide_delay[menuid]);
		nav_hide_delay[menuid] = null;
		if (menueffect == 'fade' && nav_current[menuid])
		{
			setOpacity(nav_current[menuid], 0.95);
		}
	}
}

function setOpacity(el, opacity)
{
	if (el && (!el.opacity || el.opacity != opacity))
	{
		el.opacity = opacity;
		if (el.filters)
		{
			if (el.filters.alpha)
			{
				el.filters.alpha.opacity = opacity * 100;
			}
			else
			{
				el.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
			}
		}
		else
		{
			el.style.opacity = opacity;
		}
	}
}

//-- Inklap functies
function toggle_categorydisplay(img)
{
	var row = img.parentNode, display, selects, i;

	if (img.src == fclosed.src)
	{
		img.src =  fopen.src;
		display = '';
		delete klipklapcookie[img.id];
	}
	else if (img.src == fopen.src)
	{
		img.src = fclosed.src;
		display = 'none';
		klipklapcookie[img.id] = 1;
	}

	while (row)
	{
		if (row.tagName.toLowerCase() == 'tr')
		{
			row.className = display ? '' : 'hide';

			while ((row = node_after(row)))
			{
				row.style.display = display;
				if (is.ie)
				{
					selects = row.getElementsByTagName('select'), i = selects.length;
					while (i--)
						selects[i].style.display = display;
				}
			}

			writeCookies();
			break;
		}

		row = row.parentNode;
	}
}

function readCookies()
{
	var cookiecontent = GetCookie('klipklapcookie');
	if (cookiecontent)
	{
		var temp = cookiecontent.split(','), i = temp.length;
		while (i--)
			klipklapcookie[temp[i]] = 1;

		i = categories.length;
		while (i--)
			if (klipklapcookie[categories[i]])
				toggle(categories[i]);
	}

	skipcookie = false;
}

function writeCookies()
{
	if (!skipcookie)
	{
		var temp = [];
		for (var category in klipklapcookie)
			if (klipklapcookie.hasOwnProperty(category))
				temp.push(category);
	
		SetCookie('klipklapcookie', temp.join(','));
	}
}

function toggle(name)
{
	var el = document.getElementById(name);
	if (el && typeof el.onclick == 'function') el.onclick();
}

function toggle_userdata(img, msgid)
{
	if (img.src == fclosed.src)
		img.src =  fopen.src;
	else if (img.src == fopen.src)
		img.src = fclosed.src;
	else if (img.src == ftsclosed.src)
		img.src = ftsopen.src;
	else if (img.src == ftsopen.src)
		img.src = ftsclosed.src;

	var el = document.getElementById('extra_'+msgid), admin_display;
	if (el.style.display == 'block')
	{
		el.style.display = 'none';
		admin_display = '';
	}
	else
	{
		el.style.display = 'block';
		admin_display = 'visible';
	}

	// admin
	el = document.getElementById('admin_'+msgid);
	if (el) el.className = admin_display;
}

function toggle_admin(img, hideall)
{
	var display;

	if (img.src == aclosed.src)
	{
		img.src =  aopen.src;
		display = '';
		delete klipklapcookie[img.id];
	}
	else if (img.src == aopen.src)
	{
		img.src = aclosed.src;
		display = 'none';
		klipklapcookie[img.id] = 1;
	}

	var fe = node_after(img.parentNode);
	do
	{
		if (hideall || fe.tagName.toLowerCase() == 'dl' || fe.tagName.toLowerCase() == 'fieldset' || fe.tagName.toLowerCase() == 'table' || fe.tagName.toLowerCase() == 'ol')
			fe.style.display = display;
	}
	while ((fe = node_after(fe)));

	writeCookies();
}

var updatetracker = null, slider_delay = null;
function init_tracker(sessiontime, prefs_linktolastpage)
{
	updatetracker = document.getElementById('updatetracker');

	if (updatetracker)
	{
		if (GetCookie('tracker') == '1')
		{
			updatetracker.className = 'open';
			slide_tracker(500);
			skytop = getOffsetTop(updatetracker) + updatetracker.clientHeight + 30;
		}
		else if (is.ie)
		{
			// IE needs this
			setTimeout(function(){updatetracker.style.clip = 'rect(0px,'+ updatetracker.offsetWidth + 'px,1200px,' + (updatetracker.offsetWidth - 16) + 'px)';}, 10);
		}

		// mark new links if sessiontime cookie is set
		var tracker = document.getElementById('headeractivetopics');
		if (tracker)
		{
			if (sessiontime == 0) sessiontime = GetCookie('SessionTime');
			if (sessiontime != null && sessiontime > 0)
				mark_links(node_after(tracker), sessiontime);
			if (prefs_linktolastpage)
				linktolastpage(node_after(tracker));
		}

		// mark new links if Tnet cookie is set
		tracker = document.getElementById('headerheadlines');
		if (tracker)
		{
			var tc = GetCookie('tc');
			if (tc !== null)
			{
				var tcontent = tc.split(',');
				sessiontime = tcontent.length == 2 ? parseInt(tcontent[0], 10) : 0;
				mark_links(node_after(tracker), sessiontime);
			}
		}

		updatetracker.style.visibility = 'visible';
	}
}

function mark_links(tracker, sessiontime)
{
	var el = tracker.getElementsByTagName('a'), i = 0, a, attr, match;
	var re = /(^|\s)time:(\d{10})(\s|$)/;
	while ((a = el[i++]))
	{
		attr = a.getAttribute('rel');
		if (attr)
		{
			match = re.exec(attr);

			if (match && parseInt(match[2], 10) > sessiontime)
			{
				addClass(a.parentNode, 'newlink');
			}
		}
	}
}

function linktolastpage(tracker)
{
	var el = tracker.getElementsByTagName('a'), i = 0, a;
	if (is.ie)
	{
		var text = '';
		while ((a = el[i++]))
		{
			text = a.firstChild.nodeValue;
			a.firstChild.nodeValue = 'IE sucks';
			a.href += '/last';
			a.firstChild.nodeValue = text;
		}
	}
	else
	{
		while ((a = el[i++]))
			a.href += '/last';
	}
}

function toggle_tracker()
{
	if (slider_delay) clearTimeout(slider_delay);
	slider_delay = null;
	if (updatetracker.className == 'closed')
	{
		updatetracker.className = 'open';
		skytop = getOffsetTop(updatetracker) + updatetracker.clientHeight + 30;
		if (sky) sky.style.top = skytop + 'px';
		slide_tracker((animate?12:300));
		SetCookie('tracker', '1');
	}
	else
	{
		updatetracker.className = 'closed';
		slide_tracker((animate?-12:-300));
		SetCookie('tracker', '0');
	}
}

function slide_tracker(s)
{
	var l = updatetracker.offsetLeft + s, w = updatetracker.parentNode.offsetWidth, t = updatetracker.offsetWidth - 16, next = true;
	if (l >= w)
	{
		l = --w;
		quicksearch.className = 'trackersupport';
		next = false;
	}
	else if (l < w - t)
	{
		l = w - t;
		quicksearch.className = '';
		skytop = 120;
		movesky();
		next = false;
	}
	updatetracker.style.left = l + 'px';
	updatetracker.style.clip = 'rect(0px,'+ (t + 16) + 'px,1200px,' + (w - l) + 'px)';
	if (next) slider_delay = setTimeout('slide_tracker('+s+')',20);
	else slider_delay = null;
}

//-- Generic Cookie functies
function GetCookie(sName)
{
	var aCookie = document.cookie.split('; '), i = aCookie.length, aCrumb;
	while (i--)
	{
 		aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0])
			return aCrumb[1] != undefined ? unescape(aCrumb[1]) : null;
	}

	return null;
}

function SetCookie(sName, sValue)
{
	document.cookie = sName + '=' + escape(sValue) + '; expires=Fri, 31 Dec 2099 23:59:59 GMT; path=/; domain=.' + document.domain;
}

//-- Message box editing functions
var target = null;
function initMessageBox()
{
	if (!target) target = document.getElementById('messageBox');
	if (target)
	{
		target.focus();
		if (target.createTextRange)
		{
			target.onkeyup = storeCursor;
			target.onclick = storeCursor;
			target.onselect = storeCursor;
			target.onselect();
		}

		if (!is.mac && target.tagName.toLowerCase() == 'textarea')
		{
			if (target.createTextRange)
				target.onkeydown = shortkey;
			else
				target.onkeypress = shortkey;
		}
	}
}

function storeCursor()
{
	this.cursorPos = document.selection.createRange().duplicate();
}

function det_replace(type, text)
{
	var val = '';
	switch (type)
	{
		case 'plain':
			break;
		case 'AND':
			if (text != '')	text = text.replace(/(\w+)\s+/g, '$1 AND ');
			else text = ' AND ';
			break;
		case 'OR':
			if (text != '')	text = text.replace(/(\w+)\s+/g, '$1 OR ');
			else text = ' OR ';
			break;
		case 'brackets':
			if (text != '')	text = '('+text+')';
			else text = '()';
			break;
		case 'title':
			if (text != '')	text = 'title:('+text+')';
			else text = 'title:';
			break;
		case 'start':
			if (text != '')	text = 'start:('+text+')';
			else text = 'start:';
			break;
		case 'bold':
			text = '[b]'+text+'[/b]';
			break;
		case 'italic':
			text = '[i]'+text+'[/i]';
			break;
		case 'underline':
			text = '[u]'+text+'[/u]';
			break;
		case 'strike':
			text = '[s]'+text+'[/s]';
			break;
		case 'sub':
			text = '[sub]'+text+'[/sub]';
			break;
		case 'sup':
			text = '[sup]'+text+'[/sup]';
			break;
		case 'small':
			text = '[small]'+text+'[/small]';
			break;
		case 'left':
			text = '[left]'+text+'[/left]';
			break;
		case 'center':
			text = '[center]'+text+'[/center]';
			break;
		case 'right':
			text = '[right]'+text+'[/right]';
			break;
		case 'listbullet':
			text = '[list]\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'))+'\r\n[/list]';
			break;
		case 'listnum':
			text = '[list=1]\r\n[*]'+(text.split(/\r?\n/).join('\r\n[*]'))+'\r\n[/list]';
			break;
		case 'bgcolor':
			val = prompt('Voer een hexadecimale kleurcode in:','#');
			if (val !== null) text = '[bgcolor='+val+']'+text+'[/bgcolor]';
			break;
		case 'color':
			val = prompt('Voer een hexadecimale kleurcode in:','#');
			if (val !== null) text = '[color='+val+']'+text+'[/color]';
			break;
		case 'url':
			if (/^(http:\/\/|www\.)/i.test(text))
			{
				val = prompt('Voer omschrijving in:', text);
				if (val !== null && val != '') text = '[url='+text+']'+val+'[/url]';
			}
			else
			{
				val = prompt('Voer de URL in:','http:\/\/');
				if (val !== null && val != 'http:\/\/')
				{
					if (text == '') text = '[url]'+val+'[/url]';
					else text = '[url='+val+']'+text+'[/url]';
				}
			}
			break;
		case 'img':
			if (text == '')
			{
				val = prompt('Voer de URL in:','http:\/\/');
				if (val !== null && val != 'http:\/\/') text = '[img]'+val+'[/img]';
			}
			else
			{
				text = '[img]'+text+'[/img]';
			}
			break;
		case 'table':
			text = '[table border=1 width=350 cellpadding=2 bordercolor=#000000]\r\n[tr]\r\n[td]'+(text.split(/\r?\n/).join('[/td]\r\n[/tr]\r\n[tr]\r\n[td]'))+'[/td]\r\n[/tr]\r\n[/table]';
			break;
		case 'hr':
			text += '[hr]';
			break;
		case 'quote':
			text += '[/quote]\r\n[quote]';
			break;
	}

	return text;
}

function putStr(text)
{
	putExt('plain', text);
}

function putExt(type, text)
{
	if (target)
	{
		if (target.cursorPos)
		{
			var cursorPos = target.cursorPos;
			if (type != 'plain') text = cursorPos.text;
			cursorPos.text = det_replace(type, text);
		}
		else if (target.selectionStart != undefined)
		{
			// remember scrollposition
			var scrollTop = target.scrollTop;

			var sStart = target.selectionStart;
			var sEnd = target.selectionEnd;
			if (type != 'plain') text = target.value.substring(sStart, sEnd);
			text = det_replace(type, text);
			target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd);
			var nStart = sStart == sEnd ? sStart + text.length : sStart;
			var nEnd = sStart + text.length;
			target.setSelectionRange(nStart, nEnd);

			// reset scrollposition
			target.scrollTop = scrollTop;
		}
		else
		{
			if (type != 'plain') text = '';
			target.value += det_replace(type, text);
		}

		target.focus();
		if (target.cursorPos) target.onselect();
	}
}

function shortkey(e)
{
	if (!e) e = event;

	var key = 0;
	if (e.keyCode) key = e.keyCode;
	else if (e.which) key = e.which - 32;

	if (e.ctrlKey && !e.shiftKey)
	{
		switch (key)
		{
			case 66:
				putExt('bold');
				return cancelEvent(e);
			case 73:
				putExt('italic');
				return cancelEvent(e);
			case 83:
				putExt('strike');
				return cancelEvent(e);
			case 85:
				putExt('underline');
				return cancelEvent(e);
		}
	}

	return true;
}

function increaseTextarea(img)
{
	if (!target) target = document.getElementById('messageBox');
	if (target)
	{
		if (target.style.height)
		{
			target.style.height = '';
			img.src = maximize.src;
			img.title = 'Vergroot tekstveld';
		}
		else
		{
			target.style.height = 2 * target.offsetHeight + 'px';
			img.src = minimize.src;
			img.title = 'Verklein tekstveld';
		}
	}
}

if (is.ie) document.onkeydown = function()
{
	var key = event.keyCode;
	var a = String.fromCharCode(key).toLowerCase();
	if (event.altKey && key > 64 && key < 91 && acckeys[a])
	{
		window.location.href = /^http:\/\//.test(acckeys[a]) ? acckeys[a] : board_script_url + acckeys[a];
		event.keyCode = 90; // use a valid keycode that is not in IE's context menu
		event.returnValue = 0;
		event.cancelBubble = true;
		return false;
	}

	return true;
}

function cancelEvent(e)
{
	if (e.preventDefault)
	{
		e.preventDefault();
	}
	else if (e.cancelBubble != undefined)
	{
		if (e.keyCode) e.keyCode = 0;
		e.returnValue = 0;
		e.cancelBubble = true;
	}

	return false;
}

function winopen(url, winname, width, height, extra)
{
	if (!extra) extra = ''; else extra = ',' + extra;
	var popup = window.open(url,winname,'toolbar=no,location=no,menubar=no,width='+width+',height='+height+',resizable=yes,status=no'+extra);
	try { popup.focus(); } catch(e) {}
}

function winopen2(url, winname)
{
	alert('hi');

	var width = screen.availWidth;
	var height = screen.availHeight;
	winopen(url, winname, width, height, '')
}

function mark_topicstarter(user_id)
{
	var i = messageids.length, img;
	while (i--)
	{
		if (messageids[i][1] == user_id)
		{
			img = document.getElementById('ts_'+messageids[i][0]);
			if (img.src == fclosed.src) img.src = ftsclosed.src;
			else img.src = ftsnone.src;
			img.title = 'Topicstarter';

			img = document.getElementById('oi_'+messageids[i][0]);
			if (img.src == online.src) img.src = online_ts.src;
			else img.src = offline_ts.src;
			img.width = '14';
			img.title = 'Topicstarter ' + img.title;
		}
	}
}

function user_images(warning)
{
	if (warning) showwarning = true;
	var im = getElementsByClassName('rml', 'img'), i = im.length;
	while (i--)
	{
		if (im[i].naturalWidth || im[i].complete)
			scaleImage(0,im[i]);
		else if (typeof im[i].onreadystatechange != 'undefined')
			im[i].onreadystatechange = scaleImage;
		else
			im[i].onload = scaleImage;
		im[i].onerror = scaleImage;
		im[i].onabort = scaleImage;
	}

	if (is.ie && window.attachEvent) window.attachEvent('onload', user_images_ie); 

}

function user_images_ie()
{
	var im = document.images, i = im.length;
	while (i--)
	{
		if (hasClass(im[i], 'rml'))
			scaleImage(0,im[i]);
	}
}

var showwarning = false;
function scaleImage(e,img)
{
	if (!img) img = this;
	var imgwidth = 0, imgheight = 0, el;

	if (img.width || img.complete)
	{
		if (img.naturalWidth)
		{
			imgwidth = img.naturalWidth;
			imgheight = img.naturalHeight;
		}
		else if (img.complete)
		{
			var dum = new Image(); dum.src = img.src;
			imgwidth = dum.width;
			imgheight = dum.height;
		}
		if (imgwidth && img.onreadystatechange) img.onreadystatechange = null;

		var contentDiv = img.parentNode;
		//while (!hasClass(contentDiv, 'content') && contentDiv.className != 'message-quote-div') contentDiv = contentDiv.parentNode;

		//var maxWidth = contentDiv.offsetWidth - (hasClass(contentDiv, 'content') ? 10 : 4);
		maxWidth = 800;
		if (imgwidth > maxWidth)
		{
			maxWidth -= 2;
			if (img.parentNode.tagName.toLowerCase() != 'a')
			{
				if (!img.naturalWidth) img.naturalWidth = imgwidth;
				if (!img.naturalHeight) img.naturalHeight = imgheight;
				img.className += ' resized hand';
				img.onclick = openImage;
				el = img;
			}
			else
			{
				img.className += ' resized2';
				el = img.parentNode;
			}

			// create a nice warning when image is in normal post
			if (showwarning && imgwidth > 800 && contentDiv.className != 'message-quote-div')
			{
				var warning = document.createElement('div');
				warning.className = 'resizewarning';
				warning.style.width = ((img.width < maxWidth ? img.width : maxWidth) + 2) + 'px';
				warning.innerHTML = '<div>Deze afbeelding is verkleind [Origineel: ' + imgwidth + ' * ' + imgheight + ' pixels' + (img.fileSize && img.fileSize > 0 ? ' en ' + Math.floor(img.fileSize/1024) + 'KB' : '') + ']</div>';
				if (node_after(el))
				{
					el.parentNode.insertBefore(warning, node_after(el));
				}
				else
				{
					el.parentNode.appendChild(warning);
				}
			}
		}

		if (img.width > maxWidth)
		{
			if (img.height) img.height = Math.round(maxWidth / img.width * img.height);
			img.width = maxWidth;
		}
	}
}

function user_images_2(warning)
{
	if (warning) showwarning = true;
	var im = getElementsByClassName('rml_2', 'img'), i = im.length;
	while (i--)
	{
		if (im[i].naturalWidth || im[i].complete)
			scaleImage_2(0,im[i]);
		else if (typeof im[i].onreadystatechange != 'undefined')
			im[i].onreadystatechange = scaleImage_2;
		else
			im[i].onload = scaleImage_2;
		im[i].onerror = scaleImage_2;
		im[i].onabort = scaleImage_2;
	}

	if (is.ie && window.attachEvent) window.attachEvent('onload', user_images_2_ie); 

}

function user_images_2_ie()
{
	var im = document.images, i = im.length;
	while (i--)
	{
		if (hasClass(im[i], 'rml_2'))
			scaleImage_2(0,im[i]);
	}
}

var showwarning = false;
function scaleImage_2(e,img)
{
	if (!img) img = this;
	var imgwidth = 0, imgheight = 0, el;

	if (img.width || img.complete)
	{
		if (img.naturalWidth)
		{
			imgwidth = img.naturalWidth;
			imgheight = img.naturalHeight;
		}
		else if (img.complete)
		{
			var dum = new Image(); dum.src = img.src;
			imgwidth = dum.width;
			imgheight = dum.height;
		}
		if (imgwidth && img.onreadystatechange) img.onreadystatechange = null;

		var contentDiv = img.parentNode;
		//while (!hasClass(contentDiv, 'content') && contentDiv.className != 'message-quote-div') contentDiv = contentDiv.parentNode;

		//var maxWidth = contentDiv.offsetWidth - (hasClass(contentDiv, 'content') ? 10 : 4);
		maxWidth = 160;
		if (imgwidth > maxWidth)
		{
			//maxWidth -= 2;
			if (img.parentNode.tagName.toLowerCase() != 'a')
			{
				if (!img.naturalWidth) img.naturalWidth = imgwidth;
				if (!img.naturalHeight) img.naturalHeight = imgheight;
				//img.className += ' resized hand';
				//img.onclick = openImage;
				//el = img;
			}
			else
			{
				//img.className += ' resized2';
				//el = img.parentNode;
			}
/*
			// create a nice warning when image is in normal post
			if (showwarning && imgwidth > 800 && contentDiv.className != 'message-quote-div')
			{
				var warning = document.createElement('div');
				warning.className = 'resizewarning';
				warning.style.width = ((img.width < maxWidth ? img.width : maxWidth) + 2) + 'px';
				warning.innerHTML = '<div>Deze afbeelding is verkleind [Origineel: ' + imgwidth + ' * ' + imgheight + ' pixels' + (img.fileSize && img.fileSize > 0 ? ' en ' + Math.floor(img.fileSize/1024) + 'KB' : '') + ']</div>';
				if (node_after(el))
				{
					el.parentNode.insertBefore(warning, node_after(el));
				}
				else
				{
					el.parentNode.appendChild(warning);
				}
			}
*/
		}

		if (img.width > maxWidth)
		{
			if (img.height) img.height = Math.round(maxWidth / img.width * img.height);
			img.width = maxWidth;
		}
	}
}



function openImage()
{
	var winwidth = (this.naturalWidth < screen.availWidth ? this.naturalWidth : screen.availWidth);
	var winheight = (this.naturalHeight < screen.availHeight ? this.naturalHeight : screen.availHeight);
	winopen(board_template_url+'includes/showimage.html?'+escape(this.src),'',winwidth,winheight,'scrollbars=no,left=0,top=0');
}

function showCar(id)
{
	var winwidth = (this.naturalWidth < screen.availWidth ? this.naturalWidth : screen.availWidth);
	var winheight = (this.naturalHeight < screen.availHeight ? this.naturalHeight : screen.availHeight);
	winopen(board_template_url+'includes/showcar.php?id=' + id,'',winwidth,winheight,'scrollbars=no,left=0,top=0');
}

function code_tags()
{
	var el = getElementsByClassName('phphighlight', 'table'), i = el.length, row, div, pre, img;

	while (i--)
	{
		row = first_child(el[i]);
		if (row.tagName.toLowerCase() != 'tr') row = first_child(row);
		div = first_child(row.childNodes[row.childNodes.length-1]);
		if (!div || div.tagName.toLowerCase() != 'div') continue;
		div.style.paddingBottom = '0px';
		pre = first_child(div);
		if (!pre || (pre.tagName.toLowerCase() != 'pre' && pre.tagName.toLowerCase() != 'code')) continue;

		if (div.scrollWidth > div.clientWidth)
		{
			if (is.ie)
			{
				div.orgPadding = (div.scrollHeight - div.clientHeight) + 'px';
				div.style.paddingBottom = div.orgPadding;
			}
			pre.style.width = div.scrollWidth + 'px';
			div.orgWidth = div.clientWidth;
			img = document.createElement('img');
			img.src = aopen.src;
			img.className = 'klipklap hand';
			img.onclick = klipklap_code;
			el[i].parentNode.insertBefore(img, node_before(node_before(el[i])));
		}
	}

	// pre tags as well
	el = getElementsByClassName('(pre|cmd)', 'div'), i = el.length;

	while (i--)
	{
		div = el[i];
		div.style.paddingBottom = '0px';
		pre = first_child(div);
		if (!pre || pre.tagName.toLowerCase() != 'pre') continue;

		if (div.scrollWidth > div.clientWidth)
		{
			if (is.ie)
			{
				div.orgPadding = (div.scrollHeight - div.clientHeight) + 'px';
				div.style.paddingBottom = div.orgPadding;
			}
			pre.style.width = div.scrollWidth + 'px';
			div.orgWidth = div.clientWidth;
			img = document.createElement('img');
			img.src = aopen.src;
			img.className = 'klipklap hand';
			img.onclick = klipklap_pre;
			div.parentNode.insertBefore(img, div);
		}
	}
}

function klipklap_code()
{
	var table = node_after(node_after(node_after(this)));
	if (!table || table.tagName.toLowerCase() != 'table') return;
	var row = first_child(table);
	if (row.tagName.toLowerCase() != 'tr') row = first_child(row);
	var div = first_child(row.childNodes[row.childNodes.length-1]);
	if (!div || div.tagName.toLowerCase() != 'div') return;
	var pre = first_child(div);
	if (!pre || (pre.tagName.toLowerCase() != 'pre' && pre.tagName.toLowerCase() != 'code')) return;

	if (this.src == aopen.src)
	{
		this.src = aclosed.src;
		table.style.width = 'auto';
		div.style.overflow = 'visible';
		if (is.ie) div.style.paddingBottom = '0px';
		pre.style.borderRight = '1px solid black';
		div.style.width = pre.scrollWidth + 'px';
		hide_sky(pre);
	}
	else
	{
		this.src = aopen.src;
		table.style.width = '100%';
		div.style.overflow = '';
		if (is.ie) div.style.paddingBottom = div.orgPadding;
		pre.style.borderRight = 'none';
		div.style.width = div.orgWidth + 'px';
		show_sky();
	}
}

function klipklap_pre()
{
	var div = node_after(this);
	if (!div || div.tagName.toLowerCase() != 'div') return;
	var pre = first_child(div);
	if (!pre || pre.tagName.toLowerCase() != 'pre') return;

	if (this.src == aopen.src)
	{
		this.src = aclosed.src;
		div.style.overflow = 'visible';
		if (is.ie) div.style.paddingBottom = '0px';
		div.style.width = pre.scrollWidth + 'px';
		hide_sky(pre);
	}
	else
	{
		this.src = aopen.src;
		div.style.overflow = '';
		if (is.ie) div.style.paddingBottom = div.orgPadding;
		div.style.width = div.orgWidth + 'px';
		show_sky();
	}
}

function more_smilies(a)
{
	var m = document.getElementById('moresmilies');
	if (m)
	{
		if (m.style.display == 'none')
		{
			m.style.display = 'block';
			a.style.display = 'none';
		}
	}
}

/* DOM functions */

function is_ignorable( nod )
{
	return (nod.nodeType == 8 || (nod.nodeType == 3 && !/[^\t\n\r ]/.test(nod.data)));
}

function node_before( sib )
{
	if (sib)
	{
		while ((sib = sib.previousSibling))
		{
			if (!is_ignorable(sib)) return sib;
		}
	}

	return null;
}

function node_after( sib )
{
	if (sib)
	{
		while ((sib = sib.nextSibling))
		{
			if (!is_ignorable(sib)) return sib;
		}
	}

	return null;
}

function last_child( par )
{
	if (par && par.nodeType == 1)
	{
		var res=par.lastChild;
		do
		{
			if (!is_ignorable(res)) return res;
		}
		while ((res = res.previousSibling));
	}

	return null;
}

function first_child( par )
{
	if (par && par.nodeType == 1)
	{
		var res=par.firstChild;
		do
		{
			if (!is_ignorable(res)) return res;
		}
		while ((res = res.nextSibling));
	}

	return null;
}

function getElementsByClassName(needle, tagname)
{
	if (!tagname) tagname = '*';
	var s = document.getElementsByTagName(tagname), i = s.length, e, r = [];
	var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');

	while (i--)
	{
		e = s[i];
		if (e.className && re.test(e.className)) r.push(e);
	}

	return r;
}

function getDocumentProperty(prop)
{
	return document.documentElement && document.compatMode != 'BackCompat' ? document.documentElement[prop] : document.body[prop];
}

//-- classdealer functions
function addClass(element, classname)
{
	var classes = getClassList(element);
	if (classes.indexOf(classname) == -1)
	{
		classes[classes.length] = classname;
	}

	setClassList(element, classes);
}

function removeClass(element, classname)
{
	var classes = getClassList(element), index;
	if ((index = classes.indexOf(classname)) > -1)
	{
		delete classes[index];
	}

	setClassList(element, classes);
}

function replaceClass(element, oldclass, newclass)
{
	var classes = getClassList(element), index;
	if ((index = classes.indexOf(oldclass)) > -1 && classes.indexOf(newclass) == -1)
	{
		classes[index] = newclass;
	}

	setClassList(element, classes);
}

function getClassList(element)
{
	if (element.className) return element.className.split(/\s+/);
	return [];
}

function setClassList(element, classes)
{
	element.className = classes.join(' ');
}

function hasClass(element, classname)
{
	var classes = getClassList(element);
	return classes.indexOf(classname) > -1;
}

if (!Array.prototype.indexOf)
{
	Array.prototype.indexOf = function(searchElement, fromIndex)
	{
		var l = this.length, i = 0;
		if (fromIndex)
		{
			i = fromIndex;
			if (i < 0)
			{
				i += l;
				if (i < 0) i = 0;
			}
		}

		while (i < l)
		{
			if (this[i] === searchElement) return i;
			i++;
		}

		return -1;
	}
}

//-- Positie van element verkrijgen
function getOffsetTop(el)
{
	var offsetTop = 0;
	do
	{
		offsetTop += el.offsetTop
	}
	while ((el = el.offsetParent));

	return offsetTop;
}

function getOffsetLeft(el)
{
	var offsetLeft = 0;
	do
	{
		offsetLeft += el.offsetLeft
	}
	while ((el = el.offsetParent));

	return offsetLeft;
}

//-- IE 5.0 specific
if (!Array.push)
{
	Array.prototype.push = function()
	{
		for (var i = 0; i < arguments.length; ++i)
		{
			this[this.length] = arguments[i];
		}

		return this.length;
	}
}

if (!window.encodeURIComponent)
{
	window.encodeURIComponent = function(string) { return escape(string); }
}

if (!Object.prototype.hasOwnProperty)
{
	Object.prototype.hasOwnProperty = function(p)
	{
		return this.constructor.prototype[p] === undefined;
	}
}

//-- Initialisation
var categories = [];
var messageids = [];
var klipklapcookie = {}, skipcookie = true;
