Index: /FCKeditor/branches/developers/mjk/editor/_source/classes/fckeditingarea.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/classes/fckeditingarea.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/classes/fckeditingarea.js	(revision 244)
@@ -49,6 +49,6 @@
 		eTargetElement.removeChild( eTargetElement.childNodes[0] ) ;
 
-	if ( this.Mode == FCK_EDITMODE_WYSIWYG )
-	{
+
+
 		// Create the editing area IFRAME.
 		var oIFrame = this.IFrame = oTargetDocument.createElement( 'iframe' ) ;
@@ -120,19 +120,6 @@
 		else
 			FCKEditingArea_CompleteStart.call( this.Window ) ;
-	}
-	else
-	{
-		var eTextarea = this.Textarea = oTargetDocument.createElement( 'textarea' ) ;
-		eTextarea.className = 'SourceField' ;
-		eTextarea.dir = 'ltr' ;
-		eTextarea.style.width = eTextarea.style.height = '100%' ;
-		eTextarea.style.border = 'none' ;
-		eTargetElement.appendChild( eTextarea ) ;
-
-		eTextarea.value = html  ;
-
-		// Fire the "OnLoad" event.
-		FCKTools.RunFunction( this.OnLoad ) ;
-	}
+
+
 }
 
@@ -214,25 +201,13 @@
 	try
 	{
-		if ( this.Mode == FCK_EDITMODE_WYSIWYG )
-		{
-			// The following check is important to avoid IE entering in a focus loop. Ref:
-			// http://sourceforge.net/tracker/index.php?func=detail&aid=1567060&group_id=75348&atid=543653
-			if ( FCKBrowserInfo.IsIE && this.Document.hasFocus() )
-				return ;
-
-			if ( FCKBrowserInfo.IsSafari )
-				this.IFrame.focus() ;
-			else
-			{
-				this.Window.focus() ;
-			}
-		}
+		// The following check is important to avoid IE entering in a focus loop. Ref:
+		// http://sourceforge.net/tracker/index.php?func=detail&aid=1567060&group_id=75348&atid=543653
+		if ( FCKBrowserInfo.IsIE && this.Document.hasFocus() )
+			return ;
+		if ( FCKBrowserInfo.IsSafari )
+			this.IFrame.focus() ;
 		else
 		{
-			var oDoc = FCKTools.GetElementDocument( this.Textarea ) ;
-			if ( (!oDoc.hasFocus || oDoc.hasFocus() ) && oDoc.activeElement == this.Textarea )
-				return ;
-
-			this.Textarea.focus() ;
+			this.Window.focus() ;
 		}
 	}
Index: /FCKeditor/branches/developers/mjk/editor/_source/commandclasses/fck_othercommands.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/commandclasses/fck_othercommands.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/commandclasses/fck_othercommands.js	(revision 244)
@@ -339,4 +339,6 @@
 
 // FCKSelectAllCommand
+// mjk: since source is in the main frame, this command is now
+// redundant and probably should be removed.
 var FCKSelectAllCommand = function()
 {
@@ -346,23 +348,5 @@
 FCKSelectAllCommand.prototype.Execute = function()
 {
-	if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
-	{
-		FCK.ExecuteNamedCommand( 'SelectAll' ) ;
-	}
-	else
-	{
-		// Select the contents of the textarea
-		var textarea = FCK.EditingArea.Textarea ;
-		if ( FCKBrowserInfo.IsIE )
-		{
-			textarea.createTextRange().execCommand( 'SelectAll' ) ;
-		}
-		else
-		{
-			textarea.selectionStart = 0;
-			textarea.selectionEnd = textarea.value.length ;
-		}
-		textarea.focus() ;
-	}
+	FCK.ExecuteNamedCommand( 'SelectAll' ) ;
 }
 
Index: /FCKeditor/branches/developers/mjk/editor/_source/internals/fck.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/internals/fck.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/internals/fck.js	(revision 244)
@@ -49,5 +49,5 @@
 	{
 		if ( this.EditMode == FCK_EDITMODE_SOURCE )
-			return ( this.StartupValue != this.EditingArea.Textarea.value ) ;
+			return ( this.StartupValue != FCK._fromRawHTML(this.EditorDocument.body.innerHTML));
 		else
 			return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
@@ -57,5 +57,5 @@
 	{
 		if ( this.EditMode == FCK_EDITMODE_SOURCE )
-			this.StartupValue = this.EditingArea.Textarea.value ;
+			this.StartupValue = FCK._fromRawHTML(this.EditorDocument.body.innerHTML);
 		else if ( this.EditorDocument.body )
 			this.StartupValue = this.EditorDocument.body.innerHTML ;
@@ -196,5 +196,5 @@
 		// represent the exact contents of the source, as the user wanted it to be.
 		if ( FCK.EditMode == FCK_EDITMODE_SOURCE )
-				return FCK.EditingArea.Textarea.value ;
+				return FCK._fromRawHTML(FCK.EditorDocument.body.innerHTML);
 
 		this.FixBody() ;
@@ -257,4 +257,27 @@
 	{
 		FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
+		//Put the cursor where we left it when moving into or
+		//out of Source view -- or somewhere close to it.
+		if (FCK.MoveToMarker)
+		{
+			if (FCKBrowserInfo.IsIE)
+			{
+				var oRange = FCK.EditorDocument.body.createTextRange();
+				oRange.findText("__FCK_RAW_Marker__",1);
+				oRange.select();
+				FCK.InsertHtml('');
+				oRange.scrollIntoView();
+			}
+			else
+			{
+				FCK.Selection.SelectNode(FCK.EditorDocument.body);
+				FCK.Selection.Collapse();
+				FCK.EditorWindow.find("__FCK_RAW_Marker__", true, false, false, false, false, false );
+				var oSel = FCKSelection.Delete() ;
+				var oRange = oSel.getRangeAt(0) ;	
+				oRange.Select() ;
+			}
+			FCK.MoveToMarker = null;
+		}
 		FCKUndo.SaveUndoStep() ;
 
@@ -327,133 +350,104 @@
 		this.EditingArea.Mode = FCK.EditMode ;
 
-		if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
-		{
-			html = FCKConfig.ProtectedSource.Protect( html ) ;
-
-			// Fix for invalid self-closing tags (see #152).
-			html = html.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ;
-
-			html = FCK.ProtectEvents( html ) ;
-			html = FCK.ProtectUrls( html ) ;
-			html = FCK.ProtectTags( html ) ;
-
-			// Firefox can't handle correctly the editing of the STRONG and EM tags.
-			// We must replace them with B and I.
-			if ( FCKBrowserInfo.IsGecko )
+		html = FCKConfig.ProtectedSource.Protect( html ) ;
+
+		// Fix for invalid self-closing tags (see #152).
+		html = html.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ;
+
+		html = FCK.ProtectEvents( html ) ;
+		html = FCK.ProtectUrls( html ) ;
+		html = FCK.ProtectTags( html ) ;
+
+		// Firefox can't handle correctly the editing of the STRONG and EM tags.
+		// We must replace them with B and I.
+		if ( FCKBrowserInfo.IsGecko )
+		{
+			html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ;
+			html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ;
+			html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
+			html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
+		}
+
+		this._ForceResetIsDirty = ( resetIsDirty === true ) ;
+
+		var sHtml = '' ;
+
+		if ( FCKConfig.FullPage )
+		{
+			// The HTML must be fixed if the <head> is not available.
+			if ( !FCKRegexLib.HeadOpener.test( html ) )
 			{
-				html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ;
-				html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ;
-				html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
-				html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
+				// Check if the <html> is available.
+				if ( !FCKRegexLib.HtmlOpener.test( html ) )
+					html = '<html dir="' + FCKConfig.ContentLangDirection + '">' + html + '</html>' ;
+
+				// Add the <head>.
+				html = html.replace( FCKRegexLib.HtmlOpener, '$&<head></head>' ) ;
 			}
 
-			this._ForceResetIsDirty = ( resetIsDirty === true ) ;
-
-			var sHtml = '' ;
-
-			if ( FCKConfig.FullPage )
-			{
-				// The HTML must be fixed if the <head> is not available.
-				if ( !FCKRegexLib.HeadOpener.test( html ) )
-				{
-					// Check if the <html> is available.
-					if ( !FCKRegexLib.HtmlOpener.test( html ) )
-						html = '<html dir="' + FCKConfig.ContentLangDirection + '">' + html + '</html>' ;
-
-					// Add the <head>.
-					html = html.replace( FCKRegexLib.HtmlOpener, '$&<head></head>' ) ;
-				}
-
-				// Save the DOCTYPE.
-				FCK.DocTypeDeclaration = html.match( FCKRegexLib.DocTypeTag ) ;
-
-				if ( FCKBrowserInfo.IsIE )
-					sHtml = FCK._GetBehaviorsStyle() ;
-				else if ( FCKConfig.ShowBorders )
-					sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
-
-				sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
-
-				// Attention: do not change it before testing it well (sample07)!
-				// This is tricky... if the head ends with <meta ... content type>,
-				// Firefox will break. But, it works if we include the temporary
-				// links as the last elements in the HEAD.
-				sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ;
-
-				// Insert the base tag (FCKConfig.BaseHref), if not exists in the source.
-				// The base must be the first tag in the HEAD, to get relative
-				// links on styles, for example.
-				if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) )
-					sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
-			}
+			// Save the DOCTYPE.
+			FCK.DocTypeDeclaration = html.match( FCKRegexLib.DocTypeTag ) ;
+
+			if ( FCKBrowserInfo.IsIE )
+				sHtml = FCK._GetBehaviorsStyle() ;
+			else if ( FCKConfig.ShowBorders )
+				sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
+
+			sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
+
+			// Attention: do not change it before testing it well (sample07)!
+			// This is tricky... if the head ends with <meta ... content type>,
+			// Firefox will break. But, it works if we include the temporary
+			// links as the last elements in the HEAD.
+			sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ;
+
+			// Insert the base tag (FCKConfig.BaseHref), if not exists in the source.
+			// The base must be the first tag in the HEAD, to get relative
+			// links on styles, for example.
+			if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) )
+				sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
+		}
+		else
+		{
+			sHtml =
+				FCKConfig.DocType +
+				'<html dir="' + FCKConfig.ContentLangDirection + '"' ;
+
+			// On IE, if you are use a DOCTYPE differenft of HTML 4 (like
+			// XHTML), you must force the vertical scroll to show, otherwise
+			// the horizontal one may appear when the page needs vertical scrolling.
+			if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) )
+				sHtml += ' style="overflow-y: scroll"' ;
+
+			sHtml +=
+				'><head><title></title>' +
+				_FCK_GetEditorAreaStyleTags() +
+				'<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
+
+			if ( FCKBrowserInfo.IsIE )
+				sHtml += FCK._GetBehaviorsStyle() ;
+			else if ( FCKConfig.ShowBorders )
+				sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
+
+			sHtml += FCK.TempBaseTag ;
+
+			// Add ID and Class to the body
+			var sBodyTag = '<body' ;
+			if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 )
+				sBodyTag += ' id="' + FCKConfig.BodyId + '"' ;
+			if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 )
+				sBodyTag += ' class="' + FCKConfig.BodyClass + '"' ;
+			sHtml += '</head>' + sBodyTag + '>' ;
+
+			if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) )
+				sHtml += GECKO_BOGUS ;
 			else
-			{
-				sHtml =
-					FCKConfig.DocType +
-					'<html dir="' + FCKConfig.ContentLangDirection + '"' ;
-
-				// On IE, if you are use a DOCTYPE differenft of HTML 4 (like
-				// XHTML), you must force the vertical scroll to show, otherwise
-				// the horizontal one may appear when the page needs vertical scrolling.
-				if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) )
-					sHtml += ' style="overflow-y: scroll"' ;
-
-				sHtml +=
-					'><head><title></title>' +
-					_FCK_GetEditorAreaStyleTags() +
-					'<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
-
-				if ( FCKBrowserInfo.IsIE )
-					sHtml += FCK._GetBehaviorsStyle() ;
-				else if ( FCKConfig.ShowBorders )
-					sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
-
-				sHtml += FCK.TempBaseTag ;
-
-				// Add ID and Class to the body
-				var sBodyTag = '<body' ;
-				if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 )
-					sBodyTag += ' id="' + FCKConfig.BodyId + '"' ;
-				if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 )
-					sBodyTag += ' class="' + FCKConfig.BodyClass + '"' ;
-				sHtml += '</head>' + sBodyTag + '>' ;
-
-				if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) )
-					sHtml += GECKO_BOGUS ;
-				else
-					sHtml += html ;
-
-				sHtml += '</body></html>' ;
-			}
-
-			this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ;
-			this.EditingArea.Start( sHtml ) ;
-		}
-		else
-		{
-			// Remove the references to the following elements, as the editing area
-			// IFRAME will be removed.
-			FCK.EditorWindow	= null ;
-			FCK.EditorDocument	= null ;
-
-			this.EditingArea.OnLoad = null ;
-			this.EditingArea.Start( html ) ;
-
-			// Enables the context menu in the textarea.
-			this.EditingArea.Textarea._FCKShowContextMenu = true ;
-
-			// Removes the enter key handler.
-			FCK.EnterKeyHandler = null ;
-
-			if ( resetIsDirty )
-				this.ResetIsDirty() ;
-
-			// Listen for keystroke events.
-			FCK.KeystrokeHandler.AttachToElement( this.EditingArea.Textarea ) ;
-
-			this.EditingArea.Textarea.focus() ;
-
-			FCK.Events.FireEvent( 'OnAfterSetHTML' ) ;
-		}
+				sHtml += html ;
+
+			sHtml += '</body></html>' ;
+		}
+
+		this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ;
+		this.EditingArea.Start( sHtml ) ;
 
 		if ( FCKBrowserInfo.IsGecko )
@@ -566,6 +560,4 @@
 		var bIsDirty = FCK.IsDirty() ;
 
-		var sHtml ;
-
 		// Update the HTML in the view output to show.
 		if ( bIsWysiwyg )
@@ -573,23 +565,28 @@
 			if ( !noUndo && FCKBrowserInfo.IsIE )
 				FCKUndo.SaveUndoStep() ;
-
-			sHtml = FCK.GetXHTML( FCKConfig.FormatSource ) ;
-
-			if ( sHtml == null )
-				return false ;
+	
+			//drop a marker so we can find where we were
+			if (FCK.Selection.GetType() != 'None') FCK.Selection.Collapse();
+			FCK.InsertHtml("__FCK_RAW_Marker__");
+			sHtml = FCK._toRawHTML(FCK.GetXHTML( FCKConfig.FormatSource ));
+			FCK.MoveToMarker = true;
 		}
 		else
-			sHtml = this.EditingArea.Textarea.value ;
-
+		{
+			sHtml = FCK.GetXHTML( FCKConfig.FormatSource );
+			//set this before SetHTML so we get HTML out rather than raw out
+			FCK.EditMode = FCK_EDITMODE_WYSIWYG;
+		}
+	
+		FCK.SetHTML( sHtml ) ;
+	
 		FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ;
-
-		FCK.SetHTML( sHtml, !bIsDirty ) ;
-
+	
 		// Set the Focus.
 		FCK.Focus() ;
-
+	
 		// Update the toolbar (Running it directly causes IE to fail).
 		FCKTools.RunFunction( FCK.ToolbarSet.RefreshModeState, FCK.ToolbarSet ) ;
-
+	
 		return true ;
 	},
@@ -618,4 +615,34 @@
 		}
 		return null ;
+	},
+	
+	// Handle text processing when moving into or out of Source view.
+	// per mjk's patches, Source is no longer a separate textarea but
+	// a differently formatted view inside the main editor iframe.
+	// Consequently, we get some redundant source formatting that we need
+	// to simply remove before returning to WYSIWYG view.
+	// TODO: Add syntax coloring support.
+	_fromRawHTML : function(sIn)
+	{
+		var sHtml = sIn;
+		sHtml = sHtml.replace(/<[\/]*pre>/ig,'');
+		sHtml = sHtml.replace(/<p>/ig,'\n');
+		sHtml = sHtml.replace(/<[\/]*b>/ig,'');
+		sHtml = sHtml.replace(/<\/p>/ig,'');
+		sHtml = sHtml.replace(/<br[^>]*>/ig,'\n');
+		sHtml = sHtml.replace(/&gt;/ig,'>');
+		sHtml = sHtml.replace(/&lt;/ig,'<');
+		sHtml = sHtml.replace(/&amp;/ig,'&');
+		return sHtml;
+	},
+
+	_toRawHTML : function (sIn)
+	{
+		sHtml = sIn;
+		sHtml = sHtml.replace(/&/ig,'&amp;');
+		sHtml = sHtml.replace(/</ig,'&lt;');
+		sHtml = sHtml.replace(/>/ig,'&gt;');
+		sHtml = '<pre>' + sHtml + '</pre>';
+		return sHtml;
 	}
 
Index: /FCKeditor/branches/developers/mjk/editor/_source/internals/fckcommands.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/internals/fckcommands.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/internals/fckcommands.js	(revision 244)
@@ -50,5 +50,5 @@
 
 		case 'Find'			: oCommand = new FCKDialogCommand( 'Find'		, FCKLang.DlgFindTitle			, 'dialog/fck_find.html'		, 340, 170 ) ; break ;
-		case 'Replace'		: oCommand = new FCKDialogCommand( 'Replace'	, FCKLang.DlgReplaceTitle		, 'dialog/fck_replace.html'		, 340, 200 ) ; break ;
+		case 'Replace'		: oCommand = new FCKDialogCommand( 'Replace'	, FCKLang.DlgReplaceTitle		, 'dialog/fck_find.html?rep'	, 340, 200 ) ; break ;
 
 		case 'Image'		: oCommand = new FCKDialogCommand( 'Image'		, FCKLang.DlgImgTitle			, 'dialog/fck_image.html'		, 450, 400 ) ; break ;
Index: /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbaritems.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbaritems.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbaritems.js	(revision 244)
@@ -47,10 +47,10 @@
 		case 'About'			: oItem = new FCKToolbarButton( 'About'		, FCKLang.About, null, null, true, null, 47  ) ; break ;
 
-		case 'Cut'				: oItem = new FCKToolbarButton( 'Cut'		, FCKLang.Cut, null, null, false, true, 7 ) ; break ;
-		case 'Copy'				: oItem = new FCKToolbarButton( 'Copy'		, FCKLang.Copy, null, null, false, true, 8 ) ; break ;
-		case 'Paste'			: oItem = new FCKToolbarButton( 'Paste'		, FCKLang.Paste, null, null, false, true, 9 ) ; break ;
+		case 'Cut'				: oItem = new FCKToolbarButton( 'Cut'		, FCKLang.Cut, null, null, true, true, 7 ) ; break ;
+		case 'Copy'				: oItem = new FCKToolbarButton( 'Copy'		, FCKLang.Copy, null, null, true, true, 8 ) ; break ;
+		case 'Paste'			: oItem = new FCKToolbarButton( 'Paste'		, FCKLang.Paste, null, null, true, true, 9 ) ; break ;
 		case 'PasteText'		: oItem = new FCKToolbarButton( 'PasteText'	, FCKLang.PasteText, null, null, false, true, 10 ) ; break ;
 		case 'PasteWord'		: oItem = new FCKToolbarButton( 'PasteWord'	, FCKLang.PasteWord, null, null, false, true, 11 ) ; break ;
-		case 'Print'			: oItem = new FCKToolbarButton( 'Print'		, FCKLang.Print, null, null, false, true, 12 ) ; break ;
+		case 'Print'			: oItem = new FCKToolbarButton( 'Print'		, FCKLang.Print, null, null, true, true, 12 ) ; break ;
 		case 'SpellCheck'		: oItem = new FCKToolbarButton( 'SpellCheck', FCKLang.SpellCheck, null, null, null, null, 13 ) ; break ;
 		case 'Undo'				: oItem = new FCKToolbarButton( 'Undo'		, FCKLang.Undo, null, null, false, true, 14 ) ; break ;
@@ -98,6 +98,6 @@
 		case 'BGColor'			: oItem = new FCKToolbarPanelButton( 'BGColor'	, FCKLang.BGColor, null, null, 46 ) ; break ;
 
-		case 'Find'				: oItem = new FCKToolbarButton( 'Find'		, FCKLang.Find, null, null, null, null, 16 ) ; break ;
-		case 'Replace'			: oItem = new FCKToolbarButton( 'Replace'	, FCKLang.Replace, null, null, null, null, 17 ) ; break ;
+		case 'Find'				: oItem = new FCKToolbarButton( 'Find'		, FCKLang.Find, null, null, null, true, 16 ) ; break ;
+		case 'Replace'			: oItem = new FCKToolbarButton( 'Replace'	, FCKLang.Replace, null, null, null, true, 17 ) ; break ;
 
 		case 'Form'				: oItem = new FCKToolbarButton( 'Form'			, FCKLang.Form, null, null, null, null, 48 ) ; break ;
Index: /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbarset.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbarset.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/_source/internals/fcktoolbarset.js	(revision 244)
@@ -355,4 +355,8 @@
 
 	for ( var i = 0 ; i < aItems.length ; i++ )
-		aItems[i].RefreshState() ;
-}
+	{
+		if (FCK.EditMode == FCK_EDITMODE_WYSIWYG ||
+			aItems[i].SourceView)
+			aItems[i].RefreshState() ;
+	}
+}
Index: /FCKeditor/branches/developers/mjk/editor/dialog/fck_anchor.html
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/dialog/fck_anchor.html	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/dialog/fck_anchor.html	(revision 244)
@@ -65,6 +65,9 @@
 	if ( oAnchor )
 		GetE('txtName').value = oAnchor.name ;
-	else
-		oAnchor = null ;
+	else if (FCK.Selection.GetType() == 'Text')
+    	//for text anchors, use the selected text as default anchor name
+        if (FCK.Selection.SelectedText())
+            GetE('txtName').value = FCK.Selection.SelectedText();
+
 
 	window.parent.SetOkButton( true ) ;
Index: /FCKeditor/branches/developers/mjk/editor/dialog/fck_find.html
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/dialog/fck_find.html	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/dialog/fck_find.html	(revision 244)
@@ -24,21 +24,43 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
-	<title></title>
+	<title>Find and Replace</title>
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 	<meta content="noindex, nofollow" name="robots" />
+    <script src="common/fck_dialog_common.js" type="text/javascript"></script>
+    <link href="common/fck_dialog_common.css" rel="stylesheet" type="text/css" />
 	<script type="text/javascript">
 
 var oEditor = window.parent.InnerDialogLoaded() ;
+var FCK			= oEditor.FCK ;
+var FCKLang		= oEditor.FCKLang ;
+var FCKConfig	= oEditor.FCKConfig ;
+var strFind     = '';
+var bFirstFind  = true;
+
+window.parent.AddTab( 'Find', FCKLang.DlgFindTitle) ;
+window.parent.AddTab( 'Replace', FCKLang.DlgReplaceTitle) ;
+
+//show the tabs and hide the buttons -- because we draw buttons on the tabs
+parent.document.getElementById("TabsRow").style.display = "";
+parent.document.getElementById("Buttons").style.display = "none";
+
+// Function called when a dialog tag is selected.
+function OnDialogTabChange( tabCode )
+{
+	document.getElementById('replace').style.display = (tabCode == 'Find') ? 'none' : '';
+    document.getElementById('replaceButtons').style.display = (tabCode == 'Find') ? 'none' : '';
+    //fixme: allow hide/show of regex based on user privs
+    document.getElementById('regex').style.display = (tabCode == 'Replace') ? '' : 'none';
+    
+}
 
 function OnLoad()
 {
-	// Whole word is available on IE only.
-	if ( oEditor.FCKBrowserInfo.IsIE )
-		document.getElementById('divWord').style.display = '' ;
-
 	// First of all, translate the dialog box texts.
 	oEditor.FCKLanguageManager.TranslatePage( document ) ;
 
 	window.parent.SetAutoSize( true ) ;
+    if ( document.location.search.substr(1) == 'rep')
+        window.parent.SetSelectedTab('Replace');
 }
 
@@ -48,57 +70,65 @@
 		( document.getElementById('txtFind').value.length == 0 ) ;
 }
-
-function ReplaceTextNodes( parentNode, regex, replaceValue, replaceAll )
-{
-	for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
-	{
-		var oNode = parentNode.childNodes[i] ;
-		if ( oNode.nodeType == 3 )
-		{
-			var sReplaced = oNode.nodeValue.replace( regex, replaceValue ) ;
-			if ( oNode.nodeValue != sReplaced )
-			{
-				oNode.nodeValue = sReplaced ;
-				if ( ! replaceAll )
-					return true ;
-			}
-		}
-		else
-		{
-			if ( ReplaceTextNodes( oNode, regex, replaceValue ) )
-				return true ;
-		}
-	}
-	return false ;
-}
-
-function GetRegexExpr()
-{
-	var sExpr ;
-
-	if ( document.getElementById('chkWord').checked )
-		sExpr = '\\b' + document.getElementById('txtFind').value + '\\b' ;
-	else
-		sExpr = document.getElementById('txtFind').value ;
-
-	return sExpr ;
-}
-
-function GetCase()
-{
-	return ( document.getElementById('chkCase').checked ? '' : 'i' ) ;
-}
-
-function Ok()
-{
-	if ( document.getElementById('txtFind').value.length == 0 )
-		return ;
-
-	if ( oEditor.FCKBrowserInfo.IsIE )
-		FindIE() ;
-	else
-		FindGecko() ;
-}
-
+function Find(bDB)
+{
+    //start finding at the top -- IE does this automagically
+    if (bFirstFind)
+    {
+        FCK.Selection.SelectNode(oEditor.FCK.EditorDocument.body);
+        FCK.Selection.Collapse();
+    }
+    if ( document.getElementById('txtFind').value.length == 0 )
+        return false;
+    var bOut;
+    if ( oEditor.FCKBrowserInfo.IsIE )
+        bOut = FindIE(document.getElementById('txtFind').value,
+                document.getElementById('chkCase').checked,
+                document.getElementById('chkWord').checked) ;
+    else
+        bOut = FindGecko(document.getElementById('txtFind').value,
+                document.getElementById('chkCase').checked,
+                document.getElementById('chkWord').checked) ;
+    if (!bOut && bDB) alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ;
+    bFirstFind = false;
+    return bOut;
+}
+
+function Replace()          //replace -- or if nothing selected, Find Next
+{
+    if (document.getElementById('chkRegex').checked)
+        return ReplaceAllRegex();
+    
+    if (FCK.Selection.SelectedHTML())
+        FCK.InsertHtml(filterReplaceText());
+    Find(true);
+}
+
+function ReplaceAll()
+{
+    if (document.getElementById('chkRegex').checked)
+        return ReplaceAllRegex();
+    while (Find(false) && FCK.Selection.SelectedHTML())
+    {
+      FCK.InsertHtml(filterReplaceText());
+    }
+}
+
+function ReplaceAllRegex()
+{
+    var strXHTML = FCK.GetXHTML(false);
+    strXHTML = strXHTML.replace(new RegExp(document.getElementById('txtFind').value,
+                                document.getElementById('chkCase').checked ? 'g' : 'gi'),
+                        document.getElementById('txtReplace').value);
+    FCK.SetHTML(strXHTML);
+}
+
+function filterReplaceText()
+{
+    var sHtml = document.getElementById('txtReplace').value;
+   	sHtml = sHtml.replace(/&/ig,'&amp;');
+	sHtml = sHtml.replace(/</ig,'&lt;');
+	sHtml = sHtml.replace(/>/ig,'&gt;');
+    return sHtml    
+}
 var oRange ;
 
@@ -106,31 +136,30 @@
 	oRange = oEditor.FCK.EditorDocument.body.createTextRange() ;
 
-function FindIE()
+function FindIE(strText, bCase, bWord)
 {
 	var iFlags = 0 ;
 
-	if ( chkCase.checked )
+	if (bCase)
 		iFlags = iFlags | 4 ;
 
-	if ( chkWord.checked )
+	if (bWord)
 		iFlags = iFlags | 2 ;
-
-	var bFound = oRange.findText( document.getElementById('txtFind').value, 1, iFlags ) ;
-
-	if ( bFound )
-	{
+	var bFound = oRange.findText(strText, 1, iFlags ) ;
+
+	if ( bFound )	{
 		oRange.scrollIntoView() ;
 		oRange.select() ;
 		oRange.collapse(false) ;
 		oLastRangeFound = oRange ;
+        return true;
 	}
 	else
 	{
 		oRange = oEditor.FCK.EditorDocument.body.createTextRange() ;
-		alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ;
 	}
-}
-
-function FindGecko()
+    return false;
+}
+
+function FindGecko(strText, bCase, bWord)
 {
 	var bCase = document.getElementById('chkCase').checked ;
@@ -138,11 +167,19 @@
 
 	// window.find( searchString, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog ) ;
-	if ( !oEditor.FCK.EditorWindow.find( document.getElementById('txtFind').value, bCase, false, false, bWord, false, false ) )
-		alert( oEditor.FCKLang.DlgFindNotFoundMsg ) ;
-}
-	</script>
+	var bFound = oEditor.FCK.EditorWindow.find( document.getElementById('txtFind').value, bCase, false, false, bWord, false, false );
+	
+    return (bFound);
+}
+
+function toggleRegex()
+{
+    bRegex = document.getElementById('chkRegex').checked ;
+    document.getElementById('btnReplace').disabled = bRegex;
+    document.getElementById('btnFind').disabled = bRegex;
+}
+    </script>
 </head>
 <body onload="OnLoad()" style="overflow: hidden">
-	<table cellspacing="3" cellpadding="2" width="100%" border="0">
+	<table cellspacing="3" cellpadding="2" width="100%" border="0" height="130">
 		<tr>
 			<td nowrap="nowrap">
@@ -151,23 +188,43 @@
 			</td>
 			<td width="100%">
-				<input id="txtFind" style="width: 100%" tabindex="1" type="text" />
-			</td>
-			<td>
-				<input id="btnFind" style="padding-right: 5px; padding-left: 5px" onclick="Ok();"
-					type="button" value="Find" fcklang="DlgFindFindBtn" />
+				<input id="txtFind" style="width: 100%" tabindex="1" type="text"
+                       onkeyup = "document.getElementById('btnFind').disabled = ( document.getElementById('txtFind').value.length == 0 || document.getElementById('chkRegex').checked );" />
+			</td>
+		</tr>
+		<tr id="replace" style="display:none">
+			<td valign="top" nowrap="nowrap">
+				<label for="txtReplace" fcklang="DlgReplaceReplaceLbl">
+					Replace with:</label>
+			</td>
+			<td valign="top">
+				<input id="txtReplace" style="width: 100%" tabindex="2" type="text" />
 			</td>
 		</tr>
 		<tr>
-			<td valign="bottom" colspan="3">
-				&nbsp;<input id="chkCase" tabindex="3" type="checkbox" /><label for="chkCase" fcklang="DlgReplaceCaseChk">Match
-					case</label>
-				<br />
-				<div id="divWord" style="display: none">
-					&nbsp;<input id="chkWord" tabindex="4" type="checkbox" /><label for="chkWord" fcklang="DlgReplaceWordChk">Match
-						whole word</label>
-				</div>
+			<td valign="middle" colspan="2">
+                <table border="0">
+                    <tr>
+                        <td>
+                        &nbsp;<input id="chkCase" tabindex="3" type="checkbox" /><label for="chkCase" fcklang="DlgReplaceCaseChk">Match
+                            case</label>
+                        <br />
+                        &nbsp;<input id="chkWord" tabindex="4" type="checkbox" /><label for="chkWord" fcklang="DlgReplaceWordChk">Match
+                                whole word</label>
+                        </td>
+                        <td id="regex" valign="top" style="display:none">
+                            <input id="chkRegex" tabindex="5" type="checkbox" onclick="toggleRegex()"/><label for="chkRegex">Regex</label>
+                        </td>
+                    </tr>
+                </table>
 			</td>
 		</tr>
 	</table>
+    <div style="text-align: right; margin-right: 5px">
+        <span id="replaceButtons" style="display:none">
+        <input type="button" id="btnReplaceAll" class="button" value="Replace All" onclick="ReplaceAll()"  fcklang="DlgReplaceReplaceAllBtn" />
+        <input type="button" id="btnReplace" class="button" value="Replace" onclick="Replace()"  fcklang="DlgReplaceReplaceBtn" /></span>
+        <input type="button" id="btnFind" class="button" value="Find Next" onclick="Find()"  disabled="disabled" />
+        <input type="button" id="btnCancel" class="button" value="Close" onclick="top.Cancel()" />
+    </div>
 </body>
 </html>
Index: /FCKeditor/branches/developers/mjk/editor/dialog/fck_table.html
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/dialog/fck_table.html	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/dialog/fck_table.html	(revision 244)
@@ -66,5 +66,5 @@
 			document.getElementById('selWidthType').value = "percent" ;
 		}
-		else if (iWidth.indexOf('px') >= 0)		// Style Pixel = px
+		else									// Style Pixel = px, or width=nn
 		{																										  //
 			iWidth = iWidth.substr(0,iWidth.length - 2);
@@ -89,7 +89,6 @@
 		document.getElementById('txtColumns').disabled = true ;
 	}
-
-	window.parent.SetOkButton( true ) ;
-	window.parent.SetAutoSize( true ) ;
+	window.parent.SetOkButton( true ) ;	
+	window.parent.SetAutoSize( true ) ;	
 }
 
Index: /FCKeditor/branches/developers/mjk/editor/fckdialog.html
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/fckdialog.html	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/fckdialog.html	(revision 244)
@@ -132,6 +132,6 @@
 	SetSelectedTab( this.TabCode ) ;
 }
-
-function AddTab( tabCode, tabText, startHidden )
+                  
+function AddTab( tabCode, tabText, startHidden, bNoTabRow )
 {
 	if ( typeof( oTabs[ tabCode ] ) != 'undefined' )
@@ -162,5 +162,5 @@
 
 		oDiv.className = 'PopupTabSelected' ;
-		eTabsRow.style.display = '' ;
+		if (!bNoTabRow) eTabsRow.style.display = '' ;
 
 		if ( ! window.dialogArguments.Editor.FCKBrowserInfo.IsIE )
@@ -183,4 +183,13 @@
 	if ( typeof( window.frames["frmMain"].OnDialogTabChange ) == 'function' )
 		window.frames["frmMain"].OnDialogTabChange( tabCode ) ;
+}
+
+function GetSelectedTab()
+{
+	for ( var sCode in oTabs )
+	{
+		if (oTabs[sCode].className == 'PopupTabSelected')
+			return sCode;
+	}
 }
 
@@ -210,5 +219,31 @@
 		switch ( e.keyCode )
 		{
-			case 13 :		// ENTER
+            case 76 :       // Ctrl+Alt+L: become lowercase
+                if (e.altKey && e.ctrlKey)
+                {
+                    var oTarget = e.srcElement || e.target ;
+                    if (oTarget.value) oTarget.value = oTarget.value.toLowerCase();
+                    return false;
+                }
+                break;
+            case 82 :       // Ctrl+Alt+R: become Propercase
+                if (e.altKey && e.ctrlKey)
+                {
+                    var oTarget = e.srcElement || e.target ;
+                    if (oTarget.value) oTarget.value = oTarget.value.toLowerCase().replace(/(\S)(\S*\s*)/g,
+						function(str,p1,p2) {return p1.toUpperCase()+p2});
+                    return false;
+                }
+                break;
+            case 85 :       // Ctrl+Alt+U: become UPPERCASE
+                if (e.altKey && e.ctrlKey)
+                {
+                    var oTarget = e.srcElement || e.target ;
+                    if (oTarget.value) oTarget.value = oTarget.value.toUpperCase();
+                    return false;
+                }
+                break;
+                    
+        	case 13 :		// ENTER
 				var oTarget = e.srcElement || e.target ;
 				if ( oTarget.tagName == 'TEXTAREA' )
@@ -306,11 +341,11 @@
 				</td>
 			</tr>
-			<tr>
+			<tr id="Buttons">
 				<td class="PopupButtons">
-					<table border="0" cellpadding="0" cellspacing="0">
+					<table border="0" cellpadding="0" cellspacing="0" width="100%">
 						<tr>
-							<td width="100%">&nbsp;</td>
-							<td nowrap="nowrap">
-								<input id="btnOk" style="VISIBILITY: hidden;" type="button" value="Ok" class="Button" onclick="Ok();" fckLang="DlgBtnOK" />
+							<td nowrap="nowrap" align="right" width="100%">
+								<span id="runtimeButtons"></span>
+                                <input id="btnOk" style="VISIBILITY: hidden;" type="button" value="Ok" class="Button" onclick="Ok();" fckLang="DlgBtnOK" />
 								&nbsp; 
 								<input id="btnCancel" type="button" value="Cancel" class="Button" onclick="Cancel();" fckLang="DlgBtnCancel" />
Index: /FCKeditor/branches/developers/mjk/editor/lang/en.js
===================================================================
--- /FCKeditor/branches/developers/mjk/editor/lang/en.js	(revision 243)
+++ /FCKeditor/branches/developers/mjk/editor/lang/en.js	(revision 244)
@@ -124,4 +124,5 @@
 FlashProperties		: "Flash Properties",
 
+AnchorDelete		: "Remove Anchor",
 AnchorProp			: "Anchor Properties",
 ButtonProp			: "Button Properties",
