﻿String.prototype.bool = function() { return (/^true$/i).test(this); };

var editorFrameHeight = -1;
var rteHeight = -1;
var isToolBarResized = false;
var codeValue = "";

// NewPost object
//#region
function FileAttachment()
{
    this.FileName = "";
    this.Status = "";
}

var NewPost =
{
    Id: -1,
    ThreadId: -1,
    HasCode: false,
    Attachments: null,
    EditMode: "", // Edit, Reply or Quote
    DeletedAttachment: null,
    IsDirty: false,
    HasExitEditMode: true,
    SubmitMode: "", //Submit or Cancel
    IsBusy: false,
    IsUploadingFilesOnSubmit: false,
    IsSubmitClicked: false,
    IsInsertCodeDirty: false,

    ResetValue: function()
    {
        this.Id = -1;
        this.HasCode = false;
        this.Attachments = new ISArray();
        //this.EditMode = "";
        this.DeletedAttachment = null;
        this.IsDirty = false;
        this.HasExitEditMode = true;
        this.SubmitMode = "";
        this.IsBusy = false;
        this.IsUploadingFilesOnSubmit = false;
        this.IsSubmitClicked = false;

        this.ResetElement();
    },

    ResetElement: function()
    {
        var el = document.getElementById("replyAttachment");
        el.style.display = "none";

        el = document.getElementById("replyAttContent");
        ClearAttachmentItems(el);

        el = document.getElementById("replyAttSummary");
        el.innerText = "";

        if (this.EditMode == "Edit" || this.EditMode == "Reply" || this.EditMode == "Quote")
            ResetRTEState();
        else
        {
            var rte = ISGetObject("te1");
            rte.ToggleToolBar(rte.ClientToolBar[1], false);
        }
    },

    AddAttachment: function(fileName, status) // fileName : file name;status
    {
        if (typeof (status) == "undefined")
            status = "Added";

        var flag = false;

        var list = this.Attachments;
        for (var i = 0; i < list.length; i++)
        {
            var item = list[i];

            if (item.FileName == fileName)
            {
                item.Status = "Added";
                flag = true;
                break;
            }
        }

        if (!flag)
        {
            var item = new FileAttachment();
            item.FileName = fileName;
            item.Status = "Added";

            list.Add(item);
        }
    },

    RemoveAttachment: function(fileName)
    {
        var list = this.Attachments;
        for (var i = 0; i < list.length; i++)
        {
            var item = list[i];

            if (item.FileName == fileName)
            {
                item.Status = "Removed";
                break;
            }
        }
    },

    GetTotalAttachment: function()
    {
        var total = 0;
        var list = this.Attachments;
        for (var i = 0; i < list.length; i++)
        {
            var item = list[i];

            if (item.Status != "Removed")
            {
                total++;
            }
        }

        return total;
    },

    GetAttachmentAttributeString: function()
    {
        var attachment = "";
        var list = this.Attachments;
        for (var i = 0; i < list.length; i++)
        {
            var item = list[i];

            if (item.Status != "Removed")
            {
                attachment += item.FileName + ",";
            }
        }

        return attachment.substring(0, attachment.length - 1);
    },

    GetAttachmentStringForSubmit: function(isCancel)
    {
        var attachment = "";
        var list = this.Attachments;
        var uploadPath = document.getElementById("uploadPath").value;

        for (var i = 0; i < list.length; i++)
        {
            var item = list[i];

            switch (this.EditMode)
            {
                case "Reply":
                case "Quote":
                    if (item.Status != "Removed")
                    {
                        if (isCancel)
                            attachment += uploadPath + "/" + item.FileName + ",";
                        else
                            attachment += item.FileName + ",";
                    }
                    break;

                case "Edit":
                    attachment += uploadPath + "/" + item.FileName + ";" + item.Status + ",";
                    break;

                case "New":
                    if (item.Status != "Removed")
                        attachment += uploadPath + "/" + item.FileName + ",";
                    break;
            }
        }

        return attachment.substring(0, attachment.length - 1);
    }
};
//#endregion

// other rte functions
//#region
function RegisterIFrameBehavior()
{
    var rte = ISGetObject("te1");
    window.setTimeout(function() { rte.UnregisterIFrameBehavior(); rte.RegisterIFrameBehavior(); }, 10);
}

function ResizeEditor()
{
    var rte = ISGetObject("te1");
    rte.DoResize();

    for (var i = 0; i < rte.ClientToolBar.length; i++)
    {
        var tb = rte.ClientToolBar[i];
        tb.DoResize();
    }
}

function SetEditorValue(text, isQuote)
{
    var rte = ISGetObject("te1");

    if ((text == "" && !rte.IsEditorEmpty()) || text != "")
    {
        var value = "";

        if (isQuote)
            value = "<blockquote>" + text + "</blockquote>" + AddNewLine();
        else
            value = text;

        if (IS.moz)
            window.setTimeout(function() { rte.SetValue(value); }, 1);
        else
            rte.SetValue(value);
    }
}

function HideCallOut()
{
    var rte = ISGetObject("te1");
    if (rte != null)
        rte.HideCallOut(false);

    var c = ISGetObject("CallOutForum");
    if (c != null)
        c.Hide();
}

function FocusOnEditor()
{
    var rte = ISGetObject("te1");
    rte.SwitchToDesignView();
    
    if (IS.safari || IS.chrome)
        window.setTimeout(function() { ISGetObject("te1").SetFocus(); }, 1);
    else
        rte.SetFocus();
}

function ResetRTEState()
{
    var rte = ISGetObject("te1");
    rte.ResetEditorState();
    
    rte.OnToolbarCommandNotify("Emoticon", false);
    rte.OnToolbarCommandNotify("InsertCode", false);
    rte.OnToolbarCommandNotify("More", false);

    var textarea = document.getElementById("code_t");
    if (textarea != null)
        textarea.value = "";

    ToggleRTEFrameLayer(false);
    rte.ToggleToolBar(rte.ClientToolBar[1], false);
}
//#endregion

// rte custom pane
//#region

/* Emoticon */
//#region
function EmoticonPane()
{
    TaskPaneContent.call(this); //inherit from TaskPaneContent object

    this.Id = "Emoticon";

    this.OnCreate = function()
    {
        this.Type = "Emoticon";
        this.Caption = "Insert Emoticons";
        this.ShowToolBar = false;
    };

    this.GetContainerElement = function()
    {
        var str = "<div id='frame'>";
        for (var i = 1; i < 24; i++)
        {
            str += "<div style='float: left; padding-left: 5px; padding-bottom: 5px;'>"
                        + "<img src='/WebResources/Images/Community/Editor/smiley" + i + ".gif' style='cursor: pointer' "
                        + "title='Click here to add this emoticon' /></div>";
        }
        str += "</div>";

        var div = document.createElement("DIV");
        div.innerHTML = str;

        return div.children[0];
    };

    this.OnAfterRender = function()
    {
        var el = document.getElementById("frame");
        Listener.Add(el, "onclick", InsertEmoticon, this);
    };

    this.OnClose = function()
    {
        var rte = this.Parent.Parent;
        rte.OnToolbarCommandNotify("Emoticon", false);
    };

    this.OnContentOptionsSelected = function()
    {
        var pane = this.Parent;
        var rte = pane.Parent;

        if (pane.ActiveType == "Emoticon")
        {
            rte.OnToolbarCommandNotify("Emoticon", true);
            rte.OnToolbarCommandNotify("Search", false);
        }
        else
            rte.OnToolbarCommandNotify("Emoticon", false);
    };

    this.Unload = function()
    {
        var el = document.getElementById("frame");
        Listener.Unload(el);
    };
}

function InsertEmoticon()
{
    var paneContent = this;
    var rte = paneContent.Parent.Parent;
    var el = event.srcElement;

    if (el.tagName == "IMG")
    {
        rte.ShowCallOutOnMediaInsert = false;
        rte.InsertImage(el.src);
    }
}
//#endregion

/* Insert Code */
//#region
function InsertCodePane()
{
    TaskPaneContent.call(this); //inherit from TaskPaneContent object

    this.Id = "InsertCode";

    this.OnCreate = function()
    {
        this.Type = "Insert Code";
        this.Caption = "Insert Code";

        this.CreateCodeToolBar();
    };

    this.GetContainerElement = function()
    {
        var str = "<div id='code_f' style='height: 100%; width: auto; padding: 5px;'>"
                    + "<span style='font-family: Segoe UI, Tahoma; font-size: 9pt;'>Insert code here: </span>"
                    + "<textarea id='code_t' style='height: 98%; width: 98%; border: solid 1px #D7D7D7; font-family: Courier New, Tahoma; font-size: 9pt;'></textarea>"
                    + "</div>";

        var div = document.createElement("DIV");
        div.innerHTML = str;

        return div.children[0];
    };

    this.OnAfterRender = function()
    {
        var el = document.getElementById("code_t");
        Listener.Add(el, "onkeydown", InsertCodeKeyDown, this);
    };

    this.OnInitialize = function()
    {
        this.ResizePane();
    };

    this.OnResize = function()
    {
        this.ResizePane();
    };
    
    this.OnShow = function()
    {
        if (IS.safari || IS.chrome)
        {
            var el = document.getElementById("code_t");
            el.value = codeValue;
            codeValue = "";
        }
    };

    this.OnClose = function()
    {
        var rte = this.Parent.Parent;
        rte.OnToolbarCommandNotify("InsertCode", false);
        
        if (IS.safari || IS.chrome)
        {
            var el = document.getElementById("code_t");
            codeValue = el.value;
        }
    };

    this.OnContentOptionsSelected = function()
    {
        var pane = this.Parent;
        var rte = pane.Parent;

        if (pane.ActiveType == "Code")
        {
            rte.OnToolbarCommandNotify("InsertCode", true);
            rte.OnToolbarCommandNotify("Emoticon", false);
        }
        else
            rte.OnToolbarCommandNotify("InsertCode", false);
    };

    this.ResizePane = function()
    {
        var el = document.getElementById("code_f");
        el.style.display = "none";

        var content = this.Parent.GetContentElement();

        var height = content.offsetHeight - 25;
        if (height > 0)
            el.style.height = height + "px";

        el.style.display = "";
    };

    this.CreateCodeToolBar = function()
    {
        var toolbar = this.ToolBar;

        //create toolcommands
        var command = new ClientToolCommand();
        command.Id = command.Name = "cmdInsertCode";
        command.Text = "Insert";
        command.ToolTip = "Insert code";
        command.CommandImage = "/WebResources/Images/Community/Editor/hascode.gif";
        command.DisplayMode = "TextAndImage";
        toolbar.Commands.Add(command);

        command = new ClientToolCommand();
        command.Id = command.Name = "cmdClose";
        command.Text = "Close";
        command.ToolTip = "Close";
        command.CommandImage = "ISRes.axd?E/tb_cancel.gif";
        command.DisplayMode = "TextAndImage";
        toolbar.Commands.Add(command);

        toolbar.ClientSideEvents.OnClick = "OnPaneToolBarClick";
    };

    this.Unload = function()
    {
        var el = document.getElementById("code_t");
        Listener.Unload(el);
    };
}

function OnPaneToolBarClick(controlId, command, commandSection)
{
    var tb = ISGetObject(controlId);
    var rte = tb.Parent;

    switch (command.Name)
    {
        case "cmdInsertCode":
            var textarea = document.getElementById("code_t");
            var value = textarea.value;
            value = value.replace(/</g, "&lt;");
            value = value.replace(/>/g, "&gt;");

            var text = "<pre>" + value + "</pre>" + AddNewLine();

            rte.SetValueToCurrentPosition(text);

            NewPost.HasCode = true;
            NewPost.IsInsertCodeDirty = false;

            break;

        case "cmdClose":
            rte.OnToolbarCommandNotify("InsertCode", false);
            rte.HideTaskPane();

            break;
    }
}

function InsertCodeKeyDown()
{
    NewPost.IsInsertCodeDirty = true;    
}
//#endregion
//#endregion

// rte client-side events
//#region
function WebTextEditor1_OnInitialize(controlId)
{
    var rte = ISGetObject(controlId);
    rte.RegisterPaneContent(new EmoticonPane());
    rte.RegisterPaneContent(new InsertCodePane());
}

function WebTextEditor1_OnInitializeToolBar(controlId, args)
{
    var rte = ISGetObject(controlId);
    args.ToolBar = new ISArray();

    // re-arrange the commands sequence
    toolbars = [
        { "Name": rte.ID + "_tbFormatting", "Text": "Formatting", "Category": "Formatting",
            "Commands": new Array("Bold", "Italic", "Underline", "Separator", "FontSize", "Bullets", "Numbering", "Separator", "AlignLeft", "AlignCenter", "AlignRight", "Separator", "Paste", "Quote", "Separator", "Hyperlink", "RemoveLink", "Separator", "InsertFromWeb", "InsertFromComputer", "Separator", "FullScreen")
        },
        { "Name": rte.ID + "_tbStandard", "Text": "Standard", "Category": "Standard", 
            "Commands": new Array("Undo", "Redo", "Separator", "FontColor", "TextHighlightColor", "Separator", "DecreaseIndent", "IncreaseIndent", "AlignJustify", "ClearFormatting", "Heading", "Separator", "Cut", "Copy", "Separator", "Find", "Replace", "Separator", "InsertSymbol", "SpellChecker", "Separator", "ChangeCase", "Subscript", "Superscript", "Strikethrough")}];

    args.AddToolBar(args.ToolBar, toolbars);

    // add emoticon and insert code commands
    var toolbar = args.ToolBar[0];
    var command = { "Name": "cmdEmoticon", "Text": "Emoticon", "DisplayMode": "Image", "Image": "/WebResources/Images/Community/Editor/smiley1.gif", "Type": "ToggleButton", "ToggleGroupName": "TaskPane", "Items" : new ISArray() };
    args.AddCommand(toolbar, command, 19);

    command = { "Name": "cmdInsertCode", "Text": "Insert Code", "DisplayMode": "TextAndImage", "Image": "/WebResources/Images/Community/Editor/hascode.gif", "Type": "ToggleButton", "ToggleGroupName": "TaskPane", "Items": new ISArray() };
    args.AddCommand(toolbar, command, 21);
    
    command = { "Name": "cmdMore", "Text": "Show More Commands", "DisplayMode": "Image", "Image": "/WebResources/Images/Community/Editor/more.gif", "Type": "ToggleButton", "ToggleGroupName": "More", "Items": new ISArray() };
    args.AddCommand(toolbar, command);
}

function WebTextEditor1_OnToolBarClick(controlId, command, commandSection)
{
    var rte = ISGetObject(controlId);

    switch (command.Name)
    {
        case "cmdEmoticon":
        case "cmdInsertCode":
            if (command.IsActive)
                rte.ShowTaskPane(command.Text);
            else
                rte.HideTaskPane();

            if (command.Name == "cmdEmoticon")
                rte.OnToolbarCommandNotify("InsertCode", false);
            else
                rte.OnToolbarCommandNotify("Emoticon", false);

            break;

        case "cmdMore":
            var toolbar = rte.ClientToolBar[1];

            if (command.IsActive)
            {
                rte.ToggleToolBar(toolbar, true);
                if (!isToolBarResized)
                {
                    toolbar.DoResize();
                    isToolBarResized = true;
                }
            }
            else
                rte.ToggleToolBar(toolbar, false);

            rte.SetHeaderHeightCache();

            break;
    }
}

function WebTextEditor1_OnAfterExecCommand(controlId, action)
{
    var rte = ISGetObject(controlId);
    if (action == "InsertImage")
        rte.ShowCallOutOnMediaInsert = true;

    NewPost.IsDirty = true;
}

function WebTextEditor1_OnKeyDown(controlId, keyCode)
{
    NewPost.IsDirty = true;
}

function WebTextEditor1_OnMediaSelected(contolId, element)
{
    var src = element.src;
    
    if (src.indexOf("Community/Editor/smiley") != -1)
        return false;
        
    return true;
}

function WebTextEditor1_OnAfterResize(controlId)
{
    var rte = ISGetObject(controlId);
    rteHeight = rte.FrameObj.clientHeight;
    
    SetEditorFrameHeight();
    
    var el = document.getElementById("persistRTEHeight");
    if (el && el.value.bool())
    {
        var fpb = ISGetObject("WebFlyPostBackManager1");
        fpb.SaveEditorHeight(rteHeight);
    }
}
//#endregion

// uploader related
//#region
function WebTextEditor1_OnAfterUpload(controlId, fileInfo)
{
    var attContent = document.getElementById("replyAttContent");
    var attachment = GetAttachmentAttribute(attContent);

    //update the attachment array
    NewPost.AddAttachment(fileInfo.FileName, "Added");

    //update attachments attribute value
    var attachment = NewPost.GetAttachmentAttributeString();
    SetAttachmentAttribute(attContent, attachment);

    //update attachment summary
    WriteAttachmentSummaryElement(document.getElementById("replyAttSummary"));

    //add attachment item element
    attContent.appendChild(CreateAttachmentItem(fileInfo.FileName, true));

    NewPost.IsDirty = true;
}

function WebTextEditor1_OnUploaderCompleted(controlId)
{
    var el = document.getElementById("replyAttachment");
    ToggleElement(el, true);

    if (NewPost.IsUploadingFilesOnSubmit)
    {
        NewPost.IsUploadingFilesOnSubmit = false;

        if (NewPost.EditMode == "New")
        {
            document.getElementById("attachments").value = NewPost.GetAttachmentStringForSubmit();

            var wb = ISGetObject("SubmitButton");
            wb.Click();
        }
        else
            SubmitAction();
    }
}

function OnUploaderError(id, fileinfo, errorMessage, errorStackTrace)
{
    var up = ISGetObject(id);
}

function GetNonUploadedFilesCount()
{
    var rte = ISGetObject("te1");
    var uploader = rte.WebFileUploader;
    var cnt = 0;

    for (var i = 0; i < uploader.Files.length; i++)
    {
        var file = uploader.Files[i];

        if (file.Status == "Selected")
        {
            var fileParts = file.File.split("\\");

            NewPost.AddAttachment(fileParts[fileParts.length - 1], "Added");
            cnt++;
        }
    }

    return cnt;
}
//#endregion

// attachments
//#region

/* create attachment item */
//#region
function CreateAttachmentItem(fileName, isInEditMode)
{
    var path = document.getElementById("uploadPath").value;
    var div = document.createElement("DIV");
    var ext = fileName.split('.');

    var str = "<div class=\"attachmentitem\">"
        + "<img src=\"/WebResources/Images/Community/" + GetAttachmentIcon(ext[ext.length - 1]) + "\" align=\"top\" class=\"attachmentitemimage\" />"
        + "<a href=\"\" onclick=\"window.open('" + path + "/" + fileName + "'); return false;\" class=\"actionlink\">" + fileName + "</a>";

    if (isInEditMode)
        str += "<img src=\"ISRes.axd?E/delete.gif\" class=\"attachmentdelete\" title=\"Remove attachment\" onclick=\"DeleteAttachment(this, '" + fileName + "');\" />";

    str += "</div>";

    div.innerHTML = str;

    return div.children[0];
}

function GetAttachmentIcon(ext)
{
    switch (ext.toLowerCase())
    {
        case "jpg":
        case "jpeg":
            return "jpg.png";

        case "aspx":
        case "master":
            return "aspx.png";

        case "asmx":
        case "svc":
        case "wsdl":
            return "wsdl.png";

        case "rtf":
        case "doc":
        case "docx":
            return "docx.png";

        case "isl":
        case "istheme":
            return "istheme.png";

        case "avi":
        case "wmv":
            return "avi.png";

        case "zip":
        case "rar":
            return "zip.png";

        case "xls":
        case "xlsx":
            return "xlsx.png";

        default:
            var list = "gif,bmp,png,cs,vb,datasource,disco,dbml,xsd,xss,mdf,ldf,mdb,js,css,xaml,edmx,txt,swf,pdf,html,xml,dll,config";

            if (list.indexOf(ext) != -1)
                return ext + ".png";
            else
                return "default.png";
    }
}
//#endregion

/* attachment summary*/
//#region
function WriteAttachmentSummary(post, isAnswer)
{
    var id = "attSummary" + post.PostID;
    if (isAnswer)
        id = "answerAttSummary" + post.PostID;

    WriteAttachmentSummaryElement(document.getElementById(id));
}

function WriteAttachmentSummaryElement(el)
{
    el.innerText = GetAttachmentSummary();
    el.attributes["count"].value = NewPost.GetTotalAttachment().toString();
}

function GetAttachmentSummary()
{
    var totalAttachment = NewPost.GetTotalAttachment();
    var str = totalAttachment + " attachment";

    if (totalAttachment > 1)
        str += "s";

    return str;
}
//#endregion

/* write attachment*/
//#region
function WriteAttachments(post)
{
    if (post.Attachment != "")
    {
        //write attachment in its container
        WriteAttachmentSummary(post, false);
        WriteAttachmentElement(post.Attachment, document.getElementById("attContent" + post.PostID));

        //write attachment in answer container
        if (post.IsAnswer)
        {
            var el = document.getElementById("answerAttContent" + post.PostID);
            WriteAttachmentSummary(post, true);
            WriteAttachmentElement(post.Attachment, el);

            ToggleElement(el.parentElement, true);
        }
    }
    else
    {
        if (post.IsAnswer)
            ToggleElement(document.getElementById("answerAtt" + post.PostID), false);

        //attachment box in original post is toggled in ToggleEdit or ToggleReply
    }
}

function WriteAttachmentElement(attachments, attContent)
{
    var list = attachments.split(',');

    //clear previous attachment item elements
    if (attContent.children.length > 0)
        ClearAttachmentItems(attContent);

    //add new attachment items 
    for (var i = 0; i < list.length; i++)
        attContent.appendChild(CreateAttachmentItem(list[i], false));

    //set the attachments attributes in attContent
    SetAttachmentAttribute(attContent, attachments);
}
//#endregion

/* delete attachment */
//#region
function ClearAttachmentItems(el) //el => containerEl
{
    var cnt = el.children.length;
    for (var i = 0; i < cnt; i++)
        el.removeChild(el.children[0]);

    SetAttachmentAttribute(el, "");
}

function DeleteAttachment(img, fileName)
{
    if (confirm("Are you sure you want to remove this attachment?"))
    {
        HideCallOut();

        NewPost.DeletedAttachment = img.parentElement;
        NewPost.IsDirty = true;

        NewPost.RemoveAttachment(fileName);

        switch (NewPost.EditMode)
        {
            case "Edit":
                RemoveAttachmentElement(fileName);

                break;

            case "Reply":
            case "Quote":
            case "New":
                var fpb = ISGetObject("WebFlyPostBackManager1");
                fpb.DeleteAttachment(document.getElementById("uploadPath").value + "/" + fileName);

                break;
        }
    }
}

function WebFlyPostBackManager1_OnDeleteAttachment(returnValue)
{
    RemoveAttachmentElement(returnValue);
}

function RemoveAttachmentElement(fileName)
{
    SetAttachmentAttribute(el, NewPost.GetAttachmentAttributeString());
    WriteAttachmentSummaryElement(document.getElementById("replyAttSummary"));

    var el = NewPost.DeletedAttachment.parentElement;
    el.removeChild(NewPost.DeletedAttachment);

    if (el.children.length <= 0)
        el.parentElement.parentElement.style.display = "none";

    NewPost.DeletedAttachment = null;
}
//#endregion

/* attachment in edit - different scenario*/
//#region
function FillEditAttachment(el)
{
    if (el.attributes["attachments"])
    {
        var attContent = document.getElementById("replyAttContent");
        var attachments = GetAttachmentAttribute(el);

        if (attachments != "")
        {
            //add attachment item
            var list = attachments.split(',');

            for (var i = 0; i < list.length; i++)
            {
                var fileName = list[i];

                if (fileName != "")
                {
                    NewPost.AddAttachment(fileName, "PreviouslyAdded");
                    attContent.appendChild(CreateAttachmentItem(fileName, true));
                }
            }

            //set the attachments attribute
            SetAttachmentAttribute(attContent, NewPost.GetAttachmentAttributeString());

            //write attachment summary
            WriteAttachmentSummaryElement(document.getElementById("replyAttSummary"));
        }
    }
}
//#endregion

/* other */
//#region
function SetAttachmentAttribute(el, attachments)
{
    if (el != null)
        el.attributes["attachments"].value = attachments;
}

function GetAttachmentAttribute(el)
{
    if (el && el.attributes["attachments"])
        return el.attributes["attachments"].value;

    return "";
}
//#endregion

//#endregion

// other
//#region

function HasLogin(el)
{
    if (document.getElementById("hasLogin") == null)
    {
        CreateForumCallOut("Login", el);
        return false;
    }

    return true;
}

function NewThreadLoad()
{
    NewPost.ResetValue();
    NewPost.EditMode = "New";

    rteHeight = parseInt(document.getElementById("editorFrameHeight").value);
    SetEditorFrameHeight();
}

function ToggleElement(el, isDisplay)
{
    if (isDisplay)
        el.style.display = "";
    else
        el.style.display = "none";
}

function ToggleRTEFrameLayer(isDisplay)
{
    var layer = document.getElementById("rteFrameLayer");
    var frame = document.getElementById("rteFrame");

    if (isDisplay)
    {
        layer.style.width = frame.offsetWidth + "px";
        layer.style.height = frame.offsetHeight + "px";

        ToggleElement(layer, true);
    }
    else
        ToggleElement(layer, false);
}

function SetEditorFrameHeight()
{
    if (typeof (editorFrameHeight) != "undefined")
        editorFrameHeight = rteHeight + 120;
}

function AddNewLine()
{
    if (IS.safari || IS.chrome)
        return "<p>&nbsp;</p>";
    else if (IS.moz)
        return "<p><br /></p>";
    else
        return "<p></p>";
}
//#endregion
