if (typeof(RadEditorMCMSScriptsOverrideRegistered) == "undefined" )
{
    window["RadEditorMCMSScriptsOverrideRegistered"] = true;

    if (typeof(RadEditorNamespace) != "undefined" ) {
	    RadEditorNamespace.IMAGE_MANAGER_DIALOG_NAME = "MCMSImageManager";
    }

    function RadEditorGetDialogParametersString(editor, commandName)
    {
	    var args = editor.GetDialogParameters(commandName);
	    var argStr = "";
	    for (var item in args)
	    {
		    if (item == "MCMSUpdateMode")
		    {
			    argStr += "&" + args[item];
			    continue;
		    }
		    argStr += "&" + item + "=" + args[item];
	    }
	    return argStr;
    }

    if (typeof(RadEditorCommandList)!="undefined")
    {
    RadEditorCommandList["DocumentManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    var callBackFn = (oTool && "function" == typeof(oTool) ? oTool : RadEditorNamespace.radEditorCreateLink);

		    var argument = RadEditorNamespace.GetSelectionLinkArgument(editor);
		    argument.InternalParameters = editor.GetDialogInternalParameters(commandName);

		    editor.ShowDialog(editor.GetDialogUrl("MCMS" + commandName) + RadEditorGetDialogParametersString(editor, commandName)
			    , argument
			    , 400
			    , 300
			    , callBackFn
			    , null
			    , editor.Localization[commandName]);
		    return false;
	    };

    RadEditorCommandList["MediaManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    editor.SetFocus();
		    var argument = {};
		    argument.InternalParameters = editor.GetDialogInternalParameters(commandName);

		    var selectedMediaObject = editor.GetSelection().GetParentElement()

		    argument.Media = selectedMediaObject;
		    var selectedMediaObjectPath = null;

		    if (selectedMediaObject && selectedMediaObject.tagName)
		    {
			    selectedMediaObjectPath = (selectedMediaObject.tagName.toUpperCase() == "OBJECT") ? getParameterValue(selectedMediaObject,"movie"): selectedMediaObject.src;
		    }
		    argument.MediaPath = selectedMediaObjectPath;

		    var callBackFn = (oTool && "function" == typeof(oTool) ? oTool : RadEditorNamespace.radEditorCreateMedia);

		    var dialogUrl = editor.GetDialogUrl("MCMS" + commandName);
		    if (selectedMediaObjectPath)
		    {
			    dialogUrl += "&selectedObjectPath=" + selectedMediaObjectPath;
		    }
		    editor.ShowDialog(dialogUrl + RadEditorGetDialogParametersString(editor, commandName)
			    , argument
			    , 400
			    , 300
			    , callBackFn
			    , null
			    , editor.Localization[commandName]);
		    return false;
	    };

    RadEditorCommandList["FlashManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    editor.SetFocus();
		    var argument = {};
		    argument.StripAbsoluteImagesPaths = editor.StripAbsoluteImagesPaths;
		    argument.InternalParameters = editor.GetDialogInternalParameters(commandName);
    		
		    var selectedFlashObject = editor.GetSelection().GetParentElement()
		    argument.Flash = selectedFlashObject;
		    var selectedFlashObjectPath = null;
		    if (selectedFlashObject)
		    {
			    selectedFlashObjectPath = (selectedFlashObject.tagName.toUpperCase() == "OBJECT")?getParameterValue(selectedFlashObject, "movie"):selectedFlashObject.src;
		    }
		    argument.FlashPath = selectedFlashObjectPath;

		    var callBackFn = (oTool && "function" == typeof(oTool) ? oTool : RadEditorNamespace.radEditorCreateFlash);
		    var dialogUrl = editor.GetDialogUrl("MCMS" + commandName);
		    if (selectedFlashObjectPath)
		    {
			    dialogUrl += "&selectedObjectPath=" + selectedFlashObjectPath;
		    }
		    editor.ShowDialog(dialogUrl + RadEditorGetDialogParametersString(editor, commandName)
			    , argument
			    , 400
			    , 300
			    , callBackFn
			    , null
			    , editor.Localization[commandName]);
		    return false;
	    };

    RadEditorCommandList["ImageManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    var callBackFn = (oTool && "function" == typeof(oTool) ? oTool : RadEditorNamespace.radEditorCreateImage);
		    var argument = {};

		    argument.InternalParameters = editor.GetDialogInternalParameters(commandName);

		    editor.ShowDialog(editor.GetDialogUrl(RadEditorNamespace.IMAGE_MANAGER_DIALOG_NAME) + RadEditorGetDialogParametersString(editor, commandName)
			    , argument
			    , 400
			    , 300
			    , callBackFn
			    , null
			    , editor.Localization[commandName]);
		    return false;
	    };

    RadEditorCommandList["TemplateManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    var callBackFn = (oTool && "function" == typeof(oTool) ? oTool : RadEditorNamespace.radEditorInsertTemplate);
		    var argument = {};
		    argument.InternalParameters = editor.GetDialogInternalParameters(commandName);

		    editor.ShowDialog(editor.GetDialogUrl("MCMS" + commandName) + RadEditorGetDialogParametersString(editor, commandName)
			    , argument
			    , 400
			    , 300
			    , callBackFn
			    , null
			    , editor.Localization[commandName]);
		    return false;
	    };

    RadEditorCommandList["SetLinkProperties"] =
    RadEditorCommandList["LinkManager"] =
	    function anon(commandName, editor, oTool)
	    {
		    var selectedTab = null;
		    if (oTool && oTool.SelectedTab) selectedTab = oTool.SelectedTab;

		    var args = RadEditorNamespace.GetSelectionLinkArgument(editor, selectedTab);
		    var callbackFunc = (null == args.realLinkObject
								    ? RadEditorNamespace.radEditorCreateLink
								    : RadEditorNamespace.radEditorSetLinkProperties);

		    editor.ShowDialog(editor.GetDialogUrl("MCMSLinkManager")
			    , args
			    , 400
			    , 300
			    , callbackFunc
			    , { cmdName : editor.Localization[commandName]}
			    , editor.Localization[commandName]);
		    return false;
	    };
    }
    function radEditor_CMS_restoreAfterPreviewPostback(originalFunction)
    {
	    originalFunction();
	    if (typeof(RadEditorGlobalArray) != "undefined")
	    {
			var editors = RadEditorGlobalArray;
			for (var counter = 0; editors && counter < editors.length; counter++)
			{
				editors[counter].PostBackRegisterEditor(editors[counter]);
				editors[counter].ValueSaved = false;
				editors[counter].SkipSaving = false;

				var theContent = editors[counter].ContentHiddenTextarea.value;
				editors[counter].ContentHiddenTextarea.value = theContent;
				editors[counter].private_EncodeHiddenAreaContent(false);
				editors[counter].ContentTextarea.value = editors[counter].ContentHiddenTextarea.value;
			}
	    }
    };
    
    //prevent access is denied js error when submitting content
    function UpdateSiblingFramesInUnpublishedMode()
	{
		for (i=0; i < window.top.frames.length; i++) 
		{
			if (window.top.frames[i] != window)
			{
				// refresh it with Unpublished mode URL
				var frameElementSrc = '';
				try
				{
					frameElementSrc = window.top.frames[i].frameElement.src;
				}
				catch (e)
				{}
				if (frameElementSrc && frameElementSrc.indexOf('javascript:') < 0)
				{
					try
					{
						window.top.frames[i].location.href = GetUrlModeUnpublished( window.top.frames[i].location.href );
					}
					catch (e)
					{}
				}
			}
		}
	}

	//preview functions override
	if (typeof(CMS_restoreAfterPreviewPostback) == 'function')
	{
		var radEditorOriginalRestorationAfterPostbackFunction = CMS_restoreAfterPreviewPostback;
		CMS_restoreAfterPreviewPostback = function()
		{
			radEditor_CMS_restoreAfterPreviewPostback(radEditorOriginalRestorationAfterPostbackFunction);
		};
	}

}