﻿$.fn.WysiwygDialog = function (options) {
    var opts = $.extend(defaults, options);
    var dialogElement;
    var editorElement;
    var editor;


    $(this).dblclick(function () {

        //tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.dom.select('div'), 'someclass'); 
        function myclose() {
            //tinyMCE.save();
            //tinyMCE.close();
            //editor.remove();
            //            var mce = tinyMCE.get("editContent");
            //            mce.save();
            //            mce.remove();

            var ed = tinyMCE.get("editContent");
            var xx = "Rob";
            var key = $("#myKey");
            alert(key);
            $.post("/admin/updatesecurity",
            {
                Elm1: ed.getContent(),
                Elm2: key
            },
            function (data) {
                //Result = eval('(' + data + ')'
            });

            //SectionKey: $("#FirstName").val(),
            //Elm1: $("#LastName").val(),

            //            // Do you ajax call here, window.setTimeout fakes ajax call
            //            ed.setProgressState(1); // Show progress

            //            window.setTimeout(function () {
            //                ed.setProgressState(0); // Hide progress
            //                alert(ed.getContent());
            //            }, 3000);



            //alert("close!");
        };

        //myclose()
        tinyMCE.init({
            theme: "advanced",
            mode: "exact",
            elements: "editContent",
            plugins: "save",
            theme_advanced_buttons3_add: "save,cancel",
            save_onsavecallback: myclose
        });
        // Theme options
        //                    theme_advanced_buttons1: "save,newdocument,save,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        //                    theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        //                    theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        //                    theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        //                    theme_advanced_toolbar_location: "top",
        //                    theme_advanced_toolbar_align: "left",
        //                    theme_advanced_statusbar_location: "bottom",
        //                    theme_advanced_resizing: true
    });

    //                tinyMCE.init({
    //                    theme: "advanced",
    //                    mode: "textareas",
    //                    plugins: "inlinepopups",
    //                    dialog_type: "modal"
    //               });
    //tinyMCEPopup.onInit.add(SomeObject.init, SomeObject);


    //                tinyMCE.init({
    //                    theme: "advanced",
    //                    mode: "textareas",
    //                    plugins: "fullscreen",
    //                    theme_advanced_buttons3_add: "fullscreen",
    //                    fullscreen_new_window: false,
    //                    fullscreen_settings: {
    //                        theme_advanced_path_location: "top"
    //                    }


    //alert('Hey Rob');
    ////        dialogElement = $("<div id=\"dialog\"></div>");
    ////        editorElement = $("<textarea id=\"wysiwyg\" rows=\"15\" cols=\"63\" name=\"desc\">" + $(this).html() + "</textarea>");
    ////        dialogElement.append(editorElement);
    ////        var contentName = $(this).attr('id').replace('content-', '');
    ////        dialogElement.appendTo("body").dialog({
    ////            modal: true,
    ////            title: 'Content Editor: ' ,
    ////            zindex: 10000,
    ////            height: 811,
    ////            width: 770
    ////        });

    //            close: function () { destroyDialog(); },
    //            buttons: {
    //                "Submit": function () {
    //                    var content = editor.getContent();
    //                    $.post(opts.postUrl + contentName, { ContentBody: escape(content) }, function (json) {
    //                        if (json.Success) { document.location.reload(); } else { alert(json.Message); }
    //                    }, "json");
    //                },
    //                "Cancel": function () { destroyDialog(); }
    //            }
    //        });
    //        $('.ui-widget-overlay').click(function () { $('div#dialog').dialog('destroy'); });


    //        dialogElement = $("<div id=\"dialog\"></div>");
    //        editorElement = $("<textarea id=\"wysiwyg\" rows=\"15\" cols=\"63\" name=\"desc\">" + $(this).html() + "</textarea>");
    //        dialogElement.append(editorElement);
    //        var contentName = $(this).attr('id').replace('content-', '');
    //        dialogElement.appendTo("body").dialog({
    //            modal: true,
    //            title: 'Content Editor: ' + contentName,
    //            zindex: 10000,
    //            height: 811,
    //            width: 770,
    //            open: function () { editorElement.wysiwyg({ autoSave: true, debug: true }); editor = $.data($('#wysiwyg')[0], 'wysiwyg'); $('#wysiwygIFrame').focus(); },
    //            close: function () { destroyDialog(); },
    //            buttons: {
    //                "Submit": function () {
    //                    var content = editor.getContent();
    //                    $.post(opts.postUrl + contentName, { ContentBody: escape(content) }, function (json) {
    //                        if (json.Success) { document.location.reload(); } else { alert(json.Message); }
    //                    }, "json");
    //                },
    //                "Cancel": function () { destroyDialog(); }
    //            }
    //        });
    //        $('.ui-widget-overlay').click(function () { $('div#dialog').dialog('destroy'); });
    //});
    function destroyDialog() { dialogElement.dialog('destroy').remove(); editorElement = null; dialogElement = null; }
    var defaults = { postUrl: '', title: '' };

}
