Index: /CKEditor/branches/prototype/_source/core/ckeditor.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/ckeditor.js	(revision 2089)
+++ /CKEditor/branches/prototype/_source/core/ckeditor.js	(revision 2090)
@@ -37,5 +37,5 @@
 
 		var loadedConfig = loadConfigLoaded[ customConfig ] || ( loadConfigLoaded[ customConfig ] = { editors : [] } );
-		
+
 		// If the custom config has already been downloaded, reuse it.
 		if ( loadedConfig.fn )
@@ -53,5 +53,5 @@
 		{
 			// Add the editor to the list of editors waiting for this config.
-			loadedConfig.editors.push( editor ); 
+			loadedConfig.editors.push( editor );
 
 			// Load the custom configuration file.
@@ -73,9 +73,9 @@
 							loadConfig( editor );
 						});
-					
+
 					delete loadedConfig.editors;
 				} );
 		}
-		
+
 		return true;
 	};
@@ -85,10 +85,16 @@
 	{
 		var textarea = new CKEDITOR.dom.element( textarea );
-		textarea.hide();
 
 		// Create the editor instance.
 		var editor = new CKEDITOR.editor( textarea );
+
+		// Abort it there is already an instance with that name.
+		if ( CKEDITOR.instances[ editor.name ] )
+			return;
+
+		textarea.hide();
+
 		CKEDITOR.instances[ editor.name ] = editor;
-		
+
 		// Setup the lister for the "configloaded" event.
 		editor.on( 'configloaded', function()
@@ -99,5 +105,5 @@
 
 				// Fire the "instancecreated" event.
-				CKEDITOR.fire( 'instancecreated', editor.name, editor );				
+				CKEDITOR.fire( 'instancecreated', editor.name, editor );
 			});
 
Index: /CKEditor/branches/prototype/_source/core/ckeditor_basic.js
===================================================================
--- /CKEditor/branches/prototype/_source/core/ckeditor_basic.js	(revision 2089)
+++ /CKEditor/branches/prototype/_source/core/ckeditor_basic.js	(revision 2090)
@@ -22,5 +22,5 @@
 CKEDITOR.event.implementOn( CKEDITOR );
 
-/** 
+/**
  * The class name used to identify &lt;textarea&gt; elements to be replace
  * by CKEditor instances.
@@ -43,5 +43,5 @@
 CKEDITOR.replaceByClassEnabled = true;
 
-/** 
+/**
  * Replaces a specific &lt;textarea&gt; with a CKEditor instance.
  * @param {object|string} elementOrIdOrName The DOM element (textarea), its
@@ -81,14 +81,14 @@
 			if ( !textarea )
 			{
-				alert( '[CKEDITOR.replace] The <textarea> with id or name "' + elementOrIdOrName + '" was not found' );
+				throw '[CKEDITOR.replace] The <textarea> with id or name "' + elementOrIdOrName + '" was not found.';
 				return;
 			}
 		}
-		
+
 		CKEDITOR.replace._replaceElement( textarea, config );
 	}
 };
 
-// This function will be overwritten by the fill core code implementation.
+// This function will be overwritten by the full core code implementation.
 CKEDITOR.replace._replaceElement = function( textarea, config )
 {
@@ -132,6 +132,6 @@
 		var name = textarea.name;
 
-		// The "name" attribute must exist.
-		if ( !name || name.length == 0 )
+		// The "name" and/or "id" attribute must exist.
+		if ( !textarea.name && !textarea.id )
 			continue;
 
@@ -166,5 +166,5 @@
 {
 };
-	
+
 if ( CKEDITOR.status == 'unloaded' )
 {
Index: /CKEditor/branches/prototype/_source/tests/core/ckeditor.html
===================================================================
--- /CKEditor/branches/prototype/_source/tests/core/ckeditor.html	(revision 2090)
+++ /CKEditor/branches/prototype/_source/tests/core/ckeditor.html	(revision 2090)
@@ -0,0 +1,125 @@
+﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<title>CKEDITOR</title>
+	<link rel="stylesheet" type="text/css" href="../test.css" />
+	<script type="text/javascript" src="../../../ckeditor.js"></script>
+	<script type="text/javascript" src="../test.js"></script>
+	<script type="text/javascript">
+	//<![CDATA[
+
+CKEDITOR.test.addTestCase( (function()
+{
+	// Local reference to the "assert" object.
+	var assert = CKEDITOR.test.assert;
+
+	return {
+		test_replaceId : function()
+		{
+			CKEDITOR.replace( 'editor1' );
+			assert.isObject( CKEDITOR.instances.editor1, 'editor instance not found' );
+			assert.areSame( 'editor1', CKEDITOR.instances.editor1.name, 'instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor1' ), CKEDITOR.instances.editor1.element.$, 'instance element doesn\'t match' );
+		},
+
+		test_replaceName : function()
+		{
+			CKEDITOR.replace( 'editor2' );
+			assert.isObject( CKEDITOR.instances.editor2, 'editor instance not found' );
+			assert.areSame( 'editor2', CKEDITOR.instances.editor2.name, 'instance name doesn\'t match' );
+			assert.areSame( document.getElementsByName( 'editor2' )[0], CKEDITOR.instances.editor2.element.$, 'instance element doesn\'t match' );
+		},
+
+		test_replaceElement : function()
+		{
+			CKEDITOR.replace( document.getElementById( 'editor5' ) );
+			assert.isObject( CKEDITOR.instances.editor5, 'editor instance not found' );
+			assert.areSame( 'editor5', CKEDITOR.instances.editor5.name, 'instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor5' ), CKEDITOR.instances.editor5.element.$, 'instance element doesn\'t match' );
+		},
+
+
+		test_replaceError : function()
+		{
+			try
+			{
+				CKEDITOR.replace( 'error' );
+			}
+			catch ( e )
+			{
+				assert.areSame( '[CKEDITOR.replace] The <textarea> with id or name "error" was not found.', e );
+			}
+		},
+
+		test_replaceAll_Class : function()
+		{
+			CKEDITOR.replaceAll( 'myclass' );
+
+			assert.isObject( CKEDITOR.instances.editor3, 'editor3 instance not found' );
+			assert.areSame( 'editor3', CKEDITOR.instances.editor3.name, 'editor3 instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor3' ), CKEDITOR.instances.editor3.element.$, 'editor3 instance element doesn\'t match' );
+
+			assert.isObject( CKEDITOR.instances.editor4, 'editor4 instance not found' );
+			assert.areSame( 'editor4', CKEDITOR.instances.editor4.name, 'editor4 instance name doesn\'t match' );
+			assert.areSame( document.getElementsByName( 'editor4' )[0], CKEDITOR.instances.editor4.element.$, 'editor4 instance element doesn\'t match' );
+
+			assert.isUndefined( CKEDITOR.instances.editor6, 'editor6 should be undefined' );
+			assert.isUndefined( CKEDITOR.instances.editor7, 'editor7 should be undefined' );
+			assert.isUndefined( CKEDITOR.instances.editor8, 'editor8 should be undefined' );
+			assert.isUndefined( CKEDITOR.instances.editor8, 'editor9 should be undefined' );
+		},
+
+		test_replaceAll_Function : function()
+		{
+			CKEDITOR.replaceAll( function( textarea )
+				{
+					return ( textarea.id != 'editor6' && textarea.id != 'editor8' );
+				} );
+
+			assert.isObject( CKEDITOR.instances.editor7, 'editor7 instance not found' );
+			assert.areSame( 'editor7', CKEDITOR.instances.editor7.name, 'editor7 instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor7' ), CKEDITOR.instances.editor7.element.$, 'editor7 instance element doesn\'t match' );
+
+			assert.isObject( CKEDITOR.instances.editor9, 'editor9 instance not found' );
+			assert.areSame( 'editor9', CKEDITOR.instances.editor9.name, 'editor9 instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor9' ), CKEDITOR.instances.editor9.element.$, 'editor9 instance element doesn\'t match' );
+
+			assert.isUndefined( CKEDITOR.instances.editor6, 'editor6 should be undefined' );
+			assert.isUndefined( CKEDITOR.instances.editor8, 'editor8 should be undefined' );
+		},
+
+		test_replaceAll : function()
+		{
+			CKEDITOR.replaceAll();
+
+			assert.isObject( CKEDITOR.instances.editor6, 'editor6 instance not found' );
+			assert.areSame( 'editor6', CKEDITOR.instances.editor6.name, 'editor6 instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor6' ), CKEDITOR.instances.editor6.element.$, 'editor6 instance element doesn\'t match' );
+
+			assert.isObject( CKEDITOR.instances.editor8, 'editor8 editor instance not found' );
+			assert.areSame( 'editor8', CKEDITOR.instances.editor8.name, 'editor8 instance name doesn\'t match' );
+			assert.areSame( document.getElementById( 'editor8' ), CKEDITOR.instances.editor8.element.$, 'editor8 instance element doesn\'t match' );
+		},
+
+		name : document.title
+	};
+})() );
+
+
+
+
+	//]]>
+	</script>
+</head>
+<body>
+	<textarea id="editor1" cols="80" rows="10"></textarea>
+	<textarea name="editor2" cols="80" rows="10"></textarea>
+	<textarea id="editor3" name="editor3" class="myclass" cols="80" rows="10"></textarea>
+	<textarea name="editor4" class="myclass" cols="80" rows="10"></textarea>
+	<textarea id="editor5" cols="80" rows="10"></textarea>
+	<textarea id="editor6" cols="80" rows="10"></textarea>
+	<textarea id="editor7" cols="80" rows="10"></textarea>
+	<textarea id="editor8" cols="80" rows="10"></textarea>
+	<textarea id="editor9" cols="80" rows="10"></textarea>
+</body>
+</html>
Index: /CKEditor/branches/prototype/_source/tests/test.js
===================================================================
--- /CKEditor/branches/prototype/_source/tests/test.js	(revision 2089)
+++ /CKEditor/branches/prototype/_source/tests/test.js	(revision 2090)
@@ -41,4 +41,15 @@
 		div.innerHTML = text;
 	};
+	
+	var htmlEncode = function( data )
+	{
+		if ( typeof data != 'string' )
+			return data;
+
+		return data.replace( 
+			'&', '&amp;' ).replace(
+			'<', '&lt;' ).replace(
+			'>', '&gt;' );
+	};
 
 	window.onload = function()
@@ -52,5 +63,5 @@
 			{
 				case runner.TEST_FAIL_EVENT:
-					outputResult( '<span class="testFail">FAIL</span> Test named "' + data.testName + '" failed with message: "' + data.error.message + '".<div>Expected:</div><pre>' + data.error.expected + '</pre><div>Actual:</div><pre>' + data.error.actual + '</pre>' );
+					outputResult( '<span class="testFail">FAIL</span> Test named "' + data.testName + '" failed with message: "' + htmlEncode( data.error.message ) + '".<div>Expected:</div><pre>' + htmlEncode( data.error.expected ) + '</pre><div>Actual:</div><pre>' + htmlEncode( data.error.actual ) + '</pre>' );
 					break;
 				case runner.TEST_PASS_EVENT:
Index: /CKEditor/branches/prototype/_source/tests/testall.html
===================================================================
--- /CKEditor/branches/prototype/_source/tests/testall.html	(revision 2089)
+++ /CKEditor/branches/prototype/_source/tests/testall.html	(revision 2090)
@@ -10,4 +10,5 @@
 [
 	'core/ajax',
+	'core/ckeditor',
 	'core/dom/element',
 	'core/env',
