Index: /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html
===================================================================
--- /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html	(revision 2196)
+++ /FCKeditor/branches/features/div_container/editor/dialog/fck_div.html	(revision 2197)
@@ -59,11 +59,34 @@
 }
 
-var ActiveEl = null ;
+var CurrentContainers = [] ;
 if ( !AlwaysCreate )
 {
-	var oSelection = dialog.Selection.GetSelection() ;
-	ActiveEl = ( new FCKElementPath( oSelection.GetSelectedElement() || oSelection.GetParentElement() ) ).BlockLimit ;
-	if ( ActiveEl && ActiveEl.nodeName.toLowerCase() != 'div' )
-		ActiveEl = null ;
+	dialog.Selection.EnsureSelection() ;
+	var range = new FCKDomRange( FCK.EditorWindow ) ;
+	range.MoveToSelection() ;
+
+	var startNode = range.StartNode ;
+	var endNode = range.EndNode ;
+	var currentNode = startNode ;
+	var elementMarkers = {} ;
+
+	do
+	{
+		if ( currentNode.nodeName.IEquals( 'div' ) && currentNode.firstChild &&
+				oEditor.FCKListsLib.BlockElements[ currentNode.firstChild.nodeName.toLowerCase() ] )
+		{
+			CurrentContainers.push( currentNode ) ;
+			if ( currentNode.parentNode.nodeName.IEquals( 'div' ) )
+				FCKDomTools.SetElementMarker( elementMarkers, currentNode, '_fckignorethisnode', true ) ;
+		}
+	}
+	while ( ( currentNode = FCKDomTools.GetNextSourceElement( currentNode ) ) && currentNode != endNode
+			&& currentNode != endNode.parentNode ) ;
+
+	for ( var i = CurrentContainers.length - 1 ; i >= 0 ; i-- )
+	{
+		if ( CurrentContainers[i]['_fckignorethisnode'] )
+			CurrentContainers.splice( i, 1 ) ;
+	}
 }
 
@@ -114,29 +137,37 @@
 	var match = null ;
 	var selectableStyles = {} ;
-	for ( var i in styles )
-	{
-		if ( ! /^_FCK_/.test( i ) && styles[i].Element == 'div' )
-		{
-			if ( ActiveEl && styles[i].CheckElementRemovable( ActiveEl, true ) )
-				match = i ;
-			selectableStyles[i] = styles[i] ;
-		}
-	}
-	if ( !match )
-		AddStyleOption( "" ) ;
-	for ( var i in selectableStyles )
-		AddStyleOption( i ) ;
-	if ( match )
-		GetE( 'selStyle' ).value = match ;
-
-	// Set the value for other inputs
-	if ( ActiveEl )
-	{
-		GetE( 'txtClass' ).value = ActiveEl.className ;
-		GetE( 'txtId' ).value = ActiveEl.id ;
-		GetE( 'txtLang' ).value = ActiveEl.lang ;
-		GetE( 'txtInlineStyle').value = ActiveEl.getAttribute( 'style' ) ;
-		GetE( 'txtTitle' ).value = ActiveEl.title ;
-		GetE( 'selLangDir').value = ActiveEl.dir || GetNearestAncestorDirection( ActiveEl ) ;
+	if ( CurrentContainers.length <= 1 )
+	{
+		var target = CurrentContainers[0] ;
+		for ( var i in styles )
+		{
+			if ( ! /^_FCK_/.test( i ) && styles[i].Element == 'div' )
+			{
+				if ( target && styles[i].CheckElementRemovable( target, true ) )
+					match = i ;
+				selectableStyles[i] = styles[i] ;
+			}
+		}
+		if ( !match )
+			AddStyleOption( "" ) ;
+		for ( var i in selectableStyles )
+			AddStyleOption( i ) ;
+		if ( match )
+			GetE( 'selStyle' ).value = match ;
+
+		// Set the value for other inputs
+		if ( target )
+		{
+			GetE( 'txtClass' ).value = target.className ;
+			GetE( 'txtId' ).value = target.id ;
+			GetE( 'txtLang' ).value = target.lang ;
+			GetE( 'txtInlineStyle').value = target.getAttribute( 'style' ) ;
+			GetE( 'txtTitle' ).value = target.title ;
+			GetE( 'selLangDir').value = target.dir || GetNearestAncestorDirection( target ) ;
+		}
+	}
+	else
+	{
+		GetE( 'txtId' ).disabled = GetE( 'selStyle' ).disabled = true  ;
 	}
 }
@@ -144,5 +175,5 @@
 function CreateDiv()
 {
-	var bqBlock ;
+	var newBlocks = [] ;
 	var range = new FCKDomRange( FCK.EditorWindow ) ;
 	range.MoveToSelection() ;
@@ -214,5 +245,5 @@
 		for ( var j = 0 ; j < groups[i].length ; j++ )
 			FCKDomTools.MoveNode( groups[i][j], divNode ) ;
-		bqBlock = divNode ;
+		newBlocks.push( divNode ) ;
 	}
 
@@ -223,5 +254,5 @@
 	FCK.Events.FireEvent( 'OnSelectionChange' ) ;
 
-	return bqBlock ;
+	return newBlocks ;
 }
 
@@ -230,34 +261,46 @@
 	oEditor.FCKUndo.SaveUndoStep() ;
 
-	if ( !ActiveEl )
-		ActiveEl = CreateDiv();
+	if ( CurrentContainers.length < 1 )
+		CurrentContainers = CreateDiv();
 
 	var setValue = function( attrName, inputName )
 	{
 		var val = GetE( inputName ).value ;
-		if ( val == '' )
-			ActiveEl.removeAttribute( attrName ) ;
-		else
-			ActiveEl.setAttribute( attrName, val ) ;
+		for ( var i = 0 ; i < CurrentContainers.length ; i++ )
+		{
+			if ( val == '' )
+				CurrentContainers[i].removeAttribute( attrName ) ;
+			else
+				CurrentContainers[i].setAttribute( attrName, val ) ;
+		}
 	}
 
 	// Apply modifications to the DIV container according to dialog inputs.
-	setValue( 'class', 'txtClass' ) ;
-	setValue( 'id', 'txtId' ) ;
+	if ( CurrentContainers.length == 1 )
+	{
+		setValue( 'class', 'txtClass' ) ;
+		setValue( 'id', 'txtId' ) ;
+	}
 	setValue( 'lang', 'txtLang' ) ;
 	if ( FCKBrowserInfo.IsIE )
-		ActiveEl.style.cssText = GetE( 'txtInlineStyle' ).value ;
+	{
+		for ( var i = 0 ; i < CurrentContainers.length ; i++ )
+			CurrentContainers[i].style.cssText = GetE( 'txtInlineStyle' ).value ;
+	}
 	else
 		setValue( 'style', 'txtInlineStyle' ) ;
 	setValue( 'title', 'txtTitle' ) ;
-	var dir = GetE( 'selLangDir' ).value ;
-	if ( GetNearestAncestorDirection( ActiveEl ) != dir )
-		ActiveEl.dir = dir ;
-	else
-		ActiveEl.removeAttribute( 'dir' ) ;
-
-	var styleName = GetE( 'selStyle' ).value ;
-	if ( styleName )
-		FCKStyles.GetStyle( styleName ).ApplyToObject( ActiveEl ) ;
+	for ( var i = 0 ; i < CurrentContainers.length ; i++ )
+	{
+		var dir = GetE( 'selLangDir' ).value ;
+		var styleName = GetE( 'selStyle' ).value ;
+		if ( GetNearestAncestorDirection( CurrentContainers[i] ) != dir )
+			CurrentContainers[i].dir = dir ;
+		else
+			CurrentContainers[i].removeAttribute( 'dir' ) ;
+		
+		if ( styleName )
+			FCKStyles.GetStyle( styleName ).ApplyToObject( CurrentContainers[i] ) ;
+	}
 
 	return true ;
