Index: editor/filemanager/browser/default/browser.html
===================================================================
--- editor/filemanager/browser/default/browser.html	(revision 1684)
+++ editor/filemanager/browser/default/browser.html	(working copy)
@@ -27,7 +27,38 @@
 		<link href="browser.css" type="text/css" rel="stylesheet">
 		<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 )
 {
 	var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
Index: editor/filemanager/browser/default/frmactualfolder.html
===================================================================
--- editor/filemanager/browser/default/frmactualfolder.html	(revision 1684)
+++ editor/filemanager/browser/default/frmactualfolder.html	(working copy)
@@ -25,7 +25,38 @@
 	<head>
 		<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()
 {
 	divName.style.width = "1px" ;
Index: editor/filemanager/browser/default/js/common.js
===================================================================
--- editor/filemanager/browser/default/js/common.js	(revision 1684)
+++ editor/filemanager/browser/default/js/common.js	(working copy)
@@ -22,6 +22,38 @@
  * 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 )
 {
 	var oOption = document.createElement("OPTION") ;
Index: editor/filemanager/connectors/perl/commands.pl
===================================================================
--- editor/filemanager/connectors/perl/commands.pl	(revision 1684)
+++ editor/filemanager/connectors/perl/commands.pl	(working copy)
@@ -169,8 +169,43 @@
 
 	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>';
 	exit ;
Index: editor/filemanager/connectors/php/io.php
===================================================================
--- editor/filemanager/connectors/php/io.php	(revision 1684)
+++ editor/filemanager/connectors/php/io.php	(working copy)
@@ -277,7 +277,40 @@
 // This is the function that sends the results of the uploading process.
 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 ) . '") ;' ;
 	echo '</script>' ;
Index: editor/filemanager/connectors/py/fckoutput.py
===================================================================
--- editor/filemanager/connectors/py/fckoutput.py	(revision 1684)
+++ editor/filemanager/connectors/py/fckoutput.py	(working copy)
@@ -102,6 +102,37 @@
 		self.setHttpHeaders("text/html")
 		"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>""" % {
 			'errorNumber': errorNo,
