Index: FCKeditor/trunk/editor/filemanager/browser/default/browser.html
===================================================================
--- FCKeditor/trunk/editor/filemanager/browser/default/browser.html	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/browser/default/browser.html	(revision 1791)
@@ -29,4 +29,35 @@
 		<script type="text/javascript" src="js/fckxml.js"></script>
 		<script language="javascript">
+// Automatically detect the correct document.domain (#1919).
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
 
 function GetUrlParam( paramName )
Index: FCKeditor/trunk/editor/filemanager/browser/default/frmactualfolder.html
===================================================================
--- FCKeditor/trunk/editor/filemanager/browser/default/frmactualfolder.html	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/browser/default/frmactualfolder.html	(revision 1791)
@@ -27,4 +27,35 @@
 		<link href="browser.css" type="text/css" rel="stylesheet">
 		<script type="text/javascript">
+// Automatically detect the correct document.domain (#1919).
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
 
 function OnResize()
Index: FCKeditor/trunk/editor/filemanager/browser/default/js/common.js
===================================================================
--- FCKeditor/trunk/editor/filemanager/browser/default/js/common.js	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/browser/default/js/common.js	(revision 1791)
@@ -22,4 +22,36 @@
  * File Browser dialog window.
  */
+
+// Automatically detect the correct document.domain (#1919).
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
 
 function AddSelectOption( selectElement, optionText, optionValue )
Index: FCKeditor/trunk/editor/filemanager/connectors/asp/io.asp
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/asp/io.asp	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/asp/io.asp	(revision 1791)
@@ -215,4 +215,36 @@
 	Response.Clear
 	Response.Write "<script type=""text/javascript"">"
+	Response.Write "(function()"
+	Response.Write "{"
+	Response.Write "var d = document.domain ;"
+
+	Response.Write " while ( true )"
+	Response.Write "	{"
+	' Test if we can access a parent property.
+	Response.Write "		try"
+	Response.Write "		{"
+	Response.Write "			var test = window.top.opener.document.domain ;"
+	Response.Write "			break ;"
+	Response.Write "		}"
+	Response.Write "		catch( e ) {}"
+
+	' Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...
+	Response.Write "		d = d.replace( /.*?(?:\.|$)/, '' ) ;"
+
+	Response.Write "		if ( d.length == 0 )"
+	' It was not able to detect the domain.
+	Response.Write "			break ;"
+	Response.Write ""
+	Response.Write "		try"
+	Response.Write "		{"
+	Response.Write "			document.domain = d ;"
+	Response.Write "		}"
+	Response.Write "		catch (e)"
+	Response.Write "		{"
+	Response.Write "			break ;"
+	Response.Write "		}"
+	Response.Write "	}"
+	Response.Write "})() ;"
+
 	Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "\""" ) & """,""" & Replace( fileName, """", "\""" ) & """,""" & Replace( customMsg , """", "\""" ) & """) ;"
 	Response.Write "</script>"
Index: FCKeditor/trunk/editor/filemanager/connectors/cfm/cf5_upload.cfm
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/cfm/cf5_upload.cfm	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/cfm/cf5_upload.cfm	(revision 1791)
@@ -48,4 +48,36 @@
 	{
 		WriteOutput('<script type="text/javascript">');
+		WriteOutput("(function()"&
+"{"&
+"	var d = document.domain ;"&
+""&
+"	while ( true )"&
+"	{"&
+		// Test if we can access a parent property.
+"		try"&
+"		{"&
+"			var test = window.top.opener.document.domain ;"&
+"			break ;"&
+"		}"&
+"		catch( e ) {}"&
+""&
+		// Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...
+"		d = d.replace( /.*?(?:\.|$)/, '' ) ;"&
+""&
+"		if ( d.length == 0 )"&
+			// It was not able to detect the domain.
+"			break ;"&
+""&
+"		try"&
+"		{"&
+"			document.domain = d ;"&
+"		}"&
+"		catch (e)"&
+"		{"&
+"			break ;"&
+"		}"&
+"	}"&
+"})() ;");
+
 		WriteOutput('window.parent.OnUploadCompleted(' & errorNumber & ', "' & JSStringFormat(fileUrl) & '", "' & JSStringFormat(fileName) & '", "' & JSStringFormat(customMsg) & '");' );
 		WriteOutput('</script>');
Index: FCKeditor/trunk/editor/filemanager/connectors/cfm/cf_io.cfm
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/cfm/cf_io.cfm	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/cfm/cf_io.cfm	(revision 1791)
@@ -267,5 +267,36 @@
 
 	<cfoutput>
-		<script type="text/javascript">
+<script type="text/javascript">
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
+
 			window.parent.OnUploadCompleted( #errorNumber#, "#JSStringFormat(fileUrl)#", "#JSStringFormat(fileName)#", "#JSStringFormat(customMsg)#" );
 		</script>
Index: FCKeditor/trunk/editor/filemanager/connectors/lasso/connector.lasso
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/lasso/connector.lasso	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/lasso/connector.lasso	(revision 1791)
@@ -204,14 +204,45 @@
                 Set the HTML response.
                 */
-                if($uploadResult == '0' || $uploadResult == '201');
-				$__html_reply__ = '\
+                $__html_reply__ = '\
 <script type="text/javascript">
-	window.parent.frames[\'frmUpload\'].OnUploadCompleted(' + $uploadResult + ',\'' + $NewFilePath + '\',\'' + $NewFilePath->split('/')->last + '\');
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
+';
+				if($uploadResult == '0' || $uploadResult == '201');
+				$__html_reply__ = $__html_reply__ + '\
+	window.parent.OnUploadCompleted(' + $uploadResult + ',\'' + $NewFilePath + '\',\'' + $NewFilePath->split('/')->last + '\');
 </script>
 				';
-                else;
-				$__html_reply__ = '\
-<script type="text/javascript">
-	window.parent.frames[\'frmUpload\'].OnUploadCompleted(' + $uploadResult + ');
+				else;
+				$__html_reply__ = $__html_reply__ + '\
+	window.parent.OnUploadCompleted(' + $uploadResult + ');
 </script>
 				';
Index: FCKeditor/trunk/editor/filemanager/connectors/perl/commands.pl
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/perl/commands.pl	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/perl/commands.pl	(revision 1791)
@@ -170,6 +170,41 @@
 	local($sErrorNumber, $sFileUrl, $sFileName, $customMsg) = @_;
 
-	print "Content-type: text/html\n\n";
-	print '<script type="text/javascript">';
+	print <<EOF;
+Content-type: text/html
+
+<script type="text/javascript">
+// Automatically detect the correct document.domain (#1919).
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
+
+EOF
 	print 'window.parent.OnUploadCompleted(' . $sErrorNumber . ',"' . JS_cnv($sFileUrl) . '","' . JS_cnv($sFileName) . '","' . JS_cnv($customMsg) . '") ;';
 	print '</script>';
Index: FCKeditor/trunk/editor/filemanager/connectors/php/io.php
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/php/io.php	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/php/io.php	(revision 1791)
@@ -278,5 +278,38 @@
 function SendUploadResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
 {
-	echo '<script type="text/javascript">' ;
+	echo <<<EOF
+<script type="text/javascript">
+(function()
+{
+	var d = document.domain ;
+
+	while ( true )
+	{
+		// Test if we can access a parent property.
+		try
+		{
+			var test = window.top.opener.document.domain ;
+			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.
+
+		try
+		{
+			document.domain = d ;
+		}
+		catch (e)
+		{
+			break ;
+		}
+	}
+})() ;
+
+EOF;
 	$rpl = array( '\\' => '\\\\', '"' => '\\"' ) ;
 	echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . strtr( $fileUrl, $rpl ) . '","' . strtr( $fileName, $rpl ) . '", "' . strtr( $customMsg, $rpl ) . '") ;' ;
Index: FCKeditor/trunk/editor/filemanager/connectors/py/fckoutput.py
===================================================================
--- FCKeditor/trunk/editor/filemanager/connectors/py/fckoutput.py	(revision 1790)
+++ FCKeditor/trunk/editor/filemanager/connectors/py/fckoutput.py	(revision 1791)
@@ -103,4 +103,35 @@
 		"This is the function that sends the results of the uploading process"
 		return """<script type="text/javascript">
+			(function()
+			{
+				var d = document.domain ;
+
+				while ( true )
+				{
+					// Test if we can access a parent property.
+					try
+					{
+						var test = window.top.opener.document.domain ;
+						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.
+
+					try
+					{
+						document.domain = d ;
+					}
+					catch (e)
+					{
+						break ;
+					}
+				}
+			})() ;
+
 			window.parent.OnUploadCompleted(%(errorNumber)s,"%(fileUrl)s","%(fileName)s","%(customMsg)s");
 			</script>""" % {
