try{
	_debug;
}catch(e){
	_debug = false;
}

function RTEditor(container, base, content){
	if (container.tagName != "DIV")
		throw "RTEditor.init: container must be a div (DIV)";
	this.base = base;
	if (this.base == undefined) this.base = "."
	this.container = container;
	this.content = content;
	if (this.content == undefined) this.content = "";
	document.createStyleSheet(this.base + "/rte.css");
	document.createStyleSheet(this.base + "/menu.css");
    document.createStyleSheet(this.base + "/toolbar.css");
	
	function Dialog(url, height, width){
		this.url = url;
		this.height = height;
		this.width = width;
	
		this.show= function(arg, modal){
			if (modal) 
				return window.showModalDialog(this.url, arg, "dialogHeight:" + this.height + "px;dialogWidth:" + this.width + "px;scroll:no;status:no;help:no;");
			else
				return window.showModelessDialog(this.url, arg, "dialogHeight:" + this.height + "px;dialogWidth:" + this.width + "px;scroll:no;status:no;help:no;");
		}
	}
	 
	this.SpellingWindow = new Dialog(this.base + "/spellcheck.html", 195, 415);
	this.ReplaceWindow = new Dialog(this.base + "/replace.html", 145, 345);
	this.FormatWindow = new Dialog(this.base + "/format.html", 240, 300);
	this.TableWindow = new Dialog(this.base + "/table.html", 170, 245);
	this.LinkWindow = new Dialog(this.base + "/link.html", 110, 300);
	this.OptionsWindow = new Dialog(this.base + "/options.html", 265, 250);
	this.DictionaryWindow = new Dialog(this.base + "/dictionary.html", 265, 250);

	function TabStrip(container){
	
		this.getTabWidth = function(left){
			for(var i = Math.floor(left/10); i < this.tabstops.length; i++){
				if (this.tabstops[i])
					return i * 10 - left + 10;
			}
			var tabwidth =  Math.ceil(left / 40) * 40 - left + 10;
			if (tabwidth == 0) return 40;
			return tabwidth;
		}
	
		this.reset = function(){
			this.tabstops = new Array();
			for (var i = 0; i < this.MAX_VALUE; i ++) {
				var tick = this.scale.children[i];
				if (i % 8 != 0)
					tick.className = 'tabstrip_tick';
				else {
					tick.className = 'tabstrip_label';
					tick.innerText = i / 8;
				}
			}
		}
	
		this.setTabStops = function(paragraph){
			var s = paragraph.style.getAttribute("tab-stops");
			if(this.s != s){
				this.reset();
				if (s != null){
					var tabstops = s.replace(/in\s*/g, ";").split(";");
					for(var i = 0; i < tabstops.length; i ++){
						if (Number(tabstops[i]) > 0) {
							this.tabstops[tabstops[i] * 8] = true;
							this.scale.children[tabstops[i] * 8].className = 'tabstrip_tabstop';
						}
					}
				}
				this.s = s;
			}
		}

		this.toggleTab = function(){
			var i = 0;
			if (event.srcElement.className == 'tabstrip')
				i = Math.round(event.offsetX / 10) - 1;
			else i = event.srcElement.index;
			var tick = this.scale.children[i]; 
			if (i % 8 != 0) {
				if (tick.className == 'tabstrip_tick'){
					tick.className = 'tabstrip_tabstop';
					this.tabstops[i] = true;
				}else{
					tick.className = 'tabstrip_tick';
					this.tabstops[i] = false;
				}
			} else {
				if (tick.className == 'tabstrip_label') {
					tick.innerText = "";
					tick.className = 'tabstrip_tabstop';
					this.tabstops[i] = true;
				} else {
					tick.className = 'tabstrip_label';
					tick.innerText = i / 8;
					this.tabstops[i] = false;
				}
			}
			var selection = this.rte.getSelection();
			if(selection != null){
				var tabstops = "";
				for (var i = 0; i < this.tabstops.length; i ++) {
					if (this.tabstops[i]){
						if (tabstops.length > 0) tabstops += " ";
						tabstops += (i * 1 / 8) + "in";
					}
				}
				var paragraphs = this.rte.getParagraphs(selection);
				for(var i = 0; i < paragraphs.length; i ++){
					paragraphs[i].style.setAttribute("tab-stops", tabstops);
					this.rte.resizeTabs(paragraphs[i]);
				}
			}
		}
	
		this.caretUpdate = function(){
			this.scale.scrollLeft = this.rte.editor.scrollLeft;
			this.setTabStops(this.rte.getParagraph(this.rte.getSelection().parentElement()));
		}
	
		this.s = "";
		this.MAX_VALUE = 256;
		this.tabstops = new Array();
		this.scale = container;
		this.scale.tabstrip = this;
		this.scale.unSelectable = "on";
		this.scale.noWrap = "true";
		this.scale.className = "tabstrip";
		this.scale.onclick = function(){this.tabstrip.toggleTab();}
		var html = "";
		for (var i = 0; i < this.MAX_VALUE; i ++) {
			if (i % 8 != 0)
				html += "<span class = 'tabstrip_tick' index = '" + i + "' unselectable = \"on\"></span>";
			else html += "<span class = 'tabstrip_label' index = '" + i + "' unselectable = \"on\">"+ i/8 +"</span>";
		}
		this.scale.innerHTML = html;
	}
    var html = "<table cellspacing=\"0\" cellpadding=\"0\" style=\"height:100%;width:100%;\">"
    + "<tr><td><table></table></td></tr>"
	+ "<tr><td><div style=\"width:0px;overflow:hidden;\"></div></td></tr>"
	+ "<tr style=\"height:100%;\"><td><div class=\"editor\" style=\"height:100%;width:100%;overflow:scroll;border:2px inset;background:window;padding:10px;\" ondrag=\"return false;\"></div></td></tr></table>"
    + "<div style=\"visibility:hidden;height:0px;\"></div>"
	+ "<applet style=\"visibility:hidden;height:0px;\" code=\"JSpellChecker\" " + (!_debug ? "archive=\""+this.base+"/jazzy.zip\"" : "") + " codebase=\".\" height=\"0\" width=\"0\"><param name=\"dictionary\" value=\"/dict/english.0\"><param name=\"phonetic\" value=\"/dict/phonet.en\"></applet>";
    //+ "<applet code=\"WSpellChecker\" " + (!_debug ? "archive=\""+this.base+"/ssce.zip, "+this.base+"/lib/ssce.jar\"" : "archive=\""+this.base+"/., "+this.base+"/lib/ssce.jar\"") + " codebase=\".\" height=\"0\" width=\"0\"><param name=\"lexicons\"  value=\"dict/ssceam2.clx\"></applet>";
    this.container.innerHTML = html;
	this.toolbar = new Toolbar(this.container.children[0].rows[0].cells[0].children[0], this.base + "/images");
	this.tabstrip = new TabStrip(this.container.children[0].rows[1].cells[0].children[0]);
	this.tabstrip.rte = this;
	this.editor = this.container.children[0].rows[2].cells[0].children[0];
    this.editor.rte = this;
	//this is needed for the tab spans to have an absolute reference to 
	//the rte object.  it also prevents multiple instances on a single page.
	this.editor.document.rte = this;
	this.menucontainer = this.container.children[1];
	this.menucontainer.className = "menu";
	this.spellchecker = this.container.children[2];
    this.editor.onresize = function(){
		this.rte.tabstrip.scale.style.width = this.offsetWidth;
	}
	this.editor.onresize();
    this.docmap = new Array(0);
	this.actions = new Array(0);
	this.caretlisteners = new Array(0);
	
	this.getHTML = function(){
		return this.editor.innerHTML;
	}

	this.setHTML = function(html){
		this.editor.innerHTML = html;
	}

	this.setEnabled = function(state){
		this.editor.contentEditable = state;
		this.toolbar.setEnabled(state);
		this.editor.focus();
	}

	this.select = function (pos, length){
		//alert("select (" + pos + ", " + length + ")");
		this.selection = this.editor.document.body.createTextRange();
		this.selection.moveToElementText(this.editor);
        this.selection.collapse(true)
		moveSelection(this.docmap, this.selection, pos);
		var end = this.editor.document.body.createTextRange();
		moveSelection(this.docmap, end, pos + length);
		this.selection.setEndPoint("EndToStart", end);
		this.selection.select();
		return this.selection;

		function moveSelection(docmap, selection, pos){
            for(var i = pos; i >=0;i--)
				if(docmap[i] != null) break;
            if(docmap[i] != null) selection.moveToElementText(docmap[i]);
			for (; i < pos; i++) {
				selection.move("character", 1);
				if (selection.parentElement().className == "tab") {
					selection.moveToElementText(selection.parentElement());
					selection.collapse(false);
					selection.move("character", 1);
				}
			}
		}
	}

    this.init = function (){
        this.editor.onscroll=function(){this.rte.tabstrip.scale.scrollLeft = this.scrollLeft;}
        this.editor.innerHTML = this.content;
        this.setEnabled(true);
		this.fireCaretUpdate();
		//this.select(0,0);
	}

    this.getSelection = function(){
        if (this.editor.document.selection.type != "Control"){
			this.selection = this.editor.document.selection.createRange();
			//if (this.selection.parentElement().className == "tab") 
            //    this.selection.move("character", 1);
            return this.selection;
		}
		return null;
	}
	
	this.format = function (cmd, param) {
        if (!this.editor.disabled) {
            this.editor.focus();
            if (cmd == "zoom")
				this.editor.style.zoom = param;
			else this.editor.document.execCommand(cmd, false, param);
		}
	}
	
	this.setFont = function(font){
		var selection = this.getSelection();
		var element = this.editor.document.createElement("span");
        element.innerHTML = selection.htmlText;
		for(var i=0; i < element.all.length; i++)
			element.all[i].style.fontFamily = font;
        element.style.fontFamily = font;
		selection.pasteHTML(element.outerHTML);
	}

    this.setFontSize = function(fontsize){
		var selection = this.getSelection();
		var element = this.editor.document.createElement("span");
        element.innerHTML = selection.htmlText;
        for(var i=0; i < element.all.length; i++)
			element.all[i].style.fontSize = fontsize;
        element.style.fontSize = fontsize;
		selection.pasteHTML(element.outerHTML);
	}
    
	function isParagraph (element){
		return  ("|DIV|P|TD|".indexOf("|" + element.tagName + "|") >= 0)
	}

	function isRoot(element){
		return element.tagName == "DIV" && element.className == "editor"
	}

	this.getParagraph = function(element){
		if (isParagraph(element) || isRoot(element.parentElement))
			return element;
		else return this.getParagraph(element.parentElement);
	}
	
	this.getParagraphs = function(selection){	  
        var parent = this.getParagraph(selection.parentElement());
        var paragraphs = new Array();
		for (var i = 0; i < parent.all.length; i ++){
			if (isParagraph(parent.all[i])){
				elementrange = parent.document.body.createTextRange();
				elementrange.moveToElementText(parent.all[i]);
				elementrange.collapse();
				if(selection.inRange(elementrange) || elementrange.inRange(selection)) 
					paragraphs.push(parent.all[i]);
			}
		}
		if(paragraphs.length == 0){
			paragraphs.push(parent);
		}
		return paragraphs;
	}
	
	this.showFormatDialog = function(paragraphs){
        this.FormatWindow.show([this, paragraphs], true);
	}

    var actcut = new Action(null, this, function(){this.target.format("cut")});
	var actcopy = new Action(null, this, function(){this.target.format("copy")});
	var actpaste = new Action(null, this, function(){this.target.format("paste")});
	var actundo = new Action(null, this, function(){this.target.format("undo")});
	
    var actformat = new Action("alt+enter", this, function(){
		var selection = this.target.getSelection();
		if(selection != null){
            var paragraphs = this.target.getParagraphs(selection);
            if(paragraphs.length > 0) this.target.showFormatDialog(paragraphs);
		}else if(this.target.selected != null) 
			this.target.showFormatDialog([this.target.selected]);
	});

	this.toolbar.addAction(actformat);
	
	this.getTD = function(element){
		if (isRoot(element)) return null;
		if (element.tagName == "TD") return element;
		else if (element.parentElement != null)
			return this.getTD(element.parentElement);
		else return null;
	}

    var actformattable = new Action(null, this, function(){
		var selection = this.target.getSelection();
		var cell = this.target.getTD(selection.parentElement());
		if (cell != null) this.target.showFormatDialog(cell.parentElement.parentElement.parentElement.cells);
	});

	var actformatrow = new Action(null, this, function(){
		var selection = this.target.getSelection();
		var cell = this.target.getTD(selection.parentElement());
		if (cell != null) this.target.showFormatDialog(cell.parentElement.cells);
	});

	var actformatcell = new Action(null, this, function(){
		var selection = this.target.getSelection();
		var cell = this.target.getTD(selection.parentElement());
		if (cell != null) this.target.showFormatDialog([cell]);
    });

	var acttable = new Action("alt+T", this, function(){
		this.target.TableWindow.show(this.target, true);
	});

	var actlink = new Action(null, this, function(){
		this.target.LinkWindow.show(this.target, true);
	});

	var actunlink = new Action(null, this, function(){
		var a = this.target.getSelection().parentElement();
		a.outerHTML = a.innerHTML;
	});

    this.caretUpdate = function(){
		var selection = this.getSelection();
		if (selection != null) {
			for (var i = 0; i < this.toolbar.items.length; i++) {
				if (this.toolbar.items[i].name != null) {
					if (this.toolbar.items[i].constructor == ToggleButton)
						this.toolbar.items[i].setState(selection.queryCommandValue(this.toolbar.items[i].name));
					else if (this.toolbar.items[i].constructor == OptionList)
						this.toolbar.items[i].selectItem(selection.parentElement().currentStyle[this.toolbar.items[i].name]);
				}
			}
		}
	}

	this.addCaretListener = function(listener){
		if (listener.caretUpdate == undefined)
			throw "RTEditor.addCaretListener: listener must implement caretUpdate()";
		this.caretlisteners.push(listener);
	}
	
	this.fireCaretUpdate = function(_event){
		for (var i = 0; i < this.caretlisteners.length; i ++) {
			this.caretlisteners[i].caretUpdate();
		}
	}
	
	this.onControlSelect = function(_event){
		this.selected = _event.srcElement;
	}
	
	this.onClick = function(_event){
		if(this.menu != null) this.menu.hide();
		if (this.selected != _event.srcElement)
			this.selected = null;
	}
	
	this.onDoubleClick = function(_event){
		if (_event.srcElement.tagName == "TABLE" || 
			(this.selected != null && this.selected.tagName == "TABLE")) {
			this.toolbar.actions["alt+T"].execute();
		}
	}
	
	this.onContextMenu = function(_event){
		var selection = this.getSelection();
		this.menu = new Menu();
		this.menu.addItem(new MenuItem("Undo", actundo));
		this.menu.addSeparator();
		this.menu.addItem(new MenuItem("Cut", actcut));
		this.menu.addItem(new MenuItem("Copy", actcopy));
		this.menu.addItem(new MenuItem("Paste", actpaste));
        if(selection.text != ""){
			this.menu.addSeparator();
			this.menu.addItem(new MenuItem("Hyperlink", actlink));
		}
		if(selection.parentElement().tagName == "A"){
			if(selection.text == "") this.menu.addSeparator();
			this.menu.addItem(new MenuItem("Unlink", actunlink));
		}
		this.menu.addSeparator();
		this.menu.addItem(new MenuItem("Format", actformat));
        var cell = null;
        if (selection != null) cell = this.getTD(selection.parentElement());
		if (cell != null) {
			if (this.selected == null)
				this.selected = cell.parentElement.parentElement.parentElement;
			this.menu.addItem(new MenuItem("Format Table", actformattable));
			this.menu.addItem(new MenuItem("Format Row", actformatrow));
			this.menu.addItem(new MenuItem("Format Cell", actformatcell));
			this.menu.addSeparator();
			this.menu.addItem(new MenuItem("Table", acttable));
		} 
        this.menu.draw(this.menucontainer, _event.x - 2, 
					   _event.y - 2);
	}

	this.editor.onclick = function(){this.rte.onClick(event);}
	this.editor.ondblclick = function(){this.rte.onDoubleClick(event);}
	//this.editor.onkeydown= function(){if (this.rte.toolbar.performAction(event))return false;}
	this.editor.onkeyup = function(){this.rte.fireCaretUpdate(event);}
	this.editor.onmouseup = function(){this.rte.fireCaretUpdate(event);}
    this.editor.oncontrolselect = function(){this.rte.onControlSelect(event);}
	this.editor.oncontextmenu = function(){this.rte.onContextMenu(event);return false;}


	this.find = function (word, mode) {
		var findrange = this.getSelection();
		if (mode & 1) findrange.setEndPoint("EndToStart", findrange);
		else findrange.setEndPoint("StartToEnd", findrange);
		var found = findrange.findText(word, 1000000000, mode);
		if (found) findrange.select();
		return found;
	}

	this.setHTML = function(html){
		this.editor.innerHTML = html;
	}

    this.getText = function () {
		var docmap = new Array();
        var text = getInnerText(this.editor, 0);
        this.docmap = docmap;
        return text;
        function getInnerText(element, position){
			var text = "";
			if (element.tagName == "SPAN" && element.className == "tab") return "\t";
			if (element.children.length > 0) {
				text += element.getAdjacentText("afterBegin");
				for (var i = 0; i < element.children.length; i ++)
					text += getInnerText(element.children[i], text.length + position) + element.children[i].getAdjacentText("afterEnd");
			} else text	= element.innerText;
			if (element.tagName == "TD" && element.nextSibling != null) text += "\t";
			if (element.tagName == "IMG") text += " ";
			if (isBlockTag(element)){
                text += "\n";
				if(docmap[position] == null) docmap[position] = element;
			}
			return text;
        }

		function isBlockTag(element){
			return  ("|P|DIV|BR|TH|TR|LI|H1|H2|H3|H4|H5|H6|H7|H8|".indexOf("|" + element.tagName + "|") >= 0)
		}
	}

	this.toggleCase = function(){
		var selection = this.getSelection();
		var content = selection.text;
		var isupper =  /[A-Z]/.test(content);
		if (isupper)
			selection.text = content.toLowerCase();
        else selection.text = content.toUpperCase();
		selection.select();
	}

	this.insertTab = function(){
		var selection = this.getSelection();
        var tabwidth = this.tabstrip.getTabWidth(selection.offsetLeft - 14);
		selection.pasteHTML("<span class=\"tab\" style = \"mso-tab-count:1;width:" + tabwidth + "px;\" onmove = \"this.style.width = this.document.rte.tabstrip.getTabWidth(this.offsetLeft) + 'px'\" unselectable = \"on\"/>");
	}
    
	this.resizeTabs = function(paragraph){
		this.tabstrip.setTabStops(paragraph);
        var tabs = paragraph.getElementsByTagName("span");
		for(var j = 0; j < tabs.length; j ++)
			if (tabs[j].className = "tab") 
				tabs[j].onmove();
	}

	this.toolbar.addAction(new Action("tab", this, function(_event){
		var selection = this.target.getSelection();
        var element = this.target.getTD(selection.parentElement());
		if (element != null){
			if(!_event.shiftKey){
				if(element.nextSibling != null)
					selection.moveToElementText(element.nextSibling);   
				else if(element.parentElement.nextSibling != null)
					selection.moveToElementText(element.parentElement.nextSibling.cells[0]);
				else{
					this.target.addCols(element.parentElement.parentElement.insertRow(), element.parentElement.cells.length);
					selection.moveToElementText(element.parentElement.nextSibling.cells[0]);
				}
			}else{
				if(element.previousSibling != null)
					selection.moveToElementText(element.previousSibling);   
				else if(element.parentElement.previousSibling != null)
					selection.moveToElementText(element.parentElement.previousSibling.cells[element.parentElement.previousSibling.cells.length - 1]);
			}
			selection.select();
		}
        else this.target.insertTab();
	}));

	this.addCols = function(tr, ncols){
		for (var j = 0; j < ncols; j ++) {
			var td = tr.insertCell();
			td.style.border = "dashed 1px";
		}
	}

	this.removeCols = function(tr, ncols){
		for (var j = 0;j < ncols; j++) {
			tr.cells[tr.cells.length - 1].removeNode(true);
		}
	}

	
	//new Action(null, this, 
	//			function(){
	//				function FindValues(findText, window, document){
	//					this.findText = findText;
	//					this.unsecuredWindowOfDocument = window;
	//					this.document = document;
	//				}
	//				if(this.findwindow == null || this.findwindow.closed)
	//                  this.findwindow = window.showModelessDialog("res://shdoclc.dll/find.dlg", new FindValues(this.target.getSelection().text, this.target.editor, this.target.editor.document), "dialogHeight:141px;dialogWidth:357px;scroll:no;status:no;");
	//this.findwindow = window.showModelessDialog(this.base + "/find.html", this.target, "dialogHeight:110px;dialogWidth:330px;scroll:no;status:no;help:no;");
	//          });
	this.toolbar.addAction(new Action("ctrl+R", this, 
									  function(){
									  if(this.replacewindow == null || this.replacewindow.closed)
									  this.replacewindow = this.target.ReplaceWindow.show(this.target, false);
									 }));
	var actspell = new Action("F7", this, function(){this.target.SpellingWindow.show(this.target, true)});
	this.toolbar.addSeparator();
	this.toolbar.addSeparator();
	//this.toolbar.addButton(new Button("print", null, "Print (Ctrl+P)", new Action("ctrl+P", this, function(){this.target.editor.print()})));
    this.toolbar.addButton(new Button("spell", null, "Spelling (F7)", actspell));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new Button("cut", null, "Cut", actcut));
	this.toolbar.addButton(new Button("copy", null, "Copy", actcopy));
	this.toolbar.addButton(new Button("paste", null, "Paste", actpaste));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new Button("undo", null, "Undo", actundo));
	this.toolbar.addButton(new Button("redo", null, "Redo", new Action(null, this, function(){this.target.format("redo")})));
	this.toolbar.addSeparator();
	//this.toolbar.addItem(new OptionList(null, "Zoom", ["Zoom", "200%","175%","150%","125%", "100%","75%","50%","25%","10%"],
	//				      new Action(null, this, function(){this.target.format("zoom", this.optionlist.value);})));
	this.toolbar.addItem(new OptionList("fontFamily", "Font" ,"Font", FONTS,
										new Action(null, this, function(){this.target.setFont(this.optionlist.value);})));
	this.toolbar.addItem(new OptionList("fontSize", null, "Size", FONT_SIZE, 
										new Action(null, this, function(){this.target.setFontSize(this.optionlist.value);})));
	//this.toolbar.addSeparator();
	//this.toolbar.addButton(new Button("togglecase", null, "Toogle Case", new Action(null, this, function(){this.target.toggleCase()})));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new ToggleButton("bold", null, "Bold", new Action(null, this, function(){this.target.format("bold")})));
	this.toolbar.addButton(new ToggleButton("italic", null, "Italic", new Action(null, this, function(){this.target.format("italic")})));
	this.toolbar.addButton(new ToggleButton("underline", null, "Underline", new Action(null, this, function(){this.target.format("underline")})));
	this.toolbar.addSeparator();
	var alignmentgroup = new Array();
	this.toolbar.addButton(new ToggleButton("justifyleft", null, "Align Left", new Action(null, this, function(){this.target.format("justifyleft")}), alignmentgroup));
	this.toolbar.addButton(new ToggleButton("justifycenter", null, "Align Center", new Action(null, this, function(){this.target.format("justifycenter")}), alignmentgroup));
	this.toolbar.addButton(new ToggleButton("justifyright", null, "Align Right", new Action(null, this, function(){this.target.format("justifyright")}), alignmentgroup));
	this.toolbar.addSeparator();
	var listgroup = new Array();
	this.toolbar.addButton(new ToggleButton("insertorderedlist", null, "Numbered List", new Action(null, this, function(){this.target.format("insertorderedlist")}), listgroup));
	this.toolbar.addButton(new ToggleButton("insertunorderedlist", null, "Bulleted List", new Action(null, this, function(){this.target.format("insertunorderedlist")}), listgroup));
	this.toolbar.addButton(new Button("decrease-indent", null, "Decrease Indent", new Action(null, this, function(){this.target.format("outdent")})));
	this.toolbar.addButton(new Button("increase-indent", null, "Increase Indent", new Action(null, this, function(){this.target.format("indent")})));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new Button("table", null, "Insert Table (Alt+T)", acttable));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new Button("options", null, "Options (Alt+O)", new Action("alt+O", this, function(){this.target.OptionsWindow.show([this.target, 0], true);})));
	this.toolbar.addSeparator();
	this.toolbar.addButton(new ToggleButton(null, "HTML", "View Source (Alt+H)", new Action("alt+H", this, function(){this.button.state ? this.target.editor.innerText = this.target.editor.innerHTML : this.target.editor.innerHTML = this.target.editor.innerText;})));
	this.toolbar.draw();
	this.addCaretListener(this);
	this.addCaretListener(this.tabstrip);
	this.init();
}
