var BASE_EDIROT = '/nbbs/module';
//ÃÊ±âÈ­
function TextEditorEvent() {
	if (TextEditor.event.button==2) {

		var oSource = TextEditor.event.srcElement;
    if (!oSource.isTextEdit)
    	oSource = TextEditor.event.srcElement.parentTextEdit;

		var strValue = TextEditor.event.srcElement.tagName; //¼±ÅÃµÈ ºÎºÐÀÇ ÅÂ±× Á¾·ù
    if ((strValue == "IMG" || strValue == "HR") && oSource != null) {
	    var oTextRange = oSource.createTextRange();
    }

		var selectedRange = TextEditor.document.selection.createRange();
		var edValue = selectedRange.htmlText;

		var strX = TextEditor.event.x;
		var strY = TextEditor.event.y+180;

		if (strValue == "IMG")
			strH = "180px";
		else if (strValue == "HR" || strValue == "TABLE")
			strH = "135px";
		else
			strH = "340px";

		var strParam = "dialogLeft:" + strX + ";dialogTop:" + strY + ";"
		strParam = strParam + "center:no;dialogWidth:150px; dialogHeight:" + strH + ";status:0;scroll:0; help:0;unadorned:yes;"
	}
}

/*¼öÁ¤ µÈ ºÎºÐ */
//action event
function check(param){
	if(document.write.html_check[0].checked) {
		document.write.content.value = TextEditor.document.body.innerHTML;
		if( !document.write.content.value ) {
			alert( "³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä!^^");
			TextEditor.document.body.focus();
			return;
		}
	} else {
		document.write.content.value = document.write.html_body.value;
		if( !document.write.content.value ) {
			alert( "³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä!^^");
			document.write.html_body.focus();
			return;
		}
	}
	document.write.method='post';
	document.write.action=param;
}



//since 2002/03/17
function paste(param){
	TextEditor.focus();
	var sel = TextEditor.document.selection;
	if (sel!=null) {
		var rng = sel.createRange();
	    if (rng!=null)
		    rng.pasteHTML(param);
	}
}

//since 2002.4.20
function layer_change(hidden_key,view_key){
	if(hidden_key == "html_layer")
		TextEditor.document.body.innerHTML = document.bbsMasterForm.html_body.value;
	else
		document.bbsMasterForm.html_body.value = TextEditor.document.body.innerHTML;
		document.all[hidden_key].style.display = "none";
		document.all[view_key].style.display = "block";
}
/*¼öÁ¤ µÈ ºÎºÐ */

function ButtonUp(param) {
	param.style.border="1px outset";
	param.style.background="#D4D4D4";
}

function ButtonOut(param) {
	param.style.border="";
	param.style.background="";

}
function MenuOver(param) {
	param.style.fontColor="white";
	param.style.backgroundColor="navy";
}

function MenuOut(param) {
	param.style.fontcolor="white";
	param.style.backgroundColor="#C0C0C0";
}


function block_style(o, cmd) {
	var ed=TextEditor.document;
	ed.execCommand(cmd, false, o.value);
}

function marquee_style(o, cmd) {
	var ed=TextEditor.document.selection.createRange();
	var temp=ed.value();
	alert(temp);
	ed.execCommand(cmd, false, o.value);
}

function SelectionCommand(Btn, cmd) {
	TextEditor.focus();
	var EdRange=TextEditor.document;
	EdRange.execCommand(cmd);
}

function SelectionCommand1(Btn, cmd) {
	TextEditor.focus();
	var path = prompt('ÀÎÅÍ³Ý¿¡ ¿Ã·ÁÁø ÀÌ¹ÌÁö ÁÖ¼Ò(url)À» ³Ö¾îÁÖ¼¼¿ä\n(¿¹: http://chosim.pe.kr/images/image.jpg) - "http://" ²À ½á¾ßÇÔ', 'http://');
	var EdRange1=TextEditor.document.selection.createRange();
	if (path != null) {
		EdRange1.pasteHTML("<IMG src='"+path+"' border='0'>");
	}
}

function ChFontColor(cmd) {
	var ed;
	var value;
	var value = showModalDialog( BASE_EDIROT+"/common/colorPicker.html", "»ö»ó¼±ÅÃ", "dialogWidth:240px;dialogHeight:189px;resizable:no;status:no;help:no;self-close:no;scroll:yes" );
	if( value != null ){
    ed = TextEditor.document;
		ed.execCommand(cmd, true, value);
	}
	TextEditor.document.body.focus();
}

function OpenWin(URL) {
	alert("DDDDDDDDD");
	var str;
	var scrWidth = (screen.availWidth / 2 ) - 200;
	var scrHeight = (screen.availHeight / 2) - 150;
	str="'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,";
	str=str+"width=400";
	str=str+",height=300',top="+scrHeight+",left="+scrWidth;
	wopen = window.open(URL,'remote',str);
}

function OpenColorPicker(){
	for(var k=0x00; k<0x100; k+=0x33) {
		for(var j=0x00; j<0x80; j+=0x33) {
			for(var i=0x00; i<0x100; i+=0x33) {
				n=""+(k.toString(16)==0?'00':k.toString(16))+
				     (j.toString(16)==0?'00':j.toString(16))+
				     (i.toString(16)==0?'00':i.toString(16));
				document.writeln("<span class='cTable' style='background-color:"+n+"' title='"+n+"' onclick=\"colorChange('"+n+"')\"></span> ");
			}
		}
	}

	for(var k=0x00; k<0x100; k+=0x33) {
		for(var j=0x99; j<0x100; j+=0x33) {
			for(var i=0x00; i<0x100; i+=0x33) {
			n=""+(k.toString(16)==0?'00':k.toString(16))+
			     (j.toString(16)==0?'00':j.toString(16))+
			     (i.toString(16)==0?'00':i.toString(16));

			document.writeln("<span class='cTable' style='background-color:"+n+"' title='"+n+"' onclick=\"colorChange('"+n+"')\"></span> ");
			}
		}
	}
}


//------------------------hmtl ÄÚµù°ú ¿¡µðÅÍ Åø ¼±ÅÃ¿©ºÎ----------------------//
function modeType(a) {
	TextFocus();
	if(a == "T") {
		document.getElementById("edit").style.display = "none";
		document.getElementById("text").style.display = ""
		document.getElementById("text_layer").style.display = "none";
		document.getElementById("html_layer").style.display = "";
		document.bbsMasterForm.CONTENT_TYPE.value="T";
		document.bbsMasterForm.CONTENTS.value = TextEditor.document.body.innerHTML;
		document.bbsMasterForm.CONTENTS.focus();
	} else {
		document.getElementById("edit").style.display = "";
		document.getElementById("text").style.display = "none";
		document.getElementById("text_layer").style.display = "block";
		document.getElementById("html_layer").style.display = "none";
		document.bbsMasterForm.CONTENT_TYPE.value="H";
		ini();
		TextEditor.document.body.innerHTML = document.bbsMasterForm.CONTENTS.value;
	}
}

function initEditor() {
	var bHeader = "<style>P {margin-top:3px;margin-bottom:3px;margin-left:0;margin-right;3}</style>\n";
	iText.document.open();
	iText.document.write(bHeader);
	iText.document.close();
	iText.document.body.style.fontSize = "9pt";
	iText.document.body.style.fontFamily = "±¼¸²";
}

function ini() {
	if(document.bbsMasterForm.CONTENT_TYPE.value == "H"){
		TextEditor.document.onmousedown = new Function("TextEditorEvent()");
		iText = TextEditor;
		iText.document.designMode = "On";
		TextEditView.style.display="inline";
		initEditor();
		bLoad = true;

		var len = document.bbsMasterForm.BBS_ETIQUETTE_TEXT.value.length;
		if(len > 0) {
			document.bbsMasterForm.CONTENTS.value = TextLoad();
		} else {
			document.bbsMasterForm.CONTENTS.value = document.bbsMasterForm.CONTENTS.value;
		}
		TextEditor.document.body.innerHTML = document.bbsMasterForm.CONTENTS.value;
	} else {
		document.getElementById("edit").style.display = "none";
		document.getElementById("text").style.display = ""
		document.getElementById("text_layer").style.display = "none";
		document.getElementById("html_layer").style.display = "";
	}
}

function iniFocus() {
	if(document.bbsMasterForm.CONTENT_TYPE.value == "H"){
		TextEditor.document.onmousedown = new Function("TextEditorEvent()");
		iText = TextEditor;
		iText.document.designMode = "On";
		TextEditView.style.display="inline";
		initEditor();
		bLoad = true;

		var len = document.bbsMasterForm.BBS_ETIQUETTE_TEXT.value.length;
		if(len > 0) {
			document.bbsMasterForm.CONTENTS.value = TextLoad();
		} else {
			document.bbsMasterForm.CONTENTS.value = document.bbsMasterForm.CONTENTS.value;
		}
		TextEditor.document.body.innerHTML = document.bbsMasterForm.CONTENTS.value;
	} else {
		document.getElementById("edit").style.display = "none";
		document.getElementById("text").style.display = ""
		document.getElementById("text_layer").style.display = "none";
		document.getElementById("html_layer").style.display = "";
	}
	TextEditor.document.body.focus();
	TextEditor.document.body.focus();
	
}