var onEditMode = true;

function editorinit() {
	var source 
	source = "<html><head><style>"
	source = source + " body {word-break:break-all; scrollbar-face-color:#DDDDDD;	scrollbar-highlight-color: #CCCCCC;	scrollbar-shadow-color: #CCCCCC;	scrollbar-3dlight-color: #FFFFFF;	scrollbar-darkshadow-color: #FFFFFF;	scrollbar-track-color: #F0F0F0;	scrollbar-arrow-color: #FFFFFF; }"
	source = source + " P {margin-top:2px;margin-bottom:2px;} table {border:1 solid C6C3C6}</style><script>function resizeImage(num){}</script></head><body></body></html>"
	HTMLEDITOR.document.designMode="On"
	HTMLEDITOR.document.open("text/html");
	HTMLEDITOR.document.write(source);
	HTMLEDITOR.document.close();
	HTMLEDITOR.document.body.style.fontSize = "9pt";
	HTMLEDITOR.document.body.style.fontFamily = "µ¸¿ò";
	HTMLEDITOR.document.onmouseup = setSelectBoxInfo1;
	HTMLEDITOR.document.onkeyup = setSelectBoxInfo2;
}


function ContentsDecode(str){

	str = str.replace(/&lt;/gi,"<");
    	str = str.replace(/&gt;/gi,">");
    	str = str.replace(/&amp;/gi,"&");
	return str;
}

function SetContents(){
	HTMLEDITOR.document.body.innerHTML = ContentsDecode(document.all.contentsDiv.innerHTML);
}


var Selection = null;
			 
function SetFont(ch){
	if (ch.options[ch.selectedIndex].value != '')
       		HTMLEDITOR.document.execCommand("FontName", null, ch.options[ch.selectedIndex].value);
}

function SetFontSize(ch){
	if (ch.options[ch.selectedIndex].value != '')
        	HTMLEDITOR.document.execCommand("FontSize", null, ch.options[ch.selectedIndex].value);
}

function copyContents(){
	var strHTML = "";
	try{
   		strHTML = HTMLEDITOR.document.body.innerHTML;
	}
	catch(e){
	}
	return strHTML;
}
		
//Ä¿¼­Æ÷ÀÎÆ®ÀÇ À§Ä¡¿¡ ¸Â´Â ±Û²Ã°ú ±ÛÀÚÅ©±â°ª ¼¿·ºÆ®¹Ú½º¿¡ Ç¥½Ã			
function setSelectBoxInfo1(){
	try{
   		var sText = HTMLEDITOR.document.selection.createRange();
   		
		if (sText.parentElement().all.HTMLEDITOR == null && sText.parentElement().all.papermain == null){
		         var lineval = sText.parentElement().outerHTML;
		         
         		 lineval = lineval.toLowerCase();
			 var idx = lineval.indexOf("<font");
			 if (idx > -1)
			 {
			 	try{
                          		if (sText.parentElement().face != null)
             				{
				 		if (sText.parentElement().face != "")
				 		{
					 		document.all.fontface.value = sText.parentElement().face;
				 		}
			      			else{
					 		document.all.fontface.selectedIndex = 1;
				 		}
					}
				 	else{
						document.all.fontface.selectedIndex = 1;
				 	}
             				if (sText.parentElement().size != null)
             				{
				 		if (sText.parentElement().size != "")
				 		{
				      			document.all.fontsize.value = sText.parentElement().size;
				 		}
				 		else{
					 		document.all.fontsize.selectedIndex = 0;
				 		}
             				}
				 	else{
						document.all.fontsize.selectedIndex = 0;
				 	}
				 }
			 	 catch(e){}
			 }else{
			 	try{
             				document.all.fontface.selectedIndex = 1;
             				document.all.fontsize.selectedIndex = 0;
			 	}
			 	catch(e){}
			 }
		}
	}	
	catch(e){}
}

//Ä¿¼­Æ÷ÀÎÆ®ÀÇ À§Ä¡¿¡ ¸Â´Â ±Û²Ã°ú ±ÛÀÚÅ©±â°ª ¼¿·ºÆ®¹Ú½º¿¡ Ç¥½Ã	
//¹æÇâÅ°ÀÏ°æ¿ì¸¸ Ã¼Å©		
function setSelectBoxInfo2(){
	if (HTMLEDITOR.event.keyCode >= 37 && HTMLEDITOR.event.keyCode <= 40)
	{
		var sText = HTMLEDITOR.document.selection.createRange();
		if (sText.parentElement().all.HTMLEDITOR == null && sText.parentElement().all.papermain == null){
			var lineval = sText.parentElement().outerHTML;
			lineval = lineval.toLowerCase();
			var idx = lineval.indexOf("<font");
			if (idx > -1)
			{
				try{
             				if (sText.parentElement().face != null)
             				{
				 		if (sText.parentElement().face != "")
				 		{
					 		document.all.fontface.value = sText.parentElement().face;
				 		}
			      			else{
					 		document.all.fontface.selectedIndex = 1;
				 		}
				        }
				 	else{
						document.all.fontface.selectedIndex = 1;
				 	}
             				
             				if (sText.parentElement().size != null)
             				{
				 		if (sText.parentElement().size != "")
				 		{
				      			document.all.fontsize.value = sText.parentElement().size;
				 		}
				 		else{
					 		document.all.fontsize.selectedIndex = 0;
				 		}
             				}
					else{
						document.all.fontsize.selectedIndex = 0;
				 	}
			 	}
			 	catch(e){}
			 }else{
			 	try{
             				document.all.fontface.selectedIndex = 1;
             				document.all.fontsize.selectedIndex = 0;
			 	}
			 	catch(e){}
			 }
		}
	}
}
	
function setTAG(order){
	Selection = HTMLEDITOR.document.selection.createRange();
	if (Selection!=null)Selection.select();

	if (Selection.text == '') return;
		
	switch (order) {
		case "Bold" 		: HTMLEDITOR.document.execCommand("Bold"); break;
		case "Italic" 		: HTMLEDITOR.document.execCommand("Italic"); break;
		case "Underline" 	: HTMLEDITOR.document.execCommand("Underline"); break;
		case "fontcolor" 	: showPalette('1'); break;
		case "bgcolor" 		: showPalette('2'); break;
		case "alignLeft" 	: HTMLEDITOR.document.execCommand("JustifyLeft"); break;
		case "alignCenter" 	: HTMLEDITOR.document.execCommand("JustifyCenter"); break;
		case "alignRight" 	: HTMLEDITOR.document.execCommand("JustifyRight"); break;
		//case "link" 		: HTMLEDITOR.focus(); HTMLEDITOR.document.execCommand("CreateLink",1); break;
		case "link" 		: popupLink(); break;
	}	
}

function showPalette(ch){
	if (navigator.userAgent.indexOf("MSIE 5.0") > 0)
	{
	 	document.all["TableFontColor"].style.top = "65";
     		document.all["TableFontBackColor"].style.top = "65";
	}

	if (ch=="1")
	{
		document.all["TableFontColor"].style.display = "";
		document.all["TableFontBackColor"].style.display = "none";
	}
	if (ch=="2")
	{
		document.all["TableFontColor"].style.display = "none";
		document.all["TableFontBackColor"].style.display = "";
	}
}

function Set_fontcolor(color){
	if (Selection!=null)Selection.select();
    	HTMLEDITOR.document.execCommand("forecolor", null, color);
    	document.all["TableFontColor"].style.display = "none";
	HTMLEDITOR.document.selection.empty()
}

function Set_bgcolor(color,color2){
	if (Selection!=null)Selection.select();
	HTMLEDITOR.document.execCommand("BackColor", null, color );
	if (color2 != "")
	{
        	HTMLEDITOR.document.execCommand("forecolor", null, color2);
	}
    	document.all["TableFontBackColor"].style.display = "none";
	HTMLEDITOR.document.selection.empty()
}

function popupAttachImage(){
	window.open ("/withstaff/asp/mail/attachImage.html","","width=400,height=360,scrollbars=no")
}
function AttachImage(code){
//	window.open ("./attachImage.html","","width=400,height=360,scrollbars=no")
	window.open ("/include/_attachImage.asp?code="+code,"","width=400,height=360,scrollbars=no")
}
function AttachImage2(){
	window.open ("./attachImage2.html","","width=400,height=360,scrollbars=no")
}
function placeImage(posVal,imgName)
{
	var tempHTML = HTMLEDITOR.document.body.innerHTML;

	if (posVal == "top") {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " border=0><br><p><br><p>" + tempHTML;
	} else if (posVal == "bottom") {
		HTMLEDITOR.document.body.innerHTML = tempHTML + "<img src=" + imgName + " border=0><br><p><br><p>";
	} else if (posVal == "left") {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " align=left border=0><br><p><br><p>" + tempHTML;
	} else {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " align=right border=0><br><p><br><p>" + tempHTML;
	}
}

function placeImage2(posVal,imgName)
{
	var tempHTML = HTMLEDITOR.document.body.innerHTML;	
	var count = document.frm.count.value;

	HTMLEDITOR.document.body.innerHTML = tempHTML + "<img src=" + imgName + " border=0 hspace=0 align=absMiddle vspace=3 border=0 id='upload_img"+ count +"' onload='controlImage(this.id);'><br><p><br><p>";

	count = count + 1;
	document.frm.count.value = count;
	
}

//ÀÌ¹ÌÁö Á¶°É
function controlImage(img_id) {
    var maxWidth = 700;
    var w = document.getElementById(img_id).width;
    if (w <= 0) {
    	time_id = window.setTimeout("controlImage('"+img_id+"')",10);
    } else {
        if (w > maxWidth) {
            document.getElementById(img_id).width = maxWidth;
        }
    }
}

function placeImage_(posVal,imgName, imageWidth)
{
	var tempHTML = HTMLEDITOR.document.body.innerHTML;
	var strWidth = "";

	// ÀÌ¹ÌÁö »çÀÌÁî°¡ 700ÀÌ ³ÑÀ¸¸é ³ÐÀÌ¸¦ 700À¸·Î ÁÙ¿©¼­ º¸¿©ÁØ´Ù
	if ( imageWidth > 700 ) strWidth = " width=700"


	if (posVal == "top") {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " border=0 " + strWidth + "><br><p><br><p>" + tempHTML;
	} else if (posVal == "bottom") {
		HTMLEDITOR.document.body.innerHTML = tempHTML + "<img src=" + imgName + " border=0 " + strWidth + "><br><p><br><p>";
	} else if (posVal == "left") {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " align=left border=0 " + strWidth + "><br><p><br><p>" + tempHTML;
	} else {
		HTMLEDITOR.document.body.innerHTML = "<img src=" + imgName + " align=right border=0 " + strWidth + "><br><p><br><p>" + tempHTML;
	}

}

function placeImage2_(posVal,imgName, imageWidth)
{
	var tempHTML = HTMLEDITOR.document.body.innerHTML;	
	var count = document.frm.count.value;
	var strWidth = "";

	// ÀÌ¹ÌÁö »çÀÌÁî°¡ 700ÀÌ ³ÑÀ¸¸é ³ÐÀÌ¸¦ 700À¸·Î ÁÙ¿©¼­ º¸¿©ÁØ´Ù
	if ( imageWidth > 700 ) strWidth = " width=700"

	HTMLEDITOR.document.body.innerHTML = tempHTML + "<img src=" + imgName + " border=0 " + strWidth + " hspace=0 align=absMiddle vspace=3 border=0 id='upload_img"+ count +"' onload='controlImage(this.id);'><br><p><br><p>";

	count = count + 1;
	document.frm.count.value = count;
	
}


function deleteAttachFileList(){
	try{
		var idx = document.all.filelist.options.selectedIndex;
		if (idx == 0)
		{
			alert("»èÁ¦ÇÏ½Ç ÆÄÀÏÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.")
			return;
		}

		var objvalue = document.all.filelist.options[idx].value;

		//Ãß°¡ °íº´¿í 20090119 Ã·ºÎÆÄÀÏ »èÁ¦½Ã hidden ifilelist¿¡¼­ Á¦¿Ü½ÃÅ²´Ù.
		var rmObjName = objvalue;
		var iFileListAll = document.all["ifileList"].value;
		rmObjName = rmObjName.replace(objvalue.slice(objvalue.lastIndexOf("[namu]")+6), '');
		iFileListAll = iFileListAll.replace(rmObjName, '');
		document.all["ifileList"].value = iFileListAll;		



		filesize = objvalue.slice(objvalue.lastIndexOf("[namu]")+6);
		subtractFileSize(filesize);

		document.all.filelist.remove(idx);

		

		// Ãß°¡. ±è³²±Ô 2005.11.15 ÆÄÀÏ »èÁ¦½Ã ½ÇÁ¦ ÆÄÀÏ »èÁ¦½ÃÅ²´Ù(DB¿¡¼­ used_yn = 'N' Ã³¸®)
		//window.open("./file_delete.asp?file_nm="+objvalue, "fruit", "width=200,height=100,scrollbars=no,resizeable=no,statusbar=0,alwaysRaised=yes,top=50,left=100");
		
		}
	catch(e){
		alert(e+"»èÁ¦ÇÏ½Ç ÆÄÀÏÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.");
	}
}

function deleteAttachFileList_edt(){
	try{
		var idx = document.all.filelist.options.selectedIndex;
		if (idx == 0)
		{
			alert("»èÁ¦ÇÏ½Ç ÆÄÀÏÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.")
			return;
		}

		var objvalue = document.all.filelist.options[idx].value;

		//Ãß°¡ °íº´¿í 20090119 Ã·ºÎÆÄÀÏ »èÁ¦½Ã hidden ifilelist¿¡¼­ Á¦¿Ü½ÃÅ²´Ù.
		var rmObjName = objvalue;
		var iFileListAll = document.all["ifileList"].value;
		iFileListAll = iFileListAll.replace(rmObjName+'[namu]', '');
		document.all["ifileList"].value = iFileListAll;		



		filesize = objvalue.slice(objvalue.lastIndexOf("[namu]")+6);
		subtractFileSize(filesize);

		document.all.filelist.remove(idx);


		// Ãß°¡. ±è³²±Ô 2005.11.15 ÆÄÀÏ »èÁ¦½Ã ½ÇÁ¦ ÆÄÀÏ »èÁ¦½ÃÅ²´Ù(DB¿¡¼­ used_yn = 'N' Ã³¸®)
		//window.open("./file_delete.asp?file_nm="+objvalue, "fruit", "width=200,height=100,scrollbars=no,resizeable=no,statusbar=0,alwaysRaised=yes,top=50,left=100");
		
		}
	catch(e){
		alert(e+"»èÁ¦ÇÏ½Ç ÆÄÀÏÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.");
	}
}


function addAttachFileList(text,value){
   
   var obj = document.all.filelist;
   obj[obj.length] = new Option(text, value);
}

function concatenateFileList(){
    	var obj = document.all.filelist;
	var objlen = obj.length;
	var text = "";
	
	try{
		for(i=1;i<objlen;i++){
			if (i==(objlen - 1))
			{
				text = text + obj[i].value;
			}
			else{
	             		text = text + obj[i].value + "<namu>"; 
        		}
        		obj[i].selected = true;
        		
		}
	}
	catch(e){
	}
    	return text;
}

function SetValueFile(filenm,filesize,originFileName,gubun){
	filetail = filenm.slice(filenm.lastIndexOf("/")+1)
	//filenm2 = filenm.slice(filenm.lastIndexOf("D:/nes_test/upload/board/")+13)
	filenm2 = filenm.slice(filenm.lastIndexOf("D:/CSMS/Upload_Files/")+13)
	document.all["ifileList"].value = document.all["ifileList"].value + filenm + "[namu]";
	addAttachFileList(originFileName + "   " + parseInt(parseInt(filesize)/1024) + "KB",originFileName + "[namu]" + filesize);
	addFileSize(filesize);	
	document.all["attachedOriginFileName"].value = document.all["attachedOriginFileName"].value + originFileName + "[namu]";
	//total·Î ³Ñ±è 
	document.all["attach"].value = document.all["attach"].value + originFileName + "," + filenm + "," + parseInt(filesize) + "," + gubun +"/";
}

function addFileSize(filesize){
	var attachedTotalBytes = document.all["attachedTotalBytes"].value;
	attachedTotalBytes = parseInt(attachedTotalBytes) + parseInt(filesize);
	document.all["attachedTotalBytes"].value = attachedTotalBytes;
	document.all["attachedTotalKB"].value = parseInt(attachedTotalBytes/1024);
}

function subtractFileSize(filesize){
	var attachedTotalBytes = document.all["attachedTotalBytes"].value;
	attachedTotalBytes = parseInt(attachedTotalBytes) - parseInt(filesize);
    	document.all["attachedTotalBytes"].value = attachedTotalBytes;
    	document.all["attachedTotalKB"].value = parseInt(attachedTotalBytes/1024);
}




function checkForm(){

	document.WriteFrm.action = "NES_SEM_board_writeok.asp";
	document.WriteFrm.submit();
}



// ±è³²±Ô Ãß°¡. 2005.11.22 ¸µÅ© »õÃ¢¶ç¿ì±â
function popupLink() {

  HTMLEDITOR.focus();

  var EdRange=HTMLEDITOR.document.selection.createRange();
  EdRange.execCommand("CreateLink");

  if (EdRange.parentElement().tagName=='A'){
	var href=EdRange.parentElement().href;
	var data=EdRange.text;
	EdRange.execCommand('UnLink');
	EdRange.pasteHTML("<a href='"+href+"' target=_blank>"+data+"</a>");
  }

}