//Determine user resolution and set in cookie:
// for NN4/IE4
if (self.screen) {     
 	var g_resWidth = screen.width
    var g_resHeight = screen.height
	
}
// for NN3 w/Java
else if (self.java) {   
       var javakit = java.awt.Toolkit.getDefaultToolkit();
       var scrsize = javakit.getScreenSize();       
       var g_resWidth = scrsize.width; 
       var g_resHeight = scrsize.height; 
}
else {
// N2, E3, N3 w/o Java (Opera and WebTV)
}

setCookie('resWidth', g_resWidth, false, '/', '.' + g_hostName);
setCookie('resHeight', g_resHeight, false, '/', '.' + g_hostName);

function nav_main_click(id) {
	setCookie('cur_active_tab', id, false, '/', '.' + g_hostName);
	setCookie('cur_active_sub', -1, false, '/', '.' + g_hostName);
}

function clear_main_nav_cookie() {
	delCookie('cur_active_tab');
}

function nav_sub_click(id) {
	setCookie('cur_active_sub', id, false, '/', '.' + g_hostName);
}

function clear_sub_nav_cookie() {
	delCookie('cur_active_sub');
}

function toggle_display(id) {

	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = '';
		if (document.forms['frm_'+id]) document.forms['frm_'+id].l_username.focus();
	} else {
		document.getElementById(id).style.display = 'none';
	}

}

// The specification for cookies says that browsers need support no more than 300 different cookies.
// Of those, no more than 20 should be associated with any particular server. 
// For each cookie, the data stored is not expected to exceed 4 kilobytes.
function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
		+ (path ? '; PATH=' + path : '')
		+ (domain ? '; DOMAIN=' + domain : '')
		+ (secure ? '; SECURE' : '');
}

// A complementary function to unwrap a cookie.
function getCookie(cookieName) {
	
	var cookieValue = null;
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	
	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1) {
			cookieValue = unescape(document.cookie.substring(posValue, endPos));
		} else {
			cookieValue = unescape(document.cookie.substring(posValue));
		}
	}
	return cookieValue;
}

function delCookie(cookieName,path, domain) {
	d = new Date();
	document.cookie = escape(cookieName) 
	+ '=; expires=' + getexpirydate(-1)
	+ (path ? '; PATH=' + path : '')
	+ (domain ? '; DOMAIN=' + domain : '');
} 

function cleanNavigation() {
	delCookie('cur_active_tab', '/', '.' + g_hostName);
	delCookie('cur_active_sub', '/', '.' + g_hostName);
}


// Returns a date in UTC format which can be used to set an expiration date for a cookie
function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime (nomilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function show_login() {
	/* hacked zodat altijd alleen in top nav geopend wordt vanwege positionering */
	showLayer('login_box', document.getElementById('login_nav'), 0, 0, 0, 0, -175, 5);
	document.frm_top_login.l_username.focus();
}

function show_info(parent,child) {
	if (document.getElementById(child).style.display=='none') {
		showLayer(child, document.getElementById(parent), 0, 0, 0, 0, 0, 0);
	} else {
		document.getElementById(child).style.display = 'none';		
	}
}


function totalElementOffset(obj) {

	var yOffset = (obj.offsetTop ? obj.offsetTop : 0);
	var xOffset = (obj.offsetLeft ? obj.offsetLeft : 0);
	var elParent = obj.offsetParent;

	while (elParent) {
		yOffset += (elParent.offsetTop ? elParent.offsetTop : 0);
		xOffset += (elParent.offsetLeft ? elParent.offsetLeft : 0);
		elParent = elParent.offsetParent;
	}

	this.y = yOffset;
	this.x = xOffset;

}
/*
	
	Shows a layer at a specific position.
	id is the layer id, parent is the object to align 
	the layer to and the pos and align arguments specify
	the layer's position relative to the parent object;
	The vAlign/hAlign side of the layer will be placed at the
	vPos/hPos coordinate of the parent object:
	             
	          ----------------  <- [vPos 0]
			 |     PARENT     |
	          ----------------  <- [vPos 1]
             ^                ^
	      [hPos 0]         [hPos 1]
		  

	          --------------  <- [vAlign 0]
			 |     LAYER     |
	          --------------  <- [vAlign 1]
             ^               ^
	     [hAlign 0]      [hAlign 1]
		  
*/

function showLayer(id, parent, hPos, vPos, hAlign, vAlign, hOffset, vOffset) {

	var layer = document.getElementById(id);
	var offset = new totalElementOffset(parent);
	var left = offset.x;
	var top = offset.y;
	
	if (hPos == 1) left += parent.offsetWidth;
	if (vPos == 1) top += parent.offsetHeight;
	if (hAlign == 1) left -= layer.style.width.replace(/px/,'');
	if (vAlign == 1) top -= layer.style.height.replace(/px/,'');
	if (hOffset) left += hOffset;
	if (vOffset) top += vOffset;

	layer.style.display = '';
	layer.style.left = left+'px';
	layer.style.top = top+'px';

}

function help(helpitem) {
	//window.open('/help.php?item=' + helpitem, 'wndhelp', 'width=375,height=400,resize=no,scrollbars=yes,locationbar=no,menubar=no');
}

function confirmDeleteThread(vars,id){
	if(confirm("Als u deze post weggooit worden ook alle bijbehorende reacties verwijderd! Doorgaan?")){
		window.location.href=vars+'&delete_thread='+id;
	}
}


// 20060313-TA/VH: Create Trade Center Navigation Tree (TCNT(tm))
var menus = new Array();
var timers = new Array();

function init_menu(id) {

	if (typeof(id) == 'undefined' || !id) id = 'nav';
	menus[id] = document.getElementById(id);

	var li = menus[id].getElementsByTagName('li'), i = li.length;
	while (i--) {
		li[i].onmouseover = showMenu;
		li[i].onmouseout = hideMenu;
	}

	menus[id].onmouseout = timeout;
	menus[id].onmouseover = cleartimer;

}

function timeout() {
	timers[this.id] = setTimeout("hideMenus(menus['"+this.id+"'], null)", 1000);
}

function cleartimer() {

	if (timers[this.id]) {
		clearTimeout(timers[this.id]);
		timers[this.id] = null;
	}

}

function showMenu() {

	var ul = this.parentNode;
	this.className += ' hover';

	while (ul) {

		if (ul.tagName.toLowerCase() == 'ul') {
			hideMenus(ul, this);
			break;
		}

		ul = ul.parentNode;

	}

	ul = this.firstChild;
	while (ul) {

		if (ul.nodeType == 1 && ul.tagName.toLowerCase() == 'ul') {
			ul.style.display = 'block';
			ul.style.visibility = 'visible'; /* necessary for IE*/
			break;
		}

		ul = ul.nextSibling;

	}

}

function hideMenu() {
	this.className = this.className.replace('hover','');
}

function hideMenus(level, skipli) {

	var stack = [level], i = 0, li, j, el, tag;

	do {

		li = stack[i].childNodes, j = li.length;

		while (j--) {

			el = li[j];
			if (el.nodeType == 1 && el != skipli) {

				tag = el.tagName.toLowerCase();

				if (tag == 'li') {

					stack[i++] = el;

				} else if (tag == 'ul' && el.style.display == 'block') {

					stack[i++] = el;
					el.style.display = 'none';
					el.style.visibility = 'hidden'; /* necessary for IE*/

				}

			}

		}

	} while (i--);

}

function setIframeHeight(elm_id, height) {
	var elm = document.getElementById(elm_id);
	if (elm) elm.style.height = height;
}