﻿
//  <script src="../tiny_mce/tiny_mce.js" type="text/javascript"></script>
//  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
/// <reference path="../tiny_mce/tiny_mce.js" />


var language = navigator.userLanguage;
tinyMCE.init({
    // General options
    mode: "textareas",
    theme: "advanced",
    skin: "cirkuit",

    file_browser_callback: 'myFileBrowser',     // Call start function for ImageBrowser
    relative_urls: false,
    editor_selector: "mceAll",
    content_css: "/Templates/mce.css",
 
    plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

    // Theme options
    theme_advanced_buttons1: "save,newdocument,|,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,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,pxImage",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: false,
    
    // Drop lists for link/image/media/template dialogs
    template_external_list_url: "lists/template_list.js",
    external_link_list_url: "lists/link_list.js",
    external_image_list_url: "lists/image_list.js",
    media_external_list_url: "lists/media_list.js",
   
    setup: function (ed) { // Only for the Menu Button
        ed.addButton('pxImage', {
            title: 'Image',
            image: '/tiny_mce/folder_picture.png',
            onclick: function () {// Add you own code to execute something on click
                myFileBrowser('', '', '', window);
            }
        });
    }
});

// ADVANCED
tinyMCE.init({
    // General options
    mode: "textareas",
    theme: "advanced",
    skin: "cirkuit",
    file_browser_callback: 'myFileBrowser',     // Call start function for ImageBrowser
    relative_urls: false,
    editor_selector: "mceAdvanced",
    content_css: "/Templates/mce.css",
    dialog_type : "modal",

    plugins: "inlinepopups,safari,style,table,advhr,advimage,advlink,media,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",

    theme_advanced_buttons1: "cut,copy,pastetext,|,bullist,numlist,|,undo,redo,|,link,unlink,|,forecolor,backcolor, |,tablecontrols,|,removeformat,visualaid,|,sub,sup,charmap,iespell",
    theme_advanced_buttons2: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,styleselect,|,pxImage,media,|,fullscreen, code",
    theme_advanced_buttons3: "",
    theme_advanced_buttons4: "",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: false,

    setup: function (ed) { // Only for the Menu Button
        ed.addButton('pxImage', {
            title: 'Image',
            image: '/tiny_mce/folder_picture.png',
            onclick: function () {// Add you own code to execute something on click
                myFileBrowser('', '', '', window);
            }
        });
    }
});

// BASIC
tinyMCE.init({
    // General options
    mode: "textareas",
    theme: "advanced",
    relative_urls: false,
    editor_selector: "mceBasic",
    content_css: "/Templates/mce.css",
    dialog_type: "modal",

    plugins: "inlinepopups,safari,advhr,advimage,advlink,paste,directionality,xhtmlxtras",

    theme_advanced_buttons1: "bold,italic,underline,pastetext,bullist,numlist,undo,link,unlink",
    theme_advanced_buttons2: "",
    theme_advanced_buttons3: "",
    theme_advanced_buttons4: "",

    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: false,

    setup: function (ed) { // Only for the Menu Button
        ed.addButton('pxImage', {
            title: 'Image',
            image: '/tiny_mce/folder_picture.png',
            onclick: function () {// Add you own code to execute something on click
                myFileBrowser('', '', '', window);
            }
        });
    }
});


tinyMCE.init({
    mode: "textareas",
    editor_selector: "mceSimple",
    theme: "simple",
    content_css: "/Templates/mce.css"
});



function myFileBrowser(field_name, url, type, win) {

    // alert("Field_Name: " + field_name + " nURL: " + url + "  nType: " + type + "  nWin: " + win); // debug/testing
    tinyMCE.activeEditor.focus(); // Must save a bookmark
    var bm = tinyMCE.activeEditor.selection.getBookmark();

    var cmsURL = window.location.toString();    // script URL - use an absolute path!
    if (cmsURL.indexOf("?") < 0) {
        //add the type as the only query parameter
        cmsURL = cmsURL + "?type=" + type;
    }
    else {
        cmsURL = cmsURL + "&type=" + type;
    }

    tinyMCE.activeEditor.windowManager.open({
        //file: "http://localhost:55797/TinyMCE_Tester/pxImageMan2.aspx",
        //file: "http://localhost:55797/TinyMCE_Tester/imageViewer/imageViewer.aspx", // FIX PATH !!
        file: imageBrowserUrl,
        title: 'Image Browser',
        width: 600,  
        height: 650,
        resizable: "yes",
        inline: "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous: "no"
    }, {
        window: win,
        input: field_name,
        bookm: bm
    });

    return false;
}



function test() {

    //alert("test");

    // var ed = tinyMCEPopup.editor, dom = ed.dom;
    //var ed = tinyMCE.editor, dom = ed.dom;
    //ed.focus();

    //var elm = ed.selection.getNode();
    //i = ed.selection.getBookmark();
    //ed.selection.moveToBookmark(i);

    var img = tinyMCE.activeEditor.dom.createHTML('img', { 'src': 'door.png', 'border': 0 });
    tinyMCE.execCommand('mceInsertContent', false, img);

    /*
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer") {
    var ed = tinyMCE.activeEditor;
    if (ed.getContent()) {
    tinyMCE.execCommand('mceInsertContent', false, img);
    }
    }
    else {
    //tinyMCEPopup.execCommand('mceInsertContent', false, img);
    tinyMCE.execCommand('mceInsertContent', false, img);
    }*/

}
