/**
 * @fileoverview
 * cafenEditor v21 레인에디터의 각종 함수입니다.
 * 당 프로그램의 저작권은 http://cafen.net (outmind@cafen.net)에 있습니다
 * 당 프로그램의 수정 후 재 배포는 저작권자의 허락을 득한 후 재배포 할수 있습니다. 
 * 당 프로그램의 이용은 비 상업적인 목적의 경우 무료로 이용할 수 있습니다.
 * 당 프로그램의 이용은 상업적인 목적의 경우 저작권자의 허락을 득한 후 이용할 수 있습니다.
 * 당 프로그램의 설치후 관리자는 outmind@cafen.net 으로 설치하였다는 통보 메일을 발송하여야 합니다.
 * 당 프로그램안에 있는 모든 저작권 표시 영역은 수정할수 없습니다.
 *
 * ------------------------------------------------
 * 설치 방법은 함께 배포된 README 파일 참조 바랍니다.
 * ------------------------------------------------
 *
 * @author Kimjonggab(outmind@cafen.net)
 * @copyright Copyright (c) 2004 Cafen.net (http://cafen.net)
 */

if (typeof SWFUpload == 'undefined') {
	if (cafen.srartLoad) {
		cafen.srartLoad(_cafen_service_url+'swfupload.js');
	} else {
		document.write('<scr'+'ipt TYPE="text/JavaScript" charset="utf-8" LANGUAGE="JavaScript1.2" SRC="'+_cafen_service_url+'swfupload.js"></scr'+'ipt>');
	}
}

/**
 * cafenEditor_loader 
 * 레인 에디터 적재 프로그램
 */

var cafenEditor_loader = {
/**
 * 레인 에디터 환경변수
 * @type object
 */
	editorBaseConf : {
		editorURL : _cafen_service_url,
		imageURL : _cafen_service_url + 'images/',
		uploadSCRIPT : null,
		downloadSCRIPT : null,
		uploadURL : cafen.getDomain() +'uploads/',
		uploadedURL : null,
		uploadDOMAIN : cafen.getDomain(),
		callbackURL : '',
		editorClassName : 'cafenEditorContents',
		editorStyleSheet : _cafen_service_url +'images/blank.css',
		maxUploadSize : 1024*1024*5,
		maxMovieSize : 1024*1024*20,
		maxFileBoxSize : 1024*1024*1,
		singleUploadSize : Math.round(1024*1024*1.5),
		maxFileBoxCnt : 50,
		toolbarset : 'auto',
		mobiletoolbarset : 'mobile',
		middlebarset : 'base',
		middlebarontop : false,
		xmlParse : false,
		usesimpleparser : true,
		useFilebox : true,
		useMediaPlayer : true,
		useImageEditor : true,
		useFlashChart : false,
		useStaticMap : false,
		mediaPlayer : {
			logo : _cafen_service_url +'images/logo_media.png',
			backColor : '0x000000',
			frontColor : '0xccCCCC'
		},
		attachAs : false,
		useWebFont :[],
		useDivColor : [],
		useEmoticon : [],
		useStyle : [],
		addedCSS : [],
		toolbarSet : {},
		middlebarSet : {},
		skinSet : {},
		Plugin : {}
	},
/**
 * 레인 에디터 환경변수 체크 여부
 * @type boolean
 */
	cafeneditor_check	: false,
/**
 * 레인 에디터 객체 적재
 * @type array
 */
	childNodes : [],
/**
 * Popup 오프젝트
 * @type class
 */
	out_popupobj : null,
/**
 * Popup 오프젝트 콜백
 * @type function
 */
	out_callback : function() {},
/**
 * 이미지 싸인
 * @type string
 */
	img_sign : '',
	navigator_check : null,
	checkNavigator : function() {
		if (this.navigator_check == null) {
			if (navigator.userAgent.indexOf('MSIE') > 0) {
				var ie_version = parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE') + 5, navigator.userAgent.indexOf('MSIE') + 8));
				this.navigator_check = (ie_version < 5.5) ? false : true;
			} else
				this.navigator_check = true;
			
		}
		return this.navigator_check;
	},
/**
 * 에디터 환경 체크
 * @return {boolean}
 */
	check : function() {
		if (this.cafeneditor_check) {
			return true;
		} else {
			if (typeof cafenGlobalConf != 'undefined')
				this.editorBaseConf = cafen.extend(this.editorBaseConf,cafenGlobalConf);
				if (this.editorBaseConf.uploadedURL == null)
					this.editorBaseConf.uploadedURL = this.editorBaseConf.uploadURL;
			if (this.editorBaseConf.editorURL == null) {
				this.showMsg('설치 안내',' cafenGlobalConf.editorURL 이 설정되지 않았습니다.');
				return false;
			} else if (!this.checkNavigator()) {
				return false;
			} else {
				if (this.editorBaseConf.useWebFont.length > 0) {
					var addedStyle = [];
					var webfont_Classid = cafenMsg.getObject('ed_webfont');
					for(var i =0; i < this.editorBaseConf.useWebFont.length; i++) {
						var webFont = this.editorBaseConf.useWebFont[i];
						cafenMsg.add('ed', 'fontnames', {title : webFont.title, font : webFont.family});
						cafenMsg.add('ed', 'aliasfontnames',webFont.title,webFont.family);
						if (webfont_Classid[webFont.family] != undefined && webfont_Classid[webFont.family] != null)
							cafenMsg.add('ed', 'aliasfontnames',webFont.title,webfont_Classid[webFont.family]);
						this.editorBaseConf.addedCSS.push("@font-face {font-family:"+webFont.family+"; src:url("+webFont.url+");}");
					}
				}
				if (this.checkDomain()) {
					cafen.Editor.Upload.base_upload_script = this.editorBaseConf.uploadSCRIPT;
					cafen.Editor.Upload.base_upload_url = this.editorBaseConf.uploadURL;
					cafen.Editor.Upload.base_uploaded_url = this.editorBaseConf.uploadedURL;
					cafen.Editor.Upload.base_upload_domain = this.editorBaseConf.uploadDOMAIN;
					cafen.Editor.Upload.flash_path = this.editorBaseConf.imageURL;
					cafen.Editor.Upload.base_image_url = this.editorBaseConf.imageURL;
					cafen.Editor.baseConf._editor_url = this.editorBaseConf.editorURL;
					cafen.Ajax_basexmlurl = this.editorBaseConf.uploadSCRIPT;
					cafen.Editor.Upload.use_mediaplayer = this.editorBaseConf.useMediaPlayer;
					cafen.Editor.Upload.use_imageeditor = this.editorBaseConf.useImageEditor;
					cafen.Editor.Upload.mediaplayer_info = this.editorBaseConf.mediaPlayer;
					cafen.SwfUpload.singleupload_max = Math.min(this.editorBaseConf.singleUploadSize,this.editorBaseConf.maxUploadSize);
				} else {
					cafen.Editor.Upload.base_upload_script = '';
					cafen.Editor.Upload.base_upload_url = '';
					cafen.Editor.Upload.base_upload_domain = '';
					cafen.Editor.Upload.flash_path = '';
					cafen.Editor.Upload.base_image_url = '';
					cafen.Editor.baseConf._editor_url = '';
					cafen.Editor.Upload.use_mediaplayer = '';
					cafen.Editor.Upload.use_imageeditor = '';
					cafen.Editor.Upload.mediaplayer_info = '';
					cafen.SwfUpload.singleupload_max = 0;
				}
				cafen.Editor.baseConf.toolbarskin = cafen.extend(cafen.Editor.baseConf.toolbarskin, this.editorBaseConf.toolbarSet);
				cafen.Editor.baseConf.middlebarskin = cafen.extend(cafen.Editor.baseConf.middlebarskin, this.editorBaseConf.middlebarSet);
				cafen.Editor.baseConf.skin = cafen.extend(cafen.Editor.baseConf.skin, this.editorBaseConf.skinSet);
				if (this.editorBaseConf.useFlashChart && cafenGlobalConf.ofc_swfurl == null || cafenGlobalConf.ofc_swfurl == '')
					this.editorBaseConf.useFlashChart = false;
				this.cafeneditor_check = true;
				return true;
			}
		}
	},
/**
 * 업로드 스크립터 체크
 * @return {string} 업로드 파일 위치
 */
	getUploadScript : function() {
		if (_editor_url.indexOf('http://') == 0 || _editor_url.indexOf('/') == 0) 
			return _editor_url ;
		else {
			return document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/') + 1) +_editor_url;
		}
	},
/**
 * 크로스 도메인 체크
 * @return {boolean} true|false
 */
	checkDomain : function() {
		this.checkCallBack()
		this.checkUploadURL();
		if (this.editorBaseConf.uploadSCRIPT == null || this.editorBaseConf.uploadSCRIPT == '')
			return false;
		else if (this.editorBaseConf.uploadSCRIPT.indexOf('http://') == 0) {
			return true;
		} else {
			if (this.editorBaseConf.uploadSCRIPT.indexOf('/') != 0) {
				var theUrl = window.location.href.split('/'); 
				theUrl.pop(); 
				theUrl.push(this.editorBaseConf.uploadSCRIPT); 
				this.editorBaseConf.uploadSCRIPT = theUrl.join('/'); 
			}
			return true;
		}
	},
	checkUploadScript : function() {
		if (this.editorBaseConf.uploadSCRIPT == null || this.editorBaseConf.uploadSCRIPT == '')
			return false;
		else
			return true;
	},
/**
 * CallBack 체크
 * @return {boolean}
 */
	checkCallBack : function() {
		if (this.editorBaseConf.callbackURL.indexOf('http://') == 0) 
			return true;
		else if (this.editorBaseConf.callbackURL.indexOf('/') == 0) {
			this.editorBaseConf.callbackURL = cafen.nodeUtil.getDomain() + this.editorBaseConf.callbackURL;
			return true;
		} else if (this.editorBaseConf.callbackURL != '') {
			var theUrl = window.location.href.split('/'); 
			theUrl.pop(); 
			theUrl.push(this.editorBaseConf.callbackURL); 
			this.editorBaseConf.callbackURL = theUrl.join('/'); 
			return true;
		}
	},
/**
 * UploadScript 체크
 * @return {boolean}
 */
	checkUploadURL : function () {
		if (this.editorBaseConf.uploadURL.indexOf('http://') == 0) 
			return true;
		else if (this.editorBaseConf.uploadURL.indexOf('/') == 0) {
			this.editorBaseConf.uploadURL = cafen.getDomain() + this.editorBaseConf.uploadURL;
			return true;
		} else if (this.editorBaseConf.uploadURL != '') {
			var theUrl = window.location.href.split('/'); 
			theUrl.pop(); 
			theUrl.push(this.editorBaseConf.uploadURL); 
			this.editorBaseConf.uploadURL = theUrl.join('/'); 
			return true;
		}
	},
	msgShown : false,
/**
 * 메세지 보이기
 * @param {string} msg 보일 메세지
 */
	showMsg : function(title, msg) {
		if (!this.msgShown) {
			msg = msg.replace(/<br>/gi,'\r\n');
			if (typeof msg.stripTags == 'function')
				msg = msg.stripTags();
			var html = 'Editor [' + title + ']\r\n'
				+ '--------------------------------------------------------------------------------------\r\n'
				+ msg + '\r\n'
				+ '--------------------------------------------------------------------------------------\r\n';
			alert(html);
			this.msgShown = true;
		}
	},
/**
 * 레인에디터 적재
 * @param {object} objname 객체명
 * @param {object} userConfig 환경파일
 */
 	load : function(objname, userConfig) {
 		var obj = null;
		if (this.checkNavigator()) {
			obj = new cafen.Editor(objname, userConfig);
			this.childNodes.push({obj:obj,name:objname});
		} else 
			obj = null;
		return obj;
	},
/**
 * 레인에디터 객체 가져오기
 * @param {string} objname 가져올 객체명
 * @return {cafen.Editor} 에디터 객체
 */
	get : function(objname) {
		for(var i = 0; i < this.childNodes.length; i++) {
			if (obj.name == objname) {
				return obj;
				break;
			}
		}
		return null;
	}
}


/**
 * cafenEditor 
 * 레인 에디터 이전 버전과 호환 프로그램
 * @param {string} objname 연결 Object ID
 * @param {object} userConfig 에디터 환경변수
 */
function cafenEditor(objname, userConfig) {
	if (navigator.userAgent.indexOf('MSIE') > 0) {
		var ie_version = parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE') + 5, navigator.userAgent.indexOf('MSIE') + 8));
		if (ie_version < 5.5) 
			return ;
	}
	switch(userConfig) {
		case 'E' : 
			return cafenEditor_loader.end(objname);
			break;
		case 'F' : 
			cafenEditor_loader.focus(objname);
			break;
		default :
			return cafenEditor_loader.load(objname, userConfig);
			break;
	}
}


/**
 * @class cafenEditor class
 * @constructor 
 * @param {string} editor_url 에디터의 기본경로
 * @param {string} editor_url_xml 에디터의 기본경로
 * @param {string} editor_url_image 에디터의 기본경로
 * @param {string} base_serverscript 에디터의 기본경로
 */

function cafenEditor(editor_url, editor_url_image, base_upload_url, base_upload_script, editor_callback) {
	if (editor_url != null)
		_editor_url = editor_url;
	if (editor_url_image != null)
		_editor_url_image = editor_url_image;
	if (base_upload_url != null)
		_base_upload_url = base_upload_url;
	if (base_upload_script != null)
		_base_upload_script = base_upload_script;
	if (editor_callback != null)
		_editor_url_callback = editor_callback;
}

cafenEditor.prototype = {
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	render : function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (element != null)
				this._renderElement(element);
		}
	},
	renderElements : function(renderObjs) {
		for(var i=0; i < renderObjs.length; i++) 
			this.renderElement(renderObjs[i]);
	},
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	renderElement : function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (element != null)
				this._renderElement(element);
		}
	},
/**
 * 에디터 랜드링하기
 * @param {object}
 */
	_renderElement : function(editorObj) {
		if (typeof editorObj.parse != 'undefined')
			return ;
		cafenEditor_loader.check();
		var textAttribObj = new cafen.Attribute(editorObj);
		var config = {
			width : textAttribObj.get('width',editorObj.offsetWidth),
			height : textAttribObj.get('height',editorObj.offsetHeight),
			attachfile_max : textAttribObj.getInt('attachfile_size',cafenEditor_loader.editorBaseConf.maxUploadSize),
			attachfile_cnt : textAttribObj.getInt('attachfile_cnt',0),
			onefile_max : textAttribObj.getInt('onefile_size', cafenEditor_loader.editorBaseConf.singleUploadSize),
			attachfile_type : textAttribObj.get('attachfile_type','all'),
			toolbarset : textAttribObj.get('toolbar',''),
			toolbartext : textAttribObj.get('toolbartext',''),
			mobiletoolbarset : textAttribObj.get('mobiletoolbar',''),
			mobiletoolbartext : textAttribObj.get('mobiletoolbartext',''),
			mobleui : textAttribObj.getBoolean('mobleui',null),
			divui : textAttribObj.getBoolean('divui',false),
			middlebarset : textAttribObj.get('middlebar',''),
			swaptab : textAttribObj.getBoolean('swaptab',true),
			allowiframe : textAttribObj.getBoolean('allowiframe',false),
			attachAs : textAttribObj.getBoolean('attachas','null'),
			topmenu :textAttribObj.get('topmenu','HSTAP'),
			useAutoParse :textAttribObj.getBoolean('autoparse',true),
			mode : textAttribObj.get('mode','H'),
			attachfile_mode : textAttribObj.getBoolean('attach',true),
			max_length : textAttribObj.getInt('max_length',65535),
			showattachsize :textAttribObj.getInt('showattachsize',2),
			linktitle : textAttribObj.get('linktitle',''),
			skin : textAttribObj.get('skin','white'),
			img_sign : textAttribObj.get('usesign',''),
			file_box : textAttribObj.get('filebox',''),
			autosave : textAttribObj.getInt('autosave',0),
			canbe_null : textAttribObj.getBoolean('canbenull',false) ,
			canbe_resize : textAttribObj.getBoolean('resize',true) ,
			maxpageheight : textAttribObj.getInt('maxpageheight',0) ,
			p2br : textAttribObj.getBoolean('p2br',false) ,
			maxpagewidth : textAttribObj.getInt('maxpagewidth',0) ,
			onready : textAttribObj.get('onready','') ,
			parsewithoutattach : textAttribObj.getBoolean('parsewithoutattach',false) ,
			statusoff : textAttribObj.getBoolean('statusoff',false) ,
			onloadfocus : textAttribObj.getBoolean('onloadfocus',true) ,
			onloadhidetoolbar : textAttribObj.getBoolean('onloadhidetoolbar',false) ,
			use_unloadevent : textAttribObj.getBoolean('unloadevent',false),
			simpleParse : textAttribObj.getBoolean('simpleparser','null')
		};
		var obj = cafenEditor_loader.load(editorObj, config);
		if (obj == null) {
			editorObj.insertHTML = function() {}
			editorObj.isEditable = function() { return false;}
			editorObj.parse = function() { return (this.value.split(' ').join('') != '')? true : false;}
			editorObj.setUnload = function(bl) {}
			editorObj.getContents = function() { return this.value}
			editorObj.getAttach = function() { return ''; }
			editorObj.getAttachSize = function() { return 0; }
			editorObj.getAttachCnt = function() { return 0; }
			editorObj.getAttachImage = function() { return 0; }
		}
	},
	/**
	* render Elements by className
	* @param {string}  className The class name of the Object to do render
	*/
	renderElementsByClassName : function(className) {
		var objs = document.getElementsByTagName('textarea');
		var editorObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) 
				editorObjs.push(child);
		}
		this.renderElements(editorObjs);
	},
	/**
	* render Elements by id
	* @param {string}  id The id of the Object to do render
	*/
	renderElementsById : function(id) {
		if (document.getElementById(id) != null) {
			var editorObjs = [];
			var objs = document.getElementsByTagName(document.getElementById(id).tagName);
			for(var i=0;i<objs.length;i++){
				if(objs[i].id==id) 
					editorObjs.push(objs[i]);
			}
			this.renderElements(editorObjs);
		}
	},
	/**
	* render Elements by className
	* @param {string}  className The class name of the Object to do render
	*/
	renderElementsByName : function(objName) {
		var objs = document.getElementsByTagName('textarea');
		var editorObjs = [];
		for(var i =0; i < objs.length; i++) {
			var child = objs[i];
			if (child.getAttribute('name') == objName) 
				editorObjs.push(child);
		}
		this.renderElements(editorObjs);
	}
}

cafen.Editor = function(id, config) {
	this.setOptions({name : 'rainEditor', tag : 'div', attribute :{className:'r_div'}, style : {width :'auto', height:'auto'}});
	this.initEditor(id, config);
}

cafen.Editor.prototype = cafen.extendClass({
	version : 'E21',
	_pageBreak : '<!-- page -->',
	initEditor : function(id, config) {
		cafen.getMonitor(this.version);
		this.obj = cafen.$(id);
		this.pageContents = [];
		this.isloaded = false;
		if (!cafenEditor_loader.check()) {
			this.obj.insertHTML = function() {};
			this.obj.isEditable = function() {return false};
			this.obj.parse = function() {return true;};
			this.obj.setUnload = function() {};
			this.obj.getContents = function() {return this.value;};
			this.obj.getAttach = function() {};
			this.obj.getAttachSize = function() {};
			this.obj.getAttachCnt = function() {};
			this.obj.getAttachImage = function() {};
			this.obj.setMode = function() {};
			this.obj.setSize = function(w, h) {this.style.width = w+'px';this.style.height = h+'px';}
			this.setDesignModeBind = function() {};
			return ;	
		}
		cafen.checkStyle();
		this._editorObject = {};
		try {
			this.obj.parentNode.insertBefore(this.getElement(), this.obj);
		} catch(ex) {
			this.obj.insertAdjacentElement("beforeBegin",this.getElement())
		}
		this.initConfig = config;
		this.config = new cafen.Editor.Config(this, config);
		this.conf = new cafen.Editor.conf(this.config.color_info);
		this.obj.style.display = 'none';
		this.setTabObject();
		this._editorObject.editorPopup = new cafen.XWindow();
		this.appendChild(this._editorObject.editorPopup);
		this._editorObject.TopMenuFrm = new cafen.TableAuto({attribute :{width : this.config.width +'px', border : 0}});
		this.setStyle({width : this.config.width +'px', height:'auto'});
		this.appendChild(this._editorObject.TopMenuFrm);
		this._tabObj = new cafen.XTabMenu(this.tab_info);
		this._editorObject.TopMenuFrm.addCell(this._tabObj);
		this._editorObject.TopMenuFrm.addStyle({textAlign:'left'});
		this._editorObject.saveObj = this._editorObject.TopMenuFrm.addCell();
		this._editorObject.TopMenuFrm.addStyle({padding:'0 0 3px 0'});
		if (this.config.file_box != '') {
			this._editorObject.saveObj.attachEvent('click', this.getSavedDoc.bind(this));
			this._editorObject.TopMenuFrm.addText('(0)');
			this._editorObject.TopMenuFrm.addStyle({width: '120px', textAlign:'right', cursor : cafen.getCursor()});
		} else {
			this._editorObject.TopMenuFrm.addText('&nbsp;');
			this._editorObject.TopMenuFrm.addStyle({width: '120px', textAlign:'right'});
		}
		this._editorObject.editorSkin = new cafen.TableAuto({className : this.conf.getClassName('box'), tplName : (this.config.statusoff) ? '' : 'bottom', attribute : {width : this.config.width}, style : {width :(this.config.width) +'px', height : 'auto', marginBottom:'1px'}});
		this.appendChild(this._editorObject.editorSkin);
		this._editorObject.buttonAreaSkin = new cafen.Div({className : this.conf.getClassName('buttonarea'), align:'left', attribute : {border:0},style : {width:(this.config.width -6) +'px', overflowX : 'hidden'}});
		this._editorObject.editorSkin.addRow(this._editorObject.buttonAreaSkin);
		this._editorObject.buttonAreaOut = new cafen.TableAuto({align:'left', attribute : {border:0},style : {width:(this.config.width -6) +'px'}});
		this._editorObject.buttonAreaSkin.appendChild(this._editorObject.buttonAreaOut);
		this._editorObject.buttonArea = new cafen.Div({align:'left', attribute : {border:0},style : {width:(this.config.width -29) +'px', overflowX: 'hidden'}});
		this._editorObject.buttonAreaOut.addCell(this._editorObject.buttonArea);
		this._editorObject.buttonAreaOut.addStyle({width: (this.config.width -29) +'px'});
		this._editorObject.buttonToggle = new cafen.XIcon({icon:'r_winset', off :60, on : 14,  over :45, style:{width: '15px', height: '14px'}, event:{click : this.toggleToolBar.bind(this)}, attribute : {title : 'Ctrl + T'}})
		this._editorObject.buttonAreaOut.addCell(this._editorObject.buttonToggle);
		this._editorObject.buttonAreaOut.addStyle({width:'17px', verticalAlign: 'bottom', textAlign:'right'});
		this.drawToolbar();
		this._editorObject.editorDumy = this._editorObject.frmSkin = new cafen.Div({className :this.conf.getClassName('editorarea'), style : {textAlign:'center', marginTop:'3px', marginBottom:'3px'}});
		this._editorObject.editorSkin.addRow(this._editorObject.frmSkin);
		if (this.config.useDivUI) 
			this._editorObject.htmlEditor = new cafen.divEditable({style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px'}, attribute : {}});
		else
			this._editorObject.htmlEditor = new cafen.Iframe({style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px'}, attribute : {frameBorder:0, allowTransparency:true}});
		this._editorObject.htmlEditor.setStyle(this.conf.editorStyle(this.config.width -2,this.config.editor_height,'block',0));
		var guideline_style = '';
		if (this.config.maxpageheight > 0) {
			cafen.Editor.Upload.baseLimitSize = {
				width : parseInt(this.config.maxpagewidth),
				height : parseInt(this.config.maxpageheight)
			}
			guideline_style = 'BODY {	background-image:url('+_cafen_service_url+'images/guideline.gif);background-repeat:repeat-x;background-position:0 '+this.config.maxpageheight+'px;}';
		}
		this.htmlskin = "<html><head><meta http-equiv=Content-Type content='text/html;charset=utf-8'><link href='"
			+cafenEditor_loader.editorBaseConf.editorStyleSheet +'?'+cafen.getUniqID('css')
			+ "' type='text/css' rel='stylesheet' /><style>"+cafenEditor_loader.editorBaseConf.addedCSS.join('')+guideline_style+"</style><script>window.onerror = function() {return false;}</script></head><body spellcheck='false' topmargin=5 leftmargin=5 style='position:relative'>"
			+ "<p></p></body></html>";
		this._editorObject.frmSkin.appendChild(this._editorObject.htmlEditor);
		this._editorObject.htmlEditor.initDoc(this.htmlskin, true);
		this._editorObject.textEditor = new cafen.Textarea({style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px', border : '0 none', overflowX : 'hidden', overflowY : 'auto'}, attribute : {cols : '60', rows : '10'}});
		this._editorObject.textEditor.setStyle(this.conf.editorStyle(this.config.width,this.config.height,'none', 0));
		this._editorObject.frmSkin.appendChild(this._editorObject.textEditor);
		if (this.config.useDivUI)
			this._editorObject.previewEditor = new cafen.divEditable({style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px'}, attribute : {}});
		else
			this._editorObject.previewEditor = new cafen.Iframe({style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px'}, attribute : {frameBorder:0, allowTransparency:true}});
		var preview_addStyle = cafenEditor_loader.editorBaseConf.addedCSS;
		preview_addStyle.push('marquee, table {border:0}');
		preview_addStyle.push('.morecontents {display:none}');
		this.previewskin = "<html><head><meta http-equiv=Content-Type content='text/html;charset=utf-8'><link href='"
			+cafenEditor_loader.editorBaseConf.editorStyleSheet
			+ "' type='text/css' rel='stylesheet' /><style>"+preview_addStyle.join('')+"</style><script>window.onerror = function() {return false;}</script><base target='_blank' /></head><body topmargin=5 leftmargin=5>"
			+ "<p></p></body></html>";
		this._editorObject.frmSkin.appendChild(this._editorObject.previewEditor);
		this._editorObject.previewEditor.initDoc(this.previewskin);
		this._editorObject.previewEditor.setStyle(this.conf.editorStyle(this.config.width -2,this.config.height,'none', 0));
		try {
			cafen.setStyle(this._editorObject.previewEditor.getRealObject(),this.conf.editorScroll());
		} catch(ex) {}
		if (this.config.attachfile_max > 0) {
			this._editorObject.AttachAreaOut = new cafen.TableAuto({className : this.conf.getClassName('buttonarea'), align:'left', attribute : {border:0},style : {width:(this.config.width -6) +'px', position : 'relative'}});
			this._editorObject.editorSkin.addRow(this._editorObject.AttachAreaOut);
			this._editorObject.editorSkin.addStyle({paddingBottom:'3px'});
			this._editorObject.AttachAreaOut.addRow();
			this._editorObject.editorAttachArea = new cafen.TableAuto({align:'left', attribute : {border:0},style : {width:(this.config.width -29) +'px', position : 'relative'}});
			this._editorObject.AttachAreaOut.addCell(this._editorObject.editorAttachArea);
			this._editorObject.attachToggle = new cafen.XIcon({icon:'r_winset', off :60, on : 14,  over :45, style:{width: '15px', height: '14px'}, event:{click : this.toggleAttach.bind(this)}})
			this._editorObject.AttachAreaOut.addCell(this._editorObject.attachToggle);
			this._editorObject.AttachAreaOut.addStyle({width:'17px', verticalAlign: 'bottom'});
		}
		if (this.config.canbe_resize) {
			this._editorObject.resizeButton = new cafen.XButton(
				{
					attribute : {className : 'r_winset', innerHTML : '&#160;'},
					style : {backgroundRepeat: 'no-repeat', backgroundPosition: 'center -203px', width :this.config.width +'px', height : '8px', fontSize : '1px', overflow : 'hidden', textAlign : 'center', padding:'0', margin : '0'},
					className : this.conf.getClassName('attachbutton'),
					event : {mousedown : this.resizeStart.bind(this)}
				});
			this.appendChild(this._editorObject.resizeButton);
		}
		if (!this.config.statusoff) {
			if (!cafen.getLicence()) {
				var tmpStatus = new cafen.TableAuto({attribute:{width:'100%', border : 0}});
				tmpStatus.addRow();
				this._editorObject.statusObj = new cafen.Div({attribute : {innerHTML :''}, style: { fontSize : '12px', lineHeight:'100%',paddingTop:'3px', width : (this.config.width - 106) + 'px' , overflowX : 'hidden', wordBreak:'keep-all'}});
				tmpStatus.addCell(this._editorObject.statusObj);
				this._editorObject.copyrightObj = tmpStatus.addCell();
				tmpStatus.addStyle({textAlign:'right', width : '90px',lineHeight:'100%'});
				this._editorObject.editorSkin.appendChild(tmpStatus, 'bottom');
			} else {
				this._editorObject.statusObj = new cafen.Div({attribute : {innerHTML :''}, style: {fontSize : '12px', lineHeight:'100%', paddingTop:'3px', width : (this.config.width -6)+ 'px' , overflowX : 'hidden'}});
				this._editorObject.editorSkin.appendChild(this._editorObject.statusObj, 'bottom');
			}
		}
		if (this._editorObject.editorAttachArea != null)
			this.drawAttachMenu();
		this.obj.insertHTML = this.insertHTMLOUT.bind(this);
		this.obj.setDoc = this.setDoc.bind(this);
		this.obj.reset = this.resetDoc.bind(this);
		this.obj.getPageHeight = this.getDocHeight.bind(this);
		this.obj.getPageWidth = this.getDocWidth.bind(this);
		this.obj.changeStyle = this.changeStyle.bind(this);
		this.obj.addPage = this.addPage.bind(this);
		this.obj.preview = this.previewDoc.bind(this);
		this.obj.getConfig = this.getConfig.bind(this);
		this.obj.getEditor = this.getEditor.bind(this);
		this.obj.movePage = this.movePage.bind(this);
		this.obj.checkPage = this.checkPage.bind(this);
		this.obj.deletePage = this.deletePage.bind(this);
		this.obj.getPageContents = this.getPageContents.bind(this);
		this.obj.getPageCnt = this.getPageCnt.bind(this);
		this.obj.getPageCurrent = this.getPageCurrent.bind(this);
		this.obj.savePage = this.savePage.bind(this);
		this.obj.isEditable = this.checkMode.bind(this);
		this.obj.parse = this.end.bind(this);
		this.obj.setUnload = this.setloadUnload.bind(this);
		this.obj.getContents = this.getContents.bind(this);
		if (this.editorAttachView != null) {
			this.obj.getAttach = this.editorAttachView.parse.bind(this.editorAttachView);
			this.obj.getAttachSize = this.editorAttachView.getAttachSize.bind(this.editorAttachView);
			this.obj.getAttachCnt = this.editorAttachView.getAttachCnt.bind(this.editorAttachView);
			this.obj.getAttachImage = this.editorAttachView.getImageCnt.bind(this.editorAttachView);
		} else {
			this.obj.getAttach = function() {};
			this.obj.getAttachSize = function() {};
			this.obj.getAttachCnt = function() {};
			this.obj.getAttachImage = function() {};
		}
		this.obj.setMode = this.modeSwap.bind(this);
		this.obj.setSize = this.setSize.bind(this);
		this.obj.hasContents = this.hasContents.bind(this);
		this.setDesignModeBind = this.setDesignMode.bind(this);
		this.setDesignMode();
		if (this.config.use_unloadevent) 
			this.setloadUnload(true);
		if (this.obj.form != null) {
			if (!(this.obj.form.submitqueue instanceof Array)) 
				this.obj.form.submitqueue = [];
			this.obj.form.submitqueue.push(this.end.bind(this));
			
			if (typeof this.obj.form.onsubmit == 'function' && this.obj.form.oldonsubmit == null) {
				this.obj.form.oldonsubmit = this.obj.form.onsubmit;
				this.obj.form.onsubmit = null;
			} else if (this.obj.form.oldonsubmit == null) {
				this.obj.form.oldonsubmit = function() {return true;};
				this.obj.form.onsubmit = null;
			}
			if (this.obj.form.onsubmit == null) {
				this.obj.form.onsubmit = function() {
					if (this.submitqueue.length > 0) {
						for(var i = 0; i < 	this.submitqueue.length; i++) {
							if (!this.submitqueue[i]())
								return false;
						}
					}
					if (this.oldonsubmit != null)
						return this.oldonsubmit();
					else
						return true;
				}
			} 
		}
	},
	changeStyle : function(stylecss) {
		this._editorObject.htmlEditor.changeStyle(stylecss);
		if (this._editorObject.previewEditor != null) 
			this._editorObject.previewEditor.changeStyle(stylecss);
		cafenEditor_loader.editorBaseConf.editorStyleSheet = stylecss;
	},
	getConfig : function(val) {
		if (this.config[val] != null)
			return this.config[val];
		else
			return '';
	},
	getEditor : function() {
		return this;
	},
	previewDoc : function(options) {
		var htmls = this.getPageContents();
		if (htmls != '') {
			options = cafen.extend({width :this.config.width -6, height: this.config.maxpageheight , top: 5, right : 5, bottom : 5, left : 5 , bg :''}, options || {});
			new cafen.EditorViewer(htmls, options);
		}
	},
	addPage : function() {
		if (this.checkPageMode() && this.savePage()) {
			this.currentPage++;
			this.pageContents.push('');
			this.setContents(this.pageContents[this.currentPage]);
			return true;
		} else 
			return false;
	},
	movePage : function(num) {
		if (this.checkPageMode() && this.savePage() && num <= this.getPageCnt()) {
			this.currentPage = num -1;
			this.setContents(this.pageContents[this.currentPage]);
			return true;
		} else
			return false;
	},
	deletePage : function(num) {
		if (this.checkPageMode()) {
			var delPage = (num != null) ? (num -1 ) : this.currentPage;
			var newPageContents = [];
			for(var i = 0 ; i < this.pageContents.length; i++)
				if (i != delPage)
					newPageContents.push(this.pageContents[i]);
			if (newPageContents.length > 0) {
				this.pageContents = newPageContents;
				if (this.currentPage >= this.pageContents.length)
					this.currentPage--;
				this.setContents(this.pageContents[this.currentPage]);
				return true;
			} else
				return false;
		} else
			return false;
	},
	getPageContents : function() {
		if (this.checkPageMode()) {
			if (this.savePage()) {
				var newPageContents = [];
				for(var i = 0 ; i < this.pageContents.length; i++)
					if (cafen.html2Text(this.pageContents[i]) != '')
						newPageContents.push(this.pageContents[i]);
				if (newPageContents.length > 0) 
					return newPageContents.join(this._pageBreak);
				else
					return '';
			} else
				return '';
		} else
			return this.getContents();		
	},
	getPageCnt : function() {
		return this.pageContents.length;
	},
	getPageCurrent : function() {
		return this.currentPage + 1;
	},
	savePage : function() {
		if (this.checkPage()) {
			this.pageContents[this.currentPage] = this.getContents();
			return true;
		} else
			return false;
	},
	checkPageMode : function() {
		return (this.config.maxpageheight > 0) ? true : false;
	},
	checkPage : function() {
		if (this.checkPageMode()) {
			if (this.config.maxpageheight < this.getDocHeight()) {
				this.showMsg(cafenMsg.get('ed_0139', this.getDocHeight(), this.config.maxpageheight));
				return false;
			} else if ((this.config.maxpagewidth) < this.getDocWidth()) {
				this.showMsg(cafenMsg.get('ed_0140', this.getDocWidth(), this.config.maxpagewidth));
				return false;
			} else
				return true;
		} else
			return true;
	},
	getDocHeight : function() {
		return this._editorObject.htmlEditor.getDocHeight();
	},
	getDocWidth : function() {
		return this._editorObject.htmlEditor.getDocWidth();
	},
	getUploadScript : function() {
		return cafenEditor_loader.editorBaseConf.uploadSCRIPT;
	},
	getUploadUrl : function() {
		return cafenEditor_loader.editorBaseConf.uploadURL;
	},
	getUploadedUrl : function() {
		return cafenEditor_loader.editorBaseConf.uploadedURL;
	},
	getMediaPlayerParam : function(use_logo) {
		var params = '';
		if (use_logo && cafenEditor_loader.editorBaseConf.mediaPlayer.logo != '')
			params += '&amp;logo=' + cafenEditor_loader.editorBaseConf.mediaPlayer.logo;
		if (cafenEditor_loader.editorBaseConf.mediaPlayer.backColor != '')
			params += '&amp;backcolor=' + cafenEditor_loader.editorBaseConf.mediaPlayer.backColor;
		if (cafenEditor_loader.editorBaseConf.mediaPlayer.frontColor != '')
			params += '&amp;frontcolor=' + cafenEditor_loader.editorBaseConf.mediaPlayer.frontColor;
		return params;
	},
	hasContents : function() {
		var contents = (this.config.maxpageheight > 0) ? this.getPageContents() : this.getContents();
		if (cafen.stripTags(contents).split('&nbsp;').join('').split(' ').join('') == '') 
			return false;
		else
			return true;
	},
/**
 * Editor 종료
 * @param {boolean}
 */
	end : function(bl) {
		this.obj.value = '';
		var contents = (this.config.maxpageheight > 0) ? this.getPageContents() : this.getContents();
		if (cafen.stripTags(contents).split('&nbsp;').join('').split(' ').join('') == '') {
			contents = '';
		}
		if (!this.config.canbe_null && contents == '') {
			if (!bl) 
				this.showMsg(cafenMsg.get('ed_0001'));
			return false;	
		} else if (!this.checkDataLength()) {
			return false;
		} else {
			if (this.config.p2br)
				contents = contents.replace(/<p>/gi, '').replace(/<\/p>/gi, '<br/>');
			var tmpObj = document.createElement('div');
			tmpObj.innerHTML = contents;
			var tags = tmpObj.getElementsByTagName('*'); 
			var removeObj = [];
			for(var i = 0; i < tags.length; i++) {
				var currObj = tags[i];
				if (currObj.tagName != null) {
					switch(currObj.tagName.toLowerCase()) {
						case 'a' :
							try {
								var href_url = currObj.getAttribute('href');
								if (href_url.indexOf('javascript:') == 0)
									currObj.setAttribute('href', "javascript:;");
								currObj.setAttribute('target', "_blank");
							} catch(ex) {}
							break;
						case 'style' :
						case 'script' :
						case 'input' :
						case 'textarea' :
						case 'select' :
							removeObj.push(currObj);
							break;
						case 'iframe' :
							if (!this.config.allowiframe) {
								if (currObj.src.indexOf('cafen.net/') == -1)
									removeObj.push(currObj);
							}
							break;
					}
				}
			}			
			for (var i =0; i < removeObj.length; i++) {
				try {
					removeObj[i].parentNode.removeChild(removeObj[i]);
				} catch(ex) {}
			}
			contents = tmpObj.innerHTML;
			if (!this.config.parsewithoutattach) {
				if (this.config.xmlParse) {
					var docs = (this.editorAttachView != null) ? {
						doc	:contents,
						mode : (this.config.mode == 'S')?'H':this.config.mode,
						attachimage : this.editorAttachView.getImageCnt(), 
						attachsize : this.editorAttachView.getAttachSize(),
						attachcnt : this.editorAttachView.getAttachCnt(),
						attachfiles : this.editorAttachView.parse('xml')
					} : {
						doc	:contents,
						mode : (this.config.mode == 'S')?'H':this.config.mode,
						attachimage : 0, 
						attachsize : 0,
						attachcnt : 0,
						attachfiles : ''
					}
					contents = '<?xml version=\"1.0\">\r\n<rss><channel>\r\n';
					for(var idx in docs) {
						if (idx != 'attachfiles') 
							contents += '<'+idx+'><![CDATA['+docs[idx]+']]></'+idx+'>\r\n';
						else
							contents += '<'+idx+'>'+docs[idx]+'</'+idx+'>\r\n';
					}
					contents += '</channel></rss>';
				} else if (this.config.simpleParse) {
					contents = this.editorAttachView.parse() + '<div mode=' + ((this.config.mode == 'S')?'H':this.config.mode) +'>'+contents+'</div>';
				}
				else {
					var boundary = cafen.Editor.baseConf.boundary;
					if (this.editorAttachView != null)
						contents =  contents + boundary + ((this.config.mode == 'S')?'H':this.config.mode) + '*' + this.editorAttachView.parse(true)+boundary;
					else
						contents =  contents + boundary + ((this.config.mode == 'S')?'H':this.config.mode) + '*' +boundary;
				}
			}
			this.obj.value = contents;
			if (!bl)
				this.setloadUnload(false);
			return true;
		}
	},
	setloadUnload : function(bl) {
		cafen.setloadUnload(bl, cafenMsg.get('ed_0116'));
	},
	checkDataLength : function() {
		var contents = '';
		if (this.config.max_length > 0 && (contents = this.getContents()).length > this.config.max_length) {
			var useRate = Math.round(contents.length / this.config.max_length *100);
			this.showMsg(cafenMsg.get('ed_0007',useRate,useRate -100));
			return false;
		} else 
			return true;
	},
	synkData : function() {
		switch(this.config.mode.toLowerCase()) {
			case 's' :
				this.setHTML(cafen.source2Html(this._editorObject.textEditor.getValue()));
				break;
			case 'h' :
				break;
			case 't' :
				this.setHTML(cafen.text2Html(this._editorObject.textEditor.getValue()));
				break;
			case 'a' :
				this.setHTML(cafen.text2Html(this._editorObject.textEditor.getValue(), true));
				break;
		}
	},
	setSaveDocStatus : function(str) {
		this._editorObject.saveObj.getElement().innerHTML = str;
	},
	toggleToolBar : function() {
		this._editorObject.buttonToggle.isSelected = !this._editorObject.buttonToggle.isSelected;
		this._editorObject.buttonToggle.setSelected(this._editorObject.buttonToggle.isSelected);
		if (!this._editorObject.buttonToggle.isSelected) {
			this._editorObject.buttonArea.show();
			this.config.toogleSatus.tool = true;
		} else {
			this._editorObject.buttonArea.hide();
			this.config.toogleSatus.tool = false;
		}
		this.setEditorHeight(this.config.height);
	},
	toggleAttach : function() {
		this._editorObject.attachToggle.isSelected = !this._editorObject.attachToggle.isSelected;
		this._editorObject.attachToggle.setSelected(this._editorObject.attachToggle.isSelected);
		if (!this._editorObject.attachToggle.isSelected) {
			this.config.toogleSatus.attach = true;
			this.editorAttachView.show();
		} else {
			this.config.toogleSatus.attach = false;
			this.editorAttachView.hide();
		}
		this.setEditorHeight(this.config.height);
	},
	drawAttachMenu : function() {
		this._editorObject.editorAttachArea.addRow();
		this.editorAttachScale = new cafen.Editor.AttachScale(this);
		this._editorObject.editorAttachArea.addCell(this.editorAttachScale);
		this._editorObject.editorAttachArea.addStyle({textAlign:'left'});
		this._editorObject.editorAttachArea.addRow();
		this.editorAttachView = new cafen.Editor.AttachFile(this);
		this._editorObject.editorAttachArea.addCell(this.editorAttachView);
	},
	resizeStart : function(obj, event) {
		this.options._lastresizeInfo = [cafen.pointer(event || window.event), this._editorObject.editorDumy.getSize()];
		this._editorObject.editorDumy.setSize(null,this.options._lastresizeInfo[1][1]);
		this.showHideEditor('S');
		if (this._reizeBind == null ) 
			this._reizeBind = {move : this.resizeMove.bindAsEventListener(this), stop : this.resizeStop.bindAsEventListener(this)};
		cafen.Event.observe(document.body,'mousemove', this._reizeBind.move);
		cafen.Event.observe(document.body,'mouseup', this._reizeBind.stop);
	},
	resizeMove : function(event) {
		var pos = cafen.pointer(event);
		var moveY = pos[1] - this.options._lastresizeInfo[0][1];
		var newHeight = this.options._lastresizeInfo[1][1] + moveY;
		if (newHeight > this.config.minHeight * 3 || newHeight < this.config.minHeight/2) {
			this.resizeStop();
		} else { 
			this._editorObject.editorDumy.setSize(null, newHeight);
			this.showStatus(newHeight +' px Resize ' + cafenMsg.get('ed_0054'));
		}
	},
	resizeStop : function() {
		cafen.Event.stopObserving(document.body,'mousemove', this._reizeBind.move);
		cafen.Event.stopObserving(document.body,'mouseup', this._reizeBind.stop);
		var size = this._editorObject.editorDumy.getSize();
		this._editorObject.editorDumy.setStyle({height : 'auto'});
		this.setEditorHeight(this.config.height + size[1] - this.options._lastresizeInfo[1][1]);
		switch(this.config.modeCurr) {
			case 'H' :
				this.showHideEditor('E');
				break;
			case 'P' :
				this.showHideEditor('P');
				break;
			default :
				this.showHideEditor('T');
				break;
		}
	},
	setSize : function(w, h) {
		this.setEditorWidth(w);
		this.setEditorHeight(h);
	},
	setEditorWidth : function(w) {
		if (w < 350)
			w = 350;
		if (w > 1000)
			w = 1000;
		if (w > 350 && w < 1000) {
			this.config.width = w;
			this._editorObject.TopMenuFrm.setStyle({width: this.config.width +'px'});
			this._editorObject.editorSkin.setStyle({width: (this.config.width -12) +'px', overflowX : 'hidden'});
			this._editorObject.buttonAreaSkin.setStyle({width: (this.config.width -12) +'px'});
			this._editorObject.buttonAreaOut.setStyle({width: (this.config.width -12) +'px', overflowX : 'hidden'});
			this._editorObject.buttonArea.setStyle({width: (this.config.width -29) +'px'});
			this._editorObject.buttonArea.parentNode.setStyle({width: (this.config.width -29) +'px'});
			if (this._editorObject.editorAttachArea != null) {
				this._editorObject.editorAttachArea.setStyle({width: (this.config.width -29) +'px'});
				this._editorObject.AttachAreaOut.setStyle({width: (this.config.width -12) +'px'});
			}
			if (this._editorObject.resizeButton != null)
				this._editorObject.resizeButton.setStyle({width: (this.config.width -6)+'px'});
			if (this._editorObject.htmlEditor !=null)
				this._editorObject.htmlEditor.setStyle({width: (this.config.width -14) +'px'});
			if (this._editorObject.textEditor !=null)
				this._editorObject.textEditor.setStyle({width: (this.config.width -12) +'px'});
			if (this._editorObject.previewEditor !=null)
				this._editorObject.previewEditor.setStyle({width: (this.config.width -14) +'px'});
			if (this.editorAttachScale !=null)
				this.editorAttachScale.reSize();
			if (this.editorAttachView !=null)
				this.editorAttachView.reSize();
			if (this._editorObject.copyrightObj != null)
				this._editorObject.statusObj.setStyle({width : (this.config.width - 106) + 'px' });
			else
				this._editorObject.statusObj.setStyle({width : (this.config.width -6)+ 'px' });
		}
	},
	setEditorHeight : function(h) {
		if (h < 150)
			h = 150;
		if (h > 700)
			h = 700;
		if (h > 150 && h < 700) {
			this.config.height = h;
			h -= (this.config.toogleSatus.attach) ? this.config.toogleSize.attach : 29;
			if (this._editorObject.htmlEditor != null) {
				var editor_height = h ;
				editor_height -= (this.config.toogleSatus.tool) ? this.config.toogleSize.tool : 20;
				this.config.editorheight = editor_height;
				this._editorObject.htmlEditor.setStyle({height : editor_height +'px'});
				this._editorObject.htmlEditor.onChange();
			}
			if (this._editorObject.textEditor != null) {
				this._editorObject.textEditor.setStyle({height : h +'px'});
				this._editorObject.textEditor.onChange();
			}
			if (this._editorObject.previewEditor != null) {
				this._editorObject.previewEditor.setStyle({height : h +'px'});
				this._editorObject.previewEditor.onChange();
			}
			if (this.config.useMobleUI) 
				this.synkDummyPos();
		}
	},
	setTabObject : function() {
		this.tab_info = [];
		var tmpTab_info = {
			H: cafenMsg.getObject('ed_0002'), 
			S: cafenMsg.getObject('ed_0003')
		};
		if (this.config.tab_text == true) {
			tmpTab_info['T'] = cafenMsg.getObject('ed_0004');
			tmpTab_info['A'] = cafenMsg.getObject('ed_0005');
		}
		if (this.config.tab_preview == true) 
			tmpTab_info['P'] = cafenMsg.getObject('ed_0006');
		this.tabObject = {};
		this.config.topmenu = this.config.topmenu.toUpperCase();
		for(var i = 0 ; i < this.config.topmenu.length; i++) {
			var idx = this.config.topmenu.charAt(i);
			if (tmpTab_info[idx] != null) {
				this.tabObject[idx] = new cafen.XTab({className : this.conf.getClassName('tab'), text : tmpTab_info[idx].name, event:{click:this.modeSwap.bind(this,idx, null)}, style : {height : '20px'}});
				this.tab_info.push(this.tabObject[idx]);
			}
		}
	},	
	showConfirm : function(msg, bindFn, pos) {
		if (cafenGlobalConf.donotUseLayerModal || cafen.isMobile()) {
			cafen.xConfirm(msg, bindFn);
		} else {
			msg = this.getPaddingText(msg);
			if (this._editorObject.confirm == null) {
				this._editorObject.confirm = new cafen.XConfirm({title :cafenMsg.get('com_confirm'), contents :'', sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'middle'}, style : {width: '300px'}, onClose : this.getConfirm.bind(this)});
				this._editorObject.confirm.setContents(msg);
				this._editorObject.editorPopup.addChild(this._editorObject.confirm);
			}
			this._lastConfirmFnc = bindFn;
			this._editorObject.confirm.setContents(msg, pos ? {y : 'exbottom', plus : [0, 5]} : {y : 'top', plus : [0, 5]});
			this._editorObject.confirm.onLoad();
		}
		if (this.getSelectedType() == "Control") 
			this.unsetSelectedType();
	},
	getConfirm : function(bl) {
		if (this._lastConfirmFnc != null)
			this._lastConfirmFnc(bl);
		this._lastConfirmFnc = null;
	},
	showMsg : function(msg, pos) {
		if (cafenGlobalConf.donotUseLayerModal || cafen.isMobile()) {
			cafen.xAlert(msg);
		} else {
			msg = this.getPaddingText(msg);
			if (this._editorObject.alert == null) {
				
				this._editorObject.alert = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents :'', sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'middle'}, style : {width: '300px'}});
				this._editorObject.alert.setContents(msg, null);
				this._editorObject.editorPopup.addChild(this._editorObject.alert);
			}
			this._editorObject.alert.setContents(msg, pos ? {y : 'exbottom', plus : [0, 5]} : {y : 'top', plus : [0, 5]});
			this._editorObject.alert.onLoad();
		}
		if (this.getSelectedType() == "Control") 
			this.unsetSelectedType();
	},
	showContents : function(contents, contentstype) {
		if (this._editorObject.contentsViewer == null) 
			this._editorObject.contentsViewer = new cafen.Editor.contentsViewer(this);
		switch(contentstype) {
			case 'image' :
				this._editorObject.contentsViewer.setImage(contents);
				break;
			case 'imageeditor' :
				this._editorObject.contentsViewer.setImageEditor(contents);
				break;
			case 'movie' :
				this._editorObject.contentsViewer.setMovie(contents);
				break;
			case 'movieeditor' :
				this._editorObject.contentsViewer.setMovieEditor(contents);
				break;
			case 'map' :
				this._editorObject.contentsViewer.setMap(contents);
				break;
		}
	},
	showStatus : function(msg) {
		if (this._editorObject.statusObj != null) {
			if (typeof msg == 'string')
				this._editorObject.statusObj.getElement().innerHTML = msg;
			else {
				this._editorObject.statusObj.getElement().innerHTML = '';
				this._editorObject.statusObj.appendChild(msg);
			}
		}
	},
	getPreviewObject : function() {
		if (this._editorObject.previewEditor == null) {
			this._editorObject.previewEditor = new cafen.Iframe({className :'r_btnskin',style:{width: (this.config.width - 6) +'px', height: this.config.height + 'px'}, attribute : {frameBorder:0, allowTransparency:true}});
			var preview_addStyle = cafenEditor_loader.editorBaseConf.addedCSS;
			preview_addStyle.push('marquee, table {border:0}');
			preview_addStyle.push('.morecontents {display:none}');
			this.previewskin = "<html><head><meta http-equiv=Content-Type content='text/html;charset=utf-8'><link href='"
				+cafenEditor_loader.editorBaseConf.editorStyleSheet
				+ "' type='text/css' rel='stylesheet' /><style>"+preview_addStyle.join('')+"</style></head><body topmargin=5 leftmargin=5>"
				+ "<p></p></body></html>";
			this._editorObject.editorSkin.addRow(this._editorObject.previewEditor);
			this._editorObject.previewEditor.initDoc(this.previewskin);
			this._editorObject.previewEditor.setStyle(this.conf.editorStyle(this.config.width,this.config.height,'none', 0));
		}
		return this._editorObject.previewEditor;
	},
	showHideEditor : function(mode) {
		this._editorObject.editorPopup.closeChild();
		this._lastCommandObj = null;
		this._lastCommand = null;
		switch(mode) {
			case 'E' :
				this._editorObject.buttonAreaSkin.show();
				if (this._editorObject.textEditor != null)
					this._editorObject.textEditor.hide();
				if (this._editorObject.previewEditor != null)
					this._editorObject.previewEditor.hide();
				this._editorObject.htmlEditor.synkShow();
				if (this.isloaded)
					this.setFocus();
				break;
			case 'T' :
				this._editorObject.buttonAreaSkin.hide();
				if (this._editorObject.textEditor != null) 
					this._editorObject.textEditor.show();
				if (this._editorObject.previewEditor != null)
					this._editorObject.previewEditor.hide();
				this._editorObject.htmlEditor.synkHide();
				break;
			case 'P' :
				this._editorObject.buttonAreaSkin.hide();
				if (this._editorObject.textEditor != null)
					this._editorObject.textEditor.hide();
				if (this._editorObject.previewEditor != null)
					this._editorObject.previewEditor.show();
				this._editorObject.htmlEditor.synkHide();
				break;
			case 'S' :
				if (this._editorObject.textEditor != null)
					this._editorObject.textEditor.hide();
				if (this._editorObject.previewEditor != null)
					this._editorObject.previewEditor.hide();
				this._editorObject.htmlEditor.synkHide();
				break;
		}
	},
	modeSwap : function(idx, bl) {
		var init_mode = this.config.mode.toUpperCase();
		idx = idx.toUpperCase();
		if (this.tabObject[idx] == null) 
			return ;	
		if (this.config.initmode != idx && idx != 'P' && !this.config.swaptab) {
				this.showMsg(cafenMsg.get('ed_0008'));
				return ;
		} else if ((init_mode == 'S' || init_mode == 'H') && (idx == 'A' || idx == 'T') ) {
			if (bl == null) {
				this.showConfirm(cafenMsg.get('ed_0009'), this.modeSwap.bind(this, idx));
				return ;
			} else if (!bl) {
				this._lastCommandObj = null;
				this._lastCommand = null;
				return ;
			}
		}
		switch(idx) {
			case 'H' : 
				this._tabObj.setSelected(this.tabObject.H);
				var tagetContents = '';
				switch (init_mode) {
					case 'A':
						tagetContents = cafen.text2Html(this._editorObject.textEditor.getValue(), true);
						break;
					case 'T':
						tagetContents = cafen.text2Html(this._editorObject.textEditor.getValue(), false);
						break;
					case 'S':
						tagetContents = this._editorObject.textEditor.getValue();
						break;
					case 'H':
					case 'P':
						tagetContents = null;
						break;
				}
				if (tagetContents != null)
					this.setHTML(tagetContents);
				this.showHideEditor('E');
				this.config.mode = 'H';
				break;
			case 'S' : 
				this._tabObj.setSelected(this.tabObject.S);
				var tagetContents = null;
				switch (init_mode) {
					case 'A':
					case 'T':
						tagetContents = cafen.text2Html(this._editorObject.textEditor.getValue());
						break;
					case 'H':
						tagetContents = this.getHTML();
						break;
					case 'S':
					case 'P':
						tagetContents = null;
						break;
				}
				if (tagetContents != null)
					this._editorObject.textEditor.setValue(cafen.html2Source(tagetContents));
				this.showHideEditor('T');
				this.config.mode = idx;
				break;
			case 'A' : 
			case 'T' : 
				this._tabObj.setSelected(this.tabObject[idx]);
				var tagetContents = null;
				switch (init_mode) {
					case 'A':
					case 'T':
					case 'S':
						tagetContents = this._editorObject.textEditor.getValue();
						if (init_mode == 'S')
							tagetContents = cafen.html2Text(tagetContents)
						break;
					case 'H':
						tagetContents = cafen.html2Text(this.getHTML());
						break;
					case 'P':
						tagetContents = null;
						break;
				}
				if (tagetContents != null)
					this._editorObject.textEditor.setValue(tagetContents);
				this.showHideEditor('T');
				this.config.mode = idx;
				break;
			case 'P' : 
				this._tabObj.setSelected(this.tabObject.P);
				var tagetContents = null;
				switch (init_mode) {
					case 'A':
					case 'T':
					case 'S':
						tagetContents = this._editorObject.textEditor.getValue();
						if (init_mode != 'S')
							tagetContents = cafen.text2Html(tagetContents)
						break;
					case 'H':
						tagetContents = this.getHTML();
						break;
					case 'P':
						tagetContents = null;
						break;
				}
				this.getPreviewObject();
				if (tagetContents != null) {
					var moreScript = ''
						+ ' onclick="{\r\n'
						+ 'var objs = this.parentNode.getElementsByTagName(\'div\'), findObj = objs[0], obj = null, seqn = 0;'
						+ ' while(findObj && findObj.id) {'
						+ ' if (findObj.id == this.id +\'_contents\') {'
						+ ' obj = findObj;'
						+ ' break;'
						+ ' }'
						+ ' seqn++;findObj = objs[seqn];'
						+ ' }'
						+ ' if (obj !=null) { '
						+	' if (obj.style.display == \'block\') { '
						+ ' if (this.org_txt != null )this.innerHTML = this.org_txt; '
						+ ' obj.style.display =  \'none\'; '
						+ ' } else { '
						+ ' obj.style.display =  \'block\'; '
						+ ' if (this.org_txt == null )this.org_txt = this.innerHTML; '
						+ ' this.innerHTML = \'<p>&gt; '+cafenMsg.get('ed_0128')+'</p>\'; '
						+ ' }'
						+ ' }}"'
						+ ' class="moretitle" ';
					tagetContents = tagetContents.replace(eval('/ class="moretitle"/gi'), moreScript);
					tagetContents = tagetContents.replace(eval('/ class=moretitle/gi'), moreScript);
					tagetContents = tagetContents.replace(eval('/ src="images/gi'), ' src="'+this.conf._editor_url+'/images');
					tagetContents = tagetContents.replace(eval('/ src="uploads/gi'), ' src="'+this.conf._editor_url+'/uploads');
					this._editorObject.previewEditor.setContents(tagetContents);
				}
				this.showHideEditor('P');
				break;
			default :
				break;
		}
		this.showStatus('');
		this.config.modeCurr = idx;
	},
	drawToolbar : function() {
		this.statusButton = [];
		this.actionButton = {};
		this.setDrawToolbar(this._editorObject.buttonArea, this.config.toolbar, this.statusButton, this.actionButton, false);	
	},
	drawMobileToolbar : function() {
		this._editorObject.mobileButtonArea = new cafen.Div({align:'left', attribute : {border:0},style : {}});
		var buttonAreaSkin = new cafen.Div({className : this.conf.getClassName('buttonarea'), align:'left', attribute : {border:0},style : {}});
		buttonAreaSkin.appendChild(this._editorObject.mobileButtonArea);
		this.mobileStatusButton = [];
		this.mobileActionButton = {};
		this.setDrawToolbar(this._editorObject.mobileButtonArea, this.config.mobiletoolbar, this.mobileStatusButton, this.mobileActionButton, true);
		this._editorObject.dummyFocusOut = document.createElement('span');
		this._editorObject.dummyFocusPos = document.createElement('div');
		cafen.setStyle(this._editorObject.dummyFocusOut, {position:'absolute',left:'5px',top:'0px', width: '1px', height:'1px',marginTop:'0', padding:'0', textAlign:'left',fontSize:'1px',lineHeight:'1px'});
		cafen.setStyle(this._editorObject.dummyFocusPos, {position:'absolute', width:'1px', height:'1px',left:'0',top:'0',marginTop:'0', padding:'0', textAlign:'left'});
		cafen.setOpacity(this._editorObject.dummyFocusPos, 90);
		this._editorObject.dummyFocusOut.appendChild(this._editorObject.dummyFocusPos);
		this._editorObject.dummyFocus = document.createElement('textarea');
		cafen.setAttribute(this._editorObject.dummyFocus, {placeholder:'', autocapitalize : 'off', spellcheck : 'false', wrap :'off'});
		this._editorObject.dummyFocus.autocapitalize = 'off';
		this._editorObject.dummyFocusPos.appendChild(this._editorObject.dummyFocus);
		this._editorObject.dummyFocusPos.appendChild(buttonAreaSkin.getObject());
		cafen.setStyle(buttonAreaSkin.getObject(), {marginTop:'3px', position : 'relative'});
		this._editorObject.editorPopup.getElement().appendChild(this._editorObject.dummyFocusOut);
		cafen.setStyle(this._editorObject.dummyFocus, {position : 'relative', padding:'2px', margin:'0',width:'auto' ,height:'auto',backgroundColor:'#ffffff', fontSize:'12px', color:'#464646', border:'1px gray dotted', resize :'none', lineHeight:'100%',overflowX : 'hidden',overflowY :'visible', whiteSpace: 'nowrap'});
		cafen.Event.observe(this._editorObject.dummyFocus, 'keyup', this.onDummyDown.bind(this), false);
		cafen.Event.observe(this._editorObject.htmlEditor.getScrollObject(), 'scroll', this.synkDummySize.bind(this), false);
		this.dummyBaseWidth = Math.round(this.config.width / 2);
		if (this.dummyBaseWidth > 300)
			this.dummyBaseWidth = 300;
		this.synkDummySize();
		this.checkDummyLen();
	},
	checkDummyLen : function() {
		cafen.setStyle(this._editorObject.dummyFocus, {width : '10px', height:'5px'});
		cafen.setStyle(this._editorObject.dummyFocus, {width : (Math.max(this._editorObject.dummyFocus.scrollLeft +10, this._editorObject.dummyFocus.scrollWidth))+'px', height : (Math.max(this._editorObject.dummyFocus.scrollTop +5, this._editorObject.dummyFocus.scrollHeight+5))+'px'});
		window.setTimeout(this.checkDummyLen.bind(this),300);
	},
	_bummyHasFocus : false,
	onDummyFocus : function() {
		this._bummyHasFocus = true;
	},
	onDummyBlur : function() {
		this._bummyHasFocus = false;
	},
	onDummyShowHide : function(bl) {
		if (bl) {
			if (this._lastCommand != 'find') {
				cafen.show(this._editorObject.dummyFocusOut);
				window.setTimeout(this.setDummyFocus.bind(this),1);
			}
		} else {
			cafen.hide(this._editorObject.dummyFocusOut);	
		}
	},
	onDummyDown : function(event) {
		var ev = event || window.event;
		if (this._editorObject.dummyFocus != null) {
			switch(ev.keyCode) {
				case 8 :
					if (this._editorObject.dummyFocus.value.length == 0) {
						this.execCommand("Delete",false, null); 
						this._editorObject.dummyFocus.focus();
					}
					break;
				case 13 :
				case 32 :
				case 109:
				case 186:
				case 187:
				case 188:
				case 189:
				case 190:
				case 191:
				case 192:
				case 219:
				case 220:
				case 221:
				case 222:
					this.synkDummyValue(ev);
					break;
				default :
					break;
			} 
		}
	},
	synkDummyValue : function(ev) {
		var txt = this._editorObject.dummyFocus.value;
		if (txt != '') {
			ev = ev || {keyCode : null};
			var subtxt = txt;
			if (ev.keyCode == 32)
				subtxt = subtxt.substring(0, subtxt.length -1)+'&nbsp;';
			if (subtxt == ' ')
				subtxt = '&nbsp;';
			subtxt = cafen.text2Html(cafen.stringUtil.trim(subtxt));
			this._editorObject.htmlEditor.execCommand("insertHTML", false ,subtxt); 
			if (ev.keyCode == 13)
				this._editorObject.htmlEditor.execCommand("InsertParagraph"); 
			this._editorObject.dummyFocus.value = '';
			cafen.setAttribute(this._editorObject.dummyFocus, {'value' : ''});
		}
	},
	setDummyFocus : function() {
		try {
			this._editorObject.dummyFocus.focus();
		} catch(ex) {}
	},
	synkDummySize : function() {
		var objSize = this._editorObject.htmlEditor.getObjectSize();
		var baseWidth = this.dummyBaseWidth;
		var basePosY = 5;
		var basePosX = 5;
		var eventPointer = null;
		try {
			eventPointer = this._editorObject.htmlEditor.getSelectionCoordinates();
		} catch(ex) {}
		if (eventPointer != null) {
			basePosY = eventPointer.y;
			basePosX = eventPointer.x;
			var cssForeColor = cafen.rgb2hexFF(this.queryCommandValue('ForeColor'));
			var cssFontSize = parseInt(this.queryCommandValue('FontSize'));
			switch(cssFontSize) {
				case 1 :
					cssFontSize = 8;
					break;	
				case 2 :
					cssFontSize = 10;
					break;	
				case 3 :
					cssFontSize = 12;
					break;	
				case 4 :
					cssFontSize = 14;
					break;	
				case 5 :
					cssFontSize = 18;
					break;	
				case 6 :
					cssFontSize = 24;
					break;	
				case 7 :
					cssFontSize = 36;
					break;	
				default :
					if (isNaN(cssFontSize) ||  cssFontSize == null) {
						var selectObj = this.getSelectedElement();
						if (selectObj != null)
							cssFontSize = parseInt(cafen.getStyle(selectObj,'fontSize', this._editorObject.htmlEditor.getDocument()));
						if (isNaN(cssFontSize))
							cssFontSize = 10;
					} else
						cssFontSize = 10;
					break;	
			}
			cafen.setStyle(this._editorObject.dummyFocus, {fontSize: cssFontSize +'pt'});
		}
		cafen.setStyle(this._editorObject.dummyFocusPos, {left:basePosX +'px',top:basePosY+'px'});
		if (basePosY < 0)
			this._editorObject.htmlEditor.getScrollObject().scrollTop = Math.max(0,this._editorObject.htmlEditor.getScrollObject().scrollTop + basePosY);
		else if (basePosY > (this.config.editorheight -15))
			this._editorObject.htmlEditor.getScrollObject().scrollTop = this._editorObject.htmlEditor.getScrollObject().scrollTop + (basePosY -this.config.editorheight +15);
	},
	synkDummyPos : function() {
		if (this._editorObject.dummyFocusOut != null) {
			var posPopup = cafen.cumulativeOffset(this._editorObject.editorPopup.getElement());
			var posEditor = cafen.cumulativeOffset(this._editorObject.htmlEditor.getElement());
			cafen.setStyle(this._editorObject.dummyFocusOut, {top : (posEditor[1] - posPopup[1])+'px'});
		}
	},	
	setDrawToolbar : function(buttonArea, toolbarConfig, statusButton, actionButton, isMobileToolbar) {
		var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
		var groupstart = false;
		var groupmiddle = false;
		var groupend = false;
		var groupAlign = 'left';
		var cnt = toolbarConfig.length;
		var currRowObj = null;
		
		var iconMargin = null;
		if(cafen.browser.isIE) 
			iconMargin = '0 0 0 3px';
		else if(cafen.browser.isFF) 
			iconMargin = '-1px 0 0 0px';
		else
			iconMargin = '3px 0px 3px 2px';
		
		for(var i = 0; i < cnt ; i++) {
			if (currRowObj == null) {
				switch (groupAlign) {
					case 'center' :
					case 'right' :
						currRowObj = new cafen.TableAuto({attribute : {border:0, align: groupAlign},style : {}});
						var tmpAlignObj = new cafen.Div({style: {textAlign: groupAlign, height : '22px'}});
						tmpAlignObj.appendChild(currRowObj);
						buttonArea.appendChild(tmpAlignObj);
						break;
					default :
						currRowObj = new cafen.TableAuto({attribute : {border:0},style : {}});
						buttonArea.appendChild(currRowObj);
						break;
				}
				currRowObj.addRow();
			}
			var idx = toolbarConfig[i];
			switch(idx) {
				case 'separator':
					break;
				case 'group' :
				case '[' :
					groupstart = true;
					groupmiddle = false;
					groupend = false;
					break;
				case 'break' :
				case ']' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'blank' :
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'linebreakc' :
				case 'linebreakl' :
				case 'linebreakr' :
				case 'linebreakb' :
				case 'linebreak' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					switch(idx) {
						case 'linebreakr' :
							groupAlign = 'right';
							break;
						case 'linebreakc' :
							groupAlign = 'center';
							break;
						default :
							groupAlign = 'left';
							break;
					}
					if (idx == 'linebreak')
						buttonArea.appendChild(new cafen.Div({style:{height:'3px', margin:'1px 6px 2px 6px', fontSize:'1px', backgroundPosition : '0 -1122px', backgroundRepeat : 'repeat-x'}, attribute : {className : this.conf.getClassName('buttonbg')}}));
					else
						buttonArea.appendChild(new cafen.Div({style:{height:'3px', margin:'0px', fontSize:'1px'}}));
					currRowObj = null;
					break;
				default :
					var currButton = buttonInfo[idx];
					var baseClassName = 'r_editorset';
					if (currButton == null) {
						baseClassName = 'r_editorplugin';
						if (cafenEditor_loader.editorBaseConf.Plugin[idx] != null) {
							currButton = cafenEditor_loader.editorBaseConf.Plugin[idx].info;
						} else
							break;
					}
					var buttonNo = currButton[2];
					var x = (buttonNo % 10) * 16;
					var y = Math.floor(buttonNo /10) * 16;
					var icon = null;
					var bindCommand = null;
					switch(idx) {
						case 'fontblock' :
						case 'fontname' :
							icon = new cafen.Div({style: {cssFloat : 'left', margin : iconMargin, fontSize : '12px', width:'70px', height:'16px', marginLeft : '4px', marginTop : '4px', overflowX:'hidden', whiteSpace: 'nowrap'}});
							bindCommand = this.actionCommand.bind(this,idx,icon,'',isMobileToolbar);
							break;
						case 'lineheight' :
						case 'changestyle' :
						case 'fontsize' :
							icon = new cafen.Div({style: {cssFloat : 'left',margin : iconMargin, fontSize : '12px', width:'40px', height:'16px', marginLeft : '4px', marginTop : '4px', overflowX:'hidden', whiteSpace: 'nowrap', textAlign:'left'}});
							bindCommand = this.actionCommand.bind(this,idx,icon,'',isMobileToolbar);
							break;
						case 'forecolor':
						case 'backcolor':
						case 'forecolorp':
						case 'backcolorp':
							icon = new cafen.XImage({className :'r_editorset',x: x,y : y}, {style:{cssFloat : 'left',margin : iconMargin, width:'16px', height:'16px'},attribute :{unselectable : 'on'}, childNodes : [new cafen.Editor.ButtonColor()]});
							bindCommand = this.actionCommand.bind(this,idx,icon,'',isMobileToolbar);
							break;
						default :
							icon = new cafen.XImage({className :baseClassName,x: x,y : y}, {style:{cssFloat : 'left',margin : iconMargin, width:'16px', height:'16px'},attribute :{unselectable : 'on'}});
							bindCommand = (currButton[0] != null) ? this.execCommand.bind(this,currButton[0],'','') : this.actionCommand.bind(this,idx,'','',isMobileToolbar);
							break;
					}
					var tmpButton = null;
					var baseBgPos = 0,baseSize =0 , basePadding = 0; 
					if (currButton[5] != null ) {
						if (currButton[5] > 60) {
							baseBgPos = 792;
							baseSize  = 100;
						} else if (currButton[5] > 30) {
							baseBgPos = 528;
							baseSize  = 56;
						} else {
							baseBgPos = 0;
							baseSize  = 33;
						}
						basePadding = 0;
					} else {
						baseBgPos = 264;
						baseSize  = 24;
						basePadding = 0;
					}
					var nextidx = (cnt -1 >= i +1) ? this.config.toolbar[i+1] : '';
					if (!groupstart) {
						tmpButton = new cafen.XIcon({icon : this.conf.getClassName('buttonbg'), off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on'}, event :{click:bindCommand}, childNodes : [icon]}) ;
						currRowObj.addCell(tmpButton);
						currRowObj.addStyle({width:baseSize +'px'});
						currRowObj.addCell();
						currRowObj.addStyle({width:'3px'});
						currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					} else {
						var title = currButton[1];
						var shortkey = null;
						if (this.keyMapShortCut[idx] != null) {
							var keyMap = [];
							if (this.keyMapShortCut[idx][0] != null) {
								keyMap.push(this.keyMapShortCut[idx][0]);
								shortkey = this.keyMapShortCut[idx][0];
							}
							if (this.keyMapShortCut[idx][1] != null)
								keyMap.push(this.keyMapShortCut[idx][1]);
							if (keyMap.length > 0) 
								title += ' (' + keyMap.join(', ') +')';
						}
						
						if (nextidx == 'group' || nextidx == 'break' || nextidx == ']'  || nextidx == ']' || nextidx == 'linebreak' || nextidx == 'linebreakb')
							groupend = true;
						if (!groupmiddle && groupend) {
							tmpButton = new cafen.XIcon({icon : this.conf.getClassName('buttonbg'), shortkey : shortkey, off : baseBgPos+198, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : title}, event :{click:bindCommand}, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (!groupmiddle) {
							tmpButton = new cafen.XIcon({icon : this.conf.getClassName('buttonbg'), shortkey : shortkey, off : baseBgPos, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : title}, event :{click:bindCommand}, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (groupend) {
							tmpButton = new cafen.XIcon({icon : this.conf.getClassName('buttonbg'), shortkey : shortkey, off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : title}, event :{click:bindCommand}, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else {
							tmpButton = new cafen.XIcon({icon : this.conf.getClassName('buttonbg'), shortkey : shortkey, off : baseBgPos+66, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : title}, event :{click:bindCommand}, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						}
						actionButton[idx] = {classObj : null, obj : tmpButton};
						if (currButton[4] && currButton[0] != null)
							statusButton.push({cmd : currButton[0], obj : tmpButton});
						groupmiddle = true;
					}
					break;
			}
		}
	},
	_downstartObj : null,
	_downstartPos : [0,0],
	_downendPos : [0,0],
	_mouseclickeventstop : false,
	setMouseDown : function(event) {
		if ((event.button|| event.which) == 1) {
			var tagObj = (event.target || event.srcElement);
			tagObj = this._editorObject.htmlEditor.getParentElement('TD',tagObj);
			if (tagObj == null || !tagObj.tagName)
				return true;
			switch(tagObj.tagName.toLowerCase()) {
				case 'td' :
					this.clickBind(event);
					if (this.mouseupbind == null) {
						this.mouseupbind = this.setMouseUp.bindAsEventListener(this);
						this.mousemovebind = this.setMouseMove.bindAsEventListener(this);
					}
					this._downstartObj = tagObj;
					var contentMenuObj = this.getContextMenu();
					contentMenuObj.lastObj = tagObj;
					var posObj = cafen.cumulativeOffset(tagObj);
					posObj = this._editorObject.htmlEditor.getEventPointer({pageX : posObj[0], pageY: posObj[1]});
					var posPointer = this._editorObject.htmlEditor.getEventPointer(event);
					var posSize = cafen.getSize(tagObj);
					var posX = posPointer[0] - posObj[0];
					var posY = posPointer[1] - posObj[1];
					var dirResize = [false, false, posPointer, posSize];
					if (posX > (posSize[0] - 5)) 
						dirResize[0] = true;
					if (posY > (posSize[1] - 5)) 
						dirResize[1] = true;
					if (dirResize[0]|| dirResize[1]) {
						var cursorStyle = 'pointer';
						if (!cafen.browser.isIE) {
							if (dirResize[0] && dirResize[1])
								cursorStyle = 'nw-resize';
							else if (dirResize[0])
								cursorStyle = 'w-resize';
							else if (dirResize[1])
								cursorStyle = 'n-resize';
						}
						var tableSize = cafen.getSize(tagObj.parentNode.parentNode.parentNode);
						var tablePos = cafen.cumulativeOffset(tagObj.parentNode.parentNode.parentNode);
						tablePos = this._editorObject.htmlEditor.getEventPointer({pageX : tablePos[0], pageY: tablePos[1]});
						if (this._dummyLayer == null) {
							this._dummyLayer = this._editorObject.htmlEditor.createElement('div'); 
							cafen.setStyle(this._dummyLayer, {position : 'absolute', backgroundColor:'#d0d0d0', zIndex:'100'});
							cafen.setOpacity(this._dummyLayer, 50);
						}
						cafen.setStyle(this._dummyLayer, {width : tableSize[0]+'px', height: tableSize[1]+'px', tableLayout :'fixed',left : tablePos[0]+'px', top : tablePos[1]+'px', cursor : cursorStyle});
						tagObj.parentNode.parentNode.parentNode.parentNode.insertBefore(this._dummyLayer, tagObj.parentNode.parentNode.parentNode);
						this._downResizeRule = dirResize;
						this._downstartPos = contentMenuObj.getTableNo(tagObj, false, true);
						contentMenuObj.table2Fix();
					} else {
						this._downstartPos = contentMenuObj.getTableNo(tagObj, false);
						this._downResizeRule = null;
					}
					cafen.Event.observe(this._editorObject.htmlEditor.getBody(),'mouseup',this.mouseupbind);
					cafen.Event.observe(this._editorObject.htmlEditor.getBody(),'mousemove',this.mousemovebind, true);
					cafen.Event.stopObserving(this._editorObject.htmlEditor.getRealObject(),'click',this.clickBind);
					this._mouseclickeventstop = true;
//					cafen.Event.stop(event);
					return false;
					break;
				default :
					if (this._mouseclickeventstop)
						cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'click',this.clickBind);
//					cafen.Event.stop(event);
					return true;
					break;
			}
		}
	},
	setMouseMove : function(event) {
		var tagObj = (event.target || event.srcElement);
		if (this._downstartObj.parentNode.parentNode == tagObj.parentNode.parentNode || this._downResizeRule) {
			if (this._downResizeRule != null) {
				var x = null;
				var y = null; 
				var eventPos = this._editorObject.htmlEditor.getEventPointer(event);
				var resizeX = eventPos[0] - this._downResizeRule[2][0];
				var resizeY = eventPos[1] - this._downResizeRule[2][1];
				this.getContextMenu().tableCellSize(this._downstartPos, resizeX, resizeY, this._downResizeRule);
				if (this._dummyLayer != null)
					cafen.setStyle(this._dummyLayer, {height : this._downstartObj.parentNode.parentNode.parentNode.offsetHeight + 'px', width : this._downstartObj.parentNode.parentNode.parentNode.offsetWidth + 'px'});
			} else {
				if (this._downstartObj == tagObj) {
					this._moveObj = null;
					this.getContextMenu().restoreCellColor();
				} else if (tagObj != this._moveObj) {
					this._downendPos = this.getContextMenu().getTableNo(tagObj, true);
					if (this._downendPos != null && this._downstartPos != null) {
						this.getContextMenu().setTableRange(this._downstartPos, this._downendPos);
						this._moveObj = tagObj;
					}
				}
			}
			cafen.Event.stop(event);
		} 
		return false;
	},
	setMouseUp : function(event) {
		cafen.Event.stopObserving(this._editorObject.htmlEditor.getBody(),'mouseup',this.mouseupbind);
		cafen.Event.stopObserving(this._editorObject.htmlEditor.getBody(),'mousemove',this.mousemovebind, true);
		var tagObj = (event.target || event.srcElement);
		if (this._dummyLayer != null && this._dummyLayer.parentNode != null) {
			this._dummyLayer.parentNode.removeChild(this._dummyLayer);
		}
		if (this._downstartObj.parentNode.parentNode == tagObj.parentNode.parentNode) {
			if (this._downResizeRule != null) {

			} else {
				this._downendPos = this.getContextMenu().getTableNo(tagObj, true);
				if (this._downendPos != null && this._downstartPos != null) 
					this.getContextMenu().setTableRange(this._downstartPos, this._downendPos);
			}
		}
		if (this._mouseclickeventstop) {
			if (this.restoreClickbind == null)
				this.restoreClickbind = this.restoreClickEvent.bind(this);
			window.setTimeout(this.restoreClickbind, 100);
		}
		this._editorObject.htmlEditor.onChange();
	},
	restoreClickEvent : function() {
		if (this._mouseclickeventstop) {
			cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'click',this.clickBind);
				this._mouseclickeventstop = false;
		}
	},
	getContextMenu : function() {
		if (this._editorObject.contextmenu == null) {
			this._editorObject.contextmenu = new cafen.Editor.contextMenu(this,{sticker : {obj : this._editorObject.frmSkin, x : 'left', y : 'top'}});
			this._editorObject.editorPopup.addChild(this._editorObject.contextmenu);
		}
		return this._editorObject.contextmenu;
	},
	setContextMenu : function(event) {
		var obj = this.getSelectedElement();
		if (obj != null) {
			var pos = this._editorObject.htmlEditor.getEventPointer(event);
			this.getContextMenu().setTagObject(obj, pos[0], pos[1]);
			this._lastcontextshown = true;
		}
		if (this._mouseclickeventstop) 
			this.restoreClickEvent();
		cafen.Event.stop(event);
		return false;
	},
	setDesignMode : function() {
		try {
			if (this.tryoutcnt == null)
				this.tryoutcnt = 0;
			else
				this.tryoutcnt ++;
			if (this._editorObject.htmlEditor.getWindow() && this._editorObject.htmlEditor.getDocument()) {
//				if (!this.config.useMobleUI) {
					this.contextmenubind = this.setContextMenu.bind(this);
					cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'contextmenu',this.contextmenubind, true);
					cafen.Event.observe(this._editorObject.htmlEditor.getScrollObject(),'scroll',this.hideContextmenu.bind(this));
//				}
				cafen.setStyle(this._editorObject.htmlEditor.getRealObject(),this.conf.editorScroll());
				this.buttonUpdateBind = this.buttonUpdate.bind(this);
				this.setDropDocBind = this.setDropDoc.bind(this);
				this.setDropDocEndBind = this.setDropDocEnd.bind(this);

				this.keypressbind = this.setKeyPress.bindAsEventListener(this);
				cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'keydown',this.keypressbind, true);

				this.clickBind = this.setClickDoc.bindAsEventListener(this);
				cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'click',this.clickBind);
				this._editorObject.htmlEditor.setOnChangeRange(this.buttonUpdateBind);
				this.mouseDownBind = this.setMouseDown.bindAsEventListener(this);
				cafen.Event.observe(this._editorObject.htmlEditor.getRealObject(),'mousedown',this.mouseDownBind);

				this.config.toogleSize.tool = this._editorObject.buttonAreaOut.getSize()[1]+6;
				this.config.toogleSize.attach = (this._editorObject.AttachAreaOut != null) ? this._editorObject.AttachAreaOut.getSize()[1]+6 : 0;
				try {this.initDoc(); } catch(ex) { }
				try {this.buttonUpdate(); } catch(ex) {}
				this.setEditorHeight(this.config.height);
			} else if (this.tryoutcnt < 10) 
				window.setTimeout(this.setDesignModeBind,100);
		} catch(ex) {
			if (this.tryoutcnt < 10) 
				window.setTimeout(this.setDesignModeBind,100);
		}
	},
	setDropDoc : function() {
		window.setTimeout(this.setDropDocEndBind,1);
		return true;
	},
	setDropDocEnd : function() {
		var obj = this._editorObject.getRealObject().getElementById('thumb_cafenimg');
		if (obj != null && obj.tagName == 'IMG') {
			obj.removeAttribute('id'); 
			cafen.setStyle(obj, {width : 'auto', height : 'auto', filter : null, cursor : null, position : null, left : null, top : null});
		}
	},
	initDoc : function() {
		var contents = this.config.contents;
		var htmlBreak = this._pageBreak;
		htmlBreak = htmlBreak.replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
		contents = contents.replace(eval('/'+htmlBreak +'/gi'),this._pageBreak);
		this.pageContents = [];
		var contentsArr = contents.split(this._pageBreak);
		for (var i = 0; i < contentsArr.length; i++)
			if (contentsArr[i] != '')
				this.pageContents.push(contentsArr[i]);
		if (this.pageContents.length == 0)
			this.pageContents.push('');
		this.currentPage = 0;
		contents = this.pageContents[this.currentPage];
		var init_mode = this.config.initmode.toLowerCase();
		if (this.config.onChangeHeight != null)
			this.onChangeHeight = this.config.onChangeHeight;
		switch(init_mode) {
			case 't' :
				this._editorObject.textEditor.setValue(cafen.html2Text(contents));
				break;
			case 'a' :
				this._editorObject.textEditor.setValue(contents);
				break;
			case 'h' :
			default :
				this.setHTML(contents);
				break;
		}
		if (this.editorAttachView != null) 
			this.editorAttachView.initFiles(this.config.attachtxt);
		this.config.initmode = this.config.initmode.toUpperCase();
		this.modeSwap(this.config.initmode, null);
		if (this.config.autosave > 0 || this.config.file_box != '')
			this.autoSave(2, true);
		try {
			this.setSize(this.config.width, this.config.height);
		} catch(ex) {}
		this.isloaded = true;
		if (this.config.onloadfocus)
			this.setFocus();
		if (this._editorObject.copyrightObj != null)
			this._editorObject.copyrightObj.getElement().innerHTML = '<a href="http://www.cafen.net" target=_blank><img src="'+_cafen_service_url+'images/ico_pwbycafen.gif" border=0 hspace=5 vspace=3></a>';
		if (this.config.onloadhidetoolbar)
			this.toggleToolBar();
		window.setTimeout(this.onLoad.bind(this), 10);
	},
	onLoad : function() {
		if (this.editorAttachView != null) 
			this.editorAttachView.onload();
		if (this._editorObject.htmlEditor)
			this._editorObject.htmlEditor.onChange();
		if (this.config.useMobleUI) {
			this.drawMobileToolbar();
			this._editorObject.htmlEditor.setOnChangeFocus(this.onDummyShowHide.bind(this));
			this.synkDummyPos();
		}
		if (this.config.onready != null && this.config.onready != '') {
			try {
				var funcObj = eval(this.config.onready);
				if (typeof funcObj == 'function')
					funcObj(this);
			} catch(ex) {}
		}
	},
/**
 * html 문서 내용가져오기
 * @return {string} html
 */
	getHTML : function() {
		if (this._editorObject.contextmenu != null) 
			this._editorObject.contextmenu.restoreCellColor();
		var contents = this.getFF2Source(this._editorObject.htmlEditor.getContents());
		return contents;
	},
	checkMode : function() {
		switch(this.config.modeCurr.toLowerCase()) {
			case 'h' :
				return true;
				break;
			default :
				return false;
		}
	},
	getContents : function() {
		var mode  = this.config.mode.toLowerCase();
		var contents = '';
		switch(mode) {
			case 's' :
				contents = this._editorObject.textEditor.getValue();
				break;
			case 't' :
				contents = cafen.text2Html(this._editorObject.textEditor.getValue());
				break;
			case 'a' :
				contents = cafen.text2Html(this._editorObject.textEditor.getValue());
				break;
			case 'h' :
			default : 	
				contents = this.getHTML();
				break;
		}
	  	return contents;
	},  
	setContents : function(txt) {
		var mode  = this.config.mode.toLowerCase();
		var contents = '';
		switch(mode) {
			case 't' :
			case 's' :
			case 'a' :
				this._editorObject.textEditor.setValue(txt);
				break;
			case 'h' :
			default : 	
				this.setHTML(txt);
				break;
		}
	},
	hideContextmenu : function() {
		if (this._lastcontextshown && this._editorObject.contextmenu) {
			this._lastcontextshown = false;
			this._editorObject.contextmenu.onClose();
			this._editorObject.contextmenu.hide();	
		}
		if (this._editorObject.contextmenu != null) 
			this._editorObject.contextmenu.restoreCellColor();
	},
	keyColorSet : {
		48 : '#ffffff',
		49 : '#000000',
		50 : '#eeece1',
		51 : '#1f497d',
		52 : '#4f81bd',
		53 : '#c0504d',
		54 : '#9bbb59',
		55 : '#8064a2',
		56 : '#4bacc6',
		57 : '#f79646'
	},
	keyMapShortCut : {
		'insertmap' : ['M',null],
		'inserticon' : ['E',null],
		'translate' : ['T',null],
		'insertdb' : ['R',null],
		'bold' : [null,'Ctrl + B'],
		'underline' : ['U','Ctrl + U'],
		'copy' : [null,'Ctrl + C'],
		'cut' : [null,'Ctrl + X'],
		'paste' : [null,'Ctrl + V'],
		'fontlarge' : [null,'Ctrl + >'],
		'fontsmall' : [null,'Ctrl + <'],
		'justifyleft' : [null,'Ctrl + L'],
		'justifycenter' : [null,'Ctrl + E'],
		'justifyright' : [null,'Ctrl + R'],
		'justifyfull' : [null,'Ctrl + J'],
		'strikethrough' : [null,'Ctrl + S'],
		'undo' : [null,'Ctrl + Z'],
		'redo' : [null,'Ctrl + Y'],
		'print' : [null,'Ctrl + P'],
		'createlink' : ['L','Ctrl + M'],
		'italic' : [null,'Ctrl + I'],
		'horizontalrule' : [null,'Ctrl + Enter'],
		'indent' : [null,'Ctrl + Tab'],
		'remove' : [null,'Ctrl + Del'],
		'outdent' : [null,'Ctrl + Shift + tab'],
		'callhelper' : ['H','Ctrl + H'],
		'find' : ['F','Ctrl + F'],
		'unorderedlist' : [null,'Ctrl + D'],
		'orderedlist' : [null,'Ctrl + Shift + D']
	},
	keyMapSpecalChar : '\u2469\u2460\u2461\u2462\u2463\u2464\u2465\u2466\u2467\u2468       \u24D0\u24D1\u24D2\u24D3\u24D4\u24D5\u24D6\u24D7\u24D8\u24D9\u24DA\u24DB\u24DC\u24DD\u24DE\u24DF\u24E0\u24E1\u24E2\u24E3\u24E4\u24E5\u24E6\u24E7\u24E8\u24E9\u247D\u2474\u2475\u2476\u2477\u2478\u2479\u247A\u247B\u247C       \u249C\u249D\u249E\u249F\u24A0\u24A1\u24A2\u24A3\u24A4\u24A5\u24A6\u24A7\u24A8\u24A9\u24AA\u24AB\u24AC\u24AD\u24AE\u24AF\u24B0\u24B1\u24B2\u24B3\u24B4\u24B5',
	setKeyPress : function(event, obj) {
		try {
			this.hideContextmenu();
			if (event.altKey && event.keyCode == 18) {
				cafen.Event.stop(event);
				return false;
			}
			if ((event.ctrlKey && ((event.keyCode >= 40  && event.keyCode <= 191) || event.keyCode == 13)) || event.keyCode == 9 || event.keyCode == 27) {
				if (event.altKey) {
					var keyMap = this.keyMapSpecalChar.split('');
					var curCode = (event.shiftKey) ? event.keyCode - 5 : event.keyCode - 48;
					if (keyMap[curCode] != null && keyMap[curCode] != '')
						this.execCommand('insertHTML', false, keyMap[curCode]);
				} else {
					switch(event.keyCode) {
						case 27 :
							this.closePopup();
							break;
						case 40 :
							this.setContextMenu(event);
							break;
						case 13 :
							this.execCommand('InsertHorizontalRule',false, null);
							break;
						case 9 :
							if (event.shiftKey)
								this.execCommand('Outdent');
							else
								this.execCommand('Indent');
							break;
						case 48 :
						case 49 :
						case 50 :
						case 51 :
						case 52 :
						case 53 :
						case 54 :
						case 55 :
						case 56 :
						case 57 :
							this.execCommand( event.shiftKey ? 'BackColor' : 'ForeColor', false , this.keyColorSet[event.keyCode]);
							break;
						case 190:
							this.execCommand('fontlarge');
							break;
						case 188:
							this.execCommand('fontsmall');
							break;
						case 80 :
							this.execCommand('print',false, null);
							break;
						case 68 :
							this.execCommand(event.shiftKey ? 'InsertOrderedList' : 'InsertUnorderedList' ,false, null);
							break;
						case 76 :
							this.execCommand('JustifyLeft',false, null);
							break;
						case 69 :
							this.execCommand('JustifyCenter',false, null);
							break;
						case 82 :
							this.execCommand('JustifyRight',false, null);
							break;
						case 74 :
							this.execCommand('JustifyFull',false, null);
							break;
						case 72 :
						case 112 :
						case 191 :
							this.actionCommand('callhelper');
							break;
						case 70 :
							this.actionCommand('find');
							break;
						case 77 :
							this.actionCommand('createlink');
							break;
						case 46 :
							this.execCommand('RemoveFormat',false, null);
							break;
						case 83 :
							this.execCommand('StrikeThrough',false, null);
							break;
						case 85 :
							this.execCommand('Underline',false, null);
							break;
						case 66 :
							this.execCommand('bold',false, null);
							break;
						case 73 :
							this.execCommand('Italic',false, null);
							break;
						case 84 :
							this.toggleToolBar();
							break;
						default :
							return true;
							break;
					}
				}
				cafen.Event.stop(event);
				return false;
			}
		} catch(ex) {}
	},
	setFocusDoc : function(event) {
		return true;
	},
	setClickDoc : function(event, obj) {
		this.hideContextmenu();
		return true;
	},
	changeTab : function(mode) {
		this._tabMenu.E.setSelected(false);
		this._tabMenu.H.setSelected(false);
		this._tabMenu.T.setSelected(false);
		switch(mode) {
			case 'E':
				this._tabMenu.E.setSelected(true);
				this._editorObject.E.show();
				this._editorObject.textEditor.hide();
				break;
			case 'H':
				this._tabMenu.H.setSelected(true);
				this._editorObject.textEditor.show();
				this._editorObject.E.hide();
				break;
			case 'T':
				this._tabMenu.T.setSelected(true);
				this._editorObject.textEditor.show();
				this._editorObject.E.hide();
				break;
		}
	},
	selectCurrentObject : function(no) {
		if (!this.checkMode())
			return ;
		var currObj = this.lastSelectObject;
		for(var i = 0; i < no; i++) {
			if (currObj.parentNode == null) {
				currObj = null;
				break;
			} else
				currObj = currObj.parentNode;
		}
		if (currObj != null) 
			this.selectNode(currObj);
	},
	showHepler : function() {
		this.actionCommand('callhelper');
	},
	buttonUpdate : function() {
		try {
			this._lastSelectObj = this.getSelectedElement();
		} catch(ex) {
			cafen.debugMessage(ex);
		}
		if (this._editorObject.statusObj != null) {
			if (this.config.maxpageheight > 0) {
				if (this.getDocHeight() > this.config.maxpageheight) {
					this.showStatus(cafenMsg.get('ed_0136', this.getDocHeight(), this.config.maxpageheight));
				} else if (this.getDocWidth() > this.config.maxpagewidth) {
					this.showStatus(cafenMsg.get('ed_0137', this.getDocWidth(), this.config.maxpagewidth));
				} else {
					this.showStatus(cafenMsg.get('ed_0138', this.getPageCurrent(), this.getPageCnt()));
				}
			} else {
				var selectObj = this._lastSelectObj;
				if (selectObj) {
					var tags = [];
					var selectTag = selectObj;
					this.lastSelectObject = selectTag;
					var stopObj = this._editorObject.htmlEditor.getRealObject();
					while(selectTag && selectTag != stopObj) {
						if (selectTag.tagName != null && selectTag.tagName !='HTML')
							tags.push(selectTag.tagName);
						selectTag =  (selectTag.parentNode) ? selectTag.parentNode : null;
					}
					if (tags.length > 0) {
						var tmpDiv = new cafen.Div({style : {fontSize:'9px', lineHeight:'100%', height: '10px',margin:'3px 0 0 5px', fontFamily:"arial"}});
						var tmpTag = document.createElement("a");
						tmpTag.innerHTML = '?';
						tmpTag.href = "javascript:;";
						cafen.setStyle(tmpTag, {marginRight:'10px', fontSize : '9px'});
						tmpDiv.appendChild(tmpTag);
						tmpTag.onclick = this.showHepler.bind(this);
						for(var i = (tags.length - 1); i >= 0 ; i--) {
							tmpTag = document.createElement("a");
							tmpTag.innerHTML = tags[i];
							tmpTag.href = "javascript:;";
							cafen.setStyle(tmpTag, {margin:'0 5px', fontSize : '9px'});
							tmpDiv.appendChild(tmpTag);
							tmpTag.onclick = this.selectCurrentObject.bind(this, i);
							if (i != 0) 
								tmpDiv.appendChild(document.createTextNode('>'));
						}
						this.showStatus(tmpDiv);
					} else 
						this.showStatus('');
				} else
					this.showStatus('');
			}
		}
		this.updateButtonStatus(this.statusButton);
		if (this.mobileStatusButton != null && this.mobileStatusButton.length > 0)
			this.updateButtonStatus(this.mobileStatusButton);
		if (this.config.useMobleUI) 
			this.synkDummySize();
	},
	updateButtonStatus : function(statusButton) {
		for(var i = 0; i < statusButton.length; i++) {
			var obj = 	statusButton[i];
			switch(obj.cmd.toLowerCase()) {
				case 'fontname' :
					var fontName = this.queryCommandValue(obj.cmd);
					if (fontName != null) {
						fontName = fontName.split('"').join('');
						var fontNames = fontName.split(',');
						fontName = fontNames[0];
						if (fontName.indexOf('#') > 0)
							fontName = fontName.substring(0,16);
						try {							
						if (cafen.Editor.baseConf.fontname_alias[fontName] != null)
							obj.obj.childNodes[0].getElement().innerHTML = cafen.Editor.baseConf.fontname_alias[fontName];
						else
							obj.obj.childNodes[0].getElement().innerHTML = fontName;
						} catch(ex) {}
					}
					break;
				case 'formatblock' :
					if (this.aliasfontblocks == null) 
						this.aliasfontblocks = cafenMsg.get('ed_aliasfontblocks');
					var fontBlock = this.queryCommandValue(obj.cmd);
					if (typeof fontBlock == 'boolean') 
						fontBlock = this.getSelectedBlockTag();
					var blockName = (this.aliasfontblocks[fontBlock] == null) ? null : this.aliasfontblocks[fontBlock];
					if (blockName == null)
						blockName = obj.obj.getElement().title;
					obj.obj.childNodes[0].getElement().innerHTML = blockName;
					break;
				case 'unlink' :
					var selectObj = this._lastSelectObj;
					if (selectObj != null && selectObj.tagName == 'A') {
						obj.obj.setSelected(true);
						obj.obj.setDisable(false);
					} else {
						obj.obj.setSelected(false);
						obj.obj.setDisable(true);
					}
					break;
				case 'fontsize' :
					if (this.aliasfontsizes == null)
						this.aliasfontsizes = cafenMsg.get('ed_aliasfontsizes');
					var fontSize = this.queryCommandValue(obj.cmd);
					if (fontSize == null) {
						var selectObj = this._lastSelectObj || this.getSelectedElement();
						if (selectObj != null && selectObj.style)
							fontSize = selectObj.style.fontSize;
					}
					if (fontSize == null || fontSize == 0)
						fontSize = '';
					obj.obj.childNodes[0].getElement().innerHTML = (this.aliasfontsizes[fontSize] == null) ? fontSize : this.aliasfontsizes[fontSize];
					break;
				case 'lineheight' :
					var selectObj = this._lastSelectObj || this.getSelectedElement();
					if (selectObj != null && selectObj.tagName == null)
						selectObj = selectObj.parentNode;
					if (selectObj != null && selectObj.style) {
						var lineheight = selectObj.style.lineHeight;
						if (lineheight == null || lineheight == 0)
							lineheight = obj.obj.getElement().title;
						obj.obj.childNodes[0].getElement().innerHTML = lineheight;
					}
					break;
				case 'copystyle' :
				case 'pastestyle' :
					if (this._copyStyle == null)
						obj.obj.setSelected(false);
					else
						obj.obj.setSelected(true);
					break;
				case 'forecolor':
				case 'backcolor':
					obj.obj.childNodes[0].childNodes[0].setColor(cafen.rgb2hexFF(this.queryCommandValue(obj.cmd)));
					break;
				default : 
					obj.obj.setSelected(this.queryCommandState(obj.cmd));
					break;
			}
		}		
	},
	addNodeStyle : function(objNode, styleName, styleValue) {
		if (objNode.nodeType == 1) {
			objNode.style[styleName] = styleValue;
			for(var i = 0; i < objNode.childNodes.length; i++) 
				this.addNodeStyle(objNode.childNodes[i], styleName, styleValue);
		}
	},
	addNodeAttribute : function(objNode, attName, attValue) {
		if (objNode.nodeType == 1) {
			if (attValue == null)
				objNode.removeAttribute(attName); 
			else
				objNode.setAttribute(attName, attValue); 
			for(var i = 0; i < objNode.childNodes.length; i++) 
				this.addNodeAttribute(objNode.childNodes[i], attName, attValue);
		}
	},
	selectNode : function(thisNode) {
		if (!this.checkMode())
			return ;
		this._editorObject.htmlEditor.selectNode(thisNode);
	},
	getSelectedBlockTag : function () {
		return this._editorObject.htmlEditor.getSelectedBlockTag();
	},	
	getParentElement : function(tag) {
		return this._editorObject.htmlEditor.getParentElement(tag);
	},
	getSelectedElement : function () {
		return this._editorObject.htmlEditor.getSelectedElement();
	},
	getSelectedType : function () {
		return this._editorObject.htmlEditor.getSelectedType();
	},
	unsetSelectedType : function() {
		return this._editorObject.htmlEditor.unsetSelectedType();
	},
	getSelectedHTML : function() {
		return this._editorObject.htmlEditor.getSelectedHTML();
	},
	queryCommandValue: function(cmd) {
		return this._editorObject.htmlEditor.queryCommandValue(cmd);
	},		
	queryCommandState : function(cmd) {
		return this._editorObject.htmlEditor.queryCommandState(cmd);
	},
	closePopup : function() {
		this._editorObject.editorPopup.closeChild();
		this._lastCommandObj = null;
		this._lastCommand = null;
	},
	actionCommand : function(cmd, obj, value, isMobileToolbar) {
		if (this._lastCommand == cmd)  {
			this.closePopup();
		} else {		
			this._lastCommandObj = null;
			this._lastCommand = cmd;
			switch(cmd) {
				case 'save' :
					if (this.config.file_box == '')
						this.showMsg(cafenMsg.get('ed_0036'));
					else
						this.showConfirm(cafenMsg.get('ed_0118'), this.saveDoc.bind(this));
					this._lastCommand = null;
					break;
				case 'createlink' :
					this._lastCommandObj = this.getActionObject(cmd,obj,isMobileToolbar);
					this._lastCommand = null;
					break;
				default :
					this._lastCommandObj = this.getActionObject(cmd,obj,isMobileToolbar);
					break;
			}
			if (this._lastCommandObj != null )
				this.showPopup(this._lastCommandObj);
		}
		return true;
	},
	getActionObjectSticker : function(cmd,isMobileToolbar) {
		if (isMobileToolbar) {
			var buttonPos = cafen.cumulativeOffset(this.mobileActionButton[cmd].obj.getObject());
			var frmPos = cafen.cumulativeOffset(this._editorObject.frmSkin.getObject());
			var x = buttonPos[0] - frmPos[0] ;
			if (x + 200 > this.config.width)
				return {obj : this.mobileActionButton[cmd].obj, x : 'exright', y : 'bottom', plus : [5, 0]};
			else
				return {obj : this.mobileActionButton[cmd].obj, x : 'left', y : 'bottom'};
		} else {
			var buttonPos = cafen.cumulativeOffset(this.actionButton[cmd].obj.getObject());
			var frmPos = cafen.cumulativeOffset(this._editorObject.frmSkin.getObject());
			var x = buttonPos[0] - frmPos[0] ;
			if (x + 200 > this.config.width)
				return {obj : this.actionButton[cmd].obj, x : 'exright', y : 'bottom', plus : [5, 0]};
			else
				return {obj : this.actionButton[cmd].obj, x : 'left', y : 'bottom'};
		}
	},
	getActionObject : function(cmd,buttonObj,isMobileToolbar) {
		if (isMobileToolbar) {
			if (this.mobileActionButton[cmd] == null) 
				this.mobileActionButton[cmd] = 	{classObj : null, obj : null};
			if (this.mobileActionButton[cmd].classObj != null)
				return this.mobileActionButton[cmd].classObj;
			buttonObj = this.mobileActionButton[cmd].obj;
		} else {
			if (this.actionButton[cmd] == null) 
				this.actionButton[cmd] = 	{classObj : null, obj : null};
			if (this.actionButton[cmd].classObj != null)
				return this.actionButton[cmd].classObj;
			buttonObj = this.actionButton[cmd].obj;
		}
		var classObj = null;		
		switch(cmd) {
			case 'new' :
				classObj = new cafen.XConfirm({title : cafenMsg.get('com_confirm'), contents : this.getPaddingText(cafenMsg.get('ed_0035')), sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'middle'}, onClose : this.execCommand.bind(this, 'new','')});
				break;
			case 'insertimage' :
				classObj = new cafen.Editor.Image(this,{ 
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj
					});
					break;
			case 'insertmovie' :
			case 'insertmedia' :
				classObj = new cafen.Editor.Movie(this,{ 
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj
					});
					break;
			case 'createlink' :
				if (buttonObj == null) {
					classObj = new cafen.Editor.HrefLink(this, { 
						sticker : {obj : this._editorObject.frmSkin, x : 'exright', y : 'top'}
						});
				} else {
					classObj = new cafen.Editor.HrefLink(this, { 
						sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
						linkButton : buttonObj
						});
				}
					break;
			case 'fontblock' :
				classObj = new cafen.Editor.FormatBlock(this, { 
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj
					});
				break;
			case 'backcolor' :
			case 'forecolor' :
				classObj = new cafen.Editor.ColorPicker(this, cmd,{ 
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj
					});
				break;
			case 'specialchar' :
				classObj = new cafen.Editor.SpecialChar(this,{ 
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj
					});
				break;
			case 'inserttable' :
				classObj = new cafen.Editor.TableMaker(this,{ 
						sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
						linkButton : buttonObj
					});
				break;
			case 'inserticon' :
				classObj = new cafen.Editor.Emoticon(this,{ 
						sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
						linkButton : buttonObj
					});
				break;
			case 'find' :
				classObj = new cafen.Editor.FindReplace(this,{ 
						sticker : {obj : this._editorObject.frmSkin, x : 'exright', y : 'top'},
						linkButton : buttonObj
					});
				break;
			case 'divblock' :
				classObj = new cafen.Editor.DivBlock(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'changestyle' :
				classObj = new cafen.Editor.SelectStyle(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'inserthtml' :
				classObj = new cafen.Editor.FormatHtml(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'fontname' :
				classObj = new cafen.Editor.FontName(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'fontsize' :
				classObj = new cafen.Editor.FontSize(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'lineheight' :
				classObj = new cafen.Editor.LineHeight(this, {
					sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
					linkButton : buttonObj,
					style : {}
					});
				break;
			case 'translate' : 
				if (cafenGlobalConf.useTranlate) {
					classObj = new cafen.Editor.Translate(this, {
						sticker : this.getActionObjectSticker(cmd,isMobileToolbar),
						linkButton : buttonObj,
						style : {}
						});
				} else {
					classObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents : this.getPaddingText(cafenMsg.get('ed_0036')), sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'top'}});
				}
				break;
			case 'insertdb' :
				classObj = new cafen.Editor.DataBase(this,{ 
					sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'top', plus : [0,0]},
					linkButton : buttonObj,
					style : {overflowX : 'hidden', overflowY : 'auto'}
					});
				break;
			case 'callhelper' :
				classObj = new cafen.Editor.Helper(this, {sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'top'},linkButton : buttonObj});
				break;
			default :
				if (cafenEditor_loader.editorBaseConf.Plugin[cmd] != null) {
					var currObj = cafenEditor_loader.editorBaseConf.Plugin[cmd];
					if (currObj.fnc != null)
						classObj = currObj.fnc;
					else if (currObj.obj != null) 
						classObj = new currObj.obj(this);
					else
						classObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents : this.getPaddingText(cafenMsg.get('ed_0037')), sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'top'}});
				} else
					classObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents : this.getPaddingText(cafenMsg.get('ed_0037')), sticker : {obj : this._editorObject.frmSkin, x : 'center', y : 'top'}});
				break;
		}
		if (isMobileToolbar) {
			this.mobileActionButton[cmd].classObj = classObj;
			if (this.mobileActionButton[cmd].classObj != null && typeof this.mobileActionButton[cmd].classObj == 'object')
				this._editorObject.editorPopup.addChild(this.mobileActionButton[cmd].classObj);
			return this.mobileActionButton[cmd].classObj;
		} else {
			this.actionButton[cmd].classObj = classObj;
			if (this.actionButton[cmd].classObj != null && typeof this.actionButton[cmd].classObj == 'object')
				this._editorObject.editorPopup.addChild(this.actionButton[cmd].classObj);
			return this.actionButton[cmd].classObj;
		}
	},
	getPaddingText : function(txt) {
		return '<div style="padding:5px;line-height:130%;text-align:center">'+txt+'</div>';
	},
	showPopup : function(obj) {
		if (this._editorObject.editorPopup._lastOpenChild == obj) 
			this._editorObject.editorPopup.closeChild();
		else {
			if (obj != null) {
				if (typeof obj == 'object' && obj.onLoad)
					obj.onLoad();
				else if (typeof obj == 'function') {
					obj(this);
					this._lastCommand = null;
				}
			}
		}
	},
	getSource2FF : function(contents) {
		if (cafen.Editor.baseConf.isIE) 
			return contents;
		else {
			var tmpObj = document.createElement('div');
			tmpObj.innerHTML = contents;
			var tags = tmpObj.getElementsByTagName('*'); 
			var removeObj = [];
			for(var i = 0; i < tags.length; i++) {
				var currObj = tags[i];
				if (currObj.tagName != null) {
					switch(currObj.tagName.toLowerCase()) {
						case 'embed' :
						case 'object' :
						case 'iframe' :
							var src= currObj.getAttribute('src');
							var flashvars= currObj.getAttribute('flashvars');
							var width= currObj.getAttribute('width');
							var height= currObj.getAttribute('height');
							var replace_obj = cafen.getImage({src :_cafen_service_url + 'images/img_fftmp.gif', title : '외부 자료가 첨부 되었습니다.'});
							replace_obj.setAttribute('url', src);
							if (flashvars != null)
								replace_obj.setAttribute('flashvars', flashvars);
							replace_obj.setAttribute('width', width);
							replace_obj.setAttribute('height', height);
							replace_obj.setAttribute('contentType', currObj.tagName.toLowerCase());
							replace_obj.style.width = width + 'px';
							replace_obj.style.height = height + 'px';
							replace_obj.style.border = '2px dotted #767676';
							removeObj.push([currObj, replace_obj]);
							break;
					}
				}
			}
			for (var i = 0; i < removeObj.length; i++) {
				var currObj = removeObj[i];
				currObj[0].parentNode.insertBefore(currObj[1], currObj[0]);
				currObj[0].parentNode.removeChild(currObj[0]);
			}
			return tmpObj.innerHTML;
		}
	},
	getFF2Source : function(contents) {
		if (cafen.Editor.baseConf.isIE) 
			return contents;
		else {
			var tmpObj = document.createElement('div');
			tmpObj.innerHTML = contents;
			var tags = tmpObj.getElementsByTagName('*'); 
			var removeObj = [];
			for(var i = 0; i < tags.length; i++) {
				var currObj = tags[i];
				if (currObj.tagName != null) {
					switch(currObj.tagName.toLowerCase()) {
						case 'img' :
							var contentType= currObj.getAttribute('contentType');
							if (contentType != null && contentType != '') {
								var src= currObj.getAttribute('url');
								var width= currObj.getAttribute('width');
								if (width == null || width == '')
									width = parseInt(currObj.style.width);
								var height= currObj.getAttribute('height');
								if (height == null || height == '')
									height = parseInt(currObj.style.height);
								switch(contentType.toLowerCase()) {
									case 'embed' :
									case 'object' :
									case 'iframe' :
										var replace_obj = document.createElement(contentType.toLowerCase());
										var flashvars = currObj.getAttribute('flashvars');
										if (flashvars != null) 
											replace_obj.setAttribute('flashvars', flashvars);
										if (contentType.toLowerCase() == 'embed' || contentType.toLowerCase() == 'object')
											replace_obj.setAttribute('wmode', 'transparent');
										replace_obj.setAttribute('src', src);
										replace_obj.setAttribute('width', width);
										replace_obj.setAttribute('height', height);
										if (contentType.toLowerCase() == 'iframe') {
											replace_obj.setAttribute('scrolling', 'no');
											replace_obj.setAttribute('frameBorder', 0);
											replace_obj.setAttribute('allowTransparency', true);
										}
										replace_obj.style.width = width + 'px';
										replace_obj.style.height = height + 'px';
										removeObj.push([currObj, replace_obj]);
										break;
								}
							}
							break;
					}
				}
			}
			for (var i = 0; i < removeObj.length; i++) {
				var currObj = removeObj[i];
				currObj[0].parentNode.insertBefore(currObj[1], currObj[0]);
				currObj[0].parentNode.removeChild(currObj[0]);
			}
			return tmpObj.innerHTML;
		}
	},
	setHTML : function(html, append_mode) {
		if (append_mode)
			html = this.getHTML() + '<br>' + html;
		this._editorObject.htmlEditor.setContents((html == '')?'<p>&nbsp;</p>':this.getSource2FF(html));
	},
	insertHTML : function(html, last_range, pos, beforeObj) {
		this._editorObject.htmlEditor.insertHTML(this.getSource2FF(html),beforeObj);
	},
/**
 * 외부에서  문서에 html 넣기
 * @param {string} html  넣을 html 문서
 * @param {int} pos  대상 위치
 */
	insertHTMLOUT : function(html, pos) {
		if (this.checkMode()) {
			switch(pos) {
				case 1 :
				case 2 :
				case 3 :
					var docs = this.getContents();
					if (pos == 1)
						docs =  html + '<br>' + docs;
					else if (pos == 2)
						docs =  docs + '<br>' + html;
					else 
						docs =  html;
					this.setHTML(docs);
					break;
				default :
					this.insertHTML(html);
					break;
			}
		} else {
			var myField = this._editorObject.textEditor.getElement();
			switch(pos) {
				case 1 :
				case 2 :
				case 3 :
					var docs = myField.value;
					if (pos == 1)
						docs =  html + '<br>' + docs;
					else if (pos == 2)
						docs =  docs + '<br>' + html;
					else 
						docs =  html;
					myField.value = docs;
					break;
				default :
					if (document.selection) { 
						myField.focus(); 
						sel = document.selection.createRange(); 
						sel.text = html; 
						sel.select();
					} else if (myField.selectionStart && myField.selectionStart == '0') { 
						var startPos = myField.selectionStart; 
						var endPos = myField.selectionEnd; 
						myField.value = myField.value.substring(0, startPos)+ html+ myField.value.substring(endPos, myField.value.length); 
					} else {
						myField.value += html; 
						myField.scrollTop = myField.scrollHeight - myField.clientHeight;
						myField.focus();
					}
					break;
			}
		}
	},
	getSavedDoc : function() {
		if (this.loaddoc_class == null) {
			this.loaddoc_class = new cafen.Editor.loadDoc(this,{
						sticker : {obj : this._editorObject.saveObj, x : 'exright', y : 'bottom', plus:[0,0]},
						style : {}
						});
			this._editorObject.editorPopup.addChild(this.loaddoc_class);
		}
		this.showPopup(this.loaddoc_class);
	},
/**
 * 자동 저장
 * @param {int} next_time  실행 시간
 * @param {boolean} bl 강제 실행 여부
 */
	autoSave : function(next_time, bl) {
		if (this._autosaveEvent != null)
			window.clearTimeout(this._autosaveEvent);
		if (bl) 
			this.saveDoc(true);
		else if (next_time >= 5) {
			this._autosaveEvent = window.setTimeout(this.saveDoc.bind(this), next_time * 1000);
		}
	},
/**
 * 자동 저장 설정
 * @param {int} val  실행 시간
 */
	setAutoSave : function(val) {
		val = (val < 10) ? 0 : val; 
		if (val > 0) {	
			var sec = val % 60;
			var min = Math.floor(val / 60);
			this.setSaveDocStatus(cafenMsg.get('ed_0123') + ' (' + min +':'+sec +')');
		} else 
			this.setSaveDocStatus(cafenMsg.get('ed_0123') + ' (' + cafenMsg.get('ed_0124') +')');
		if (this.config.autosave != val) {
			this.config.autosave = val ;
			this.autoSave(this.config.autosave);
		}
	},
/**
 * 자동 저장 설정
 * @param {boolean} bl  강제 실행
 */
	saveDoc : function(bl) {
		if (this._editordocid == null)
			this._editordocid = cafen.getUniqID('doc');
		var docs = this.getFullContents();
		if (docs != '' ) {
			var doctitle = (this.config.linktitle != null && this.config.linktitle != undefined) ? this.config.linktitle.value : '';
			if (doctitle == '' && this.last_doctitle != null)
				doctitle = this.last_doctitle;
			if (doctitle == null || doctitle == 'null')
				doctitle = '';
			new cafen.Ajax({mode:'SAVE', title : doctitle, boxid : this.config.file_box, docid : this._editordocid , doc: docs}, this.saveDocEnd.bind(this), null, 'post');
			this.setSaveDocStatus('Saving ....');
		} else if (bl) {
			new cafen.Ajax({mode:'SAVE', boxid : this.config.file_box, docid : this._editordocid , doc: ''}, this.saveDocEnd.bind(this), null, 'post');
		} else if (this.config.autosave > 0) 
			this.autoSave(this.config.autosave);
	},
/**
 * 자동 저장 완료
 * @param {cafen.xmlParser.Channel} channel  채널
 */
	saveDocEnd : function(channel) {
		this.setDocCount(parseInt(channel.getNode ? channel.getNode('doccount') : 0));
		if (this.config.autosave > 0) 
			this.autoSave(this.config.autosave);
	},
/**
 * 저장 문서 가져오기
 * @param {string} idx 문서 고유번호
 */
	openDoc : function(idx) {
		this.lastCallDocIdx = idx;
		this.showConfirm(cafenMsg.get('ed_0119'), this.openDocConfirm.bind(this), false);
		
	},
	openDocConfirm : function(bl) {
		if (bl) {
			if (this.lastCallDocIdx == null) 
				this.lastCallDocIdx = (this._editordocid != null) ? this._editordocid : null;
			else
				this._editordocid = this.lastCallDocIdx;
			if (this.lastCallDocIdx == null)
				return ;
			new cafen.Ajax({mode:'OPEN', boxid : this.config.file_box, docid : this.lastCallDocIdx}, this.openDocEnd.bind(this), null, 'post');
			this.setSaveDocStatus('Loading ....');
		}
	},
/**
 * 저장 문서 가져오기 완료
 * @param {cafen.xmlParser.Channel} channel  채널
 */
	setDoc : function(docs) {
		docs = docs.replace(/&gt;/gi,'>').replace(/&lt;/gi,'<').replace(/&amp;/gi,'&');
		this.obj.value = docs;
		this.config = new cafen.Editor.Config(this, this.initConfig);
		this.initDoc();
	},
	resetDoc : function(docs) {
		this.initDoc();
	},
/**
 * 저장 문서 가져오기 완료
 * @param {cafen.xmlParser.Channel} channel  채널
 */
	openDocEnd : function(channel) {
		if (channel.checkMsg()) {
			var msg = channel.getMsg();
			this.showMsg(msg.title +'<hr>'+ msg.contents);
		} else {
			var docstitle = channel.getNode('doctitle');
			if (docstitle != null && docstitle != '' && docstitle != 'null') 
				this.last_doctitle = docstitle;
			var docs = channel.getNode('doc');
			if (docs != '') 
				this.setDoc(docs);
		}
		this.setDocCount(null);
		if (this.config.autosave > 0) 
			this.autoSave(this.config.autosave);
	},
/**
 * 기존 저장 문서 갯수 지정
 * @param {number} num  갯수
 */
	setDocCount : function(num) {
		if (num != null)
			this._editordoccnt = (!isNaN(num)) ? num : 0;
		if (this._editordoccnt != null)
			this.setSaveDocStatus(cafenMsg.get('ed_0122') +' <b>('+this._editordoccnt+')</b>');
		else
			this.setSaveDocStatus('');
	},
/**
 * Editor 종료
 * @param {boolean}
 */
	getFullContents : function(bl) {
		var contents = this.getContents();
		if (cafen.stripTags(contents).split('&nbsp;').join('').split(' ').join('') == '') {
			contents = '';
		}
		if (contents == '')
			return '';
		else {
			var boundary = cafen.Editor.baseConf.boundary;
			if (this.editorAttachView != null)
				contents = contents + boundary + ((this.config.mode == 'S')?'H':this.config.mode) + '*' + this.editorAttachView.parse(true)+boundary;
			else
				contents = contents + boundary + ((this.config.mode == 'S')?'H':this.config.mode) + '*' +boundary;
			return contents;
		}
	},
	aliasFontSizes :{
		'1' : '8pt',
		'2' : '10pt',
		'3' : '12pt',
		'4' : '14pt',
		'5' : '18pt',
		'6' : '24pt',
		'7' : '36pt',
		'10px' : '8pt',
		'13px' : '10pt',
		'16px' : '12pt',
		'18px' : '14pt',
		'24px' : '18pt',
		'32px' : '24pt',
		'48px' : '36pt'
	},
	fontSizesData :{
		'8pt' : 1,
		'10pt' : 2,
		'12pt' : 3,
		'14pt' : 4,
		'18pt' : 5,
		'24pt' : 6,
		'36pt' : 7
	},
	execCommand : function(cmd, bl, value, extra) {
		if (cmd == 'outlink') {
			cmd = value[0];
			value = value[1];
		}
		if (cmd.toLowerCase() == 'backcolor' && (cafen.browser.isFF || cafen.browser.isOpera)) 
			cmd = 'hilitecolor';
		this._editorObject.editorPopup.closeChild();
		this._lastCommandObj = null;
		this._lastCommand = null;
		switch(cmd.toLowerCase()) {
			case 'insertmap' :
				if (cafenEditor_loader.editorBaseConf.useStaticMap) 
					this.showContents(null, 'map');
				else
					this.showMsg(cafenMsg.get('ed_0036'));
				break;
			case 'closepopup' :
				break;
			case 'new' :
				if (value) 
					this.setHTML('');
				break;
			case 'changestyle' :
				this.changeStyle(value);
				break;
			case 'copystyle' :
				if (this._copyStyle == null) {
					var cssFontName = this.queryCommandValue('FontName');
					var cssBackColor = this.queryCommandValue('BackColor');
					var cssForeColor = this.queryCommandValue('ForeColor');
					var cssFontSize = this.queryCommandValue('FontSize');
					var cssBold = this.queryCommandState('Bold');
					var cssItalic = this.queryCommandState('Italic');
					var cssUnderline = this.queryCommandState('Underline');
					var cssStrikeThrough = this.queryCommandState('StrikeThrough');
					this._copyStyle = {
						cssFontName : cssFontName,
						cssBackColor : cssBackColor,
						cssForeColor : cssForeColor,
						cssFontSize : cssFontSize,
						cssBold : cssBold,
						cssItalic : cssItalic,
						cssUnderline : cssUnderline,
						cssStrikeThrough : cssStrikeThrough
					};
				} else
					this._copyStyle = null;
				break;
			case 'pastestyle' :
				if (this._copyStyle != null) {
					if (	this._copyStyle.cssFontName != null &&  this._copyStyle.cssFontName != '') 
						this.execCommand('FontName', 	null, this._copyStyle.cssFontName);
					if (	this._copyStyle.cssBackColor != null &&  this._copyStyle.cssBackColor != '') 
						this.execCommand('BackColor', 	null, this._copyStyle.cssBackColor);
					if (	this._copyStyle.cssForeColor != null &&  this._copyStyle.cssForeColor != '')
						this.execCommand('ForeColor', 	null, this._copyStyle.cssForeColor);
					if (	this._copyStyle.cssFontSize != null &&  this._copyStyle.cssFontSize != '')
						this.execCommand('FontSize', 	null, this._copyStyle.cssFontSize);
					if (	this._copyStyle.cssBold != null &&  this._copyStyle.cssBold != this.queryCommandState('Bold'))
						this.execCommand('Bold', 	null, true);
					if (	this._copyStyle.cssItalic != null &&  this._copyStyle.cssItalic != this.queryCommandState('Italic'))
						this.execCommand('Italic', 	null, true);
					if (	this._copyStyle.cssUnderline != null &&  this._copyStyle.cssUnderline != this.queryCommandState('Underline'))
						this.execCommand('Underline', 	null, true);
					if (	this._copyStyle.cssStrikeThrough != null &&  this._copyStyle.cssStrikeThrough != this.queryCommandState('StrikeThrough'))
						this.execCommand('StrikeThrough', 	null, true);
				}
				break;
			case 'insertmore' :
				var uniqid = cafen.getUniqID('more');
				this.insertHTML('<br><div class="moretitle" id="'+uniqid+'"><p>&gt; '+cafenMsg.get('ed_0120')+'</p></div><div  class="morecontents" id="'+uniqid+'_contents"><p>'+cafenMsg.getObject('ed_0121')+'</p></div><p>&nbsp;</p>');
			case 'save' :
				if (value) 
					this.saveDoc();
				break;
			case 'open' :
				if (value) 
					this.openDoc();
				break;
			case 'sethtml' :
				this.setHTML(value);
				break;
			case 'inserthtml' :
				this.insertHTML(value, null, null, extra);
				break;
			case 'inserthtmlend' :
				this.insertHTMLOUT(value,0);
				break;
			case 'createlink' : 
				var html = this.getSelectedHTML();
				if (html == null || html == '' )
					html = value;
				this.insertHTML('<a href="'+value+'">'+html+'</a>');
				break;
			case 'attach' :
				if (value !=undefined && this.editorAttachView.chkUploadSize(value.size)) {
					if (value.html_tag != undefined && value.html_tag != '') 
						this.insertHTML(value.html_tag, null, null, extra);
					this.editorAttachView.addFile(value);
					this.editorAttachView.updateScale();
					this.setloadUnload(true);
					return true;
				} else
					return false;
				break;
			case 'extra' :
				var obj = cafen.extend(
					{server :'', param :'', add : false, width : 0, height : 0, align : ''}
					, value);
				this.attach.setFileParam(obj.server, obj.param, obj.add, obj.width, obj.height, obj.align);
				break;
			case 'lineheight' :
				var selectObj = this._lastSelectObj || this.getSelectedElement();
				if (selectObj != null && selectObj.tagName == null)
					selectObj = selectObj.parentNode;
				if (selectObj != null) {
					this.addNodeStyle(selectObj, 'lineHeight', value);
					selectObj.style.lineHeight = value;
				}
				break;
			case 'fontlarge' :
			case 'fontsmall' :
			case 'fontsize' :
				if (cmd.toLowerCase() == 'fontlarge' || cmd.toLowerCase() == 'fontsmall') {
					var fontSize = this.queryCommandValue('FontSize');
					if (fontSize != null)
						fontSize = this.aliasFontSizes[fontSize +''];
					if (fontSize == null)
						fontSize = '8pt';
					var fontSizeVal = this.fontSizesData[fontSize];
					if (fontSizeVal == null)
						fontSizeVal = 1;
					if (cmd.toLowerCase() == 'fontlarge')
						fontSizeVal ++;
					else
						fontSizeVal --;
					cmd = 'FontSize';
					value = Math.min(8, Math.max(1,fontSizeVal));
					bl = false;
				}
				if (Math.round(value) != value) {
					try {
						this._editorObject.htmlEditor.execCommand(cmd,bl, 2);
						var selectObj = this.getSelectedElement();
						if (selectObj != null) {
							this.addNodeAttribute(selectObj, 'size', null);
							switch(value) {
								case 1.5 :
									this.addNodeStyle(selectObj, 'fontSize', '9pt');
									break;
								case 2.5 :
									this.addNodeStyle(selectObj, 'fontSize', '11pt');
									break;
								default :
									break;
							}
						}
					} catch(ex) {}
				} else {
					var selectObj = this.getSelectedElement();
					if (selectObj !=null)
						this.addNodeStyle(selectObj, 'fontSize', null);
					this._editorObject.htmlEditor.execCommand(cmd,bl, value);
				}
				break;
			default : 
				try {
					this._editorObject.htmlEditor.execCommand(cmd,bl, value);
				} catch(ex) {
					this.showMsg(ex);
				}
				break;
		}
		return true;
	},
	saveFocus : function() {
		this._editorObject.htmlEditor.saveFocus();
	},
	setFocus : function() {
		this._editorObject.htmlEditor.setFocus();
	}
},cafen.Element.prototype);


cafen.Editor.ButtonColor = function(options) {
	this.setOptions(cafen.extend(options, {tag : 'div', attribute :{}, style : {width :'16px', height:'4px', overflow : 'hidden', backgroundColor : '#ff0000', marginTop: '11px'}}));
}

cafen.Editor.ButtonColor.prototype = cafen.extendClass({
	setColor : function(bgColor) {
		if (bgColor != null && bgColor != '')
			this.setStyle({backgroundColor : bgColor});
	}
},cafen.Element.prototype);

cafen.Editor.FontSize = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initFontSize();
}

cafen.Editor.FontSize.prototype = cafen.extendClass({
	initFontSize : function() {
		var fontSizes =  cafenMsg.getObject('ed_fontsizes');;
		var fontMenu = [];
		var iconInfo = {
			'8pt' : 0,
			'9pt' : 16,
			'10pt' : 32,
			'11pt' : 48,
			'12pt' : 64,
			'14pt' : 80,
			'18pt' : 96,
			'24pt' : 112,
			'36pt' : 128
		}
		var shortkey = 0;
		var currShortKey = null;
		for(var i = 0; i < fontSizes.length; i++) {
			currShortKey = (shortkey++ < 9) ? shortkey : null;
			var currObj = fontSizes[i];
			var icon = (iconInfo[currObj.show] != null) ? {className : 'r_editorset', x : iconInfo[currObj.show], y : 256} : {text : currObj.show};
			fontMenu.push({icon : icon, height : currObj.height,  text : '<font style="font-size:'+currObj.show+';line-height:100%">'+currObj.title+'</font>', options : currObj.value});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(fontMenu, 230, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'hidden'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		this._editorObject.execCommand('fontSize', false, obj.options.itemOptions);
	},
	onPopup : function() {
		var fontSize = this._editorObject.queryCommandValue('fontSize');
		if (fontSize == null) {
			var selectObj = this._editorObject.getSelectedElement();
			var fontSizeStyle = selectObj.style.fontSize;
			switch(fontSizeStyle) {
				case '9pt' :
					fontSize = 1.5;
					break;
				case '11pt' :
					fontSize = 2.5;
					break;
			}
		}
		var items = this.xMenu.getItems();
		
		for(var i = 0 ; i < items.length; i++) {
			if (fontSize > 0 && items[i].options.itemOptions == fontSize) 
				items[i].setSelected(true);
			else
				items[i].setSelected(false);
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.LineHeight = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initLineHeight();
}

cafen.Editor.LineHeight.prototype = cafen.extendClass({
	initLineHeight : function() {
		var fontSizes =  [
			'100%',
			'120%',
			'140%',
			'160%',
			'180%',
			'200%',
			'220%',
			'240%',
			'260%',
			'280%',
			'300%',
			'320%'
		];
		var fontMenu = [];
		for(var i = 0; i < fontSizes.length; i++) {
			var currObj = fontSizes[i];
			var seqn = 7 +i;
			seqn = Math.min(seqn, 11);
			var x = (seqn % 10) * 16;
			var y = Math.floor(seqn / 10) * 16 + 368;
			var icon = {className : 'r_editorset', x : x, y : y};
			fontMenu.push({icon : icon, text : currObj, options : currObj});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(fontMenu, 80, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		this._editorObject.execCommand('LineHeight', null, obj.options.itemOptions);
	},
	onPopup : function() {
		var selectObj = this._editorObject.getSelectedElement();
		var fontSize = selectObj.style.lineHeight;
		var items = this.xMenu.getItems();
		for(var i = 0 ; i < items.length; i++) {
			if (fontSize != '' && items[i].options.itemOptions == fontSize) 
				items[i].setSelected(true);
			else
				items[i].setSelected(false);
		}
	}
},cafen.XWindow.prototype);



cafen.Editor.HrefLink = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initHrefLink();
}

cafen.Editor.HrefLink.prototype = cafen.extendClass({
	initHrefLink : function() {
		var tmpTable = new cafen.TableAuto({attribute : {className:'r_table r_cell2px'}});
		this.appendChild(tmpTable);
		this.inputObj = new cafen.XInput({style : {width:'190px'}, shortkey : 'I', attribute : {unselectable : 'off'}, event : {end : this.sendValue.bind(this)}});
		tmpTable.addCell(this.inputObj);
		this.buttonObj = new cafen.XButton({text: cafenMsg.get('com_ok'), shortkey : 'O', event : {click : this.sendValue.bind(this)}});
		cafen.setNextObject(this.inputObj,this.buttonObj);
		tmpTable.addCell(this.buttonObj);
		cafen.setNextObject(this.inputObj,this.buttonObj);
	},
	sendValue : function() {
		if (this.inputObj.getValue() != '' && cafen.isURL(this.inputObj.getValue())) {
			if (this.selectObj == null) {
				this._editorObject.execCommand('createlink', null, this.inputObj.getValue());
			}else {
				try {
					this.selectObj.setAttribute('href', this.inputObj.getValue());
					var nodeValue = this.selectObj.innerHTML.replace( " ", "");
					if (nodeValue.indexOf('http:') == 0)
						this.selectObj.innerHTML = this.inputObj.getValue();
				} catch(ex) {

				}
				this._editorObject.execCommand('closepopup');
			}
		} else {
			if (this.selectObj != null && this.inputObj.getValue() == '') {
				this._editorObject.execCommand('unlink');
			} else
				this.inputObj.setError(true);
		}
		return false;
	},
	onPopup : function() {
		this.selectObj = this._editorObject.getParentElement('a');
		if (this.selectObj != null && this.selectObj.tagName == 'A') {
			this.inputObj.setValue(this.selectObj.getAttribute('href'));
		} else {
			this.selectObj = null;
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.Image = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'left', position :'absolute'}, shadow : true}, options));
	this.initImage();
}

cafen.Editor.Image.prototype = cafen.extendClass({
	initImage : function() {
		var tmpTable = new cafen.TableAuto({attribute : {className:'r_table r_cell2px'}});
		this.appendChild(tmpTable);
		this.inputObj = new cafen.XInput({style : {width:'170px', marginLeft:'3px'}, shortkey : 'I', attribute : {unselectable : 'off', value : 'http://'}, event : {end : this.previewImage.bind(this), blur : this.previewImage.bind(this)}});
		tmpTable.addCell(this.inputObj);
		tmpTable.addStyle({paddingTop:'3px',paddingBottom:'3px'})
		this.buttonObj = new cafen.XButton({text: cafenMsg.get('com_ok'), shortkey :'O', style: {marginLeft:'3px'},event : {click : this.sendValue.bind(this)}});
		tmpTable.addCell(this.buttonObj);
		this.previewArea = new cafen.Div({className :this._editorObject.conf.getClassName('buttonarea'), style:{width: '240px', height: '150px', overflowX : 'hidden', textAlign:'left',overflowY : 'hidden', overflow:'hidden',position:'relative' }});
		this.appendChild(this.previewArea);
		cafen.setNextObject(this.inputObj,this.buttonObj);
	},
	loadError : function() {
		if (this._lastImgObj != null)
			this._lastImgObj.hide();
		if (this._lastErrorObj == null) {
			this._lastErrorObj = new cafen.Div({style : {width:'240px', height : '100px'}, attribute : {innerHTML : 'ErrorLoading'}});
			this.previewArea.appendChild(this._lastErrorObj);
		}
		this._lastErrorObj.show();
	},
	previewImage : function() {
		var theURL = this.inputObj.getValue();
		if (theURL != '' && cafen.isURL(theURL)) {
			if (this._lastErrorObj != null)
				this._lastErrorObj.hide();
			if (this._lastImgObj == null) {
				this._lastImgObj = new cafen.Image(theURL, {style:{width:'240px', height : '150px', cursor : cafen.getCursor()}, scale : 'max', event : {fail : this.loadError.bind(this), click : this.sendValue.bind(this)}});
				this.previewArea.appendChild(this._lastImgObj);
			} else
				this._lastImgObj.setImage(theURL);
			this._lastImgObj.show();	
		}
		return true;
	},
	sendValue : function() {
		var theURL = this.inputObj.getValue();
		if (this._lastImgObj != null && this._lastImgObj.isLoaded() && theURL == this._lastImgObj.getImageUrl() ) {
			if (this._editorObject.editorAttachView != null && this._editorObject.config.attachAs)
				this._editorObject.editorAttachView.uploadRemote(theURL, '');
			else 
				this._editorObject.execCommand('insertHTML',null,'<img src='+this._lastImgObj.getImageUrl()+'>');
		} else if (theURL.indexOf('http://') == 0 && theURL.length > 15) {
			if (this.selectedObj != null) {
				this.selectedObj.setAttribute('src',theURL);
				this._editorObject.execCommand('closepopup');
			} else 
				this._editorObject.execCommand('insertHTML',null,'<img src='+theURL+'>');
		}else 
			this.inputObj.setError(true);
		return true;
	},
	onPopup : function() {
		this.selectedObj = this._editorObject.getParentElement('img');
		if (this.selectedObj != null) {
			this.inputObj.setValue(this.selectedObj.getAttribute('src'));
			this.previewImage();
			if (this._editorObject.getSelectedType() == "Control") 
				this._editorObject.unsetSelectedType();
		}
		this.inputObj.setError(false);
	},
	onClose : function() {
		this._editorObject.closePopup();
	}
},cafen.XWindow.prototype);

cafen.Editor.Movie = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className : this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initMovie();
}

cafen.Editor.Movie.prototype = cafen.extendClass({
	initMovie : function() {
		var tmpTable = new cafen.TableAuto({attribute : {className:'r_table r_cell2px'}});
		this.appendChild(tmpTable);
		this.inputObj = new cafen.XTextarea({style : {width:'200px', height:'100px'}, shortkey : 'I', attribute : {unselectable : 'off', value : 'http://'}, event : {}});
		tmpTable.addRow(this.inputObj);
		var buttonTable = new cafen.TableAuto({attribute : {className:'r_table r_cell2px', align:'center'}});
		tmpTable.addRow(buttonTable);
		tmpTable.addStyle({paddingTop:'3px',paddingBottom:'3px'})
		this.buttonObj = new cafen.XButton({text: cafenMsg.get('com_ok'), shortkey : 'O',event : {click : this.sendValue.bind(this)}, style :{width:'60px'}});
		buttonTable.addCell(this.buttonObj);
		buttonTable.addStyle({paddingRight:'3px'});
		cafen.setNextObject(this.inputObj,this.buttonObj);
		this.closeObj = new cafen.XButton({text: cafenMsg.get('com_close'), shortkey : 'C', event : {click : this.close.bind(this)}, style :{width:'60px'}});
		buttonTable.addCell(this.closeObj);
	},
	onClose : function() {
		this._editorObject.closePopup();
	},
	sendValue : function() {
		var theURL = this.inputObj.getValue();
		var reg = null;
		var flashvars = '';
		if (reg = cafen.find('flashvars="([^"\']+)"', theURL)) 
			flashvars = reg[1];
		var movie_width = 330;
		var movie_height = 227;
		
		if (reg = cafen.find('width=([^ ]+)', theURL)) {
			movie_width = parseInt(reg[1].split("'").join('').split('"').join(''));
			if (reg = cafen.find('height=([^ ]+)', theURL)) 
				movie_height = parseInt(reg[1].split("'").join('').split('"').join(''));
			else
				movie_height = Math.round(movie_width * 0.69);
		}
		if (theURL.length < 10) {
			this.inputObj.setError(true);
		} else if (reg = cafen.find('src=([^ ]+)', theURL))
			theURL = reg[1];
		else if (reg = cafen.find('(http[^ ]+)', theURL))
			theURL = reg[1];
		else if (reg = cafen.find('(mms[^ ]+)', theURL))
			theURL = reg[1];
		else
			theURL = '';
		if (reg = cafen.find('(http[^ ]+)', theURL))
			theURL = reg[1];
		else if (reg = cafen.find('(mms[^ ]+)', theURL))
			theURL = reg[1];
		else
			theURL = '';
		
		if (theURL == '' || theURL.length < 12) {
			this.inputObj.setError(true);
		} else {
			if (this.selectedObj == null) {
				var objs = [];
				objs.push('<embed type="application/x-shockwave-flash" wmode="transparent" ');
				objs.push('src="'+theURL+'" ');
				objs.push('allowFullScreen="true" width="'+movie_width+'px" height="'+movie_height+'px" quality="high" ');
				if (flashvars != '')
					objs.push('flashvars="'+flashvars+'"');
				objs.push('></embed>');
				this._editorObject.execCommand('insertHTML',null,objs.join(''));
			} else {
				if (	this.selectedObj.tagName == 'IMG') {
					
				} else {
					this.selectedObj.setAttribute('src', theURL);	
				}
				this._editorObject.execCommand('closepopup');
			}
		}
		return true;
	},
	onPopup : function() {
		this.selectedObj = this._editorObject.getParentElement('img,embed,object');
		if (this.selectedObj != null) {
			this.inputObj.setValue(this.selectedObj.getAttribute('url') || this.selectedObj.getAttribute('src'));
			if (this._editorObject.getSelectedType() == "Control") 
				this._editorObject.unsetSelectedType();
		} else {
			this.inputObj.setError(false);
		}
	}
},cafen.XWindow.prototype);


cafen.Editor.loadDoc = function(editorObj, options) {
	this._editorObject = editorObj;
	this.boxid = this._editorObject.config.file_box;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initLoadDoc();
};

cafen.Editor.loadDoc.prototype = cafen.extendClass({
	initLoadDoc : function() {
		var tmpTable = new cafen.TableAuto({style : {width: '150px'}});
		this.appendChild(tmpTable);
		tmpTable.addRow();
		this.displayObj = tmpTable.addCell();
		this.cmdBind = this.setValue.bind(this);
	},
	setSlider : function(val) {
		if (this.doc_obj.config.autosave != val)
			this.doc_obj.setAutoSave(val);
	},
	getList : function() {
		new cafen.Ajax({mode:'READ', boxid : this.boxid}, this.setList.bind(this), null, 'post');
	},
	setList : function(channel) {
		this.displayObj.addText('');
		if (channel.checkMsg()) {
			var msginfo = channel.getMsg();
			var msg = cafen.SwfUpload.getErrorHTML(msginfo.title, msginfo.domain , msginfo.contents);
			this.displayObj.addText(msginfo.contents);
			this._editorObject.setDocCount(0);
			window.setTimeout(this.close.bind(this),2000)
		} else {
			var item = null;
			var seqn = 0;
			var docMenu = [];
			while((item = channel.getNext()) && seqn <= 8) {
				var idx = item.getNode('url');
				var mdate = item.getNode('date');
				docMenu.push({icon :{text : ''}, text : mdate, options : idx});
				seqn ++;
			}
			this.xMenu = new cafen.XMenu(docMenu, 150, {event :{select : this.cmdBind}, style : {overflowX : 'hidden', overflowY : 'hidden'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
			this.displayObj.appendChild(this.xMenu);
			this._editorObject.setDocCount(seqn);
		}
	},
	deleteDoc : function(idx) {
		new cafen.Ajax({mode:'DELETE', boxid : this.boxid, docid : idx}, this.setList.bind(this), null, 'post');
	},
	setValue : function(tmp, obj) {
		this._editorObject.openDoc(obj.options.itemOptions);
	},
	onPopup : function() {
		this.getList();
	}
},cafen.XWindow.prototype);


cafen.Editor.FormatBlock = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initFormatBlock();
}

cafen.Editor.FormatBlock.prototype = cafen.extendClass({
	initFormatBlock : function() {
		var fontBlocks =  cafenMsg.getObject('ed_fontblocks');
		this.fontBlocksAlias =  cafenMsg.getObject('ed_aliasfontblocks');
		var fontMenu = [];
		for(var i = 0; i < fontBlocks.length; i++) {
			var currObj = fontBlocks[i];
			fontMenu.push({icon :{text : currObj.value}, text : currObj.title , options : {value: currObj.value, text : currObj.title}});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(fontMenu, 100, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'hidden'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		this._editorObject.execCommand('FormatBlock', null, '<' +obj.options.itemOptions.value +'>');
	},
	onPopup : function() {
		var fontBlocks = this._editorObject.queryCommandValue('FormatBlock');
		if (typeof fontBlocks == 'boolean' || fontBlocks == '') 
			fontBlocks = this._editorObject.getSelectedBlockTag();
		if (this.fontBlocksAlias[fontBlocks] != null)
			fontBlocks = this.fontBlocksAlias[fontBlocks];
		var items = this.xMenu.getItems();
		for(var i = 0 ; i < items.length; i++) {
			if (items[i].options.itemOptions.text == fontBlocks) 
				items[i].setSelected(true);
			else
				items[i].setSelected(false);
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.contextMenu = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend(options, {className : '', tag : 'div', style : { textAlign:'center', position :'absolute', width : '120px', overflow : ''}, shadow : false}));
	this.initcontextMenu();
}

cafen.Editor.contextMenu.prototype = cafen.extendClass({
	initcontextMenu : function() {
		this._loadedMenu = {};
	},
	getParentElement : function(tag, obj) {
		tag = tag.toUpperCase();
		var findObj = null;
		var tarObj = obj || this.lastObj;
		if (this.lastObj.tagName == 'TABLE') {
			while(tag.indexOf(tarObj.tagName) == -1 && tarObj.firstChild)
				tarObj = tarObj.firstChild;
		} else {
			while(tag.indexOf(tarObj.tagName) == -1 && tarObj.parentNode) {
				if (tarObj.parentNode == this._editorObject._editorObject.htmlEditor.getElement())
					break
				tarObj = tarObj.parentNode;
			}
		}
		if (tag.indexOf(tarObj.tagName) > -1)
			return tarObj;
		else
			return null;
	},
	getChildElements : function(tag, obj) {
		tag = tag.toUpperCase();
		var findObj = null;
		var tarObj = obj || this.lastObj;
		
		while(tarObj.tagName != tag && tarObj.firstChild)
			tarObj = tarObj.firstChild;
		if (tarObj.tagName == tag)
			return tarObj.childNodes;
		else
			return null;
	},
	createElement : function(tag) {
		return this._editorObject._editorObject.htmlEditor.createElement(tag);
	},
	cloneElement : function(obj, styles, attributes, innerValue) {
		styles = styles || [];
		attributes = attributes || [];
		var tarObj = this.createElement(obj.tagName);
		if (innerValue != null && innerValue != '')
			tarObj.innerHTML = innerValue;
		var cssStyle = {}
		var baseStyle = this.getCellStyle(obj);
		
		for(var j = 0 ; j < styles.length; j++) {
			var styleName = styles[j];
			var styleValue = null;
			switch(styleName) {
				case 'borderTop' :
					styleValue = baseStyle.top;
					break;
				case 'borderRight' :
					styleValue = baseStyle.right;
					break;
				case 'borderBottom' :
					styleValue = baseStyle.bottom;
					break;
				case 'borderLeft' :
					styleValue = baseStyle.left;
					break;
				default :
					styleValue = obj.style[styleName] ;
					break;
			}
			if (styleValue != null && styleValue != '')
				cssStyle[styleName] = styleValue;
		}
		cafen.setStyle(tarObj, cssStyle);
		var cellAttribute = {}
		for(var j = 0 ; j < attributes.length; j++) {
			var attrName = attributes[j];
			var attrValue = obj.getAttribute(attrName);
			if (attrValue != null && attrValue != '')
				cellAttribute[attrName] = attrValue;
		}
		cafen.setAttribute(tarObj, cellAttribute);
		return tarObj;
	},
	getObject2Array : function(obj) {
		var arrObjs = [];
		for(var i = 0; i < obj.childNodes.length; i++) 
			arrObjs.push(obj.childNodes[i]);
		return arrObjs;
	},
	_tblData : [],
	table2Arrange : function() {
		var tblObj = this.getParentElement('tbody');
		this._tblData = [];
		var tmpTbl = [];
		var colMax = 0, rowMax = 0;
		try {
			for(var i = 0 ; i < tblObj.childNodes.length; i++) {
				var currRow = tblObj.childNodes[i];
				if (currRow.nodeType == 1 && currRow.tagName == 'TR') {
					var rowTbl = [];
					for(var j = 0 ; j < currRow.childNodes.length; j++) {
						var currNode = currRow.childNodes[j];
						if (currNode.nodeType == 1 && currNode.tagName == 'TD') {
							var x = parseInt(currNode.getAttribute('colSpan') || 1);
							var y = parseInt(currNode.getAttribute('rowSpan') || 1);
							rowTbl.push([x, y, currNode, currNode.offsetWidth, currNode.offsetHeight]);
						}
					}
					tmpTbl.push(rowTbl);
				}
			}
			var totalCell = 0;
			for(var i = 0 ; i < tmpTbl.length; i++) {
				var currCol = 0;
				for(var j = 0 ; j < tmpTbl[i].length; j++) {
					var currObj = tmpTbl[i][j];
					totalCell += currObj[0] * currObj[1];
					currCol += currObj[0];
				}
				colMax = Math.max(colMax, currCol);
			}
			rowMax = Math.ceil(totalCell / colMax);
			for(var i = 0 ; i < rowMax; i++) {
				var tmpData = [];
				for(var j = 0 ; j < colMax; j++) 
					tmpData.push(null);
				this._tblData.push(tmpData);
			}
			for(var i = 0 ; i < tmpTbl.length; i++) {
				var currCol = 0;
				var currRow = 0;
				for(var j = 0 ; j < tmpTbl[i].length; j++) {
					var currObj = tmpTbl[i][j];
					currRow = i + currObj[1];
					for(var y = i ; y < currRow ; y++) {
						var addedNo = 0;
						var x = 0;
						while(addedNo < currObj[0]) {
							if (this._tblData[y][currCol + x] == null) {
								this._tblData[y][currCol + x] = currObj;
								addedNo++;
							}
							x++;
						}
					}
					currCol += currObj[0];
				}
			}
			this._tableOutSize = [tblObj.parentNode, tblObj.parentNode.offsetWidth, tblObj.parentNode.offsetHeight, colMax, rowMax];
		} catch(ex) {
			this._tblData = [];
		}
	},
	table2Fix : function() {
		var tblObj = this.getParentElement('table');
		if (tblObj != null) {
			var fixed = tblObj.getAttribute('fixed');
			if (fixed == null && this._tblData) {
				tblObj.setAttribute('fixed', 'true');
				for(var i = 0; i < this._tblData.length ; i++) {
					for(var j = 0; j < this._tblData[i].length ; j++) {
						var currObj = this._tblData[i][j][2];
						var currSize = cafen.getSize(currObj);
						cafen.setStyle(currObj, {width : currSize[0] +'px', height : currSize[1] +'px'});
					}
				}
			}	
		}
	},
	tableCellSize : function(pos, width, height, rule) {
		if (!rule[0])
			width = null;
		if (!rule[1])
			height = null;
		pos[0] = Math.max(pos[0],pos[2]);
		pos[1] = Math.max(pos[1],pos[3]);
		for(var i = 0; i < this._tblData.length ; i++) {
			for(var j = 0; j < this._tblData[i].length ; j++) {
				var currObj = this._tblData[i][j];
				if (pos[0] == i && height != null) { 
					var reheight = Math.max(1, currObj[4] + height); 
					cafen.setStyle(currObj[2], {height : reheight +'px'});
				}
				if (pos[1] == j && width != null) {
					var rewidth = Math.max(1, currObj[3] + width); 
					cafen.setStyle(currObj[2], {width : rewidth +'px'});
					var nextObj = this._tblData[i][j+1];
					if (nextObj != null) {
						var rewidth = Math.max(1, nextObj[3] - width); 
						cafen.setStyle(nextObj[2], {width : rewidth +'px'});
					} else {
						var rewidth = Math.max(1, this._tableOutSize[1] + width); 
						cafen.setStyle(this._tableOutSize[0], {width : rewidth +'px'});
					}
				}
			}
		}
	},
	lastTableObj : null,
	getTableNo : function(obj, donotArrange) {
		var tableObj = this._editorObject._editorObject.htmlEditor.getParentElement('TABLE', obj);
		if (tableObj == null)
			return null;
		if (!donotArrange) {
			this.lastTableObj = tableObj;
			this.table2Arrange();
		} else {
			if (this.lastTableObj != tableObj)
				return null;
		}
		if (this._tblData != null) {
			for(var i = 0; i < this._tblData.length ; i++) {
				for(var j = 0; j < this._tblData[i].length ; j++) {
					var currObj = this._tblData[i][j];
					if (currObj != null && (obj == currObj[2] || obj == currObj[2].parentNode)) {
						return [i, j, i + currObj[1] -1, j + currObj[0] -1];
						break;
					}
				}
			}
		}
		return [-1,0];		
	},
	_lastSelectedCell : [],
	_lastSelectedPos : [],
	reverseCellColor : function(obj, styleObj) {
		if (obj.style && styleObj != null) {
			var reMakeStyle = {};
			if (styleObj.top != null)
				reMakeStyle.borderTop = styleObj.top;
			if (styleObj.right != null)
				reMakeStyle.borderRight = styleObj.right;
			if (styleObj.bottom != null)
				reMakeStyle.borderBottom = styleObj.bottom;
			if (styleObj.left != null)
				reMakeStyle.borderLeft = styleObj.left;
			cafen.setStyle(obj, reMakeStyle);
		}
	},
	restoreCellColor : function() {
		if (this._lastSelectedCellOrgStyle != null && this._lastSelectedCellOrgStyle.length > 0) {
			for(var i = 0 ; i < this._lastSelectedCellOrgStyle.length; i++) {
				if (this._lastSelectedCellOrgStyle[i] != null) 
					this.reverseCellColor(this._lastSelectedCellOrgStyle[i][0], this._lastSelectedCellOrgStyle[i][1]);
			}
		}
		this._lastSelectedCell = [];
		this._lastSelectedCellOrgStyle = [];
	},
	selectCellColor : function() {
		this._lastSelectedCellOrgStyle = [];
		if (this._lastSelectedCell.length > 1) {
			var startX = this._lastSelectedPos[0];
			var endX = this._lastSelectedPos[2];
			var startY = this._lastSelectedPos[1];
			var endY = this._lastSelectedPos[3];
			var xsize = this._lastSelectedPos[2] - this._lastSelectedPos[0] + 1;
			var ysize = this._lastSelectedPos[3] - this._lastSelectedPos[1] + 1;
			var selectBorderStyle = '#f66e6e 2px solid';
			for(var py = startY; py <= endY; py++) {
				var y = py - startY;
				for(var px = startX; px <= endX; px++) {
					var reverseStyle = {top : null, right : null, bottom :null, left : null};
					var currCell = this._tblData[py][px];
					var x = px - startX;
					var ex = x + currCell[0] -1;
					var ey = y + currCell[1] -1;
					if (x == 0)
						reverseStyle.left = selectBorderStyle;
					if (ex == (xsize -1))
						reverseStyle.right = selectBorderStyle;
					else if (ex > (xsize -1)) {
						reverseStyle.right = selectBorderStyle;
						reverseStyle.top = selectBorderStyle;
						reverseStyle.bottom = selectBorderStyle;
					}
					if (y == 0)
						reverseStyle.top = selectBorderStyle;
					if (ey == (ysize -1))
						reverseStyle.bottom = selectBorderStyle;
					else if (ey > (ysize -1)) {
						reverseStyle.bottom = selectBorderStyle;
						reverseStyle.left = selectBorderStyle;
						reverseStyle.right = selectBorderStyle;
					}
					if (reverseStyle.top || reverseStyle.right || reverseStyle.bottom || reverseStyle.left) {
						var currCellObj = this._tblData[py][px][2];
						var addedFound = false;
						for(var i = 0 ; i < this._lastSelectedCellOrgStyle.length; i++) {
							if (this._lastSelectedCellOrgStyle[i][0] == currCellObj) {
								addedFound = true;
								break;
							}
						}
						if (!addedFound) {
							this._lastSelectedCellOrgStyle.push([currCellObj , this.getCellStyle(currCellObj)]);
							this.reverseCellColor(currCellObj, reverseStyle);
						}
					}
					if (currCell[0] > 0)
						px += (currCell[0] -1);
				}
			}
		}
	},
	getCellStyle : function(currCellObj) {
		var borderStyle = currCellObj.style.borderStyle || 'solid';
		var borderColor = currCellObj.style.borderColor ;
		var borderWidth = currCellObj.style.borderWidth || '1px';
		var borderLeft = (currCellObj.style.borderLeftColor || borderColor) + ' '+ (currCellObj.style.borderLeftWidth || borderWidth) +' '+(currCellObj.style.borderLeftStyle || borderStyle)
		var borderRight = (currCellObj.style.borderRightColor || borderColor) + ' '+ (currCellObj.style.borderRightWidth || borderWidth) +' '+(currCellObj.style.borderRightStyle || borderStyle)
		var borderBottom = (currCellObj.style.borderBottomColor || borderColor) + ' '+ (currCellObj.style.borderBottomWidth || borderWidth) +' '+(currCellObj.style.borderBottomStyle || borderStyle)
		var borderTop = (currCellObj.style.borderTopColor || borderColor) + ' '+ (currCellObj.style.borderTopWidth || borderWidth) +' '+(currCellObj.style.borderTopStyle || borderStyle)
		return {left : borderLeft, right : borderRight, bottom :borderBottom, top :borderTop};
	},
	setTableRange : function(posStart, posEnd) {
		var startX = Math.min(posStart[1], posEnd[1],posStart[3], posEnd[3]);
		var startY = Math.min(posStart[0], posEnd[0],posStart[2], posEnd[2]);
		var endX = Math.max(posStart[1], posEnd[1],posStart[3], posEnd[3]);
		var endY = Math.max(posStart[0], posEnd[0],posStart[2], posEnd[2]);
		var cellData = this._tblData[endY][endX];
		this._lastSelectedPos = [startX, startY, endX, endY, (endX - startX+1) * (endY - startY+1)];
		this.restoreCellColor();
		var tmpSelectedCell = [];
		for(var y = startY; y <= endY; y++) 
			for(var x = startX; x <= endX; x++) 
				tmpSelectedCell.push(this._tblData[y][x][2]);
		if (tmpSelectedCell.length > 0) {
			for(var i = 0 ; i < tmpSelectedCell.length; i++) {
				var foundAdded = false;
				for(var j = 0 ; j < this._lastSelectedCell.length; j++) {
					if (this._lastSelectedCell[j] == tmpSelectedCell[i]) {
						foundAdded = true;
						break;
					}
				}
				if (!foundAdded) 
					this._lastSelectedCell.push(tmpSelectedCell[i]);
			}
		}
		this.selectCellColor();
		return (this._lastSelectedCell.length > 0) ? true : false;
	},
	checkRemoveTable : function(obj) {
		var checkObj = [];
		switch(obj.tagName.toLowerCase()) {
			case 'td' :
				if (obj.parentNode.tagName == 'TR')
					checkObj.push(obj.parentNode); 
				if (obj.parentNode.tagName == 'TBODY')
					checkObj.push(obj.parentNode.parentNode);
				if (obj.parentNode.tagName == 'TABLE')
					checkObj.push(obj.parentNode.parentNode.parentNode);
				obj.parentNode.removeChild(obj);
				break;
			case 'tr' :
				if (obj.parentNode.tagName == 'TBODY')
					checkObj.push(obj.parentNode);
				if (obj.parentNode.tagName == 'TABLE')
					checkObj.push(obj.parentNode.parentNode);
				obj.parentNode.removeChild(obj);
				break;
			case 'tbody' :
				if (obj.parentNode.tagName == 'TABLE')
					checkObj.push(obj.parentNode);
				obj.parentNode.removeChild(obj);
				break;
			case 'table' :
				obj.parentNode.removeChild(obj);
				break;
		}
		for(var i = 0 ; i < checkObj.length; i++) {
			var currObj = checkObj[i];
			if (currObj.childNodes.length == 0) 
				currObj.parentNode.removeChild(currObj);
		}
	},
	sendValue : function(parent, obj) {
		var cmd = obj.options.itemOptions;
		try {
		switch(cmd) {
			case 'delete' :
				if (this.lastObj != null && this.lastObj.tagName != 'BODY' && this.lastObj.parentNode != null) {
					switch(this.lastObj.tagName.toLowerCase()) {
						case 'td' :
							if (this._lastSelectedPos[4] > 1) {
								var startX = this._lastSelectedPos[0];
								var startY = this._lastSelectedPos[1];
								var endX = this._lastSelectedPos[2];
								var endY = this._lastSelectedPos[3];
								for(var y = startY; y <= endY ; y++) {
									for(var x = startX; x <= endX ; x++) {
										if (this._tblData[y][x] != null && this._tblData[y][x][2] != null)
											this._tblData[y][x][2].innerHTML = '&nbsp;';
									}
								}
							} else {
								this.lastObj.innerHTML = '&nbsp;';
							}
							break;
						case 'tbody' :
						case 'table' :
						default :
							this.lastObj.parentNode.removeChild(this.lastObj);
							break;
					}
				}
				break;
			case 'coladd' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('tr');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var tmpObj = this.cloneElement(tblObj, ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft'], ['bgColor']);
					for(var i = 0; i < this._tblData[y].length; i++) {
						var currObj = this._tblData[y][i];
						if (currObj == null)
							continue;
						if (currObj[2].parentNode == tblObj) {
							tmpObj.appendChild(this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['colSpan','bgColor'], '&nbsp;'));
							i += (currObj[1] -1);
						} else {
							currObj[2].setAttribute('rowSpan',currObj[1] + 1);
						}
					}
					tblObj.parentNode.insertBefore(tmpObj,tblObj);
				}
				break;
			case 'colremove' :
				this.restoreCellColor();
				var outObj = this.getParentElement('tbody');
				var tblObj = this.getParentElement('tr');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var nextObj = null;
					for(var i = 0; i < outObj.childNodes.length; i++) {
						if (	outObj.childNodes[i] == tblObj) {
							if (outObj.childNodes[i +1] != null)
								nextObj = outObj.childNodes[i +1];
							break;	
						}
					}
					var y =pos[0];
					var x =pos[1];
					for(var i = 0; i < this._tblData[y].length; i++) {
						var currObj = this._tblData[y][i];
						if (currObj == null)
							continue;
						if (currObj[2].parentNode == tblObj) {
							if (currObj[1] > 1 && nextObj != null) {
								var nextRow = this._tblData[y+1];
								var findObj = null;
								for(var j = i +1; j < nextRow.length; j++) {
									if (nextObj == nextRow[j][2].parentNode) {
										findObj = nextRow[j][2];
										break;
									}
								}
								var cloneObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['colSpan','bgColor'], '&nbsp;');
								cloneObj.setAttribute('rowSpan', currObj[1] -1);
								if (findObj != null) 
									findObj.parentNode.insertBefore(cloneObj,findObj);
								else 
									nextObj.appendChild(cloneObj);
							}
							tblObj.removeChild(currObj[2]);
							i += (currObj[1] -1);
						}else 
							currObj[2].setAttribute('rowSpan',currObj[1] -1);
					}
					tblObj.parentNode.removeChild(tblObj);
				}
				break;
			case 'colmerge' :
			case 'colmergeall' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var colSpan = 0;
					for(var i = x; i < this._tblData[x].length; i++) {
						var currObj = this._tblData[y][i];
						if (currObj == null)
							continue;
						colSpan += currObj[0];
						if (currObj[0] > 1)
							i += (currObj[0] - 1);
						if (tblObj != currObj[2]) {
							if (currObj[2].parentNode == tblObj.parentNode) {
								for(var j = 0; j < currObj[2].childNodes.length; j++) 
									tblObj.appendChild(currObj[2].childNodes[j]);
								currObj[2].parentNode.removeChild(currObj[2]);
								if (cmd == 'colmerge')
									break;
							} else 
								break;
						}
					}
					tblObj.setAttribute('colSpan',colSpan);
				}
				break;
			case 'colsplit' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var currObj = this._tblData[y][x];
					if (currObj[0] > 1) {
						currObj[2].setAttribute('colSpan',1);
						var tmpObj = null;
						for(var i = 1; i < currObj[0]; i++) {
							tmpObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['bgColor', 'rowSpan'],'&nbsp;');
							currObj[2].parentNode.insertBefore(tmpObj, currObj[2]);
						}
						if (tmpObj != null) {
							tmpObj.innerHTML = '';
							var childNodes = this.getObject2Array(currObj[2]);
							for(var i = 0 ; i < childNodes.length; i++) 
								tmpObj.appendChild(childNodes[i]);		
						}
					} else {
						for(var i = 0; i < this._tblData.length; i++) {
							if (i == y) {
								tmpObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['bgColor', 'rowSpan'],'&nbsp;');
								currObj[2].parentNode.insertBefore(tmpObj, currObj[2]);
								var childNodes = this.getObject2Array(currObj[2]);
								for(var x = 0 ; x < childNodes.length; x++) 
									tmpObj.appendChild(childNodes[x]);		
								if (currObj[1] > 1)
									i += (currObj[1] -1);
							} else {
								tmpObj = this._tblData[i][x];
								if (tmpObj != null) {
									tmpObj[2].setAttribute('colSpan', tmpObj[0]+1);
									if (tmpObj[1] > 1)
										i += (tmpObj[1] -1);
								}
							}
						}
					}
				}
				break;
			case 'colwidth' :
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var baseWidth = Math.round(100 / this._tblData[0].length);
					for(var i = 0; i < this._tblData.length; i++) 
						for(var j = 0; j < this._tblData[i].length; j++) 
							if (this._tblData[i][j] != null)
								cafen.setStyle(this._tblData[i][j][2], {width : (this._tblData[i][j][0] * baseWidth) +'%'});

				}
				break;
			case 'rowadd' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					for(var i = 0; i < this._tblData.length; i++) {
						var currObj = this._tblData[i][x];
						if (currObj == null)
							continue;
						var tmpObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft'], ['bgColor', 'rowSpan'],'&nbsp;');
						currObj[2].parentNode.insertBefore(tmpObj, currObj[2]);
						if (currObj[1] > 1)
							i += (currObj[1] -1);
					}
				}
				break;
			case 'rowmerge' :
			case 'rowmergeall' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var rowSpan = 0;
					for(var i = y; i < this._tblData.length; i++) {
						var currObj = this._tblData[i][x];
						if (currObj == null)
							continue;
						rowSpan += currObj[1];
						if (tblObj != currObj[2]) {
							for(var j = 0; j < currObj[2].childNodes.length; j++) 
								tblObj.appendChild(currObj[2].childNodes[j]);
							if (currObj[1] > 1)
								i += (currObj[1] -1);
							currObj[2].parentNode.removeChild(currObj[2]);
							if (cmd == 'rowmerge' || currObj[0] > 1)
								break;
						} else 
							currObj[1] = 0;
					}
					tblObj.setAttribute('rowSpan',rowSpan);
				}
				break;
			case 'rowremove' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					for(var i = 0; i < this._tblData.length; i++) {
						var currObj = this._tblData[i][x];
						if (currObj == null)
							continue;
						if (currObj[1] > 1) {
							if (currObj[0] > 1) {
								var tmpObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft'], ['bgColor', 'rowSpan', 'colSpan'],'&nbsp;');
								tmpObj.setAttribute('colSpan', currObj[0] -1);
								var addCell = this._tblData[i][currObj[0] + x][2];
								addCell.parentNode.insertBefore(tmpObj,addCell);
							}
							i += (currObj[1] -1);
						}
						currObj[2].parentNode.removeChild(currObj[2]);
					}
				}
				break;
			case 'rowsplit' :
				this.restoreCellColor();
				var outObj = this.getParentElement('tbody');
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var currObj = this._tblData[y][x];
					if (currObj[1] > 1) {
						currObj[2].setAttribute('rowSpan',1);
						for(var i = 1; i < currObj[1]; i++) {
							var tmpObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['bgColor', 'colSpan'],'&nbsp;');
							var nextObj = outObj.childNodes[y+i];
							if (nextObj != null) {
								var checkObj = this._tblData[y+i][x + 1];
								if (checkObj != null && checkObj[2].parentNode == nextObj)
									nextObj.insertBefore(tmpObj, checkObj[2]);
								else if (this._tblData[y+i] != null){
									var findObj = null;
									for(var j = x +2 ; j < this._tblData[y+i].length; j++) {
										var checkObj = this._tblData[y+i][j];
										if (checkObj != null && checkObj[2].parentNode == nextObj) {
											findObj = checkObj[2];
											break;
										}
									}
									if (findObj != null) 
										nextObj.insertBefore(tmpObj, findObj);
									else
										nextObj.appendChild(tmpObj);
								}
							}
						}	
					} else {
						for(var i = 0; i < 	this._tblData[y].length; i++) {
							if (i == x) {
								var tmpObj = this.cloneElement(currObj[2].parentNode, [], [],null);
								var cellObj = this.cloneElement(currObj[2], ['backgroundColor','color','borderTop','borderRight','borderBottom','borderLeft','textAlign'], ['bgColor', 'colSpan'],'&nbsp;');
								tmpObj.appendChild(cellObj);
								currObj[2].parentNode.parentNode.insertBefore(tmpObj, currObj[2].parentNode);
								currObj[2].parentNode.parentNode.insertBefore(currObj[2].parentNode, tmpObj);
							} else {
								var tmpObj = this._tblData[y][i];
								if (tmpObj != null) {
									tmpObj[2].setAttribute('rowSpan', tmpObj[1]+1);
									if (tmpObj[0] > 1)
										i += (tmpObj[0] -1);
								}
							}
						} 
					}
				}
				break;
			case 'rowwidth' :
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var baseHeight = Math.round(100 / this._tblData.length);
					for(var i = 0; i < this._tblData.length; i++) 
						for(var j = 0; j < this._tblData[i].length; j++) 
							if (this._tblData[i][j] != null)
								cafen.setStyle(this._tblData[i][j][2], {height : (this._tblData[i][j][1] * baseHeight) +'%'});

				}
				break;
			case 'cellmerge' :
				if (this._lastSelectedCell.length > 1) {
					var tarObj = this._lastSelectedCell[0];
					for(var i = 1 ; i < this._lastSelectedCell.length; i++) {
						var currObj = this._lastSelectedCell[i];
						var childObj = this.getObject2Array(currObj);
						for(var j = 0 ; j < childObj.length; j++) 
							tarObj.appendChild(childObj[j]);
						currObj.parentNode.removeChild(currObj);
					}
					var colSpan = 0 ,rowSpan = 0;
					colSpan = this._lastSelectedPos[2] - this._lastSelectedPos[0] +1;
					rowSpan = this._lastSelectedPos[3] - this._lastSelectedPos[1] +1;
					cafen.setAttribute(tarObj, {colSpan : colSpan, rowSpan : rowSpan});
				}
				break;
			case 'cellsplit' :
				this.restoreCellColor();
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				if (pos[0] > -1) {
					var y =pos[0];
					var x =pos[1];
					var currObj = this._tblData[y][x];
					if (currObj	[0] > 1) {
						this.sendValue(null, {options : {itemOptions : 'colsplit'}});
						if (currObj[1] > 1) {
							for(var y = this._lastSelectedPos[1]; y <=  this._lastSelectedPos[1] + currObj[1]; y++) {
								this.lastObj = this._tblData[y][x][2];
								this.sendValue(null, {options : {itemOptions : 'rowsplit'}});
							}							
						}
					} else if (currObj	[1] > 1) 
						this.sendValue(null, {options : {itemOptions : 'rowsplit'}});
				}
				break;
			case 'rowsum' :
			case 'colsum' :
			case 'cellsum' :
				var tblObj = this.getParentElement('table');
				if (tblObj != null) {
					var cellObj = this.getParentElement('td');
					var cellPos = this.getTableNo(cellObj);
					var startX = 0;
					var startY = 0;
					var endX = (this._tblData[0].length - 2);
					var endY = (this._tblData.length - 2);
					var rangestartX = startX;
					var rangestartY = startY;
					var rangeendX = endX;
					var rangeendY = endY;
					var rangeUse = false;
					if (this._lastSelectedPos[4] > 1) {
						rangeUse = true;
						rangestartX = this._lastSelectedPos[0];
						rangestartY = this._lastSelectedPos[1];
						rangeendX = this._lastSelectedPos[2];
						rangeendY = this._lastSelectedPos[3];
					}
					switch(cmd) {
						case 'rowsum' :
							if (rangeUse) {
								startX = rangestartX;
								startY = rangestartY;
								endX = rangeendX;
								endY = rangeendY;
							} else {
								startX = cellPos[1];
								startY = 0;
								endX = cellPos[1];
								endY = (this._tblData.length - 2);
							}
							break;
						case 'colsum' :
							if (rangeUse) {
								startX = rangestartX;
								startY = rangestartY;
								endX = rangeendX;
								endY = rangeendY;
							} else {
								startX = 0;
								startY = cellPos[0];
								endX = (this._tblData[startY].length - 2);
								endY = cellPos[0];
							}
							break;
						case 'cellsum' :
							if (rangeUse) {
								startX = rangestartX;
								startY = rangestartY;
								endX = rangeendX;
								endY = rangeendY;
							}						
							break;
					}
					var totalSum = 0;
					if (cmd != 'rowsum' && (endX - startX) > 0) {
						totalSum = 0;
						for(var y = startY; y <= endY; y++) {
							var colSum = 0;
							for(var x = startX; x <= endX; x++) {
								if (this._tblData[y][x] != null && this._tblData[y][x][2] != null) {
									var currCell = 	this._tblData[y][x][2];
									var nodeValue = parseFloat(((currCell.childNodes.length > 0 ) ? currCell.childNodes[0].nodeValue : currCell.innerText).replace( " ", "").replace( ",", ""));
									colSum += isNaN(nodeValue) ? 0 : nodeValue;
									if (this._tblData[y][x][0] > 1)
										x += (this._tblData[y][x][0] -1);
								}
							}
							if (this._tblData[y][endX+1] != null && this._tblData[y][endX+1][2] != null) {
								var tarObj = this._tblData[y][endX+1][2];
								if (colSum < 10 && colSum > -10)
									tarObj.innerHTML = colSum.toFixed(3);
								else
									tarObj.innerHTML = colSum.toFixed(1);
							}
							totalSum += colSum;
						}
					}
					if (cmd != 'colsum' && (endY - startY) > 0) {
						totalSum = 0;
						for(var x = startX; x <= endX; x++) {
							var rowSum = 0;
							for(var y = startY; y <= endY; y++) {
								if (this._tblData[y][x] != null && this._tblData[y][x][2] != null) {
									var currCell = 	this._tblData[y][x][2];
									var nodeValue = parseFloat(((currCell.childNodes.length > 0 ) ? currCell.childNodes[0].nodeValue : currCell.innerText).replace( " ", "").replace( ",", ""));
									rowSum += isNaN(nodeValue) ? 0 : nodeValue;
									if (this._tblData[y][x][1] > 1)
										y += (this._tblData[y][x][1] -1);
								}
							}
							if (this._tblData[endY+1][x] != null && this._tblData[endY+1][x][2] != null) {
								var tarObj = this._tblData[endY+1][x][2];
								if (rowSum < 10 && rowSum > -10)
									tarObj.innerHTML = rowSum.toFixed(3);
								else
									tarObj.innerHTML = rowSum.toFixed(1);
							}
							totalSum += rowSum;
						}
					}
					if (cmd == 'cellsum' && (endY - startY) > 0 && (endX - startX) > 0) {
						if (this._tblData[endY+1][endX+1] != null && this._tblData[endY+1][endX+1][2] != null) {
							var tarObj = this._tblData[endY+1][endX+1][2];
							if (totalSum < 10 && totalSum > -10)
								tarObj.innerHTML = totalSum.toFixed(3);
							else
								tarObj.innerHTML = totalSum.toFixed(1);
						}
					}
				}
				break;
			case 'tablethema' :
			case 'tablethema01' :
			case 'tablethema02' :
			case 'tablethema03' :
			case 'tablethema04' :
			case 'tablethema05' :
			case 'tablethema06' :
			case 'tablethema07' :
				var tblObj = this.getParentElement('table');
				var tableStyle = null;
				if (this.tableStyle[cmd] != null) {
					tableStyle = this.tableStyle[cmd];
					if (obj != null) {
						this._lastshowObj.changeIcon('tablethema', obj.icon);
						this._lastshowObj.options._lastTableThema = tableStyle;
					}
				} else 
					tableStyle = (this._lastshowObj.options._lastTableThema != null ) ? this._lastshowObj.options._lastTableThema : {border : '#000000', titleBG : '#000000', titleFnt : '#ffffff', evenBG : '#d8d8d8',oddBG : '#ffffff', cellFnt : '#000000'};
				if (tblObj != null) {
					this.table2Arrange();
					var startX = 0;
					var startY = 0;
					var endX = (this._tblData[0].length - 1);
					var endY = (this._tblData.length - 1);
					if (this._lastSelectedPos[4]> 1) {
						startX = this._lastSelectedPos[0];
						startY = this._lastSelectedPos[1];
						endX = this._lastSelectedPos[2];
						endY = this._lastSelectedPos[3];
					}
					cafen.setStyle(tblObj, {backgroundColor : tableStyle.border, borderCollapse:'collapse'});
					cafen.setAttribute(tblObj, {cellSpacing : '0', cellPadding : '3', borderColor : tableStyle.border});
					var cellStyle =  {
						title : {backgroundColor: tableStyle.titleBG, color:tableStyle.titleFnt, textAlign:'center', fontWeight:'bold', border : '1px solid '+tableStyle.border},
						even : {backgroundColor: tableStyle.evenBG, color:tableStyle.cellFnt, textAlign:'right', border : '1px solid '+tableStyle.border},
						odd : {backgroundColor: tableStyle.oddBG, color:tableStyle.cellFnt, textAlign:'right', border : '1px solid '+tableStyle.border}
					};
					var ySeqn = 0;
					for(var y = startY ; y <= endY; y++) {
						for(var x = startX ; x <= endX; x++) {
							if (this._tblData[y][x] != null && this._tblData[y][x][2] != null) {
								if ((x == startX && endX != startX)|| y == startY) 
									cafen.setStyle(this._tblData[y][x][2], cellStyle.title);
								else if (ySeqn % 2 == 0) 
									cafen.setStyle(this._tblData[y][x][2], cellStyle.even);
								else
									cafen.setStyle(this._tblData[y][x][2], cellStyle.odd);
							}
						}
						ySeqn ++;
					}
				}
				this._lastSelectedCell = [];
				break;
			case 'lineheight' :
			case 'lineheight100' :
			case 'lineheight120' :
			case 'lineheight140' :
			case 'lineheight160' :
			case 'lineheight180' :
			case 'lineheight200' :
				var lineheight = null;
				switch(cmd) {
					case 'lineheight100' :
						lineheight = '100%';
						break;
					case 'lineheight140' :
						lineheight = '140%';
						break;
					case 'lineheight160' :
						lineheight = '160%';
						break;
					case 'lineheight180' :
						lineheight = '180%';
						break;
					case 'lineheight200' :
						lineheight = '200%';
						break;
					case 'lineheight120' :
						lineheight = '120%';
						break;
					default :
						break;
				}		
				if (lineheight != null && obj != null) {
					this._lastshowObj.changeIcon('lineheight', obj.icon);
					this._lastshowObj.options._lastLineHeight = lineheight;
				} else 
					lineheight = (this._lastshowObj.options._lastLineHeight != null) ? this._lastshowObj.options._lastLineHeight : '120%';
				this._editorObject.execCommand('lineheight', true, lineheight);
				break;
			case 'fontlarge' :
			case 'fontsmall' :
				this._editorObject.execCommand(cmd, true, null);
				break;
			case 'translate' :
			case 'trans_ko' :
			case 'trans_en' :
			case 'trans_jp' :
			case 'trans_cn' :
				if (cafenGlobalConf.useTranlate) {
					var tblObj = this.getParentElement('font,td,p,div,body');
					if (tblObj != null) {
						this._lastTransObj = tblObj;
						var trans_lang = null;
						switch(cmd) {
							case 'trans_ko' :
								trans_lang = 'ko';
								break;
							case 'trans_en' :
								trans_lang = 'en';
								break;
							case 'trans_jp' :
								trans_lang = 'ja';
								break;
							case 'trans_cn' :
								trans_lang = 'zh-CN';
								break;
						}
						if (trans_lang != null) {
							if (obj != null) {
								this._lastshowObj.changeIcon('translate', obj.icon);
								this._lastshowObj.options._lastTranslate = trans_lang;
							}
						} else {
							trans_lang = (this._lastshowObj.options._lastTranslate != null) ? this._lastshowObj.options._lastTranslate : 'en';
						}
						var str = this._editorObject.getSelectedHTML();
						if (str == null || str == '') {
							str = tblObj.innerHTML;
						} else {
							this._lastTransObj = null;
						}
						if (str != null && str.split(' ').join('') != '') {
							if (str.length > 300) { 
								this._editorObject.showMsg(cafenMsg.get('ed_0132', str.length));
								return ;
							} else {
								cafen.smallSWFAjax.getTranslate(str, trans_lang, this.translateLanguage.bind(this));
							}
						}
					}
				} else {
					this._editorObject.showMsg(cafenMsg.get('ed_0036'));
					return ;
				}
				break;
			case 'linestyle' :
			case 'line01' :
			case 'line02' :
			case 'line03' :
			case 'line04' :
			case 'line05' :
			case 'line06' :
			case 'line07' :
			case 'line08' :
			case 'line09' :
			case 'line10' :
			case 'line11' :
			case 'line12' :
			case 'line13' :
				var tblObj = this.getParentElement('table');
				var lineColor = tblObj.getAttribute('bgColor') || tblObj.getAttribute('borderColor') || tblObj.style.backgroundColor || '#000000' ;
				if (cmd == 'linestyle') 
					cmd = (this._lastshowObj.options._lastLineStyle != null) ? this._lastshowObj.options._lastLineStyle : 'line06';
				else if (obj != null) {
					this._lastshowObj.changeIcon('linestyle', obj.icon);
					this._lastshowObj.options._lastLineStyle = cmd;
				}
				var lineStyle = this.lineStyle[cmd];
				cafen.setAttribute(tblObj, {border:0,cellSpacing : 0, cellPadding : 0});
				cafen.setStyle(tblObj, {border:'0px none', borderCollapse:'collapse'});
				if (lineStyle != null) {
					this.table2Arrange();
					var startX = 0;
					var startY = 0;
					var endX = (this._tblData[0].length - 1);
					var endY = (this._tblData.length - 1);
					if (this._lastSelectedPos[4]> 1) {
						startX = this._lastSelectedPos[0];
						startY = this._lastSelectedPos[1];
						endX = this._lastSelectedPos[2];
						endY = this._lastSelectedPos[3];
					}
					for(var y = startY ; y <= endY; y++) {
						for(var x = startX ; x <= endX; x++) {
							var currCell = this._tblData[y][x][2];
							if (currCell == null)
								continue;
							var borderStyle = {top : null, right : null, bottom : null, left : null};
							if (y == startY && y == endY) {
								if (x == startX && x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[4],lineStyle[10],lineStyle[2]);
								else if (x == startX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[3],lineStyle[10],lineStyle[2]);
								else if (x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[1],lineStyle[4],lineStyle[11],lineStyle[3]);
								else
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[3],lineStyle[11],lineStyle[3]);
							} else if (y == startY) {
								if (x == startX && x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[4],lineStyle[5],lineStyle[2]);
								else if (x == startX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[3],lineStyle[5],lineStyle[2]);
								else if (x == endX)
									borderStyle = this.getBorderStyle(lineColor, lineStyle[1],lineStyle[4],lineStyle[6],lineStyle[3]);
								else 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[0],lineStyle[3],lineStyle[3],lineStyle[3]);
							} else if (y == endY) {
								if (x == startX && x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[5],lineStyle[9],lineStyle[10],lineStyle[7]);
								else if (x == startX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[5],lineStyle[8],lineStyle[10],lineStyle[7]);
								else if (x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[6],lineStyle[9],lineStyle[11],lineStyle[8]);
								else 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[5],lineStyle[8],lineStyle[10],lineStyle[8]);
							} else {
								if (x == startX && x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[6],lineStyle[3],lineStyle[5],lineStyle[8]);
								else if (x == startX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[5],lineStyle[8],lineStyle[5],lineStyle[7]);
								else if (x == endX) 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[6],lineStyle[9],lineStyle[6],lineStyle[8]);
								else 
									borderStyle = this.getBorderStyle(lineColor, lineStyle[6],lineStyle[3],lineStyle[5],lineStyle[8]);
							}
							if (borderStyle != null) {
								if (borderStyle.top != null)	
									currCell.style.borderTop = borderStyle.top;
								if (borderStyle.right != null)	
									currCell.style.borderRight = borderStyle.right;
								if (borderStyle.bottom != null)	
									currCell.style.borderBottom = borderStyle.bottom;
								if (borderStyle.left != null)	
									currCell.style.borderLeft = borderStyle.left;
							}
						}
					}	
				}	
				tblObj.parentNode.insertBefore(tblObj,tblObj);
				break;
			case 'cellalign' :
			case 'celllefttop' :
			case 'cellcentertop' :
			case 'cellrighttop' :
			case 'cellleftmiddle' :
			case 'cellcentermidle' :
			case 'cellrightmiddle' :
			case 'cellleftbottom' :
			case 'cellcenterbottom' :
			case 'cellrightbottom' :
				var tblObj = this.getParentElement('td');
				var pos = this.getTableNo(tblObj);
				var startX = pos[1];
				var startY = pos[0];
				var endX = pos[1];
				var endY = pos[0];
				if (this._lastSelectedPos[4]> 1) {
					startX = this._lastSelectedPos[0];
					startY = this._lastSelectedPos[1];
					endX = this._lastSelectedPos[2];
					endY = this._lastSelectedPos[3];
				}
				if (startX > -1 && startY > -1) {
					var alignStyle = null;
					switch(cmd) {
						case 'cellalign' :
							break;
						case 'celllefttop' :
							alignStyle = {verticalAlign: 'top', textAlign : 'left'};
							break;
						case 'cellcentertop' :
							alignStyle = {verticalAlign: 'top', textAlign : 'center'};
							break;
						case 'cellrighttop' :
							alignStyle = {verticalAlign: 'top', textAlign : 'right'};
							break;
						case 'cellleftmiddle' :
							alignStyle = {verticalAlign: 'middle', textAlign : 'left'};
							break;
						case 'cellcentermidle' :
							alignStyle = {verticalAlign: 'middle', textAlign : 'center'};
							break;
						case 'cellrightmiddle' :
							alignStyle = {verticalAlign: 'middle', textAlign : 'right'};
							break;
						case 'cellleftbottom' :
							alignStyle = {verticalAlign: 'bottom', textAlign : 'left'};
							break;
						case 'cellcenterbottom' :
							alignStyle = {verticalAlign: 'bottom', textAlign : 'center'};
							break;
						case 'cellrightbottom' :
							alignStyle = {verticalAlign: 'bottom', textAlign : 'right'};
							break;
					}
					if (alignStyle == null) 
						alignStyle = (this._lastshowObj.options._lastCellAlignStyle != null) ? this._lastshowObj.options._lastCellAlignStyle : {verticalAlign: 'middle', textAlign : 'left'};
					else if (obj != null) {
						this._lastshowObj.changeIcon('cellalign', obj.icon);
						this._lastshowObj.options._lastCellAlignStyle = alignStyle;
					}
					for(var y = startY ; y <= endY; y++) {
						for(var x = startX ; x <= endX; x++) {
							var currCell = this._tblData[y][x][2];
							if (currCell == null)
								continue;
							cafen.setStyle(currCell, alignStyle);
						}
					}
				}
				break;
			case 'row' :
			case 'col' :
			case 'align' :
			case 'justify' :
			case 'left' :
			case 'right' :
			case 'center' :
				if (cmd != 'align') {
					if (obj != null) {
						this._lastshowObj.changeIcon('align', obj.icon);
						this._lastshowObj.options._lastAlignStyle = cmd;
					}
				} else  
					cmd = (this._lastshowObj.options._lastAlignStyle != null) ? this._lastshowObj.options._lastAlignStyle : 'left';
				if (this.lastObj != null && this.lastObj.style != null) {
					switch(this.lastObj.tagName) {
						case 'TABLE' :
						case 'IMG' :
							this.lastObj.setAttribute('align', cmd);	
							break;
						default :
							var tblObj = this.getParentElement('td,p,div,body');
							if (tblObj != null) 
								tblObj.style.textAlign = cmd;
							else {
								switch(cmd) {
									case 'center' :
										cmd = 'justifycenter';
										break;	
									case 'right' :
										cmd = 'justifyright';
										break;
									case 'justify' :
										cmd = 'justifyfull';
										break;	
									case 'left' :
									default :
										cmd = 'justifyleft';
										break;	
								}
								this._editorObject.execCommand(cmd, true, null);
							}
							break;
					}
				}
				break;
			case 'createlink' :
				this.close();
				this._editorObject.actionCommand('createlink');
				return ;
				break;
			case 'copypaste' :
				return ;
				break;
			case 'pastestyle' :
			case 'paste' :
				var tblObj = this.getParentElement('font,td,p,div,body,table');
				if (tblObj != null && this._lastCopyObject != null) {
					switch(tblObj.tagName.toLowerCase()) {
						case 'table' :
						case 'tbody' :
						case 'tr' :
							break;
						default :
							var selectedObj = this._editorObject.getSelectedElement();
							if (this._lastCopyObject.w == 0 && this._lastCopyObject.h == 0) {
								for(var i = 0 ; i < this._lastCopyObject.objs.length; i++) {
									var currObj = this._lastCopyObject.objs[i];
									if (typeof currObj == 'object') {
										if (cmd == 'pastestyle' ) {
											if (selectedObj != null && selectedObj.parentNode != null) 
												cafen.setStyle(selectedObj.parentNode, currObj.style);
											else
												cafen.setStyle(tblObj, currObj.style);
										} else {
											if (currObj.selectedTag != null && currObj.selectedTag != '') {
												if (selectedObj != null) {
													this._editorObject.execCommand('insertHTML', null, currObj.selectedTag);
												} else {
													var tarObj = this.createElement((currObj.tagName == 'BODY') ?  'P' : currObj.tagName);
													tarObj.innerHTML = currObj.selectedTag;						
													tblObj.appendChild(tarObj);
												}
											} else {
												var tarObj = this.createElement((currObj.tagName == 'BODY') ?  'P' : currObj.tagName);
												cafen.setStyle(tarObj, currObj.style);
												cafen.setAttribute(tarObj, currObj.attribute);
												if (selectedObj != null) {
													this._editorObject.execCommand('insertHTML', null, cafen.outerHTML(tarObj));
												}else
													tblObj.appendChild(tarObj);
											}
										}
									} else {
										this._editorObject.execCommand('insertHTML', null, currObj);
									}
								}
							} else {
								var tarObj = null;
								switch(tblObj.tagName.toLowerCase()) {
									case 'td' :
										var pos = this.getTableNo(tblObj);
										var startX = pos[1];
										var startY = pos[0];
										var endX = startX + this._lastCopyObject.w;
										var endY = startY + this._lastCopyObject.h;
										var seqn = 0;
										for(var y = startY; y < endY; y++) {
											for(var x = startX; x < endX; x++) {
												if (this._tblData[y][x] != null && this._tblData[y][x][2] != null) {
													var currObj = this._lastCopyObject.objs[seqn];
													var currCell = this._tblData[y][x][2];
													cafen.setStyle(currCell, currObj.style);
													if (cmd != 'pastestyle') 
														cafen.setAttribute(currCell, currObj.attribute);
												}
												seqn ++;
											}
										}
										break;
									case 'tbody':
									case 'tr':
									case 'table':
										break;
									default :
										var tarObj = this.createElement('table');
										cafen.setStyle(tarObj, {borderCollapse:'collapse'});
										cafen.setAttribute(tarObj, {cellSpacing : '0', cellPadding : '3'});
										var tarBodyObj = this.createElement('tbody');
										tarObj.appendChild(tarBodyObj);
										var seqn = 0;
										for(var y = 0; y < this._lastCopyObject.h; y++) {
											var tarTrObj = this.createElement('tr');
											tarBodyObj.appendChild(tarTrObj);
											for(var x = 0; x < this._lastCopyObject.w; x++) {
												var currObj = this._lastCopyObject.objs[seqn];
												var tdObj = this.createElement('td');
												cafen.setStyle(tdObj, currObj.style);
												cafen.setAttribute(tdObj, currObj.attribute);
												if (cmd == 'pastestyle') 
													tdObj.innerHTML = '&nbsp;';
													tarTrObj.appendChild(tdObj);
												seqn ++;
											}
										}
										if (selectedObj != null) {
											try {
												this._editorObject.execCommand('insertHTML', null, cafen.outerHTML(tarObj));
											} catch(ex) {

											}
										}else
											tblObj.appendChild(tarObj);
										break;									
								}
								
							}
							break;
					}
				}
				break;
			case 'cut' :
			case 'copy' :
				this._lastCopyObject = null;
				if (this._lastSelectedPos[4]> 1) {
					this._lastCopyObject = {w : this._lastSelectedPos[2] - this._lastSelectedPos[0] +1, h : this._lastSelectedPos[3] - this._lastSelectedPos[1] +1, objs : []}
					var startX = this._lastSelectedPos[0];
					var startY = this._lastSelectedPos[1];
					var endX = this._lastSelectedPos[2];
					var endY = this._lastSelectedPos[3];
					this.restoreCellColor();
					for(var y = startY ;  y <= endY; y++) {
						for(var x = startX ;  x <= endX; x++) {
							this._lastCopyObject.objs.push(this.cloneElementData(this._tblData[y][x][2]));
							if (cmd == 'cut') 
								this._tblData[y][x][2].innerHTML = '&nbsp;';
						}
					}
				} else {			
					var tblObj = this.getParentElement('td,p,blockquote,div,body,table');
					if (tblObj != null) {
						this._lastCopyObject = {w : 0, h : 0, objs : []};
						this._lastCopyObject.objs.push(this.cloneElementData(tblObj, this._editorObject.getSelectedHTML()));
						if (cmd == 'cut') {
							switch(tblObj.tagName.toLowerCase()) {
								case 'td' :
								case 'body' :
									tblObj.innerHTML = '&nbsp;';
									break;
								case 'tbody' :
									tblObj.parentNode.parentNode.removeChild(tblObj.parentNode);
									break;
								case 'tr' :
									break;
								default :
									tplObj.parentNode.removeChild(tplObj);
									break;
							}	
						}
					}
				}
				break;
			case 'divblock' :
			case 'divblock01' :
			case 'divblock02' :
			case 'divblock03' :
			case 'divblock04' :
			case 'divblock05' :
			case 'divblock06' :
			case 'divblock07' :
			case 'divblock08' :
				this.restoreCellColor();
				if (cmd != 'divblock') {
					if (obj != null) {
						this._lastshowObj.changeIcon('divblock', obj.icon);
						this._lastshowObj.options._lastBlockStyle = cmd;
					}
				} else  
					cmd = (this._lastshowObj.options._lastBlockStyle != null) ? this._lastshowObj.options._lastBlockStyle : 'divblock01';
				if (this.lastObj != null) {
					var blockColor = this.divBlockInfo[cmd];
					switch(this.lastObj.tagName) {
						case 'IMG' :
							var blockStyle = {'border' : blockColor.line+' 2px solid', margin:'2px'};
							cafen.setStyle(this.lastObj, blockStyle);
							break;
						case 'TBODY' :
						case 'TR' :
						case 'TABLE' :
						case 'TD' :
							var blockStyle = {'border' : blockColor.line+' 2px solid', backgroundColor : blockColor.bg, color : blockColor.font};
							var startX = 0;
							var startY = 0;
							var endX = 0;
							var endY = 0;
							if (this._lastSelectedPos[4] > 1) {
								startX = this._lastSelectedPos[0];
								startY = this._lastSelectedPos[1];
								endX = this._lastSelectedPos[2];
								endY = this._lastSelectedPos[3];
							} else {
								switch(this.lastObj.tagName) {
									case 'TABLE' :
									case 'TBODY' :
										startX = 0;
										startY = 0;
										endX = (this._tblData[0].length - 1);
										endY = (this._tblData.length - 1);
										break;
									case 'TR' :
										var pos = this.getTableNo(this.lastObj);
										startX = 0;
										startY = pos[0];
										endX = (this._tblData[startY].length - 1);
										endY = pos[0];
										break;
									default :
										var pos = this.getTableNo(this.lastObj);
										startX = pos[1];
										startY = pos[0];
										endX = pos[1];
										endY = pos[0];
										break;									
								}
							}
							for(var y = startY ;  y <= endY; y++) {
								for(var x = startX ;  x <= endX; x++) {
									if (this._tblData[y][x] != null && this._tblData[y][x][2] != null) 
										cafen.setStyle(this._tblData[y][x][2], blockStyle);
								}
							}
							break;
						default :
							var blockStyle = {'border' : blockColor.line+' 2px solid', backgroundColor : blockColor.bg, color : blockColor.font, padding:'4px'};
							var tblObj = this.getParentElement('td,p,div,blockquote');
							if (tblObj != null)  
								cafen.setStyle(tblObj, blockStyle);
							break;
					}
				}
				break;
			default :
				break;
		}	
		} catch(ex) {}
		this.close();
	},
	cloneElementData : function(obj, txt) {
		var tagName = obj.tagName;
		var styleData = ['fontSize', 'fontWeight','color', 'backgroundColor', 'border', 'borderStyle', 'borderColor', 'borderLeft','borderTop','borderRight','borderBottom', 'paddingLeft','paddingTop','paddingRight','paddingBottom'];
		var style = {};
		if (obj.style) {
			for (var i = 0; i < styleData.length; i++) {
				var styleKey = styleData[i];
				var styleVal = obj.style[styleKey];
				if (styleVal != null && styleVal != '')
					style[styleKey] = styleVal;
			}
		}
		var attrData = ['size', 'color', 'bgColor', 'align', 'innerHTML', 'src', 'width','height', 'border'];
		var attribute = {};
		if (obj.getAttribute) {
			for (var i = 0; i < attrData.length; i++) {
				var attrKey = attrData[i];
				var attrVal = null;
				switch(attrKey) {
					case 'innerHTML' :
						attrVal = obj.innerHTML;
						break;
					default :
						attrVal = obj.getAttribute(attrKey);
						break;
				}
				if (attrVal != null && attrVal != '')
					attribute[attrKey] = attrVal;
			}
		}
		return {tagName : tagName, style : style, attribute : attribute, selectedTag : txt};
	},
	onClose : function() {
		if (this._lastshowObj != null) 
			this._lastshowObj.hide();
	},
	getBorderStyle : function(lineColor, topStyle, rightStyle, bottomStyle, leftStyle) {
		if (topStyle != null)
			topStyle += ' ' +lineColor;
		if (rightStyle != null)
			rightStyle += ' ' +lineColor;
		if (bottomStyle != null)
			bottomStyle += ' ' +lineColor;
		if (leftStyle != null)
			leftStyle += ' ' +lineColor;
		if (topStyle == null && rightStyle == null && bottomStyle == null &&  leftStyle == null)
			return null;
		else
			return {top : topStyle, right : rightStyle, bottom : bottomStyle, left : leftStyle};
	},
	translateLanguage : function (result) {
		if (result.translation) {
			if (this._lastTransObj != null)
				this._lastTransObj.innerHTML = result.translation;
			else 
				this._editorObject.execCommand('insertHTML', false, result.translation);	
		} else if (result.error){
			this._editorObject.showMsg(result.error.message);
		}
	},
	setTagObject : function(obj, cur_x, cur_y) {
		if (!obj.tagName)
			obj = obj.parentNode;
		if (!obj.tagName)
			return false;
		this.lastObj = obj;
		if (this._editorObject.getSelectedType() == "Control") 
			this._editorObject.unsetSelectedType();
		var tagName = obj.tagName.toLowerCase() ;
		if (this._lastshowObj != null) {
			this._lastshowObj.hide();
			this._lastshowObj = null;
		}
		switch(tagName) {
			case 'table' :
			case 'tbody' :
			case 'tr' :
				tagName =  'table';
				break;
			case 'td' :
				tagName =  'td';
				break;
			case 'embed' :
			case 'object' :
			case 'img' :
				tagName =  'img';
				break;
			default :
				var tblObj = this.getParentElement('td');
				if (tblObj != null) {
					this.lastObj = tblObj;
					tagName =  'td';
				} else 
					tagName =  'div';
				break;
		}
		if (	this._loadedMenu[tagName] == null) {
			var menuData = [];
			switch(tagName) {
				case 'td' :
					menuData = ['col','row','linestyle','cellalign','tablethema','tablecmd','line','lineheight','fontlarge','fontsmall','line','translate','copypaste','divblock','delete'];
					break;
				case 'table' :
					menuData = ['cellmerge','linestyle','tablethema','align','line','divblock','delete'];
					break;
				case 'img' :
					menuData = ['left','right','center','line','copy','delete'];
					break;
				case 'div' :
					menuData = ['align','lineheight','fontlarge','fontsmall','line','translate','createlink','copypaste','divblock','delete'];
					break;
			}
			var menuObjs = [];
			for(var i = 0; i < menuData.length; i++) {
				var currMenuObjs = this.getMenuObject(menuData[i]);
				if (currMenuObjs != null)
					menuObjs.push(currMenuObjs);
			}
			var cmdBind = this.sendValue.bind(this);
			var tagnameObj = cafenMsg.getObject('ed_contexttag');
			var tagTitle = tagnameObj[tagName] || 'Others';
			this._loadedMenu[tagName] = new cafen.XMenu(menuObjs, 120, {title : tagTitle, className :this._editorObject.conf.getClassName('buttonarea'), shadow : true, event :{select : cmdBind}, style : {overflowX : '', overflowY : 'visible'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
			this.appendChild(this._loadedMenu[tagName]);
		}
		if (	this._loadedMenu[tagName] != null) {
			this._loadedMenu[tagName].show();
			this._lastshowObj = this._loadedMenu[tagName];
			if (cur_x == null || cur_y == null) {
				var pos = cafen.cumulativeOffset(obj);
				var scroll = cafen.cumulativeScrollOffset(obj);
				cur_x = pos[0] - scroll[0];
				cur_y = pos[1] - scroll[1];
			}
			this.onLoad({obj : this._editorObject._editorObject.frmSkin, x : 'left', y : 'top', plus : [cur_x, cur_y]});
		}		
	},
	lineStyle : {
		line01 : [null,null,null,null,null,null,null,null,null,null,'1px solid','1px solid'],
		line02 : ['1px solid','1px solid',null,null,null,null,null,null,null,null,null,null],
		line03 : [null,null,'1px solid',null,null,null,null,'1px solid',null,null,null,null],
		line04 : [null,null,null,null,'1px solid',null,null,null,null,'1px solid',null,null],
		line05 : ['1px none','1px none','1px none','1px none','1px none','1px none','1px none','1px none','1px none','1px none','1px none','1px none'],
		line06 : ['1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid','1px solid'],
		line07 : ['1px solid','1px solid','1px solid',null,'1px solid',null,null,'1px solid',null,'1px solid','1px solid','1px solid'],
		line08 : ['2px solid','2px solid','2px solid',null,'2px solid',null,null,'2px solid',null,'2px solid','2px solid','2px solid'],
		line09 : [null,null,null,null,null,null,null,null,null,null,'3px double','3px double'],
		line10 : [null,null,null,null,null,null,null,null,null,null,'2px solid','2px solid'],
		line11 : ['1px solid','1px solid',null,null,null,null,null,null,null,null,'1px solid','1px solid'],
		line12 : ['1px solid','1px solid',null,null,null,null,null,null,null,null,'2px solid','2px solid'],
		line13 : ['1px solid','1px solid',null,null,null,null,null,null,null,null,'3px double','3px double']
	},
	tableStyle : {
		'tablethema01' : {border : '#000000', titleBG : '#000000', titleFnt : '#ffffff', evenBG : '#d8d8d8',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema02' : {border : '#95b3d7', titleBG : '#4f81bd', titleFnt : '#ffffff', evenBG : '#dbe5f1',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema03' : {border : '#d99795', titleBG : '#c0504d', titleFnt : '#ffffff', evenBG : '#f2dddc',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema04' : {border : '#c2d69a', titleBG : '#9bbb59', titleFnt : '#ffffff', evenBG : '#eaf1dd',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema05' : {border : '#b2a1c7', titleBG : '#8064a2', titleFnt : '#ffffff', evenBG : '#d8d8d8',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema06' : {border : '#93cddd', titleBG : '#4bacc6', titleFnt : '#ffffff', evenBG : '#dbeef3',oddBG : '#ffffff', cellFnt : '#000000'},
		'tablethema07' : {border : '#fac090', titleBG : '#f79646', titleFnt : '#ffffff', evenBG : '#fde9d9',oddBG : '#ffffff', cellFnt : '#000000'}
	},
	divBlockInfo : {
		divblock01 : {bg : 'transparent', line : 'transparent',font : ''},
		divblock02 : {bg : '#ffffff', line : '#d3d3d3',font : '#464646'},
		divblock03 : {bg : '#e2e2e2', line : '#9a9a9a',font : '#464646'},
		divblock04 : {bg : '#555555', line : '#cdcdcd',font : '#ffffff'},
		divblock05 : {bg : '#d5ebb6', line : '#9faf88',font : '#464646'},
		divblock06 : {bg : '#9fd9ef', line : '#749eae',font : '#464646'},
		divblock07 : {bg : '#fffac5', line : '#bdb992',font : '#464646'},
		divblock08 : {bg : '#ffd7d7', line : '#c3a4a4',font : '#464646'}
	},
	menuDatas : null,
	initmenuDatas : {
		'col' : {text : 'Column',icon : 44, child : ['coladd','colremove','colmerge','colsplit','colwidth','colmergeall','colsum']},
		'coladd' : {text : 'Add', icon : 45},
		'colremove' : {text : 'Remove', icon : 48},
		'colmerge' : {text : '2 Cell Merge', icon : 26},
		'colmergeall' : {text : 'Merge All', icon : 27},
		'colsplit' : {text : 'Split', icon : 60},
		'colwidth' : {text : 'Same Width', icon : 63},
		'colsum' : {text : 'Auto Sum', icon : 85},
		'row' : {text : 'Row',icon : 47, child : ['rowadd','rowremove','rowmerge','rowsplit','rowwidth','rowmergeall','rowsum']},
		'rowadd' : {text : 'Add', icon : 46},
		'rowremove' : {text : 'Remove', icon : 49},
		'rowmerge' : {text : '2 Row Merge', icon : 18},
		'rowmergeall' : {text : 'Merge All', icon : 28},
		'rowsplit' : {text : 'Split', icon : 61},
		'rowwidth' : {text : 'Same Height', icon : 62},
		'rowsum' : {text : 'Auto Sum', icon : 85},
		'cellmerge' : {text : 'Cell Merge', icon : 13},
		'cellsplit' : {text : 'Split', icon : 10},
		'cellsum' : {text : 'Auto Sum', icon : 85},
		'cellalign' : {text : 'Cell Align',icon : 20, child : ['celllefttop','cellcentertop','cellrighttop','cellleftmiddle','cellcentermidle','cellrightmiddle','cellleftbottom','cellcenterbottom','cellrightbottom'], childwidth : 130},
		'celllefttop' : {text : 'Left Top', icon : 15},
		'cellcentertop' : {text : 'Center Top', icon : 16},
		'cellrighttop' : {text : 'Right Top', icon : 17},
		'cellleftmiddle' : {text : 'Left Middle', icon : 20},
		'cellcentermidle' : {text : 'Center Middle', icon : 21},
		'cellrightmiddle' : {text : 'Right Middle', icon : 22},
		'cellleftbottom' : {text : 'Left Bottom', icon : 23},
		'cellcenterbottom' : {text : 'Center Bottom', icon : 24},
		'cellrightbottom' : {text : 'Right Bottom', icon : 25},
		'tablecmd' : {text : 'Merge&amp;Split&amp;Sum', icon : 11, child : ['cellmerge','cellsplit','cellsum']},
		'linestyle' : {text : 'Line Style',icon : 75, child : ['line01','line02','line03','line04','line05','line','line06','line07','line08','line','line09','line10','line11','line12','line13'], childwidth : 180},
		'line01' : {text : 'Bottom Line', icon : 70},
		'line02' : {text : 'Top Line', icon : 71},
		'line03' : {text : 'Left Line', icon : 72},
		'line04' : {text : 'Right Line', icon : 73},
		'line05' : {text : 'No Border', icon : 74},
		'line06' : {text : 'All Border', icon : 75},
		'line07' : {text : 'Outside Line', icon : 76},
		'line08' : {text : 'Outside Thick Line', icon : 77},
		'line09' : {text : 'Bottom Double Line', icon : 78},
		'line10' : {text : 'Bottom Thick Line', icon : 79},
		'line11' : {text : 'Bottom Top Line', icon : 80},
		'line12' : {text : 'Bottom Top Thick Line', icon : 81},
		'line13' : {text : 'Top/Bottom Double Line', icon : 82},
		'tablethema' : {text : 'Table Color',icon : 50, child : ['tablethema01','tablethema02','tablethema03','tablethema04','tablethema05','tablethema06','tablethema07'], childwidth : 100},
		'tablethema01' : {text : 'Black', icon : 50},
		'tablethema02' : {text : 'Blue', icon : 51},
		'tablethema03' : {text : 'Red', icon : 52},
		'tablethema04' : {text : 'Green', icon : 53},
		'tablethema05' : {text : 'Purple', icon : 54},
		'tablethema06' : {text : 'Sky Blue', icon : 55},
		'tablethema07' : {text : 'Yellow', icon : 56},
		'translate' : {text : 'Translate', icon : 64, child : ['trans_ko','trans_en','trans_jp','trans_cn']},
		'trans_ko' : {text : 'Korean', icon : 65},
		'trans_en' : {text : 'English', icon : 66},
		'trans_jp' : {text : 'Japanese', icon : 67},
		'trans_cn' : {text : 'Chnese', icon : 68},
		'lineheight' : {text : 'Line Height',  icon : 36, child : ['lineheight100','lineheight120','lineheight140','lineheight160','lineheight180','lineheight200'], childwidth : 70},
		'lineheight100' : {text : '100%', icon : 37},
		'lineheight120' : {text : '120%', icon : 38},
		'lineheight140' : {text : '140%', icon : 39},
		'lineheight160' : {text : '160%', icon : 40},
		'lineheight180' : {text : '180%', icon : 41},
		'lineheight200' : {text : '200%', icon : 41},
		'fontlarge' : {text : 'Large', icon : 42},
		'fontsmall' : {text : 'Small', icon : 43},
		'createlink' : {text : 'Create Link', icon : 3},
		'align' : {text : 'Align',  icon : 35, child : ['justify','left','center','right']},
		'justify' : {text : 'Justify', icon : 32},
		'left' : {text : 'Left', icon : 35},
		'center' : {text : 'Center', icon : 34},
		'right' : {text : 'Right', icon : 33},
		'copypaste' : {text : 'Copy &amp; Paste', icon : 1, child : ['copy','cut','paste','pastestyle']},
		'copy' : {text : 'Copy', icon : 1},
		'cut' :{text : 'Cut', icon : 0},
		'paste' :{text : 'Paste', icon : 2},
		'pastestyle' :{text : 'Style Paste', icon : 86},
		'divblock' : {text : 'Block Format', icon : 90, child : ['divblock01','divblock02','divblock03','divblock04','divblock05','divblock06','divblock07','divblock08']},
		'divblock01' :{text : 'no Style', icon : 90},
		'divblock02' :{text : 'White', icon : 91},
		'divblock03' :{text : 'Gray', icon : 92},
		'divblock04' :{text : 'Black', icon : 93},
		'divblock05' :{text : 'Green', icon : 94},
		'divblock06' :{text : 'Blue', icon : 95},
		'divblock07' :{text : 'Yellow', icon : 96},
		'divblock08' :{text : 'Pink', icon : 97},
		'delete' : {text : 'Delete', icon : 29}
	},
	getMenuData : function(cmd) {
		if (this.menuDatas == null) {
			this.menuDatas = this.initmenuDatas;
			var contextLang = cafenMsg.getObject('ed_contextmenu');
			if (cafenMsg.lang !='ko') {
				this.menuDatas['fontlarge'].icon = 87;
				this.menuDatas['fontsmall'].icon = 88;
			}
			for(var idx in contextLang) {
				if (this.menuDatas[idx] != null && contextLang[idx] != null)
					this.menuDatas[idx].text = contextLang[idx];
			}
			if (!cafenGlobalConf.useTranlate) {
				this.menuDatas['translate'] = null;
			}
		}
		return this.menuDatas[cmd];
	},
	getMenuObject : function(cmd) {
		if (cmd != 'line') {
			var currObj = this.getMenuData(cmd);
			if (currObj != null) {
				var icon_no = currObj.icon;
				var x = (icon_no % 10) * 16;
				var y = Math.floor(icon_no / 10) * 16 + 320;
				var items = [];
				var width = null;
				if (currObj.child != null && currObj.child.length > 0) {
					for(var j = 0; j < currObj.child.length; j++) 
						items.push(this.getMenuObject(currObj.child[j]));	
					width = currObj.childwidth || 90;
				}
				return {width : width, text : currObj.text, shortkey : currObj.shortkey || null, items : items, icon : {className : 'r_editorset', x : x, y : y}, options : cmd };	
			} else 
				return  null;
		} else
			return  '----';
	}
},cafen.XWindow.prototype);


cafen.Editor.FontName = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initFontName();
}

cafen.Editor.FontName.prototype = cafen.extendClass({
	initFontName : function() {
		var fontMenu = [];
		var fontNames = cafenMsg.getObject('ed_fontnames');
		var shortkey = 0;
		var currShortKey = null;
		for(var i = 0; i < fontNames.length; i++) {
			var currObj = fontNames[i];
			currShortKey = (shortkey++ < 9) ? shortkey : null;
			fontMenu.push({text : '&nbsp;<font style="font-family:'+currObj.font+'">'+currObj.title +'</font>', icon : {className : 'r_editorset', x : 80, y : 112}, options : currObj.font});
		}
		fontMenu.push('----');
		var fontNames = cafenMsg.getObject('ed_fontnameseng');
		for(var i = 0; i < fontNames.length; i++) {
			var currObj = fontNames[i];
			currShortKey = (shortkey++ < 9) ? shortkey : null;
			fontMenu.push({text : '&nbsp;<font style="font-family:'+currObj.font+'">'+currObj.title +'</font>', icon : {className : 'r_editorset', x : 96, y : 112}, options : currObj.font});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(fontMenu, 140, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		this._editorObject.execCommand('fontName', null, obj.options.itemOptions);
	},
	onPopup : function() {
		var fontName = this._editorObject.queryCommandValue('fontName');
		var items = this.xMenu.getItems();
		for(var i = 0 ; i < items.length; i++) {
			if (fontName != '' && items[i].options.itemOptions.indexOf(fontName) != -1) 
				items[i].setSelected(true);
			else
				items[i].setSelected(false);
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.FindReplace = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', tplName :'bottom',style : { textAlign:'center', position :'absolute', width:'270px'}, shadow : true, donotresize : true}, options));
	this.contentsObj = new cafen.Div({style : {margin :'0px', padding:'0px',textAlign:'left', width:'270px'}});
	this.setObject(this.contentsObj);
	this.msgObj = new cafen.Div({style : {margin :'0px', padding:'4px 0px 2px 0px', width:'260px',textAlign:'right'}});
	this.appendChild(this.msgObj,'bottom');
	this.initFindReplace();
}

cafen.Editor.FindReplace.prototype = cafen.extendClass({
	tabShortKey : {find : 'S', replace : 'X'},
	initFindReplace : function() {
		var msgObj = cafenMsg.getObject('ed_findreplace');
		var tabObj = msgObj.menu;
		this._infoTab = [];
		this._infoTabObj = {}
		this._contentsObj = {}
		for(var idx in tabObj) {
			var text = tabObj[idx];
			this._infoTabObj[idx] = new cafen.XTab({className : this._editorObject.conf.getClassName('tab'), shortkey : this.tabShortKey[idx], text : text ,style : {},attribute : {}, event : {click: this.selectTab.bind(this,idx)}});
			this._infoTab.push(this._infoTabObj[idx]); 
		}
		this._infoTabMenu = new cafen.XTabMenu(this._infoTab);
		this.contentsObj.appendChild(this._infoTabMenu);

		var tmpOutDiv = new cafen.Div({className : this._editorObject.conf.getClassName('box'), style : {width:'270px', padding:'2px', margin:'0'}});
		this.contentsObj.appendChild(tmpOutDiv);
		var textTable = new cafen.TableAuto({attribute:{className:'r_table r_cell2px', cellSpacing:0, unselectable : 'on'}, style : {width:'270px',display:'none'}});
		textTable.addRow();
		textTable.addCell(msgObj.keyword);
		this.findKeywordObj = new cafen.XInput({style:{width:'100px'}, shortkey : 'I', event :{end : this.findKeyword.bind(this)}});
		textTable.addCell(this.findKeywordObj);
		var tmpButton = new cafen.XButton({text : msgObj.searchnext, shortkey : 'N', style:{margin:'1px 3px', width:'90px'}, event :{click : this.findKeyword.bind(this)}});
		textTable.addCell(tmpButton);
		cafen.setNextObject(this.findKeywordObj,tmpButton);
		tmpOutDiv.appendChild(textTable);
		this._contentsObj.find = textTable;
		var textTable = new cafen.TableAuto({attribute:{className:'r_table r_cell2px', cellSpacing:0, unselectable : 'on'}, style : {width:'270px',display:'none'}});
		textTable.addRow();
		textTable.addCell(msgObj.keyword);
		this.replaceKeywordObj = new cafen.XInput({style:{width:'100px'}, shortkey : 'I', event :{end : this.findKeyword.bind(this)}});
		textTable.addCell(this.replaceKeywordObj);
		var tmpButton = new cafen.XButton({text : msgObj.searchnext, shortkey : 'N', style:{margin:'1px 3px', width:'90px'}, event :{click : this.findKeyword.bind(this)}})
		textTable.addCell(tmpButton);
		textTable.addRow();
		textTable.addCell(msgObj.replaceword);
		this.replaceTxtObj = new cafen.XInput({style:{width:'100px'}, shortkey : 'T', event :{end : this.replaceKeyword.bind(this)}});
		textTable.addCell(this.replaceTxtObj);
		var tmpButton = new cafen.XButton({text : msgObj.replacenext, shortkey : 'R', style:{margin:'1px 3px', width:'90px'}, event :{click : this.replaceKeyword.bind(this)}});
		textTable.addCell(tmpButton);
		textTable.addRow();
		textTable.addCell('&nbsp;');
		textTable.addCell('&nbsp;');
		var replaceAllButton = new cafen.XButton({text : msgObj.replaceall, shortkey : 'A', style:{margin:'1px 3px', width:'90px'}, event :{click : this.replaceAll.bind(this)}});
		textTable.addCell(replaceAllButton);
		cafen.setNextObject(this.replaceKeywordObj, this.replaceTxtObj, tmpButton,replaceAllButton);

		tmpOutDiv.appendChild(textTable);
		this._contentsObj.replace = textTable;

/*
		var tmpOutDiv = new cafen.Div({style : {width:'270px', margin:'3px', textAlign:'right'}});
		var tmpButton = new cafen.XButton({text : cafenMsg.get('com_close'),shortkey : 'C', style:{marginLeft:'3px'}, event :{click : this.close.bind(this)}});
		tmpOutDiv.appendChild(tmpButton);
		this.contentsObj.appendChild(tmpOutDiv);
*/

		this.selectTab('find');
		if (cafen.browser.isOpera)
			this.showMsg(cafenMsg.get('ed_finderror'));
	},
	replaceAll : function() {
		var keyword = this.replaceKeywordObj.getValue();
		if (keyword.split(' ').join('') == '') {
			this.replaceKeywordObj.setError(true);
			this.showMsg(cafenMsg.get('ed_inputfind'));
		} else {
			this.replaceKeywordObj.setError(false);
			var replacekeyword = this.replaceTxtObj.getValue();
			this.replaceTxtObj.setError(false);
			if (this.lastKeyword != replacekeyword) {
				this._range = null;
				this.lastKeyword = replacekeyword;
			}
			this.replaceCnt = 0;
			this.findReset();
			this.find(keyword);
			var startRange = this._range;
			if (startRange != null) {
				this._reachBottom = false;
				while(this.replace(keyword, replacekeyword) == 0 && !this._reachBottom) {}
			}
			if (this.replaceCnt == 0) 
				this.showMsg(cafenMsg.get('ed_findnoresult'));
			else 
				this.showMsg(cafenMsg.get('ed_replaceresult',this.replaceCnt));
		}
	},
	showMsg : function(msg) {
		this.msgObj.getElement().innerHTML = msg;
	},
	lastKeyword : null,
	replaceCnt : 0,
	replaceKeyword : function() {
		var keyword = this.replaceKeywordObj.getValue();
		if (keyword.split(' ').join('') == '') {
			this.replaceKeywordObj.setError(true);
			this.showMsg(cafenMsg.get('ed_inputfind'));
		} else {
			this.replaceTxtObj.setError(false);
			var replacekeyword = this.replaceTxtObj.getValue();
			this.replaceTxtObj.setError(false);
			if (this.lastKeyword != keyword) {
				this._range = null;
				this.lastKeyword = keyword;
			}
			this.replaceCnt = 0;
			if (this.replace(keyword, replacekeyword) != 0) {
				this._range = null;
				this.lastKeyword = null;
				if (this.replaceCnt >= 1)
					this.showMsg(cafenMsg.get('ed_replacedone'));
				else
					this.showMsg(cafenMsg.get('ed_findnoresult'));
			} else 
				this.showMsg('');
		}
	},
	findKeyword : function(obj) {
		if (this.lastShownIdx == 'find') {
			var keyword = this.findKeywordObj.getValue();
			if (keyword.split(' ').join('') == '') {
				this.findKeywordObj.setError(true);
				this.showMsg(cafenMsg.get('ed_inputfind'));
			} else {
				this.findKeywordObj.setError(false);
				this.docFind(keyword);
			}
		} else {
			var keyword = this.replaceKeywordObj.getValue();
			if (keyword.split(' ').join('') == '') {
				this.replaceKeywordObj.setError(true);
				this.showMsg(cafenMsg.get('ed_inputfind'));
			} else {
				this.replaceKeywordObj.setError(false);
				this.docFind(keyword);
			}
		}
	},
	docFind : function(txt) {
		this.lastKeyword = txt;
		if (this.find(this.lastKeyword) != 0)
			this.showMsg(cafenMsg.get('ed_findnoresult'));
		else
			this.showMsg('');
	},
	find : function(sKeyword, bCaseMatch, bBackwards, bWholeWord){
		var bSearchResult, bFreshSearch;
		this._editorObject._editorObject.htmlEditor.getWindow().focus();
		if(!sKeyword) return 2;
		this._reachBottom = false;
		bSearchResult = this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
		if(bSearchResult) return 0;
		this._reachBottom = true;
		bSearchResult = this.findNew(sKeyword, bCaseMatch, bBackwards, bWholeWord);
		if(bSearchResult) return 0;
		return 1;
	},
	findNew : function (sKeyword, bCaseMatch, bBackwards, bWholeWord){
		this.findReset();
		return this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
	},
	findNext : function(sKeyword, bCaseMatch, bBackwards, bWholeWord){
		var bSearchResult;
		bCaseMatch = bCaseMatch || false;
		bWholeWord = bWholeWord || false;
		bBackwards = bBackwards || false;
		if(window.find){
			var bWrapAround = false;
			var bSearchResult = this._editorObject._editorObject.htmlEditor.getWindow().find(sKeyword, bCaseMatch, bBackwards, bWrapAround, bWholeWord);
			if (bSearchResult) { 
				this._range = this._editorObject._editorObject.htmlEditor.getWindow().getSelection().getRangeAt(0);
				if (!this._editorObject._editorObject.htmlEditor.isInRange(this._range)) {
					this._range = null;
					bSearchResult = this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
					if (!bSearchResult) 
						this._editorObject._editorObject.htmlEditor.restoreFocus();
				}
			} else {
				this._range = null;
			}
			if (bSearchResult)
				this._editorObject._editorObject.htmlEditor.saveFocus();
			return bSearchResult
		} else if (document.selection) {
			var iOption = 0;
			if(bBackwards) iOption += 1;
			if(bWholeWord) iOption += 2;
			if(bCaseMatch) iOption += 4;
			this._editorObject._editorObject.htmlEditor.getWindow().focus();
			try {
			this._range = this._editorObject._editorObject.htmlEditor.getDocument().selection.createRangeCollection().item(0);
			if (this._lastRange != null && this._lastRange.inRange(this._range)) {
				return 0;
			} else {
				this._lastRange= this._range.duplicate();
			}
			this._range.collapse(false);
			bSearchResult = this._range.findText(sKeyword, 1, iOption);
			if (bSearchResult) {
				if (!this._editorObject._editorObject.htmlEditor.isInRange(this._range)) {
					this._range.select();
					bSearchResult = this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
					if (!bSearchResult) {
						this._editorObject._editorObject.htmlEditor.restoreFocus();
					}
				} else {
					this._range.select();
				}
			} else {
				this._range = null;	
			}
			
			} catch(ex) {} 
			if (bSearchResult)
				this._editorObject._editorObject.htmlEditor.saveFocus();
			return bSearchResult;
		} else {
			this._range = null;
		}
		return false;
	},
	findReset : function() {
		if (window.find){
			this._editorObject._editorObject.htmlEditor.getWindow().getSelection().removeAllRanges();
			return;
		} else if(document.selection){
			this._range = this._editorObject._editorObject.htmlEditor.getBody().createTextRange();
			this._range.collapse(true);
			this._range.select();
		}
	},
	replace : function(sOriginalWord, sReplaceWord, bCaseMatch, bBackwards, bWholeWord){
		if (this._range == null) 
			this.findNext(sOriginalWord, bCaseMatch, bBackwards, bWholeWord);
		if (this._range != null) {
			this.replaceCnt++;
			if (sReplaceWord == '') {
				try {
					this._editorObject._editorObject.htmlEditor.execCommand("delete", false, null);
				} catch(ex) {}
			} else {
				if(document.selection) {
					this._range.pasteHTML(sReplaceWord);
					this._range.collapse(true);
					this._range.select();
				} else {
					 try {
						this._editorObject._editorObject.htmlEditor.execCommand("insertHTML", false ,sReplaceWord); 
					} catch (ex){}
				}
			}
			return this.find(sOriginalWord, bCaseMatch, bBackwards, bWholeWord);
		} else
			return 1;
	},
	selectTab : function(idx, obj) {
		if (obj == null)
			obj = this._infoTabObj[idx];
		this._infoTabMenu.setSelected(obj);
		if (this.lastShownObj != null)
			this.lastShownObj.hide();
		if (	this._contentsObj[idx] != null) {
			this.lastShownObj = this._contentsObj[idx];
			this.lastShownObj.show();
			if (this.lastShownIdx != null) {
				if (this.lastShownIdx == 'find') {
					this.replaceKeywordObj.setValue(this.findKeywordObj.getValue());
					this.replaceKeywordObj.setError(false);
				} else {
					this.findKeywordObj.setValue(this.replaceKeywordObj.getValue());
					this.findKeywordObj.setError(false);
				}
			}
			this.lastShownIdx = idx;
		}
	},
	onClose : function() {
		this._editorObject.closePopup();
	}
},cafen.XWindow.prototype);

cafen.Editor.SelectStyle = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initSelectStyle();
}

cafen.Editor.SelectStyle.prototype = cafen.extendClass({
	initSelectStyle : function() {
		var fontMenu = [];
		var styleNames = cafenMsg.getObject('ed_stylenames');
		var shortkey = 0;
		var currShortKey = null;
		for(var i = 0; i < styleNames.length; i++) {
			var currObj = styleNames[i];
			currShortKey = (shortkey++ < 9) ? shortkey : null;
			fontMenu.push({shortkey : currShortKey, text : '&nbsp;'+currObj.title +'', icon : {className : 'r_editorset', x : 80, y : 112}, options : _cafen_service_url +'images/'+currObj.href});
		}
		if (cafenEditor_loader.editorBaseConf.useStyle.length > 0) {
			fontMenu.push('----');
			for(var i =0; i < cafenEditor_loader.editorBaseConf.useStyle.length; i++) {
				var currObj = cafenEditor_loader.editorBaseConf.useStyle[i];
				currShortKey = (shortkey++ < 9) ? shortkey : null;
				fontMenu.push({shortkey : currShortKey, text : '&nbsp;'+currObj.title +'', icon : {className : 'r_editorset', x : 80, y : 112}, options : _cafen_service_url +'images/'+currObj.href});
			}
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(fontMenu, 140, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'150px'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		this._editorObject.execCommand('changestyle', null, obj.options.itemOptions);
	},
	onPopup : function() {	}
},cafen.XWindow.prototype);

cafen.Editor.DivBlock = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initDivBlock();
}

cafen.Editor.DivBlock.prototype = cafen.extendClass({
	initDivBlock : function() {
		this.colorset = [];
		if (cafenEditor_loader.editorBaseConf.useDivColor.length > 0) {
			for(var i = 0; i < cafenEditor_loader.editorBaseConf.useDivColor.length; i++) 
				this.colorset.push(cafenEditor_loader.editorBaseConf.useDivColor[i]);	
		} else {
			var colorInfo = [
				{bg : '#ffffff', line : '#d3d3d3',font : '#464646'},
				{bg : '#e2e2e2', line : '#9a9a9a',font : '#464646'},
				{bg : '#555555', line : '#cdcdcd',font : '#ffffff'},
				{bg : '#d5ebb6', line : '#9faf88',font : '#464646'},
				{bg : '#9fd9ef', line : '#749eae',font : '#464646'},
				{bg : '#fffac5', line : '#bdb992',font : '#464646'},
				{bg : '#ffd7d7', line : '#c3a4a4',font : '#464646'}
			];
			var colorset = [];
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.line+' 2px solid;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.line+' 3px double;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.line+' 1px solid;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.bg+' 1px solid;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.line+' 1px dotted;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push('BORDER:'+obj.line+' 1px dashed;PADDING: 10px; BACKGROUND-COLOR: '+obj.bg+'; COLOR: '+obj.font+'');
			}
			
			this.colorset = colorset ;
		}
		var divMenu = [];
		var shortkey = 0;
		var currShortKey = null;
		for(var i = 0; i < this.colorset.length; i++) {
			var currObj = this.colorset[i];
			currShortKey = (shortkey++ < 9) ? shortkey : null;
			divMenu.push({text : '<div style="'+currObj+';padding:2px;margin-right:3px;width:85px;overflow:hidden;height:18px;margin:0px">Block</div>', height : '23px',options : i, icon : {text : '<div style="'+currObj+';padding:1px;font-size:2px;height:14px;width:14px;margin:0">&nbsp;</div>'}});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(divMenu, 140, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		var style_color = this.colorset[obj.options.itemOptions];
		if (this.selectedObj == null) {
			var html = '<br/><blockquote style="'+style_color+'"><P>&nbsp;</P></blockquote><br/>';
			this._editorObject.execCommand('insertHTML', null, html);
		} else {
			style_color = style_color.replace(/[ ]*:[ ]*/g,':');
			var styleArr = style_color.split(';');
			var blockStyle = {};
			for(var i = 0; i < styleArr.length; i++) {
				var styleInfo = 	styleArr[i].split(':');
				var styleName = styleInfo[0].replace(/ /g,'');
				var styleValue = styleInfo[1].replace(/^ | $/,'');
				switch(styleName.toLowerCase()) {
					case 'color' :
						blockStyle.color = styleValue;
						break;
					case 'border' :
						blockStyle.border = styleValue;
						break;
					case 'padding' :
						blockStyle.padding = styleValue;
						break;
					case 'background-color' :
						blockStyle.backgroundColor = styleValue;
						break;
				}
			}
			cafen.setStyle(this.selectedObj,blockStyle);
			this._editorObject.execCommand('closepopup');
		}
	},
	onPopup : function() {
		this.selectedObj = this._editorObject.getParentElement('blockquote');
	}
},cafen.XWindow.prototype);


cafen.Editor.FormatHtml = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initFormatHtml();
}

cafen.Editor.FormatHtml.prototype = cafen.extendClass({
	initFormatHtml : function() {
		this.baseformat = [];
		var tmpFormat = cafenMsg.getObject('ed_baseformat');
		for(var i = 0; i < tmpFormat.length; i++) 
			this.baseformat.push({title : tmpFormat[i].title, thumb : _cafen_service_url+'images/'+ tmpFormat[i].thumb, xml : _cafen_service_url +'htmlxml/'+tmpFormat[i].xml});
		this._iconTable = new cafen.TableAuto({attribute:{unselectable : 'on'}, style : {cursor : cafen.getCursor()}});
		for(var i = 0; i < this.baseformat.length; i++) {
			var currObj = this.baseformat[i];
			if (i % 3 == 0)
				this._iconTable.addRow();
			var tmpcell = this._iconTable.addCell('<img src="'+currObj.thumb+'" border=0 width=38 height=38 title="'+currObj.title+'" style="margin:1px">');
			tmpcell.attachEvent('click', this.sendValue.bind(this, i));
		}
		this.appendChild(this._iconTable);
	},
	sendValue : function(seqn) {
		cafen.smallSWFAjax.getFlashXml({}, this.setFormat.bind(this), this.baseformat[seqn].xml, false);
	},
	setFormat : function(html) {
		this._editorObject.execCommand('insertHTML', null, html +'<br/>');
	},
	onPopup : function() {
	}
},cafen.XWindow.prototype);


cafen.Editor.Emoticon = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className : this._editorObject.conf.getClassName('buttonarea') , tag : 'div', style : { textAlign:'left', position :'absolute'}, shadow : true}, options));
	this.initEmoticon();
}

cafen.Editor.Emoticon.prototype = cafen.extendClass({
	_iconTable : null,
	_baseIcon : null,
	_selectedIdx : null,
	_iconTab : [],
	_iconTabMenu : null,
	_maxLength : null,
	base_config : [
		{
			title :'Cafen',
			shortkey : 'C',
			text : [
			'icon/cafen/one_icon1.gif','icon/cafen/one_icon2.gif','icon/cafen/one_icon3.gif','icon/cafen/one_icon4.gif','icon/cafen/one_icon5.gif','icon/cafen/one_icon6.gif','icon/cafen/one_icon7.gif','icon/cafen/one_icon8.gif','icon/cafen/one_icon9.gif','icon/cafen/one_icon10.gif',
			'icon/cafen/one_icon11.gif','icon/cafen/one_icon12.gif','icon/cafen/one_icon13.gif','icon/cafen/one_icon14.gif','icon/cafen/one_icon15.gif','icon/cafen/one_icon16.gif','icon/cafen/one_icon17.gif','icon/cafen/one_icon18.gif','icon/cafen/one_icon19.gif','icon/cafen/one_icon20.gif'
			]
		},
		{
			title :'MSN',
			shortkey : 'M',
			text :[
				'icon/msn/angel_smile.gif','icon/msn/angry_smile.gif','icon/msn/broken_heart.gif','icon/msn/cake.gif','icon/msn/confused_smile.gif','icon/msn/cry_smile.gif','icon/msn/devil_smile.gif','icon/msn/embaressed_smile.gif','icon/msn/envelope.gif','icon/msn/heart.gif',
				'icon/msn/kiss.gif','icon/msn/lightbulb.gif','icon/msn/omg_smile.gif','icon/msn/regular_smile.gif','icon/msn/sad_smile.gif','icon/msn/shades_smile.gif','icon/msn/teeth_smile.gif','icon/msn/thumbs_down.gif','icon/msn/thumbs_up.gif','icon/msn/tounge_smile.gif','icon/msn/whatchutalkingabout_smile.gif','icon/msn/wink_smile.gif'
			]
		}
	],
	initEmoticon : function() {
		this._baseIcon = [];
		this._maxLength = 20;
		if (cafenEditor_loader.editorBaseConf.useEmoticon.length > 0) {
			for(var i = 0; i < cafenEditor_loader.editorBaseConf.useEmoticon.length; i++) 
				this._baseIcon.push(cafenEditor_loader.editorBaseConf.useEmoticon[i]);	
		}
		for(var i = 0; i < this.base_config.length; i++) {
			var title = this.base_config[i].title;
			var shortkey = this.base_config[i].shortkey;
			var text = [];
			for(var j = 0 ; j  < this.base_config[i].text.length; j++)
				text.push(this._editorObject.conf.imgURL() + this.base_config[i].text[j]);
			this._baseIcon.push({title : title, text : text, shortkey : shortkey});
		}
		this._iconTab = [];
		this._maxLength = 0;
		for(var i = 0; i < this._baseIcon.length; i++) {
			this._iconTab.push(new cafen.XTab({className : this._editorObject.conf.getClassName('tab'), text : this._baseIcon[i].title, shortkey : this._baseIcon[i].shortkey ,attribute : {title : this._baseIcon[i].title}, event : {click: this.selectTab.bind(this,i)}})); 
			this._maxLength = Math.max(this._maxLength, this._baseIcon[i].text.length);
		}
		this._iconTabMenu = new cafen.XTabMenu(this._iconTab);
		this.appendChild(this._iconTabMenu);
		var tmpDiv = new cafen.Div({className : this._editorObject.conf.getClassName('box')});
		this._iconTable = new cafen.TableAuto({attribute:{border :0, cellpadding : 1, cellspacing:1, unselectable : 'on'}, style : {margin:'2px',width:'175px',cursor : cafen.getCursor()}});
		tmpDiv.appendChild(this._iconTable);
		this.appendChild(tmpDiv);
		for(var i = 0; i<this._maxLength; i++) {
			if (i % 7 == 0)
				this._iconTable.addRow();
			var tmpcell = this._iconTable.addCell();
			this._iconTable.addStyle({width:'25px', height:'25px', border : '0',fontSize :'12px', backgroundRepeat:'no-repeat', backgroundPosition : 'center center'});
			this._iconTable.addText('&nbsp;');
			this._iconTable.addMouseEvent({backgroundColor : ''},{backgroundColor : '#d6d6d6'});
			tmpcell.attachEvent('click', this.sendIcon.bind(this, i));
		}
		this.selectTab(0, this._iconTab[0]);
	},
	selectTab : function(idx, obj) {
		this._iconTabMenu.setSelected(obj);
		this._selectedIdx = idx;
		var baseIconSetText = this._baseIcon[idx].text;
		var currLength = baseIconSetText.length;
		for(var i = 0 ; i < this._maxLength; i++) {
			var x = i % 7;
			var y = Math.floor(i/7);
			var str = (currLength > i) ? baseIconSetText[i] : '';
			if (str != '') 
				this._iconTable.addStyle({backgroundImage : 'url('+str+')'}, x, y);
			else
				this._iconTable.addStyle({backgroundImage : 'none'}, x, y);
		}
	},
	sendIcon : function(val) {
		var baseIconSetText = this._baseIcon[this._selectedIdx].text;
		var currLength = baseIconSetText.length;
		var str = (currLength > val) ? baseIconSetText[val] : '';
		if (str != null && str != '') {
			this._editorObject.execCommand('insertHTML', null, '<img src='+str+' border=0 align=absmiddle>');
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.ColorPicker = function(editorObj, cmd, options) {
	this._editorObject = editorObj;
	this.colorCmd = cmd;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'left', position :'absolute'}, shadow : true}, options));
	this.initPicker();
}

cafen.Editor.ColorPicker.prototype = cafen.extendClass({
	_colorTable : null,
	_colorTab : [],
	_colorTabMenu : null,
	_maxLength : null,
	_selectedIdx : null,
	_baseColor : [
		{
			title : 'MS-Word',
			shortkey : 'W',
			color :[
				 '#FFFFFF','#000000','#EEECE1','#1F497D','#4F81BD','#C0504D','#9BBB59','#8064A2','#4BACC6','#F79646',
				'#F2F2F2','#7F7F7F','#DDD9C3','#C6D9F0','#DBE5F1','#F2DCDB','#EBF1DD','#E5E0EC','#DBEEF3','#FDEADA',
				'#D8D8D8','#595959','#C4BD97','#8DB3E2','#B8CCE4','#E5B9B7','#D7E3BC','#CCC1D9','#B7DDE8','#FBD5B5',
				'#BFBFBF','#3F3F3F','#938953','#548DD4','#95B3D7','#D99694','#C3D69B','#B2A2C7','#92CDDC','#FAC08F',
				'#A5A5A5','#262626','#494429','#17365D','#366092','#953734','#76923C','#5F497A','#31859B','#E36C09',
				'#7F7F7F','#0C0C0C','#1D1B10','#0F243E','#244061','#632423','#4F6128','#3F3151','#205867','#974806',
				'#C00000','#FF0000','#FFC000','#FFFF00','#92D050','#00B050','#00B0F0','#0070C0','#002060','#7030A0'
			]
		},
		{
			title : 'Google',
			shortkey : 'G',
			color :[
		 		'#FFFFFF','#000000','#FF0000', '#FF9900', '#FFFF00','#00FF00','#00FFFF','#0000FF','#9900FF','#FF00FF',
		 		'#F2F2F2','#7F7F7F','#F4CCCC', '#FCE5CD', '#FFF2CC','#D9EAD3','#D0E0E3','#CFE2F3','#D9D2E9','#EAD1DC',
		 		'#D8D8D8','#595959','#EA9999', '#F9CB9C', '#FFE599','#B6D7A8','#A2C4C9','#9FC5E8','#B4A7D6','#D5A6BD',
		 		'#BFBFBF','#3F3F3F','#E06666', '#F6B26B', '#FFD966','#93C47D','#76A5AF','#6FA8DC','#B4A7D6','#C27BA0',
		 		'#A5A5A5','#262626','#CC0000', '#E69138', '#F1C232','#6AA84F','#45818E','#3D85C6','#674EA7','#A64D79',
		 		'#7F7F7F','#0C0C0C','#990000', '#B45F06', '#BF9000','#38761D','#134F5C','#0B5394','#351C75','#741B47',
		 		'#C00000','#FF0000','#660000', '#783F04', '#7F6000','#274E13','#0C343D','#073763','#20124D','#4C1130'
			]
		},
		{
			title : 'Color Set1-1',
			shortkey : '1',
			color :[
				'#CD853F','#CD8B45','#CD904A','#D2954F','#D29A54','#D79F59','#D7A45E','#E1A963','#E1AE68','#E6B36D',
				'#DB631F','#E56D29','#E57733','#EA813D','#EF8B47','#EF904C','#F49551','#F49A56','#F49F5B','#F4A460',
				'#D2691E','#D27328','#D77D32','#D7873C','#DC9146','#E19B50','#E6A055','#EBA55A','#F0AA5F','#F5AF64',
				'#A0522D','#A05C37','#A06641','#A5704B','#AA7A55','#B4845F','#B98E69','#C39873','#CDA27D','#D7AC87',
				'#8B4513','#8B4F1D','#8B5927','#8B6331','#906D3B','#9A7745','#A4814F','#AE8B59','#B89563','#C29F6D',
				'#DA70D6','#DF75DB','#E47AE0','#E97FE5','#EE84EA','#F389EF','#F88EF4','#FD93F9','#FF98FE','#FF9DFF',
				'#BA55D3','#BF5AD8','#C45FDD','#C964E2','#CE69E7','#D36EEC','#D873F1','#DD78F6','#E27DFB','#E782FF'
			]
		},
		{
			title : 'Color Set1-2',
			shortkey : '2',
			color :[
				'#9932CC','#9E37D1','#A33CD6','#A841DB','#AD46E0','#B24BE5','#B750EA','#BC55EF','#C15AF4','#C65FF9',
				'#9400D3','#9905D8','#9E0ADD','#A30FE2','#A814E7','#AD19EC','#B21EF1','#B723F6','#BC28FB','#C12DFF',
				'#942894','#9E329E','#A83CA8','#B246B2','#BC50BC','#C65AC6','#D064D0','#DA6EDA','#E478E4','#EE82EE',
				'#8C008C','#960A96','#A014A0','#AA1EAA','#B428B4','#BE32BE','#C83CC8','#D246D2','#DC50DC','#E65AE6',
				'#800080','#8A0A8A','#941494','#9E1E9E','#A828A8','#B232B2','#BC3CBC','#C646C6','#D050D0','#DA5ADA',
				'#834683','#8D508D','#975A97','#A164A1','#AB6EAB','#B578B5','#BF82BF','#C98CC9','#D396D3','#DDA0DD',
				'#FFFFFF','#000000','#F2F2F2','#7F7F7F','#D8D8D8','#595959','#BFBFBF','#3F3F3F','#A5A5A5','#262626'
			]
		}
	],
	initPicker : function() {
		this._maxLength = 0;
		this._colorTab = [];
		for(var i = 0; i < this._baseColor.length; i++) {
			this._colorTab.push(new cafen.XTab({className : this._editorObject.conf.getClassName('tab') , shortkey : i+1, icon : {className :'r_editorset', x : i * 16, y : 144, w : 16, h:16},attribute : {title : this._baseColor[i].title}, event : {click: this.selectTab.bind(this,i)}})); 
			this._maxLength = Math.max(this._maxLength, this._baseColor[i].color.length);
		}
		this._colorTabMenu = new cafen.XTabMenu(this._colorTab);
		this.appendChild(this._colorTabMenu);
		var tmpDiv = new cafen.Div({className : this._editorObject.conf.getClassName('box')});
		this._colorTable = new cafen.TableAuto({attribute:{className :'r_table r_sboxselected', border :0, cellPadding : 0, cellSpacing: 0, unselectable : 'on'}, style : {width:'170px', margin:'2px',cursor : cafen.getCursor(), borderSpacing:'0'}});
		tmpDiv.appendChild(this._colorTable);
		this.appendChild(tmpDiv);
		for(var i = 0; i< this._maxLength; i++) {
			if (i % 10 == 0)
				this._colorTable.addRow();
			var tmpcell = this._colorTable.addCell("&nbsp;");
			tmpcell.attachEvent('click', this.sendColor.bind(this, i));
		}
		this.selectTab(0, this._colorTab[0]);
	},
	selectTab : function(idx, obj) {
		this._colorTabMenu.setSelected(obj);
		this._selectedIdx = idx;
		var baseCharSetText = this._baseColor[idx].color;
		var currLength = baseCharSetText.length;
		for(var i = 0 ; i < this._maxLength; i++) {
			var x = i % 10;
			var y = Math.floor(i/10);
			var str = (currLength > i) ? baseCharSetText[i] : 'transparent';
			this._colorTable.addStyle({backgroundColor : str}, x, y);
		}
	},
	sendColor : function(val) {
		var baseCharSetText = this._baseColor[this._selectedIdx].color;
		var currLength = baseCharSetText.length;
		var str = (currLength > val) ? baseCharSetText[val] : '';
		if (str != null && str != '') 
			this._editorObject.execCommand(this.colorCmd, null, str);
	}
},cafen.XWindow.prototype);

cafen.Editor.SpecialChar = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'left', position :'absolute'}, shadow : true}, options));
	this.initSpecialChar();
}
cafen.Editor.SpecialChar.prototype = cafen.extendClass({
	_charTable : null,
	_baseChar : null,
	_selectedIdx : null,
	_charTab : [],
	_charTabMenu : null,
	_maxLength : null,
	initSpecialChar : function() {
		this._baseChar = cafenMsg.getObject('ed_specialchar');
		this._charTab = [];
		this._maxLength = 0;
		for(var i = 0; i < this._baseChar.length; i++) {
			this._charTab.push(new cafen.XTab({className : this._editorObject.conf.getClassName('tab'), shortkey : i+1, icon : {className :'r_editorset', x : this._baseChar[i].icon[0], y :this._baseChar[i].icon[1], w : 16, h:16},attribute : {title : this._baseChar[i].title}, event : {click: this.selectTab.bind(this,i)}})); 
			this._maxLength = Math.max(this._maxLength, this._baseChar[i].text.length);
		}
		this._charTabMenu = new cafen.XTabMenu(this._charTab);
		this.appendChild(this._charTabMenu);
		var tmpDiv = new cafen.Div({className : this._editorObject.conf.getClassName('box'), style : {width:'220px', height : '220px',overflowY : 'auto'}});
		this.appendChild(tmpDiv);
		this._charTable = new cafen.TableAuto({attribute:{className : 'r_table r_boxselected',border :0, cellpadding : 1, cellspacing:1, unselectable : 'on'}, style : {cursor : cafen.getCursor()}});
		tmpDiv.appendChild(this._charTable);
		for(var i = 0; i<this._maxLength; i++) {
			if (i % 10 == 0)
				this._charTable.addRow();
			var tmpcell = this._charTable.addCell();
			this._charTable.addStyle({width:'20px', height:'20px', fontSize: '12px', textAlign:'center'});
			tmpcell.attachEvent('click', this.sendChar.bind(this, i));
		}
		this.selectTab(0, this._charTab[0]);
	},
	selectTab : function(idx, obj) {
		this._charTabMenu.setSelected(obj);
		this._selectedIdx = idx;
		var baseCharSetText = this._baseChar[idx].text;
		var currLength = baseCharSetText.length;
		for(var i = 0 ; i < this._maxLength; i++) {
			var x = i % 10;
			var y = Math.floor(i/10);
			var str = (currLength > i) ? baseCharSetText.charAt(i) : '&nbsp;';
			this._charTable.addText(str, x, y);
		}
	},
	sendChar : function(val) {
		var x = val % 10;
		var y = Math.floor(val/10);
		var str = this._charTable.getText(x,y);
		if (str != null && str != '' && str != '&nbsp;') 
			this._editorObject.execCommand('insertHTML', null, str);
	}
},cafen.XWindow.prototype);


cafen.Editor.TableMaker = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(
	cafen.extend(
		{className :this._editorObject.conf.getClassName('buttonarea') , style : {
			backgroundImage : 'url('+_cafen_service_url+'images/editor_table.gif)', 
			backgroundPosition: '-189px -151px', width: '190px', height : '152px'
			}
		}, options));
	this.initTable();
}
cafen.Editor.TableMaker.prototype = cafen.extendClass({
	_mkTable : null,
	initTable : function() {
		this._colorTable = new cafen.TableAuto({attribute:{border :0, width :'190', height : '152', cellpadding : 0, cellspacing:0, unselectable : 'on'}, style : {width :'190px', height : '152px',cursor : cafen.getCursor()}});
		this.appendChild(this._colorTable);
		for(var i = 0; i < 8; i++) {
			this._colorTable.addRow();
			for(var j = 0; j < 10; j++) {
				var tmpcell = this._colorTable.addCell();
				this._colorTable.addText('&nbsp;');
				tmpcell.attachEvent('click', this.sendTable.bind(this, j, i));
				tmpcell.attachEvent('mouseover', this.showTable.bind(this, j, i));
			}
		}		
	},
	showTable : function(x, y) {
		x = (x +1)*19 - 189;
		y = (y +1)*19 - 151;
		this.setStyle({backgroundPosition : x+'px '+y+'px'});
	},
	sendTable : function(x,y) {
		var htmltable = '<TABLE cellSpacing=0 cellPadding=2 borderColor=#b7bbb5 border=0 style="border-collapse:collapse;width:100%"><TBODY>';
		for (var i = 0; i < y+1; i++) {
			htmltable += '<TR>';
			for (var j = 0; j < x+1; j++) {
				htmltable += '<TD style="background-color:#ffffff;color:#464646;border-style:solid;border-color:#b7bbb5;border-width:1px">&nbsp;</TD>';
			}
			htmltable += '</TR>';
		}
		htmltable += '</TBODY></TABLE>';
		this._editorObject.execCommand('insertHTML', null, htmltable);
	},
	setColor : function(bgColor) {
		this.setStyle({backgroundColor : bgColor});
	}
},cafen.XWindow.prototype);


cafen.Editor.Translate = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :this._editorObject.conf.getClassName('buttonarea'), tag : 'div', style : { textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.initTranslate();
};

cafen.Editor.Translate.prototype = cafen.extendClass({
	languages : cafenMsg.getObject('ed_translate'),
	xMenuObj : null,
	initTranslate : function(doc_obj) {
		var childNodes = [];
		
		var flagInfo = {
			'ko' : 0,
			'en' : 16,
			'ja' : 32,
			'zh-CN' : 48,
			'ru' : 64,
			'fr' : 80,
			'de' : 96,
			'vi': 112,
			'zh-TW' : 128,
			'ar' : 144
		}
		for(var idx in this.languages)  {
			var icon  = (flagInfo[idx] != null) ? {className :'r_editorset',x: flagInfo[idx],y : 160} : null;
			childNodes.push({icon : icon , text : this.languages[idx], onclick : this.sendValue.bind(this, idx)});
		}
		this._xMenuObj = new cafen.XMenu(childNodes, 150, {style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : this._editorObject.conf.getClassName('attachbutton')});
		this.appendChild(this._xMenuObj);
	},
/**
 * 값전송
 * @param {int} idx  메뉴 번호
 */
	sendValue : function(idx) {
		var str = this._editorObject.getSelectedHTML();
		if (str != null && str.split(' ').join('') != '') {
			if (str.length > 300) { 
				this._editorObject.showMsg(cafenMsg.get('ed_0132', str.length));
			} else {
				this.selectObj = this._editorObject.getSelectedElement();
				this._editorObject.showStatus(cafenMsg.get('ed_0133', this.languages[idx]));
				this._editorObject.execCommand('closepopup', true, null);
				cafen.smallSWFAjax.getTranslate(str, idx, this.translateLanguage.bind(this));
			}
		} else {
			this._editorObject.showMsg(cafenMsg.get('ed_0131'));
		}
	},
	translateLanguage : function (result) {
		if (result.translation) {
			this._editorObject.execCommand('insertHTML', true, result.translation, this.selectObj);
			this._editorObject.showStatus('', true);
		} else if (result.error){
			this._editorObject.showMsg(result.error.message);
		}
	},
	onPopup : function() {
		var str = this._editorObject.getSelectedHTML();
		if (str != null && str.split(' ').join('') != '') {

		} else {
			this.selectObj = this._editorObject.getSelectedElement();
			this._editorObject.selectNode(this.selectObj);
		}
	}
},cafen.XWindow.prototype);

cafen.Editor.Chart = function(editorObject, options) {
	this._editorObject = editorObject;
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r_popskin', tag : 'div', tplName : 'both', style : {textAlign:'center', width : '536px',position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('ed_0135'));
	this.setToolBar();
	this._popupObj = new cafen.XWindow();
	this.setObject(this._popupObj);
	this.contentsObj = new cafen.Div({style : {margin :'0px', textAlign:'left', width : '534px'}});
	this.setObject(this.contentsObj);
	this.initChart();
};

cafen.Editor.Chart.prototype = cafen.extendClass({
	initChart : function() {
		this._uploadScript = this._editorObject.getUploadScript();
		this._uploadUrl = this._editorObject.getUploadUrl();
		this.chartData = [];
		this.buttonArea = new cafen.TableAuto({className : 'r_boxblue', style : {width : '524px', margin :'2px'}});
		this.contentsObj.appendChild(this.buttonArea);
		this.dataArea = new cafen.Div({className : 'r_boxwhite', style : {width : '524px', height : '60px',margin :'2px', overflowX : 'auto', overflowY : 'auto'}});
		this.contentsObj.appendChild(this.dataArea);
		this.chartArea = new cafen.Div({className : 'r_boxwhite', style : {width : '524px', height : '250px',margin :'2px', textAlign:'center', overflowY : 'auto'}});
		this.contentsObj.appendChild(this.chartArea);
		this._chartOption = {axisType : 'xyaxis', width : 504, height:250, title : 'rainchart'};
		this.drawToolbar();
	},
	drawToolbar : function() {
		this.getAutoColorSet();
		var buttonInfo = cafenMsg.getObject('chart_buttonInfo');
		var groupstart = false;
		var groupmiddle = false;
		var groupend = false;
		var toolbarSet = cafenMsg.getObject('chart_menu').mini;
		var cnt = toolbarSet.length;
		var currRowObj = null;
		this.statusButton = [];
		this.actionButton = {};
		var iconMargin = null;
		if(cafen.browser.isIE) 
			iconMargin = '0 0 0 3px';
		else if(cafen.browser.isFF) 
			iconMargin = '-1 0 0 0px';
		else
			iconMargin = '3px 0px 3px 2px';
		for(var i = 0; i < cnt ; i++) {
			if (currRowObj == null) {
				currRowObj = new cafen.TableAuto({align:'left', attribute : {border:0},style : {}});
				this.buttonArea.addRow();
				this.buttonArea.addCell(currRowObj);
				currRowObj.addRow();
			}
			var idx = toolbarSet[i];
			switch(idx) {
				case 'separator':
					break;
				case 'group' :
				case '[' :
					groupstart = true;
					groupmiddle = false;
					groupend = false;
					break;
				case 'break' :
				case ']' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'blank' :
					currRowObj.addCell();
					currRowObj.addStyle({width:'3px'});
					currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					break;
				case 'linebreakb' :
				case 'linebreak' :
					groupstart = false;
					groupmiddle = false;
					groupend = false;
					this.buttonArea.addRow();
					this.buttonArea.addCell();
					this.buttonArea.addStyle({height:'3px'});
					currRowObj = null;
					break;
				default :
					var currButton = buttonInfo[idx];
					var buttonNo = currButton[2] + 120;
					var x = (buttonNo % 10) * 16;
					var y = Math.floor(buttonNo /10) * 16;
					var icon = null;
					var bindCommand = null;
					switch(idx) {
						case 'color':
							icon = new cafen.Div({attribute : {innerHTML : '&nbsp;'},style: {cssFloat : 'left',margin : iconMargin, fontSize : '1px', width:'12px', height:'10px', marginTop : '2px', marginRight : '15px', overflowX:'hidden', whiteSpace: 'nowrap', textAlign:'left'}});
							bindCommand = this.actionCommand.bind(this,idx,icon,'');
							break;
						default :
							icon = new cafen.XImage({className :'r_editorset',x: x,y : y}, {style:{cssFloat : 'left',margin : iconMargin, width:'16px', height:'16px'},attribute :{unselectable : 'on'}});
							bindCommand = (currButton[0] != null) ? this.execCommand.bind(this,currButton[0],'','') : this.actionCommand.bind(this,idx,'','');
							break;
					}
					var tmpButton = null;
					var baseBgPos = 0,baseSize =0 , basePadding = 0; 
					if (currButton[5] != null ) {
						if (currButton[5] > 60) {
							baseBgPos = 792;
							baseSize  = 100;
						} else if (currButton[5] > 30) {
							baseBgPos = 528;
							baseSize  = 56;
						} else {
							baseBgPos = 0;
							baseSize  = 33;
						}
						basePadding = 0;
					} else {
						baseBgPos = 264;
						baseSize  = 24;
						basePadding = 0;
					}
					if (icon != null) {
					var nextidx = (cnt -1 >= i +1) ? toolbarSet[i+1] : '';
					var tagButton = (bindCommand != null ) ? 'button' : 'div';
					var eventBind = (bindCommand == null ) ? {} : {click:bindCommand};
					if (!groupstart) {
						tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r_wordset', off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on'}, event :eventBind, childNodes : [icon]}) ;
						currRowObj.addCell(tmpButton);
						currRowObj.addStyle({width:baseSize +'px'});
						currRowObj.addCell();
						currRowObj.addStyle({width:'3px'});
						currRowObj.addText('<div style="width:3px;font-size:1px;line-height:1px;display:block;overflow:hidden;">&nbsp;</div>');
					} else {
						if (nextidx == 'group' || nextidx == 'break' || nextidx == ']'  || nextidx == ']' || nextidx == 'linebreak' || nextidx == 'linebreakb')
							groupend = true;
						if (!groupmiddle && groupend) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r_wordset', off : baseBgPos+198, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (!groupmiddle) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r_wordset', off : baseBgPos, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else if (groupend) {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r_wordset', off : baseBgPos+132, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						} else {
							tmpButton = new cafen.XIcon({tag : tagButton, icon : 'r_wordset', off : baseBgPos+66, on : 22 , over : 100, style :{width:baseSize +'px', paddingRight:  basePadding + 'px'}, attribute :{unselectable : 'on', title : currButton[1]}, event :eventBind, childNodes : [icon]}) ;
							currRowObj.addCell(tmpButton);
							currRowObj.addStyle({width:baseSize +'px'});
						}
						this.actionButton[idx] = {classObj : null, obj : tmpButton};
						if (currButton[4])
							this.statusButton.push({cmd : idx, obj : tmpButton});
						groupmiddle = true;
					}}
					break;
			}
		}	
	},
	execCommand : function(cmd, value1, value2, value3) {
		this._popupObj.closeChild();
		this._lastCommand = null;
		switch(cmd.toLowerCase()) {
			case 'line' :
			case 'bar_3d' :
			case 'area' :
			case 'bar' :
			case 'bar_glass' :
			case 'bar_cylinder' :
			case 'bar_round' :
			case 'bar_dome' :
			case 'bar_round3d' :
			case 'bar_cylinder_outline' :
			case 'bar_rounded_glass' :
				this.setCurrInfo('type', cmd.toLowerCase());
				break;
			case 'render' :
				this.preview();
				break;
			case '3dxyaxis' :
			case 'pie' :
			case 'radar' :
			case 'noaxis' :
			case 'xyaxis' :
				this.setAxisType(cmd.toLowerCase());
				break;
			case 'save' :
				this.sendValue();
				break;
			case 'color' :
				this.setCurrInfo('color', value1, value2, value3);
				break;
			case 'linestyle' :
				this.setCurrInfo('linestyle', value1, value2);
				break;
			case 'pointer' :
				this.setCurrInfo('pointer', value1, value2);
				break;
			default :
				alert(cmd +'exec');
				break;
		}
	},
	actionCommand : function(cmd, obj) {
		if (this._lastCommand == cmd)  {
			this._popupObj.closeChild();
			this._lastCommandObj = null;
			this._lastCommand = null;
		} else {		
			this._lastCommandObj = null;
			this._lastCommand = cmd;
			switch(cmd) {
				default :
					this._lastCommandObj = this.getActionObject(cmd,obj);
					break;
			}
			if (this._lastCommandObj != null) {
				this.showPopup(this._lastCommandObj);
			}
		}
		return true;
	},
	getActionObject : function(cmd) {
		if (this.actionButton[cmd].classObj != null)
			return this.actionButton[cmd].classObj;
		else {
			switch(cmd) {
				case 'color' :
					this.actionButton[cmd].classObj = new cafen.Editor.Chart.Color(this, {
						sticker : {obj : this.actionButton[cmd].obj, x : 'left', y : 'bottom', plus :[0,0]},
						linkButton : this.actionButton[cmd].obj,
						style : {}
						});
					break;
				case 'linestyle' :
					this.actionButton[cmd].classObj = new cafen.Editor.Chart.LineStyle(this, {
						sticker : {obj : this.actionButton[cmd].obj, x : 'left', y : 'bottom', plus :[0,0]},
						linkButton : this.actionButton[cmd].obj,
						style : {}
						});
					break;
				case 'pointer' :
					this.actionButton[cmd].classObj = new cafen.Editor.Chart.Pointer(this, {
						sticker : {obj : this.actionButton[cmd].obj, x : 'left', y : 'bottom', plus :[0,0]},
						linkButton : this.actionButton[cmd].obj,
						style : {}
						});
					break;
			}
			if (this.actionButton[cmd].classObj != null)
				this._popupObj.addChild(this.actionButton[cmd].classObj);
			return this.actionButton[cmd].classObj;
		}
	},
	showPopup : function(obj) {
		if (this._lastOpenChild == obj)
			this._popupObj.closeChild();
		else {
			if (obj != null)
				obj.onLoad();
		}
	},
	findFirstChild : function(obj) {
		var resultObj = null;
		for(var i = 0; i < obj.childNodes.length; i++) {
			if (	obj.childNodes[i].nodeType == 1) {
				if (	obj.childNodes[i].tagName == 'TBODY')
					return obj.childNodes[i];
				else if (	obj.childNodes[i].tagName == 'TR')
					return obj;
			}
		}
		return obj;
	},
	onPopup : function() {
		this.colorsetSeqn  = 0;
		var selectObj = this._editorObject.getSelectedElement();
		var tableObj = null;
		var parentObj = selectObj;
		while(parentObj) {
			if (parentObj.tagName == 'TABLE') {
				break;		
			} else
				parentObj = parentObj.parentNode;
		}
		if (parentObj != null) {
			this.lastTableObj = parentObj;
			this.chartData = [];
			var tBodyObj = this.findFirstChild(this.lastTableObj);
			for(var i = 0; i < tBodyObj.childNodes.length; i++) {
				var currTR = tBodyObj.childNodes[i];
				if (currTR.nodeType == 1) {
					var tmpData = [];
					for(var j = 0; j < currTR.childNodes.length; j++) {
						if (currTR.childNodes[j].nodeType == 1) {
							var tmpValue = (cafen.browser.isIE) ? currTR.childNodes[j].innerText : currTR.childNodes[j].innerHTML.replace(/<[^>]+>/g,''); 
							tmpData.push(tmpValue);
						}
					}
					if (tmpData.length > 1 && tmpData.join('').split(' ').join('') != '')
						this.chartData.push(tmpData);
				}
			}
		}
		this.setButtonDisable(['bar','bar_3d','bar_glass','bar_cylinder','bar_round','bar_dome','bar_round3d','bar_cylinder_outline','bar_rounded_glass'], false);
		this.render();
	},
	getAutoColorSet : function() {
		if (this.colorSet == null) {
			this.colorSet = [
				['#000000','#000000','#ffffff'],
				['#000080','#000064','#d7d7d7'],
				['#008000','#006400','#d7d7d7'],
				['#008080','#006464','#d7d7d7'],
				['#800000','#640000','#d7d7d7'],
				['#800080','#640064','#d7d7d7'],
				['#808000','#646400','#d7d7d7'],
				['#808080','#646464','#7f7f7f'],
				['#c0c0c0','#8b8b8b','#272727'],
				['#0000ff','#0000ff','#7f7f7f'],
				['#00ff00','#00ff00','#7f7f7f'],
				['#00ffff','#00ffff','#7f7f7f'],
				['#ff0000','#ff0000','#7f7f7f'],
				['#ff00ff','#ff00ff','#7f7f7f'],
				['#ffff00','#ffff00','#7f7f7f'],
				['#ffffff','#ffffff','#000000'],
				['#333333','#2e2e2e','#e3e3e3'],
				['#4c4c4c','#424242','#cacaca'],
				['#666666','#545454','#a9a9a9'],
				['#999999','#737373','#565656'],
				['#b3b3b3','#828282','#353535'],
				['#cccccc','#949494','#1c1c1c'],
				['#e6e6e6','#b3b3b3','#0a0a0a'],
				['#e6e6ff','#b3b3ff','#040404'],
				['#ff3366','#ff2e54','#565656'],
				['#dc2300','#a52000','#9c9c9c'],
				['#b84700','#853e00','#b6b6b6'],
				['#ff3333','#ff2e2e','#565656'],
				['#eb613d','#bc5136','#5e5e5e'],
				['#b84747','#853e3e','#7f7f7f'],
				['#b80047','#85003e','#b6b6b6'],
				['#99284c','#732542','#b0b0b0'],
				['#94006b','#700057','#cdcdcd'],
				['#94476b','#703e57','#9c9c9c'],
				['#944794','#703e70','#9c9c9c'],
				['#9966cc','#735494','#565656'],
				['#6b4794','#573e70','#9c9c9c'],
				['#6b2394','#572070','#b6b6b6'],
				['#6b0094','#570070','#cdcdcd'],
				['#5e11a6','#4f107b','#b6b6b6'],
				['#280099','#250073','#c9c9c9'],
				['#4700b8','#3e0085','#b6b6b6'],
				['#2300dc','#2000a5','#9c9c9c'],
				['#2323dc','#2020a5','#7f7f7f'],
				['#0047ff','#003eff','#7f7f7f'],
				['#0099ff','#0073ff','#7f7f7f'],
				['#00b8ff','#0085ff','#7f7f7f'],
				['#99ccff','#7394ff','#1c1c1c'],
				['#00dcff','#00a5ff','#7f7f7f'],
				['#00cccc','#009494','#a9a9a9'],
				['#23b8dc','#2085a5','#7f7f7f'],
				['#47b8b8','#3e8585','#7f7f7f'],
				['#33a3a3','#2e7979','#a1a1a1'],
				['#198a8a','#176a6a','#c3c3c3'],
				['#006b6b','#005757','#e1e1e1'],
				['#004a4a','#004040','#eeeeee'],
				['#355e00','#304f00','#e7e7e7'],
				['#5c8526','#4d6723','#bebebe'],
				['#7da647','#637b3e','#8e8e8e'],
				['#94bd5e','#70884f','#676767'],
				['#00ae00','#007f00','#bdbdbd'],
				['#33cc66','#2e9454','#7f7f7f'],
				['#3deb3d','#36bc36','#5e5e5e'],
				['#23ff23','#20ff20','#636363'],
				['#e6ff00','#b3ff00','#7f7f7f'],
				['#ffff99','#ffff73','#1c1c1c'],
				['#ffff66','#ffff54','#353535'],
				['#e6e64c','#b3b342','#565656'],
				['#cccc00','#949400','#a9a9a9'],
				['#b3b300','#828200','#b9b9b9'],
				['#808019','#646417','#c9c9c9'],
				['#666600','#545400','#e3e3e3'],
				['#4c1900','#421700','#ededed'],
				['#663300','#542e00','#e3e3e3'],
				['#804c19','#644217','#c9c9c9'],
				['#996633','#73542e','#a9a9a9'],
				['#cc6633','#94542e','#7f7f7f'],
				['#ff6633','#ff542e','#565656'],
				['#ff9966','#ff7354','#353535'],
				['#ffcc99','#ff9473','#1c1c1c'],
				['#9999ff','#7373ff','#1c1c1c'],
				['#993366','#732e54','#a9a9a9'],
				['#ffffcc','#ffff94','#0a0a0a'],
				['#ccffff','#94ffff','#0a0a0a'],
				['#660066','#540054','#e3e3e3'],
				['#ff8080','#ff6464','#272727'],
				['#0066cc','#005494','#a9a9a9'],
				['#333366','#2e2e54','#c9c9c9'],
				['#666699','#545473','#7f7f7f'],
				['#9999cc','#737394','#353535'],
				['#ccccff','#9494ff','#0a0a0a'],
				['#004586','#003c68','#d4d4d4'],
				['#ff420e','#ff3a0d','#737373'],
				['#ffd320','#ff9b1e','#646464'],
				['#579d1c','#4a751a','#b5b5b5'],
				['#7e0021','#63001f','#d8d8d8'],
				['#83caff','#6693ff','#262626'],
				['#314004','#2c3804','#f0f0f0'],
				['#aecf00','#7f9700','#a6a6a6'],
				['#4b1f6f','#411d5a','#d0d0d0'],
				['#ff950e','#ff710d','#737373'],
				['#c5000b','#8e000b','#adadad'],
				['#0084d1','#006799','#a4a4a4'],
				['#f4f4f4','#d0d0d0','#030303']
			];
		}
		this.colorsetSeqn ++;
		return this.colorSet[this.colorsetSeqn];
	},
	render : function() {
		this.chartArea.getElement().innerHTML = '';
		this.dummyTable = null;		
		if (this.chartData.length > 1) {
			this.dataArea.getElement().innerHTML = '';
			this.dataTable = new cafen.TableAuto({attribute : {cellPadding : 2, cellSpacing:3}, style : {cursor : cafen.getCursor(), width : '100%', backgroundColor:'#ffffff'}});
			this.chartTypes = {}
			this.dataTable.addRow();
			for(var i = 0; i < this.chartData[0].length; i++) {
				this.dataTable.addCell(this.chartData[0][i]);	
				this.dataTable.addStyle({padding:'3px', borderTop : '1px solid #aeaeae', borderBottom : '1px solid #aeaeae', borderLeft : '1px solid #aeaeae', textAlign:'center', fontWeight:'bolder'});
			}
			for(var i = 1; i < this.chartData.length; i++) {
				var subTrData = this.dataTable.addRow();
				subTrData.attachEvent("click",this.setCurrRow.bind(this,i));
				var tmpColor = this.getAutoColorSet();
				this.chartTypes[i] = {type : 'line', colour : tmpColor[0] , 'fill_colour' : tmpColor[1], linestyle : 'solid', linesize : 1, pointer : 's_box', pointersize : 4}
				for(var j = 0; j < this.chartData[i].length; j++) {
					this.dataTable.addCell(this.chartData[i][j]);
					if (j == 0)
						this.dataTable.addStyle({padding:'2px', border : '1px solid ' + tmpColor[1], color : tmpColor[2], backgroundColor : tmpColor[0]});
					else
						this.dataTable.addStyle({paddingLeft:'5px',paddingRight:'2px', borderLeft : '1px solid #aeaeae', borderBottom : '1px solid #aeaeae', textAlign:'right'});
				}
			}
			this.dataArea.appendChild(this.dataTable);
			this.setCurrRow(1, this.dataTable.childNodes[0].childNodes[1]);
			this.setAxisType(this._chartOption.axisType);
			this.preview();
		} else {
			this.dataArea.getElement().innerHTML = '<div align=center style="padding-top:20px;font-size:12px">'+cafenMsg.get('chart_error')+'</div>';	
			this.chartArea.getElement().innerHTML = '<div align=center>Example <hr>' +this.getSampleTxt() + '</div>';
		}
	},
	getSampleTxt : function() {
		var txt = [];
		txt.push('<table border=1>');
		txt.push('<tr height=20>');
		var dayname = cafenMsg.getObject('com_dayname');
		txt.push('<td>&nbsp;</td>');
		for(var i = 0; i < 	dayname.length; i++) 
			txt.push('<td width=20>'+dayname[i]+'</td>');
		txt.push('</tr>');
		var attachname = cafenMsg.getObject('com_filetypes');
		for(var idx in attachname) {
			txt.push('<tr height=20>');
			txt.push('<td>'+attachname[idx]+'</td>');
			for(var i = 0; i < 	dayname.length; i++) 
				txt.push('<td align=right>'+cafen.rand(0,20)+'</td>');
			txt.push('</tr>');
		}
		return txt.join('');		
	},
	preview : function() {
		if (this.chartData.length > 0) {
			if (this.dummyTable != null) {
				if (	this.dummyTable.getElement().chartObj != null) 
					this.dummyTable.getElement().chartObj.remove();
				this.chartArea.getElement().innerHTML = '';
				this.dummyTable = null;		
			}
			this.dummyTable = new cafen.TableAuto({style:{display:'none'}});
			switch(this._chartOption.axisType) {
				case 'pie' :
				case 'radar' :
					this.dummyTable.setAttribute({'width': Math.round(this._chartOption.width*0.8), 'height' : Math.round(this._chartOption.width*0.8), 'bg_color' : '#FFFFFF'});
					break;
				default :
					this.dummyTable.setAttribute({'width': this._chartOption.width, 'height' : this._chartOption.height, 'bg_color' : '#FFFFFF'});
					break;
			}
			var axisTr = this.dummyTable.addRow();
			if (this._chartOption.axisType == 'pie') {
				axisTr.setAttribute({'type_ofc': 'pie', 'size' : '11', font_colour : '#000000',  gradient_fill : 'true', animate:'5'})
				this.dummyTable.addCell('');	
				for(var i = 1; i < this.chartData.length; i++) {
					var sum_val = 0;
					for(var j = 1; j < this.chartData[i].length; j++) {
						var tmp_val = parseFloat(this.chartData[i][j]);
						sum_val += (isNaN(tmp_val)) ? 0 : tmp_val;
					}
					this.dummyTable.addCell(sum_val + ',' + this.chartData[i][0] +',' + this.chartTypes[i].colour);	
				}
			} else {
				for(var i = 0; i < this.chartData[0].length; i++)
					this.dummyTable.addCell(this.chartData[0][i]);	
				var minValue = 100;
				var maxValue = 0;
				var line_loop = false;
				switch(this._chartOption.axisType) {
					case 'radar' :
						line_loop = true;
						break;
				}			
				for(var i = 1; i < this.chartData.length; i++) {
					var subTr = this.dummyTable.addRow();
					switch(this.chartTypes[i].type) {
						case 'line' :
							subTr.setAttribute({'type_ofc': 'line', 'colour' : this.chartTypes[i].colour , 'font_size' : 12})
							break;
						case 'area' :
							subTr.setAttribute({'type_ofc': this.chartTypes[i].type, 'colour' : this.chartTypes[i].colour, 'fill_colour' : this.chartTypes[i].fill_colour, 'fill_alpha' : 0.7, 'font_size' : 12})
							break;
						case 'bar_3d' :
						case 'bar' :
						case 'bar_glass' :
						case 'bar_cylinder' :
						case 'bar_round' :
						case 'bar_dome' :
						case 'bar_round3d' :
						case 'bar_cylinder_outline' :
						case 'bar_rounded_glass' :
							if (line_loop)
								subTr.setAttribute({'type_ofc': 'area', 'colour' : this.chartTypes[i].colour, 'fill_colour' : this.chartTypes[i].fill_colour, 'fill_alpha' : 0.7, 'font_size' : 12})
							else
								subTr.setAttribute({'type_ofc': this.chartTypes[i].type, 'colour' : this.chartTypes[i].colour, 'fill_colour' : this.chartTypes[i].fill_colour, 'fill_alpha' : 0.7, 'font_size' : 12})
							break;
						default :
							subTr.setAttribute({'type_ofc': 'line', 'colour' : this.chartTypes[i].colour, 'font_size' : 12})
							break;
					}
					switch(this.chartTypes[i].linestyle) {
						case 'dot' :
						case 'dashed' :
						case 'dotted' :
							subTr.setAttribute({line: this.chartTypes[i].linestyle, stroke :this.chartTypes[i].linesize});
							break;						
					}
					switch(this.chartTypes[i].pointer) {
						case 'hollow_dot' :
						case 'star' :
						case 'bow' :
						case 'anchor' :
						case 's_box' :
							subTr.setAttribute({pointer: this.chartTypes[i].pointer, pointersize :this.chartTypes[i].pointersize});
							break;						
					}
					if (line_loop)
						subTr.setAttribute({'loop': 'true'})
					for(var j = 0; j < this.chartData[i].length; j++) {
						this.dummyTable.addCell(this.chartData[i][j]);
						if (j > 0) {
							var curValue = parseFloat(this.chartData[i][j]);
							minValue = Math.min(minValue, curValue);
							maxValue = Math.max(maxValue, curValue);
						}
					}
				}
				var step = 1;
				if (minValue > 0)
					minValue = 0;
				if (	maxValue > 5)
					maxValue = Math.round(minValue + (maxValue - minValue ) * 1.2);
				if (maxValue - minValue > 6)
					step = Math.round((maxValue - minValue ) / 6);
				else
					step = ((maxValue - minValue ) / 6).toFixed(1);
				switch(this._chartOption.axisType) {
					case 'pie' :
						break;
					case 'radar' :
						axisTr.setAttribute({'type_ofc': 'radar_axis', 'colour' : '#8c8c8c', 'grid_colour' : '#d5d5d5', 'd3' : 5, 'stroke' : 1, 'min' : minValue, 'max' : maxValue, 'step' : step, 'size' : '11', font_colour : '#000000', autolabel : 'true'})
						break;
					case '3dxyaxis' :
						axisTr.setAttribute({'type_ofc': 'xy_axis', 'colour' : '#8c8c8c', 'grid_colour' : '#d5d5d5', 'd3' : 5, 'stroke' : 1, 'min' : minValue, 'max' : maxValue , 'step' : step, 'size' : '11', font_colour : '#000000'})
						break;
					case 'noaxis' :
						axisTr.setAttribute({'type_ofc': 'xy_axis', 'colour' : '#8c8c8c', 'grid_colour' : '#ffffff', 'stroke' : 1, 'min' : minValue, 'max' : maxValue , 'step' : step, 'size' : '11', font_colour : '#000000'})
						break;
					default :
						axisTr.setAttribute({'type_ofc': 'xy_axis', 'colour' : '#8c8c8c', 'grid_colour' : '#d5d5d5', 'stroke' : 1, 'min' : minValue, 'max' : maxValue , 'step' : step, 'size' : '11', font_colour : '#000000'})
						break;
				}
			}
			this.chartArea.appendChild(this.dummyTable);
			if (this.chartObj == null)
				this.chartObj = new cafenOFC2JS();
			this.chartObj.renderElement(this.dummyTable.getElement());
			this.setButtonDisable(['save'], false);
		} 
	},
	setCurrInfo : function(name, value1, value2, value3) {
		if (this._lastRowNo != null) {
			switch(name) {
				case 'color' :
					if (this.chartTypes[this._lastRowNo].colour != value1 || this.chartTypes[this._lastRowNo].fill_colour != value2)
						this.setButtonDisable(['save'], true);
					this.chartTypes[this._lastRowNo].colour = value1;
					this.chartTypes[this._lastRowNo].fill_colour = value2;
					this._lastRowObj.childNodes[0].setStyle({backgroundColor: value1, color : value3});
					break;
				case 'linestyle' :
					if (this.chartTypes[this._lastRowNo].linestyle != value1 || this.chartTypes[this._lastRowNo].linesize != value2)
						this.setButtonDisable(['save'], true);
					this.chartTypes[this._lastRowNo].linestyle = value1;
					this.chartTypes[this._lastRowNo].linesize = value2;
					break;
				case 'pointer' :
					if (this.chartTypes[this._lastRowNo].pointer != value1 || this.chartTypes[this._lastRowNo].pointersize != value2)
						this.setButtonDisable(['save'], true);
					this.chartTypes[this._lastRowNo].pointer = value1;
					this.chartTypes[this._lastRowNo].pointersize = value2;
				default :
					if (this.chartTypes[this._lastRowNo][name] != value1)
						this.setButtonDisable(['save'], true);
					this.chartTypes[this._lastRowNo][name] = value1;
					break;
			}
			this.setCurrRow();
		}
	},
	setCurrRow : function(no, obj) {
		if (no != null && obj != null) {
			this._lastRowNo = no;
			if (this._lastRowObj != null)
				this._lastRowObj.setStyle({backgroundColor:'transparent'});
			obj.setStyle({backgroundColor:'#e7e7e7'});
			this._lastRowObj = obj;
		} else if (this._lastRowNo == null)
			return ;
		var typeButtons = ['line','area','bar','bar_3d','bar_glass','bar_cylinder','bar_round','bar_dome','bar_round3d','bar_cylinder_outline','bar_rounded_glass'];
		var currType = this.chartTypes[this._lastRowNo].type;
		for(var i = 0; i < typeButtons.length; i++) {
			var currName = typeButtons[i];
			if (this.actionButton[currName] != null) {
				if (currName == currType)
					this.actionButton[currName].obj.setSelected(true);
				else
					this.actionButton[currName].obj.setSelected(false);
			}
		}
		this.actionButton['color'].obj.childNodes[0].setStyle({border : '1px solid '+this.chartTypes[this._lastRowNo].colour +'' , backgroundColor:this.chartTypes[this._lastRowNo].fill_colour});
		var x = 0;
		switch(this.chartTypes[this._lastRowNo].pointer) {
			case 'hollow_dot' :
				x = 16;
				break;
			case 'bow' :
				x = 32;
				break;
			case 's_box' :
				x = 48;
				break;
			case 'star' :
				x = 64;
				break;
		}
		this.actionButton['pointer'].obj.childNodes[0].setStyle({backgroundPosition: '-'+x+'px -224px'});
		switch(this.chartTypes[this._lastRowNo].linestyle) {
			case 'solid' :
				x = 80;
				break;
			case 'dot' :
				x = 96;
				break;
			case 'dashed' :
				x = 112;
				break;
			case 'dotted' :
				x = 128;
				break;
		}		
		this.actionButton['linestyle'].obj.childNodes[0].setStyle({backgroundPosition: '-'+x+'px -224px'});
	},
	setAxisType : function(currType) {
		var typeButtons = ['radar','xyaxis','noaxis','3dxyaxis','pie'];
		if (this._chartOption.axisType != currType)
			this.setButtonDisable(['save'], true);
		this._chartOption.axisType = currType;
		for(var i = 0; i < typeButtons.length; i++) {
			var currName = typeButtons[i];
			if (this.actionButton[currName] != null) {
				if (currName == currType)
					this.actionButton[currName].obj.setSelected(true);
				else
					this.actionButton[currName].obj.setSelected(false);
			}
		}
		switch(this._chartOption.axisType) {
			case 'pie' :
			case 'radar' :
				this.setButtonDisable(['bar','bar_3d','bar_glass','bar_cylinder','bar_round','bar_dome','bar_round3d','bar_cylinder_outline','bar_rounded_glass'], true);
				break;
			case 'xyaxis' :
			case 'noaxis' :
			case '3dxyaxis' :
				this.setButtonDisable(['bar','bar_3d','bar_glass','bar_cylinder','bar_round','bar_dome','bar_round3d','bar_cylinder_outline','bar_rounded_glass'], false);
				break;
		}
	},
	setButtonDisable : function(idxs, bl) {
		for(var i = 0 ; i < idxs.length; i++) {
			var currName = idxs[i];
			if (this.actionButton[currName] != null) 
				this.actionButton[currName].obj.setDisable(bl);
		}
	},
	checkLastImage : function() {
		cafen.smallSWFAjax.getFlashXml({mode:'INFO', name : this.lastImgName}, this.checkLastImageEnd.bind(this),  this._uploadScript, false);
	},
	checkLastImageEnd : function(xml) {
		try {
			var rssObj = new cafen.xmlParser(xml);
			var contentsObj = null;
			var fileObj = {};
			if (contentsObj = rssObj.getNext()) {
				var item = null;
				while(item = contentsObj.getNext()) {
					fileObj = {
						fileName : item.getNode('filename'),
						extension : item.getNode('fileext'),
						server : item.getNode('fileserver'),
						size : parseInt(item.getNode('filesize')),
						html_tag : ''
					}
				}
			}
			if (fileObj.server != null) {
				fileObj.html_tag = '<img src='+this._uploadUrl+fileObj.server+' align=center>';
				if (this._editorObject.execCommand('attach',true,fileObj, this.lastTableObj)) {
					this.close();
				} else {
					this.showMsg(cafenMsg.get('ed_0019', cafen.getSize2Short(this._editorObject.editorAttachView.attachSize,2), cafen.getSize2Short(this._editorObject.editorAttachView.maxUpload,2), cafen.getSize2Short(fileObj.size,2)), true);
				}
			} else
				this.close();
		} catch(ex) {
			this.close();
		}
	},
	sendValue : function() {
		if (this.dummyTable != null && this.dummyTable.getElement().chartObj != null) {
			this.lastImgName = 'junk/' +cafen.getUniqID('ofc_')+'.png';
			this.dummyTable.getElement().chartObj.saveImage(this.lastImgName, this._uploadScript);
			this.error_cnt = 0;
			this.checkChartImgError();
		}
	},
	checkChartImgError : function() {
		window.setTimeout(this.checkChartImg.bind(this), 200);
	},
	checkChartImg : function() {
		if (this.error_cnt <= 50) {
			var tmpImg = new Image();
			tmpImg.onerror = this.checkChartImgError.bind(this);
			tmpImg.onload = this.checkLastImage.bind(this);
			tmpImg.src = this._uploadUrl + this.lastImgName + "?" +this.error_cnt;
			this.error_cnt ++;
		} else
			this.showMsg('error Save Chart!!!');
	},
	showMsg : function(msg) {
		if (this.msgObj == null) {
			this.msgObj = new cafen.XAlert({title :cafenMsg.get('com_alert'), contents :'', sticker : {obj : this, x : 'center', y : 'middle'}, style : {width: '300px'}});
			this.addChild(this.msgObj);
		}
		this.msgObj.setContents(msg, {x : 'center', y : 'middle', plus : [0, 5]});
		this.msgObj.onLoad();
	}
},cafen.XWindow.prototype);


cafen.Editor.Chart.Color = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :'r_boxwhite', tag : 'div', style : { textAlign:'center'}, shadow : true}, options));
	this.initDivBlock();
}

cafen.Editor.Chart.Color.prototype = cafen.extendClass({
	initDivBlock : function() {
		this.colorset = [];
		this.colorInfo = this._editorObject.colorSet;
		var tmp = new cafen.TableAuto({attribute:{border :0, cellpadding : 1, cellspacing:1, width : 168}, style :{cursor : cafen.getCursor(),  width : '168px'}});
		for(var i = 0; i < this.colorInfo.length; i++) {
			var currColor = this.colorInfo[i];
			if (i % 12 == 0)
				tmp.addRow();
			tmp.addCell('&nbsp;').attachEvent('click', this.sendValue.bind(this,i));
			tmp.addStyle({fontSize : '2px',width:'12px', height:'12px', backgroundColor : currColor[0], border : '1px solid '+currColor[1]});
		}
		this.appendChild(tmp);
	},
	sendValue : function(idx) {
		var currColor = this.colorInfo[idx];
		if (currColor != null) 
			this._editorObject.execCommand('color', currColor[0], currColor[1], currColor[2]);
	},
	onPopup : function() {

	}
},cafen.XWindow.prototype);

cafen.Editor.Chart.LineStyle = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :'r_boxwhite', tag : 'div', style : { textAlign:'center'}, shadow : true}, options));
	this.initDivBlock();
}

cafen.Editor.Chart.LineStyle.prototype = cafen.extendClass({
	initDivBlock : function() {
		this.colorset = [];
		var colorInfo = [
			{no : 80, text : 'solid', value : 'solid'},
			{no : 96, text : 'dot', value : 'dot'},
			{no : 112, text : 'dashed', value : 'dashed'},
			{no : 128, text : 'dotted', value : 'dotted'}
		];
		var colorset = [];
		for(var j =1; j < 5; j++) {
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push({no : obj.no, text : obj.text, value : obj.value, size : j});
			}
		}
		this.colorset = colorset ;
		var divMenu = [];
		for(var i = 0; i < this.colorset.length; i++) {
			var currObj = this.colorset[i];
			divMenu.push({text : currObj.size+'px',options : i, icon : {className :'r_editorset',x: currObj.no ,y : 224}});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(divMenu, 80, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : 'r_tbtnskin'});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		var currColor = this.colorset[obj.options.itemOptions];
		this._editorObject.execCommand('linestyle', currColor.value, currColor.size);
	},
	onPopup : function() {

	}
},cafen.XWindow.prototype);

cafen.Editor.Chart.Pointer = function(editorObj, options) {
	this._editorObject = editorObj;
	this.initOptions(cafen.extend({className :'r_boxwhite', tag : 'div', style : { textAlign:'center'}, shadow : true}, options));
	this.initDivBlock();
}

cafen.Editor.Chart.Pointer.prototype = cafen.extendClass({
	initDivBlock : function() {
		this.colorset = [];
		var colorInfo = [
			{no : 16, text : 'dot', value : 'hollow_dot'},
			{no : 32, text : 'bow', value : 'bow'},
			{no : 48, text : 'box', value : 's_box'},
			{no : 64, text : 'star', value : 'star'}
		];
		var colorset = [];
		colorset.push({no : 0, text : 'none', value : '', size : 0});
		for(var j =1; j < 5; j++) {
			for(var i = 0; i < colorInfo.length; i++) {
				var obj = colorInfo[i];
				colorset.push({no : obj.no, text : obj.text, value : obj.value, size : j*2});
			}
		}
		this.colorset = colorset ;
		var divMenu = [];
		for(var i = 0; i < this.colorset.length; i++) {
			var currObj = this.colorset[i];
			divMenu.push({text : (currObj.size > 0) ? currObj.size+'px' : 'none',options : i, icon : {className :'r_editorset',x: currObj.no ,y : 224}});
		}
		var cmdBind = this.sendValue.bind(this);
		this.xMenu = new cafen.XMenu(divMenu, 80, {event :{select : cmdBind}, style : {overflowX : 'hidden', overflowY : 'auto', height:'200px'}, buttonClass : 'r_tbtnskin'});
		this.appendChild(this.xMenu);
	},
	sendValue : function(parent, obj) {
		var currColor = this.colorset[obj.options.itemOptions];
		this._editorObject.execCommand('pointer', currColor.value, currColor.size);
	},
	onPopup : function() {

	}
},cafen.XWindow.prototype);

cafen.Editor.Helper = function(editorObject, options) {
	this._editorObject = editorObject;
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r_popskin', tag : 'div', tplName : 'top', donotresize : true, style : {width:'270px',textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('ed_help'));
	this.setToolBar();
	this.contentsObj = new cafen.Div({style : {margin :'0px', padding:'2px', textAlign:'left'}});
	this.setObject(this.contentsObj);
	this.drawContents();
};

cafen.Editor.Helper.prototype = cafen.extendClass({
	drawContents : function() {
		this.lastShownObj = null;
		var tabObj = cafenMsg.getObject('ed_helpmenu');
		this._infoTab = [];
		this._infoTabObj = {}
		this._contentsObj = {}
		for(var idx in tabObj) {
			var text = tabObj[idx];
			this._infoTabObj[idx] = new cafen.XTab({ text : text ,style : {},attribute : {}, event : {click: this.selectTab.bind(this,idx)}});
			this._infoTab.push(this._infoTabObj[idx]); 
		}
		this._infoTabMenu = new cafen.XTabMenu(this._infoTab);
		this.contentsObj.appendChild(this._infoTabMenu);

		this.showContentsObj = new cafen.Div({className :'r_btnskin',attribute:{}, style : {width:'260px', height: '150px', overflowY : 'auto', overflowX : 'hidden'}});
		this.contentsObj.appendChild(this.showContentsObj);

		var baseTbl =  this.showContentsObj.appendChild(new cafen.TableAuto({attribute:{cellPadding: '0', cellSpacing : '0', width : '100%'}, style : {'display' : 'none', width:'100%'}}));
		this._contentsObj['bg'] = baseTbl;
		var colorSet = this._editorObject.keyColorSet;
		var seqn = 0;
		for(var idx in colorSet) {
			var currColor = colorSet[idx].toUpperCase();
			var trObj = baseTbl.addRow();
			if (seqn % 2 == 0)
				trObj.setStyle({backgroundColor:'#ffffff'});
			seqn ++;
			baseTbl.addCell('<div style="width:16px;height:16px;background-color:'+currColor+';border:1px solid #d0d0d0">&nbsp;</div>');
			baseTbl.addStyle({fontSize : '13px', width:'20px', padding:'3px'});
			var shortKey = 'Ctrl + (Shift) + '+String.fromCharCode(idx) +' ('+currColor+')';
			baseTbl.addCell(shortKey);
			baseTbl.addStyle({fontSize : '13px', padding:'3px', lineHeight:'100%', textAlign:'left'});
		}
		var baseTbl =  this.showContentsObj.appendChild(new cafen.TableAuto({attribute:{cellPadding: '0', cellSpacing : '0', width : '100%'}, style : {'display' : 'none', width:'100%'}}));
		this._contentsObj['specialchar'] = baseTbl;
		var charSetData = this._editorObject.keyMapSpecalChar.split('');
		var seqn = 0;
		for(var i = 0  ; i < charSetData.length; i++) {
			var currChar = charSetData[i];
			if (currChar != null && currChar != ' ') {
				var trObj = baseTbl.addRow();
				if (seqn % 2 == 0)
					trObj.setStyle({backgroundColor:'#ffffff'});
				seqn ++;
				baseTbl.addCell(currChar);
				baseTbl.addStyle({fontSize : '13px', width:'20px', padding:'3px', lineHeight:'100%'});
				var shortKey = (i > 42) ? 'Ctrl + Alt + Shift + '+String.fromCharCode(i + 5) :  'Ctrl + Alt + '+String.fromCharCode(i+48);
				baseTbl.addCell(shortKey);
				baseTbl.addStyle({fontSize : '13px', padding:'3px', lineHeight:'100%', textAlign:'left'});
			}
		}		

		var baseTbl =  this.showContentsObj.appendChild(new cafen.TableAuto({attribute:{cellPadding: '0', cellSpacing : '0', width : '100%'}, style : {'display' : 'none', width:'100%'}}));
		this._contentsObj['button'] = baseTbl;

		var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
		var seqn = 0;
		for(var idx in buttonInfo) {
			var currButton = buttonInfo[idx];
			var iconNo = currButton[2];
			if (iconNo > 0) {
				var trObj = baseTbl.addRow();
				if (seqn % 2 == 0)
					trObj.setStyle({backgroundColor:'#ffffff'});
				seqn ++;
				var x =  (iconNo % 10) * 16;
				var y =  Math.floor(iconNo / 10) * 16;
				var icon = new cafen.XImage({className :'r_editorset',x: x,y : y}, {style:{cssFloat : 'left', width:'16px', height:'16px'},attribute :{unselectable : 'on'}});
				baseTbl.addCell(icon);
				baseTbl.addStyle({fontSize : '13px', width:'20px', padding:'3px'});
				var controlKey = currButton[1];
				if (this._editorObject.keyMapShortCut[idx] != null) {
					if (this._editorObject.keyMapShortCut[idx][1] != null)
						controlKey += ' (' +this._editorObject.keyMapShortCut[idx][1] +')';
					if (this._editorObject.keyMapShortCut[idx][0] != null)
						controlKey += ' (Alt + ' +this._editorObject.keyMapShortCut[idx][0]+')';
				}
				baseTbl.addCell(controlKey);
				baseTbl.addStyle({fontSize : '13px', padding:'3px', lineHeight:'100%', textAlign:'left'});
			}
		}
		this.selectTab('button');
		this.getElement().style['position'] = 'relative';
	},
	selectTab : function(idx, obj) {
		if (obj == null)
			obj = this._infoTabObj[idx];
		this._infoTabMenu.setSelected(obj);
		if (this.lastShownObj != null)
			this.lastShownObj.hide();
		if (	this._contentsObj[idx] != null) {
			this.lastShownObj = this._contentsObj[idx];
			this.lastShownObj.show();
		}
		this.showContentsObj.onChange({scrollTop : 0}); 
	},
	onClose : function() {
		this._editorObject.closePopup();
	}
},cafen.XWindow.prototype);

cafen.Editor.DataBase = function(editorObject, options) {
	this._editorObject = editorObject;
	this._popupOptions = options;
	this.setOptions(cafen.extend({className :'r_popskin', tag : 'div', tplName : 'both', donotresize : true, style : {width:'490px',textAlign:'center', position :'absolute'}, shadow : true}, options));
	this.setTitle(cafenMsg.get('ed_0134'));
	this.setToolBar();
	this.contentsObj = new cafen.Div({style : {margin :'0px', padding:'2px', textAlign:'left'}});
	this.setObject(this.contentsObj);
	this.drawMenu();
};

cafen.Editor.DataBase.prototype = cafen.extendClass({
	keyword : null,
	_underprocess : false,
	tabShortKey : {
			'map' : 'M',
			'news' : 'N',
			'image' : 'P',
			'vclip' : 'V',
			'webkr' : 'W',
			'kin' : 'K'
	},
	drawMenu : function() {
		this._underprocess = false;
		if (this.showContentsObj == null) {
			var topSearchTbl = new cafen.TableAuto({attribute:{cellPadding: '0'}});
			this.contentsObj.appendChild(topSearchTbl);
			this.inputObj = new cafen.XInput({style:{width:'150px'}, shortkey : 'I', event :{end : this.setInputKeyword.bind(this)}});
			var searchButton = new cafen.XButton({text : cafenMsg.get('com_ok'), shortkey : 'S', style:{marginLeft:'3px'}, event :{click : this.setInputKeyword.bind(this)}});
			topSearchTbl.addCell(this.inputObj);
			topSearchTbl.addCell(searchButton);
			this.inputObj.setNextObject(searchButton);
			var tabObj = cafenMsg.getObject('util_openapi');
			this._infoTab = [];
			this._infoTabObj = {}
			this.webDatas = {inputkeyword: null};
			var tmpMenus = [];
			for(var idx in tabObj) {
				var text = tabObj[idx];
				this._infoTabObj[idx] = new cafen.XTab({ text : text , shortkey : this.tabShortKey[idx], style : {},attribute : {}, event : {click: this.selectTab.bind(this,idx)}});
				this._infoTab.push(this._infoTabObj[idx]); 
				tmpMenus.push(idx);
			}
			this._infoTabMenu = new cafen.XTabMenu(this._infoTab);
			this.contentsObj.appendChild(this._infoTabMenu);
			this.getElement().style['position'] = 'relative';
			this.showContentsObj = new cafen.Div({className :'r_btnskin',attribute:{}, style : {width:'490px', height: '150px', overflowY : 'auto'}});
			this.contentsObj.appendChild(this.showContentsObj);
			var poserbyObj = new cafen.Div({attribute:{innerHTML : '<a href="http://naver.com" target=_blank><img src="'+_cafen_service_url+'images/ico_pwbynaver.gif" border=0  align=absmiddle hspace=2></a>&nbsp;<a href="http://daum.net" target=_blank><img src="'+_cafen_service_url+'images/ico_pwbydaum.gif" border=0 align=absmiddle hspace=2></a>&nbsp;<a href="http://google.com" target=_blank><img src="'+_cafen_service_url+'images/ico_pwbygoogle.gif" border=0 align=absmiddle hspace=2></a>'}, style : {textAlign:'right',width:'485px', marginTop:'3px'}});
			this.appendChild(poserbyObj,'bottom');
			this.lastShownIdx = tmpMenus[cafen.rand(0,tmpMenus.length-1)];
		}
	},
	setKeywordTxt : function(txt) {
		if (txt == null || txt == '' || txt == 'null') 
			txt = "";
		else {
			txt = txt.split('\r').join('').split('\n').join(' ');
		}
		if (txt != null && txt != '' && txt != 'null') {
			if (this.webDatas == null || this.keyword == null || this.keyword != txt)
				this.webDatas = {};
			this.keyword = txt;
			this.inputObj.setValue(txt);
		}
		this.selectTab(this.lastShownIdx);
	},
	setInputKeyword : function() {
		var txt = this.inputObj.getValue();
		if (txt == null || txt == '' || txt == 'null') 
			txt = "";
		else {
			txt = txt.split('\r').join('').split('\n').join(' ');
		}
		if (txt.split(' ').join('') == '')
			this.inputObj.setError();
		else 
			this.setKeywordTxt(txt);
	},
	selectTab : function(idx, obj) {
		if (this._underprocess)
			return ;
		if (obj == null)
			obj = this._infoTabObj[idx];
		this._infoTabMenu.setSelected(obj);
		if (this.lastShownObj != null)
			this.lastShownObj.hide();
		if (this.webDatas[idx] == null) {
			if (this.keyword == null || this.keyword == '') {
				this.inputObj.setError();
				this.showInputKeyword(true);
			} else {
				this.getKeywordData(idx);
			}
		} else {
			this.webDatas[idx].show();
			this.lastShownObj = this.webDatas[idx];
		}
		this.lastShownIdx = idx;
		this.showContentsObj.onChange({scrollTop : 0});
	},
	showProcess : function(bl) {
		if (bl) {
			this._underprocess = true;
			if (this._processObj == null) {
				this._processObj = new cafen.Div({attribute : {innerHTML : '<img src="'+_cafen_service_url+'images/blank.gif" class="r-process">' + cafenMsg.get('com_process')}, style:{textAlign:'center', marginTop:'30px'}});
				this.showContentsObj.appendChild(this._processObj);
			} else
				this._processObj.show();
		} else {
			if (this._processObj != null && this._underprocess) 
				this._processObj.hide();
			this._underprocess = false;
		}
		this.showInputKeyword(false);
	},
	showInputKeyword : function(bl) {
		if (bl) {
			if (this._underprocess) 
				this.showProcess(false);
			this._underinputkeyword = true;
			if (this._inputkeywordObj == null) {
				this._inputkeywordObj = new cafen.Div({attribute : {innerHTML : cafenMsg.get('ed_0130')}, style:{textAlign:'center', marginTop:'30px'}});
				this.showContentsObj.appendChild(this._inputkeywordObj);
			} else
				this._inputkeywordObj.show();
		} else {
			if (this._inputkeywordObj != null && this._underinputkeyword) 
				this._inputkeywordObj.hide();
			this._underinputkeyword = false;
		}
	},
	setNullApiKey : function() {
		var tmpTbl= new cafen.TableAuto({attribute :{width :'420', cellPadding:2, cellSpacing : 2, border : 0}});
			tmpTbl.addRow();
			tmpTbl.addCell();
			tmpTbl.addCell('<u>'+this.keyword +'</u><hr>' +cafenMsg.get('com_nullkey'));
		this.webDatas[this.lastDataIdx] = tmpTbl;
		this.showContentsObj.appendChild(tmpTbl);
		this.selectTab(this.lastDataIdx);
	},
	getKeywordData : function(idx) {
		if (this._underprocess)
			return ;
		else 
			this.showProcess(true);
		this.lastDataIdx = idx;
		switch(idx) {
			case 'map' :
				if (cafen.checkAPI('GMap')) {
					var param = {
						q: this.keyword,
						output : 'json',
						oe:'utf8',
						hl : cafenMsg.get('com_hl'),
						sensor:'false',
						key: cafen.getAPI('GMap')
					};
					cafen.smallSWFAjax.getFlashXml(param,this.setKeywordData.bind(this),'http://maps.google.com/maps/geo', true);	
				} else
					this.setNullApiKey();
				break;
			case 'vclip' :
				if (cafen.checkAPI('DAUM')) {
					var param = {
						q : this.keyword,
						pageno :1,
						result  : 10,
						output : 'rss',
						apikey : cafen.getAPI('DAUM')
					};
					cafen.smallSWFAjax.getFlashXml(param,this.setKeywordData.bind(this),'http://apis.daum.net/search/' + idx, false);
				} else
					this.setNullApiKey();
				break;
			case 'image' :
			case 'webkr' :
			case 'video' :
			case 'news' :
			case 'kin' :
				if (cafen.checkAPI('NAVER')) {
					var param = {
						query : this.keyword,
						target : idx,
						start:1,
						display : 10,
						key: cafen.getAPI('NAVER')
					};
					cafen.smallSWFAjax.getFlashXml(param,this.setKeywordData.bind(this),'http://openapi.naver.com/search', false);	
				} else
					this.setNullApiKey();
				break;	
		}
	},
	onPopup : function() {
		var str = this._editorObject.getSelectedHTML();
		if (str != null && str != 'null') {
			str = cafen.stripTags(str).replace('&nbsp;','');
			if (str.length > 10) {
				var keywords = [];
				var strArr = str.split(' ');	
				str = '';
				for(var i = 0; i < strArr.length; i++) {
					if (	strArr[i] != '') {
						str += strArr[i] + ' ';
						if (str.length > 10)
							break;
					}
				}
			}
			str = str.replace(' ','');
		}
		this.setKeywordTxt(str || '');
	},
	setKeywordData : function(txt) {
		this.showProcess(false);
		var titleStyle = 'white-space:nowrap;width:420px;overflow:hidden;cursor:pointer;margin:3px 3px';
		switch(this.lastDataIdx) {
			case 'map' :
				var json = cafen.getString2Json(txt);
				var tmpTbl= new cafen.TableAuto({attribute :{width :'420', cellPadding:2, cellSpacing : 2, border : 0}});
				tmpTbl.addRow();
				tmpTbl.addCell();
				tmpTbl.addStyle({width:'20px'});
				tmpTbl.addCell();
				tmpTbl.addStyle({width:'400px'});
				var datas_cnt = 0;
				if (json.Status) {
					if (json.Status.code == 200 && json.Placemark)  {
						var addHtmlBind = this.showMap.bind(this);
						if (json.Placemark.length > 0) {
							for(var i = 0; i< json.Placemark.length; i++) {
								var Lon = json.Placemark[i].Point.coordinates[0];
								var Lat = json.Placemark[i].Point.coordinates[1];
								var Address = json.Placemark[i].address.replace('\uB300\uD55C\uBBFC\uAD6D','');
								var currData = {
									title : Address, 
									lat : Lat, 
									lon : Lon, 
									playerurl : ''
								}
								tmpTbl.addRow();
								tmpTbl.addCell(new cafen.XIcon({icon:'r_mapset', off :288, on : 0,  over :16, style:{width: '16px', height:'16px'}, event : {click: addHtmlBind}, datas : currData}));
								var tmpCell = tmpTbl.addCell('<div style="'+titleStyle+'" title="'+currData.title+'">'+currData.title+'</div>');
								tmpTbl.addStyle({borderLeft:'1px dotted #d0d0d0', borderBottom:'1px dotted #d0d0d0'});
								tmpCell.attachEvent('click', this.previewMap.bind(this, {lat : Lat, lon : Lon}));
								tmpTbl.addRow();
								tmpTbl.addCell('&nbsp;');
								tmpTbl.addCell('Latitude :<u>' + Lat + '</u>, Longitude : <u>'+ Lon+'</u>');
								tmpTbl.addStyle({paddingBottom:'5px', lineHeight:'120%',wordBreak:'break-all', wordWrap:'break-word', textAlign:'left'});
								datas_cnt ++;
							}
						}
					} 
				}
				if (datas_cnt ==0) {
					tmpTbl.addRow();
					tmpTbl.addCell();
					tmpTbl.addCell('<u>'+this.keyword +'</u><hr>' +cafenMsg.get('map_0036'));
				}
				this.webDatas[this.lastDataIdx] = tmpTbl;
				this.showContentsObj.appendChild(tmpTbl);
				this.selectTab(this.lastDataIdx);
				break;
			case 'vclip' :
			case 'image' :
			case 'webkr' :
			case 'news' :
			case 'kin' :
			case 'video' :
				var tmpTbl= new cafen.TableAuto({attribute :{width :'420', cellPadding:2, cellSpacing : 2, border : 0}});
				tmpTbl.addRow();
				tmpTbl.addCell();
				tmpTbl.addStyle({width:'20px'});
				tmpTbl.addCell();
				tmpTbl.addStyle({width:'400px'});
				var rssObj = new cafen.xmlParser(txt);
				var contentsObj = null;
				var datas = [];
				if (contentsObj = rssObj.getNext()) {
					var item = null;
					while(item = contentsObj.getNext()) {
						var img = item.getNode('thumbnail');
						var player_url = item.getNode('player_url');
						var rss_url = item.getNode('link');
						if (img != '' && (cafen.find('q=(.+)', img))) 
							img = rss_url;
						var imageSize = '';
						var thumbExtra = '';
						if (this.lastDataIdx == 'image')
							imageSize = item.getNode('sizeheight') + 'px X ' +item.getNode('sizeheight') +'px'; 
						else if (this.lastDataIdx == 'vclip')
							thumbExtra = item.getNode('thumb_0') + '|' +item.getNode('thumb_1') + '|' +item.getNode('thumb_2') +'|' +item.getNode('thumb_3'); 
						datas.push({title : cafen.stripTags(item.getNode('title')), description : cafen.stripTags(item.getNode('description')), imagesize : imageSize , link : rss_url, Image : img, playerurl : player_url, thumb : thumbExtra});
					}
				}
				if (datas.length > 0) {
					var addHtmlBind = this.addHtml.bind(this);
					for(var i = 0; i < datas.length; i++) {
						var currData = datas[i];
						if (currData.Image != '' || currData.description != '' || currData.playerurl != '') {
							if (currData.playerurl != '') {
								tmpTbl.addRow();
								tmpTbl.addCell(new cafen.XIcon({icon:'r_mapset', off :272, on : 0,  over :16, style:{width: '16px', height:'16px'}, event : {click: addHtmlBind}, datas : currData}));
								var tmpCell = tmpTbl.addCell('<div style="'+titleStyle+'" title="'+currData.title+'">'+currData.title+'</div>');
								tmpTbl.addStyle({borderLeft:'1px dotted #d0d0d0', borderBottom:'1px dotted #d0d0d0'});
								tmpCell.attachEvent('click', this.showVideo.bind(this, currData.playerurl));
								if (currData.Image != '') {
									tmpTbl.addRow();
									tmpTbl.addCell('&nbsp;');
									var thumbData = [];
									thumbData.push(currData.Image);
									var imagesize = currData.thumb;
									var thumbExtra = imagesize.split("|");
									for(var j = 0 ; j < thumbExtra.length; j++) {
										if (	thumbExtra[j] != '')
											thumbData.push(thumbExtra[j]);
									}
									var thumbHtml = [];
									for(var j = 0 ; j < thumbData.length; j++) 
										thumbHtml.push('<img src="'+thumbData[j] +'" border=0 height=50 hspace=2>');
									tmpTbl.addCell(thumbHtml.join(''));
									tmpTbl.addStyle({paddingBottom:'5px', lineHeight:'120%',wordBreak:'break-all', wordWrap:'break-word', textAlign:'left'});
								}
							} else if (currData.Image != '') {
								tmpTbl.addRow();
								tmpTbl.addCell(new cafen.XIcon({icon:'r_mapset', off :256, on : 0,  over :16, style:{width: '16px', height:'16px'}, event : {click: addHtmlBind}, datas : currData}));
								var tmpCell = tmpTbl.addCell('<div style="'+titleStyle+'" title="'+currData.title+'">'+currData.title+'</div>');
								tmpTbl.addStyle({borderLeft:'1px dotted #d0d0d0', borderBottom:'1px dotted #d0d0d0'});
								tmpCell.attachEvent('click', this.showImage.bind(this, currData.Image));
								if (currData.Image != '') {
									tmpTbl.addRow();
									tmpTbl.addCell('&nbsp;');
									var thumbData = [];
									thumbData.push(currData.Image);
									var imagesize = currData.thumb;
									if (imagesize != '') {
										var thumbExtra = imagesize.split("|");
										for(var j = 0 ; j < thumbExtra.length; j++) {
											if (thumbExtra[j] != '')
												thumbData.push(thumbExtra[j]);
										}
									}
									var thumbHtml = [];
									for(var j = 0 ; j < thumbData.length; j++) 
										thumbHtml.push('<img src="'+thumbData[j] +'" border=0 height=50 hspace=2>');
									tmpTbl.addCell(thumbHtml.join(''));
									tmpTbl.addStyle({paddingBottom:'5px', lineHeight:'120%',wordBreak:'break-all', wordWrap:'break-word', textAlign:'left'});
								}
							} else if (currData.description != '') {
								tmpTbl.addRow();
								tmpTbl.addCell(new cafen.XIcon({icon:'r_mapset', off :288, on : 0,  over :16, style:{width: '16px', height:'16px'}, event : {click: addHtmlBind}, datas : currData}));
								tmpTbl.addCell('<div style="'+titleStyle+'" title="'+currData.title+'"><a href="'+currData.link+'" target=_blank>'+currData.title+'</a></div>');
								tmpTbl.addStyle({borderLeft:'1px dotted #d0d0d0', borderBottom:'1px dotted #d0d0d0'});
								tmpTbl.addRow();
								tmpTbl.addCell('&nbsp;');
								tmpTbl.addCell(cafen.longCut(currData.description, 70));
								tmpTbl.addStyle({paddingBottom:'5px', lineHeight:'120%',wordBreak:'break-all', wordWrap:'break-word', textAlign:'left'});
							}
						}
					}
				} else {
					tmpTbl.addRow();
					tmpTbl.addCell();
					tmpTbl.addCell('<u>'+this.keyword +'</u><hr>' +cafenMsg.get('map_0036'));
				}
				this.webDatas[this.lastDataIdx] = tmpTbl;
				this.showContentsObj.appendChild(tmpTbl);
				this.selectTab(this.lastDataIdx);
				break;
		}
	},
	showVideo : function(imgurl) {
		this._editorObject.showContents(imgurl, 'movie');
	},
	showImage : function(imgurl) {
		this._editorObject.showContents(imgurl, 'image');
	},
	showMap : function(obj) {
		this._editorObject.showContents(obj.options.datas, 'map');
	},
	previewMap : function(obj) {
		var mapUrl = 'http://maps.google.co.kr/staticmap?center='+obj.lat+','+obj.lon+'&size=400x300&key='+cafen.getAPI('GMap')+'&maptype=satellite&zoom=15&sensor=false&format=jpg';
		this.showImage(mapUrl);
	},
	addHtml : function(obj) {
		var currData = obj.options.datas;
		var objs = [];
		if (currData.playerurl != '') {
			objs.push('<embed type="application/x-shockwave-flash" wmode="transparent" ');
			objs.push('src="'+currData.playerurl+'" ');
			objs.push('allowFullScreen="true" width="482px" height="384px" quality="high" ');
			objs.push('></embed>');
		} else if (currData.Image != '') {
			objs.push('<img src="'+currData.Image+'" align=center hspace=2 vspace=2>');
		} else {
			objs.push('<TABLE cellSpacing=1 cellPadding=0 width="100%" >');
			objs.push('<tr>');
			objs.push('<td><a href="'+currData.link+'" target=_blank><b>'+currData.title+'</b></a></td>');
			objs.push('</tr>');
			objs.push('<tr>');
			objs.push('<td style="padding-left:30px">'+currData.description+'</td>');
			objs.push('</tr>');
		}
		this._editorObject.execCommand('insertHTML', true, objs.join(''));
	},
	showMsg : function(msg) {
		this._editorObject.showMsg(msg);
	},
	onClose : function() {
		this._editorObject.closePopup();
	}
},cafen.XWindow.prototype);


cafen.Editor.contentsViewer = function(parentNode) {
	this.parentNode = parentNode;
	this.initcontentsViewer();
};
cafen.Editor.contentsViewer.prototype = {
	initcontentsViewer : function() {
		this.obj = new cafen.Div({style:{position : 'absolute', textAlign : 'left', zIndex : '500000'}, attribute : {}});
		this.parentNode.appendChild(this.obj);
		var obj_width = this.parentNode.config.width - 30;
		var obj_height = this.parentNode.config.height - 10;
		if (obj_width < 200)
			obj_width = 300;
		else if (obj_width > 500)
			obj_width = 500;
		if (obj_height < 100)
			obj_height = 200;
		else if (obj_height > 500)
			obj_height = 500;
		this.baseSize = [obj_width, obj_height];
	},
	hideLastObj : function(obj) {
		if (this.lastObj != null && this.lastObj != obj)
			this.lastObj.hide();
		this.lastObj = obj;
		if (this.lastObj != null && this.lastObj.onLoad)
			this.lastObj.onLoad();
	},
	setImageEditor  : function(imgurl) {
		if (this.imageEditor == null) {
			var maxSize = Math.min(this.parentNode.config.onefile_max, this.parentNode.config.attachfile_max);
			var signTxt = this.parentNode.config.img_sign || '';
			this.imageEditor = new cafen.XImageViewer({maxSize : maxSize, signTxt : signTxt, style : {width : '550px', height : '375px'}, sticker : {obj : this.parentNode._editorObject.frmSkin, x : 'center', y : 'middle'}}, this.parentNode);
			this.obj.appendChild(this.imageEditor);
		}
		this.hideLastObj(this.imageEditor);
		this.imageEditor.setFileObj(imgurl, true);
	},
	setImage : function(imgurl) {
		if (this.imageViewer == null) {
			this.imageViewer = new cafen.XImageViewer({style : {width : this.baseSize[0] +'px', height : this.baseSize[1] +'px'}, sticker : {obj : this.parentNode._editorObject.frmSkin, x : 'center', y : 'middle'}});
			this.obj.appendChild(this.imageViewer);
		}
		this.hideLastObj(this.imageViewer);
		this.imageViewer.setImage(imgurl);
	},
	setMovie : function(imgurl) {
		if (this.movieViewer == null) {
			this.movieViewer = new cafen.XMovieViewer({style : {width : this.baseSize[0]  +'px', height : Math.round(this.baseSize[0]*0.7) +'px'}, sticker : {obj : this.parentNode._editorObject.frmSkin, x : 'center', y : 'middle'}});
			this.obj.appendChild(this.movieViewer);
		}
		this.hideLastObj(this.movieViewer);
		this.movieViewer.setMovie(imgurl);
	},
	setMovieEditor : function(imgurl) {
		if (this.movieEditor == null) {
			var maxSize = Math.min(this.parentNode.config.onefile_max, this.parentNode.config.attachfile_max);
			this.movieEditor = new cafen.XMovieViewer({maxSize : maxSize, style : {width : '550px', height : '271px'}, sticker : {obj : this.parentNode._editorObject.frmSkin, x : 'center', y : 'middle'}}, this.parentNode);
			this.obj.appendChild(this.movieEditor);
		}
		this.hideLastObj(this.movieEditor);
		this.movieEditor.setFileObj(imgurl);
	},
	setMap : function(mapInfo) {
		if (cafen.checkAPI('GMap')) {
			if (this.mapViewer == null) {
				var base_height = Math.max(this.baseSize[1], 300);
				this.mapViewer = new cafen.XMapViewer({style : {width : this.baseSize[0] +'px', height : base_height +'px'}, sticker : {obj : this.parentNode._editorObject.frmSkin, x : 'center', y : 'middle'}, event : {done : this.insertMap.bind(this)}});
				this.obj.appendChild(this.mapViewer);
			}
			this.hideLastObj(this.mapViewer);
			this.mapViewer.setMap(mapInfo);
		} else 
			this.parentNode.showMsg(cafenMsg.get('com_nullkey'));
	},
	insertMap : function(obj) {
		if (this.parentNode.editorAttachView != null && this.parentNode.config.attachAs) {
			this.parentNode.editorAttachView.uploadRemote(obj.getMap(), cafen.getUniqID('map')+'.' + (obj.getApi() == 'daum' ? 'gif' : 'png'));
		} else {
			this.parentNode.execCommand('insertHTML', true, '<img src=' +obj.getMap() +' hsapce=5 vspave=5>');
		}
		this.hideLastObj(null);
	}
}

cafen.Editor.AttachScale = function(obj) {
	this._editorObj = obj;
	this.baseWidth = this._editorObj.config.width -120;
	this.maxUpload = this._editorObj.config.attachfile_max;
	this.setOptions({tag : 'div', attribute :{}, style : {width :(this._editorObj.config.width-35)+'px', height:'22px', marginLeft : '8px'}});
	this.initAttachScale()
}


cafen.Editor.AttachScale.prototype = cafen.extendClass({
	initAttachScale : function() {
		var tmpTable = new cafen.TableAuto({style : {width : (this.baseWidth +83) +'px', tableLayout:'fixed', height :'22px'}});
		this.appendChild(tmpTable);
		tmpTable.addCell();
		tmpTable.addAttribute({className : this._editorObj.conf.getClassName('scale')});
		tmpTable.addText('&#160;');
		tmpTable.addStyle({backgroundPosition: '0 -40px', fontSize : '1px', width:'2px'});
		this._scalePointer = new cafen.Div({attribute :{className : this._editorObj.conf.getClassName('scale')}, style : {width :(this.baseWidth)+'px', height:'20px', backgroundPosition : '-1000px 0',backgroundColor : 'transparent', backgroundRepeat : 'no-repeat'}});
		this.middleCell = tmpTable.addCell(this._scalePointer);
		tmpTable.addStyle({verticalAlign: 'bottom', width : this.baseWidth +'px', height:'22px'});
		this._uploadPointer = new cafen.Div({attribute :{className : this._editorObj.conf.getClassName('scale')}, style : {width :(this.baseWidth)+'px', height:'20px', backgroundPosition : '-1000px -20px',backgroundColor : 'transparent', backgroundRepeat : 'no-repeat'}});
		this._scalePointer.appendChild(this._uploadPointer);
		tmpTable.addCell();
		tmpTable.addStyle({backgroundPosition: '-2px -40px', fontSize : '1px', width:'2px'});
		tmpTable.addAttribute({className : this._editorObj.conf.getClassName('scale')});
		tmpTable.addText('&#160;');
		var iconMargin = '0 0 0 1px';
		this.attachFileButton  = new cafen.Div({style:{width:'72px', height:'22px', margin : iconMargin, overflow: 'hidden', overflowX : 'hidden', overflowY : 'hidden'},attribute :{unselectable : 'on'}});
		this._attachStatus = tmpTable.addCell(this.attachFileButton);
		tmpTable.addStyle({width:'80px', paddingLeft :'7px'});
		this.setScale(50,1024*1024*5, 1024*1024*10);
	},
	reSize : function() {
		this.baseWidth = this._editorObj.config.width -125;
		this.setStyle({width : (this.baseWidth+86) +'px'});
		this.childNodes[0].setStyle({width : (this.baseWidth+80) +'px'});
		this.middleCell.setStyle({width : (this.baseWidth) +'px'});
		this._scalePointer.setStyle({width : (this.baseWidth) +'px'});
		this._uploadPointer.setStyle({width : (this.baseWidth) +'px'});
	},
	setProcessRemote : function(bl) {
		if (this.setProcessRemoteTimer != null) 
    		window.clearTimeout(this.setProcessRemoteTimer);
    	if (bl) {
			this.processSeqn = 0;
			if (this.setProcessRemoteTimeoutBind == null)
				this.setProcessRemoteTimeoutBind = this.setProcessRemoteTimeout.bind(this);
			this.setProcessRemoteTimeout();
		}
	},
	setProcessRemoteTimeout : function() {
		this.processSeqn += 2;
		this.processSeqn = this.processSeqn % 200;
		var po = (this.processSeqn > 100) ? (this.baseWidth * (200 - this.processSeqn) / 100) : (this.baseWidth * this.processSeqn / 100);
		this._uploadPointer.setStyle({backgroundPosition : (po-1000) + 'px -20px'});
		this.setProcessRemoteTimer = window.setTimeout(this.setProcessRemoteTimeoutBind, 50);
	},
	setScale : function(per, useSize, maxSize) {
		this.setProcessRemote(false);
		if (per > 100)
			per = 100;
		this._scalePointer.setAttribute({title :cafen.getSize2Short(useSize)+' / '+cafen.getSize2Short(maxSize) +'('+ cafenMsg.get('ed_0024',Math.round(per)) +' / '+cafenMsg.get('ed_0025',Math.round(100 - per)) +')'});
		this.options.moveSchedule = [];
		if (this.options.animateStartBind == null)
			this.options.animateStartBind = this.setScaleTime.bind(this);
		var x = (this.baseWidth * per / 100) ;
		var aniBind = [0, -1, -2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,19,18,17,18];
		var bg_pos = this._scalePointer.getStyle('backgroundPosition').split(' ');
		var pos_x = 1000 + parseInt(bg_pos[0]);
		var pos = [pos_x, 0];
    	var posStepX = (x != null) ? x - pos[0] : 0;
		for(var i = 0; i < aniBind.length; i++) {
			var moveRate = Math.sin(Math.PI * aniBind[i]/36);
			if (aniBind[i] > 18)
				moveRate = 2 - moveRate;
			var moveX =  (posStepX != 0) ? Math.round(pos[0] + posStepX * moveRate) : null;
			this.options.moveSchedule.push(moveX+6);
		}
    	if (this.timer != null)
    		window.clearTimeout(this.timer);
    	if (this.options.moveSchedule.length > 0)
			this.setScaleTime();
	},
	setScaleTime : function() {
		var x = this.options.moveSchedule[0] || 0;
		this.options.moveSchedule.shift();
		this._scalePointer.setStyle({backgroundPosition: (x - 1000)+'px 0'});
    	if (this.options.moveSchedule.length > 0) 
			this.timer = setTimeout(this.options.animateStartBind, 5);
	},
	setProcess : function(per) {
		var po = (this.baseWidth * per / 100);
		this._uploadPointer.setStyle({backgroundPosition : (po-1000) + 'px -20px'});
	}
},cafen.Element.prototype);


cafen.Editor.AttachFile = function(obj) {
	this._editorObject = obj;
	this.baseWidth = obj.config.width -40;
	this.baseAttachHeight = obj.config.showattachsize * 26;
	if (	this.baseAttachHeight > 200)
		this.baseAttachHeight = 200;
	if (	this.baseAttachHeight < 52)
		this.baseAttachHeight = 52;
	this.baseAttachHeight -= 4;
	this.previewHeight = this.baseAttachHeight;
	if (this.previewHeight > 100)
		this.previewHeight = 100;
	this.maxUpload = this._editorObject.config.attachfile_max;
	this.maxUploadCnt = this._editorObject.config.attachfile_cnt;
	this.attachType = this._editorObject.config.attachfile_type;
	this.setOptions({tag : 'div', attribute :{}, style : {width :this.baseWidth+'px', textAlign : 'left',position: 'relative', margin : '3px 0 1px 8px'}});
	this.initAttachFile()
}
cafen.Editor.AttachFile.prototype = cafen.extendClass({
	attachSize : 0,
	attachHtmlTags : [],
	initAttachFile : function() {
		var tmpTable = new cafen.TableAuto({attribute :{border : 0, cellSpacing: 0 },style : {width :this.baseWidth+'px'}});
		this.appendChild(tmpTable);
		tmpTable.addRow();
		this.previewArea = new cafen.Div({className : this._editorObject.conf.getClassName('box'),style : {width : '94px', height : this.previewHeight + 'px', overflow : 'hidden', overflowX : 'hidden', overflowY : 'hidden', position:'relative'}}); 
		tmpTable.addCell(this.previewArea);
		tmpTable.addStyle({verticalAlign: 'top'});
		this.attachArea = new cafen.XMenu([], this.baseWidth -188, {style: {height:(this.baseAttachHeight + 6)+'px', overflowY : 'auto', overflowX : 'hidden', marginLeft: '3px'}, event : {select : this.setSelect.bind(this)}, buttonClass : this._editorObject.conf.getClassName('attachbutton')}); 
		tmpTable.addCell(this.attachArea);
		var buttonTable = new cafen.TableAuto({attribute :{border : 0, cellSpacing: 0, cellPadding : 0},style : {width :'auto'}});
		tmpTable.addCell(buttonTable);
		tmpTable.addStyle({textAlign:'left',verticalAlign: 'top'});
		var iconMargin = null;
		if(cafen.browser.isIE) 
			iconMargin = '0 0 0 3px';
		else if(cafen.browser.isFF) 
			iconMargin = '-1px 0 0 0px';
		else
			iconMargin = '3px 0px 3px 2px';
		this.insertBind = this.insertFile.bind(this);
		var buttonSet = [];
		for(var i = 0 ; i < Math.min(6, this._editorObject.config.middlebar.length); i++) 
			buttonSet.push(this._editorObject.config.middlebar[i]);
		for(var i = 0; i < 6; i++) {
			if (i % 3 == 0) {
				buttonTable.addRow();
				if (i > 0) {
					buttonTable.addCell();
					buttonTable.addAttribute({colSpan :3});
					buttonTable.addStyle({height:'2px'});
					buttonTable.addRow();
				}
			}
			var currButton = (i < buttonSet.length ) ? buttonSet[i] : '';
			var bgPos = 330;
			var currPos = i % 3;
			if (currPos == 0 && i == buttonSet.length - 1)
				bgPos = 462;
			else if (i == buttonSet.length - 1 || currPos == 2) 
				bgPos = 396;
			else if (currPos == 0) 
				bgPos = 264;
			switch(currButton) {
				case 'left' :
					var icon = new cafen.XImage({className :'r_editorset',x: 128,y : 80}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos , on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : cafenMsg.get('ed_0011')}, event : {click : this.insertBind}, alignOptions : 'left', childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'center' :
					var icon = new cafen.XImage({className :'r_editorset',x: 112,y : 80}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : cafenMsg.get('ed_0012')}, event : {click : this.insertBind}, alignOptions : 'center', childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'right' :
					var icon = new cafen.XImage({className :'r_editorset',x: 144,y : 80}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : cafenMsg.get('ed_0013')}, event : {click : this.insertBind}, alignOptions : 'right', childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'del' :
					var icon = new cafen.XImage({className :'r_editorset',x: 144,y : 48}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : cafenMsg.get('ed_0014')}, event :{click:this.confirmDelete.bind(this)}, childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'chart' :
					var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
					var icon = new cafen.XImage({className :'r_editorset',x: 16,y : 48}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : buttonInfo['insertchart'][1]}, event :{click:this.attachChart.bind(this)}, childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'map' :
					var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
					var icon = new cafen.XImage({className :'r_editorset',x: 16,y : 32}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : buttonInfo['insertmap'][1]}, event :{click:this.attachMap.bind(this)}, childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'image' :
					var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
					var icon = new cafen.XImage({className :'r_editorset',x: 80,y : 32}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : buttonInfo['insertimaged'][1]}, event :{click:this.attachImage.bind(this)}, childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				case 'movie' :
					var buttonInfo = cafenMsg.getObject('ed_buttonInfo');
					var icon = new cafen.XImage({className :'r_editorset',x: 144,y : 32}, {style:{width:'16px', height:'16px', margin : iconMargin},attribute :{unselectable : 'on'}});
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on', title : buttonInfo['insertmediad'][1]}, event :{click:this.attachMovie.bind(this)}, childNodes : [icon]}) ;
					buttonTable.addCell(tmpButton);
					break;
				default :
					tmpButton = new cafen.XIcon({icon : this._editorObject.conf.getClassName('buttonbg'), off : bgPos, on : 22 , over : 100, style :{width: '24px'}, attribute :{unselectable : 'on'}, event :{}, attribute : {innerHTML :'&nbsp;'}}) ;
					buttonTable.addCell(tmpButton);
					break;
			}
		}
		this.updateScale();
	},
	reSize : function() {
		this.baseWidth = this._editorObject.config.width -40;
		this.setStyle({width : this.baseWidth +'px'});
		this.childNodes[0].setStyle({width : this.baseWidth +'px'});
		this.attachArea.setStyle({width : (this.baseWidth -188)+'px'});
		this.attachArea.reSize(this.baseWidth -188);
		this.updateScale();
	},
	attachChart : function() {
		if (cafenEditor_loader.editorBaseConf.useFlashChart) {
			if (!this._editorObject.checkMode()) 
				this._editorObject.showMsg(cafenMsg.get('ed_0072'),true);
			else {
				if (this.chartObj == null) {
					this.chartObj = new cafen.Editor.Chart(this._editorObject,{ 
								sticker : {obj : this._editorObject._editorObject.frmSkin, x : 'center', y : 'bottom', plus : [0,-300]},
								style : {overflowX : 'hidden', overflowY : 'auto'}
								});
					this._editorObject._editorObject.editorPopup.addChild(this.chartObj);
				}
				this.chartObj.onLoad();
			}
		} else 
			this._editorObject.showMsg(cafenMsg.get('ed_0036') , true);
	},
	attachMap : function() {
		if (cafenEditor_loader.editorBaseConf.useStaticMap) {
			if (!this._editorObject.checkMode()) 
				this._editorObject.showMsg(cafenMsg.get('ed_0072'),true);
			else 
				this._editorObject.showContents(null, 'map');
		} else 
			this._editorObject.showMsg(cafenMsg.get('ed_0036') , true);
	},
	attachImage : function() {
		if (cafenEditor_loader.editorBaseConf.useImageEditor) {
			if (!this._editorObject.checkMode()) 
				this._editorObject.showMsg(cafenMsg.get('ed_0072'),true);
			else 
				this._editorObject.showContents(null,'imageeditor');
		} else
			this._editorObject.showMsg(cafenMsg.get('ed_0036') , true);
	},
	attachMovie : function() {
		if (this.attachType.indexOf('all') > -1 || this.attachType.indexOf('video') > -1) {
			if (cafenEditor_loader.editorBaseConf.useMediaPlayer) {
				if (!this._editorObject.checkMode()) 
					this._editorObject.showMsg(cafenMsg.get('ed_0072'),true);
				else 
					this._editorObject.showContents(null,'movieeditor');
			} else
				this._editorObject.showMsg(cafenMsg.get('ed_0036') , true);
		} else {
			this._editorObject.showMsg(cafenMsg.get('ed_0036') , true);
		}
	},
	initFiles : function(attachtxt) {
		var attachFiles = this.attachArea.getItems();
		for(var i = 0; i < attachFiles.length; i++)
			this.attachArea.removeItem(attachFiles[i]);
		if (attachtxt != undefined && attachtxt != '') {
			var attach_txt = attachtxt.split("#");
			for(var i = 0; i < attach_txt.length; i++) {
				var arr_val = attach_txt[i];
				var attach_info = arr_val.split('|');
				if (attach_info.length >= 4 ) {
					var attach_obj = new Object();
					attach_obj = {server:attach_info[0], size : parseInt(attach_info[1]), extension : attach_info[2], fileName :  attach_info[3], extra :  (attach_info[4] != null)?attach_info[4]:''};
					this.addFile(attach_obj);
				}
			}
		} 
		this.updateScale();
	},
	onload : function() {
		if (this._editorObject.editorAttachScale.attachFileButton != null) {
			this._attachbuttonID = this._editorObject.editorAttachScale.attachFileButton.getAttribute('id');
			if (this._attachbuttonID == null || typeof this._attachbuttonID == 'undefined' || this._attachbuttonID == '') {
				this._attachbuttonID = cafen.getUniqID('attach');
				this._editorObject.editorAttachScale.attachFileButton.setAttribute({id : this._attachbuttonID});
				if (document.getElementById(this._attachbuttonID) != null) {
					cafen.Editor.Upload.upload_local({
						upload_max_size : this._editorObject.config.attachfile_max,
						upload_one_size : this._editorObject.config.onefile_max,
						button_placeholder_id : this._editorObject.editorAttachScale.attachFileButton.getElement(),
						upload_filetypes : this.attachType,
						handleErrors : this.uploadError.bind(this),
						uploadProgress : this.uploadProgress.bind(this),
						uploadFileComplete : this.uploadFileComplete.bind(this),
						uploadQueueComplete : this.uploadQueueComplete.bind(this),
						fileQueued : this.fileQueued.bind(this),
						button_image_url : _cafen_service_url+'images/ico_attach.png',
						button_text : '<span class="theFont">'+cafenMsg.get('ed_0051') +'</span>',
						button_text_left_padding : '18',
						button_text_top_padding : '2',
						backgroundcolor : this._editorObject.conf.options.attach_bg ,
						button_text_style : '.theFont {color: '+this._editorObject.conf.options.attach_font+'; font-size: 11px;}',
						fileDialogStart : this.fileDialogStart.bind(this)
					});
				}
			}
		}
	},
	uploadRemote : function (remote_url, saveName) {
		this.attachHtmlTags = [];
		cafen.Editor.Upload.upload_remote({
			handleErrors : this.uploadError.bind(this),
			uploadProgress : this.uploadProgress.bind(this),
			uploadFileComplete : this.uploadFileComplete.bind(this),
			uploadQueueComplete : this.uploadQueueComplete.bind(this),
			remote_url : remote_url,
			save_name : saveName,
			move : 'Y'
		});
		this._editorObject.editorAttachScale.setProcessRemote(true);
	},
	uploadError : function(msg, detail, contents) {
		this._editorObject.showMsg(detail +'<hr>'+contents, true);
	},
	fileDialogStart : function() {
		this.attachHtmlTags = [];
		this.uploadQueue = [];
		this.uploadQueueSize = 0;
		this.uploadedSize = 0;
		return true;
	},
	fileQueued : function(ufile) {
		this.uploadQueueSize += parseInt(ufile.size);
		this.uploadQueue.push(ufile);
	},
	uploadProgress : function(ufile, bytes_complete, bytes_total) {
		this._editorObject.editorAttachScale.setProcess((this.uploadedSize + bytes_complete)/this.uploadQueueSize*100);
	},
	uploadFileComplete : function(ufile) {
		if (this.addFile(ufile)) {
			this._editorObject.setloadUnload(true);
			this.uploadedSize += parseInt(ufile.size);
			if (ufile.html_tag != '') 
				this.attachHtmlTags.push(ufile.html_tag);
		}
	},
	uploadQueueComplete : function() {
		this._editorObject.editorAttachScale.setProcess(0);
		this.updateScale(true);
		if (this._editorObject.checkMode() && this.attachHtmlTags.length > 0) {
			this._editorObject.showConfirm(cafenMsg.get('ed_0102'), this.uploadFileTag.bind(this), true);
		}
	},
	uploadFileTag : function(bl) {
		if (bl && this._editorObject.checkMode() && this.attachHtmlTags.length > 0) {
			this._editorObject.execCommand('inserthtmlend', null, this.attachHtmlTags.join('<br>')+'<p>&nbsp;</p>');
		}
		this.attachHtmlTags = [];
	},
	setPreview : function(obj) {
		var fileOption = obj.options.itemOptions;
		if (cafen.Editor.Upload.isImage(fileOption)) {
			if (this.showImageContentsBind == null)
				this.showImageContentsBind = this.showImageContents.bind(this);
			this.lastSelectedObj = fileOption;
			this.previewArea.getElement().innerHTML = "";
			if (fileOption.previewObj == null) 
				fileOption.previewObj = new cafen.Image(fileOption.img.src, {fileOption : fileOption, scale : 'max', style : {width : '94px', height : this.previewHeight + 'px', cursor : cafen.getCursor()}, event : {click : this.showImageContentsBind}, attribute : {id : 'thumb_cafenimg'}});
			cafen.Event.observe(fileOption.previewObj.getElement(),'dragend', this._editorObject.setDropDocBind);
			this.previewArea.appendChild(fileOption.previewObj);
		} else if (cafenEditor_loader.editorBaseConf.useMediaPlayer && cafen.Editor.Upload.isMovie(fileOption)) {
			if (this.showMovieContentsBind == null)
				this.showMovieContentsBind = this.showMovieContents.bind(this);
			this.lastSelectedObj = fileOption;
			this.previewArea.getElement().innerHTML = "";
			if (fileOption.previewObj == null) 
				fileOption.previewObj = new cafen.Image(_cafen_service_url+'images/ico_movie.gif', {fileOption : fileOption, scale : 'min', style : {width : '94px', height : this.previewHeight + 'px', cursor : cafen.getCursor()}, event : {click : this.showMovieContentsBind}});
			this.previewArea.appendChild(fileOption.previewObj);
		}
	},
	showImageContents : function(obj) {
		if (!cafenEditor_loader.editorBaseConf.useImageEditor)
			this._editorObject.showContents(obj.getElement().src,'image');
		else {
			this._editorObject.showContents(obj.options.fileOption,'imageeditor');
		}
	},
	showMovieContents : function(obj) {
		if (cafenEditor_loader.editorBaseConf.useMediaPlayer)
			this._editorObject.showContents(obj.options.fileOption,'movieeditor');
	},
/**
 * 첨부 파일 parse
 */
	parse : function(bl) {
		var attachFiles = this.attachArea.getItems();
		if (attachFiles.length > 0) {
			if (bl == null || !bl) {
				var contents = this._editorObject.getContents();
				var attachfileHtml = '<select style="display:none">';
				for(var i = 0 ; i < attachFiles.length; i++) {
					var fileinfo = attachFiles[i].options.itemOptions;
					var isIncluded = (contents.indexOf(fileinfo.server) > -1) ? '1' : '0';
					attachfileHtml += '<option isincluded='+isIncluded+' server="'+fileinfo.server+'" size="'+fileinfo.size+'" ext="'+fileinfo.extension+'" extra="'+fileinfo.extra+'">'+fileinfo.fileName +'</option>';
				}
				attachfileHtml += '</select>';
				return attachfileHtml;
			} else {
				var attachfileHtml = '';
				if (bl == 'xml') {
					for(var i = 0 ; i < attachFiles.length; i++) {
						var fileinfo = attachFiles[i].options.itemOptions;
						var tmpObj = {
							'server' : 	fileinfo.server,
							'size' : fileinfo.size,
							'ext' : fileinfo.extension,
							'name' : fileinfo.fileName,
							'extra' : fileinfo.extra
						}
						attachfileHtml += '<item>\r\n'
						for (var idx in tmpObj) {
							attachfileHtml += '<'+idx+'><![CDATA['+tmpObj[idx]+']]></'+idx+'>\r\n';
						}
						attachfileHtml += '</item>\r\n';
					}
				} else {
					var tmpData = [];
					for(var i = 0 ; i < attachFiles.length; i++) {
						var fileinfo = attachFiles[i].options.itemOptions;
						tmpData.push(fileinfo.server + '|' + fileinfo.size + '|' + fileinfo.extension + '|' + fileinfo.fileName + '|' + fileinfo.extra);
					}
					attachfileHtml = tmpData.join('#');
				}
				return attachfileHtml;
			}
		} else
			return '';
	},
/**
 * 첨부된 이미지 갯수
 * @return {int} 첨부된 이미지 갯수
 */
	getImageCnt : function() {
		var cnt = 0;
		var attachFiles = this.attachArea.getItems();
		for(var i =0; i< attachFiles.length; i++) {
			var fileOption = attachFiles[i].options.itemOptions;
			if (cafen.Editor.Upload.isImage(fileOption)) 
				cnt++;
		}
		return cnt;
	},
/**
 * 첨부 파일 크기 가져오기
 */
	getAttachSize : function() {
		return this.attachSize;
	},
/**
 * 첨부 파일 갯수 가져오기
 */
	getAttachCnt : function() {
		return this.attachArea.getItems().length;
	},

/**
 * 첨부 파일 추가 가능 여부 확인
 * @param {int} add_cnt  추가될 크기
 * @return {boolean} 추가가능여부
 */
	chkUploadSize : function (add_size) {
		if (this.getRemindSize() > add_size)
			return true;
		else
			return false;
	},
/**
 * 남은 첨부 용량가져오기
 * @return {int} 남은첨부가능용량
 */
	getRemindSize : function() {
		return (this.maxUpload - this.attachSize);
	},
	addFile : function(obj) {
		obj = cafen.extend({fileName :'', size : 0, extension : '', server : '', extra : ''}, obj);
		if (obj.fileName == '')
			obj.fileName = obj.server.substr(obj.server.indexOf('/')+1);
		if (this.attachSize + obj.size <= this.maxUpload && (this.maxUploadCnt == 0 || this.maxUploadCnt > this.getAttachCnt())) {
			var text = (obj.size > 0) ? obj.fileName +' ('+cafen.getSize2Short(obj.size,2)+')' : obj.fileName;
			var buttonObj = this.attachArea.appendItem({text : text , icon : this.getFileIcon(obj.extension) , options : obj});
			obj.linkObj = buttonObj;
			if (obj.orgName != null && obj.orgName != '') 
				this.replaceFileConfirm(obj.orgName, obj.server);			
			return true;
		} else {
			this._editorObject.showMsg(cafenMsg.get('ed_0019', cafen.getSize2Short(this.attachSize,2), cafen.getSize2Short(this.maxUpload,2), cafen.getSize2Short(obj.size,2)), true);
			return false;
		}
	},
	_lastReplaceFileObj : [null, null],
	replaceFileConfirm : function(orgName, repName) {
		this._lastReplaceFileObj = [orgName, repName];
		this._editorObject.showConfirm(cafenMsg.get('ed_0141'), this.replaceFile.bind(this), true);
	},
	replaceFile : function(bl) {
		if (bl) {
			var orgName = this._lastReplaceFileObj[0];
			var repName = this._lastReplaceFileObj[1];
			var selectedObj = this.attachArea.getItems();
			var replaceObj = [];
			for(var i =0; i < selectedObj.length ; i++) {
				if (selectedObj[i].options.itemOptions.server == orgName) {
					replaceObj.push(selectedObj[i].options.itemOptions.server);
					this.attachArea.removeItem(selectedObj[i]);
				}
			}
			if (replaceObj.length > 0 && this._editorObject.checkMode()) {
				var imgObjs = this._editorObject._editorObject.htmlEditor.getDocument().getElementsByTagName('img');
				if (imgObjs != null && imgObjs.length > 0) {
					for(var j = 0; j < replaceObj.length ; j++) {
						var currServer = replaceObj[j];
						var oldFileFound = false;
						for(var i = 0; i < 	imgObjs.length ; i++) {
							var imgObj = imgObjs[i];
							if (imgObj.src.indexOf(currServer) > 0) {
								imgObj.src = imgObj.src.replace(currServer, repName);	
								imgObj.removeAttribute('width');
								imgObj.removeAttribute('height');
								imgObj.style.width = 'auto';
								imgObj.style.height = 'auto';
								oldFileFound = true;
							} else if (imgObj.src.indexOf(repName) > 0 && oldFileFound) {
								if (imgObj.parentNode.childNodes.length == 1) 
									imgObj.parentNode.parentNode.removeChild(imgObj.parentNode);
								else 
									imgObj.parentNode.removeChild(imgObj);
							}
						}
					}
				}
			}
		}
	},
	attach_icon : {
		avi:171, mov:171, flv:171, wma:171, asf:171, wav:171, mp3:179,
		com:176, exe:176, dll:176, 
		htm:174, html:174, docx:178, doc:178, hwp:173, 
		bmp:180, gif:175,jpg:172 ,png:172, jpeg:172, psd:187, tif:185, 
		pdf:188, ppt:187, pptx:187, txt:189, xls:184,xlsx:184,
		zip:183, mcast : 181, etc:177 
	},
	getFileIcon : function(ext) {
		var pos = (this.attach_icon[ext] != null) ? this.attach_icon[ext] : this.attach_icon['etc'];
		var x = (pos % 10) * 16;
		var y = Math.floor(pos / 10)*16;
		return {className : 'r_editorset', x : x, y : y};
	},
	baseLimitSize : null,
	getImageTag : function(imgobj) {
		var addedTag = '';
		if (this._editorObject.config.maxpageheight > 0) {
			if (this.baseLimitSize == null) {
				this.baseLimitSize = {
					width : parseInt(this._editorObject.config.maxpagewidth),
					height : parseInt(this._editorObject.config.maxpageheight)
				}
			}
			var orgsize_width = parseInt(imgobj.width || imgobj.img.width);
			var orgsize_height = parseInt(imgobj.height || imgobj.img.height);
			var resize_width = orgsize_width;
			var resize_height = orgsize_height;
			if (	this.baseLimitSize.width < resize_width) {
				resize_width = 	this.baseLimitSize.width;
				resize_height = Math.round(this.baseLimitSize.width * orgsize_height / orgsize_width) ;
			} 
			if (this.baseLimitSize.height < resize_height) {
				resize_height = 	this.baseLimitSize.height;
				resize_width = Math.round(this.baseLimitSize.height * orgsize_width / orgsize_height) ;
			}
			var addedTagData1 = [];
			var addedTagData2 = [];
			if (orgsize_width != resize_width) {
				addedTagData1.push('width="'+resize_width+'px"');
				addedTagData2.push('width:'+resize_width+'px');
			}
			if (orgsize_height != resize_height) {
				addedTagData1.push('height="'+resize_height+'px"');
				addedTagData2.push('height:'+resize_height+'px');
			}
			if (addedTagData1.length > 0 || addedTagData2.length > 0) 
				addedTag = addedTagData1.join(' ') +' style="'+addedTagData2.join(';')+'" ';
		}
		return addedTag;
	},
	insertFile : function(obj) {
		if (!this._editorObject.checkMode()) 
			this._editorObject.showMsg(cafenMsg.get('ed_0072'),true);
		else {
			var selectedObj = this.attachArea.getSelected();
			if (selectedObj.length > 0) {
				var html = [];
				for(var i = 0; i < selectedObj.length; i++) {
					fileOption = selectedObj[i].options.itemOptions;
					switch(obj.options.alignOptions) {
						case 'left' :
							if (cafen.Editor.Upload.isImage(fileOption)) 
								html.push('<img class="cafenimg_resize" src='+fileOption.img.src +' border=0 align=left style="margin-bottom:3px;margin-right:3px;" '+this.getImageTag(fileOption)+'>');
							else 
								html.push(this.getFileInsertTag(fileOption));
							break;
						case 'right' :
							if (cafen.Editor.Upload.isImage(fileOption)) 
								html.push('<img class="cafenimg_resize" src='+fileOption.img.src +' border=0 align=right style="margin-bottom:3px;margin-left:3px;" '+this.getImageTag(fileOption)+'>');
							else 
								html.push(this.getFileInsertTag(fileOption));
							break;
						default :
							html.push('<div align=center>');
							if (cafen.Editor.Upload.isImage(fileOption)) 
								html.push('<img class="cafenimg_resize" src='+fileOption.img.src +' border=0 '+this.getImageTag(fileOption)+'>');
							else 
								html.push(this.getFileInsertTag(fileOption));
							html.push('</div>');
							break;
					}
				}
				this._editorObject.execCommand('insertHTML', null, html.join('')+'<p>&nbsp;</p>');
			} else {
				this._editorObject.showMsg(cafenMsg.get('ed_0015'), true);
			}
		}
	},
	getFileInsertTag : function(fileOption) {
		var tag = '';
		if (typeof getEditorAttachTag == 'function') {
			try {
				tag = getEditorAttachTag(fileOption);
			} catch(ex) {}
		}
		if (tag != null && tag != '')
			return tag;
		else {
			var baseUrl = '';
			if (cafenEditor_loader.editorBaseConf.downloadSCRIPT == null) {
				if (cafenEditor_loader.editorBaseConf.uploadedURL != null && cafenEditor_loader.editorBaseConf.uploadURL != cafenEditor_loader.editorBaseConf.uploadedURL) {
					if (fileOption.server.indexOf("junk/") == 0) 
						baseUrl = cafenEditor_loader.editorBaseConf.uploadURL + fileOption.server;
					else 
						baseUrl = cafenEditor_loader.editorBaseConf.uploadedURL + fileOption.server;
				} else {
					baseUrl = cafenEditor_loader.editorBaseConf.uploadURL + fileOption.server;
				}
			} else {
				baseUrl = cafenEditor_loader.editorBaseConf.downloadSCRIPT + '?fileNm=' + fileOption.server + '&downNm=' +encodeURIComponent(fileOption.fileName);
			}
			var fileIcon = (cafen.Editor.Upload.attach_icon[fileOption.extension] != null) ? cafen.Editor.Upload.attach_icon[fileOption.extension] : cafen.Editor.Upload.attach_icon['etc'];
			return '<img src="'+cafenEditor_loader.editorBaseConf.imageURL+'ext/s'+fileIcon+'" align=absmiddle border=0 > <a href='+baseUrl+' target=_blank>'+fileOption.fileName+' ('+cafen.getSize2Short(fileOption.size,2)+')</a>';
		}
	},
	updateScale : function(posLast) {
		this.attachSize = 0;
		var attachFiles = this.attachArea.getItems();
		for(var i = 0; i < attachFiles.length; i++)
			this.attachSize += attachFiles[i].options.itemOptions.size;
		if (this.maxUpload > 0) 
			this._editorObject.editorAttachScale.setScale(this.attachSize/this.maxUpload*100, this.attachSize ,this.maxUpload);
		else
			this._editorObject.editorAttachScale.setScale(0, 0 ,100);
		if (posLast) {
			this.attachArea.onChange({scrollTop: 1000});
		} else {
			this.attachArea.onChange();
		}
	},
	confirmDelete : function() {
		var selectedLen = 0;
		var selectedLen = this.attachArea.getSelected().length;
		if (selectedLen == 0)
			this._editorObject.showMsg(cafenMsg.get('ed_0017'), true);
		else
			this._editorObject.showConfirm(cafenMsg.get('ed_0018', selectedLen), this.deleteSelected.bind(this), true);
	},
	deleteSelected : function(bl) {
		if (bl) {
			var selectedObj = this.attachArea.getSelected();
			var contents = this._editorObject.getContents();
			var error_file = [];
			for(var i =0; i < selectedObj.length ; i++) {
				if (contents.indexOf(selectedObj[i].options.itemOptions.server) > 0) 
					error_file.push(selectedObj[i].options.itemOptions.fileName);
				else
					this.attachArea.removeItem(selectedObj[i]);
			}
			if (error_file.length > 0)
				this._editorObject.showMsg(cafenMsg.get('ed_0020', error_file.join('<br>')), true);
			this.previewArea.getElement().innerHTML = "";
			this.updateScale();
		}
	},
	setSelect : function(tmp, obj) {
		this.attachArea.setSelectToggle(obj);
		this.setPreview(obj);
	}
},cafen.Element.prototype);


cafen.Editor.Config = function(editObj, config) {
	this.initConfig(editObj, config);
}

cafen.Editor.Config.prototype = {
	initConfig : function(editor_obj, userConfig) {
		if (userConfig == undefined) { var userConfig = new Object(); }
		this.width = parseInt((userConfig.width == undefined)?(editor_obj.obj.offsetWidth?editor_obj.obj.offsetWidth:editor_obj.obj.style.width):userConfig.width);
		this.height = parseInt((userConfig.height == undefined )?(editor_obj.obj.offsetHeight?editor_obj.obj.offsetHeight:editor_obj.obj.style.height):userConfig.height);
		this.editorHidden	= userConfig.editorHidden || false;
		if (this.width == undefined || this.width < 300) this.width = 300;
		if (this.height == undefined || this.height < 30) this.height = 30;
		this.mode = this.initmode = (userConfig.mode == undefined)?'H':userConfig.mode;
		this.useAutoParse = (userConfig.useAutoParse == undefined)?true:userConfig.useAutoParse;
		this.attachfile_max = (userConfig.attachfile_max == undefined)?1024*30:userConfig.attachfile_max;
		this.attachfile_cnt = (userConfig.attachfile_cnt == undefined)?30:userConfig.attachfile_cnt;
		this.attachfile_type = (userConfig.attachfile_max == undefined)?'all':userConfig.attachfile_type;
		this.onefile_max = (userConfig.onefile_max == undefined)?1024*30:userConfig.onefile_max;
		this.attachAs = (userConfig.attachAs == undefined || userConfig.attachAs == null)? cafenEditor_loader.editorBaseConf.attachAs :userConfig.attachAs;
		this.delayRender = (userConfig.delayRender == undefined) ? 0 : userConfig.delayRender;
		var contentsval = (userConfig.data == null) ? editor_obj.obj.value : userConfig.data;
		this.canbe_null = (userConfig.canbe_null == null) ? false : userConfig.canbe_null;
		this.canbe_resize = (userConfig.canbe_resize == null) ? true : userConfig.canbe_resize;
		this.statusoff = (userConfig.statusoff == null) ? false : userConfig.statusoff;
		this.maxpageheight = (userConfig.maxpageheight == null) ? null : userConfig.maxpageheight;
		this.p2br = (userConfig.p2br == null) ? false : userConfig.p2br;
		if (this.maxpageheight != null && this.maxpageheight > 0 && this.maxpageheight < this.height)
			this.maxpageheight = this.height;
		if (this.maxpageheight != null) 
			this.maxpagewidth = (userConfig.maxpagewidth == null || userConfig.maxpagewidth == 0) ? this.width - 6 : userConfig.maxpagewidth;
		else
			this.maxpagewidth = 0;
		this.onready = (userConfig.onready == null) ? null : userConfig.onready;
		this.parsewithoutattach = (userConfig.parsewithoutattach == null) ? false : userConfig.parsewithoutattach;
		this.topmenu = (userConfig.topmenu == null)?'HSTAP':userConfig.topmenu;
		var contentsval = (userConfig.data  == undefined || userConfig.data == null) ? editor_obj.obj.value : userConfig.data;
		var boundary = cafen.Editor.baseConf.boundary;
		this.attachtxt = this.contents = '';
		this.max_length = (userConfig.max_length == undefined)?65535:userConfig.max_length;
		if (contentsval !='') { 
			if (contentsval.indexOf('<?xml') == 0) {
				try {
					var xml = new cafen.xmlParser(contentsval);
					var channel = null;
					var item = null;
					channel = xml.getChannel(0);
					if (channel != null) {
						this.contents = channel.getNode('doc');
						this.initmode = channel.getNode('mode');
						var attachsize = parseInt(channel.getNode('attachsize'));
						if (attachsize > 0) {
							var attachfiles_channel = channel.getChannel('attachfiles');
							var attachFiles = [];
							while(item = attachfiles_channel.getNext()) {
								var fileInfo = [];
								fileInfo.push(item.getNode('server'));
								fileInfo.push(parseInt(item.getNode('size')));
								fileInfo.push(item.getNode('ext'));
								fileInfo.push(item.getNode('name'));
								fileInfo.push(item.getNode('extra'));
								attachFiles.push(fileInfo.join('|'));
							}
							this.attachtxt = attachFiles.join('#');
						}
					}
				} catch(ex){}
			} else if (contentsval.indexOf(boundary) > 0 || contentsval.indexOf('<div mode=') == -1 ) {
				var pat_reg = boundary + '(.*)' + boundary;
				var junk_arr = cafen.find(pat_reg,contentsval);
				var tmp_arr = (junk_arr.length > 0)? junk_arr[1].split("*") : [];
				switch(tmp_arr.length) {
					case 2 : 
						this.initmode = tmp_arr[0]; this.attachtxt = tmp_arr[1];
						break;
					case 1 : 
						this.initmode = tmp_arr[0]; this.attachtxt = '';
						break;
					default : 
						if (contentsval.toLowerCase().indexOf('<br') == -1 && contentsval.toLowerCase().indexOf('<p') == -1)
							contentsval = cafen.text2Html(contentsval);
						this.initmode = this.mode; this.attachtxt = junk_arr[1];
						break;
				}
				this.contents = contentsval.replace(eval('/' + boundary + '.*' +boundary +'/gi'), '');
			} else if (contentsval !='') {
				var obj = document.createElement('div');
				obj.innerHTML = contentsval;
				for(var i = 0; i < obj.childNodes.length ; i++) {
					var childNode = obj.childNodes[i];
					if (childNode.tagName != null) {
						switch(childNode.tagName.toLowerCase()) {
							case 'div' :
								var cAttrib = new cafen.Attribute(childNode);
								this.initmode = this.mode = cAttrib.get('mode',this.mode);
								this.contents = childNode.innerHTML;
								break;
							case 'select' :
								var attachFiles = [];
								for(var j = 0; j < childNode.length; j++) {
									var fileInfo = [];
									var attachAttrib = new cafen.Attribute(childNode[j]);
									fileInfo.push(attachAttrib.getString('server'));
									fileInfo.push(attachAttrib.getInt('size'));
									fileInfo.push(attachAttrib.getString('ext'));
									fileInfo.push(childNode[j].innerHTML);
									fileInfo.push(attachAttrib.getString('extra'));
									attachFiles.push(fileInfo.join('|'));
								}
								this.attachtxt = attachFiles.join('#');
								break;
						}
					}
				}
			}
		}
		if (this.initmode == '') 
			this.initmode = 'H';
		this.modeCurr = this.initmode;
		if (this.topmenu == 'OFF') {
			userConfig.swaptab = false;
			this.topmenu = '';
		} else if (this.topmenu == '')
			this.topmenu = 'HSTAP';
		if (!cafen.isContentEditable(false) && !cafen.isContentEditSupport()) {
			this.topmenu = this.topmenu.replace('H','');
			if (this.topmenu == '') {
				this.topmenu = 'TA';
				this.initmode = 'A';
			} else {
				if (this.initmode == 'H') {
					
					if (this.topmenu.indexOf('A') > -1) {
						this.contents = cafen.html2Text(this.contents);
						this.initmode = 'A';
					} else if (this.topmenu.indexOf('T') > -1) {
						this.contents = cafen.html2Text(this.contents);
						this.initmode = 'T';
					} else if (this.topmenu.indexOf('S') > -1) {
						this.initmode = 'S';
					}
				}
				this.mode = this.initmode;
			}
		}
		if (this.width < 500 && this.topmenu.length > 2 && this.topmenu != 'OFF') {
			this.topmenu = this.topmenu.substring(0,2);
		}
		if (this.topmenu != '') {
			if (this.topmenu.indexOf(this.initmode) == -1)
				this.initmode = this.topmenu.charAt(0);
			if (this.topmenu.indexOf(this.mode) == -1)
				this.mode = this.topmenu.charAt(0);
		}
		this.img_sign = (userConfig.img_sign == undefined)?'':userConfig.img_sign;
		this.linktitle = (userConfig.linktitle == undefined || userConfig.linktitle == '') ? null: cafen.$(userConfig.linktitle);
		this.file_box = (!cafenEditor_loader.editorBaseConf.useFilebox || userConfig.file_box == undefined) ? '' : userConfig.file_box;
		this.autosave = parseInt((userConfig.autosave == undefined)?0:userConfig.autosave);
		this.showattachsize = (userConfig.showattachsize == undefined)?2:userConfig.showattachsize;
		if (this.file_box == '')
			this.autosave = 0;
		this.attachfile_mode = (userConfig.attachfile_mode == undefined)?true:userConfig.attachfile_mode;
		this.simpleParse = (userConfig.simpleParse == undefined)?false:userConfig.simpleParse;
		this.skin = (userConfig.skin == undefined)?'hani':userConfig.skin;
		this.toogleSatus = {tool : true, attach : true};
		this.toogleSize = {tool : 50, attach : 70};
		this.tab_preview = (userConfig.tab_preview == undefined)?true:userConfig.tab_preview;
		this.tab_text = (userConfig.tab_text == undefined)?true:userConfig.tab_text;
		this.use_unloadevent = (userConfig.use_unloadevent == undefined)?false:userConfig.use_unloadevent;
		this.color_info = cafen.extend(cafen.Editor.baseConf.skin[this.skin], userConfig.color_info);
		
		if (userConfig.divui != undefined && userConfig.divui)
			userConfig.divui = true;
		else
			userConfig.divui = cafen.isMobile();
		this.useDivUI = userConfig.divui;
		if (userConfig.mobleui != undefined && userConfig.mobleui)
			userConfig.mobleui = true;
		else
			userConfig.mobleui = cafen.isMobile();
		this.useMobleUI = userConfig.mobleui;
		if (userConfig.toolbartext != undefined && userConfig.toolbartext !='') {
			var menuTxt = userConfig.toolbartext.split(',');
			userConfig.toolbar = [];
			for(var i = 0 ; i < menuTxt.length; i++) {
				userConfig.toolbar.push(menuTxt[i]);
			}
		}
		if (userConfig.toolbar == undefined) {
			this.toolbarset = (userConfig.toolbarset == undefined || cafen.Editor.baseConf.toolbarskin[userConfig.toolbarset] == undefined)? cafenEditor_loader.editorBaseConf.toolbarset :userConfig.toolbarset;
			switch(this.toolbarset.toLowerCase()) {
				case 'auto' :
					if (this.width < 470)
						this.toolbarset = 'autonarow';
					else if (this.width < 720)
						this.toolbarset = 'autosmall';
					else
						this.toolbarset = 'autowild';
					break;
				default :
					break;
			}
			if (cafen.Editor.baseConf.toolbarskin[this.toolbarset] == undefined)
				this.toolbarset = 'base';
			this.toolbar = cafen.Editor.baseConf.toolbarskin[this.toolbarset];
		} else 
			this.toolbar = userConfig.toolbar;
		if (this.useMobleUI) {
			this.useDivUI = true;
			if (userConfig.mobiletoolbartext != undefined && userConfig.mobiletoolbartext !='') {
				var menuTxt = userConfig.mobiletoolbartext.split(',');
				userConfig.mobiletoolbar = [];
				for(var i = 0 ; i < menuTxt.length; i++) {
					userConfig.mobiletoolbar.push(menuTxt[i]);
				}
			}
			if (userConfig.mobiletoolbar == undefined) {
				this.mobiletoolbarset = (userConfig.mobiletoolbarset == undefined || cafen.Editor.baseConf.toolbarskin[userConfig.mobiletoolbarset] == undefined)? cafenEditor_loader.editorBaseConf.mobiletoolbarset :userConfig.mobiletoolbarset;
				switch(this.mobiletoolbarset.toLowerCase()) {
					case 'auto' :
						if (this.width < 470)
							this.mobiletoolbarset = 'autonarow';
						else if (this.width < 720)
							this.mobiletoolbarset = 'autosmall';
						else
							this.mobiletoolbarset = 'autowild';
						break;
					default :
						break;
				}
				if (cafen.Editor.baseConf.toolbarskin[this.mobiletoolbarset] == undefined)
					this.mobiletoolbarset = 'base';
				this.mobiletoolbar = cafen.Editor.baseConf.toolbarskin[this.mobiletoolbarset];
			} else 
				this.mobiletoolbar = userConfig.mobiletoolbar;
		} else {
			this.mobiletoolbar = [];
		}
		if (userConfig.middlebar == undefined) {
			this.middlebarset = (userConfig.middlebarset == undefined || cafen.Editor.baseConf.middlebarskin[userConfig.middlebarset] == undefined)? cafenEditor_loader.editorBaseConf.middlebarset :userConfig.middlebarset;
			this.middlebar = cafen.Editor.baseConf.middlebarskin[this.middlebarset];
		} else 
			this.middlebar = userConfig.middlebar;
		this.middlebarontop = (userConfig.middlebarontop == undefined) ? cafenEditor_loader.editorBaseConf.middlebarontop : userConfig.middlebarontop;
		this.onloadfocus = (userConfig.onloadfocus == undefined) ? false : userConfig.onloadfocus;
		this.onloadhidetoolbar = (userConfig.onloadhidetoolbar == undefined) ? false : userConfig.onloadhidetoolbar;
		this.xmlParse = false;
		this.minHeight = this.editor_height = this.height - 30;
		if (userConfig.onChangeHeight != undefined) 
			this.onChangeHeight = userConfig.onChangeHeight;
		if (!cafenEditor_loader.checkUploadScript()) {
			this.attachfile_max = 0;
			this.file_box = '';
			this.autosave = 0;
		}
		this.swaptab	= (userConfig.swaptab == undefined)?true:userConfig.swaptab;
		this.allowiframe	= (userConfig.allowiframe == undefined)?false:userConfig.allowiframe;
	}
}


cafen.Editor.baseConf = {
/**
 * 기본 에디터 경로
 * @type string
 */
	_editor_url : 'http://service.cafen.net/',
/**
 * 브라우즈 IE 여부
 * @type boolean
 */
	isIE : window.ActiveXObject ? true : false,
	boundary : '@4d4e81d3f9219886bcadb3dc9b503f82@',
/**
 * 에디터 스킨
 * @type object
 */
	skin : {
		base : {
			editor_bg : '#f7f7f7', editor_line : '#dddddd', editor_font : '#000000',
			area_bg : '#ffffff',	area_line : '#ebebeb', area_font : '#000000',
			btn_on : '#ffffff',btn_off : '#efefef',btn_over : '#ffffff',btn_Bline : '#dddddd',btn_Wline : '#ffffff',
			attachImg : 'ico_attach.png', attach_bg : '#c8d8ed', attach_font : '#464646',
			class_Tab : 'r_tab', class_Box : 'r_boxblue', class_ButtonArea : 'r_boxblue', class_Editor : 'r_boxwhite', class_Button : 'r_wordset', class_Scale : 'r_editorattach', class_Attach : 'r_tbtnskin'
		},
		black : {
			editor_bg : '#434343', editor_line : '#404040', editor_font : '#ffffff',
			area_bg : '#434343',	area_line : '#434343', area_font : '#ffffff',
			btn_on : '#f3f3f3',btn_off : '#707070',btn_over : '#f3f3f3',btn_Bline : '#565656',btn_Wline : '#c1c1c1',
			attachImg : 'ico_attach_black.png', attach_bg : '#000000', attach_font : '#464646',
			class_Tab : 'r_tabblack', class_Box : 'r_boxblack', class_ButtonArea : 'r_boxblack', class_Editor : 'r_boxblack', class_Button : 'r_wordset-black', class_Scale : 'r_editorattach-black', class_Attach : 'r_tbtnskin-black'
		},
		white : {
			editor_bg : '#ffffff', editor_line : '#dddddd', editor_font : '#000000',
			area_bg : '#FFFFFF',	area_line : '#ebebeb', area_font : '#000000',
			btn_on : '#f3f3f3',btn_off : '#ffffff',btn_over : '#f3f3f3',btn_Bline : '#dddddd',btn_Wline : '#efefef',
			attachImg : 'ico_attach_gray.png', attach_bg : '#f5f5f5', attach_font : '#464646',
			class_Tab : 'r_tabwhite', class_Box : 'r_boxwhite', class_ButtonArea : 'r_boxwhite', class_Editor : 'r_boxwhite', class_Button : 'r_wordset-gray', class_Scale : 'r_editorattach-gray', class_Attach : 'r_tbtnskin-white'
		},
		silver : {
			editor_bg : '#e0e0e0', editor_line : '#919191', editor_font : '#000000',
			area_bg : '#e0e0e0',	area_line : '#e0e0e0', area_font : '#000000',
			btn_on : '#ffffff',btn_off : '#efefef',btn_over : '#ffffff',btn_Bline : '#919191',btn_Wline : '#dfdfdf',
			attachImg : 'ico_attach_gray.png', attach_bg : '#dfdfdf', attach_font : '#464646',
			class_Tab : 'r_tabgray', class_Box : 'r_boxgray', class_ButtonArea : 'r_boxgray', class_Editor : 'r_boxgray', class_Button : 'r_wordset-gray', class_Scale : 'r_editorattach-gray', class_Attach : 'r_tbtnskin-white'
		},
		whitenblack : {
			editor_bg : '#ffffff', editor_line : '#000000', editor_font : '#000000',
			area_bg : '#FFFFFF',	area_line : '#ebebeb', area_font : '#000000',
			btn_on : '#d7d7d7',btn_off : '#ffffff',btn_over : '#d7d7d7',btn_Bline : '#e9e9e9',btn_Wline : '#b3b3b3',
			attachImg : 'ico_attach_white.png', attach_bg : '#c3c3c3', attach_font : '#464646',
			class_Tab : 'r_tabblack', class_Box : 'r_boxblack', class_ButtonArea : 'r_boxblack', class_Editor : 'r_boxwhite', class_Button : 'r_wordset-black', class_Scale : 'r_editorattach-black', class_Attach : 'r_tbtnskin-black'
		},
		blue : {
			editor_bg : '#cfdff0', editor_line : '#cfdff0', editor_font : '#3b4546',
			area_bg : '#cfdff0',	area_line : '#cfdff0', area_font : '#000000',
			btn_on : '#b0e0e6',btn_off : '#67d8e6',btn_over : '#b0e0e6',btn_Bline : '#9eaab7',btn_Wline : '#c2e2e6',
			attachImg : 'ico_attach_white.png', attach_bg : '#cfdff0', attach_font : '#464646',
			class_Tab : 'r_tabblue', class_Box : 'r_boxblue', class_ButtonArea : 'r_boxblue', class_Editor : 'r_boxgray', class_Button : 'r_wordset-blue', class_Scale : 'r_editorattach-blue', class_Attach : 'r_tbtnskin-blue'
		},
		green : {
			editor_bg : '#e8f7d7', editor_line : '#77ad57', editor_font : '#3b4546',
			area_bg : '#e8f7d7',	area_line : '#e8f7d7', area_font : '#000000',
			btn_on : '#b0e0e6',btn_off : '#67d8e6',btn_over : '#b0e0e6',btn_Bline : '#d2f9c0',btn_Wline : '#cff8bd',
			attachImg : 'ico_attach_gray.png', attach_bg : '#bff4ad', attach_font : '#464646',
			class_Tab : 'r_tabgreen', class_Box : 'r_boxgreen', class_ButtonArea : 'r_boxgreen', class_Editor : 'r_boxgreen', class_Button : 'r_wordset-green', class_Scale : 'r_editorattach-green', class_Attach : 'r_tbtnskin-green'
		},
		red : {
			editor_bg : '#f3e2d5', editor_line : '#d7b69e', editor_font : '#3b4546',
			area_bg : '#f5ece6',	area_line : '#f5ece6', area_font : '#000000',
			btn_on : '#b0e0e6',btn_off : '#67d8e6',btn_over : '#b0e0e6',btn_Bline : '#af927e',btn_Wline : '#edc6ab',
			attachImg : 'ico_attach_gray.png', attach_bg : '#f5e3d7', attach_font : '#464646',
			class_Tab : 'r_tab-r', class_Box : 'r_boxred', class_ButtonArea : 'r_boxred', class_Editor : 'r_boxgray', class_Button : 'r_wordset-red', class_Scale : 'r_editorattach-red', class_Attach : 'r_tbtnskin-red'
		},
		hani : {
			editor_bg : '#f7f7f7', editor_line : '#dddddd', editor_font : '#000000',
			area_bg : '#FFFFFF',	area_line : '#ebebeb', area_font : '#000000',
			btn_on : '#ffffff',btn_off : '#efefef',btn_over : '#ffffff',btn_Bline : '#dddddd',btn_Wline : '#ffffff',
			attachImg : 'ico_attach.png', attach_bg : '#c8d8ed', attach_font : '#464646',
			class_Tab : 'r_tab', class_Box : 'r_btnskin', class_ButtonArea : 'r_boxblue', class_Editor : 'r_boxwhite', class_Button : 'r_wordset', class_Scale : 'r_editorattach'
		}
	},
/**
 * 툴바 스킨
 * @type object
 */
	toolbarskin : {
		base: [
			'group','fontname','fontsize','divblock','inserthtml','break',
			'group','bold','underline','italic','strikethrough','forecolor','backcolor','remove','break',
			'group','justifyleft','justifycenter','justifyright','createlink','unlink','translate','inserticon',
			'insertdb','find','break'
		],
		joins: [
			'group','fontname','fontsize','break',
			'group','bold','underline','italic','strikethrough','forecolor','backcolor','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','unorderedlist','break',
			'group','inserticon','horizontalrule','inserttable','createlink','unlink','divblock','insertmore','break'
		],
		joinssmall: [
			'group','fontname','break',
			'group','bold','underline','italic','strikethrough','forecolor','backcolor','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','unorderedlist','break',
			'linebreakb',
			'group','fontsize','break','group','inserticon','horizontalrule','inserttable','specialchar','separator','createlink','unlink','divblock','break'
		],
		power1: [
			'group','fontname','fontsize','break',
			'group','bold','underline','italic','strikethrough','subscript','superscript','remove','cut','copy','paste','redo','undo','break',
			'group','forecolor','backcolor','copystyle','pastestyle','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','break',
			'linebreakb',
			'group','fontblock','inserthtml','break',
			'group','createlink','unlink','orderedlist','unorderedlist','break',
			'group','insertmore','print','insertimage','insertmedia','translate','insertdb','break',
			'group','inserticon','divblock','horizontalrule','inserttable','specialchar','break'
		],
		autowild : [
			'group','fontname','fontsize','fontlarge','fontsmall','break',
			'group','bold','underline','italic','strikethrough','subscript','superscript','remove','break',
			'group','forecolor','backcolor','copystyle','pastestyle','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','break',
			'linebreakb',
			'group','fontblock','inserthtml','break',
			'group','createlink','unlink','orderedlist','unorderedlist','break',
			'group','insertmore','print','insertimage','insertmedia','translate','insertdb','break',
			'group','inserticon','divblock','horizontalrule','inserttable','specialchar','break'
		],
		autonarow : [
			'group','fontname','fontsize','fontlarge','fontsmall','break',
			'group','bold','underline','italic','strikethrough','subscript','superscript','remove','cut','copy','paste','break',
			'linebreakb',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','break',
			'group','forecolor','backcolor','copystyle','pastestyle','break',
			'group','inserticon','divblock','horizontalrule','inserttable','specialchar','break',
			'linebreakb',
			'group','fontblock','inserthtml','break',
			'group','createlink','unlink','orderedlist','unorderedlist','break',
			'group','insertmore','print','insertimage','insertmedia','translate','insertdb','break'
		],
		autosmall : [
			'group','fontname','fontsize','fontlarge','fontsmall','break',
			'group','bold','underline','italic','strikethrough','subscript','superscript','remove','break',
			'group','forecolor','backcolor','copystyle','pastestyle','break',
			'linebreakb',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','lineheight','break',
			'group','createlink','unlink','orderedlist','unorderedlist','break',
			'group','inserticon','divblock','horizontalrule','inserttable','specialchar','find','break',
			'linebreakb',
			'group','fontblock','inserthtml','break',
			'group','insertmore','print','insertimage','insertmedia','translate','insertdb','callhelper','break'
		],
		power2: [
			'group','fontname','fontsize','fontlarge','fontsmall','break',
			'group','bold','underline','italic','strikethrough','forecolor','backcolor','remove','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','unorderedlist','break',
			'linebreakb',
			'group','fontblock','break',
			'group','createlink','unlink','break',
			'group','copy','cut','paste','break',
			'group','separator','insertmovie','break',
			'group','divblock','inserticon','horizontalrule','inserttable','specialchar','break',
			'group','translate','insertdb','new','find','callhelper','break'
		],
		full: [
			'group','fontname','fontsize','fontlarge','fontsmall','break',
			'group','bold','underline','italic','strikethrough','subscript','superscript','forecolor','backcolor','remove','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','unorderedlist','orderedlist','break',
			'linebreak',
			'group','fontblock','break',
			'group','createlink','unlink','redo','undo','copy','cut','paste','inserticon','horizontalrule','inserttable','specialchar','break',
			'group','translate','insertdb','new','find','callhelper','break'
		],
		simple: [
			'group','fontname','fontsize','break',
			'group','bold','italic','underline','forecolor','backcolor','remove','createlink','unlink','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','break',
			'group','inserticon','inserttable','find','callhelper','break'
		],
		small: [
			'group','fontname','fontlarge','fontsmall','break',
			'group','bold','italic','underline','forecolor','backcolor','remove','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','find','callhelper','break'
		],
		mobile: [
			'group','fontlarge','fontsmall','bold','italic','underline','forecolor','backcolor','remove','break',
			'linebreakb',
			'group','justifyleft','justifycenter','justifyright','justifyfull','outdent','indent','unorderedlist','orderedlist','find','break',
		],
		nocolor: [
			'group','fontname','fontlarge','fontsmall','break',
			'group','bold','italic','underline','remove','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','find','callhelper','break'
		],
		noattach : [
			'group','fontname','fontlarge','fontsmall','break',
			'group','new','separator','bold','italic','underline','forecolor','backcolor','remove','createlink','unlink','break',
			'group','justifyleft','justifycenter','justifyright','justifyfull','break',
			'group','inserticon','inserttable','find','callhelper','break'
		]
	},
	middlebarskin : {
		base : [
			'left','center','right','del','image','map'
		],
		simple : [
			'del','left','center'
		],
		servicetop : [
			'image','map','del','left','center','right'
		],
		service : [
			'left','center','right','image','map','del'
		],
		attach : [
			'left','center','right','del'
		]
	},
/**
 * 버튼 정보
 * @type object
 */
	buttonInfo : cafenMsg.getObject('ed_buttonInfo'),
/**
 * 폰트 별명
 * @type object
 */
	fontname_alias : cafenMsg.getObject('ed_aliasfontnames'),
/**
 * 폰트 크기
 * @type object
 */
	fontsize_alias : cafenMsg.getObject('ed_aliasfontsizes'),
/**
 * 폰트 블륵
 * @type object
 */
	fontblock_alias : cafenMsg.getObject('ed_aliasfontblocks')
}



/**
 * cafen.Editor.conf
 * 에디터 스킨 정보 및 일반 정보
 * @class 에디터 스킨 정보 및 일반 정보
 * @constructor 
 * @param {object} color_info  에디터 색상정보
 */
cafen.Editor.conf = function(color_info) {
	this.initConf(color_info);	
};

cafen.Editor.conf.prototype = {
	initConf : function(color_info) {
		this._editor_url = cafen.Editor.baseConf._editor_url;
		this.options = cafen.extend(cafen.Editor.baseConf.skin.base,color_info);
		this.style_info = {
			btnBLine : this.options.btn_Bline + ' solid 1px',
			btnWLine : this.options.btn_Wline + ' solid 1px',
			editorLine : this.options.editor_line + ' solid 1px',
			areaLine : this.options.area_line + ' solid 1px'
		}
	},
/**
 * 에디터 스타일
 * @return {object}
 */
	editorStyle :function(width, height, display, padding) {
		if (display != '') {
			return {
				border : this.style_info.areaLine,
				padding: '0',
				margin : '0',
				scrollbarBaseColor : this.options.editor_bg,
				backgroundColor: this.options.area_bg,
				color: this.options.area_font,
				width : (width - 6) + 'px',
				height : height + 'px',
				display : display,
				lineHeight : '150%',
				fontSize: '9pt'
			}
		} else {
			return {
				border : this.style_info.areaLine,
				padding: '0',
				margin : '0',
				scrollbarBaseColor : this.options.editor_bg,
				backgroundColor: this.options.area_bg,
				color: this.options.area_font,
				width : (width - 6) + 'px',
				height : height + 'px',
				lineHeight : '150%',
				fontSize: '9pt'
			}
		}
	}, 
/**
 * 에디터 스크롤 스타일
 * @return {object}
 */
	editorScroll : function() {
		return {
			scrollbarBaseColor : this.options.editor_bg,
			backgroundColor : this.options.area_bg,
			color : this.options.area_font,
			resize:'none'
		}
	},
	getClassName : function(part) {
		switch(part) {
			case 'tab' : 
				return this.options.class_Tab;
				break;
			case 'box' :
				return this.options.class_Box;
				break;
			case 'buttonarea' :
				return this.options.class_ButtonArea;
				break;
			case 'editorarea' :
				return this.options.class_Editor;
				break;
			case 'buttonbg' :
				return this.options.class_Button;
				break;
			case 'attachbutton' :
				return this.options.class_Attach;
				break;
			case 'scale' :
				return this.options.class_Scale;
				break;
			default :
				return '';
				break;
		}
	},
/**
 * 이미지 경로 가져오기
 * @return {string}
 */
	imgURL : function() {
		return _cafen_service_url + 'images/';
	}
}


/**
 * cafen.Upload
 * 파일 업로드
 */
cafen.Editor.Upload = {
/**
 * 기본 업로드 SCRIPT
 * @type string
 */
	base_upload_script : null,
/**
 * 기본 업로드 URL
 * @type string
 */
	base_upload_url : null,
	base_uploaded_url : null,
/**
 * 기본 업로드 URL Domain
 * @type string
 */
	base_upload_domain : '',
/**
 * SWFUPLOAD.swf 파일 위치
 * @type string
 */
	flash_path : _cafen_service_url+'images/',
/**
 * 이미지 경로
 * @type string
 */
	base_image_url : _cafen_service_url +"editor/images/",
/**
 * 미디어 플레이어 사용여부
 * @type boolean
 */
	use_mediaplayer : false,
/**
 * 이미지 편집기 사용여부
 * @type boolean
 */
	use_imageeditor : false,
/**
 * 미디어 플레이어 정보
 * @type object
 */
	mediaplayer_info : {
		logo : 'http://service.cafen.net/images/logo_media.png',
		backColor : '0x000000',
		frontColor : '0xCCCCCC'
	},
/**
 * 싸인 앞첨자
 * @type string
 */
	imgsign_pre : '',
/**
 * 싸인 뒤첨자
 * @type string
 */
	imgsign_tail : '',
/**
 * 마지막 프리로드 함수
 * @type function
 */
	lastpreload_callback : null,
/**
 * 마지막 프리로드 ALERT 함수
 * @type function
 */
	lastpreload_alert : null,
/**
 * 이미지 프레임 정보
 * @type object
 */
	image_skin : null,
/**
 * 이미지 프레임 랜덤정보
 * @type array
 */
	image_skinrandom : null,
/**
 * 미디어 파일 자동 넣기
 * @type boolean
 */
	media_autotag : true,
/**
 * 이미지 회전 정보
 * @type object
 */
	image_rotate : cafenMsg.getObject('ed_imgrotate'),
/**
 * 마지막 접근 옵션
 * @type object
 */
	last_options : {upload_max_size:0, upload_filetypes:null},
/**
 * 마지막 생성 swfupload Object
 * @type object
 */
	last_swfuploadobj : null,
/**
 * 컴퓨터 파일 업로드
 * @param {object} options  옵션 정보
 */
	upload_local : function(options,replaceObj) {
		options = cafen.extend({
			upload_max_size : 1024*1024*100,
			upload_one_size : 1024*1024*1,
			autoBrowse : function() {},
			fileQueued : function() {},
			fileDialogStart : null,
			uploadFileStart : function() {},
			handleErrors : function() {},
			uploadProgress : function() {},
			uploadFileComplete : function() {},
			uploadQueueComplete : function() {},
			uploadCancel : function() {},
			upload_filetypes : 'all',
			use_frame : '',
			sign_txt : '',
			mybox_dir : '',
			button_placeholder_id : null,
			button_width : 76,
			button_height : 20,
			button_image_url : '',
			button_text_style : '',
			button_text: '',
			button_text_left_padding : 0,
			button_text_top_padding : 0,
			backgroundcolor : '#ffffff'
		}, options);
		var last_options = {upload_max_size : options.upload_max_size, upload_filetypes : options.upload_filetypes}
		this.last_options = last_options;
		this.options = options;
		if (options.button_placeholder_id != null && typeof options.button_placeholder_id == 'object') {
			this.options.button_width = parseInt(options.button_placeholder_id.style.width);
			this.options.button_height =parseInt(options.button_placeholder_id.style.height);
			options.button_placeholder_id = options.button_placeholder_id.getAttribute('id');
		}
		var fileTypeData = cafen.SwfUpload.getFileType(this.options.upload_filetypes);
		var filetypes_ext = fileTypeData[0];
		var filetypes_description = fileTypeData[1];
		var upload_url = (this.base_upload_script.indexOf('http://') == 0) ? this.base_upload_script : cafenEditor_loader.editorBaseConf.uploadDOMAIN + this.base_upload_script;
		var upload_options = {
			upload_url : upload_url,
			flash_url : this.flash_path+"swfupload.swf",
			file_size_limit : Math.round(Math.min(this.options.upload_one_size,this.options.upload_max_size)/1024),
			file_types : filetypes_ext,
			file_types_description : filetypes_description ,
			file_upload_limit : 1000,
			file_queue_limit : 100,
			swfupload_loaded_handler : this.autoBrowse.bind(this),
			file_dialog_start_handler : this.fileDialogStart.bind(this),
			file_queued_handler : this.fileDialogQueued.bind(this),
			file_dialog_complete_handler : this.fileDialogComplete.bind(this),
			upload_progress_handler : this.uploadProgress.bind(this),
			upload_success_handler : this.uploadFileComplete.bind(this),
			upload_complete_handler : this.uploadComplete.bind(this),
			file_queue_error_handler : this.handleErrors.bind(this),
			upload_error_handler : this.uploadError.bind(this),
//			button_placeholder : options.button_placeholder_id,
			button_placeholder_id : options.button_placeholder_id,
			button_width: options.button_width,
			button_height: options.button_height,
			button_text_style : options.button_text_style,
			button_text: '<span>'+options.button_text +'</span>',
			button_text_left_padding : options.button_text_left_padding,
			button_text_top_padding : options.button_text_top_padding,
			button_window_mode : cafen.browser.isIE ? 'window' : 'transparent',
			backgroundcolor : options.backgroundcolor,
			button_cursor : -2,
			button_image_url : options.button_image_url,
			debug : (typeof window.debug_mode == 'undefined') ? false : window.debug_mode
		};
		try {
			var uploadObj = new SWFUpload(upload_options);
		} catch(ex) {
			return ;
		}
		if (options.button_placeholder_id != null && options.button_placeholder_id != '' ) {
			var tmpObj = cafen.$(options.button_placeholder_id);
			tmpObj.uploadObj = uploadObj;
			tmpObj.uploadOptions = this.options;
			tmpObj.fileDialogStart = this.options.fileDialogStart;
			if (tmpObj.uploadObj != null && tmpObj.uploadObj.destroy) 
				tmpObj.uploadObj.destroy();
			tmpObj.uploadObj = uploadObj;
		}
		if (replaceObj != null) {
			replaceObj.uploadOptions = this.options;
			replaceObj.uploadObj.setFileUploadLimit(Math.round(this.options.upload_max_size/1024));
			replaceObj.uploadObj.setStats({
				in_progress: 0,
				files_queued: 0,
				successful_uploads: 0,
				upload_errors: 0,
				uploads_cancelled: 0,
				queue_errors: 0
			});
			if (replaceObj.uploadObj != this.last_swfuploadobj)
				this.last_swfuploadobj = replaceObj.uploadObj;
		} else {
			this.last_swfuploadobj = uploadObj;
		}
		return uploadObj;
	},
	fileDialogStart : function(obj) {
		if (obj != null && obj.uploadObj != null && obj.uploadOptions != null) {
			this.last_swfuploadobj = obj.uploadObj;
			this.options = obj.uploadOptions;
			if (obj.fileDialogStart != null) 
				obj.fileDialogStart();
		}
	},
/**
 * 리모터 파일 업로드
 * @param {object} options  옵션 정보
 */
	upload_remote : function(options) {
		this.options = cafen.extend({
			upload_max_size : 1024*1024,
			fileQueued : function() {},
			uploadFileStart : function() {},
			handleErrors : function() {},
			uploadProgress : function() {},
			uploadFileComplete : function() {},
			uploadQueueComplete : function() {},
			upload_filetypes : 'all',
			use_frame : '',
			sign_txt : '',
			mybox_dir : '',
			remote_url : '',
			save_name : '',
			move : 'N'
		}, options);
	 	new cafen.Ajax(
	 		{
				mode : 'remote',
	 			remote_url: this.options.remote_url, 
	 			move: this.options.move, 
	 			use_frame : this.options.use_frame ,
	 			save_name : this.options.save_name,
	 			use_sign : this.options.sign_txt
	 		}, this.remoteUploadEnd.bind(this)
	 		, ''
	 		,'post'
	 	);
	},
/**
 * 리모터 파일 업로드 종료
 * @param {cafen.xmlParser.Channel} channel  채널
 * @param  {string} msg  오류메세지
 */
	remoteUploadEnd : function(channel, msg) {
		var ufile = {}
		if (channel != null) {
			var item = null;
			var msg = null;
			var uploaded_seqn = 0;
			while(item = channel.getNext()) {
				if (item.getNode('fileext') != '') {
					if (this.options.move == 'Y') {
						ufile =	{
							size : parseInt(item.getNode('filesize')),
							extension : item.getNode('fileext'),
							server : item.getNode('fileserver'),
							sorce : item.getNode('filesorce'),
							fileName: item.getNode('filename'),
							width : parseInt(item.getNode('imgwidth')),
							height : parseInt(item.getNode('imgheight')),
							extra : item.getNode('extra')
						};
					} else {
						ufile =	{
							size : 0,
							extension : item.getNode('fileext'),
							server : item.getNode('fileserver'),
							sorce : item.getNode('filesorce'),
							fileName: item.getNode('filename'),
							width : parseInt(item.getNode('imgwidth')),
							height : parseInt(item.getNode('imgwidth')),
							extra : ''
						};
					}
					if (cafen.checkFileFilter(ufile)) {
						if (this.options.upload_filetypes == 'image' && !this.isImage(ufile)) 
							msg = cafenMsg.get('ed_0096');
						else {
							ufile.html_tag = this.makeTag(ufile, 'C', true);
							this.options.uploadFileComplete(ufile);
							uploaded_seqn++;
						}
					}
				}
			}
			if (uploaded_seqn == 0)
				this.options.handleErrors(cafenMsg.get('ed_0097'), '', ((msg)?msg:cafenMsg.get('ed_0098')));
		} else {
			this.options.handleErrors(cafenMsg.get('ed_0097'), '', cafenMsg.get('ed_0098'));
		}
		this.options.uploadQueueComplete(ufile);
	},
/**
 * 옵션 지정
 * @param {object} options  옵션
 */
	setOption : function(options) {
		this.options = cafen.extend(this.options, options);
	},
/**
 * 업로드 다이아로그 종료
 * @type object
 */
	uploadStat : {
		in_progress: 0,
		files_queued: 0,
		successful_uploads: 0,
		upload_errors: 0,
		uploads_cancelled: 0,
		queue_errors: 0
	},
/**
 * 자동 브라우징
 */
	autoBrowse : function() {
		try {
			if (typeof this.last_swfuploadobj.setPostParams == 'function')
				this.last_swfuploadobj.setPostParams({domain : document.domain, mode : 'upload'});
		} catch(ex) {
			
		}
	},
/**
 * 업로드 다이아로그 대기열 종료
 * @param {int} queuelength  파일선택수
 */
	fileDialogQueued : function(fileobj) {
		if(fileobj.size > 300000000) {
			this.last_swfuploadobj.cancelUpload(fileobj.id);
			this.handleErrors(fileobj, -500, '');
		} else {
			this.options.fileQueued(fileobj);
			var ext = '.tmp';
			if (fileobj.name.lastIndexOf('.') > 0)
				ext = fileobj.name.substring(fileobj.name.lastIndexOf('.') +1).toLowerCase();
			if (ext.length > 5)
				ext = '.aaa';
			this.last_swfuploadobj.addFileParam(fileobj.id, 'save_name',cafen.getUniqID('ed'));	
			this.last_swfuploadobj.addFileParam(fileobj.id, 'save_ext',ext);	
		}
	},
/**
 * 업로드 다이아로그 종료
 * @param {int} queuelength  파일선택수
 */
	fileDialogComplete : function(queuelength) {
		this.uploadComplete();
	},
/**
 * Upload 시작 
 * @param {string} id  파일ID
 */
	uploadComplete : function(ufile) {
		this.uploadStat = this.last_swfuploadobj.getStats();
		var uploaded_len = this.uploadStat.successful_uploads + this.uploadStat.upload_errors + this.uploadStat.upload_cancelled + this.uploadStat.queue_errors;
		var total_len = this.uploadStat.files_queued + this.uploadStat.successful_uploads + this.uploadStat.upload_errors + this.uploadStat.upload_cancelled + this.uploadStat.queue_errors;
		this.uploadFileStart(ufile, uploaded_len, total_len);
		if (this.uploadStat.files_queued > 0)
			this.last_swfuploadobj.startUpload();
		else 
			this.uploadQueueComplete(ufile);
	},
/**
 * 파일 Queue
 * @param {object} ufile  파일 Object
 * @param {int} queuelength  파일 Queue 갯수
 */
	fileQueued : function (ufile, queuelength) {
		this.options.fileQueued(ufile, queuelength);
	},
/**
 * 파일 업로드 시작
 * @param {object} ufile  파일 Object
 * @param {int} position  파일 위치
 * @param {int} queuelength  파일 Queue 갯수
 */
	uploadFileStart : function (ufile, position, queuelength) {
		this.options.uploadFileStart(ufile, position, queuelength);
	},
/**
 * 파일 업로드 진행
 * @param {object} ufile  파일 Object
 * @param {int} bytesLoaded  Upload 된 파일 크기
 */
	uploadProgress : function (ufile, bytes_complete, bytes_total) {
		this.options.uploadProgress(ufile, bytes_complete, bytes_total);
	},
/**
 * 파일 업로드 완료
 * @param {object} ufile  파일 Object
 * @param {string} response  결과값
 */
	uploadFileComplete : function (infile, response) {
		var channel, xml = new cafen.xmlParser(response);
		if (channel = xml.getNext()) {
			var item , msg = null;
			if (channel.checkMsg()) {
				var msg = channel.getMsg();
				this.options.handleErrors(msg.title, msg.domain, msg.contents);
			}
			while(item = channel.getNext()) {
				if (item.getNode('fileext') != '') {
					var ufile =	{
						size : parseInt(item.getNode('filesize')),
						extension : item.getNode('fileext'),
						server : item.getNode('fileserver'),
						sorce : item.getNode('filesorce'),
						fileName: item.getNode('filename'),
						width : parseInt(item.getNode('imgwidth')),
						height : parseInt(item.getNode('imgheight')),
						extra :  item.getNode('extra')
					}
					if (ufile.fileName == '') 
						ufile.fileName = infile.name;
					ufile = this.getFileObj(ufile);
					if (cafen.checkFileFilter(ufile)) {
						this.options.uploadFileComplete(ufile);
					}
				}
			}
		}
	},
/**
 * 파일 업로드 취소
 */
	uploadCancel : function() {
		this.options.uploadCancel();
	},
/**
 * 파일 정보 가져오기
 * @param {object} fileobj  파일 Object
 */
	getFileObj : function (imgobj) {
		if (this.isImage(imgobj))
			imgobj.html_tag = this.makeTag(imgobj, 'C');
		else
			imgobj.html_tag = '';
		return imgobj;
	},
/**
 * 파일 업로드 종료
 * @param {object} ufile  파일 Object
 */
	uploadQueueComplete : function (ufile) {
		this.options.uploadQueueComplete(ufile);
		this.last_options = {upload_max_size : -1, upload_filetypes : ''}
	},
/**
 * 파일 업로드 오류
 * @param {int} errno  오류번호
 */
	uploadError : function (file, error_code, message) {
		this.handleErrors(file, error_code, message);
	},
/**
 * 업로드 가능 파일 여부
 * @param {string} fileName  파일명
 * @return  {boolean} true|false
 */
	isUploadable : function(fileName) {
		return !cafen.find('(html|htm|php|php3|cgi|phtml|shtml|jsp|asp|exe|com|dll)$', fileName);
	},
/**
 * 오류 처리
 * @param {object} file  파일 Object
 * @param  {int} error_code  오류 코드
 * @param {int} msg_code  메세지 코드
 */
	handleErrors : function(ofile, error_code, msg_code) {
		if (ofile == null)
			ofile = {name :''}
		var error_info = cafen.SwfUpload.getErrorMsg(ofile, error_code);
		if (error_info.msg != '')
			this.options.handleErrors(error_info.title, ofile.name, error_info.msg);
	},
/**
 * 파일 아이콘 정보
 * @type object
 */
	attach_icon : {
		avi:'avi.gif', mov:'mov.gif', flv:'avi.gif', wma:'avi.gif', asf:'avi.gif', wav:'avi.gif', mp3:'mp3.gif',
		com:'com.gif', exe:'exe.gif', dll:'com.gif', 
		htm:'htm.gif', html:'htm.gif', docx:'doc.gif', doc:'doc.gif', hwp:'hwp.gif', 
		bmp:'bmp.gif', gif:'gif.gif',jpg:'jpg.gif', png:'jpg.gif', jpeg:'jpg.gif', psd:'psd.gif', tif:'tif.gif', 
		pdf:'pdf.gif', ppt:'ppt.gif', pptx:'ppt.gif', txt:'txt.gif', xls:'xls.gif',xlsx:'xls.gif',
		zip:'zip.gif', mcast : 'mcast.gif', etc:'etc.gif' 
	},
/**
 * 첨부 파일 아이콘 가져오기
 * @param {string} ext  확장자
 * @param {string} iconsize  아이콘 크기
 * @return {string} 아이콘 URL
 */
	getAttachIcon : function(ext, iconsize) {
		ext = ext.toLowerCase();
		var icon =  (this.attach_icon[ext] == null)?this.attach_icon.etc:this.attach_icon[ext]; 
		return this.base_image_url + 'ext/' + ((iconsize == null)?'s':'')+icon;
	},
/**
 * 썸네일 이미지 가져오기
 * @param {string} img_url  이미지 URL
 * @param {int} max_width  장축 크기
 * @return {string} 썸네일 URL
 */
	getNailImage : function(img_url, max_width) {
		return this.base_upload_url + 'thumb/' + img_url + '_M' + max_width +'.png';
	},
/**
 * 채널 파싱
 * @param {cafen.xmlParser} channel  채널
 * @return {object} 파싱된 Object
 */
	parseChannel : function(channel) {
		var item = null;
		var imgobj = {fileName:'',size:0,ext:'',server:'',width:0,height:0,extra : ''};
		while(item = channel.getNext()) {
			if (item.getNode('fileext') != '') {
				imgobj.size = parseInt(item.getNode('filesize'));
				imgobj.extension = item.getNode('fileext');
				imgobj.server = item.getNode('fileserver');
				imgobj.width = parseInt(item.getNode('imgwidth'));
				imgobj.height = parseInt(item.getNode('imgheight'));
				imgobj.extra = item.getNode('extra');
			}
		}
		if (imgobj.server == ''){
			return false;
		} else 
			return imgobj;
	},
/**
 * 이미지 여부 확인
 * @param {object} imgobj  파일 Object
 * @return  {string} 이미지 Object || null
 */
	isImage : function(imgobj) {
		if (imgobj != null && imgobj.size > 0 && imgobj.extension != null && imgobj.extension.match(/^(gif|jpg|png|jpeg)$/i)) {
			if (imgobj.img == null) {
				imgobj.img = new Image();
				if (this.base_uploaded_url != null && this.base_upload_url != this.base_uploaded_url) {
					if (	imgobj.server.indexOf("junk/") == 0) 
						imgobj.img.src = this.base_upload_url + imgobj.server;
					else 
						imgobj.img.src = this.base_uploaded_url + imgobj.server;
				} else {
					imgobj.img.src = this.base_upload_url + imgobj.server;
				}
			}
			return imgobj.img;
		} else
			return null;
	},
/**
 * 
 * 동영상 여부 확인
 * @param {object} imgobj  파일 Object
 * @return  {string} 동영상 경로 || null
 */
	isMovie : function(imgobj) {
		if (imgobj.extension != null && imgobj.extension.match(/(asf|mp3|mpeg|avi|wav|asx|wmv|wma|flv)$/i)) {
			return this.base_upload_url + imgobj.server;
		} else
			return null;
	},
/**
 * IE 7 버그 확인
 * @return  {boolean} ie7 & xp 여부 확인
 */
	checkIE7XP : function() {
		var UserAgentState = navigator.userAgent.toLowerCase();
		if (UserAgentState.indexOf('msie 7.0') != -1 && UserAgentState.indexOf('windows nt 5.1') != -1)
			return true;
		else
			return false;
	},
/**
 * 음악 파일 여부 확인
 * @param {object} imgobj  파일 Object
 * @return  {string} 음악 파일 경로 || null
 */
	isMusic : function(imgobj) {
		if (imgobj.extension != null && imgobj.extension.match(/(mp3|wav|wma)$/i)) {
			return this.base_upload_url + imgobj.server;
		} else
			return null;
	},
/**
 * 업로드 된파일 여부 확인
 * @param  {object} imgobj  파일 Object
 * @return  {boolean} true|false
 */
	isUploaded : function(imgobj) {
		return !(imgobj.server.match(/(^http:)|(^ftp:)|(^https:)|(^mms:)/i));
	},
	baseLimitSize : null,
/**
 * 태그 만들기
 * @param  {object} imgobj  파일 Object
 * @param  {string} tagalign  정렬
 * @param  {boolean} download  다운로드 적용여부
 * @param  {boolean} use_exra  Extra 정보 사용여부
 * @param  {int} img_width  이미지|동영상가로
 * @param  {int} img_height 이미지|동영상세로
 * @param  {string} sign 싸인
 * @return  {string} html
 */
	makeTag : function (imgobj, tagalign, download, use_exra, img_width, img_height, sign) {
		var str = '' , file_url = '', movie_url_img = '';
		var base_width = 400, base_height = 300;
		if (imgobj.server != '') {
			if (img_width != undefined)
				base_width = img_width;
			if (img_height != undefined)
				base_height = img_height;
			if (this.isUploaded(imgobj)) {
				if (this.use_mediaplayer && imgobj.extension =='flv') {
					file_url = this.base_upload_url + imgobj.server;
					if (imgobj.extra != '')
						movie_url_img = this.base_upload_url + imgobj.extra;
				} else  
					file_url = this.base_upload_url+imgobj.server;
			} else
				file_url = imgobj.server;
			
			var file_align = '', tag_pre = '', tag_end = '' ;
			switch(tagalign) {
				case 'L' : 
					file_align = ' align=left ';
					break;
				case 'C' : 
					tag_pre = '<div align=center width=100%>';
					tag_end = '</div><br>';
					break;
				case 'R' : 
					file_align = ' align=right ';
					break;
				default : 
					file_align = '';
					break;
			}
			if (file_url == '') {
				return '';
			} else if (this.isImage(imgobj)) {
				var addedTag = '';
				if (this.baseLimitSize != null) {
					var orgsize_width = parseInt(imgobj.width || imgobj.img.width);
					var orgsize_height = parseInt(imgobj.height || imgobj.img.height);
					var resize_width = orgsize_width;
					var resize_height = orgsize_height;
					if (	this.baseLimitSize.width < resize_width) {
						resize_width = 	this.baseLimitSize.width;
						resize_height = Math.round(this.baseLimitSize.width * orgsize_height / orgsize_width) ;
					} 
					if (this.baseLimitSize.height < resize_height) {
						resize_height = 	this.baseLimitSize.height;
						resize_width = Math.round(this.baseLimitSize.height * orgsize_width / orgsize_height) ;
					}
					var addedTagData1 = [];
					var addedTagData2 = [];
					if (orgsize_width != resize_width) {
						addedTagData1.push('width="'+resize_width+'px"');
						addedTagData2.push('width:'+resize_width+'px');
					}
					if (orgsize_height != resize_height) {
						addedTagData1.push('height="'+resize_height+'px"');
						addedTagData2.push('height:'+resize_height+'px');
					}
					if (addedTagData1.length > 0 || addedTagData2.length > 0) 
						addedTag = addedTagData1.join(' ') +' style="'+addedTagData2.join(';')+'" ';
				}
				str = tag_pre + '<img src="' + file_url + '" alt="'+imgobj.fileName+'"  border=0 class=cafenimg_resize  '+file_align+' '+addedTag+'>' + tag_end;
			} else if (this.media_autotag && this.isMusic(imgobj)) {
				str = this.getMediaPlayer(file_url, '', base_width, 20, file_align, tag_pre, tag_end);
			} else if (this.media_autotag && this.isMovie(imgobj)) {
				str = this.getMediaPlayer(file_url, movie_url_img, base_width, base_height, file_align, tag_pre, tag_end);
			} else if (this.media_autotag && imgobj.extension.match(/swf$/i)) {
				str = tag_pre + '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+imgobj.width+'" height="'+imgobj.height+'"'+file_align+'>'
					+ '<param name="movie" value="' + file_url + '">'
					+ '<param name="quality" value="high">'
					+ '<param name="wmode" value="transparent">'
					+ '<embed src="'+ file_url +'" width="'+base_width+'" height="'+base_width+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'
					+ '</OBJECT>' + tag_end;
			} else if(download) {
				if (cafenEditor_loader.editorBaseConf.downloadSCRIPT != null && cafenEditor_loader.editorBaseConf.downloadSCRIPT != '')
					file_url = cafenEditor_loader.editorBaseConf.downloadSCRIPT + '?fn=' + imgobj.server + '&dn=' +encodeURIComponent(imgobj.fileName);
				var filetxt = '<img src='+this.getAttachIcon(imgobj.extension, true)+' border=0 hspace=2 vspace=2 align=absmiddle> <a href="'+file_url+'">' + imgobj.fileName;
					+ '</a>';
				if (file_align != '')
					str = '<div '+file_align+'>'+filetxt+'</div>';
				else
					str = tag_pre + filetxt +tag_end ;
			} else 
				str = '';
		}
		return str;
		
	},
	getMediaPlayerParam : function(use_logo) {
		var params = '';
		if (use_logo && this.mediaplayer_info.logo != '')
			params += '&amp;logo=' + this.mediaplayer_info.logo;
		if (this.mediaplayer_info.backColor != '')
			params += '&amp;backcolor=' + this.mediaplayer_info.backColor;
		if (this.mediaplayer_info.frontColor != '')
			params += '&amp;frontcolor=' + this.mediaplayer_info.frontColor;
		return params;
	},

/**
 * 미디어 태그 만들기
 * @param {string} file_url  파일 Object
 * @param {string} movie_url_img  정렬
 * @param {int} img_width  이미지|동영상가로
 * @param  {int} img_height 이미지|동영상세로
 * @param  {string} file_align  정렬
 * @param  {string} tag_pre  태그 앞첨자
 * @param  {string} tag_end  태그 뒤첨자
 * @return  {string} html
 */
	getMediaPlayer : function(file_url, movie_url_img, base_width, base_height, file_align,tag_pre, tag_end) {
		var str = '';
		if (this.use_mediaplayer && file_url.match(/\.flv$/i)) {
			if (movie_url_img != '') {
				str = tag_pre + '<embed  id=cafenmedia_resize src="'+this.base_image_url+'mediaplayer.swf" '
					+ 'width="'+ base_width +'" height="'+ base_height +'" allowfullscreen="true" '
					+ 'flashvars="file='+ file_url+'&amp;image='+ movie_url_img+'&amp;height='+base_height + this.getMediaPlayerParam(true)
					+ '&width='+base_width+'&autostart=false&overstretch=true"'
					+ ' wmode="transparent" '+file_align+'></embed>' + tag_end;
			} else {
				str = tag_pre + '<embed id=cafenmedia_resize src="'+this.base_image_url+'mediaplayer.swf" '
					+ 'width="'+base_width+'" height="20" allowfullscreen="true" '
					+ 'flashvars="file='+ file_url+'&amp;height=20'+ this.getMediaPlayerParam(true)
					+ '&amp;width='+base_width+'&amp;autostart=false"'
					+ ' wmode="transparent" '+file_align+'></embed>' + tag_end;
			}
		} else {
			if (	movie_url_img != '') {
				str = tag_pre + '<embed  src="'+file_url+'" '
					+ 'width="'+base_width+'" height="'+base_height+'" autostart=false '
					+ ' wmode="transparent" '+file_align+'></embed>' + tag_end;
			} else {
				str = tag_pre + '<embed  src="'+file_url+'" '
					+ 'width="'+base_width+'" height="20"  autostart=false '
					+ ' wmode="transparent" '+file_align+'></embed>' + tag_end;
			}
		}
		return str;
	},
	/**
 * Upload 초기화
 */
	initUpload : function() {}
}


var cafenEditor_HTC = new cafenEditor();

cafen.checkLoad();

