/***********************************************************************
*	author			:	tae hun lim (soonsoo@gmail.com)
*	last modified	:	2010-01-18 15:33:09
***********************************************************************/
//	alert msg
var	ej_not_use_msg		=	"소스보기모드에서는 사용할 수 없습니다.";
var	ej_select_msg		=	"선택영역이 없습니다.";
//	array textarea
var ej_tarea_name		=	new Array();
//	css path
var ej_editor_path		=	"/Editor";
//	editor html path
var ej_html_path		=	ej_editor_path + "/Html";
//	editor image path
var ej_image_path		=	ej_editor_path + "/Images";
//	layer
var ej_layer			=	['eojin_font_ly','eojin_size_ly','eojin_fcolor_ly','eojin_bcolor_ly'];
//	array editor font
var editor_font			=	['Tahoma','Verdana','Arial','Gulim','Dotum','Batang','Gungsuh'];
//	array editor font size
var editor_size			=	['10px','12px','14px','16px','18px','20px','22px'];
var editor_real_size	=	[ '1',   '2',   '3',   '4',   '5',   '6',   '7'];
//	array font effect
var editor_effect		=	['bold','italic','underline','StrikeThrough','justifyleft','justifycenter','justifyright','outdent','indent','InsertFieldset','copy','paste','cut'];

//	array editor color
var editor_color		=	[
	'#fe1100','#fe4c24','#fe875a','#fecda7','#040967','#2d328d','#44499a','#686eb8','#669900','#66cc00','#99ff00','#ff99ff',
	'#6e0017','#7b243d','#834c6b','#66ffff','#006bd4','#0087e1','#37b7fe','#a7defe','#ffcc00','#ffff00','#fefe9f','#fefed0',
	'#4e003d','#6d2262','#926594','#c2a9c5','#005557','#03747b','#579d9f','#a2c6cc','#ff6600','#ff9933','#fecd8a','#fee2b0',
	'#1b0b73','#4c379d','#876eba','#bbbaef','#008e37','#26b168','#47be80','#76d3a2','#b31c00','#b03f21','#ae623a','#ac6e54',
	'#ffffff','#e6e6e6','#cdcdcd','#b4b4b4','#a8a8a8','#8d8d8d','#747474','#595959','#4b4b4b','#303030','#0a0a0a','#000000'
];
//	array editor button
var editor_btn_name		=	[
	'에디터','소스보기','글꼴','크기','글꼴색','배경색','굵게','기울게','밑줄',
	'취소선','좌측정렬','중앙정렬','우측정렬','내어쓰기','들여쓰기','필드셋','복사','붙여넣기',
	'자르기','테이블','이미지','미디어','플래시','링크','다음지도','에디터확대','에디터축소'
];
/*
var editor_btn_name		=	[
	'editor','html source','font','size','font color','background color','bold','italic','underline',
	'strike','align left','align center','align right','outdent','indent','fieldset','copy','paste',
	'cut','table','image','media','flash','link','map','zoon in','zoom out'
];
*/
var editor_button		=	[
//	    html		  editor		   font			size		font color		background		  bold			italic			underline
	'editor_html','editor_design','editor_face','editor_size','editor_fcolor','editor_bcolor','editor_bold','editor_italic','editor_underline',
//		strike			align left			align center		align right			outdent			indent			fieldset		copy		 paste
	'editor_strike','editor_alignleft','editor_aligncenter','editor_alignright','editor_outdent','editor_indent','editor_field','editor_copy','editor_paste',
//		cut			  table			image			media		  flash			link		  map
	'editor_cut','editor_table','editor_image','editor_media','editor_swf','editor_link','editor_map','editor_zoomin','editor_zoomout'
];
//	array popup effect
var editor_popup		=	['table','image','media','flash','link','map'];
var editor_pop_width	=	['350','350','350','350','350','668'];
var editor_pop_height	=	['200','170','140','140','170','650'];

//	create toolbar
function ej_toolbar(icon, i, tStyle, tPrint) {
	var icon_path	=	ej_image_path + "/" + icon;
	var Toolbar		=	'';
		//	effect layer start
		//	font layer
		Toolbar		+=	'<div id="eojin_font_ly' + i + '" onmouseover="this.style.display=\'inline\';" onmousemove="this.style.display=\'inline\';" onmouseout="ej_layer_close(' + i + ');" style="position:absolute; z-index:999; width:80px; border:1px solid #ddd; background:#fff; display:none;">';
		for(var xx = 0; xx < editor_font.length; xx++) {
			Toolbar	+=	'<ul style="list-style:none;">';
			Toolbar	+=	'<li style="list-style:none; cursor:pointer; _cursor:hand; padding:3px 5px;" onmouseover="this.style.backgroundColor=\'#eee\';" onmouseout="this.style.backgroundColor=\'#fff\';" onmousedown="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'fontname\', false, \'' + editor_font[xx] + '\', \'' + i + '\');"><font style="font-size:12px; font-family:' + editor_font[xx] + ';">' + editor_font[xx] + '</font></li>';
			Toolbar	+=	'</ul>';
		}
		Toolbar		+=	'</div>';
		//	size layer
		Toolbar		+=	'<div id="eojin_size_ly' + i + '" onmouseover="this.style.display=\'inline\';" onmousemove="this.style.display=\'inline\';" onmouseout="ej_layer_close(' + i + ');" style="position:absolute; z-index:998; width:80px; border:1px solid #ddd; background:#fff; display:none;">';
		for(var xx = 0; xx < editor_size.length; xx++) {
			Toolbar	+=	'<ul style="list-style:none;">';
			Toolbar	+=	'<li style="list-style:none; cursor:pointer; _cursor:hand; padding:3px 5px;" onmouseover="this.style.backgroundColor=\'#eee\';" onmouseout="this.style.backgroundColor=\'#fff\';" onmousedown="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'fontsize\', false, \'' + editor_real_size[xx] + '\', \'' + i + '\');\"><font style="font-size:' + editor_size[xx] + ';">' + editor_size[xx] + '</font></li>';
			Toolbar	+=	'</ul>';
		}
		Toolbar		+=	'</div>';

		//	font color layer
		Toolbar		+=	'<div id="eojin_fcolor_ly' + i + '" onmouseover="this.style.display=\'inline\';" onmousemove="this.style.display=\'inline\';" onmouseout="ej_layer_close(' + i + ');" style="position:absolute; z-index:997; width:192px; border-top:1px solid #000; border-left:1px solid #000; display:none;">';
		for(var xx = 0; xx < editor_color.length; xx++) {
			Toolbar	+=	'<ul style="list-style:none; margin:0; padding:0; border:0;">';
			Toolbar	+=	'<li style="float:left; list-style:none; cursor:pointer; _cursor:hand; border-right:1px solid #000; border-bottom:1px solid #000; width:15px; height:15px; margin:0; padding:0; background:' + editor_color[xx] + ';" onmousedown="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'forecolor\', false, \'' + editor_color[xx] + '\', \'' + i + '\');"><img src="' + ej_image_path + '/blank.gif" width="14" height="14" border="0" /></li>';
			Toolbar	+=	'</ul>';
			//if(xx % 12 == 11)	Toolbar	+=	'<br style="clear:both; margin:0; padding:0; border:0;" />';
		}
		Toolbar		+=	'</div>';
		//	background color layer
		Toolbar		+=	'<div id="eojin_bcolor_ly' + i + '" onmouseover="this.style.display=\'inline\';" onmousemove="this.style.display=\'inline\';" onmouseout="ej_layer_close(' + i + ');" style="position:absolute; z-index:996; width:192px; border-top:1px solid #000; border-left:1px solid #000; display:none;">';
		for(var xx = 0; xx < editor_color.length; xx++) {
			Toolbar	+=	'<ul style="list-style:none; margin:0; padding:0; border:0;">';
			Toolbar	+=	'<li style="float:left; list-style:none; cursor:pointer; _cursor:hand; border-right:1px solid #000; border-bottom:1px solid #000; width:15px; height:15px; margin:0; padding:0; background:' + editor_color[xx] + ';" onmousedown="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'backcolor\', false, \'' + editor_color[xx] + '\', \'' + i + '\');"><img src="' + ej_image_path + '/blank.gif" width="14" height="14" border="0" /></li>';
			Toolbar	+=	'</ul>';
			//if(xx % 12 == 11)	Toolbar	+=	'<br style="clear:both; margin:0; padding:0; border:0;" />';
		}
		Toolbar		+=	'</div>';
		//	effect layer end

		//	toolbar start
		Toolbar		+=	'<ul style="float:left; list-style:none;">';

		//	source & editor change
		Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[1] + i + '" src="' + icon_path + '/' + editor_button[1] + '.gif" style="display:none; cursor:pointer; _cursor:hand;" alt="' + editor_btn_name[0] + '" onclick="ej_editor_change(\'' + ej_tarea_name[i] + '\', \'' + i + '\');" />';
			Toolbar		+=	'<img id="' + editor_button[0] + i + '" src="' + icon_path + '/' + editor_button[0] + '.gif" style="cursor:pointer; _cursor:hand;" alt="' + editor_btn_name[1] + '" onclick="ej_editor_change(\'' + ej_tarea_name[i] + '\', \'' + i + '\');" />';
		Toolbar		+=	'</li>';

		//	font
		Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[2] + i + '" src="' + icon_path + '/' + editor_button[2] + '.gif" alt="' + editor_btn_name[2] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_show_layer(' + i + ', \'' + ej_layer[0] + i + '\');" />';
		Toolbar		+=	'</li>';

		//	size
		Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[3] + i + '" src="' + icon_path + '/' + editor_button[3] + '.gif" alt="' + editor_btn_name[3] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_show_layer(' + i + ', \'' + ej_layer[1] + i + '\');" />';
		Toolbar		+=	'</li>';

		//	font color
		Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[4] + i + '" src="' + icon_path + '/' + editor_button[4] + '.gif" alt="' + editor_btn_name[4] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_show_layer(' + i + ', \'' + ej_layer[2] + i + '\');" />';
		Toolbar		+=	'</li>';

		//	background color
		Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[5] + i + '" src="' + icon_path + '/' + editor_button[5] + '.gif" alt="' + editor_btn_name[5] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_show_layer(' + i + ', \'' + ej_layer[3] + i + '\');" />';
		Toolbar		+=	'</li>';

		//	button list
		for(var xx = 6; xx <= 12; xx++) {
			var ss = xx - 6;
			Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
			Toolbar		+=	'<img id="' + editor_button[xx] + i + '" src="' + icon_path + '/' + editor_button[xx] + '.gif" alt="' + editor_btn_name[xx] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'' + editor_effect[ss] + '\', false, null, \'' + i + '\');" />';
			Toolbar		+=	'</li>';
		}
		//	all print
		if(tPrint == "1") {
			//	two line print
			if(tStyle == "2") {
				Toolbar	+=	'<br style="clear:both;" />';
			}
			//	button list
			for(var xx = 13; xx <= 18; xx++) {
				var ss = xx - 6;
				Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
				Toolbar		+=	'<img id="' + editor_button[xx] + i + '" src="' + icon_path + '/' + editor_button[xx] + '.gif" alt="' + editor_btn_name[xx] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_html_exe(\'' + ej_tarea_name[i] + '\', \'' + editor_effect[ss] + '\', false, null, \'' + i + '\');" />';
				Toolbar		+=	'</li>';
			}
			//	pop button list
			for(var xx = 19; xx < 25; xx++) {
				var ss = xx - 19;
				var	scroll	=	(xx == 24)	?	1 : 0;
				Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
				Toolbar		+=	'<img id="' + editor_button[xx] + i + '" src="' + icon_path + '/' + editor_button[xx] + '.gif" alt="' + editor_btn_name[xx] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_win_open(' + i + ', \'' + editor_popup[ss] + '\', \'' + editor_pop_width[ss] + '\', \'' + editor_pop_height[ss] + '\', \''+scroll+'\', \'0\', \'eojin_editor_popup\');" />';
				Toolbar		+=	'</li>';
			}
			//	editor zoom
			for(var xx = 25; xx < editor_button.length; xx++) {
				var ss = xx - 25;
				var	zoom	=	(xx == editor_button.length - 1)	?	0 : 1;
				Toolbar		+=	'<li style="float:left; list-style:none; padding:0 3px 3px 0;">';
				Toolbar		+=	'<img id="' + editor_button[xx] + i + '" src="' + icon_path + '/' + editor_button[xx] + '.gif" alt="' + editor_btn_name[xx] + '" style="cursor:pointer; _cursor:hand;" onclick="ej_editor_zoom(\'' + ej_tarea_name[i] + '\', ' + zoom + ');" />';
				Toolbar		+=	'</li>';
			}
		}
		Toolbar		+=	'</ul>';
		Toolbar		+=	'<br style="clear:both;"/>';
		//	toolbar end
	return Toolbar;
}

//	source & editor change
function ej_editor_change(t_name, no) {
	//	view html
	if(document.getElementById(editor_button[1] + no).style.display == "none") {
		//	툴바 투명 숨기기
		ej_editor_menu_status(no, '0.3', '', true);
		document.getElementById('aChim_' + t_name).style.display		=	"none";
		document.getElementsByName(t_name)[0].style.display				=	"inline";
		document.getElementById(editor_button[0] + no).style.display	=	"none";
		document.getElementById(editor_button[1] + no).style.display	=	"inline";
		document.getElementsByName(t_name)[0].value						=	document.getElementById('aChim_' + t_name).contentWindow.document.body.innerHTML;
		document.getElementsByName(t_name)[0].focus();
	}
	else {
		//	툴바 보이기
		ej_editor_menu_status(no, '1.0', 'pointer', false);
		document.getElementById('aChim_' + t_name).style.display		=	"inline";
		document.getElementsByName(t_name)[0].style.display				=	"none";
		document.getElementById(editor_button[0] + no).style.display	=	"inline";
		document.getElementById(editor_button[1] + no).style.display	=	"none";
		document.getElementById('aChim_' + t_name).contentWindow.document.body.innerHTML		=	document.getElementsByName(t_name)[0].value;
		document.getElementById('aChim_' + t_name).contentWindow.focus();
	}
}
//	toolbar opacity
function ej_editor_menu_status(no, opaVal, pointer, clk) {
	var editor_button_length		=	editor_button.length;
	for(var i = 2; i < editor_button_length; i++) {
		if(document.getElementById(editor_button[i] + no)) {
			document.getElementById(editor_button[i] + no).disabled			=	clk;
			document.getElementById(editor_button[i] + no).style.cssText	=	"opacity:"+opaVal+"; filter:alpha(opacity="+(opaVal * 100)+");";
			if(navigator.userAgent.indexOf('MSIE 5.5') > 0) {
				document.getElementById(editor_button[i] + no).style.cursor		=	"hand";
			} else {
				document.getElementById(editor_button[i] + no).style.cursor		=	"pointer";
			}
		}
	}
}
//	show layer
function ej_show_layer(no, layer) {
	ej_layer_close(no);
	if(layer) {
		document.getElementById(layer).style.display	=	"inline";
		document.getElementById(layer).style.left		=	now_mouse_x - 35 + "px";
		document.getElementById(layer).style.top		=	now_mouse_y + 10 + "px";
	}
}
//	effect
function ej_html_exe(t_name, exe, bool, value, no) {
	if(document.getElementById('aChim_' + t_name).style.display != "none") {
		var ejEditors	=	document.getElementById('aChim_' + t_name).contentWindow;
		document.getElementById('aChim_' + t_name).contentWindow.focus();
		if(navigator.appName != "Microsoft Internet Explorer" && exe == "backcolor")	exe = "hilitecolor";
		ejEditors.document.execCommand(exe, bool, value);
		ej_copy_2_html();
		document.getElementById('aChim_' + t_name).contentWindow.focus();
		ej_layer_close(no);
	} else {
		alert(ej_not_use_msg);	//	소스보기모드에서는 사용할 수 없습니다.
		ej_layer_close(no);
	}
}
//	editor zoom
function ej_editor_zoom(t_name, zoom) {
	//	zoom : 1 = 확대, 0 = 축소
	var obj		=	document.getElementById('aChim_' + t_name);
	var	tarea	=	document.getElementsByName(t_name)[0];
	tmp			=	obj.style.height.replace(/[^\d]/g,'');
	//	클릭시 확대 또는 축소될 값
	var	ckSize	=	20;
	if(zoom == 1)	tmp	=	parseInt(tmp) + ckSize;
	else			tmp	=	parseInt(tmp) - ckSize;
	if(tmp < 100)	tmp	=	100;	//	setting min height
	if(tmp > 1500)	tmp	=	1500;	//	setting max height
	obj.style.height	=	tmp + 'px';
	tarea.style.height	=	tmp + 'px';
}
//	add effect
function ej_copy_2_html() {
	for(var i = 0; i < ej_tarea_name.length; i++) {
		document.getElementsByName(ej_tarea_name[i])[0].value	=	document.getElementById("aChim_" + ej_tarea_name[i]).contentWindow.document.body.innerHTML;
	}
}
function ej_copy_2_editor() {
	for(var i = 0; i < ej_tarea_name.length; i++) {
		document.getElementById("aChim_" + ej_tarea_name[i]).contentWindow.document.body.innerHTML	=	document.getElementsByName(ej_tarea_name[i])[0].value;
	}
}
//	hide effect layer
function ej_layer_close(no) {
	if(document.getElementById(ej_layer[0] + no))		document.getElementById(ej_layer[0] + no).style.display	=	"none";
	if(document.getElementById(ej_layer[1] + no))		document.getElementById(ej_layer[1] + no).style.display	=	"none";
	if(document.getElementById(ej_layer[2] + no))		document.getElementById(ej_layer[2] + no).style.display	=	"none";
	if(document.getElementById(ej_layer[3] + no))		document.getElementById(ej_layer[3] + no).style.display	=	"none";
}
//	show popup window
var ej_editor_popup_windows	=	null;
function ej_win_open(uid,URL,W,H,S,R,N) {
	if(document.getElementById("aChim_" + ej_tarea_name[uid]).style.display != "none") {
		document.getElementById("aChim_" + ej_tarea_name[uid]).contentWindow.focus(); // 팝업을 띄우기 전에 포커스를 layer로 간다.

		var WINWIDTH = (screen.width-W)/2;
		var WINHEIGHT = (screen.height-H)/2;
		var PopSet  ='width='+W+',';
		PopSet  +='height='+H+',';
		PopSet  +='top='+WINHEIGHT+',';
		PopSet  +='left='+WINWIDTH+',';
		PopSet  +='scrollbars='+S+',';
		PopSet  +='resizable='+R;
		ej_editor_popup_windows	 =	window.open(ej_html_path + "/create." + URL + ".html?elementID=aChim_" + ej_tarea_name[uid], N, PopSet);
		if(parseInt(navigator.appVersion) >= 4)	 ej_editor_popup_windows.window.focus();

		//window.open(ej_html_path + "/create." + URL + ".html?elementID=aChim_" + ej_tarea_name[uid], N, 'width='+W+',height='+H+',scrollbars='+S+',resizable='+R);
	}
	else	alert(ej_not_use_msg);
}
//	check Browser
function chkBrowser() {
	var browser;
	var	appname		=	navigator.appName;
	var	useragent	=	navigator.userAgent.toLowerCase();
	if(useragent.indexOf('msie') != -1)				browser	=	"ie";
	else if(useragent.indexOf('firefox') != -1)		browser	=	"ff";
	else if(useragent.indexOf('chrome') != -1)		browser	=	"cr";
	else if(useragent.indexOf('safari') != -1)		browser	=	"sf";
	else if(useragent.indexOf('opera') != -1)		browser	=	"op";
	return browser;
}

//	eojin editor
function eojinEditor() {
	var tmp				=	0;
	var ej_tarea_obj	=	document.getElementsByTagName("TEXTAREA");

	/***
	 *
	 * 구분자는 : 에디터여부, 아이콘, 툴바(1=전체,2=간단), 두줄출력
	 * editor:big:1:2
	 *
	 ***/
	for(var i = 0; i < ej_tarea_obj.length; i++) {
		if(ej_tarea_obj[i].getAttribute("lang") && ej_tarea_obj[i].getAttribute("lang").substring(0,6) == "editor") {
			ej_tarea_name[tmp] = ej_tarea_obj[i].getAttribute("name");
			tmp++;
		}
	}
	//	lang="editor:big:1:2"
	for(var i = 0; i < ej_tarea_name.length; i++) {
		var ej_tarea_org = document.getElementsByName(ej_tarea_name[i])[0];

		//	create iframe
		var ej_create_iframe	=	document.createElement("IFRAME");
		ej_create_iframe.setAttribute("id","aChim_" + ej_tarea_name[i]);
		ej_create_iframe.setAttribute("name","aChim_" + ej_tarea_name[i]);
		ej_create_iframe.setAttribute("scrolling","auto");
		ej_create_iframe.setAttribute("frameBorder","no");
		ej_create_iframe.setAttribute("marginWidth","0");
		ej_create_iframe.setAttribute("marginHeight","0");
		ej_create_iframe.setAttribute("wrap","");
		ej_create_iframe.style.width = "98%";
		ej_create_iframe.style.height = ej_tarea_org.style.height;
		ej_create_iframe.style.border = "1px solid #ddd";
		ej_create_iframe.style.padding = "3px";
		//ej_create_iframe.onmouseover = new Function("ej_show_layer('" + i + "');");
		ej_tarea_org.parentNode.insertBefore(ej_create_iframe,ej_tarea_org);

		var ej_ifrm_doc = document.getElementById("aChim_" + ej_tarea_name[i]).contentWindow;
		ej_ifrm_doc.document.open();
		ej_ifrm_doc.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
		ej_ifrm_doc.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ko\" xml:lang=\"ko\">");
		ej_ifrm_doc.document.write("<html>");
		ej_ifrm_doc.document.write("<head>");
		ej_ifrm_doc.document.write("<title>editor</title>");
		ej_ifrm_doc.document.write("<link href=\"" + ej_editor_path + "/editor.css\" rel=\"stylesheet\" type=\"text/css\" />");
		ej_ifrm_doc.document.write("</head><body>" + ej_tarea_org.value + "</body></html>");
		ej_ifrm_doc.document.close();
		ej_ifrm_doc.document.designMode = "on";
		ej_tarea_org.style.backgroundColor = "#fff";
		ej_tarea_org.style.padding = "3px";
		ej_tarea_org.style.border = "1px solid #ddd";
		ej_tarea_org.style.color = "#999";
		ej_tarea_org.style.fontSize = "12px";
		ej_tarea_org.style.fontFamily = "tahoma";
		ej_tarea_org.style.display = "none";

		if(document.addEventListener) {
			ej_ifrm_doc.document.addEventListener("mousedown", ej_copy_2_html, false);
			ej_ifrm_doc.document.addEventListener("keydown", ej_copy_2_html, false);
			ej_ifrm_doc.document.addEventListener("keyup", ej_copy_2_html, false);
			ej_ifrm_doc.document.addEventListener("blur", ej_copy_2_html, false);
			ej_tarea_org.addEventListener("mousedown", ej_copy_2_editor, false);
			ej_tarea_org.addEventListener("keydown", ej_copy_2_editor, false);
			ej_tarea_org.addEventListener("keyup", ej_copy_2_editor, false);
			ej_tarea_org.addEventListener("blur", ej_copy_2_editor, false);
		} else if(document.attachEvent) {
			ej_ifrm_doc.document.attachEvent("onmousedown", ej_copy_2_html, false);
			ej_ifrm_doc.document.attachEvent("onkeydown", ej_copy_2_html, false);
			ej_ifrm_doc.document.attachEvent("onkeyup", ej_copy_2_html, false);
			ej_ifrm_doc.document.attachEvent("onblur", ej_copy_2_html, false);
			ej_tarea_org.attachEvent("onmousedown", ej_copy_2_editor, false);
			ej_tarea_org.attachEvent("onkeydown", ej_copy_2_editor, false);
			ej_tarea_org.attachEvent("onkeyup", ej_copy_2_editor, false);
			ej_tarea_org.attachEvent("onblur", ej_copy_2_editor, false);
		}

		$(ej_ifrm_doc.document).bind("keydown", function(event) {
			event	=	event || window.event;
			var keycode		=	event.which || event.keyCode;
			var aChimIfrm	=	ej_ifrm_doc.document;
			var	browser		=	chkBrowser();
			var	selection	=	(browser == "ie")	?	aChimIfrm.selection.createRange() : aChimIfrm.getSelection().getRangeAt(0);
			if(keycode == 13) {
				if(browser == "ie" || browser == "ff" || browser == "op") {
					event.returnValue = false;
					if(browser == "ie")	event.cancelBubble = true;
					if(browser == "ff")	event.stopPropagation = true;
					selection.pasteHTML("<br />");
					selection.collapse(false);
					selection.select();
				}
				else {
					selection.pasteHTML("<br />");
				}
				//	enter => save to textarea
				ej_tarea_org.value	=	aChimIfrm.body.innerHTML;
				aChimIfrm.focus();
				return false;
			}
			//	enter => save to textarea
			ej_tarea_org.value	=	aChimIfrm.body.innerHTML;
			aChimIfrm.focus();
		});
		$(ej_ifrm_doc.document).bind("keyup", function(event) {
			event	=	event || window.event;
			var keycode			=	event.which || event.keyCode;
			var aChimIfrm		=	ej_ifrm_doc.document;
			ej_tarea_org.value	=	aChimIfrm.body.innerHTML;
			aChimIfrm.focus();
		});

		//	textarea에서의 에디터 설정값
		var	ej_setting	=	ej_tarea_org.getAttribute("lang").split(":");
		//	icon="big" 아이콘 형태 결정
		var iconSelect	=	(ej_setting[1] == "small")	?	"small" :"big";
		//	툴바 출력 아이콘 설정
		var toolprint	=	(ej_setting[2] == "2")		?	"2"	:	"1";
		//	툴바를 한줄로 할래 두줄로 할래? toolbar="1"
		var toolStyle	=	(ej_setting[3] == "2")		?	"2"	:	"1";
		//	기본 툴바만 출력시 (toolprint = 2)일때는 툴바를 무조건 한줄로 출력
		if(toolStyle == "2" && toolprint == "2")		toolStyle = "1";

		// 툴바 출력
		var ej_toolbars	=	ej_toolbar(iconSelect, i, toolStyle, toolprint);

		var aChimDivObj	=	document.createElement("div");
		//aChimDivObj.style.position = "relative";
		ej_create_iframe.parentNode.insertBefore(aChimDivObj,ej_create_iframe);
		aChimDivObj.innerHTML = ej_toolbars;
	}
}
