Index: _source/plugins/templates/dialogs/templates.js
===================================================================
--- _source/plugins/templates/dialogs/templates.js	(revision 3741)
+++ _source/plugins/templates/dialogs/templates.js	Tue Nov 24 02:34:36 CST 2009
@@ -81,15 +81,25 @@
 
 		if( isInsert )
 		{
+			// Everything should happen after the document is loaded (#4073).
+			editor.on( 'contentDom', function( evt )
+			{
+				evt.removeListener();
+				dialog.hide();
+
+				// Place the cursor at the first editable place.
+				var range = new CKEDITOR.dom.range( editor.document );
+				range.moveToElementEditStart( editor.document.getBody() );
+				range.select( true );
+			} );
 			editor.setData( html );
 		}
 		else
 		{
 			editor.insertHtml( html );
-		}
-
-		dialog.hide();
-	}
+			dialog.hide();
+		}
+	}
 
 	CKEDITOR.dialog.add( 'templates', function( editor )
 		{
Index: _source/plugins/dialog/plugin.js
===================================================================
--- _source/plugins/dialog/plugin.js	(revision 4534)
+++ _source/plugins/dialog/plugin.js	Tue Nov 24 02:34:36 CST 2009
@@ -592,8 +592,12 @@
 		 */
 		show : function()
 		{
-			if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
-				this._.editor.getSelection().lock();
+			var editor = this._.editor;
+			if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
+			{
+				var selection = editor.getSelection();
+				selection && selection.lock();
+			}

 			// Insert the dialog's element to the root document.
 			var element = this._.element;
@@ -779,8 +783,11 @@
 				editor.focus();
 
 				if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
-					editor.getSelection().unlock( true );
+				{
+					var selection = editor.getSelection();
+					selection && selection.unlock( true );
-			}
+				}
+			}
 			else
 				CKEDITOR.dialog._.currentZIndex -= 10;

