Index: trunk/phpgwapi/js/tools/xlink.js
===================================================================
--- trunk/phpgwapi/js/tools/xlink.js	(revision 2601)
+++ trunk/phpgwapi/js/tools/xlink.js	(revision 2628)
@@ -1,5 +1,7 @@
 ( function( )
 {
-	var _connector = new XConnector;
+	var _connector = null;
+	var _script = null;
+
 	var _container = null;
 	var _divAppboxHeader = null;
@@ -23,13 +25,30 @@
 				_divAppboxHeader.innerHTML = '';
 
+				var _center = document.createElement( 'center' );
+				_center.appendChild( _loading );
+
 				_container.innerHTML = '';
-				_container.appendChild( _loading );
+				_container.appendChild( _center );
 
-				var _cacheit = ( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false );
+				var _cacheit = true;//( ( pLink.hasAttribute( 'cacheit' ) && pLink.getAttribute( 'cacheit' ) === 'true' ) ? true : false );
 
-				var request = _connector.cache( _cacheit ).go( {
+				var request = _connector.go( {
 					'access' : action,
+					'cache' : _cacheit,
 					'handler' : function( data )
 					{
+						var js = data.match( /<script[^>]*>.*?<\/script>/g );
+						var _new_scripts = [ ];
+						if ( js )
+						{
+							var tag = /<script([^>]* src="(\S+)"|[^>]*)>(.*?)<\/script>/;
+							for ( var i = 0; i < js.length; i++ )
+							{
+								var type = tag.exec( js[ i ] );
+								data = data.replace( "\n\t\t" + type[ 0 ], '' );
+								_new_scripts[ _new_scripts.length ] = type;
+							}
+						}
+
 						var el = document.createElement( 'div' );
 						el.innerHTML = data;
@@ -39,33 +58,26 @@
 							handler( _links.item( i ) );
 
-						var _head = document.getElementsByTagName( 'head' ).item( 0 );
-						var _loaded = _head.getElementsByTagName( 'script' );
-						var _scripts = el.getElementsByTagName( 'script' );
-						var _new_scripts = [ ];
-
-						while ( _scripts.length )
-							_new_scripts[ _new_scripts.length ] = el.removeChild( _scripts.item( 0 ) );
-
 						_container.innerHTML = '';
 						while ( el.hasChildNodes( ) )
 							_container.appendChild( el.firstChild );
 
-						fix : for ( var i = 0; i < _new_scripts.length; i++ )
+						var _inline = [ ];
+						for ( var i = 0; i < _new_scripts.length; i++ )
+							if ( _new_scripts[ i ][ 2 ] == undefined || _new_scripts[ i ][ 2 ].length == 0 )
+								_inline[ _inline.length ] = _new_scripts[ i ][ 3 ];
+							else
+								_script.add( _new_scripts[ i ][ 2 ].substr(
+									URL_SERVER.length,
+									_new_scripts[ i ][ 2 ].indexOf( '?' ) - URL_SERVER.length
+								) );
+
+						var _it_has_loaded = _script.load( function( )
 						{
-							var _script = _new_scripts[ i ];
-							if ( _script.getAttribute( 'src' ) == null )
-							{
-								_container.appendChild( _script );
-								continue;
-							}
-							else
-							{
-								for ( var j = 0; j < _loaded.length; j++ )
-									if ( _script.getAttribute( 'src' ) === _loaded.item( j ).getAttribute( 'src' )  )
-										continue fix;
+							if ( _inline.length )
+								window.eval( _inline.join( '' ) );
+						} );
 
-								_head.appendChild( _script );
-							}
-						}
+						if ( ! _it_has_loaded && _inline.length )
+							window.eval( _inline.join( '' ) );
 					}
 				} );
@@ -76,6 +88,16 @@
 	XEvents.add( window, 'onload', function( )
 	{
-		var _center = document.createElement( 'center' );
-		_center.appendChild( _loading );
+		var _scripts = document.getElementsByTagName( 'head' ).item( 0 ).getElementsByTagName( 'script' );
+		var _loaded = [ ];
+
+		for ( var i = 0; i < _scripts.length; i++ )
+			if ( _scripts.item( i ).getAttribute( 'src' ) != null )
+				_loaded[ _loaded.length ] = _scripts.item( i ).getAttribute( 'src' ).substr(
+					URL_SERVER.length,
+					_scripts.item( i ).getAttribute( 'src' ).indexOf( '?' ) - URL_SERVER.length
+				);
+
+		_connector = new XConnector;
+		_script = new XScript( _loaded );
 
 		_divAppboxHeader = document.getElementById( 'divAppboxHeader' );
@@ -83,5 +105,4 @@
 
 		_container = document.getElementById( 'divAppbox' );
-		_loading = _center;
 
 		document.getElementsByTagName( 'body' ).item( 0 ).style.overflowY = 'scroll';
Index: trunk/phpgwapi/js/tools/xscript.js
===================================================================
--- trunk/phpgwapi/js/tools/xscript.js	(revision 2628)
+++ trunk/phpgwapi/js/tools/xscript.js	(revision 2628)
@@ -0,0 +1,60 @@
+( function( )
+{
+	var _connector = null;
+	var _loaded = [ ];
+	var _new = [ ];
+
+	function _add( pURL )
+	{
+		for ( var i = 0; i < _loaded.length; i++ )
+			if ( _loaded[ i ] == pURL )
+				return false;
+
+		_new[ _new.length ] = pURL;
+
+		return true;
+	}
+
+	function _load( )
+	{
+		if ( ! _new.length )
+			return false;
+
+		var _handler = null;
+		if ( arguments.length && typeof arguments[ 0 ] == 'function' )
+			_handler = arguments[ 0 ];
+
+		_connector.go( {
+			"access" : URL_SERVER + '/controller.php?action=phpgwapi.javascript.get_source&source=' + _new.join( ';' ),
+			"handler" : function( data )
+			{
+				for ( var i = 0; i < _new.length; i++ )
+					_loaded[ _loaded.length ] = _new[ i ];
+
+				_new = [ ];
+
+				window.eval( data );
+
+				if ( _handler )
+					_handler( data );
+			}
+		} );
+	}
+
+	function Script( )
+	{
+		if ( arguments.length && typeof arguments[ 0 ] == 'object' && arguments[ 0 ].constructor == Array )
+			for ( var i = 0; i < arguments[ 0 ].length; i++ )
+				_loaded[ _loaded.length ] = arguments[ 0 ][ i ];
+	}
+
+	Script.prototype.add = _add;
+	Script.prototype.load = _load;
+
+	window.XScript = Script;
+
+	XEvents.add( window, 'onload', function( )
+	{
+		_connector = new XConnector;
+	} );
+} )( );
Index: trunk/phpgwapi/js/tools/xconnector.js
===================================================================
--- trunk/phpgwapi/js/tools/xconnector.js	(revision 2601)
+++ trunk/phpgwapi/js/tools/xconnector.js	(revision 2628)
@@ -100,4 +100,7 @@
 								}
 
+								if ( _THREADS[ _ID ]._CACHE )
+									this._CACHED[ _ID ] = _data;
+
 								delete _THREADS[ _ID ];
 
@@ -105,10 +108,4 @@
 									try
 									{
-										if ( this._cache )
-										{
-											this._CACHED[ _ID ] = _data;
-											this._cache = false;
-										}
-
 										_request( _data );
 									}
@@ -228,9 +225,10 @@
 			'_MODE'		: 'TEXT', // [XML | TEXT]
 			'_TYPE'		: null,	// [4 for request | 3 for stream]
-			'_XHR'		: null	// [4 for request | 3 for stream]
+			'_XHR'		: null,	// [4 for request | 3 for stream]
+			'_CACHE'	: ( ( _argv.cache && _argv.cache === true ) ? true : false )
 		};
 
 		if ( _argv.mode && ( _argv.mode == 'XML' || _argv.mode == 'TEXT' ) )
-			_THREADS[ _ID ] = _argv.mode;
+			_THREADS[ _ID ]._MODE = _argv.mode;
 
 		if ( _argv.handler )
@@ -256,7 +254,6 @@
 			}
 
-		if ( this._cache && this._CACHED[ _ID ] )
-		{
-			this._cache = false;
+		if ( _THREADS[ _ID ]._CACHE && this._CACHED[ _ID ] )
+		{
 			if ( _THREADS[ _ID ]._HANDLER.request )
 				_THREADS[ _ID ]._HANDLER.request( this._CACHED[ _ID ] );
@@ -302,6 +299,4 @@
 		this._CONTROLLER  = '';
 
-		this._cache = false;
-
 		this._CACHED = [ ];
 
@@ -333,11 +328,4 @@
 	Connector.prototype.cache = function( )
 	{
-		_cache = true;
-
-		if ( arguments.length == 1 && arguments[ 0 ].constructor == Boolean )
-			_cache = arguments[ 0 ];
-
-		this._cache = _cache;
-
 		return this;
 	};
