Index: FCKeditor/trunk/editor/fckdialog.html
===================================================================
--- FCKeditor/trunk/editor/fckdialog.html	(revision 1188)
+++ FCKeditor/trunk/editor/fckdialog.html	(revision 1192)
@@ -28,20 +28,50 @@
 		<script type="text/javascript">
 
+var args = window.dialogArguments ;
+
+// Automatically detect the correct document.domain (#123).
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var parentDomain = window.opener ? window.opener.document.domain : args.Editor.document.domain ;
+			
+			if ( document.domain != parentDomain )
+				document.domain = parentDomain ;
+			break ;
+		}
+		catch( e ) {}
+		
+		// Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...
+		d = d.replace( /.*?(?:\.|$)/, '' ) ;
+
+		if ( d.length == 0 )
+			break ;		// It was not able to detect the domain.
+		
+		document.domain = d ;
+	}
+})() ; 
+
 // On some Gecko browsers (probably over slow connections) the
 // "dialogArguments" are not set so we must get it from the opener window.
-if ( !window.dialogArguments )
-	window.dialogArguments = window.opener.FCKLastDialogInfo ;
+if ( !args )
+	args = window.dialogArguments = window.opener.FCKLastDialogInfo ;
 
 // Sets the Skin CSS
-document.write( '<link href="' + window.dialogArguments.Editor.FCKConfig.SkinPath + 'fck_dialog.css" type="text/css" rel="stylesheet">' ) ;
+document.write( '<link href="' + args.Editor.FCKConfig.SkinPath + 'fck_dialog.css" type="text/css" rel="stylesheet">' ) ;
 
 // Sets the language direction.
-window.document.dir = window.dialogArguments.Editor.FCKLang.Dir ;
+window.document.dir = args.Editor.FCKLang.Dir ;
 
 // IE does not set the window name in showModalDialog(), let's set it here.
-if ( window.dialogArguments.Editor.FCKBrowserInfo.IsIE )
-	window.name = window.dialogArguments.DialogName ;
-
-var sTitle = window.dialogArguments.Title ;
+if ( args.Editor.FCKBrowserInfo.IsIE )
+	window.name = args.DialogName ;
+
+var sTitle = args.Title ;
 document.write( '<title>' + sTitle + '<\/title>' ) ;
 
@@ -52,7 +82,7 @@
 
 	// First of all, translate the dialog box contents.
-	window.dialogArguments.Editor.FCKLanguageManager.TranslatePage( document ) ;
-
-	window.frames["frmMain"].document.location.href = window.dialogArguments.Page ;
+	args.Editor.FCKLanguageManager.TranslatePage( document ) ;
+
+	document.getElementById( 'FrameCell' ).innerHTML = '<iframe id="frmMain" src="' + args.Page + '" name="frmMain" frameborder="0" height="100%" width="100%" scrolling="auto"></iframe>' ;
 }
 
@@ -62,13 +92,13 @@
 
 	// Set the language direction.
-	oInnerDoc.dir = window.dialogArguments.Editor.FCKLang.Dir ;
+	oInnerDoc.dir = args.Editor.FCKLang.Dir ;
 
 	// Sets the Skin CSS.
-	oInnerDoc.write( '<link href="' + window.dialogArguments.Editor.FCKConfig.SkinPath + 'fck_dialog.css" type="text/css" rel="stylesheet">' ) ;
+	oInnerDoc.write( '<link href="' + args.Editor.FCKConfig.SkinPath + 'fck_dialog.css" type="text/css" rel="stylesheet">' ) ;
 
 	SetOnKeyDown( oInnerDoc ) ;
 	DisableContextMenu( oInnerDoc ) ;
 
-	return window.dialogArguments.Editor ;
+	return args.Editor ;
 }
 
@@ -114,5 +144,5 @@
 // Kludge for #1316: Safari seems to have a bug with the time when RefreshSize() is executed - it thinks frmMain's innerHeight 
 // is 0 if we query the value too soon after the page is loaded in some circumstances.
-if ( window.dialogArguments.Editor.FCKBrowserInfo.IsSafari )
+if ( args.Editor.FCKBrowserInfo.IsSafari )
 {
 	window.OriginalRefreshSize = RefreshSize ;
@@ -132,9 +162,9 @@
 function Cancel( dontFireChange )
 {
-	if ( !dontFireChange && !window.dialogArguments.Editor.FCK.EditMode )
+	if ( !dontFireChange && !args.Editor.FCK.EditMode )
 	{
 		// All dialog windows, by default, will fire the "OnSelectionChange"
 		// event, no matter the Ok or Cancel button has been pressed.
-		window.dialogArguments.Editor.FCK.Events.FireEvent( 'OnSelectionChange' ) ;
+		args.Editor.FCK.Events.FireEvent( 'OnSelectionChange' ) ;
 	}
 	window.close() ;
@@ -244,5 +274,5 @@
 function DisableContextMenu( targetDocument )
 {
-	if ( window.dialogArguments.Editor.FCKBrowserInfo.IsIE ) return ;
+	if ( args.Editor.FCKBrowserInfo.IsIE ) return ;
 
 	// Disable Right-Click
@@ -257,5 +287,5 @@
 DisableContextMenu( document ) ;
 
-if ( window.dialogArguments.Editor.FCKBrowserInfo.IsGecko && !window.dialogArguments.Editor.FCKBrowserInfo.IsOpera )
+if ( args.Editor.FCKBrowserInfo.IsGecko && !args.Editor.FCKBrowserInfo.IsOpera )
 {
 	window.onresize = function( e )
@@ -280,5 +310,5 @@
 }
 
-if ( window.dialogArguments.Editor.FCKBrowserInfo.IsIE )
+if ( args.Editor.FCKBrowserInfo.IsIE )
 {
 	function Window_OnBeforeUnload()
@@ -287,5 +317,5 @@
 			oTabs[t] = null ;
 
-		window.dialogArguments.Editor = null ;
+		args.Editor = null ;
 	}
 	window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;
@@ -294,5 +324,5 @@
 function Window_OnClose()
 {
-	window.dialogArguments.Editor.FCKFocusManager.Unlock() ;
+	args.Editor.FCKFocusManager.Unlock() ;
 }
 
@@ -323,6 +353,5 @@
 			<tr>
 				<td id="FrameCell" height="100%" valign="top">
-					<iframe id="frmMain" src="javascript:void(0)" name="frmMain" frameborder="0" height="100%" width="100%" scrolling="auto">
-					</iframe>
+					&nbsp;
 				</td>
 			</tr>
