var appVer = navigator.appVersion.match(/MSIE \d+.\d+/)[0].split(" ")[1];

function init() {

	TextEditor.document.designMode = "On";		
		
   //if (appVer < 5.5) {
	
	
	TextEditor.document.onmousedown = new Function("TextEditorEvent()");
	
   //} 
   	
	iText = TextEditor;
	
	initEditor();
	
}

function Edit(){
	
	init();

	
		TextEditor.document.body.innerHTML = inputform.tmpContent.value;
		inputform.html_body.value = inputform.tmpContent.value;
	
}


function initEditor() {
		
	var bHeader = "<style> P {margin-top:5px;margin-bottom:5px;margin-left:5px;margin-right:5px;line-height:1.1;} </style><body style='font-size:10pt;font-family:±¼¸²;background-color:f7f7f7;line-height:1.1;'></body>\n";
	iText.document.open();
	iText.document.write(bHeader);	
	iText.document.close();
}

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;"
	}
}

function checkCont(){

	var editor;

	
		editor = TextEditor.document.body;
	

	if(document.inputform.cont_type[0].checked){

		document.inputform.contents.value = editor.innerHTML;
		if( !document.inputform.contents.value ){
			alert( "³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			editor.focus();
			return false;
		}
	}else{
		document.inputform.contents.value = document.inputform.html_body.value;
			if( !document.inputform.contents.value ){
			alert( "³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			document.inputform.html_body.focus();
			return false;
		}
	}

	return true;

}


function paste(param){
	TextEditor.focus();
	var sel = TextEditor.document.selection;
	if (sel!=null) {
		var rng = sel.createRange();
	    if (rng!=null)
		    rng.pasteHTML(param);
	}
	TextEditor.focus();
}

function pasteTop(param){
	TextEditor.focus();
	TextEditor.innerHTML = param + TextEditor.innerHTML;
}

function layer_change(hidden_key,view_key){
	if(hidden_key == "html_layer") {

		//if (appVer < 5.5) {

			TextEditor.document.body.innerHTML = document.inputform.html_body.value;

		//} else {

		//	TextEditor.innerHTML = document.inputform.html_body.value;

		//}

	} else {

		//if (appVer < 5.5) {

			document.inputform.html_body.value = TextEditor.document.body.innerHTML;

		//} else {

		//	document.inputform.html_body.value = TextEditor.innerHTML;

		//}

	}

	document.all[hidden_key].style.display = "none";
	document.all[view_key].style.display = "block";
}

function block_style(o, cmd) {

   TextEditor.focus();

   if (cmd == null) {
      TextEditor.document.execCommand(cmd,false, o.value);
   }
   else {
      TextEditor.document.execCommand(cmd,"",o.value);
   }

}



function selectCommand(Btn, cmd) {

   TextEditor.focus();
   TextEditor.document.execCommand(cmd);
}

function selectColor(cmd){

	var ed
	var value = showModalDialog( "/bbs/common/choice_color.jsp?gb="+cmd,"","dialogWidth:241px;dialogHeight:160px;status:no;scroll:no;help:no;self-close:no" );
	if( value != null ){
		TextEditor.focus();
		TextEditor.document.execCommand(cmd,"",value);
	}
	TextEditor.focus();
}

function addImage(st) {

	var obj = inputform;

	if (obj.imgsize.value > 1024*1024*3) {

		alert("Ã·ºÎÇÒ¼ö ÀÖ´Â ÀÌ¹ÌÁö ÆÄÀÏÀº ÃÑ 3MByte±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù.");
		return;
	}
	
	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=350";
	str=str+",height=161',top="+scrHeight+",left="+scrWidth;
	wopen = window.open('/bbs/common/addBbsImage.jsp?st='+st,'addimage',str);
}

function addBbsImage() {

	var obj = inputform;

	if (obj.imgsize.value > 1024*1024*10) {

		alert("Ã·ºÎÇÒ¼ö ÀÖ´Â ÀÌ¹ÌÁö ÆÄÀÏÀº ÃÑ 10MByte±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù.");
		return;
	}
	
	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=350";
	str=str+",height=251',top="+scrHeight+",left="+scrWidth;
	wopen = window.open('/bbs/common/addBbsImage.jsp','addimage',str);
}

function addBbsFile() {

	var obj = inputform;
	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=350";
	str=str+",height=161',top="+scrHeight+",left="+scrWidth;
	wopen = window.open('/bbs/common/addBbsFile.jsp','addfile',str);
}

function addMedia() {
	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=350";
	str=str+",height=270',top="+scrHeight+",left="+scrWidth;
	wopen = window.open('/bbs/common/addMedia.jsp','addmedia',str);
}