

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("staticText:success");
		var errorMsg = i18n.translate("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: 90%; height: auto;">';
	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,separator,undo,redo,separator,bullist,numlist,|,code",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        document_base_url : core.baseURL,
        relative_urls : false,
        remove_script_host : false,
        content_css : core.baseURL + "/assets/css/tiny_mce/tinymcefix.css"
    });
}
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();