/*******************************************************************
 *
 * $Id: global.js,v 1.137 2006/11/28 13:55:43 remon Exp $
 *
 ******************************************************************/

var op = /opera/i.test(navigator.userAgent);
var ie = !op && /msie/i.test(navigator.userAgent);			// preventing opera to be identified as ie
var mz = !ie && /mozilla/i.test(navigator.userAgent);	// preventing opera to be identified as mz		

var bCutCopyPasteEnabled = true;

// Compatibility with IE5.01
if ( !document.getElementById )
{
	function getElementById( id )
	{
		return document.all[id];
	}
}

function $()
{
	var els = [];
	for ( var i = 0, l = arguments.length; i < l; ++i )
	{
		var el = arguments[i];
		// Lookup string ids
		if ( typeof el == 'string' ) el = document.getElementById( el );
		// Single argument, return el
		if ( l == 1 ) return el;
		// Add element
		els.push( el );
	}
	return els;
}

function $S( id )
{
	return $( id ).style;
}

function getElById( id )
{
	var o = document.getElementById( id );
	if ( !o ) alert( '$(): element (\'' + id + '\') not found' );
	else return o;
}

function toggle( id, type )
{
	type = type || 'display';
	var obj = ( typeof( id ) == 'object' ? id : $( id ) );
	var s = obj.style;
	if ( type == 'visibility' ) s.visibility = ( getStyle( obj, 'visibility' ) == 'hidden' ? 'visible' : 'hidden' );
	if ( type == 'display' ) s.display = ( getStyle( obj, 'display' ) == 'none' ? 'block' : 'none' );
	setBodyHeight();
}

function hide()
{
	setStyleForIds( arguments, 'visibility', 'hidden' );
}

function show()
{
	setStyleForIds( arguments, 'visibility', 'visible' );
}

function displayNone()
{
	setStyleForIds( arguments, 'display', 'none' );
}

function displayBlock()
{
	setStyleForIds( arguments, 'display', 'block' );
}

function displayInline()
{
	setStyleForIds( arguments, 'display', 'inline' );
}

function setStyleForIds( ids, property, value )
{
	for ( var i = 0, l = ids.length; i < l; i++ )
		$( ids[i] ).style[property] = value;
}

function getStyle( obj, property )
{
	if ( !obj ) return false;
	if( obj.currentStyle )
		return ( property ? obj.currentStyle[property] : obj.currentStyle );
	else if ( doc.defaultView && doc.defaultView.getComputedStyle )
		return ( property ? doc.defaultView.getComputedStyle( obj, '' )[property] : doc.defaultView.getComputedStyle( obj, '' ) );
	return ( property ? '' : false );
}

function keydown( event )
{
	return true;

	var oContent = getContent();

	// Control
	if( event.ctrlKey )
	{
		switch ( event.keyCode )
		{
			//	Control - F
			case 70:
			//	documentLocation( ROOT_URL + 'search/quicksearch.php?objectnr=' + document.body.getAttribute('objectnr'), oContent );
				break;

			//	Control - X
			case 88:
				if ( bCutCopyPasteEnabled && oContent.menuAction( 'cut' ) )
					documentLocation( ROOT_URL + 'object/cutobject.php?objectnr=' + document.body.getAttribute('objectnr'), oContent );
				break;
		
			//	Control - C
			case 67:
				if ( bCutCopyPasteEnabled && oContent.menuAction( 'copy' ) )
					documentLocation( ROOT_URL + 'object/copyobject.php?objectnr=' + document.body.getAttribute('objectnr'), oContent );
				break;

			//	Control - V
			case 86:
				if ( bCutCopyPasteEnabled )
					documentLocation( ROOT_URL + 'object/pasteobject.php?parentnr=' + document.body.getAttribute('objectnr'), oContent );
				break;

			default:
			//	if ( event.keyCode != 17 ) alert( event.keyCode );
		}
	}

	// Control
	if( event.altKey )
	{
		switch ( event.keyCode )
		{
			//	Alt - F
			case 70:
			//		documentLocation( ROOT_URL + 'search/quicksearch.php?objectnr=' + document.body.getAttribute('objectnr'), getContent() );
				break;

			default:
			//	if ( event.keyCode != 18 ) alert( event.keyCode );
		}
	}
}

function execAsyncXML( sURL, sNodeName )
{
/*
	if ( !$( 'idHttp' ) )
		return alert( 'execAsync(): iframe not found' );
/**/
	if ( typeof( sNodeName ) != 'string' )
		return alert( 'execAsync(): argument is not a string!' );

	var el = $( sNodeName );
	if ( !el ) return alert( 'execAsyncxML(): element not found' );

	el.innerHTML = '<span class="clsTreeItemText"><img src="' + ROOT_URL +'images/loading.gif" border="0" style="padding: 6px;" /></span>';
//	window.sExecAsyncNodeName = sNodeName;
	sURL = addSessionID( sURL );
	sURL = addParam( sURL, 'nodename=' + sNodeName );
//	alert( sURL );
//	$( 'idHttp' ).src = sURL;
	callToServer( sURL );
}

function execAsyncWrite()
{
	var sNodeName = window.sExecAsyncNodeName;

	if ( $( sNodeName ) )
	{
		if ( frames['ifrmHttp'].document.body )
			$( sNodeName ).innerHTML = frames['ifrmHttp'].document.body.innerHTML;
		else
			$( sNodeName ).innerHTML = '<span class="clsTreeItemText"><img src="' + ROOT_URL +'images/16x16/error.gif" border="0" /></span>';
	}
}

function getUrlSync( url, method )
{
	// Default get
	method = method || 'GET';

	// client
	var c;
	if ( window.XMLHttpRequest )
	{
		c = new XMLHttpRequest();
	}
	else if ( window.ActiveXObject )
	{
		// IE6
		if ( !c ) try { c = new ActiveXObject( 'Msxml2.XMLHTTP' ); } catch( e ) {};
		// IE5
		if ( !c ) try { c = new ActiveXObject( 'Microsoft.XMLHTTP' ); } catch( e ) {};
	}

	if ( !c ) return '';

	// For safety and denied access on other domains
	try
	{
		if ( method == 'POST' )
		{
			url = url.split( '?' );
			var data = url[1];
			url = url[0];
		}

		c.open( method, url, false );

		if ( method == 'POST' )
		{
			url = data;

			try
			{
				c.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
			}
			catch( e ) {}
		}

		c.send( url );
//		alert( url + "\n" + c.status + "\n\n" + c.responseText );
		// Opera 8 returns content with status 304
		return ( ( c.status == 200 || c.status == 304 ) ? c.responseText : '' );
	}
	catch ( e )
	{
		return '';
	};
}	// getUrlSync()

function lang( str, format )
{
	// Cache
	var c = ( lang.c = lang.c || [] );
	var k = str + format;
	var res;
	if ( res = c[k] ) return res;
	format = format || '';
	var url = ROOT_URL + 'ajax/lang.php?str=' + str + '&format=' + format + 'PHPSESSID=' + PHPSESSID;
	var res = getUrlSync( url );
	lang.c[k] = res;
//	alert( c[k] + "\n" + lang.c[k] );
	return res;
}

function setTreeHeight()
{
	if ( ie )
	{
		var h = document.body.offsetHeight;
		var t = $( 'idTreeContainer' );
		if ( !t ) return;
		t = t.offsetHeight;
		t += 40;
		document.body.scroll = ( ( t > h ) ? 'yes' : 'auto' );

		if ( parent.document && parent.document.getElementById( 'nav' ) )
			parent.document.getElementById( 'nav' ).setAttribute( 'scrolling', document.body.scroll );
	}

//	alert( document.body.scroll );
//	alert( parent.document.getElementById( 'nav' ).getAttribute( 'scrolling' ) );
}

function setBodyHeight()
{
	if ( ie )
	{
	//	alert( document.body.offsetHeight + " / " + document.body.clientHeight + " / " + document.body.scrollHeight );
	//	alert( document.documentElement.offsetHeight + " / " + document.documentElement.clientHeight + " / " + document.documentElement.scrollHeight );
	/*
		var h = document.body.offsetHeight;
		var c = document.getElementsByTagName( 'DIV' );

		for ( var i = 0; i < c.length; i++ )
		{
			if ( c[i].className == 'container' )
			{
				var t = c[i].offsetHeight;
				break;
			}
		}
	/**/
		var h = document.documentElement.offsetHeight;
		var t = document.documentElement.scrollHeight;
		
	//	if ( !c[i] || c[i].className != 'container' ) alert( 'setBodyHeight(): warning, no container element found' );
		
	//	t -= 6;		//	Enabling this causes problems with some folders, but more accurate scroll in recyclebin, safety setting is disabled.
	//	alert( 't: ' + t + ' / h: ' + h );
	
		// Ensure menu's are within body height
		var o = $( 'idContextmenu' );
		if ( ( t < h ) && o && o.style && o.style.visibility == 'visible' && ( ( o.offsetTop + o.offsetHeight ) > h ) ) t = h;

		var o = $( 'idCreatemenu' );
		if ( ( t < h ) && o && o.style && o.style.visibility == 'visible' && ( ( o.offsetTop + o.offsetHeight ) > h ) ) t = h;

		// HTML compatibility (HTML vs. XHTML)
		if ( document.body.scrollHeight > document.body.offsetHeight )
		{
		//	alert( document.body.offsetHeight + " / " + document.body.clientHeight + " / " + document.body.scrollHeight );
			t = document.body.scrollHeight;
			h = document.body.offsetHeight;
		}

		var w = document.documentElement.offsetWidth;
		var u = document.documentElement.scrollWidth;

		document.body.scroll = ( ( t > h || u > w ) ? 'yes' : 'no' );

		if ( parent.document && parent.document.getElementById( 'viewcontent' ) )
			parent.document.getElementById( 'viewcontent' ).setAttribute( 'scrolling', document.body.scroll );
	}

//	alert( document.body.scroll );
//	if ( parent.document && parent.document.getElementById( 'viewcontent' ) )
//		alert( parent.document.getElementById( 'viewcontent' ).getAttribute( 'scrolling' ) );
//	var tmp = document.documentElement;
//	var tmp = document.body;
//	alert( tmp.offsetHeight + " / " + tmp.clientHeight + " / " + tmp.scrollHeight + " / " + tmp.scrollTop );

}

function resizeIFrame( frameId ) {
	var h,frame, doc, fStyle;
	frame = document.getElementById(frameId);
	doc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	if (!doc || !doc.body) return;
	fStyle = (frame.style) ? frame.style : frame;
	h = doc.body.scrollHeight ;
	if (h<300) h = 300;
	if (1) h = h + 30;	// !$.browser.safari
	fStyle.height = h + (frame.style ? 'px' : '');
}

/* Caculates real content size and resizes iframe accordingly */
function setContentSize( obj, headerheight, minimumheight, margin ) {

	if ( !obj ) obj = $('viewcontent');
	else if ( typeof( obj ) == 'string' ) obj = $( obj );

	if ( !obj ) return alert( 'ERROR - setContentSize(): cannot find frame' );

	try {

		if ( headerheight === undefined ) headerheight = 210;
		if ( minimumheight === undefined ) minimumheight = 400;	// $('sidebar').offsetHeight
		if ( margin === undefined ) margin = 40;

		headerheight = parseInt( headerheight );
		minimumheight = parseInt( minimumheight );
		margin = parseInt( margin );

		var frm = frames[obj.name];
		var doc = frm.document;
		obj.style.height = minimumheight + 'px';
	//	doc.body.style.height = '100%';
		var m = document.body.offsetHeight - headerheight;	// Minimum
		var h = doc.documentElement.scrollHeight;
	//	alert( "documentElement\n- offset: " + doc.documentElement.offsetHeight + ", scroll: " + doc.documentElement.scrollHeight + "\n" + "body\n- offset: " + doc.body.offsetHeight + ", scroll: " + doc.body.scrollHeight );
		doc.body.onclick = function() { setContentSize(); };
		if ( frm.$( "idContextmenu" ) ) frm.$( "idContextmenu" ).onload = function() { setContentSize(); };
		h += margin;
		// Minimum
		h = Math.max( h, m );
		// Safety
		h = Math.max( h, minimumheight );
		// Set it
	//	alert( 'set: ' + h );
		obj.style.height = h + 'px';
	}
	catch ( oError ) {
		alert( 'ERROR - setContentSize(): ' + oError.message );
	}
}	// setContentSize()

function initActiveMenus() {
	for ( var i = 0, l = arguments.length; i < l; ++i )
		initActiveMenu( arguments[i] );
}

function initActiveMenu( id )
{
	var obj = ( typeof( id ) == 'object' ? id : $( id ) );
	var col = obj.getElementsByTagName( 'A' );
	for ( var i = 0, l = col.length; i < l; ++i )
	{
		obj = col[i];
		obj.menuid = id;
		obj.onclick = function () { setActiveMenu( this ); };
	}
}	// initActiveMenu()

function setActiveMenu( item )
{
	var id = item.menuid;
	var col = $( id ).getElementsByTagName( 'A' );
	for ( var i = 0, l = col.length, obj; i < l; ++i )
	{
		obj = col[i];
		obj.className = ( obj == item ? 'active' : '' );
	}
}	// setActiveMenu()

// Starting with the given node, find the nearest containing element with the specified tag and classname
function getContainerWith( node, tagName, className )
{
	while ( node != null )
		if ( node.tagName != null && node.tagName == tagName && node.className == className )
			return node;
		else
			node = node.parentNode;

	return false;
}

function getContainerWithObjectNr( obj )
{
	while ( obj && obj.parentNode )
	{
		if ( obj.getAttribute( "objectnr" ) && obj.getAttribute( "objectnr" ) > 0 )
			return obj;
		else
			obj = obj.parentNode;
	}

	return false;
}

function MM_preloadImages() 						// v3.0
{ 	
	var d=document; 
	if (d.images) { 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i < a.length; i++)
    		if (a[i].indexOf("#")!=0) { 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}

function addParam( url, param )
{
	if ( !url ) url = document.location.href.toString();

	// Get multiple params
	var params = param.split( '&' );

	// Process params
	for ( var i = 0; i < params.length; i++ )
	{
		var p = params[i];

		// Get key
		var key = p.split( '=' )[0];

		// Empty key
		if ( key == '' ) continue;
		
		// Create regex
		var regex = "/" + key + "=([^&]+)([&]*|$)/ig";

		// Replace
		var str = "url = url.replace( " + regex + ", '' );";
	//	alert( str );
		eval( str );
	}

	// Only add when last is not either '?' or '&'
	if ( url.substring( url.length - 1 ) != '&' && url.substring( url.length - 1 ) != '?' )
		url += ( url.indexOf( '?' ) > -1 ? '&' : '?' );

	if ( param ) url += param;

	return url;
}

function addSessionID( url )
{
	// Not session already
	if ( url.indexOf( 'PHPSESSID=' == -1 ) )
		return addParam( url, 'PHPSESSID=' + PHPSESSID );
}

function openWindow( url, sid, w, h, x, y, t, o )
{
/*
	var header = 'test popin';
	popIn( 'idPopIn', header, url, w, h, x, y );
	return;
*/
	// Defaults
	w = w || 640;
	h = h || 400;

	x = x || ( ( window.screen.availWidth - w ) / 2 );
	y = y || ( ( window.screen.availHeight - h ) / 2 );

	if ( x < 0 ) x = 0;
	if ( y < 0 ) y = 0;
	
	t = t || 'Popup';
	o = o || "directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0";

	// Not extern
	if ( url.indexOf( 'http://' ) == -1 ) url = addSessionID( url );

	// Code below enables setting the title in IE but is not compatible with Firefox!
	if ( 0 )
	{
		globalHTML = "<html><head><title>"+t+"<\/title><\/head>"+"<body scroll='no' style='padding:0px;margin:0px;'><iframe src='"+url+"' width='100%' height='100%' frameborder='0'><\/iframe><\/html>";
		var oWin = window.open("javascript:opener.globalHTML", "", "height="+h+", width="+w+", left="+x+", top="+y+", "+o);
	}
	else
	{
		var oWin = window.open(url, "", "height="+h+", width="+w+", left="+x+", top="+y+", "+o);
	}

	if ( ( w > window.screen.availWidth ) || ( h > window.screen.availHeight ) )
		oWin.resizeTo(screen.availWidth,screen.availHeight);

	return oWin;

//	alert("`"+(url + ((sid == null) ? '' : ((url.indexOf('?') >= 0) ? ('&PHPSESSID='+sid) : ('?PHPSESSID='+sid)))), "", "height="+h+", width="+w+", left="+x+", top="+y+", directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0"+"`");	
//	return window.open(url + ((sid == null) ? '' : ((url.indexOf('?') >= 0) ? ('&PHPSESSID='+sid) : ('?PHPSESSID='+sid))), "", "height="+h+", width="+w+", left="+x+", top="+y+", directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0");	
//	return window.open(url+(url.indexOf('?') >= 0 ? '&' : '?')+( ( sid == null ) ? '' : 'PHPSESSID='+sid ), "", "height="+h+", width="+w+", left="+x+", top="+y+", directories=0, location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0");
}

function popIn( sID, header, url, w, h, x, y )
{
	if ( !document.body ) return;

	// Defaults
	w = w || 640;
	h = h || 400;

	if ( w > document.body.clientWidth )	w = document.body.clientWidth;
	if ( h > document.body.clientHeight )	h = document.body.clientHeight;

//	var tmp = document.documentElement;
//	var tmp = document.body;
//	alert( tmp.offsetHeight + " / " + tmp.clientHeight + " / " + tmp.scrollHeight + " / " + tmp.scrollTop );
	
	x = x || ( ( ( document.documentElement.clientWidth - w ) / 2 ) + document.documentElement.scrollLeft );
	y = y || ( ( ( document.documentElement.clientHeight - h ) / 2 ) + document.documentElement.scrollTop );

	url = addSessionID( url );
	url = addParam( url, 'id=' + sID );

	var el = $( sID );

	if ( !el )
	{
		var el = document.createElement( 'DIV' );
	//	var el = document.createElement( 'IFRAME' );
		el.className = 'clsPopIn';
		el.id = sID;
		el.name = sID;
	//	el.style.position = 'absolute';
		el.style.width = w + 'px';
		el.style.height = h + 'px';
		el.style.left = x + 'px';
		el.style.top = y + 'px';
		document.body.insertBefore( el, document.body.firstChild );
	//	document.body.appendChild( el );
	}

	var html = '';
	html += '	<table border="0" cellspacing="0" cellpadding="0" style="width: 100%; height: 100%;">';
	html += '	<tr>';
	html += '	<td style="width: 7px;"><img src="' + ROOT_URL + 'images/test/top_left.gif" border="0" /></td>';
	html += '	<td style="background-image: url(' + ROOT_URL + 'images/test/top.gif);" align="left">';

	html += '	<a href="#" title="close" onclick="$(\'' + sID + '\').style.display=\'none\'; frames[\'' + sID + 'Frame\'].document.location=\'' + ROOT_URL + 'popin/close.php\'; return false;" style="float: right;">';
	html += '	<img src="' + ROOT_URL + 'images/edit/ximage.gif" border="0" />';
	html += '	</a>';

	html += '	<div id="' + sID + 'Head" class="clsHead">';
	html += '	<img src="' + ROOT_URL + 'images/16x16/information.png" border="0" style="vertical-align: middle; margin-right: 4px;" />' + header;
	html += '	</div>';

	html += '	</td>';
	html += '	<td style="width: 7px;"><img src="' + ROOT_URL + 'images/test/top_right.gif" border="0" /></td>';
	html += '	</tr>';
	
	// The table is set to 100% and the frame adds 30px for the top and 7px for the bottom
	// the total height becomes 100% + 37px. To get the final height to match the set height,
	// the set height needs to be substracted with 37 first.
	if ( h < 37 ) h = 37;

	html += '	<tr valign="top" style="height: ' + ( h - 37 ) + 'px;">';
	html += '	<td style="background-image: url(' + ROOT_URL + 'images/test/left.gif); background-position: left; background-repeat: repeat-y;"></td>';
	html += '	<td align="left" style="padding-top: 7px; background-color: white;">';
	html += '';
	html += '	<iframe id="' + sID + 'Frame" name="' + sID + 'Frame" src="' + url + '" allowtransparency="true" frameborder="0" scrolling="auto" style="width: 100%; height: ' + ( h - 37 ) + 'px;"></iframe>';
	html += '';
	html += '	</td>';
	html += '	<td style="background-image: url(' + ROOT_URL + 'images/test/right.gif); background-position: right; background-repeat: repeat-y;"></td>';
	html += '	</tr>';
	html += '	<tr valign="bottom" style="font-size: 1px;">';
	html += '	<td><img src="' + ROOT_URL + 'images/test/bot_left.gif" border="0" /></td>';
	html += '	<td style="background-image: url(' + ROOT_URL + 'images/test/bot.gif); background-position: bottom; background-repeat: repeat-x;"></td>';
	html += '	<td><img src="' + ROOT_URL + 'images/test/bot_right.gif" border="0" /></td>';
	html += '	</tr>';
	html += '	</table>';

	el.style.display = 'block';
	el.innerHTML = html;
/*
	el.style.height = h + 7 + 'px';
	el = frames[el.name];
	el.document.write( '<body style="border: none; margin: 0px; padding: 0px; overflow: hidden;">' + html + '</body>' );
	return false;
/**/
	var pop = core.Elm( sID );
	var head = core.Elm( sID + 'Head' );
	head.turnOnDrag( pop );

	return false;
}

function popInIframe( sID, header, url, w, h, x, y )
{
	if ( !document.body ) return;

	var resize = !( w || h );
	var move = !( x || y );
	
//	alert( 'resize: ' + resize + ', move: ' + move );

	// Defaults
	w = w || 640;
	h = h || 400;

	if ( w > document.body.clientWidth - 40 )	w = document.body.clientWidth - 40;
	if ( h > document.body.clientHeight - 40 )	h = document.body.clientHeight - 40;

//	var tmp = document.documentElement;
//	var tmp = document.body;
//	alert( tmp.offsetHeight + " / " + tmp.clientHeight + " / " + tmp.scrollHeight + " / " + tmp.scrollTop );
	
	x = x || ( ( ( document.documentElement.clientWidth - w ) / 2 ) + document.documentElement.scrollLeft );
	y = y || ( ( ( document.documentElement.clientHeight - h ) / 2 ) + document.documentElement.scrollTop );

	x = Math.max( x, 0 );
	y = Math.max( y, 0 );

	url = addSessionID( url );
	url = addParam( url, 'id=' + sID );

	var el = $( sID );

	if ( !el )
	{
		var el = document.createElement( 'IFRAME' );
		el.className = 'clsPopInIframe';
		el.id = sID;
		el.name = sID;
	//	el.style.position = 'absolute';
		el.frameBorder = 0;
		// Do not set, otherwise selects will go right through
	//	el.allowTransparency = true;
		el.style.width = w + 'px';
		el.style.height = h + 'px';
		el.style.left = x + 'px';
		el.style.top = y + 'px';
	//	document.body.insertBefore( el, document.body.firstChild );
		document.body.appendChild( el );
	//	el.onmouseout = function () { this.style.display = 'none'; }
	}

	var e = getEvent();
	var src = eventSrcElement( e );
	if ( !e && !window.event ) return;

	el.style.width = w + 'px';
	el.style.height = h + 'px';

	el.style.display = 'block';
	el.style.visibility = 'visible';

	frames[el.name].document.location.replace( addSessionID( ROOT_URL + 'popiniframe.php?id=' + sID + '&header=' + escape( header ) + '&url=' + escape( addSessionID( url ) ) + '&resize=' + resize + '&move=' + move ) );
/*
	// Find out how close the mouse is to the corner of the window
	var rightedge	= ie ? document.body.clientWidth - e.clientX : window.innerWidth - e.clientX;
	var bottomedge	= ie ? document.body.clientHeight - e.clientY : window.innerHeight - e.clientY;

	// If the horizontal distance isn't enough to accomodate the width of the context menu
	if ( rightedge < el.offsetWidth )
		// Move the horizontal position of the menu to the left by it's width
		el.style.left = ( ie ? document.documentElement.scrollLeft + e.clientX - el.offsetWidth : window.pageXOffset + e.clientX - el.offsetWidth ) + 'px';
	else
		// Position the horizontal position of the menu where the mouse was clicked
		el.style.left = ( ie ? document.documentElement.scrollLeft + e.clientX : window.pageXOffset + e.clientX ) + 'px';

	// Always make sure left edge is visible
	if ( el.offsetLeft < 0 ) el.style.left = '0px';
		
	// Same concept with the vertical position
	if ( bottomedge < el.offsetHeight )
		el.style.top = ( ie ? document.documentElement.scrollTop + e.clientY - el.offsetHeight : window.pageYOffset + e.clientY - el.offsetHeight ) + 'px';
	else
		el.style.top = ( ie ? document.documentElement.scrollTop + e.clientY : window.pageYOffset + e.clientY ) + 'px';
/**/

//	el.style.left = ( ie ? document.documentElement.scrollLeft + e.clientX : window.pageXOffset + e.clientX ) + 'px';
//	el.style.top = ( ie ? document.documentElement.scrollTop + e.clientY : window.pageYOffset + e.clientY ) + 'px';

	return eventCancel();
}

function popOutIframe( sID, timeout )
{
	timeout = timeout || 0;
	setTimeout( 'displayNone("'+sID+'");', timeout );
}

function sendPM( id, subject, msgid )
{
	var url = ROOT_URL + 'object/createobject.php?type=8';
	url = addSessionID( url );

	if ( id != null )		url += '&sender=' + id;
	if ( subject != null )	url += '&subject=' + subject;
	if ( msgid != null )	url += '&msgid=' + msgid;	
	openWindow( url, null, 750, 525 );
}

function documentLocation( url, win )
{
	if ( win == null ) win = window;
	win.document.location.href = addSessionID( url );
}

function readPM( id )
{
	// Open message
	openWindow( addSessionID( ROOT_URL + 'popup.php?object=' + id ), null, 625 );

	// Find message link
	var lnk = $( 'link_' + id );

	// Reset link when new
	if ( lnk )
		lnk.style.fontWeight = 'normal';

	// Find message icon
	var img = $( 'img_' + id );

	// Reset image when new
	if ( img && img.src.indexOf( '_read' ) == -1 )
		img.src = img.src.replace ( /message\.png/, 'message_read.png' );
}

function browserType()
{
	// Browser Detection
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	
	IE5plus = IE5 || IE6;
	IEMajor = 0;
	
	if (IE4plus)
	{
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
	
	// TODO: Return value with switch statement
}

function addOnload( strFunc, before, test )
{
//	alert ( 'addOnload( ' + strFunc + ', ' + before + ', ' + test + ' )' );
	window.onload = addFunction( strFunc, window.onload, before, test );
	if ( test ) alert( window.onload );
}

function addFunction( sfunc, func, before, test )
{
	// combines two functions in to a new function
	// and return the result as a function
	// -------------------------------------------
	// sfunc - function as string
	// func  - function
	// nfunc - new function

	before = before || false;

	// make a string of the function
	if ( func == null ) func = '';
	func = func.toString();

	// remove newlines
	func = func.replace( /\n/g, '' );
	func = func.replace( /\r/g, '' );

	if ( func.indexOf( 'function' ) > -1 )
	{
		var str = 'function';
		var pos = func.indexOf( str );
		func = func.substring( pos + str.length );
		var str = '()';
		var pos = func.indexOf( str );
		func = func.substring( pos + str.length );
		var str = '{';
		var pos = func.indexOf( str );
		func = func.substring( pos + str.length );
		var str = '}';
		var pos = func.lastIndexOf( str );
		func = func.substring( 0, pos );
		if ( test ) alert( func );
	}

	var nfunc, tmp;
/*
	
	// get the content of func as string
	var regExp	= /{(.+)}/i;
	var nfunc	= '';
	var tmp		= 'if ( regExp.test( func ) ) func = RegExp.lastParen;';

//	alert( func );
//	alert( tmp );
	eval( tmp );
	
//	alert( func );
*/
	// make sure both function end with a ';' since they are put on the same line
	if ( func.lastIndexOf( ';' ) < 0 && func != '' ) func += ';';
	if ( sfunc.lastIndexOf( ';' ) < 0 && sfunc != '' ) sfunc += ';';

	// create new function of two functions
	if ( before )
	{
		tmp			= 'nfunc = function() {' + sfunc + func + '}';
	}
	else
	{
		tmp			= 'nfunc = function() {' + func + sfunc + '}';
	}

	if ( test ) alert( tmp );
	try { eval( tmp ); } catch ( e ) { return function() { }; };
	return nfunc;
}

function switchAdv( obj )
{
	var s = $('advOptions');
	s.style.display	= ( ( s.style.display == 'none' ) ? 'block' : 'none' );
	obj.firstChild.nodeValue = lang( ( s.style.display == 'none' ) ? 'LSTR_CLICK_TO_SHOW' : 'LSTR_CLICK_TO_HIDE' );
	if ( document.forms['f_group'] ) try{ focusForm( document.forms['f_group'] ); } catch ( e ) {};
}
/*
	switchObj( obj, id, show, hide, display, html )
	
	Call from a link to toggle a html node.
	The text (or html) of the node changes when showing or hiding.
	Cookie is set to remember setting, see switchObjByCookie() below.

	obj			html node of switch, typically link
	id			id of html node to switch
	show		text of switch node for showing
	hide		text of switch node for showing
	display		first-click action
	html		show/hide contain html
*/
function switchObj( obj, id, show, hide, display, html )
{
	if ( display == null ) display = 'block';

	var s = $S( id );
	if ( !s.display ) s.display = getStyle( obj, 'display' );
	s.display	= ( ( s.display == 'none' ) ? display : 'none' );

	if ( typeof( show ) == 'undefined' ) show = lang( 'LSTR_CLICK_TO_SHOW' );
	if ( typeof( hide ) == 'undefined' ) hide = lang( 'LSTR_CLICK_TO_HIDE' );

	if ( html )
	{
		show = unescape( show.replace( /[\+]/g, ' ' ) );
		hide = unescape( hide.replace( /[\+]/g, ' ' ) );
	}

	if ( typeof( show ) != 'undefined' || typeof( hide ) != 'undefined' || html )
		obj.innerHTML = ( ( s.display == 'none' ) ? show : hide );

	var c = obj.className;
	var m = c.match( /(add|remove)/ );
	if ( m ) obj.className = ( m[0] == 'add' ? c.replace( /add/, 'remove' ) : c.replace( /remove/, 'add' ) );

//	document.body.scroll = 'yes';
	if ( ie ) setTimeout( 'setBodyHeight();', 100 );

	// Set cookie
	var c = new Cookie();
	c.setCookie( obj.id, s.display );

	return eventCancel();
}

function switchObjByCookie( obj, id, show, hide, display, html )
{
	var c = new Cookie();
	if ( c.getCookie( obj.id ) )
	{
		if ( display == null ) display = 'block';

		var s = $( id );
		s.style.display	= c.getCookie( obj.id );
		s.style.display	= ( ( s.style.display == 'none' ) ? display : 'none' );
		return switchObj( obj, id, show, hide, display, html );
	}
}

function switchDIV( obj )
{
	if ( obj == null || obj.style == null ) return alert( 'switchDIV(): Not a valid object!' );
	obj.style.display	= ( ( obj.style.display == 'none' ) ? 'block' : 'none' );

	// Set cookie
	var c = new Cookie();
	c.setCookie ( obj.id, obj.style.display );

//	document.body.scroll = 'yes';
	if ( ie ) setTimeout( 'setBodyHeight();', 100 );
	
	return eventCancel();
}

window.timerImagePreview = '';
function setTimeoutImagePreview( id )
{
	window.timerImagePreview = setTimeout( "displayImagePreview('" + id + "');", 750 );
}

function displayImagePreview( id )
{
	$('idDivImagePreview_' + id ).style.display = 'block';
	var obj = $('idImagePreview_' + id );
	if ( !obj.getAttribute( 'loaded' ) )
	{
		obj.src = ROOT_URL + 'images/thumbs/' + id;
		obj.setAttribute( 'loaded', 'true' );
	}
}

function trim( text )
{
	if ( text != null )
	{
		text	= text.replace( /^[\s]+/g, '' );
		text	= text.replace( /[\s]+$/g, '' );
	}

	return text;
}

function setInfo( sObjectNr, sTitle, sObjectType, sIcon, sCreated, sCreatorNr, sCreator, sHistory, sRelated )
{
	if ( parent.info && parent.info.setInfoBox )
	{
		var sHTML = '';
		// Object type
		sHTML += '<img src="' + ROOT_URL + sIcon + '" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;' + sObjectType + '<br />';
		// Created
		sHTML += '<img src="' + ROOT_URL + 'images/16x16/clock.png" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;';
		// Created history
		if ( sHistory )
			sHTML += '<a href="' + ROOT_URL + 'object/objecthistory.php?object=' + sObjectNr + '&PHPSESSID=' + PHPSESSID + '" target="viewcontent">';		
		sHTML += sCreated;
		if ( sHistory )
			sHTML += '</a>';
		sHTML += '<br />';
		// Creator
		sHTML += '<img src="' + ROOT_URL + 'images/16x16/person.png" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;';
		// Creator link
		sHTML += '<a href="' + ROOT_URL + 'viewobject.php?object=' + sCreatorNr + '&PHPSESSID=' + PHPSESSID + '" target="viewcontent">';
		sHTML += sCreator;
		sHTML += '</a>';
		sHTML += '<br />';
		// History
		if ( sHistory )
			sHTML += '<img src="' + ROOT_URL + 'images/edit/history.gif" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;<a href="' + ROOT_URL + 'object/objecthistory.php?object=' + sObjectNr + '&PHPSESSID=' + PHPSESSID + '" target="viewcontent">' + sHistory + '</a><br />';
		// Share
	//	sHTML += '<img src="' + ROOT_URL + 'images/16x16/share.png" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;<a href="' + ROOT_URL + 'object/shareobject.php?object=' + sObjectNr + '&PHPSESSID=' + PHPSESSID + '" target="viewcontent">' + sShare + '</a><br />';
		// Support
		sHTML += '<img src="' + ROOT_URL + 'images/16x16/support.png" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;<a href="#" onclick="documentLocation(ROOT_URL+\'object/support.php?url=\'+escape(parent.frames[\'viewcontent\'].location.href)+\'&PHPSESSID=\'+PHPSESSID,parent.frames[\'viewcontent\']); return false;" target="viewcontent">support</a><br />';
		// Related
		if ( sRelated )
			sHTML += '<img src="' + ROOT_URL + 'images/16x16/related.png" border="0" style="vertical-align: middle; padding: 2px;" />&nbsp;<a href="' + ROOT_URL + 'keywords/relatedtoobject.php?objectnr=' + sObjectNr + '&PHPSESSID=' + PHPSESSID + '" target="viewcontent">related objects</a><br />';

		// Set info box
		parent.info.setInfoBox( sTitle, sHTML );
	}
}

function setActiveGroup( groupnr )
{
	if ( parent.group || parent.spaceheader )
	{
		// In case spaceheader, no groupselect
		if ( parent.spaceheader )
			var sel = parent.spaceheader.document.getElementById('groupselect');
		else
			var sel = parent.group.document.getElementById('f_selgroup');

		if ( !sel ) return;
			
		for ( var i = 0; i < sel.options.length; i++ )
		{
			if ( sel.options[i].value == groupnr )
			{
				sel.options[i].selected = true;
				break;
			}
		}
	}
}

function goGroup( groupnr, objectnr )
{
	var obj = parent;
	while( obj != obj.parent && !obj.frames['group'] ) obj = obj.parent;

	if ( !obj.frames['group'] )
	{
		// No group navigation, navigate to group or object
		documentLocation( ROOT_URL + 'viewobject.php?object=' + ( ( objectnr ) ? objectnr : groupnr ) /* + '&setactivategroup=' + groupnr /**/ );
		return;
	}

	var frm	= obj.frames['group'].document.getElementById( 'f_groupnav' );
	if ( !frm ) return;
	frm.f_selgroup.value = groupnr;
	if ( objectnr ) frm.f_objectnr.value = objectnr;
	frm.submit();
	return true;
}

function openSelectObject( sid )
{
	sid = sid || PHPSESSID;
	openWindow( addSessionID( ROOT_URL + 'object/selectobjectbytree.php' ), sid, 450, 500 );
}

function cookiesEnabled()
{
	setCookie( "testCookie", "cookieValue" );
	return ( getCookie( "testCookie" ) == "cookieValue" );
}

function setCookie( id, value )
{
	// Set cookie
	var c = new Cookie();
	c.setCookie ( id, value );
}

function getCookie( id )
{
	// Get cookie
	var c = new Cookie();
	return c.getCookie( id );
}

function Cookie()
{
	if ( document.cookie.length )
		this.cookies = ' ' + document.cookie;
}

Cookie.prototype.setCookie = function ( key, value )
{
	document.cookie = key + "=" + escape( value );
}

Cookie.prototype.getCookie = function ( key )
{
	if ( this.cookies )
	{
		var start = this.cookies.indexOf( ' ' + key + '=' );
		if ( start == -1 ) { return null; }
		var end = this.cookies.indexOf( ";", start );
		if ( end == -1 ) { end = this.cookies.length; }
		end -= start;
		var cookie = this.cookies.substr( start,end );
		return unescape( cookie.substr( cookie.indexOf( '=' ) + 1, cookie.length - cookie.indexOf( '=' ) + 1 ) );
	}
	else { return null; }
}

// Return the x coordinate of an element relative to the page.
function getPageOffsetLeft (el)
{
	var x;
	x = el.offsetLeft;

	if (el.offsetParent != null)
		x += getPageOffsetLeft(el.offsetParent);

	return x;
}

// Return the y coordinate of an element relative to the page.
function getPageOffsetTop (el)
{
	var y;				
	y = el.offsetTop;
	
	if (el.offsetParent != null)
		y += getPageOffsetTop(el.offsetParent);
				
	return y;
}

function getPageOffsetWidth (el)
{
	var w;
	w = el.offsetWidth;

	if(el.offsetParent != null)
		w += getPageOffsetWidth(el.offsetParent);
	
	return w;
}

function getEvent()
{
	var e		= ( ( window.event ) ? event : arguments.callee.caller.arguments[0] );
	return e;
}

function eventSrcElement( e )
{
	if ( !e ) e	= getEvent();
	if ( !e ) return;
	var eObj = e.srcElement || e.target;
	return eObj;
}

function eventCancel()
{
	var e		= ( ( window.event ) ? event : arguments.callee.caller.arguments[0] );
	if ( !e ) return false;
	e.cancelBubble = true;
	e.returnValue = false;
	try { e.stopPropagation(); e.preventDefault(); } catch( error ) {};
	return false;		
}

function toggleRow( obj, bool )
{
	// Get table
	var tab = obj.parentNode.parentNode;

	// Process columns
	for ( var c = 0; c < obj.cells.length; c++ )
	{
		var tmp = ( ( obj.cells[c].childNodes.length > 1 ) ? obj.cells[c].childNodes[1] : null );
		if ( tmp == null || tmp.checked == null ) tmp = obj.cells[c].childNodes[0];
		if ( tmp.checked != null && !tmp.disabled && tmp.getAttribute( "toggle" ) != "false" )
			tmp.checked = ( ( bool == null ) ? !tmp.checked : bool );
	}
}

function toggleCol( obj, bool )
{
	// Get row	
	var row = obj.parentNode;

	// Get table
	var tab = row.parentNode.parentNode;

	// Get cell number
	for ( var c = 0; c < row.cells.length; c++ ) if ( row.cells[c] == obj ) break;

	// Now process all rows
	for ( var r = 0; r < tab.rows.length; r++ )
	{
		if ( tab.rows[r].cells.length > c )
		{
			// Get the first or second childnode depending on the text node
			var tmp = tab.rows[r].cells[c].childNodes[0];
			// Mozilla has a text node first, get next node
			if ( tmp == null || tmp.checked == null ) tmp = tab.rows[r].cells[c].childNodes[1];
			// Still nothing, no checkbox, continue
			if ( tmp == null || tmp.checked == null ) continue;
			// Check and toggle
			if ( tmp.checked != null && !tmp.disabled && tmp.getAttribute( "toggle" ) != "false" )
				tmp.checked = ( ( bool == null ) ? !tmp.checked : bool );
		}
	}
}

function setVisibilitySelects( visibility )
{
	var objs = document.getElementsByTagName( 'select' );
	for ( var i = 0; i < objs.length; i++ )
		objs[i].style.visibility = ( ( objs[i].getAttribute( 'nohide' ) == 'true' ) ? 'visible' : visibility );
}

function createPosition()
{
	// Position create menu left to link
	var createLink = $('idCreateLink');
	$S('idCreatemenu').left = createLink.offsetLeft + 'px'; // + createLink.offsetWidth
	$S('idCreatemenu').top = createLink.offsetTop + createLink.offsetHeight + 'px';
}

function createShow( objectnr )
{
	if ( !objectnr ) objectnr = document.body.getAttribute( 'objectnr' );
	clearTimeout( window.createTimer );
	oObj = $( 'idCreatemenu' );
	if ( !oObj.getAttribute( 'loaded' ) )
	{
	//	oObj.src = addSessionID( ROOT_URL + 'create_menu.php?object=' + objectnr );
		frames[oObj.name].document.location.replace( addSessionID( ROOT_URL + 'create_menu.php?object=' + objectnr ) );
		oObj.setAttribute( 'loaded', true );
	}
	oObj.style.display = 'block';
}

function createHide()
{
	clearTimeout( window.createTimer );
	window.createTimer = setTimeout("displayNone('idCreatemenu');", 500 );
}

function editPosition()
{
	// Position edit menu left to link
	var editLink = $('ideditLink');
	$('ideditmenu').style.left = editLink.offsetLeft + 'px'; // + editLink.offsetWidth
	$('ideditmenu').style.top = editLink.offsetTop + editLink.offsetHeight + 'px';
}

function editShow( objectnr )
{
	if ( !objectnr ) objectnr = document.body.getAttribute( 'objectnr' );
	clearTimeout( window.editTimer );
	oObj = $( 'ideditmenu' );
	if ( !oObj.getAttribute( 'loaded' ) )
	{
		oObj.src = addSessionID( ROOT_URL + 'edit_menu.php?object=' + objectnr );
		oObj.setAttribute( 'loaded', true );
	}
	oObj.style.display = 'block';
}

function editHide()
{
	clearTimeout( window.editTimer );
	window.editTimer = setTimeout("$('ideditmenu').style.display='none';", 500 );
}

function divCreateShow()
{
	clearTimeout( window.divCreateTimer );
	$('divCreate').style.display='block';
	setVisibilitySelects('hidden');
}

function divCreateHide()
{
	clearTimeout( window.divCreateTimer );
	window.divCreateTimer = setTimeout("$('divCreate').style.display='none'; setVisibilitySelects('visible');", 500 );
}

var aSelObjNrs = Array();

function selectedObjects()
{
	// Get selection boxes
	var col = document.getElementsByName( 'f_sel[]' );
	for ( var c = 0; c < col.length; c++ )
		if ( col[c].checked ) return true;
	return false;
}

function menuDelete( msgObject, msgSelection )
{
	if ( selectedObjects() )
	{
		if ( confirm( msgSelection ) )
		{
			frm = document.forms['frm_sel'];
			if ( !frm )
			{
				alert( 'menuDelete(): select form not found' );
				return eventCancel();
			}
			frm.action = addSessionID( ROOT_URL + 'object/deleteselection.php?return=' + escape( document.location.href ) );
			frm.submit();
		}

		return eventCancel();
	}
	else if ( !msgObject || msgObject == '' )
		return false;
	else
		return confirm( unescape( msgObject ) );
}

function menuAction( action )
{
	if ( action == '' ) return alert( 'menuAction(): empty action' );

	if ( selectedObjects() )
	{
		var frm = document.forms['frm_sel'];
		if ( !frm )
		{
			alert( 'menuAction(): select form not found' );
			return eventCancel();
		}
		frm.action = addSessionID( ROOT_URL + 'object/' + action + 'selection.php' );
		frm.submit();
		
		return eventCancel();
	}
	
	return true;
}

function menuToggle( sMenu, bObject, bSelection )
{
	var selection	= selectedObjects();
	var display		= ( ( ( !selection && bObject ) || ( selection && bSelection ) ) ? 'inline' : 'none' );

//	alert( sMenu + ' / ' + selection + ' / ' + display );

	if ( $('idHeader' + sMenu ) )
		$('idHeader' + sMenu ).style.display			= display;

	if ( $('idHeaderDivider' + sMenu ) )
		$('idHeaderDivider' + sMenu ).style.display	= display;
}

function getFirstText( node, debug )
{
//	alert( node.tagName + ' / ' + node.innerText );
	if ( node.tagName == 'A' ) return node.innerText;

	// Get text of first child node
	for ( var i = 0; i < node.childNodes.length; i++ )
	{
		var child = node.childNodes[i];
		if ( child.tagName == 'SCRIPT' ) continue;

		if ( debug && !confirm( child.tagName + ' / ' + child.className + ' / ' + child.id + ' (' + i + ' / ' + node.childNodes.length + ') continue?' ) ) return;

		while ( child )
		{
			// Exit on first real text
			if ( child.innerHTML != '' && ( child.className == 'head_title' || child.innerHTML == child.innerText ) )
			{
				if ( child.innerText ) return child.innerText;
				else return child.nodeValue;
			}

			// No more children
			if ( !child.firstChild )
			{
				if ( debug && !confirm( 'no child.firstChild, current: ' + child.tagName + ' / ' + child.id + ' / ' + child.className + ', continue parentNode?' ) ) return;

				// Move up the hierarchy until nextSibling and exit when original child is reached
				while ( child != node.childNodes[i] && child.parentNode )
				{
					if ( child.nextSibling && child.nextSibling.tagName )
					{
						child = child.nextSibling;
						if ( debug ) alert( 'next sibling: ' + child.tagName + ' / ' + child.id + ' / ' + child.className );
						break;
					}
					child = child.parentNode;
				}

				if ( child == node.childNodes[i] || !child.parentNode  )
				{
					if ( debug ) alert ( 'next child node' );
					break;
				}
			}
			else 
			{
				if ( debug ) alert( 'get first child' );
				child = child.firstChild;
			}

			if ( debug && !confirm( child.tagName + ' / ' + child.id + ', continue firstChild?' ) ) return;
		}
	}

	return 'getFirstText(): no text found';
}

function setDocumentWidth()
{
	var obj = document.body;
//	alert( obj.offsetWidth + ', ' + obj.clientWidth + ', ' + obj.scrollWidth );
	if ( obj && obj.style.width )
		obj.style.width = obj.scrollWidth - 16;
}

function selectAutoWidth( obj, w, d )
{
	w = w || 150;
	d = d || 2000;
	if ( typeof( obj ) == 'string' ) obj = $( obj );
	
	if ( !window.resizeTimers )			window.resizeTimers = Array();
	if ( !window.resizeTimers[obj.id] )	window.resizeTimers[obj.id] = Array();
	window.resizeTimers[obj.id].w	= w;
	window.resizeTimers[obj.id].d	= d;

	obj.style.width = w + 'px';
	obj.onmouseover = function() {
		var w = window.resizeTimers[this.id].w;
		clearTimeout( window.resizeTimers[this.id].t );
		this.style.width = 'auto';
		window.resizeTimers[this.id].t = setTimeout( '$(\'' + this.id + '\').style.width=\'' + w + 'px\';', window.resizeTimers[this.id].d );
	}
	obj.onclick = function() { clearTimeout( window.resizeTimers[this.id].t ); }
	obj.onblur = function() { var w = window.resizeTimers[this.id].w; this.style.width = w + 'px'; }
	obj.onblur = function() {
		clearTimeout( window.resizeTimers[this.id].t );
		var w = window.resizeTimers[this.id].w;
		window.resizeTimers[this.id].t = setTimeout( '$(\'' + this.id + '\').style.width=\'' + w + 'px\';', window.resizeTimers[this.id].d );
	}
}

function getStyle(el,styleProp)
{
	if (window.getComputedStyle)
		var s = window.getComputedStyle(el,null).getPropertyValue(styleProp);
	else if (el.currentStyle)
		var s = el.currentStyle[styleProp];
	return s;
}

function search( frm )
{
	var f_search = frm;
	f_search.f_search_title.value = trim( f_search.f_search_title.value );
	if ( f_search.f_search_title.value == '' || f_search.f_search_title.value == LSTR_SEARCH_TERMS )
	{
		alert( LSTR_ENTER_SEARCH_TERMS );
		f_search.f_search_title.focus();
		return false;
	}
	if ( f_search.f_search_type && f_search.f_search_type.value == 'wikipedia' )
	{
		return searchWiki();
	}
	return true;
}

function scrollToTop() {
	var win = ( ( document.documentElement.clientHeight == document.documentElement.scrollHeight ) ? parent : window );
	win.scroll(0,0);
	return false;
}

function getParentFrame( name, debug )
{
	var win = window;
	do
	{
		// Keep searching parents that are this frame or contain this frame
		win = win.parent;
		if ( debug ) alert( ( win.name == name || ( win.frames && win.frames[name] ) ? 'Found! ' : '' ) + 'name: ' + win.name + ', frames: ' + win.frames[name] + ', location: ' + win.document.location );
		// This frame
		if ( win.name == name ) return win;
		// Contains frame
		if ( win.frames && win.frames[name] ) return win.frames[name];
	}
	while( win != win.parent );

	return false;
}	// getParentFrame()

function getKassFrame( debug )
{
	return ( getParentFrame( 'KASS', debug ) || window.top );
}

function getContent()
{
	return ( getParentFrame( 'viewcontent' ) || window.parent );
}	// getContent()

function downloadZip( nr )
{
	var frm;

	// Get form
	if ( el = $( 'frm_sel' ) )
		frm = document.forms[el.name];

	if ( !frm || !frm.tagName )
	{
		documentLocation( ROOT_URL + 'download.php?object=' + nr + '&zip=true' );
		return;
	//	return alert( 'downloadZip(): Could not find selection form' );
	}

	// Remember settings
	var target = frm.target;
	var action = frm.action;

	// Overwrite settings
	frm.target = '_top';
	frm.action = addSessionID( ROOT_URL + 'download.php?object=' + nr + '&zip=true' );
	frm.submit();

	// Restore settings
	frm.target = target;
	frm.action = action;
}

function strrev( string )
{
	var ret = '';
	for ( i = string.length; i > 0; i-- )
		ret += string.substr( i - 1, 1 );

	return ret;
}

function email_decode( email )
{
	email = email.replace ( /~at~/g, '@' );
	email = email.replace ( /~dot~/g, '.' );
	return email;
}

function ucfirst( string )
{
	return string.substring( 0, 1 ).toUpperCase() + string.substring( 1 );
}

// Inserts newNode after referenceNode
function insertAfter( referenceNode, newNode )
{
	referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}
// Clones a node and inserts it after a node
function insertCloneAfter( obj, after )
{
	var clone = obj.cloneNode( true );
	insertAfter( after, clone );
	return clone;
}