var selectArea = null;
var color_target = "";

function init_editor() {
	editCtrl.document.designMode = "on";
	var body = "";
	body += "<style>";
	body += "P {margin-top:2px;margin-bottom:2px;margin-left:2;margin-right;2; }\n";
	body += "span, body, tr, td, th, select, div, form, center, option, pre, blockquote{font-size:9pt; font-family:µ¸¿ò,verdana;color:#333333;}\n";
	body += "</style>\n";
	body += "<BODY>";
	editCtrl.document.open("text/html");
	editCtrl.document.write(body);
	editCtrl.document.close();
	editCtrl.document.body.style.fontFamily = "tahoma";
	editCtrl.document.body.style.fontSize = "9pt"
	editCtrl.document.oncontextmenu = disableContext;

}
function init_editor2() {
	editCtrl.document.designMode = "on";
	var body = "";
	body += "<link rel='stylesheet' href='http://www.teacherplus.co.kr/n_css/popup.css'><link rel='stylesheet' href='http://www.teacherplus.co.kr/n_css/resource.css'>";	
	body += "<BODY>";
	editCtrl.document.open("text/html");
	editCtrl.document.write(body);
	editCtrl.document.close();	
	editCtrl.document.oncontextmenu = disableContext;

}

function disableContext() {
	return false;
}
function showHtml() {
	var html = editCtrl.document.body.innerHTML;
	document.edit_frm.tb_content.value = html;
}
function showHtml2(){
	editCtrl.document.body.innerHTML = document.edit_frm.tb_content.value;
}
function init_update() {
editCtrl.document.body.innerHTML = document.edit_frm.tb_content.value;
}

function execCmd(cmd) {
	editCtrl.focus();
	
	if (cmd == "createlink")
		editCtrl.document.execCommand("createlink", true);
	else
		editCtrl.document.execCommand(cmd);
}

function setFont(obj) {
	var font = obj.options[obj.selectedIndex].value;
	editCtrl.document.execCommand("FontName", null, font);
}

function setFontSize(obj) {
	var size = obj.options[obj.selectedIndex].value;
	editCtrl.document.execCommand("FontSize", null, size);	
}

function setForeColor() {
	editCtrl.focus();
	selectArea = editCtrl.document.selection.createRange();

	document.all.foreColorTable.style.display = "";
	document.all.bgColorTable.style.display = "none";
}

function setBgColor() {
	editCtrl.focus();
	selectArea = editCtrl.document.selection.createRange();

	document.all.foreColorTable.style.display = "none";
	document.all.bgColorTable.style.display = "";
}

function dlg_setForeColor(color) {
	if (selectArea != null)
		selectArea.select();

	editCtrl.document.execCommand("forecolor", null, color);
	document.all.foreColorTable.style.display = "none";
}

function dlg_setBackColor(color) {
	if (selectArea != null)
		selectArea.select();

	editCtrl.document.execCommand("backcolor", null, color);
	document.all.bgColorTable.style.display = "none";
}

function insertImg() {
	//editCtrl.focus();
	//editCtrl.document.execCommand("insertimage", true);
	try
	{
	open_popup('./upload.asp?now_file_size='+document.edit_frm.file_size.value, '360', '150', '0', '0');	
	}
	catch (e)
	{
	editCtrl.focus();
	editCtrl.document.execCommand("insertimage", true);
	}
	
}

//function insertImg2(imgurl) {
	//alert(imgurl);
//	editCtrl.focus();
//	editCtrl.document.execCommand("insertimage",false, imgurl);
	//open_popup('./upload.asp?now_file_size='+document.edit_frm.file_size.value, '360', '220', '0', '0');
//}

function insertImg2(imgurl,wid) {		
	editCtrl.focus();	
	editCtrl.document.body.innerHTML = editCtrl.document.body.innerHTML + "<br><img src="+imgurl+" width="+wid+"><br><br><br>";	
	editCtrl.focus();	
}

function EkeywordKeyDown() {
    var keyCode = window.event.keyCode;
    if(keyCode == 13)   return "<br>";     //Enter Å°
    
}