

// JScript File

    var RTEDialogLocation = clientScriptPathInfo.ApplicationPath + '/editor/';

    var RadEditor1ClientObject = null;
    var restorePoint = null;

    function OnEditorClientLoad(editor) {

        if (editor.GetHtml() == "&nbsp;") {
            editor.Document.body.innerHTML = '<br/>';
        }    
        
        document.writeln('<input type="hidden" id="ASPPG_baseRefURL" name="ASPPG_baseRefURL" value="' + clientScriptPathInfo.ForumDir + '">');
                
        var filter = editor.FiltersManager.GetFilterByName("FixUlBoldItalic");
        if (filter) filter.Enabled = false;        
        
        RadEditor1ClientObject = editor;
        
        RadEditorCommandList["Insert an Image"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                editor.ShowDialog(
                    RTEDialogLocation + "image.htm"
                    , null//argument
                    , 470
                    , 120
                    , InsertCustomImage
                    , null
                    , "Insert Image");
                    return false;
            };

        RadEditorCommandList["Insert a Link"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var link = editor.GetSelection().GetParentElement();                    
                var arg = link; //link.tagName == "A" ? link : null;
                                
                RadEditor1ClientObject = editor;
                editor.ShowDialog(
                    RTEDialogLocation + "hyperlink.htm"
                    , arg
                    , 470
                    , 150
                    , InsertCustomLink
                    , null
                    , "Insert Link");
                    return false;
            };


        RadEditorCommandList["Quote Original"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var quoteField = document.getElementById(quoteFieldClientID);
                if (quoteField.value!='') editor.PasteHtml(quoteField.value);
                quoteField.value = '';
                
            }; 
                
        RadEditorCommandList["Wrap [code] tag"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                editor.PasteHtml("[code]" + editor.GetSelectionHtml() + "[/code]");
                
            };  
                
        RadEditorCommandList["Wrap [quote] tag"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                editor.PasteHtml("[quote]" + editor.GetSelectionHtml() + "[/quote]");
                
            };
            
        RadEditorCommandList["Show PGDCodes"] =
            function (commandName, editor, oTool)
            {
                restorePoint = editor.CreateRestorePoint();
                var link = editor.GetSelection().GetParentElement();                    
                var arg = link; //link.tagName == "A" ? link : null;
                                
                RadEditor1ClientObject = editor;
                editor.ShowDialog(
                    RTEDialogLocation + "custompgdcode.aspx"
                    , arg
                    , 470
                    , 450
                    , InsertCustomPGDCode
                    , null
                    , "Custom PGDCodes");
                    return false;
            };    
            
    }
    
    function OnEditorClientInit(editor)
    {
        if (!window.opera) return; 
 
        editor.old_AttachEventHandler = editor.AttachEventHandler;    
        editor.AttachEventHandler = function(eventName, eventFn)
        {     
             if (eventName.indexOf("click") < 0)
             {
                this.old_AttachEventHandler(eventName, eventFn);     
             }                    
        }
    }
    

    function InsertQuotePrevious(){
        if (restorePoint != null) restorePoint.Select();
        var quoteField = document.getElementById(quoteFieldClientID);
        if (quoteField.value!='') RadEditor1ClientObject.PasteHtml(quoteField.value);
        quoteField.value = '';
    }

    function InsertMultiQuote() {
        if (restorePoint != null) restorePoint.Select();
        var quoteField = document.getElementById(multiquoteFieldClientID);
        if (quoteField.value != '') RadEditor1ClientObject.PasteHtml(quoteField.value);
        quoteField.value = '';
    }    
    
    function InsertCustomImage(returnValue)
    {
        if (restorePoint != null) restorePoint.Select();
        if (typeof(returnValue)=="string" && returnValue!='')
        {
            RadEditor1ClientObject.PasteHtml(returnValue);
        } 
    }

    function InsertCustomLink(returnValue)
    {
        if (restorePoint != null) restorePoint.Select();
        if (returnValue)
        {
            var selectionHTML = RadEditor1ClientObject.GetSelectionHtml();
            
            if (returnValue.text==""){
                if (selectionHTML=="") {
                    RadEditor1ClientObject.PasteHtml("<a href=\"" + returnValue.url + "\">" + returnValue.url + "</a>");
                } else {
                    RadEditor1ClientObject.PasteHtml("<a href=\"" + returnValue.url + "\">" + selectionHTML + "</a>");
                }
            
            } else {
                RadEditor1ClientObject.PasteHtml("<a href=\"" + returnValue.url + "\">" + returnValue.text + "</a>");
            }
            
            
        }
    } 
    
    function InsertCustomPGDCode(returnValue)
    {
        if (restorePoint != null) restorePoint.Select();
        if (returnValue)
        {
            var selectionHTML = RadEditor1ClientObject.GetSelectionHtml();
            
            RadEditor1ClientObject.PasteHtml( returnValue.insertFront + selectionHTML + returnValue.insertBack);
        }
    }      
            
    function InsertSmiley(returnValue)
    {
        if (restorePoint != null) restorePoint.Select();
        if (returnValue != "")
        {
            RadEditor1ClientObject.PasteHtml(returnValue);
        }
        return false;
        
    }


