

function Editor() {
    this.oldHTML = "";
    this.user = "";
    this.id = "";
    this.lang = "";
}

Editor.prototype.init = function(user,id,lang) {
    this.user = user;
    this.id = id;
    this.lang = lang;
}

Editor.prototype.staticText = function(action,section) {
    
    if(action == "edit") {
        this.showEditor(section,this.lang);
    }
    if(action == "save") {

        var ed = tinyMCE.get('Core_Text_textarea_' + section);
        var text = ed.getContent();
        var query = '{"action":"saveStaticText","section":"'+section+'","lang":"'+this.lang+'","text":"'+delNL(text.replace(/\"/g,'|'))+'"}';
        var user = this.user;
        var id = this.id;
        var server = "/server.Static.php";
        var successFunc = "editor.editorClose('"+section+"')";
        var successMsg = i18n.translate("basic.staticText.saved");
        var errorMsg = i18n.translate("basic.staticText.error");
		
        disp.send(server,query,user,id,successFunc,successMsg,"",errorMsg);
    }
}

Editor.prototype.showEditor = function(section,lang) {
	
    this.oldHTML = $("#Core_Text_"+section).html();
	
    var editorForm = '';
    editorForm += '<textarea id="Core_Text_textarea_'+section+'" style="width: 99%; height: 500px;">';
    editorForm += this.oldHTML;
    editorForm += '</textarea>';
    editorForm += '<br/><br/>';
	
    var buttons = '';
    buttons += '<a href="javascript:editor.editorCancel(\''+section+'\')">Cancel</a>';
    buttons += '<a href="javascript:editor.editorReset(\''+section+'\')">Reset</a>';
    buttons += '<a href="javascript:editor.staticText(\'save\',\''+section+'\',\''+lang+'\')">Save</a>';

    $("#Core_Text_"+section).html(editorForm);
    $("#LMUI_buttonBar_"+section).html(buttons);

    tinyMCE.init({
        mode : "textareas",
        theme: "advanced",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,code,|,forecolor,backcolor",
        theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap",

        theme_advanced_toolbar_location : "top",
        document_base_url : core.baseURL,
        relative_urls : false,
        remove_script_host : false
    });
}
Editor.prototype.editorCancel = function(section) {
    $("#Core_Text_"+section).html(this.oldHTML);
    var buttons = '';
    buttons += '<a href="javascript:editor.staticText(\'edit\',\''+section+'\')">Edit</a>';
    $("#LMUI_buttonBar_"+section).html(buttons);
}
Editor.prototype.editorReset = function(section) {
    $("#Core_Text_textarea_"+section).val("");
}
Editor.prototype.editorClose = function(section) {
    var ed = tinyMCE.get('Core_Text_textarea_' + section);
    var text = ed.getContent();
    var buttons = '';
    buttons += '<a href="javascript:editor.staticText(\'edit\',\''+section+'\')">Edit</a>';
    $("#LMUI_buttonBar_"+section).html(buttons);
    $("#Core_Text_"+section).html(text);
}


var editor = new Editor();
