Index: /FCKeditor/branches/features/div_container/editor/_source/internals/fckdomtools.js
===================================================================
--- /FCKeditor/branches/features/div_container/editor/_source/internals/fckdomtools.js	(revision 2186)
+++ /FCKeditor/branches/features/div_container/editor/_source/internals/fckdomtools.js	(revision 2187)
@@ -697,5 +697,5 @@
 	SetElementMarker : function ( markerObj, element, attrName, value)
 	{
-		var id = String( parseInt( Math.random() * 0xfffffff, 10 ) ) ;
+		var id = String( parseInt( Math.random() * 0xffffffff, 10 ) ) ;
 		element._FCKMarkerId = id ;
 		element[attrName] = value ;
Index: /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html
===================================================================
--- /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html	(revision 2186)
+++ /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html	(revision 2187)
@@ -193,69 +193,26 @@
 	var block ;
 
-	if ( true )
-	{
-		iterator.EnforceRealBlocks = true ;
-		var paragraphs = [] ;
-		while ( ( block = iterator.GetNextParagraph() ) )
-			paragraphs.push( block ) ;
-
-		// If no paragraphs, create one from the current selection position.
-		if ( paragraphs.length < 1 )
+	iterator.EnforceRealBlocks = true ;
+	var paragraphs = [] ;
+	var groups = [] ;
+	var lastBlockLimit = null ;
+	while ( ( block = iterator.GetNextParagraph() ) )
+	{
+		var elementPath = new FCKElementPath( block ) ;
+		if ( elementPath.BlockLimit != lastBlockLimit )
 		{
-			para = range.Window.document.createElement( FCKConfig.EnterMode.IEquals( 'p' ) ? 'p' : 'div' ) ;
-			range.InsertNode( para ) ;
-			para.appendChild( range.Window.document.createTextNode( '\ufeff' ) ) ;
-			range.MoveToBookmark( bookmark ) ;
-			range.MoveToNodeContents( para ) ;
-			range.Collapse( true ) ;
-			bookmark = range.CreateBookmark() ;
-			paragraphs.push( para ) ;
+			groups.push( [] ) ;
+			lastBlockLimit = elementPath.BlockLimit ;
 		}
-
-		// Make sure all paragraphs have the same parent.
-		var commonParent = paragraphs[0].parentNode ;
-		var tmp = [] ;
-		for ( var i = 0 ; i < paragraphs.length ; i++ )
-		{
-			block = paragraphs[i] ;
-			commonParent = FCKDomTools.GetCommonParents( block.parentNode, commonParent ).pop() ;
-		}
-		var lastBlock = null ;
-		while ( paragraphs.length > 0 )
-		{
-			block = paragraphs.shift() ;
-			while ( block.parentNode != commonParent )
-				block = block.parentNode ;
-			if ( block != lastBlock )
-				tmp.push( block ) ;
-			lastBlock = block ;
-		}
-
-		// If any of the selected blocks is a $tagName, remove it to prevent nested $tagNames.
-		while ( tmp.length > 0 )
-		{
-			block = tmp.shift() ;
-			if ( block.nodeName.IEquals( 'div' ) )
-			{
-				var docFrag = oEditor.FCKTools.GetElementDocument( block ).createDocumentFragment() ;
-				while ( block.firstChild )
-				{
-					docFrag.appendChild( block.removeChild( block.firstChild ) ) ;
-					paragraphs.push( docFrag.lastChild ) ;
-				}
-				block.parentNode.replaceChild( docFrag, block ) ;
-			}
-			else
-				paragraphs.push( block ) ;
-		}
-
-		// Now we have all the blocks to be included in a new $tagName node.
-		bqBlock = range.Window.document.createElement( 'div' ) ;
-		commonParent.insertBefore( bqBlock, paragraphs[0] ) ;
-		while ( paragraphs.length > 0 )
-		{
-			block = paragraphs.shift() ;
-			bqBlock.appendChild( block ) ;
-		}
+		groups[groups.length - 1].push( block ) ;
+	}
+
+	for ( var i = 0 ; i < groups.length ; i++ )
+	{
+		var divNode = FCK.EditorDocument.createElement( 'div' ) ;
+		groups[i][0].parentNode.insertBefore( divNode, groups[i][0] ) ;
+		for ( var j = 0 ; j < groups[i].length ; j++ )
+			FCKDomTools.MoveNode( groups[i][j], divNode ) ;
+		bqBlock = divNode ;
 	}
 
