function checkpos()  // ±Û²Ã ¹× »çÀÌÁî ¼³Á¤
{
	try
	{
		var sText = POSTEDITOR.document.selection.createRange();
		if (sText.parentElement().all.POSTEDITOR == 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 checkposkey()	//±Û²Ã ¹× »çÀÌÁî ¼³Á¤
{
	if (POSTEDITOR.event.keyCode >= 37 && POSTEDITOR.event.keyCode <= 40)
	{
		var sText = POSTEDITOR.document.selection.createRange();
		if (sText.parentElement().all.POSTEDITOR == 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 editorinit()
{
	var source = "<html><head><style>P {margin-top:2px;margin-bottom:2px;} table {border:1 solid C6C3C6}</style><script>function resizeImage(num){}</script></head><body></body></html>";
	POSTEDITOR.document.designMode="On"
	POSTEDITOR.document.open("text/html");
	POSTEDITOR.document.write(source);
	POSTEDITOR.document.close();
	POSTEDITOR.document.body.style.fontSize = "9pt";
	POSTEDITOR.document.body.style.fontFamily = "µ¸¿ò";
	//POSTEDITOR.document.oncontextmenu = new Function("return false;");
	POSTEDITOR.document.onmouseup = checkpos;
	POSTEDITOR.document.onkeyup = checkposkey;
}

// ¿¡µðÅÍ¿¡ ³»¿ë »Ñ¸®±â
function SetContents()
{
	POSTEDITOR.document.body.innerHTML = ContentsDecode(document.all.contentsDiv.innerHTML);
}

// ¿¡µðÅÍ¿¡ ÄÚµå º¯È¯
function ContentsDecode(str)
{
	str = str.replace(/&lt;/gi,"<");
	str = str.replace(/&gt;/gi,">");
	str = str.replace(/&amp;/gi,"&");
	return str;
}

// ÆùÆ® ¼³Á¤
function SetFont(ch)
{			
	if (ch.options[ch.selectedIndex].value != '')
		POSTEDITOR.document.execCommand("FontName", null, ch.options[ch.selectedIndex].value);			
}

// ÆùÆ® Å©±â ¼³Á¤
function SetFontSize(ch)
{			
	if (ch.options[ch.selectedIndex].value != '')
		POSTEDITOR.document.execCommand("FontSize", null, ch.options[ch.selectedIndex].value);
}

var Selection = null;

function SetAction(order)
{
	Selection = POSTEDITOR.document.selection.createRange();
	if (Selection!=null) Selection.select();

	if (order == "Bold")
	{
		POSTEDITOR.document.execCommand("Bold");
	}
	else if (order == "Italic")
	{
		POSTEDITOR.document.execCommand("Italic");
	}
	else if (order == "Underline")
	{
		POSTEDITOR.document.execCommand("Underline");
	}
	else if (order == "alignLeft")
	{
		POSTEDITOR.document.execCommand("JustifyLeft");
	}
	else if (order == "alignCenter")
	{
		POSTEDITOR.document.execCommand("JustifyCenter");
	}
	else if (order == "alignRight")
	{
		POSTEDITOR.document.execCommand("JustifyRight");  
	}
	else if (order == "link")
	{
		POSTEDITOR.focus();
		POSTEDITOR.document.execCommand("CreateLink",1);
	}
	else if (order == "Strike")
	{
		POSTEDITOR.document.execCommand("StrikeThrough");
	}
	else if (order == "fontcolor")
	{
		onFontColorForm('1');
	}
	else if (order == "bgcolor")
	{
		onFontColorForm('2');
	}
}

// ÄÃ·¯ ¼±ÅÃ Æû ¶ç¿ì±â
function onFontColorForm(ch)
{
	if (navigator.userAgent.indexOf("MSIE 5.0") > 0)
	{
	     //alert("´ç½ÅÀÇ ºê¶ó¿ìÁ®´Â 5.0 ÀÌ±º¿ä!");
		 document.all["TableFontColor"].style.top = "65";
	     document.all["TableFontBackColor"].style.top = "65";
	}

	if (ch=="1")
	{
		ModalessDialog('/app/include/HtmlEditor/select_color.asp?mode=font', window, 238, 187 );
	}
	if (ch=="2")
	{
		ModalessDialog('/app/include/HtmlEditor/select_color.asp?mode=bgcolor', window, 238, 187 );
	}
}

// Modeless Dialog¸¦ À§ÇÑ Wrapper MethodÀÔ´Ï´Ù.
/*
function ModalessDialog( url, args, width, height )
{
	var env_options = "dialogHeight: " + height + "px; dialogWidth: " + width + "px;  edge: Raised; center: Yes; help: No; scroll: No; resizable: No; status: No;";
	window.showModelessDialog( url, args, env_options);
}
*/

// ÆùÆ® ÄÃ·¯ ÁöÁ¤
function setFontColor(color)
{
	if (Selection!=null) Selection.select();
	POSTEDITOR.document.execCommand("forecolor", null, color);
	POSTEDITOR.document.selection.empty();
}

// ÆùÆ® ¹è°æ ÄÃ·¯ ÁöÁ¤
function setBGColor(color,color2)
{
	if(Selection!=null) Selection.select();
	POSTEDITOR.document.execCommand( "BackColor", null, color );
	
	if (color2 != "")
	{
		POSTEDITOR.document.execCommand("forecolor", null, color2);
	}
	
	POSTEDITOR.document.selection.empty()
}


function onPopFileInsert(pMode, pMaxCnt, pAttachDBGbn)
{
	var num = document.all["filenum"].value;
	
	if (parseInt(num)>= parseInt(pMaxCnt))
	{
		alert("ÆÄÀÏÃ·ºÎ´Â " + pMaxCnt + "°³±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù");
	}
	else
	{
		if(pMode == "image_editer")
		{
			pMode = "image";
			url="/app/common/ImageEditor/imageEditor.asp?attachDB=" + pAttachDBGbn + "&umode="+pMode;
		}
		else
		{
			url="/app/include/HtmlEditor/pop_file_select.asp?attachDB=" + pAttachDBGbn + "&umode="+pMode;
		}
			
		var win = window.open(url, pMode, "top=5,left=5,width=358,height=317,status=yes");
		win.focus();
	}
}


// ÆÄÀÏ ¾÷·Îµå ÈÄ ÆÄÀÏÀ» ¼¿·ºÆ®¹Ú½º¿¡ »Ñ·ÁÁÖ±â
function setValueFile(filename,filesize,filetail,fileMode)
{
	var arrFileName = filename.split("_");
	var strFileName = "";

	for(i=0; i<arrFileName.length; i++)
	{
		if(i > 0)
		{
			strFileName += arrFileName[i];
			
			if(arrFileName.length > 2 && i < arrFileName.length - 1)
			{
				strFileName += "_";
			}
		}
	}
	
	if(fileMode == "1") strFileName = "* " + strFileName;

	AddFileList(strFileName + " " + Math.floor(parseFloat(filesize)/1024) + "KB", filename + "@izy@" + filesize + "@izy@" + filetail + "@izy@" + fileMode);
		
	FileSizeCalc(filesize);
		
	try
	{
		Setok();
		
		
	}
	catch(e)
	{
	}
}

var imgIndex;
function AddFileList(pText,pValue)
{  
   var obj = document.all.filelist;
   obj[obj.length] = new Option(pText, pValue);
   imgIndex = obj.length;
}


//ÆÄÀÏ»çÀÌÁî °è»ê
function FileSizeCalc(pFileSize)
{

	var attachAllrealsize = document.all["attachAllrealsize"].value;
	attachAllrealsize = Math.floor(parseFloat(attachAllrealsize)) + Math.floor(parseFloat(pFileSize));
    document.all["attachAllrealsize"].value = attachAllrealsize;
    document.all["attachAllsize"].value = Math.floor(parseFloat(attachAllrealsize/1024));

}

function plusFileNum()
{
	document.all["filenum"].value = Math.floor(parseFloat(document.all["filenum"].value)+1);
}

function addlink(url,type,chk)
{

	//alert(url);
	POSTEDITOR.focus();

	var sText = POSTEDITOR.document.selection;
	if (sText != null && sText.type.toLowerCase() != "control")
	{
		var rgn = sText.createRange();
		if (rgn != null)
		{
			rgn.select();
			
			if (type == 'top')
				rgn.pasteHTML("<center><img src='"+ url + "'  align='" + type + "' name='userImg' style='cursor:hand;' onload=\"imgResize('"+ url +"', '"+ type +"');\" onclick=\"openWindowPoint('/app/include/HtmlEditor/image_view_popup.asp?img=' + this.src, this.width, this.height, 'no', 'no', 'photo_view', 10, 10);\"></center><br>");
			else
				rgn.pasteHTML("<br><img src='"+ url + "'  align='" + type + "' name='userImg' style='cursor:hand;' onload=\"imgResize('"+ url +"', '"+ type +"');\" onclick=\"openWindowPoint('/app/include/HtmlEditor/image_view_popup.asp?img=' + this.src, this.width, this.height, 'no', 'no', 'photo_view', 10, 10);\"><br>");

		}
	}
}


function setFileListDel(pLocation, pParentIDX, pAttachDBGbn)
{
	try
	{
		var idx = document.all.filelist.options.selectedIndex;
				
		if (idx <= 0)
		{
			alert("»èÁ¦ÇÏ½Ç ÆÄÀÏÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.");
			return;
		}
		
		if(!confirm("ÆÄÀÏÀ» »èÁ¦ÇÏ½Ã¸é º¹¿øÀÌ ¾ÈµË´Ï´Ù.\n»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) return;
		
		var objvalue = document.all.filelist.options[idx].value;

//		alert(actionframe.location);

		actionframe.location = "/app/include/HtmlEditor/pop_file_delete_proc_.asp?location="+pLocation+"&parentIDX="+ pParentIDX +"&idx=" + idx + "&filename=" + objvalue + "&db_gbn=" + pAttachDBGbn;
	}
	catch(e)
	{
		alert("¿¡·¯¹ß»ý.");
	}
}

// ÆÄÀÏ»èÁ¦½Ã ÆÄÀÏ¸®½ºÆ®¿¡¼­ »èÁ¦, ÆÄÀÏÀüÃ¼»çÀÌÁî Á¶Á¤
function DelFileConfirm(pIDX,pFileSize, pMode, pDB)
{
	if(pMode != "0")
	{
		if(pDB != "SHomeAlbumArticle")
		{
			var idx = document.all.filelist.options.selectedIndex;
			
			arrItem = document.all.filelist.options[idx].value.split("@izy@");
			
			if(POSTEDITOR.document.all.userImg != null)
			{
							
				if(document.all.filelist.options.length > 2)
				{
					for(i=0; i<POSTEDITOR.document.all.userImg.length; i++)
					{					
						//alert(arrItem[0]);
						if(POSTEDITOR.document.all.userImg[i].src.indexOf(arrItem[0]) > 0)
						{
							POSTEDITOR.document.all.userImg[i].src = "";
							POSTEDITOR.document.all.userImg[i].name = "NoneImg";
						}
					}
				}
				else
				{	
					//alert(arrItem[0] + " - " + POSTEDITOR.document.all.userImg.src);
					if(POSTEDITOR.document.all.userImg.src.indexOf(arrItem[0]) > 0)
					{
						POSTEDITOR.document.all.userImg.src = "";
						POSTEDITOR.document.all.userImg.name = "NoneImg";
					}
				}
			}
		}
	}
	
    var obj = document.all.filelist;
	obj.options[pIDX] = null;

    FileSizeCalcM(pFileSize);
}

//ÆÄÀÏ»çÀÌÁî °è»ê
function FileSizeCalcM(pFileSize)
{
 	var attachAllrealsize = document.all["attachAllrealsize"].value;
	attachAllrealsize = Math.floor(parseFloat(attachAllrealsize)) - Math.floor(parseFloat(pFileSize));
    document.all["attachAllrealsize"].value = attachAllrealsize;
    document.all["attachAllsize"].value = Math.floor(parseFloat(attachAllrealsize/1024));
}


// ÆÄÀÏ¸®½ºÆ®¸¦ ½ºÆ®¸µÀ¸·Î ¸¸µé¾î¼­ °ªÀ» ³Ñ°ÜÁØ´Ù.
function getFileListToString()
{
	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 + "<izy>";
			}
		}
	}
	catch(e){	}
	
	return text;
}


function getPostContents()
{
	var HTMLSOURCE = "";
	try
	{
		HTMLSOURCE = POSTEDITOR.document.body.innerHTML;
	}
	catch(e){ }
	
	return HTMLSOURCE;		
}
function downloadFile(pFile)
{
	actionframe.location.href="/app/include/HtmlEditor/file_download.asp?file="+pFile;
}

function downloadFile2(pFile, pMenuIdx)
{
	actionframe.location.href="/app/include/HtmlEditor/file_download2.asp?file="+pFile+"&menuidx="+pMenuIdx;
}
