
//----------------------------------------------------------------------------------------------------------
// 위지윅 에디터(WYSWYG Editor)
// Date : 2007.03.12
// Made By Junios
// Update : 2007.03.21 (Edit By Junios)
// Update : 2007.03.26 (Edit By Junios)
// Update : 2007.03.29 (Edit By Junios)
// Update : 2010.01.18 (Edit By Espeniel) * 몇줄 추가하고 은근슬쩍 에디터 제작자로 묻어가기;;
// Version : 1.1
//----------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------
// 에디터를 생성자 및 기본 사용할 변수를 선언한다.
//----------------------------------------------------------------------------------------------------------
JEditor = function()
{
	this.nWidth = 642;									//에디터 width 
	this.nHeight = 390;									//에디터 height
	this.nIconHeight = 18;								//아이콘의 크기(서브 레이어를 위해서 필요)

	this.szContents;									//Editing contents
	this.objPlainEditor;								//TextEditor Object
	this.objRichEditor;									//RichEditor Object
	this.objToolbars;									//Toolbar Object
	this.objMenuLayer;									//서브 메뉴를 위한 레이어

	//브라우져종류 체크
	this.bOpera;										//Opera
	this.bOthers;										//IE, MSIE, FF이외 브라우져
	this.bFF;											//FireFox
	this.bMSIE;											//MS Internet Explorer
	this.bMSIE60;										//MS Internet Explorer 6.0
	this.bServicePack;									//Windows Servicepack 적용

	//에디터 모드 설정
	this.bRichMode = true;								//에디터 WYSWYG 모드 상태(false/true)
	this.bUseRichMode = false;							//에디터 WYSWYG 모드 사용 가능 여부

	this.szUseFontname = "돋움";						//에디터에서 사용 하는 폰트
	this.bUploading = false;							//파일 다운로드중에 확인을 위한 변수
	this.bUseFileUpload = false;						//파일 업로드 기능을 사용 가능 여부
	this.szFileUploadPath = "/images/";					//업로드된 파일 저장 되는 공간

	this.szEditorBorder = "#CDCDCD";					//에디터 툴바 테두리 색

	this.objRange;										//선택된 텍스트를 가르키는 오브젝트

	//Rich Editor모드의 기본 스타일 시트
	this.szMainStyle = "<style type='text/css'>";
	this.szMainStyle += " p {padding:0px; margin:0px; border:0px; font-size:12px; font-family:'"+this.szUseFontname+"'; } ";
	this.szMainStyle += " div {padding:0px; margin:0px; border:0px; font-size:12px; font-family:'"+this.szUseFontname+"';} ";
	this.szMainStyle += ".morenless {border: 1px dashed #A8A491; background: #FFFBE7; padding: 5px 5px 5px 5px;}";
	this.szMainStyle += " body {padding:10px; margin:0px; border:0px; font-size:12px; font-family:'"+this.szUseFontname+"'; overflow:auto; word-break:break-all;} ";
	this.szMainStyle += "</style>";

	//툴바 사이즈
	this.nToolbarsWidth = "100%"
	this.nToolbarsHeight = 27; //툴바한줄 사이즈

	//RichEditor 모드의 창 사이즈
	this.nRichEditorWidth = "100%";
	this.nRichEditorHeight = this.nHeight - this.nToolbarsHeight - 1;

	//PlainEditor 모드의 창 사이즈
	this.nPlainEditorWidth = "100%";
	this.nPlainEditorHeight = this.nHeight;

	//icon 파일 위치
	this.szIconPath = "http://www.pdbox.co.kr/community/image_btn/";
	this.szEmoticonPath = "http://www.pdbox.co.kr/community/image_bbs/";

	this.szDeleteFileScript = "http://ftp2.2ndrive.com:8022/app/newboard_delete_2ndrive.php";

	//툴바 기능 리스트
	// "|"  : 분리자를 추가 한다.
	// "\n" : 툴바에서 다음줄로 이동한다(한줄이 추가되면 this.nToolbarsHeight를 줄 수 만큼 늘려준다. 그렇지 않으면 화면이 깨진다.)
	// JSON ?
	this.FunctionLists =
	{
		"1":             ["FontName",                "글자체",          "Select",               false ],
		"2":             ["FontSize",                "크기",            "Select",               false ],
		"3":             ["Bold",                    "굵게",            "text_01.gif",          true ],
		"4":             ["Underline",               "밑줄",            "text_02.gif",          true ],
		"5":             ["Italic",                  "기울임체",        "text_03.gif",          true ],
		"6":             ["StrikeThrough",           "취소선",          "text_04.gif",          true ],
		"7":             ["ForeColor",               "글자색",          "text_05.gif",          false ],
		"8":             ["BackColor",               "배경색",          "text_06.gif",          false ],
		"9":             ["|",                       "|",               "line.gif",             false ],
		"10":            ["JustifyLeft",             "왼쪽정렬",        "text_07.gif",          true ],
		"11":            ["JustifyCenter",           "가운데정렬",      "text_08.gif",          true ],
		"12":            ["JustifyRight",            "오른쪽정렬",      "text_09.gif",          true ],
		"13":             ["|",                       "|",               "line.gif",            false ],
		"14":            ["CreateLink",              "링크걸기",        "link.gif",             true ],
		"15":            ["MorenLess",               "더보기/접기",     "moreview.gif",         true ],
		"16":             ["|",                       "|",              "line.gif",             false ],
		"17":            ["Undo",                    "취소",            "undo.gif",             false ],
		"18":            ["Redo",                    "재실행",          "redo.gif",             false ]
	};

	//글꼴 리스트
	this.FontLists = [ "돋움", "굴림", "바탕", "궁서", "verdana", "Arial", "Times" ];
	//글자 크기
	this.FontSizeLists = [ "7pt", "10pt", "12pt", "14pt", "18pt", "24pt", "36pt" ];

	//확인, 취소버튼 
	this.szControlButtons = [ "ok_btn.gif", "cancel_btn.gif" ];

	//이모티콘 리스트
	this.szEmoticonLists = [ "pdoll_01.gif", "pdoll_02.gif", "pdoll_03.gif", "pdoll_04.gif", "pdoll_05.gif", "pdoll_06.gif", "pdoll_07.gif", "pdoll_08.gif", 
		"pdoll_09.gif", "pdoll_10.gif", "pdoll_11.gif", "pdoll_12.gif"];

	this.szEmoticonListObjs = new Array();
}

//----------------------------------------------------------------------------------------------------------
// 에디터를 생성하고 기본값을 입력한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.Init = function() {
    //브라우져 정보에 관한 객체를 초기화 한다.
    this.BrowserCheck();

    //툴바 줄수 늘려주기
    var nTemp = 0;
    for (var i in this.FunctionLists)
        if (this.FunctionLists[i][2] == "\n")
        nTemp++;
    this.nToolbarsHeight += (nTemp * this.nToolbarsHeight);
    this.nRichEditorHeight = this.nHeight - this.nToolbarsHeight;
    this.nPlainEditorHeight = this.nHeight;

    //특정브라우져마다 설정(사이즈가 약간씩 다르다)
    if (this.bMSIE) {
        this.nPlainEditorHeight -= 3;
        this.nRichEditorHeight -= 1;
    }
    else if (this.bFF)
        this.nPlainEditorHeight -= 1;
    else if (this.bOpera) {
        this.nPlainEditorHeight -= 2;
        this.nRichEditorHeight -= 1;
    }
    else
        this.nPlainEditorHeight -= 1;

    //Rich Editor를 위한 iframe 객체 생성
    this.objRichEditor = document.createElement("iframe");
    this.objRichEditor.setAttribute("id", "RichEditor");
    this.objRichEditor.style.width = this.nRichEditorWidth;
    this.objRichEditor.style.height = this.nRichEditorHeight + "px";
    this.objRichEditor.style.border = "0px none";
    this.objRichEditor.scrolling = "auto";

    //툴바를 위한 div태크 만들기
    this.objToolbars = document.createElement("div");
    this.objToolbars.setAttribute("id", "toolbars");
    this.objToolbars.style.width = this.nToolbarsWidth;
    this.objToolbars.style.height = this.nToolbarsHeight + "px";
    this.objToolbars.style.border = "0px solid";
    this.objToolbars.style.lineHeight = "1";
    this.objToolbars.style.borderBottom = "1px solid " + this.szEditorBorder;

    //HTML 일반 에디터를 위한 textarea객체 생성
    this.objPlainEditor = document.createElement("textarea");
    this.objPlainEditor.setAttribute("id", "PlainEditor");
    this.objPlainEditor.style.width = this.nPlainEditorWidth;
    this.objPlainEditor.style.height = this.nPlainEditorHeight + "px";
    this.objPlainEditor.style.border = "0px none";
    this.objPlainEditor.scrolling = "auto";
    this.objPlainEditor.style.fontFamily = this.szUseFontname;
    this.objPlainEditor.style.fontSize = "12px";


    //위지윅 에디터는 FF, IE, Opera만 사용가능
    if (this.bMSIE || this.bFF || this.bOpera) {
        document.write("<div id='DivRichEditor' style='border: 1px solid " + this.szEditorBorder + "; display: block; width:" + this.nWidth + "px; height:" + this.nHeight + "px;'></div>");

        this.objDivRichEditor = document.getElementById("DivRichEditor");
        this.objDivRichEditor.appendChild(this.objToolbars);
        this.objDivRichEditor.appendChild(this.objRichEditor);

        //메뉴 레이어 만들기
        document.write("<div id='MenuLayer' style='display: block; position: absolute;'></div>");
        this.objMenuLayer = document.getElementById("MenuLayer");

        //자주 사용하는 윈도우 객체를 저장
        this.objRichEditor.CurrentWindow = this.objRichEditor.contentWindow;
        this.objRichEditor.CurrentDocument = this.objRichEditor.CurrentWindow.document;
        this.objRichEditor.CurrentDocument.designMode = "on";

        //위지윅 에디터의 상태를 설정, 스크롤바 설정
        this.objRichEditor.CurrentDocument.open("text/html", "replace");
        this.objRichEditor.CurrentDocument.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
        this.objRichEditor.CurrentDocument.write('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/>');
        this.objRichEditor.CurrentDocument.write(this.szMainStyle);
        this.objRichEditor.CurrentDocument.write("</head><body topmargin=0 leftmargin=0>");
        this.objRichEditor.CurrentDocument.write("</body></html>");
        this.objRichEditor.CurrentDocument.close();

        //이벤트 등록하기
        if (this.bMSIE)
        {
            this.objRichEditor.CurrentDocument.attachEvent("onkeydown", this.ProcessKeyDown);
            this.objRichEditor.CurrentDocument.attachEvent("onmousedown", this.ProcessMouseDown);
        } else {
            this.objRichEditor.CurrentDocument.addEventListener("keydown", this.ProcessKeyDown, false);
            this.objRichEditor.CurrentDocument.addEventListener("mousedown", this.ProcessMouseDown, false);
        }

        if (this.bFF) //IE와 같은 결과를 위해서 CSS기능 끈다.
        {
            this.objRichEditor.CurrentDocument.execCommand("useCSS", false, false);
        }

        for (var i = 0; i < this.szEmoticonLists.length; i++)
        {
            this.szEmoticonListObjs[i] = new Image();
            this.szEmoticonListObjs[i].src = this.szEmoticonPath + this.szEmoticonLists[i];
        }

        //툴바 만들기
        this.CreateToolbar();

        this.bRichMode = true;
        this.bUseRichMode = true;
    } else {
        this.bRichMode = false;
    }

    document.write("<div id='DivPlainEditor' style='border: 1px solid " + this.szEditorBorder + "; display: none; width:" + this.nWidth + "px; height:" + this.nHeight + "px;'></div>");
    objTemp = document.getElementById("DivPlainEditor");
    this.objDivPlainEditor = objTemp;
    objTemp.appendChild(this.objPlainEditor);

    if (this.bUseRichMode && this.bUseFileUpload)			//파일 업로드 폼 사용하기
        document.write(this.CreateFileForm());

    //모드에 따라 화면 바꿔주기
    this.SetDisplay();
}


//----------------------------------------------------------------------------------------------------------
// 파일을 업로드 처리 한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.AttachFile = function ()
{
	var objUploadFileForm = document.getElementById("UploadFileForm");

	if ( this.bUploading )
	{
	    alert("파일 업로드 중입니다");
		return;
	}

	if ( objUploadFileForm.attachfile.value == "" || objUploadFileForm.attachfile.value.length < 10 )
	{
		alert("파일을 선택 해 주세요")
		return;
	}

	this.bUploading = true;
	objUploadFileForm.target = "ActionFrame";
	objUploadFileForm.action = this.szUploadFileScript;
	objUploadFileForm.submit();
}



//----------------------------------------------------------------------------------------------------------
// 파일 입력 폼을 만들어 준다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateFileForm = function() {
    var szTemp = "<div id=\"FileUploadForm\" style=\"display: none;\">";
    szTemp += "<table width=" + (this.nWidth + 3) + " border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"5\">";
    szTemp += "<form enctype=\"multipart/form-data\" name=\"UploadFileForm\" id=\"UploadFileForm\" method=\"post\">";
    szTemp += "<tr>";
    szTemp += "<td></td>";
    szTemp += "</tr>";
    szTemp += "</table>";
    szTemp += "<table width=" + (this.nWidth + 3) + " cellpadding=\"0\" cellspacing=\"0\" class=\"tap_box\">";
    szTemp += "<tr>";
    szTemp += "<td height=\"25\" width=\"444\" bgcolor=\"#EDEDED\" style=\"padding: 3px 0px 0px 13px\" width=\"446\"><span class=\"gray_b01\">첨부된";
    szTemp += "파일들</span> <span class=\"album_text\">(1개당<font color=\"#FF6600\">3MB";
    szTemp += "미만</font>의 이미지만 등록할 수 있습니다.)</span></td>";
    szTemp += "<td height=\"25\" width=\"200\" bgcolor=\"#EDEDED\" style=\"padding: 2px 6px 0px 0px\" align=\"right\" width=\"205\">";
    szTemp += "<a href=\"javascript:Editor.DeleteFile(document.getElementById('FileList'))\">";
    szTemp += "<img src=\"http://www.pdbox.co.kr/community/image_btn/filedelete_btn.gif\" width=\"43\" height=\"18\" border=\"0\"></a></td>";
    szTemp += "</tr>";
    szTemp += "</table>";
    szTemp += "<table width=" + (this.nWidth + 3) + " cellpadding=\"0\" cellspacing=\"0\">";
    szTemp += "<tr>";
    szTemp += "<td height=\"43\" style=\"padding: 7 7 0 7px\" valign=\"top\">";
    szTemp += "<select id=\"FileList\" name=\"FileList\" size=2 style=\"width: " + (this.nWidth + 3) + "px; height: 50px;\">";
    szTemp += "</select>";
    szTemp += "<input name=\"deletefileinfo\" id=\"deletefileinfo\" type=\"hidden\">";
    szTemp += "<input name=\"deletefileindex\" id=\"deletefileindex\" type=\"hidden\">";
    szTemp += "<input name=\"board\" id=\"board\" type=\"hidden\">";
    szTemp += "<input name=\"hostname\" id=\"hostname\" type=\"hidden\">";
    szTemp += "</td>";
    szTemp += "</tr>";
    szTemp += "</form>";
    szTemp += "</table>";
    szTemp += "<iframe id=\"ActionFrame\" name=\"ActionFrame\" width=600 height=200 style=\"display: inline;\"></iframe></div>";
    szTemp += "</div>";

    return szTemp;
}


//----------------------------------------------------------------------------------------------------------
// 선택한 파일 삭제 한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.DeleteFile = function( objArg )
{
	if ( objArg.selectedIndex == -1 )
	{
		alert("삭제하실 파일을 선택해주세요")
		return;
	}

	var objUploadFileForm = document.getElementById("UploadFileForm");
	objUploadFileForm.deletefileindex.value = objArg.selectedIndex;
	objUploadFileForm.deletefileinfo.value = objArg.options[objArg.selectedIndex].value
	objUploadFileForm.board.value = document.writeForm.board.value;
	objUploadFileForm.hostname.value = document.location.hostname;

	objUploadFileForm.target = "ActionFrame";
	objUploadFileForm.action = this.szDeleteFileScript;
	objUploadFileForm.submit();
}


//----------------------------------------------------------------------------------------------------------
// 에디터를 Rich와 Plain모드를 변경한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.ChangeMode = function()
{
	if ( !this.bUseRichMode ) //위지웍 모드를 사용 할 수 없다.
	{
		this.bRichMode = false;
		this.SetDisplay();
	}
	else
	{
		this.bRichMode = !this.bRichMode;
		this.SetDisplay();
	}
}

	//----------------------------------------------------------------------------------------------------------
	// 변경된 에디터의 모드를 화면에 반영한다.
	//----------------------------------------------------------------------------------------------------------
JEditor.prototype.SetDisplay = function()
{
	if ( this.bUseRichMode ) //위지웍 모드를 사용 할 수 있다.
	{
		if ( this.bRichMode == true )
		{
			var szTemp = this.objPlainEditor.value;

			this.objPlainEditor.value = szTemp;
			this.objRichEditor.CurrentDocument.body.innerHTML = this.objPlainEditor.value;
			this.objDivPlainEditor.style.display = "none";
			this.objDivRichEditor.style.display = "block";
		}
		else
		{
			this.objPlainEditor.value = this.objRichEditor.CurrentDocument.body.innerHTML;
			this.objDivPlainEditor.style.display = "block";
			this.objDivRichEditor.style.display = "none";
		}

		this.objMenuLayer.style.display = "none";
	}
	else
	{
		this.objDivPlainEditor.style.display = "block";
	}
}



//----------------------------------------------------------------------------------------------------------
// 에디터의 내용을 가지고 온다.
// Return : 현재 사용중인 에디터 창의 내용을 넘겨준다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.GetContents = function( bHTML )
{
	if ( this.bRichMode )
	{
		if ( bHTML )
			return this.StripHTML(this.objRichEditor.CurrentDocument.body.innerHTML);
		else
			return this.objRichEditor.CurrentDocument.body.innerHTML;
	}
	else
	{
		if ( bHTML )
			return this.StripHTML(this.objPlainEditor.value);
		else
			return this.objPlainEditor.value;
	}
}



//----------------------------------------------------------------------------------------------------------
// 에디터의 내용을 가지고 온다.
// Input : szContents - 현재 사용중인 에디터 창의 내용을 설정한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.SetContents = function( szContents )
{
	if ( this.bRichMode )
		this.objRichEditor.CurrentDocument.body.innerHTML = szContents;
	else
		this.objPlainEditor.value = szContents;
}



//----------------------------------------------------------------------------------------------------------
// 에디터 툴바를 만들어 준다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateToolbar = function()
{
	var szToolbarTag = "";
	var bFirst = true;

	for(var i in this.FunctionLists )
	{
		if ( bFirst )
		{
			szToolbarTag += "<div class=\"toolbars\">";
			bFirst = false;
		}

		T = this.FunctionLists[i];
		switch( T[2] )
		{
			case "Select":
				switch( T[0] )
				{
					case "FontName":
						szToolbarTag += "<select id=\"_"+T[0]+"\" OnChange=\"Editor.EditContents('"+T[0]+"', this)\"><option value=\""+T[1]+"\" />"+T[1];
						for(var j = 0; j < this.FontLists.length; ++j )
						{
							szToolbarTag = szToolbarTag + "<option value=\"" + this.FontLists[j] + "\" />" + this.FontLists[j];
						}
						szToolbarTag +=  "</select>";
					break;
					case "FontSize":
						szToolbarTag += "<select id=\"_"+T[0]+"\" OnChange=\"Editor.EditContents('"+T[0]+"', this)\"><option value=\""+T[1]+"\" />"+T[1];
						for(var j = 0; j < this.FontSizeLists.length; ++j )
						{
							szToolbarTag = szToolbarTag + "<option value=\"" + (j+1) + "\" />" + (j+1) + "(" + this.FontSizeLists[j] + ")";
						}
						szToolbarTag += "</select>";
					break;
				}
				break;

			case "line.gif":
				szToolbarTag += "<img class=\"bar\" src=\"" + this.szIconPath +  T[2] + "\" border=0 />";
				break;

			case "\n":
				szToolbarTag += "</div><br><br><div class=\"toolbars\">";
				break;
            
			default:
				
				if ( T[3] ) //롤 오버 기능
				{
					szToolbarTag += "<a href=\"javascript:void(0);\" onclick=\"Editor.EditContents('" + T[0] + "', this)\"><img src=\"";
					szToolbarTag += this.szIconPath +  T[2] + "\" border=0 alt=\"" + T[1] + "\" onMouseover=\"this.className='selectedicon';\" ";
					szToolbarTag += "onMouseout=\"this.className='noselectedicon'\" class=\"noselectedicon\" /></a>";
				}
				else
				{
					szToolbarTag += "<a href=\"javascript:void(0);\" onclick=\"Editor.EditContents('" + T[0] + "', this)\"><img src=\"";
					szToolbarTag += this.szIconPath +  T[2] + "\" border=0 alt=\"" + T[1] + "\" class=\"noselectedicon\" /></a>";
				}
				

				break;

		}
	}

	szToolbarTag += "</div>";

	document.getElementById("toolbars").innerHTML = szToolbarTag;
}

//----------------------------------------------------------------------------------------------------------
// 툴바에 있는 명령을 처리 한다.
// input : szCommand - 태그를 위한 명령어
//       : objArg1   - 특별히 사용되는 아규먼트
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.EditContents = function(szCommand, objArg1) {

    var selection = this.GetSelection();
    this.objRange = this.CreateRange(selection);
    this.ShowMenuLayer(false);

    this.CheckSelection();

    switch (szCommand) {
        case "FontName":
            if (objArg1.options[objArg1.selectedIndex].value != '')
                this.objRichEditor.CurrentDocument.execCommand(szCommand, false, objArg1.options[objArg1.selectedIndex].value);
            objArg1.selectedIndex = 0;
            break;

        case "ForeColor":
        case "BackColor":
            var nTop = 250;
            var nLeft = 250;

            this.CreateColorTable(szCommand);
            this.objMenuLayer.style.left = nLeft + "px";
            this.objMenuLayer.style.top = nTop + "px";
            this.ShowMenuLayer(true);
            break;

        case "FontSize":
            if (objArg1.options[objArg1.selectedIndex].value != '')
                this.objRichEditor.CurrentDocument.execCommand(szCommand, false, objArg1.options[objArg1.selectedIndex].value);
            objArg1.selectedIndex = 0;
            break;

        case "Bold":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Italic":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Underline":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "StrikeThrough":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Undo":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Redo":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "JustifyLeft":
            if (this.bMSIE) {
                var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
                if (objRange.htmlText != undefined && objRange.htmlText != "") {
                    var szTemp = objRange.htmlText;
                    szTemp = szTemp.replace(/<P align=(center|left|right)>/, "");
                    szTemp = szTemp.replace(/<\/P>/, "");
                    objRange.pasteHTML("<p align=left>" + szTemp + "</p>");
                }
                else if (objRange.htmlText == undefined) {
                    this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
                }

            }
            else
                this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "JustifyCenter":
            if (this.bMSIE) {
                var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
                if (objRange.htmlText != undefined && objRange.htmlText != "") {
                    var szTemp = objRange.htmlText;
                    szTemp = szTemp.replace(/<P align=(center|left|right)>/, "");
                    szTemp = szTemp.replace(/<\/P>/, "");
                    objRange.pasteHTML("<p align=center>" + szTemp + "</p>");
                }
                else if (objRange.htmlText == undefined) {
                    this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
                }
            }
            else
                this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "JustifyRight":
            if (this.bMSIE) {
                var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
                if (objRange.htmlText != undefined && objRange.htmlText != "") {
                    var szTemp = objRange.htmlText;
                    szTemp = szTemp.replace(/<P align=(center|left|right)>/, "");
                    szTemp = szTemp.replace(/<\/P>/, "");
                    objRange.pasteHTML("<p align=right>" + szTemp + "</p>");
                }
                else if (objRange.htmlText == undefined) {
                    this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
                }
            }
            else
                this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;
            
        case "CreateLink":
            var nTop = 250;
            var nLeft = 250;
            this.CreateLinkTable(szCommand);
            this.objMenuLayer.style.left = nLeft + "px";
            this.objMenuLayer.style.top = nTop + "px";
            this.ShowMenuLayer(true);
            break;

        case "Emoticon":
            var nTop = this.GetTop(objArg1) + this.nIconHeight;
            var nLeft = this.GetLeft(objArg1) - 87;
            this.CreateEmoticonTable();
            this.objMenuLayer.style.left = nLeft + "px";
            this.objMenuLayer.style.top = nTop + "px";

            for (var i = 0; i < this.szEmoticonLists.length; ++i) {
                document.getElementById(this.szEmoticonLists[i]).appendChild(this.szEmoticonListObjs[i]);
            }

            this.ShowMenuLayer(true);
            break;

        case "InsertOrderedList":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "InsertUnorderedList":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Subscript":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "Superscript":
            this.objRichEditor.CurrentDocument.execCommand(szCommand, false, "");
            break;

        case "InsertObject":
            if (objArg1.value == "") {
                alert("삽입할 파일 선택 해주세요.");
                return;
            }
            
            var szTempHTML = "";
            var szFilename = objArg1.value.split("@#$%");
            switch (szFilename[2]) {
                case "jpg":
                case "gif":
                case "png":
                case "bmp":
                    var szTempHTML = "<img src=\"" + this.szFileUploadPath + szFilename[0] + "\" border=0>";
                    break;

                case "mp3":
                case "wav":
                case "wma":
                    var szTempHTML = "<embed src=\"" + this.szFileUploadPath + szFilename[0] + "\"></embed>";
                    break;

                case "avi":
                case "mov":
                case "wmv":
                case "asf":
                    var szTempHTML = "<embed src=\"" + this.szFileUploadPath + szFilename[0] + "\"></embed>";
                    break;

                default:
                    var szTempHTML = "<a href=\"" + this.szFileUploadPath + szFilename[0] + "\" target=\"blank\">" + szFilename[0] + "</a>";
            }
            this.InsertHTML(szTempHTML);
            break;

        case "MorenLess":
            var szHTML1 = "<div class=\"morenless\" type=\"morenless\">";
            var szMsg = "더보기 클릭 시 펼쳐지는 내용을 입력해주세요.";
            var szHTML2 = "</div>";

            this.CheckSelection();
            this.objRichEditor.CurrentWindow.focus();

            if (this.bFF || this.bOpera) //FireFox
            {
                if (selection.anchorNode.nodeValue) {
                    //this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1 + this.objRange); //By Espeniel
                    this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1);
                }
                else {
                    //this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1 + szMsg + this.objRange); //By Espeniel
                    this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1 + szMsg);
                }
            }
            else if (this.bMSIE) //IE
            {
                var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
                if (objRange.pasteHTML) {
                    if (szHTML2) {
                        if (objRange.htmlText != undefined && objRange.htmlText != "") {
                            objRange.pasteHTML(szHTML1 + objRange.htmlText + szHTML2);
                        }
                        else {
                            objRange.pasteHTML(szHTML1 + szMsg + szHTML2);
                        }
                    }
                    else
                        objRange.pasteHTML(szHTML1);
                }
            }

            break;
    }
}


//----------------------------------------------------------------------------------------------------------
// 객체의 Y축 위치를 가져온다.
// Input : objNode - 위치를 알아내야 할 객체
// Retunrn : ObjNode의 Y축 좌표값
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.GetTop = function(oNode) {
    var objCurrentNode = oNode;
    var nTop = 0;
    while (objCurrentNode.tagName != "BODY") {
        nTop += objCurrentNode.offsetTop;
        objCurrentNode = objCurrentNode.offsetParent;
    }
    return nTop;
}


//----------------------------------------------------------------------------------------------------------
// 객체의 X축 위치를 가져온다.
// Input : objNode - 위치를 알아내야 할 객체
// Retunrn : ObjNode의 X축 좌표값
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.GetLeft = function( objNode )
{
	var objCurrentNode = objNode;
	var nLeft = 0;

	while( objCurrentNode.tagName != "BODY" )
	{
		nLeft += objCurrentNode.offsetLeft;
		objCurrentNode = objCurrentNode.offsetParent;
	}

	return nLeft;
}


//----------------------------------------------------------------------------------------------------------
// 태그로 변환하기 위한 영역을 지정 했는지 확인한다.(IE는 지정영역 날라 간다)
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CheckSelection = function()
{
	if ( this.objRange != null && this.bMSIE )
	{
		this.objRichEditor.CurrentDocument.focus();
		this.objRange.select();
	}
}

//----------------------------------------------------------------------------------------------------------
// 태그로 변환하기 위한 영역을 지정한다.
// return : 커서가 선택하고 있는 영역
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.GetSelection = function()
{
	if ( this.bMSIE ) 
		return this.objRichEditor.CurrentDocument.selection;
	else
		return this.objRichEditor.CurrentWindow.getSelection();
}

//----------------------------------------------------------------------------------------------------------
// 태그로 변환하기 위한 영역을 생성한다.
// input : objSelection - 커서가 선택하고 있는 영역
// return : 새로 태그가 들어갈 영역
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateRange = function( objSelection ) 
{
	if ( this.bMSIE ) 
	{
		return objSelection.createRange();
	} 
	else 
	{
		this.objRichEditor.CurrentWindow.focus();
		if (typeof Selection != "undefined") 
		{
			try
			{
				return objSelection.getRangeAt(0);
			} 
			catch(e)
			{
				return this.objRichEditor.CurrentDocument.createRange();
			}
		} 
		else 
		{
			return this.objRichEditor.CurrentDocument.createRange();
		}
	}
}

//----------------------------------------------------------------------------------------------------------
// 에디터에서 선택된 부분에 원하는 HTML태그를 삽입한다.
// input : szHTML - 원하는 태그
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.InsertHTML = function(szHTML1, szHTML2, szArg1) {

    this.CheckSelection();
    this.objRichEditor.CurrentWindow.focus();

    if (this.bRichMode) {
        if (this.bFF || this.bOpera) //FireFox
        {
            //this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1 + this.objRange); FF undefined.. By Espeniel 2010.01.19
            this.objRichEditor.CurrentDocument.execCommand("insertHTML", false, szHTML1);
        }
        else if (this.bMSIE) //IE
        {
            var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
            try {
                if (szHTML2) {
                    if (objRange.htmlText != undefined && objRange.htmlText != "") {
                        objRange.pasteHTML(szHTML1 + objRange.htmlText + szHTML2);
                    }
                    else {
                        if (szArg1 != "" && szArg1 != undefined)
                            objRange.pasteHTML(szHTML1 + szArg1 + szHTML2);
                    }
                }
                else {
                    objRange.pasteHTML(szHTML1);
                }
            }
            catch (e) {
            }
        }
    }
    else {
        if (this.bMSIE) {
            var objRange = this.objPlainEditor;
            if (objRange.createTextRange && objRange.caretPos) {
                objRange.caretPos.text = objRange.caretPos.text.charAt(objRange.caretPos.text.length - 1) == ' ' ? szHTML1 + ' ' : szHTML1;
                objRange.focus();
            }
            else {
                objRange.value = objRange.value + szHTML1;
            }
        }
    }
}


//----------------------------------------------------------------------------------------------------------
// 에디터에서 선택된 부분에 원하는 HTML태그를 삽입한다.
// input : szHTML - 원하는 태그
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.ShowMenuLayer = function( bShow )
{
	this.objMenuLayer.style.position = "absolute";
	this.objMenuLayer.style.backgroundColor = "#EDEDED";

	this.objMenuLayer.style.display = bShow ? "block" : "none";
}


//----------------------------------------------------------------------------------------------------------
// 에디터에서 선택된 부분에 원하는 HTML태그를 삽입한다.
// input : szHTML - 원하는 태그
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.ShowToolbars = function( bShow )
{
	document.getElementById("toolbars").style.display = bShow ? "block" : "none";
}



//----------------------------------------------------------------------------------------------------------
// 색 설정 테이블을 만든다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateColorTable = function( szArg1 )
{
	var szColorTable = new Array( 
	    "FFFFFF", "E6E6E6", "CDCDCD", "B4B4B4", "A8A8A8", "8D8D8D", "747474", "595959", "4B4B4B",
	    "303030", "0A0A0A", "000001", "FEF4C4", "FEED9B", "FEE573", "FFED43", "F6CC0B", "E0B800",
	    "C9A601", "AD8E00", "8C7301", "6D5B09", "534A23", "534A23", "FFBAB7", "FE9A95", "FF7A73",
	    "FF483F", "FE2419", "F10B00", "D40A00", "940000", "6D201B", "8C0957", "F832AB", "E477BA",
	    "C7E2FE", "ADD5FE", "92C7FE", "6EB5FF", "48A2FF", "2690FE", "0162F4", "013ADD", "5B62D7",
	    "5A0093", "5A0093", "C286E8", "DFFEAA", "D1FD88", "BEFA5A", "A8F32A", "8FD80A", "79C101",
	    "3FA701", "307F00", "156200", "009869", "50AA90", "7DAE76", "D4C89F", "DAAD88", "C49578",
	    "C2877E", "AC8295", "C0A5C4", "969AC2", "92B7D7", "80ADAF", "00A0C2", "0084A0", "9CA53B"
	);

	var szHTML = "<div style=\"border: 1px solid #9B9B9B; padding: 5px 5px 5px 5px;\">";
	szHTML += "<table border=0 cellpadding=0 cellspacing=0>";
	szHTML += "<tr>"; 
	szHTML += "<td bgcolor=#EDEDED valign=top>";
	szHTML += "<table border=0 cellspacing=0 cellpadding=0>";
	szHTML += "<tr>";
	szHTML += "<td bgcolor=\"#FFFFFF\">";
	szHTML += "<table border=0 cellpadding=0 cellspacing=1>";
	for( i = 0, k = 0; i < 6; ++i )
	{
		szHTML += "<tr>";
		for ( j = 0; j < 12 ; ++j, k++ )
		{
			szHTML += "<td width=11 height=11 bgcolor=#" + szColorTable[k] + " onclick=\"Editor.SelectColor('";
			szHTML += szColorTable[k] + "', '" + szArg1 + "' )\"></td>";
		}
		szHTML += "</tr>";
	}
	szHTML += "</table>";
	szHTML += "<table width=100% border=0 cellpadding=0 cellspacing=0 height=24 bgcolor=#EDEDED>";
	szHTML += "<tr>";
	szHTML += "<td height=6></td>";
	szHTML += "</tr>";
	szHTML += "<tr>";
	szHTML += "<td><img src=http://www.pdbox.co.kr/community/image_bbs/image_masseage01.gif width=38 height=11>&nbsp;&nbsp;";
	szHTML += "<input type=text id=selectcolor size=8 style=\"color:#666666; font-size: 9pt ;font-family: '돋움', 'verdana';line-height: 15px; background-color:#ffffff; border:1px solid  #b7b7b7;\" maxlength=6>";
	szHTML += "&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"Editor.SelectColor( document.getElementById('selectcolor').value, '" + szArg1 + "' )\">";
	szHTML += "<img src=\""+this.szIconPath+this.szControlButtons[0]+"\" width=32 height=18 align=absmiddle border=0></a>";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</div>";

	this.objMenuLayer.innerHTML = szHTML;
}


//----------------------------------------------------------------------------------------------------------
// 색 설정 테이블에서 커서가 보이는 색 값을 화면에 출력해준다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.SelectedColor = function( szColor )
{
	objSelectedColor = document.getElementById("SelectedColor");
	objSelectedColor.style.background = "#" + szColor;
	objSelectedColorCode = document.getElementById("SelectedColorCode");
	objSelectedColorCode.value = "#" + szColor;
}


//----------------------------------------------------------------------------------------------------------
// 색 설정 테이블에서 선택한 색을 적용한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.SelectColor = function( szColor, szArg1 )
{
	this.CheckSelection();
	this.objRichEditor.CurrentWindow.focus();

	if ( szArg1 == "ForeColor" )	//글자색 바꾸기
		this.objRichEditor.CurrentDocument.execCommand("ForeColor", false, "#"+szColor );
	else	//글자 배경색 바꾸기
	{
		if ( this.bMSIE )
			this.objRichEditor.CurrentDocument.execCommand("BackColor", false, "#"+szColor );
		else
			this.objRichEditor.CurrentDocument.execCommand("hilitecolor", false, "#"+szColor );
	}

	this.ShowMenuLayer( false );//색상 선택 테이블 없애기

	return;
}


//----------------------------------------------------------------------------------------------------------
// 링크 입력 테이블을 만든다.
// Input - szArg1 : 명령어
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateLinkTable = function( szArg1 )
{
	var szHTML = "<div style=\"border: 1px solid #9B9B9B; padding: 5px 5px 5px 5px;\" >";
	szHTML += "<table width=\"234\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"60\">";
	szHTML += "<tr>";
	szHTML += "<td bgcolor=\"#EDEDED\" valign=\"top\" >";
	szHTML += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"60\">";
	szHTML += "<tr>";
	szHTML += "<td height=\"15\" valign=\"bottom\"><img src=\"http://www.pdbox.co.kr/community/image_bbs/image_masseage02.gif\" width=\"235\" height=\"10\"> ";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "<tr>";
	szHTML += "<td height=\"27\">";
	szHTML += "<input style=\"color:#666666; font-size: 9pt ;font-family: '돋움', 'verdana';line-height: 15px; background-color:#ffffff; border:1px solid  #b7b7b7;\" type=\"text\" id=\"LinkURL\" value=\"http://\" size=\"37\" />";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "<tr>";
	szHTML += "<td align=\"center\"><img src=\""+this.szIconPath+this.szControlButtons[0]+"\" onclick=\"Editor.CreateLink('"+szArg1+"')\">";
	szHTML += "<img src=\""+this.szIconPath+this.szControlButtons[1]+"\" onclick=\"Editor.ShowMenuLayer( false )\"></td>";
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</div>";

	this.objMenuLayer.innerHTML = szHTML;
}



//----------------------------------------------------------------------------------------------------------
// 링크를 연결한다.
// Input - szArg1 : 명령어
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateLink = function( szArg1 )
{
	this.CheckSelection();
	this.objRichEditor.CurrentWindow.focus();

	var szLink = document.getElementById("LinkURL").value;

	if ( this.bMSIE )
	{
		var objRange = this.objRichEditor.CurrentDocument.selection.createRange();
		if ( objRange.htmlText != undefined && objRange.htmlText != "")
		{
			this.InsertHTML("<a href=\""+szLink+"\" target=_blank>", "</a>");
		}
		else
			this.InsertHTML("<a href=\""+szLink+"\" target=_blank>", "</a>", szLink);
	}
	else
		this.objRichEditor.CurrentDocument.execCommand( szArg1, false, szLink );

	this.ShowMenuLayer( false );

	return;
}


//----------------------------------------------------------------------------------------------------------
// 브라우져에 관한 설정을 체크, 저장한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.BrowserCheck = function()
{
	//브라우져 종류를 체크 한다.
	var szBrowser = navigator.userAgent;

	if ( szBrowser.indexOf("MSIE 6.0;") != -1 )			//Internet Explorer 6.0
	{
		if ( szBrowser.indexOf("SV1") )					//서비스팩 2 설치 여부
		{
			this.bMSIE = true;
			this.bMSIE60 = true;
			this.bServicePack = true;
		}
		else
		{
			this.bMSIE = true;
			this.bMSIE60 = true;
			this.bServicePack = false;
		}
	}
	else if ( szBrowser.indexOf("MSIE 7.0;") != -1 )	//Internet Explorer 7.0
	{
		this.bMSIE = true;
		this.bMSIE70 = true;
		this.bServicePack = true;
	}
	else if ( szBrowser.indexOf("MSIE 8.0;") != -1 )	//Internet Explorer 8.0
	{
		this.bMSIE = true;
		this.bMSIE70 = true;
		this.bServicePack = true;
	}
	else if ( szBrowser.indexOf("Firefox") != -1 )		//Firefox
	{
		this.bFF = true;
	}
	else if ( szBrowser.indexOf("Opera") != -1 )		//Opera
	{
		this.bOpera = true;
	}
	else												//기타 브라우져
	{
		this.bOthers = true;
	}
}


//----------------------------------------------------------------------------------------------------------
// 이모티콘 테이블을 만든다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateEmoticonTable = function()
{
	var nLength = this.szEmoticonLists.length;

	var szHTML = "<table width=\"109\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	szHTML += "<tr>";
	szHTML += "<td bgcolor=\"#B2B2B2\">";
	szHTML += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
	szHTML += "<tr bgcolor=\"#FFFFFF\">";

	for( var i = 0; i < nLength; ++i )
	{
		if ( i % 4 == 0 && i != 0)
		{
			szHTML += "</tr><tr bgcolor=\"#FFFFFF\">";
		}
		if ( i < nLength )
		{
 			szHTML += "<td onclick=\"Editor.CreateEmoticon('" + this.szEmoticonLists[i] + "' )\"><div id='"+this.szEmoticonLists[i]+"'></div></td>";
		}
		else
			szHTML += "<td></td>";
	}
	szHTML += "</tr>";
	szHTML += "</table>";
	szHTML += "</td>";
	szHTML += "</tr>";
	szHTML += "</table>";

	this.objMenuLayer.innerHTML = szHTML;
	this.objMenuLayer.setAttribute( "style", "display: none;");
}

//----------------------------------------------------------------------------------------------------------
// 이모티콘을 삽입한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.CreateEmoticon = function( szArg1 )
{
	var szTempHTML = "<img src=\"" + this.szEmoticonPath + szArg1 + "\" border=0>";

	this.InsertHTML( szTempHTML );
	this.ShowMenuLayer(false);
}

//----------------------------------------------------------------------------------------------------------
// 주어진 문자열에서 HTML태그를 제거한다.
// Input : szMSG - HTML태그가 있는 문자열
// Retunrn : HTML태그를 없앤 문자열 
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.StripHTML = function( szMSG )
{
	szMSG = szMSG.replace( /</g, "&lt;" );
	szMSG = szMSG.replace( />/g, "&gt;" );
	szMSG = szMSG.replace(/&/gi,"&amp;");

	return szMSG;
}

//----------------------------------------------------------------------------------------------------------
// 위지윅 에디터에서 KeyDown를 처리한다.
// Input : e - event 객체(IE이외 이벤트 객체)
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.ProcessKeyDown = function(e) {
    var objEvent
    if (this.bMSIE) {
        objEvent = Editor.objRichEditor.CurrentWindow.event;
    }
    else
        objEvent = e;

    if (objEvent.keyCode == 13 && Editor.bMSIE) // IE에서 엔터를 입력하면 <br>태크로 처리 하기 위해서
    {
        var szTemp = "<br>";

        var objTemp = Editor.objRichEditor.CurrentDocument.selection.createRange();
        objTemp.pasteHTML(szTemp);

        objTemp.collapse(false);
        objTemp.select();

        return false;
    }

    Editor.UpdateToolbars();
}


//----------------------------------------------------------------------------------------------------------
// 위지윅 에디터에서 MouseDown를 처리한다.
// Input : e - event 객체(IE이외 이벤트 객체)
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.ProcessMouseDown = function(e) {
    var objEvent;

    if (this.bMSIE)
        objEvent = Editor.objRichEditor.CurrentWindow.event;
    else
        objEvent = e;

    HideGallery();

    Editor.UpdateToolbars();
    Editor.ShowMenuLayer(false);
}

function HideGallery()
{
    //	pdbox 갤러리 전용
	if ( document.getElementById("_boardGallery") != undefined )
	{
		document.getElementById("_boardGallery").style.display = "none";
	}
}


//----------------------------------------------------------------------------------------------------------
// 위지윅 에디터에서 툴바의 상태를 업데이트 한다.
//----------------------------------------------------------------------------------------------------------
JEditor.prototype.UpdateToolbars = function()
{
	var szFontName = this.objRichEditor.CurrentDocument.queryCommandValue('FontName');
	var szFontSize = this.objRichEditor.CurrentDocument.queryCommandValue('FontSize');

	//글꼴 업데이트
	var bFound = false;
	var objFontName = document.getElementById( "_FontName" );
	for ( i=1; i<objFontName.length; ++i )
	{
		if ( szFontName == objFontName[i].value )
		{
			objFontName.selectedIndex = i;
			bFound = true;
		}
	}
	if ( !bFound ) objFontName.selectedIndex = 1;

	//글자 크기 업데이트
	bFound = false;
	var objFontSize = document.getElementById( "_FontSize" );
	for ( i=0; i<objFontSize.length; ++i )
	{
		if ( szFontSize == objFontSize[i].value )
		{
			objFontSize.selectedIndex = i;
			bFound = true;
		}
	}

	if ( !bFound ) objFontSize.selectedIndex = 2;
}



var szEditorIcon = new Array("http://www.pdbox.co.kr/community/image_btn/editer_tap_on.gif",  "http://www.pdbox.co.kr/community/image_btn/editer_tap_off.gif");
var szHTMLIcon = new Array("http://www.pdbox.co.kr/community/image_btn/html_tap_on.gif", "http://www.pdbox.co.kr/community/image_btn/html_tap_off.gif");
var szTemp = new Array;
function ChangeMode( objTemp, bMode )
{
	HideGallery();

	if ( bMode )
	{
		if ( !Editor.bRichMode )
		{
			Editor.ChangeMode();
			document.getElementById("imgeditor").src = szEditorIcon[1];
			document.getElementById("imghtml").src = szHTMLIcon[1];
			document.getElementById(objTemp).src = szEditorIcon[0];
			szTemp[0] = document.getElementById("imgeditor").src;
			szTemp[1] = document.getElementById("imghtml").src;
		}
	}
	else
	{
		if ( Editor.bRichMode )
		{
			Editor.ChangeMode();
			document.getElementById("imgeditor").src = szEditorIcon[1];
			document.getElementById("imghtml").src = szHTMLIcon[1];
			document.getElementById(objTemp).src = szHTMLIcon[0];
			szTemp[0] = document.getElementById("imgeditor").src;
			szTemp[1] = document.getElementById("imghtml").src;
		}
	}
}

function OverMouse( objTemp, nMode )
{
	if ( nMode )
	{
		document.getElementById("imgeditor").src = szTemp[0];
		document.getElementById("imghtml").src = szTemp[1];
	}
	else
	{
		szTemp[0] = document.getElementById("imgeditor").src;
		szTemp[1] = document.getElementById("imghtml").src;
		document.getElementById("imgeditor").src = szEditorIcon[1];
		document.getElementById("imghtml").src = szHTMLIcon[1];
		if ( objTemp == "imgeditor" )
			document.getElementById(objTemp).src = szEditorIcon[nMode];
		else
			document.getElementById(objTemp).src = szHTMLIcon[nMode];
	}

}

function PreView()
{
	HideGallery();

	window.open('/app/tpl/editor/preview.php', 'preview', 'resizable=no,scrollbars=yes,status=no, toolbar=no, width=720, height=570');
}

function PreView_MyBox()
{
	HideGallery();

	window.open('/app/tpl/editor/preview_mybox.php', 'preview', 'resizable=no,scrollbars=yes,status=no, toolbar=no, width=720, height=470');
}

function Multi()
{
	HideGallery();

	window.open('/app/tpl/editor/multi_sticube.html', 'multi', 'resizable=no,scrollbars=no,status=no, toolbar=no, width=370, height=280');
}

function AppendImageList( szArg1, szArg2 )
{
	var ObjSelect = document.getElementById("FileList");
	ObjSelect.add( new Option(szArg1, szArg2) );
}

function AppendImage( nWhich, szArg2 )
{
    var szFilename = szArg2.split("@#$%");
    var szImageHTML;

    //이미지 width 700px 넘어가면 resize By Espeniel 2010.01.15
    //이미지 width 0 이면...
    var szWidth;
    var szImgPath = "http://ftp2.2ndrive.com:8022/temp2/" + szFilename[3];
    oImg = new Image();
    oImg.src = szImgPath;
    if (oImg.width > 700) {
        szWidth = "700";
    } else {
        szWidth = oImg.width;
    }

    switch( nWhich )
	{
	    case "1" :
	        szImageHTML = "<p align=center><a href=\"javascript:ImagePopup('http://ftp2.2ndrive.com:8022/temp2/" + szFilename[0] + "');\">";
	        if (szWidth == 0) {
	            szImageHTML += "<img src=\"" + szImgPath + "\" align=top border=0 onError=this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'></a></p>";
	        } else {
	            szImageHTML += "<img src=\"" + szImgPath + "\" width=" + szWidth + " align=top border=0 onError=this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'></a></p>";
	        }
	        break;
	    case "2" :
	        szImageHTML = "<p align=left><a href=\"javascript:ImagePopup('http://ftp2.2ndrive.com:8022/temp2/" + szFilename[0] + "');\">";
	        if (szWidth == 0) {
	            szImageHTML += "<img src=\"" + szImgPath + "\" border=0 onError=\"this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'\"></a><br></p>";
	        } else {
	            szImageHTML += "<img src=\"" + szImgPath + "\" width=" + szWidth + " border=0 onError=\"this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'\"></a><br></p>";
	        }
	        break;
	    case "3" :
	        szImageHTML = "<p align=right><a href=\"javascript:ImagePopup('http://ftp2.2ndrive.com:8022/temp2/" + szFilename[0] + "');\">";
	        if (szWidth == 0) {
                szImageHTML += "<img src=\"" + szImgPath + "\" border=0 onError=\"this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'\"></a><br></p>";
	        } else {
	            szImageHTML += "<img src=\"" + szImgPath + "\" width=" + szWidth + " border=0 onError=\"this.src='http://www.pdbox.co.kr/community/image_bbs/no_image.gif'\"></a><br></p>";
	        }
	        break;
	}

    Editor.InsertHTML(szImageHTML);
}

function Aprrove()
{
	var objTemp;
	var szFileinfo;
	var objForm = document.writeForm;
	var objCategory;
	var isChecked = false;

	objForm.b_content.value = Editor.GetContents();

	if ( Trim(objForm.b_subject.value) == "" )
	{
		alert("제목을 입력해주세요.");
		objForm.b_subject.focus();
		return;
	}

	if ( Trim(Editor.GetContents()) == "" || Editor.GetContents() == "<P>&nbsp;</P>" )
	{
		alert("내용을 입력해주세요.");
		Editor.objRichEditor.focus();
		return;
	}

	if (objForm.use_c != undefined && objForm.use_c.value == "Y")
	{
		objCategory = objForm.c_no;
		for ( i=0; i < objCategory.length ; i++)
		{
			if (objCategory[i].checked)
			{
				isChecked = true;
				break;
			}
		}

		if (!isChecked)
		{
			//alert("카테고리를 선택해 주세요.");
			//return;
		}
	}


	var objFiles = document.getElementById("FileList");

	if (  objFiles.length == 0)
	{
		if ( objForm.isGallery != undefined )
		{
			alert("갤러리는 이미지 파일을 한개 이상 올리셔야 합니다.");
			return;
		}
	}


	for ( var i = 0; i < objFiles.length; ++i)
	{
		szFileinfo = objFiles[i].value.split( "@#$%" );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_path[]");
		objTemp.setAttribute("value", szFileinfo[2]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_name[]");
		objTemp.setAttribute("value", szFileinfo[0]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_size[]");
		objTemp.setAttribute("value", szFileinfo[1]);
		objForm.appendChild( objTemp );
	}

	objForm.submit();

}

function Aprrove3()
{
	var objTemp;
	var szFileinfo;
	var objForm = document.writeForm;
	var objCategory;
	var isChecked = false;

	objForm.b_content.value = Editor.GetContents();

	if ( Trim(objForm.b_subject.value) == "" )
	{
		alert("제목을 입력해주세요.");
		objForm.b_subject.focus();
		return;
	}

	if ( Trim(Editor.GetContents()) == "" || Editor.GetContents() == "<P>&nbsp;</P>" )
	{
		alert("내용을 입력해주세요.");
		Editor.objRichEditor.focus();
		return;
	}


	if (objForm.use_c != undefined && objForm.use_c.value == "Y")
	{
		
		objCategory = objForm.c_no;

		for (i=0; i < objCategory.length ; i++)
		{
			if (objCategory[i].checked)
			{
				isChecked = true;
				break;
			}
		}

		if (!isChecked)
		{
//			alert("카테고리를 선택해 주세요.");
//			return;
		}
	}

	var objFiles = document.getElementById("FileList");
	/*
	if (  objFiles.length == 0)
	{
		if ( objForm.isGallery != undefined )
		{
			alert("갤러리는 이미지 파일을 한개 이상 올리셔야 합니다.");
			return;
		}
	}
*/

	for ( var i = 0; i < objFiles.length; ++i)
	{
		szFileinfo = objFiles[i].value.split( "@#$%" );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_path[]");
		objTemp.setAttribute("value", szFileinfo[2]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_name[]");
		objTemp.setAttribute("value", szFileinfo[0]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_size[]");
		objTemp.setAttribute("value", szFileinfo[1]);
		objForm.appendChild( objTemp );
	}

	objForm.submit();
}

function Aprrove4()
{
	var objTemp;
	var szFileinfo;
	var objForm = document.writeForm;
	var objCategory;
	var isChecked = false;

	objForm.b_content.value = Editor.GetContents();

	if ( Trim(objForm.b_subject.value) == "" )
	{
		alert("제목을 입력해주세요.");
		objForm.b_subject.focus();
		return;
	}

	if ( Trim(Editor.GetContents()) == "" || Editor.GetContents() == "<P>&nbsp;</P>" )
	{
		alert("내용을 입력해주세요.");
		Editor.objRichEditor.focus();
		return;
	}

	var objFiles = document.getElementById("FileList");

	for ( var i = 0; i < objFiles.length; ++i)
	{
		szFileinfo = objFiles[i].value.split( "@#$%" );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_path[]");
		objTemp.setAttribute("value", szFileinfo[2]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_name[]");
		objTemp.setAttribute("value", szFileinfo[0]);
		objForm.appendChild( objTemp );

		objTemp = document.createElement("input");
		objTemp.setAttribute("type", "hidden");
		objTemp.setAttribute("name", "b_file_size[]");
		objTemp.setAttribute("value", szFileinfo[1]);
		objForm.appendChild( objTemp );
	}

	objForm.submit();


}

function RemoveImageTag( szFilename )
{
	var i = 0;
	var objAnchor = Editor.objRichEditor.CurrentDocument.getElementsByTagName("a")
	var nCount = objAnchor.length;
	var aDeleteList = new Array(objAnchor.length);
	var iSize = 0;

	var temp;

	for ( var i=0; i < nCount; ++i )
	{
		if ( objAnchor[i].href.indexOf( szFilename ) != -1 )
		{
			aDeleteList[iSize] = objAnchor[i];
			iSize++;
		}
	}

	for ( var i=0; i < iSize; ++i )
	{
		aDeleteList[i].parentNode.removeNode( true );
	}
}


function Aprrove2()
{
	var objTemp;
	var szFileinfo;
	var objForm = document.writeForm;

	objForm.b_content.value = Editor.GetContents();

	if ( Trim(objForm.b_subject.value) == "" )
	{
		alert("제목을 입력해주세요.");
		objForm.b_subject.focus();
		return;
	}

	if( objForm.b_notice_yn.checked == false )
	{
		if( objForm.thumok.value == 0 )
		{
			var fso = objForm.b_thumnail.value;
			var pos = fso.lastIndexOf(".");
			var extc = fso.substring(pos+1).toLowerCase();
			if (fso.length == 0 )
			{
				alert("썸네일을 등록해 주세요.");
				objForm.b_thumnail.focus();
				return;
			}
			if (extc!="jpg" && extc!="gif" && extc!="bmp")
			{
				alert("확장자 jpg,gif,bmp 만 등록가능합니다.");
				objForm.b_thumnail.focus();
				return;
			}
		}

		if ( Trim(objForm.b_thum_subject.value) == "" )
		{
			alert("썸네일제목을 입력해주세요.");
			objForm.b_thum_subject.focus();
			return;
		}
	}

	if ( Trim(Editor.GetContents()) == "" || Editor.GetContents() == "<P>&nbsp;</P>" )
	{
		alert("내용을 입력해주세요.");
		Editor.objRichEditor.focus();
		return;
	}

	if( objForm.b_notice_yn.checked == false )
	{
		var objFiles = document.getElementById("FileList");

		if (  objFiles.length == 0)
		{
			if ( objForm.isGallery != undefined )
			{
				alert("갤러리는 이미지 파일을 한개 이상 올리셔야 합니다.");
				return;
			}
		}

		for ( var i = 0; i < objFiles.length; ++i)
		{
			szFileinfo = objFiles[i].value.split( "@#$%" );

			objTemp = document.createElement("input");
			objTemp.setAttribute("type", "hidden");
			objTemp.setAttribute("name", "b_file_path[]");
			objTemp.setAttribute("value", szFileinfo[2]);
			objForm.appendChild( objTemp );

			objTemp = document.createElement("input");
			objTemp.setAttribute("type", "hidden");
			objTemp.setAttribute("name", "b_file_name[]");
			objTemp.setAttribute("value", szFileinfo[0]);
			objForm.appendChild( objTemp );

			objTemp = document.createElement("input");
			objTemp.setAttribute("type", "hidden");
			objTemp.setAttribute("name", "b_file_size[]");
			objTemp.setAttribute("value", szFileinfo[1]);
			objForm.appendChild( objTemp );
		}
	}

	objForm.submit();
}

function LTrim(value)
{
	var LeftTrimValue = "";
	var i=0;

	if( value == "" )
		return "";

	strLen = value.length;
	while(i<strLen)
	{
		if(value.charAt(i) != " ") break;
		i++;
	}

	for(s=i;s<strLen;s++)
		LeftTrimValue = LeftTrimValue + value.charAt(s);

	return LeftTrimValue;
}

function RTrim(value)
{
	var RightTrimValue = "";

	if( value == "" )
		return "";

	strLen = value.length;
	--strLen;
	while( 0 <= strLen)
	{
		if(value.charAt(strLen) != " ") break;
		--strLen;
	}

	for(s=0;s<=strLen;s++)
		RightTrimValue = RightTrimValue + value.charAt(s);

	return RightTrimValue;
}

function Trim(value)
{
	return RTrim(LTrim(value));
}