﻿$(document).ready(function() {
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(function() {
        var allInstances = CKEDITOR.instances, editor, doc;
        for (var i in allInstances) {
            editor = allInstances[i];
            doc = editor.document;
            if (doc) {
                doc.$.designMode = "off";
                doc.$.designMode = "on";
            }
        }

        for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].destroy();
        }
    });

    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function() {
        var allInstances = CKEDITOR.instances, editor, doc;
        for (var i in allInstances) {
            editor = allInstances[i];
            doc = editor.document;
            if (doc) {
                doc.$.designMode = "off";
                doc.$.designMode = "on";
            }
        }

        CKFinder.setupCKEditor(null, '/ckeditor/ckfinder/');
        //CKEDITOR.replaceAll();
    });
});
