Index: /CKEditor/branches/prototype/_source/core/ckeditor.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/ckeditor.js	(revision 2398)
+++ /CKEditor/branches/prototype/_source/core/ckeditor.js	(revision 2399)
@@ -55,4 +55,22 @@
 {
 	CKEDITOR.instances[ editor.name ] = editor;
+
+	editor.on( 'focus', function()
+		{
+			if ( CKEDITOR.currentInstance != editor )
+			{
+				CKEDITOR.currentInstance = editor;
+				CKEDITOR.fire( 'currentInstance' );
+			}
+		});
+
+	editor.on( 'blur', function()
+		{
+			if ( CKEDITOR.currentInstance == editor )
+			{
+				CKEDITOR.currentInstance = null;
+				CKEDITOR.fire( 'currentInstance' );
+			}
+		});
 };
 
Index: /CKEditor/branches/prototype/_source/core/editor.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/editor.js	(revision 2398)
+++ /CKEditor/branches/prototype/_source/core/editor.js	(revision 2399)
@@ -287,4 +287,14 @@
 			this.ui = new CKEDITOR.ui( this );
 
+			/**
+			 * Controls the focus state of this editor instance. This property
+			 * is rarely used for normal API operations. It is mainly
+			 * destinated to developer adding UI elements to the editor interface.
+			 * @name CKEDITOR.editor.prototype.focusManager
+			 * @type CKEDITOR.focusManager
+			 * @example
+			 */
+			this.focusManager = new CKEDITOR.focusManager( this );
+
 			CKEDITOR.fire( 'instanceCreated', null, this );
 
@@ -339,4 +349,6 @@
 		 * @param {String} commandName The indentifier name of the command.
 		 * @param {Object} [data] Data to be passed to the command
+		 * @returns {Boolean} "true" if the command has been successfuly
+		 *		executed, otherwise "false".
 		 * @example
 		 * editorInstance.execCommand( 'Bold' );
@@ -348,5 +360,6 @@
 				return command.exec( this, data );
 
-			throw 'Unknown command name "' + commandName + '"';
+			// throw 'Unknown command name "' + commandName + '"';
+			return false;
 		},
 
Index: /CKEditor/branches/prototype/_source/core/focusmanager.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/focusmanager.js	(revision 2399)
+++ /CKEditor/branches/prototype/_source/core/focusmanager.js	(revision 2399)
@@ -0,0 +1,131 @@
+﻿/*
+ * CKEditor - The text editor for Internet - http://ckeditor.com
+ * Copyright (C) 2003-2008 Frederico Caldeira Knabben
+ *
+ * == BEGIN LICENSE ==
+ *
+ * Licensed under the terms of any of the following licenses at your
+ * choice:
+ *
+ *  - GNU General Public License Version 2 or later (the "GPL")
+ *    http://www.gnu.org/licenses/gpl.html
+ *
+ *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
+ *    http://www.gnu.org/licenses/lgpl.html
+ *
+ *  - Mozilla Public License Version 1.1 or later (the "MPL")
+ *    http://www.mozilla.org/MPL/MPL-1.1.html
+ *
+ * == END LICENSE ==
+ */
+
+/**
+ * @fileOverview Defines the {@link CKEDITOR.focusManager} class, which is used
+ *		to handle the focus on editor instances..
+ */
+
+/**
+ * Manages the focus activity in an editor instance. This class is to be used
+ * mainly by UI elements coders when adding interface elements to CKEditor.
+ * @constructor
+ * @param {CKEDITOR.editor} editor The editor instance.
+ * @example
+ */
+CKEDITOR.focusManager = function( editor )
+{
+	if ( editor.focusManager )
+		return editor.focusManager;
+
+	/**
+	 * Indicates that the editor instance has focus.
+	 * @type Boolean
+	 * @example
+	 * alert( CKEDITOR.instances.editor1.focusManager.hasFocus );  // e.g "true"
+	 */
+	this.hasFocus = false;
+
+	/**
+	 * Object used to hold private stuff.
+	 * @private
+	 */
+	this._ =
+	{
+		editor : editor
+	};
+
+	return this;
+};
+
+CKEDITOR.focusManager.prototype =
+{
+	/**
+	 * Indicates that the editor instance has the focus.
+	 *
+	 * This function is not used to set the focus in the editor. Use
+	 * {@link CKEDITOR.editor#focus} for it instead.
+	 * @example
+	 * var editor = CKEDITOR.instances.editor1;
+	 * <b>editor.focusManager.focus()</b>;
+	 */
+	focus : function()
+	{
+		if ( this._.timer )
+			clearTimeout( this._.timer );
+
+		if ( !this.hasFocus )
+		{
+			// If another editor has the current focus, we first "blur" it. In
+			// this way the events happen in a more logical sequence, like:
+			//		"focus 1" > "blur 1" > "focus 2"
+			// ... instead of:
+			//		"focus 1" > "focus 2" > "blur 1"
+			if ( CKEDITOR.currentInstance )
+				CKEDITOR.currentInstance.focusManager.forceBlur();
+
+			this.hasFocus = true;
+			this._.editor.fire( 'focus' );
+		}
+	},
+
+	/**
+	 * Indicates that the editor instance has lost the focus. Note that this
+	 * functions acts asynchronously with a delay of 100ms to avoid subsequent
+	 * blur/focus effects. If you want the "blur" to happen immediately, use
+	 * the {@link #forceBlur} function instead.
+	 * @example
+	 * var editor = CKEDITOR.instances.editor1;
+	 * <b>editor.focusManager.blur()</b>;
+	 */
+	blur : function()
+	{
+		var focusManager = this;
+
+		if ( focusManager._.timer )
+			clearTimeout( focusManager._.timer );
+
+		focusManager._.timer = setTimeout(
+			function()
+			{
+				delete focusManager._.timer;
+				focusManager.forceBlur();
+			}
+			, 100 );
+	},
+
+	/**
+	 * Indicates that the editor instance has lost the focus. Unlike
+	 * {@link #blur}, this function is synchronous, marking the instance as
+	 * "blured" immediately.
+	 * @example
+	 * var editor = CKEDITOR.instances.editor1;
+	 * <b>editor.focusManager.forceBlur()</b>;
+	 */
+	forceBlur : function()
+	{
+		if ( this.hasFocus )
+		{
+			this.hasFocus = false;
+			this._.editor.fire( 'blur' );
+		}
+	}
+};
Index: /CKEditor/branches/prototype/_source/core/loader.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/loader.js	(revision 2398)
+++ /CKEditor/branches/prototype/_source/core/loader.js	(revision 2399)
@@ -55,8 +55,9 @@
 			'core/dom/window'		: [ 'core/dom/domobject' ],
 			'core/dtd'				: [ 'core/tools' ],
-			'core/editor'			: [ 'core/config', 'core/editor_basic', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
+			'core/editor'			: [ 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
 			'core/editor_basic'		: [ 'core/event' ],
 			'core/env'				: [],
 			'core/event'			: [],
+			'core/focusmanager'		: [],
 			'core/htmlparser'		: [],
 			'core/htmlparser/comment'	: [ 'core/htmlparser' ],
Index: /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js
===================================================================
--- /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js	(revision 2398)
+++ /CKEditor/branches/prototype/_source/plugins/wysiwygarea/plugin.js	(revision 2399)
@@ -110,4 +110,14 @@
 						}
 
+//						iframe.on( 'blur', function()
+//							{
+//								console.log( 'iframe Blur' );
+//							});
+
+//						iframe.on( 'focus', function()
+//							{
+//								console.log( 'iframe Blur' );
+//							});
+
 						// Append the new IFRAME to the main element. For IE, it
 						// must be done after setting the "src", to avoid the
@@ -161,6 +171,19 @@
 						try { domDocument.execCommand( 'enableInlineTableEditing', false, !editor.config.disableNativeTableHandles ) ; } catch(e) {}
 
-						editor.window	= new CKEDITOR.dom.window( domWindow );
-						editor.document	= new CKEDITOR.dom.document( domDocument );
+						domWindow	= editor.window		= new CKEDITOR.dom.window( domWindow );
+						domDocument	= editor.document	= new CKEDITOR.dom.document( domDocument );
+
+						var focusTarget = ( CKEDITOR.env.ie || CKEDITOR.env.safari ) ?
+								domWindow : domDocument;
+
+						focusTarget.on( 'blur', function()
+							{
+								editor.focusManager.blur();
+							});
+
+						focusTarget.on( 'focus', function()
+							{
+								editor.focusManager.focus();
+							});
 
 						editor.fire( 'contentDom' );
