

function Editor() {
	this.oldHTML = "";
	this.user = "";
	this.id = "";
	this.lang = "";
}

Editor.prototype.init = function(lang) {
	this.user = core.user;
	this.id = core.id;
	this.lang = core.lang;
}

Editor.prototype.staticText = function(action,section) {
	
	if(action == "edit") {
		this.showEditor(section,this.lang);	
	}
	if(action == "save") {
		var text = $("#Core_Text_textarea_"+section).val();
		var query = "action:saveStaticText||section:"+section+"||lang:"+this.lang+"||text:"+text;
		var user = this.user;
		var id = this.id;
		var server = "/core/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: 99%; height: 200px;">';
	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);
}
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 newText = $("#Core_Text_textarea_"+section).val();
	var buttons = '';
	buttons += '<a href="javascript:editor.staticText(\'edit\',\''+section+'\')">Edit</a>';
	$("#LMUI_buttonBar_"+section).html(buttons);
	$("#Core_Text_"+section).html(newText);
}


var editor = new Editor();
