////////////////////////////////////////////////////////////////////////////////////
//
//	R2Na Editor 3.0b4
//
// - 20070627 Wed
//
////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////
//
// 설정
//
////////////////////////////////////////////////////////////////////////////////////
var R2Na_root = "/inc/R2Na"; // 에디터가 설치된 URL
var Neko_root = "/inc/neko_upper";
var baseCSS = "/css/zardsama.php"; // 기본 CSS

var R2NaIDs = new Array ();
var is_IE = (window.showModelessDialog) ? true : false;
var is_gekko = ( navigator.userAgent.toLowerCase().indexOf('gecko') > -1 ) ? true : false;

include (R2Na_root+"/classes/R2Na_pallete.js");
include (R2Na_root+"/classes/R2Na_table.js");


////////////////////////////////////////////////////////////////////////////////////
//
//	에디터 호출
//
////////////////////////////////////////////////////////////////////////////////////
R2Na = function (bid, css, framedesign){

	if ( document.getElementById (bid) == null ) return false;

	// R2Na 클래스 변수 선언
	this.sNo = R2NaIDs.length;			// 에디터 시리얼 넘버
	this.oWe;									// R2Na 베이스 레이어
	this.t_textarea;							// HTML 수정창
	this.o_textarea;							// 원본 텍스트 에리어
	this.R2Na_tools;							// 툴바 에리어
	this.R2Na_area;							// 위지윅 에디터 에리어
	this.R2Na_DOM;							// DOM Navigater 에리어
	this.o_PArea	;							// 팔레트 출력창
	this.o_Tbl;									// 테이블 입력창
	this.nekobody;							// Neko™ 프레임
	this.css = css;							// 에디터 CSS 파일 지정		
	this.framedesign = framedesign;	// Frame Border 출력여부
	this.useDOM = false;					// DOM Navigator 사용여부
	this.colorMode;							// 팔레트 모드 0 = 글자색, 1 = 배경색
	this.currentEditor = false;				// Neko™ 연동 에디터 윈도우 

	// 기존의 텍스트 에리어를 찾아서 백업
	this.t_textarea = document.getElementById (bid);
	if ( this.t_textarea == null ) return;
	this.o_textarea = this.t_textarea;
	this.o_textarea.style.display = "none";

	// 각 객체를 생성하여 Body 에 붙임
	this.R2Na_init ();
	R2NaIDs[this.sNo] = this;

	var container = this.t_textarea.parentNode;
	for (i = 0; i < container.childNodes.length; i++ ) {
		if ( container.childNodes[i] == this.t_textarea ) {
			container.insertBefore (this.oWe, container.childNodes[i]);
			container.removeChild (this.t_textarea);
			break;
		}
	}

	this.oWe.appendChild (this.R2Na_tools);
	this.oWe.appendChild (this.o_textarea);
	this.oWe.appendChild (this.R2Na_area);
	this.oWe.appendChild (this.o_PArea);
	this.oWe.appendChild (this.o_Tbl);

	// 위지윅 에디터 에리어에 디자인 모드 속성 부여 + 내용 삽입 
	this.R2Na_area.contentWindow.document.open (); // Gekko 1.9b5 Bug Hack
	this.R2Na_area.contentWindow.document.close (); 
	this.R2Na_insert ();

	var Editor = R2NaIDs[this.sNo]
	this.R2Na_area.contentWindow.document.designMode = "On";
	setTimeout ( function () { Editor.R2Na_area.contentWindow.document.designMode = "On"; },20); // 보험

	// 위지윅 에디터 에리어에 이벤트 적용
	var func = function () { Editor.R2NaTocontent (); }
	addEvent (this.R2Na_area.contentWindow.document, 'keyup', func );
	addEvent (this.R2Na_area.contentWindow.document, 'mouseup', func );

	// DOM Navigator
	addEvent (this.R2Na_area.contentWindow.document, 'keyup', function () { Editor.scanDOM (Editor.getSelectElement ()) } );
	addEvent (this.R2Na_area.contentWindow.document, 'mouseup', function () { Editor.scanDOM (Editor.getSelectElement ()) } );
}

R2Na.prototype.R2Na_init = function () { // 각 컴포넌트가 추가될 공간 생성
	// 베이스 레이어 생성
	this.oWe = document.createElement ("DIV");
	this.t_textarea.rows = 10;

	// 위지윅 에디터 에리어 생성
	this.R2Na_area = document.createElement ("IFRAME");
	this.R2Na_area.id = "R2Na_"+this.sNo;
	this.R2Na_area.className = "editorBody";
	this.R2Na_area.frameBorder = ( this.framedesign ) ? "0" : "1";
	this.R2Na_area.style.width = ( this.t_textarea.style.width ) ? this.t_textarea.style.width : "100%";
	this.R2Na_area.style.height = ( this.t_textarea.style.height ) ? this.t_textarea.style.height : "350px";

	// 컨트롤 버튼 에리어 생성
	this.R2Na_tools = document.createElement ("DIV");
	this.R2Na_tools.className = "bt_slot";
	this.R2Na_tools.style.width = this.R2Na_area.style.width;
	this.bt_generator ();

	// 팔렛트 에리어 생성
	this.o_PArea = document.createElement ("DIV");
	this.o_PArea.style.position = "absolute";
	this.o_PArea.style.zIndex = 11;

	// 테이블 입력 에리어 생성
	this.o_Tbl = document.createElement ("DIV");
	this.o_Tbl.style.position = "absolute";
	this.o_Tbl.style.zIndex = 10;
}

R2Na.prototype.bt_generator = function () { //	각 컴포넌트가 추가될 공간 생성
	this.R2Na_add_select ("ff", "Font@굴림@궁서@바탕", "굴림@굴림@궁서@바탕", "R2Na_Exec("+this.sNo+",'fontName',this.value)");
	this.R2Na_add_select ("fs", "Size@8 pt@10 pt@12 pt@14 pt@18 pt@24 pt@36 pt", "1@1@2@3@4@5@6@7", "R2Na_Exec("+this.sNo+",'fontSize',this.value)");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_b","진하게","R2Na_Exec("+this.sNo+",'bold')");
	this.R2Na_add_bt ("set_i","기울임","R2Na_Exec("+this.sNo+",'italic')");
	this.R2Na_add_bt ("set_u","밑줄","R2Na_Exec("+this.sNo+",'underline')");
	this.R2Na_add_bt ("set_s","가로줄","R2Na_Exec("+this.sNo+",'strikethrough')");
	this.R2Na_add_bt ("set_color", "글자색", "openPall(1,"+this.sNo+",event)");
	this.R2Na_add_bt ("set_bgcolor", "배경색", "openPall(2,"+this.sNo+",event)")
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_left","좌측정렬","R2Na_Exec("+this.sNo+",'justifyleft')");
	this.R2Na_add_bt ("set_center","가운데정렬","R2Na_Exec("+this.sNo+",'justifycenter')");
	this.R2Na_add_bt ("set_right","우측정렬","R2Na_Exec("+this.sNo+",'justifyright')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_ol","목록1","R2Na_Exec("+this.sNo+",'insertorderedlist')");
	this.R2Na_add_bt ("set_ul","목록2","R2Na_Exec("+this.sNo+",'insertunorderedlist')");
	this.R2Na_add_bt ("set_in","들여쓰기","R2Na_Exec("+this.sNo+",'outdent')");
	this.R2Na_add_bt ("set_out","내어쓰기","R2Na_Exec("+this.sNo+",'indent')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_cut","자르기","R2Na_Exec("+this.sNo+",'cut')");
	this.R2Na_add_bt ("set_put","붙이기","R2Na_Exec("+this.sNo+",'paste')");
	this.R2Na_add_bt ("set_wline","가로줄","R2Na_Exec("+this.sNo+",'InsertHorizontalRule')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_table","테이블생성","R2Na_tbl("+this.sNo+",event)");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_html","HTML편집","htmlonoff("+this.sNo+")");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");

	if ( is_gekko ) return; // Firefox 는 자체 셀편집기 제공

	this.R2Na_add_bt ("<div class='bt_slot_table'>");
	this.R2Na_add_bt ("set_row_up","상단열 추가","R2Na_tbl_control("+this.sNo+",'mkup')");
	this.R2Na_add_bt ("set_row_dn","하단열 추가","R2Na_tbl_control("+this.sNo+",'mkdn')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_col_left","좌측행 추가","R2Na_tbl_control("+this.sNo+",'mkleft')");
	this.R2Na_add_bt ("set_col_right","우측행 추가","R2Na_tbl_control("+this.sNo+",'mkright')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("set_col_merge","우측병합","R2Na_tbl_control("+this.sNo+",'mright')");
	this.R2Na_add_bt ("set_col_del","셀 삭제","R2Na_tbl_control("+this.sNo+",'del')");
	this.R2Na_add_bt ("<img src='"+R2Na_root+"/icon/h_line.gif'>");
	this.R2Na_add_bt ("</div>");
}

R2Na.prototype.R2Na_add_bt = function (icon, alt, exec) { // 컨트롤 버튼 생성 스크립트
	if (exec) var temp = "<img src='"+R2Na_root+"/icon/"+icon+".gif' alt='"+alt+"' onclick="+exec+" class='R2Na_bt'>"; 
	else var temp = icon;

	this.R2Na_tools.innerHTML += temp;
}


R2Na.prototype.R2Na_add_select = function (title, text, value, exec) { //	컨트롤 셀렉트 버튼 생성 스크립트
	spt = text.split ("@");
	val = value.split ("@");

	temp = "<select onchange="+exec+" class='R2Na_select'>";
	for (i = 0; i < spt.length; i++) {
		temp += "<option value="+val[i]+">"+spt[i]+"</option>";
	}
	temp += "</select>";

	this.R2Na_tools.innerHTML += temp;
}

R2Na.prototype.DOMNavigator = function (mode) {
	if ( mode == true ) {
		if ( this.useDOM == true ) return;

		this.useDOM = true;
		this.R2Na_DOM = document.createElement ("DIV");
		this.R2Na_DOM.className = "R2Na_DOM";
		this.R2Na_DOM.style.width = this.R2Na_area.style.width;
		this.oWe.insertBefore (this.R2Na_DOM, this.R2Na_area);

	} else {

	}
}


////////////////////////////////////////////////////////////////////////////////////
//
//	텍스트 동기화
//
////////////////////////////////////////////////////////////////////////////////////
R2Na.prototype.R2Na_insert = function (){ // 위지윅 에디터의 로딩 완료 후 기존 텍스트 넣음
	try {
		var doc;
		var cssfile = ( this.css ) ? this.css : baseCSS;

		doc  = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'>\n";
		doc += "<html>\n";
		doc += "<head>\n";
		doc += "<style type='text/css'>@import url('"+cssfile+"');</style>\n";
		doc += "</head>\n";
		doc += "<body style='margin: 5px;'>";
		doc += this.t_textarea.value;
		doc += "</body>\n";
		doc += "</html>\n";

		var area = this.R2Na_area.contentWindow;
		area.document.open ();
		area.document.write (doc);
		area.document.close ();
	} catch ( ex ) {
		setTimeout ("R2Na_insert ()", 20);
	}
}

R2Na.prototype.R2NaTocontent = function () { //	위지윅 에디터 -> 텍스트 에리어로 내용 전송
	if ( this.t_textarea.style.display == "block" ) return;
	this.t_textarea.value = this.R2Na_area.contentWindow.document.body.innerHTML;
}

R2Na.prototype.contentToR2Na = function () { //	텍스트 에리어 -> 위지윅 에디터로 내용 전송
	this.R2Na_area.contentWindow.document.body.innerHTML = this.t_textarea.value;
}

function htmlonoff (sNo){ //	HTML 편집창 On/Off
	var Editor = R2NaIDs[sNo];

	if (Editor.t_textarea.style.display == "none") {
		Editor.R2NaTocontent ();
		Editor.t_textarea.style.display = "block";
		Editor.R2Na_area.style.display = "none";
		Editor.t_textarea.focus ();
	} else {
		Editor.contentToR2Na ();
		Editor.t_textarea.style.display = "none";
		Editor.R2Na_area.style.display = "block";
		Editor.R2Na_area.focus ();
	}
}

////////////////////////////////////////////////////////////////////////////////////
//
//	Selection / DOM 처리
//
////////////////////////////////////////////////////////////////////////////////////
R2Na.prototype.getSelRange = function () { // 에디터의 선택 영역을 리턴한다
	var win = this.R2Na_area.contentWindow;
	var selRange;

	if ( win.document.selection ) selRange = win.document.selection;
	else selRange = win.getSelection().getRangeAt(0);

	return selRange;
}

R2Na.prototype.getSelectElement = function () { // 에디터의 선택된 엘리먼트를 리턴한다
	var sel = this.getSelRange ();
	var rng = (sel.type) ? sel.createRange() : sel;
	var parent = null;

	if ( sel.type ) { // IE, Opera
		switch ( sel.type ) {
			case "Text" :	parent = rng.parentElement(); break;
			case "None" : parent = rng.parentElement(); break;
			case "Control" : parent = rng.item(0); break;
			default : parent = this.R2Na_area.contentWindow.document.body;
		}
	} else { // Gekko
		parent = rng.commonAncestorContainer;
		if (!rng.collapsed && rng.startContainer == rng.endContainer && rng.startOffset - rng.endOffset < 2 && rng.startContainer.hasChildNodes() ) parent = rng.startContainer.childNodes[rng.startOffset];
		while ( parent.tagName == undefined ) {
			parent = parent.parentNode;
		}
	}

	return parent;
}

R2Na.prototype.scanDOM = function (obj) { // Dom Tree 를 출력

	this.selectedElement = obj;
	if ( this.useDOM != true ) return;

	this.R2Na_DOM.innerHTML = "";

	while ( obj ) {
		var link = document.createElement ("SPAN");
		link.innerHTML = obj.tagName;
		link.style.cursor = "pointer";

		var separate = document.createElement ("SPAN");
		separate.innerHTML = "&nbsp;>&nbsp;";

		this.toSelection (link, obj);
		if ( this.R2Na_DOM.innerHTML != "" ) this.R2Na_DOM.insertBefore (separate, this.R2Na_DOM.firstChild);
		this.R2Na_DOM.insertBefore (link, this.R2Na_DOM.firstChild);

		if ( obj.tagName == "BODY" ) break;
		else 	obj = obj.parentNode;
	}
}

R2Na.prototype.toSelection = function (link, obj) { // Dom Tree 에서 선택한 테그를 선택

	var Editor = this;

	func = function () {
		Editor.R2Na_area.contentWindow.focus();

		try {
			var selRange = Editor.getSelRange().createRange();
			selRange.moveToElementText (obj);
			selRange.select ();
		} catch ( Gekko ) {
			var selRange = Editor.getSelRange();
			selRange.setStart(obj, 0);
			selRange.setEnd(obj, obj.childNodes.length);
			alert ("'"+obj.tagName+"' 태그가 선택되었습니다");
		}

	}

	addEvent (link, 'click', func );

}


////////////////////////////////////////////////////////////////////////////////////
//
//	위지윅 명령들을 실행
//
////////////////////////////////////////////////////////////////////////////////////
function R2Na_Exec(sNo, excute, values) { // 에디터 버튼 실행
	var win = R2NaIDs[sNo].R2Na_area.contentWindow;
	var selRange = R2NaIDs[sNo].getSelRange ();

	win.focus ();

	if ( ( excute == "InsertImage" || excute == "InsertHTML" ) &&  selRange.type != "Control") {
		toimg = (excute == "InsertImage") ? "<img src='"+values+"'>" : values;

		try { // IE
			selRange.createRange().pasteHTML (toimg);
		} catch (gekko) {
			try { // Opera
				win.document.execCommand ('InsertHTML', false, toimg);
			} catch (OperaDom) { // gekko engine based
				selRange.deleteContents(); 
				selRange.insertNode(selRange.createContextualFragment(toimg));
			}
		}
	} else {
		win.document.execCommand (excute,'',values);
	}
}


////////////////////////////////////////////////////////////////////////////////////
//
//	색상 팔렛트 관련 메소드
//
////////////////////////////////////////////////////////////////////////////////////
function openPall (colormode, sNo, ev) { //	색상 팔렛트 켜기
	var Editor = R2NaIDs[sNo];
	var ev = convevent (ev);

	Editor.o_PArea.style.display = "block";
	Editor.o_PArea.style.top = (document.body.scrollTop + ev.clientY)+"px";
	Editor.o_PArea.style.left = (document.body.scrollLeft + ev.clientX)+"px";

	temp = R2NaPLT;
	Editor.o_PArea.innerHTML = temp.replace (/sNo/gi, sNo);

	Editor.colormode = colormode;
}

function closePall (sNo) { // 색상 팔레트 닫기
	var Editor = R2NaIDs[sNo];
	Editor.o_PArea.style.display = "none";
}

function selectColorCode (sNo, color) { //	마우스로 선택한 색상코드를 에디터에 적용
	var Editor = R2NaIDs[sNo];

	switch ( Editor.colormode ) {
		case 1:
			R2Na_Exec(sNo, 'ForeColor', color);
			break;
		case 2:
			if ( is_IE ) R2Na_Exec(sNo, 'BackColor',color)
			else  R2Na_Exec(sNo, 'Hilitecolor',color)
			break;
		case 3:
			var f = document.getElementById ("tablecolor_"+sNo);
			f.value = color;
			break;
	}

	closePall (sNo);
}

function viewColorCode (obj) { //	마우스로 선택한 색상코드를 화면에 출력
	tColor = document.getElementById ("sFont");
	tText = document.getElementById ("sDiv");

	tColor.color = obj.getAttribute ("bgcolor");
	tText.innerText = obj.getAttribute ("bgcolor");
}


/*////////////////////////////////////////////////////////////////////////////////////
//
//	Table Control
//
////////////////////////////////////////////////////////////////////////////////////*/
function R2Na_tbl (sNo, ev) { // 테이블 생성 다이얼로그 오픈
	var Editor = R2NaIDs[sNo];
	var ev = convevent (ev);

	Editor.o_Tbl.style.display = "block";
	Editor.o_Tbl.style.top = (document.body.scrollTop + ev.clientY)+"px";
	Editor.o_Tbl.style.left = (document.body.scrollLeft + ev.clientX)+"px";

	temp = R2NaTbl.replace (/sNo/gi, sNo);
	Editor.o_Tbl.innerHTML = temp;
}

function R2Na_put_tbl (sNo) { // 다이얼로그에서 받은 값으로 테이블 생성

	var Editor = R2NaIDs[sNo];
	if ( !Editor ) return;

	var cols = document.getElementsByName ("r2na_table_col")[0];
	var rows = document.getElementsByName ("r2na_table_row")[0];
	var width = document.getElementsByName ("r2na_table_width")[0];
	var ppx = document.getElementsByName ("r2na_table_ppx")[0];
	var border = document.getElementsByName ("r2na_table_border")[0];
	var color = document.getElementsByName ("r2na_table_color")[0];
	var align = document.getElementsByName ("r2na_table_align")[0];
	var floats = document.getElementsByName ("r2na_table_float")[0];

	rows = parseInt (rows.value);
	cols = parseInt (cols.value);

	var table = "<table width='"+width.value+ppx.value+"' border='"+border.value+"' bordercolor='"+color.value+"' align='"+align.value+"' style='border-collapse:collapse; float:"+floats.value+"'>";
	for (r = 0; r < rows; r++) {
		table += "	<tr>";
		for (c = 0; c < cols; c++) {
			table += "		<td>&nbsp;</td>";
		}
		table += "	</tr>";
	}
	table += "</table>";

	R2Na_Exec(Editor.sNo,'InsertHTML',table);
	closeTbl (sNo);
}

function closeTbl (sNo) { // 테이블 생성 다이얼로그 닫기
	var Editor = R2NaIDs[sNo];
	Editor.o_Tbl.innerHTML = "";
	Editor.o_Tbl.style.display = "none";
}

function R2Na_tbl_control (sNo, cmd) { // 테이블 셀 편집
	var Editor = R2NaIDs[sNo];

	switch ( Editor.selectedElement.tagName ) {
		case "TD" : 
			var el_tr = Editor.selectedElement.parentNode;
			var el_tbl = el_tr.parentNode.parentNode;
			break;
		case "TH" : 
			var el_tr = Editor.selectedElement.parentNode;
			var el_tbl = el_tr.parentNode.parentNode;
			break;
		case "TR" : 
			var el_tr = Editor.selectedElement;
			var el_tbl = el_tr.parentNode.parentNode;
			break;
		default :
			window.alert ("TD / TH / TR 오브젝트를 선택해 주십시오"); 
			return;
	}

	if ( cmd == "mkup" || cmd == "mkdn" ) { // 열추가
		for ( i = 0; i < el_tbl.rows.length; i++ ) {
			if ( el_tbl.rows[i] == el_tr ) var index = ( cmd == "mkup" ) ? i : i + 1;
		}

		var newrow = el_tbl.insertRow(index);
		for (i = 0 ; i < el_tr.cells.length; i++ ) {
			newtd = newrow.insertCell(0);
			newtd.innerHTML = "&nbsp";
		}
	}

	if ( cmd == "mkleft" || cmd == "mkright" ) { // 행추가
		for ( i = 0; i < el_tr.cells.length; i++ ) {
			if ( el_tr.cells[i] == Editor.selectedElement ) var index = ( cmd == "mkleft" ) ? i : i + 1;
		}
	
		newtd = el_tr.insertCell(index);
	}

	if ( cmd == "mright" ) { // 우측 행 병합
		for ( i = 0; i < el_tr.cells.length; i++ ) {
			if ( el_tr.cells[i] == Editor.selectedElement ) {
				if ( el_tr.cells[i+1] == null ) return; // 우측에 더이상 셀이 없으면 병합불가
				el_tr.deleteCell(i+1);
				colspan = ( el_tr.cells[i].colSpan ) ? el_tr.cells[i].colSpan : 1;
				el_tr.cells[i].colSpan = colspan + 1;
				break;
			}
		}
	}

	if ( cmd == "del" ) { // 제거
		for ( i = 0; i < el_tr.cells.length; i++ ) {
			if ( el_tr.cells[i] == Editor.selectedElement ) el_tr.deleteCell(i);
		}
	}

}


/*////////////////////////////////////////////////////////////////////////////////////
//
//	Neko™ Javascript
//
////////////////////////////////////////////////////////////////////////////////////*/
R2Na.prototype.initNeko = function (neko_id, neko_gr, neko_mode) { // Neko™ 객체 초기화 (구분코드, 저장될 서브 디렉토리, 작동모드)

	if ( !neko_id || !neko_gr || !neko_mode ) return;

	if ( document.getElementById ("neko_load") ) {

		this.neko_id = getEditor().neko_id;
		this.neko_gr = getEditor().neko_gr;
		this.neko_conf_id = getEditor().neko_conf_id;
		this.neko_conf_gr = getEditor().neko_conf_gr;
		this.neko_conf_mode = getEditor().neko_conf_mode;
		this.neko_conf_files = getEditor().neko_conf_related;

	} else {
		this.neko_id = neko_id;
		this.neko_gr = neko_gr;
		this.neko_mode = neko_mode;

		// neko_mode = img - 이미지만 업로드 가능, related - 에디터에 이미지를 삽입하면 리스트에서 제거, std - 디폴트
		this.neko_conf_id = this.createNekoElement ("neko_id", neko_id);
		this.neko_conf_gr = this.createNekoElement ("neko_gr", neko_gr);
		this.neko_conf_mode = this.createNekoElement ("neko_mode", neko_mode);
		this.neko_conf_files = this.createNekoElement ("neko_files", "");
		this.neko_conf_related = this.createNekoElement ("neko_related", "");

		this.oWe.appendChild (this.neko_conf_id);
		this.oWe.appendChild (this.neko_conf_gr);
		this.oWe.appendChild (this.neko_conf_mode);
		this.oWe.appendChild (this.neko_conf_files);
		this.oWe.appendChild (this.neko_conf_related);
	}

	this.setCurrentEditor (this.sNo); // 현재 에디터로 Neko™ 의 포커스를 이동
}

R2Na.prototype.createNekoElement = function (eName, eVal) { // 메인 폼에 Neko™ 의 부수정보를 전달할 inputbox 를 생성
	var el = document.createElement ("INPUT");
	el.type = "hidden";
	el.name = eName;
	el.value = eVal;

	return el;
}

R2Na.prototype.printNeko = function () { // 초기화된 Neko™ 를 현재 위치에 출력
	var frm = "<iframe id='neko_load' src='"+Neko_root+"/neko_body.php?neko_sNo="+this.sNo+"&neko_id="+this.neko_id+"&neko_gr="+this.neko_gr+"&neko_mode="+this.neko_mode+"' frameborder='0'></iframe>";
	document.writeln (frm);
}

R2Na.prototype.setCurrentEditor = function (sNo) { // 현재 클래스를 Neko™ 연동 클래스로 지정
	var len = R2NaIDs.length;

	for (i = 0; i < len; i++) {
		R2NaIDs[i].currentEditor = ( R2NaIDs[i].sNo == sNo ) ? true : false;
	}
}

function neko_loaded () { // 로딩된 후 프레임 크기 조정
	var Editor = parent.getEditor ();

	// Neko™ 프레임 크기 조정
	var fr = parent.document.getElementById ("neko_load");

	fr.contentWindow.document.body.style.overflow = "hidden";
	fr.style.width = Editor.R2Na_area.offsetWidth+"px";
	fr.style.height = "118px";

	// Neko™ 파일박스 크기 조정
	var se = document.getElementById ("neko_select");
	se.style.width = (Editor.R2Na_area.offsetWidth - 113)+"px";
}

function getEditor () { // Neko™ 의 대상 에디터를 검색
	var obj = R2NaIDs;

	for ( i = 0; i < obj.length; i++) {
		if ( R2NaIDs[i].currentEditor == true ) return R2NaIDs[i];
	}

	return;
}

function neko_sel ( no ) { // 클릭한 파일을 선택
	pr = document.getElementById ("neko_preview");
	pr.src = "/inc/neko_upper/neko_preview.php?no="+no;

	var neko_selno = document.getElementsByName ("neko_selno")[0];

	if (neko_selno.value) {
		oldsel = document.getElementById ("nekolist_"+neko_selno.value);
		if (oldsel) oldsel.style.backgroundColor = "";
	}

	newsel = document.getElementById ("nekolist_"+no);
	newsel.style.backgroundColor = "#fffbd7";
	neko_selno.value = no;
}

function neko_copyTo (sNo) { // 선택된 이미지를 R2Na 에 붙여넣는다
	var Editor = (sNo) ? parent.R2NaIDs[sNo] : parent.getEditor ();
	var neko_selno = document.getElementsByName ("neko_selno")[0];
	var neko_id = document.getElementsByName ("neko_id")[0];

	if ( Editor == null ) return;

	// 체크해서 연속 붙이기 2007-11-09
	var f = document.getElementById("neko_form");
	var cks = new Array();
	for (i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name == "ckno[]" && f.elements[i].checked == true ) cks[cks.length] = f.elements[i];
	}
	if (cks.length == 0 && neko_selno.value) cks[0] = neko_selno;

	for (i = 0; i < cks.length; i++) {
		selno = cks[i].value;
		cks[i].checked = false;
		var filename = getHttpRequest (Neko_root+"/neko_related.php?mode="+Editor.neko_conf_mode.value+"&no="+selno);

		if ( filename ) {
			parent.R2Na_Exec(Editor.sNo,'InsertImage',filename);
			Editor.R2NaTocontent ();

			Editor.neko_conf_related.value = Editor.neko_conf_related.value+"@"+filename;
		} else {
			window.alert ("GIF, JPG, PNG 파일만 사용할수 있습니다");
		}
	}

	if (cks.length == 0) window.alert ("선택된 파일이 없습니다");
}


////////////////////////////////////////////////////////////////////////////////////
//
//	관련 공통 스크립트
//
////////////////////////////////////////////////////////////////////////////////////
function addEvent (object, event ,listener) {  // 브라우저 공통 이벤트 첨부
    if (object.addEventListener){ 
        object.addEventListener (event, listener, false); 
    } else if (object.attachEvent){ 
        object.attachEvent ('on' + event, listener); 
    } 
}

function convevent (ev) { // Explorer 및 Firebox 이벤트 객체 호환 메소드
	e = (window.event) ? window.event : ev;
	return e;
}

function include (sFile){ //	외부 JS 파일 인클루드
	document.write ('<script language="javascript" src="'+ sFile +'"></script>');
}