function ChatEditor() {
	var _editor = null;
	
	var fontSize = 12;
	var fontName = "Arial";	
	var fontBold = false;
	var fontItalic = false;
	var underLine = false;
	var fontColor = "black";
	
	function getChatEditor() {
		return document.getElementById("InputAreaFrame").contentWindow; 
	}
	
	this.clear = function() {
		with (_editor.document) {
			if (document.all) {
			    body.innerHTML = "";
			    focus();
			} else {
				body.innerHTML = "<br>";	//firefox, or cursor not appear
			}
		}
	}
	
	this.getContent = function() {
		return _editor.document.body.innerHTML;
	}
	
	this.add = function(content) {
		_editor.document.body.innerHTML += content;
	}
	
	this.addKeyEvent = function(keyEvent) {
		if (!document.all && document.getElementById) {
	       _editor.document.addEventListener("keyup", keyEvent, true);
	    } else if (document.all) {
	       _editor.document.attachEvent("onkeyup", keyEvent);
	    }
	}
	
	this.getEditorStyle = function() {
		return "font-size:"+ fontSize + "px;font-family:'" + fontName + "';color:" + fontColor 
				+ ";font-weight:" + _editor.document.body.style.fontWeight 
				+ ";font-style:" + _editor.document.body.style.fontStyle 
				+ ";text-decoration:" + _editor.document.body.style.textDecoration;
	}
	
	this.applyStyle = function() {
		with(_editor.document.body) {
			style.fontSize = parseInt(fontSize);
			style.fontFamily = fontName;
			style.color = fontColor;
			if (fontBold) {
				style.fontWeight = "bold";
			} else {
				style.fontWeight = "";
			}
			if (fontItalic) {
				style.fontStyle = "italic";
			} else {
				style.fontStyle = "normal";
			}
			if (underLine) {
				style.textDecoration = "underline";
			} else {
				style.textDecoration = "none";
			}
		}
	}
	
	this.setFont=function(name,size) {
		fontName = name;
		fontSize = size;
		this.applyStyle();
	}
	
	this.setInitFontName=function(name) {
		fontName = name;
	}
	
	this.setFontBold=function() {
		fontBold = !fontBold;
		this.applyStyle();
		return fontBold;
	}
	
	this.setFontItalic=function() {
		fontItalic = !fontItalic;
		this.applyStyle();
		return fontItalic;
	}
	
	this.setUnderline=function() {
		underLine = !underLine;
		this.applyStyle();
		return underLine;
	}
	
	this.setFontColor=function(color) {
		fontColor = color;
		this.applyStyle();
	}
	
	this.init = function() {
	     _editor = getChatEditor(); 
	     _editor.document.open();
	     _editor.document.writeln("<html><head></head><body style='margin:2px;word-wrap:break-word'></body></html>");
	     _editor.document.close();
	     if (document.all) {
	     	_editor.document.designMode = "On";
	     } else {
	     	_editor.onfocus = function() {
				_editor.document.designMode = 'On';
			}
	     }
	     _editor.document.contentEditable = true;
	     _editor.document.charset="UTF-8";
	}
}

var _chatEditor = new ChatEditor();
