Index: /trunk/phpgwapi/inc/class.javascript.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.javascript.inc.php	(revision 2623)
+++ /trunk/phpgwapi/inc/class.javascript.inc.php	(revision 2628)
@@ -145,6 +145,6 @@
 									else
 									{
-										$_script = '<script type="text/javascript" src="%s/%s/js/%s/%s.js?%d"></script>';
-										$links .= "\n\t\t" . sprintf( $_script, $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'webserver_url' ], $app, $pkg, $file, filemtime( $jsFilePath ) );
+										$_script = '<script type="text/javascript" src="%s/%s/js/%s/%s.js?%d">/* %s  */</script>';
+										$links .= "\n\t\t" . sprintf( $_script, $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'webserver_url' ], $app, $pkg, $file, filemtime( $jsFilePath ), $file );
 									}
 
@@ -262,6 +262,15 @@
 				return true;
 			}
-			error_log( $_file . "\n\n", 3, '/tmp/log' );
 			return false;
+		}
+
+		function get_source( $param )
+		{
+			$source = '';
+			foreach( explode( ';', $param[ 'source' ] ) as $script )
+				$source .= file_get_contents( realpath( dirname( __FILE__ ) . '/../..' ) . $script );
+
+			echo $source;
+			exit;
 		}
 	}
Index: /trunk/phpgwapi/inc/class.common.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.common.inc.php	(revision 2623)
+++ /trunk/phpgwapi/inc/class.common.inc.php	(revision 2628)
@@ -394,4 +394,5 @@
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'expressoAjax', 'dom', NULL, true );
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xlink', NULL, true );
+					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xscript', NULL, true );
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xconnector', NULL, true );
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xevent', NULL, true );
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;
 	};
Index: /trunk/phpgwapi/templates/default/head.inc.php
===================================================================
--- /trunk/phpgwapi/templates/default/head.inc.php	(revision 2623)
+++ /trunk/phpgwapi/templates/default/head.inc.php	(revision 2628)
@@ -28,7 +28,7 @@
 			. "<![endif]-->\n";
 
-	error_log( var_export( $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode',
+	$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode',
 		( ( ! $GLOBALS['phpgw_info']['user']['preferences']['common']['disable_slider_effects'] ) ? 'slidereffects' : 'simple_show_hide' ),
-		'phpgwapi/templates/' . $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'template_set' ], true ), true ) . "\n\n" , 3, '/tmp/log' );
+		'phpgwapi/templates/' . $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'template_set' ], true );
 
 	$bodyheader = ' bgcolor="' . $GLOBALS['phpgw_info']['theme']['bg_color']
Index: /trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2579)
+++ /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2628)
@@ -1277,5 +1277,5 @@
 			if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
 				f_unseen++;				
-			tr_element = this.make_tr_message(headers_msgs[i], msg_folder);
+			tr_element = make_tr_message(headers_msgs[i], msg_folder);
 			if (tr_element){
 				tbody_element.appendChild(tr_element);
Index: /trunk/expressoMail1_2/js/jscode/main.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/main.js	(revision 2616)
+++ /trunk/expressoMail1_2/js/jscode/main.js	(revision 2628)
@@ -24,4 +24,5 @@
 			"access" : "expressoMail1_2.imap_functions.get_range_msgs2&folder=INBOX&msg_range_begin=1&msg_range_end="
 						+ preferences.max_email_per_page + "&sort_box_type=SORTARRIVAL&search_box_type=ALL&sort_box_reverse=1",
+			"cache" : true,
 			"handler" : handler_draw_box
 		} );
@@ -71,8 +72,10 @@
 		_connector.go( { //Save contacts needs preferences.
 			"access" : "expressoMail1_2.db_functions.get_dropdown_contacts",
+			"cache" : true,
 			"handler" : save_contacts
 		} );
 		_connector.go( {
 			"access" : "expressoMail1_2.imap_functions.get_folders_list&onload=true",
+			"cache" : true,
 			"handler" : function( data )
 			{
@@ -99,4 +102,5 @@
 	setTimeout('auto_refresh()', time_refresh);
 
+	refresh(preferences.alert_new_msg);
 }
 
