	/**
 	* @projectDescription QBoard JavaScript Library
 	* @copyright NHN corp. <http://www.nhncorp.com>
 	* @author AjaxUI Team <TarauS>
 	*/

	/** 전역 변수 선언 */
	var oCategory0, oCategory1, oCategory2, oCategory3;
	var bAjaxRequesting = false;
	var oEditor;
	var aAttachedFileList = new Array();
	var oImageUploader, oFileUploader, oAttachArea;
	var nAttachIndex = 0, nFileUploadRequestCount = 0;
	var oClipboardCopyModule, oControlLayer;
	var bImageLoadCheck = false;
	var oTimer;
	var oControlLayer;
	var sTemporaryDocumentType, nTemporaryDocumentID;
	var sDeleteAnswerId;
	var oAgent = $Agent();

	/***********************************************************************************************************************
	* 글 목록 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 글 목록 페이지 초기화 함수
	 */
	function initializeListScript(){
		setDocumentDomain();

	        //검색 체크박스
		new Ku.Radiobox('searchBy', {
			skinFormat : sImageUrl+'/img_check_%s.gif'
		});

		oControlLayer = new Ju.controlLayer({'bAutoAdjusting' : true});
		checkParentIFrame();
		truncateListTitles();
		$('elCategoryList').style.width = $('qboard').offsetWidth+"px";
	}

	function previewLayer(sLayerID){
		if(!oAgent.IE){
			$(sLayerID).style.width = (($(sLayerID).parentNode.offsetWidth * 0.95) - 20) + "px"; //1029 수정
		}
		Element.show(sLayerID);
	}

	function closeLayer(sLayerID){
		Element.hide(sLayerID)
	}

	/**
	 * 페이지 이동
	 * @param {String} sUrl
	 */
	function goPage(sUrl) {
		document.location.href = sUrl;
		return false;
	}

	function goListPage(nPage) {
		document.location.href = sListPageUrlTemplate.replace("_page_", nPage);
	}

	function truncateListTitles() {
	    var maxWidth = aQuestionIdList.length ? $('elTitleHeader').offsetWidth - $('elCategoryTD_'+aQuestionIdList[0]).offsetWidth : $('elTitleHeader');

	    for(var i=0; i < aQuestionIdList.length; i++){
	        truncateTitle(aQuestionIdList[i], aQuestionTitleList[i], maxWidth);
	    }
	}

	function truncateTitle(sId, title, maxWidth) {
	   var oTitleLine = $("elTitleLine_" + sId);
	   var oTitle = $("elTitle_" + sId);
	   var maxHeight = oTitleLine.offsetHeight * 1.2;
	   var truncate = 10;

	   while(true) {
	       truncate += 5;
	       if(truncate > title.length) {
	           truncate = title.length;
	           oTitle.innerHTML = escapeHtml(title);
	       } else {
	           oTitle.innerHTML = escapeHtml(title.substr(0, truncate)) + " ..";
	       }

	       if(oTitleLine.offsetHeight > maxHeight || oTitleLine.offsetWidth > maxWidth) {
	           oTitle.innerHTML = escapeHtml(title.substr(0, truncate - 5)) + " ..";
	           break;
	       }

	       if(truncate == title.length) {
	           break;
	       }
	   }
    }

    function escapeHtml(str) {
    	return str.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
    }

	/**
	 * 검색 처리
	 */
	function goSearchList() {
		var oSearchBy = document.getElementsByName('searchBy');
		var oQuery = $('query');
		var sQuery = oQuery.value.replace(/^\s+/,'').replace(/\s+$/,'');
		if(sQuery == "") {
			alert(oMessages[oSearchBy[0].checked ? 'enterContentSearchKeyword' : 'enterWriterSearchKeyword']);
			oQuery.focus();
			return false;
		}else{
			var sSearchBy = oSearchBy[0].checked ? 'contents' : 'writer';
			document.location.href = sSearchUrlTemplate.replace("_searchBy_", sSearchBy).replace("_query_", encodeURIComponent(sQuery));
		}
	}

	function toggleMoreContent() {
		var preview = $('elQuestionPreview');
		var content = $('elQuestionContent');
		var button = $('elQuestionToggleButton');
		if(content.style.display == 'none') {
			preview.style.display = 'none';
			content.style.display = 'inline';
			button.innerHTML = oMessages['contentToggleButtonClose'];
		} else {
			preview.style.display = 'inline';
			content.style.display = 'none';
			button.innerHTML = oMessages['contentToggleButtonMore'];
		}
		checkParentIFrame();
	}

	/**
	 * 게시물 보기 방법 변경
	 * @param {String} sType
	 */
	function gotoListByType(sType) {
		if(bPreview) return false;
		var nDocumentPerPage;

		if(sType == 'text') nDocumentPerPage = 15;
		else if(sType == 'thumbnail') nDocumentPerPage = 15;
		else if(sType == 'album') nDocumentPerPage = nDocumentPerPageAlbum;
		else if(sType == 'webzine') nDocumentPerPage = 5;

		document.location.href = sDocumentListTypeUrl + "&n2_listType=" + sType + "&n2_cntPerPage=" + nDocumentPerPage;
	}

	/**
	 * 업데이트 알림 레이어를 보여줌
	 * @param {Object} oBaseElement
	 * @param {Boolean} bShow
	 */
	function showUpdateNoticeLayer(oBaseElement, bShow){
	    if(bShow == null) {
	       bShow = $('elUpdateNoticeLayer').style.display == 'none';
	    }

		if(bShow) {
		    if(nUpdateNoticePage == -1){
                updateUpdateNoticeLayer(1);
            }
		    showMessageLayer('elUpdateNoticeLayer', oBaseElement, null, 5, 8);
		} else {
		    hideMessageLayer('elUpdateNoticeLayer');
		}
	}

	/**
	 * 업데이트 알림 페이지 이동
	 * @param {Number} nPage
	 */
	function updateUpdateNoticeLayer(nPage){
		if(bAjaxRequesting == false){
			bAjaxRequesting = true;
			new Ajax(sUpdateNoticeUrlTemplate.replace('_page_', nPage), {
				onLoad : function(oRequest) {
					if(checkAjaxError(oRequest)){
						if(oRequest.responseText){
							$('elUpdateNoticeLayer').innerHTML = oRequest.responseText;
							nUpdateNoticePage = nPage;
						}
					}
					bAjaxRequesting = false;
				}
			});
		}else{
			alert(oMessages['ajaxRequesting']);
			return false;
		}
	}


	/***********************************************************************************************************************
	* 글 읽기 페이지 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 글 읽기 페이지 초기화 함수
	 */

	function initializeReadScript(){
		setDocumentDomain();
		resizeAttachedImage(true);
		checkParentIFrame();
		oControlLayer = new Ju.controlLayer({'bAutoAdjusting' : true});
	}

	function showDeleteAnswerLayer(oBaseElement, sAnswerId) {
		sDeleteAnswerId = sAnswerId;
		showMessageLayer('elMessageLayer_ConfirmAnswerDelete', oBaseElement, null, null, 8);
	}

	function deleteAnswer() {
		if(sDeleteAnswerId) {
			var url = sDeleteAnswerUrlTemplate.replace('_answerId_', sDeleteAnswerId);
			document.location = url;
		}
	}

	function checkLoginForCommentInput(id) {
		if(sLoginUserId) {
			var textArea = $('elCommentContent_' + id);
			if(textArea.value == oMessages['loginRequired'])
				textArea.value = '';
		} else {
			popupLogin();
		}
	}

	/**
	 * 게시물 읽기 시에 덧글 페이지 이동시 덧글 정보 설정 함수
	 * @param {Number} nPage
	 */
	function updateCommentPage(sQuestionYn, nDocumentID, nCommentPage){
		if(bAjaxRequesting == false){
			bAjaxRequesting = true;
			new Ajax(sCommentPageUrlTemplate.replace('_questionYn_', sQuestionYn).replace('_docId_',nDocumentID).replace('_commentPage_', nCommentPage), {
				onLoad : function(oRequest) {
					if(checkAjaxError(oRequest)){
						if(oRequest.responseText){
							$('elCommentContainer_'+nDocumentID).innerHTML = oRequest.responseText;
							setAutoExpand(nDocumentID);
							checkParentIFrame();
						}
					}
					bAjaxRequesting = false;
				}
			});
		}else{
			alert(oMessages['ajaxRequesting']);
			return false;
		}
	}

	/**
	 * 덧글 등록 처리 및 업데이트 함수
	 * @param {Object} elForm
	 * @param {Number} nType
	 */
	function submitComment(sQuestionYn, nDocumentID, nCommentPage){
 		if(sLoginUserId){
			if(sWriteCommentDisallowReason){ alert(sWriteCommentDisallowReason); return false; }
			var oContent = $('elCommentContent_'+nDocumentID);
			if(oContent.value && oContent.value.replace(/\s*/,'').length >= 1){
				oContent.value = oContent.value.replace(/^\s+/, '').replace(/^\s+$/mg, '\n').replace(/\n\n+/g, '\n\n');

				if(!checkObjectValueMaxLengthInByte(oContent, 4000, oMessages["commentOverflow"])) return false;
				if(!checkForbiddenWords(oContent.value, aCommentForbiddenWords)) return false;

				if(bAjaxRequesting == false){
					bAjaxRequesting = true;
					new Ajax(sWriteCommentUrlTemplate.replace('_questionYn_', sQuestionYn).replace('_docId_', nDocumentID).replace('_commentPage_', nCommentPage), {
						method : 'post',
						params : {
							'commentValue'   : oContent.value
						},
						onLoad : function(oRequest) {
							if(checkAjaxError(oRequest)){
								if(oRequest.responseText){
									$('elCommentTitle_'+nDocumentID).innerHTML = oMessages['commentTitle'];
									$('elCommentCount_'+nDocumentID).innerHTML++;
									$('elCommentContainer_'+nDocumentID).innerHTML = oRequest.responseText;
									setAutoExpand(nDocumentID);
									checkParentIFrame();
								}
							}
							bAjaxRequesting = false;
						}
					});
				}else{
					alert(oMessages['ajaxRequesting']);
					return false;
				}
			}else{
				alert(oMessages['inputCommentContent']);
				oContent.focus();
				return false;
			}
		}else{
			popupLogin();
		}
	}

	/**
	 * 덧글 삭제 요청 및 결과 업데이트 처리
	 * @param {Number} nCommentID
	 */
	function deleteComment(sQuestionYn, nDocumentID, nCommentID, nCommentPage){
		if(bAjaxRequesting == false){
			bAjaxRequesting = true;
			new Ajax(sDeleteCommentUrlTemplate.replace('_questionYn_', sQuestionYn).replace('_docId_', nDocumentID).replace('_commentId_', nCommentID).replace('_commentPage_', nCommentPage), {
				onLoad : function(oRequest) {
					if(checkAjaxError(oRequest)){
						if(oRequest.responseText){
							$('elCommentContainer_'+nDocumentID).innerHTML = oRequest.responseText;
							setAutoExpand(nDocumentID);
							$('elCommentTitle_'+nDocumentID).innerHTML = oMessages['commentTitle'];
							$('elCommentCount_'+nDocumentID).innerHTML--;
							checkParentIFrame();
						}
					}
					bAjaxRequesting = false;
				}
			});
		}else{
			alert(oMessages['ajaxRequesting']);
			return false;
		}
	}

	/**
	 * 아이디 공개/비공개 설정 레이어를 띄움
	 * @param {Object} oBaseElement
	 * @param {String} sDocumentType
	 * @param {Number} nDocumentID
	 */
	function showChangeWriterIDLayer(oBaseElement, sDocumentType, nDocumentID){
		sTemporaryDocumentType = sDocumentType;
		nTemporaryDocumentID = nDocumentID;
		if($('elChangeWriterID_'+nDocumentID).innerHTML == oMessages['hideId']){
			showMessageLayer('elMessageLayer_PrivateID', oBaseElement, null, null, 8);
		}else{
			showMessageLayer('elMessageLayer_PublicID', oBaseElement, null, null, 8)
		}
	}

	/**
	 * 아이디를 비공개로 변경하거나 공개로 변경
	 * @param {String} sDocumentType
	 * @param {Number} nDocumentID
	 * @param {Boolean} bType
	 */
	function changeWriterID(){
		var bType = $('elChangeWriterID_'+nTemporaryDocumentID).innerHTML == oMessages['hideId'] ? 0 : 1;
		var sActionUrl = (sTemporaryDocumentType == "question" ? sShowQuestionWriterIdUrlTemplate : sShowAnswerWriterIdUrlTemplate).replace('_answerId_', nTemporaryDocumentID).replace('_writerOpenYn_', bType);

		if(bAjaxRequesting == false){
			bAjaxRequesting = true;
			new Ajax(sActionUrl, {
				onLoad : function(oRequest) {
					if(checkAjaxError(oRequest)){
						if(oRequest.responseText){
							if(bType){
								hideMessageLayer('elMessageLayer_PublicID');
								$('elChangeWriterID_'+nTemporaryDocumentID).innerHTML = oMessages['hideId'];
								$('elWriterID_'+nTemporaryDocumentID).innerHTML = sMyWriterText;
							}else{
								hideMessageLayer('elMessageLayer_PrivateID');
								$('elChangeWriterID_'+nTemporaryDocumentID).innerHTML = oMessages['showId'];
								$('elWriterID_'+nTemporaryDocumentID).innerHTML = oMessages['private'];
							}
						}
					}
					bAjaxRequesting = false;
				}
			});
		}else{
			alert(oMessages['ajaxRequesting']);
			return false;
		}
	}

	function hideQuestionWriterID(sQuestionId){
	        var sActionUrl = sShowQuestionWriterIdUrlTemplate.replace('_writerOpenYn_', 0);

	        if(bAjaxRequesting == false){
	            bAjaxRequesting = true;
	            new Ajax(sActionUrl, {
	                onLoad : function(oRequest) {
	                    if(checkAjaxError(oRequest)){
	                        if(oRequest.responseText){
	                            hideMessageLayer('elMessageLayer_DisallowQuestionDelete');
	                            $('elChangeWriterID_'+sQuestionId).innerHTML = oMessages['showId'];
	                            $('elWriterID_'+sQuestionId).innerHTML = oMessages['private'];
	                        }
	                    }
	                    bAjaxRequesting = false;
	                }
	            });
	        }else{
	            alert(oMessages['ajaxRequesting']);
	            return false;
	        }
	}

	/**
	 * 텍스트 입력 시 자동으로 늘어나도록 텍스트에어리어를 설정
	 * @param {Number} nDocumentID
	 */
	function setAutoExpand(nDocumentID){
		if(oAgent.Safari){
			$('elCommentContent_'+nDocumentID).style.width = ($('qboard').offsetWidth - 122)+"px";
			$('elCommentContent_'+nDocumentID).rows = 6;

		}else{
			if($('elCommentContent_'+nDocumentID) != null && $('elCommentContent_'+nDocumentID).getAttribute('AutoExpand') == "false"){
				new Ku.AutoExpand("elCommentContent_"+nDocumentID, {maxRows : 25, stopAutoExpandAt: 10, width : ($('qboard').offsetWidth - 122)+"px", gripImg : sImageUrl+'/btn_resize.gif', gripImg_y_spacing : 2, onRowChange : checkParentIFrame});
				$('elCommentContent_'+nDocumentID).AutoExpand = "true";
			}
		}
	}

	/**
	 * 덧글 목록을 보이거나 숨김 (덧글이 있을 경우 Ajax로 요청)
	 * @param {String} sDocumentType
	 * @param {Number} nDocumentID
	 */
	function toggleCommentList(sQuestionYn, nDocumentID){
		if($('elCommentContent_'+nDocumentID) != null){
			Element.toggle($('elCommentContainer_'+nDocumentID));
			checkParentIFrame();
			setAutoExpand(nDocumentID);
		}else{
			if(bAjaxRequesting == false){
				bAjaxRequesting = true;
				new Ajax(sCommentPageUrlTemplate.replace('_questionYn_', sQuestionYn).replace('_docId_',nDocumentID).replace('_commentPage_', '1'), {
					onLoad : function(oRequest) {
						if(checkAjaxError(oRequest)){
							if(oRequest.responseText){
								$('elCommentContainer_'+nDocumentID).innerHTML = oRequest.responseText;
								Element.toggle($('elCommentContainer_'+nDocumentID));
								setAutoExpand(nDocumentID);
								checkParentIFrame();
							}
						}
						bAjaxRequesting = false;
					}
				});
			}else{
				alert(oMessages['ajaxRequesting']);
				return false;
			}
		}


		if(oAgent.IE55) {
			var doc = document.body;
			doc.style.zoom = 1;
			setTimeout(function() { doc.style.zoom = 'normal'; }, 0);
		}
	}

	/**
	 * 기타 답변 목록의 페이지를 변경 처리
	 * @param {String} sAnswerSortType
	 * @param {Number} nAnswerPage
	 * @param {Boolean} bSelectAnswer
	 */
	function updateEtcAnswerList(sAnswerSortType, nAnswerPage, bSelectAnswer){
		if(bAjaxRequesting == false){
			bAjaxRequesting = true;
			new Ajax(sEtcAnswerListUrlTemplate.replace('_answerSortType_', sAnswerSortType).replace('_answerPage_', nAnswerPage).replace('_canSelectAnswer_', bSelectAnswer), {
				onLoad : function(oRequest) {
					if(checkAjaxError(oRequest)){
						if(oRequest.responseText){
							$('etcAnswerList').innerHTML = oRequest.responseText;
							checkParentIFrame();
						}
					}
					bAjaxRequesting = false;
				}
			});
		}else{
			alert(oMessages['ajaxRequesting']);
			return false;
		}
	}

	/**
	 * 답변 선택창을 열음
	 * @param {Number} nAnswerID
	 */
	function openChooseAnswerWindow(nAnswerID){
		var sUrl = sChooseAnswerPopupUrlTemplate.replace('_answerId_', nAnswerID);
		var nTop = (window.screen.availHeight - 487) / 2;
		var nLeft = (window.screen.availWidth - 277) / 2;

		window.open(sUrl, 'wndChooseAnswer', 'width=487, height=277, left=' + nLeft + ', top=' + nTop);
	}

	/**
	 *
	 * @param {String} sElementID
	 */
	function showRecommendLayer(sElementID){
		var oPosition = oControlLayer.getRealPosition($(sElementID))

		Element.toggle('elMessageLayer_ReadersChoice');
		$('elMessageLayer_ReadersChoice').style.top = (oPosition.top + parseInt($(sElementID).offsetHeight) +(oAgent.IE ? 10 : 30))+"px";
		$('elMessageLayer_ReadersChoice').style.left = (oPosition.left - $('elMessageLayer_ReadersChoice').offsetWidth + $(sElementID).offsetWidth - 59) + "px";
		setTimeout(function(){
			Element.toggle('elMessageLayer_ReadersChoice');
		}, 3000);
	}

	function showMsg(sMsg){
		alert(sMsg);
	}

	/**
	 * @param	 {String} fileName	swf 파일 경로
	 * @param	 {String} idName		id
	 * @param {Number} width		swf 너비
	 * @param	 {Number} height		swf 높이
	 * @param	 {Number} goodNum	good 포인트
	 * @param	 {Number} badNum	bad 포인트
	 * @param	 {Boolean} isActivity	유저가 버튼을 클릭할 수 있는지 없는지의 값
	 *						이미 good 이나 bad 버튼을 클릭한 유저라면 또 클릭할 수 없어야 한다고 하네요.
	 *						클릭할수 있는 조건이면 true, 이미 추천을 해서 클릭할 수 없는 조건이면 false
	 * @param	 {String} country		영문이면 "en", 중국이면 "cn"
	 * @param	 {Boolean} isMaximum	해당 영역의 Good 포인트 값이 최대값인지의 여부
	 *						해당 버튼의 Good 포인트가 최대값이라면 true, 아니라면 false
	 * @param	 {Boolean} isLogin	로그인 상태라면 true, 아니면 false
	 * @param	 {String} goodURL	Good 눌렀을때의 링크 주소
	 * @param	 {String} badURL		Bad 눌렀을 때의 링크 주소
	 */

	function setAnswerFlash(fileName, idName, width, height, goodNum, badNum, isActivity, country, isMaximum, isLogin, goodURL, badURL){
		var data = "goodNum="+goodNum+"&badNum="+badNum+"&isActivity="+isActivity+"&country="+country+"&isMaximum="+isMaximum+"&swfID="+idName+"&isLogin="+isLogin+"&goodURL="+goodURL+"&badURL="+badURL;
		var _object_ = "";
		_object_ ='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+idName+'" align="middle">';
		_object_ += '<param name="allowScriptAccess" value="always" />';
		_object_ += '<param name="movie" value="'+fileName+'" />';
		_object_ += '<param name="quality" value="high" />';
		_object_ += '<param name="wmode" value="transparent" />';
		_object_ += '<param name="flashvars" value='+data+' />';
		_object_ += '<embed src="'+fileName+'" wmode="transparent" flashvars='+data+' quality="high" width="'+width+'" height="'+height+'" name="'+idName+'" id="'+idName+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		_object_ += '</object>';
		document.write(_object_);
	}

	/**
	 * setQuestionFlash
	 * @param {String} fileName		swf 파일 경로
	 * @param	 {String} idName		id
	 * @param	 {Number} width		swf 너비
	 * @param {Number} height		swf 높이
	 * @param	 {Number} answerNum	답변 갯수
	 * @param	 {Number} visitNum	방문자 수
	 * @param	 {Number} newIcon	New Icon 이 나타날지의 Boolean값 (New Icon 이 나타나면 true, 나타나지 않아도 되면 false)
	 */
	function setQuestionFlash(fileName, idName, width, height, answerNum, visitNum, newIcon){
		var data = "answerNum="+answerNum+"&visitNum="+visitNum+"&newIcon="+newIcon;
		var _object_ = "";
	       _object_ ='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+idName+'" align="middle">';
	       _object_ += '<param name="allowScriptAccess" value="always" />';
	       _object_ += '<param name="movie" value="'+fileName+'" />';
	       _object_ += '<param name="quality" value="high" />';
	       _object_ += '<param name="wmode" value="transparent" />';
	       _object_ += '<param name="flashvars" value='+data+' />';
	       _object_ += '<embed src="'+fileName+'" wmode="transparent" flashvars='+data+' quality="high" width="'+width+'" height="'+height+'" name="'+idName+'" id="'+idName+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	       _object_ += '</object>';
	       document.write(_object_);
	}


	/***********************************************************************************************************************
	* 글 쓰기 페이지 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 글 쓰기 페이지 초기화 함수
	 */

	function initializeWriteScript(){
		setDocumentDomain();
		var aCheckboxList = ['elHtmlMode','elCB_HideID', 'elCB_Best', 'elCB_Appropriate', 'elCB_RSS'];
		for(var i=0; i < aCheckboxList.length; i++) {
			if ($(aCheckboxList[i])) {
				new Ku.Checkbox(aCheckboxList[i], {
					skinFormat : sImageUrl+'/img_input_%s.gif',
					style : {'margin' : '6px 7px -3px 0', 'verticalAlign':'baseline'}
				});
			}
		}

		if($('elCategory_0') != null){
			for(var i=0; i<aCategoryList['0'].length; i++){
				addCategoryOption($("elCategory_0"), aCategoryList['0'][i]['id'], aCategoryList['0'][i]['name']);
			}

			oCategory0 = new Selectbox();
			oCategory0.transform("elCategory_0", { width : 'auto' });
		}
		if($('elCategory_1') != null){ oCategory1 = new Selectbox();oCategory0.transform("elCategory_1", { width : 'auto' });}
		if($('elCategory_2') != null){ oCategory2 = new Selectbox();oCategory0.transform("elCategory_2", { width : 'auto' });}
		if($('elCategory_3') != null){ oCategory3 = new Selectbox();oCategory0.transform("elCategory_3", { width : 'auto' });}
		try{
			setCategoryList();
		}catch(e){}

		initializeEditor();
		initializeAttachModule();
		checkParentIFrame();
	}

	/**
	 * 글로벌 에디터 초기화 함수
	 */
	function initializeEditor(){
		if(oAgent.Safari || oAgent.IE55){
			bUsePhotoUpload = false;
			bUseFileUpload = false;
			$('textbox').style.visibility = 'visible';
			$('textbox').style.width = '100%';
			$('textbox').style.height = '300';
			if($('textbox').value) $('textbox').value = $('textbox').value.replace(/<br>/gi, '\n');
			$('naver_common_editor').insertBefore($('textbox'), $('naver_common_editor').firstChild);
			$('toolbox').style.display = 'none';
			window.onbeforeunload = function(){
				return (Editor._('event.onexit.message'));
			}
		}else{
			$('toolbox').style.visibility = "visible"
			oEditor = new Editor('textbox',{
				toolbox    : 'toolbox',
				attarea    : true,
				resizable  : true,
				skin : 'edit_skin',
				minHeight  : 450,
//				defaultDoc : sStaticEditorUrl+'/html/default.html',
				defaultDoc : sStaticEditorUrl,
				sizeGrip   : 'size_grip',
				onResize : function(){
					checkParentIFrame();
				}
			});
			$('textbox').style.visibility = 'visible';

			if(sLanguage == "en"){
				fontNamePlugin.addDefaultFont('Courier New', 'Courier New');
				fontNamePlugin.addDefaultFont('Georgia', 'Georgia');
				fontNamePlugin.addDefaultFont('Trebuchet', 'Trebuchet');
			}else{
				fontNamePlugin.addDefaultFont('宋体', '宋体');
				fontNamePlugin.addDefaultFont('黑体', '黑体');
				fontNamePlugin.addDefaultFont('MS Song', 'MS Song');
			}
			fontNamePlugin.addDefaultFont('Arial', 'Arial');
			fontNamePlugin.addDefaultFont('Tahoma', 'Tahoma');
			fontNamePlugin.addDefaultFont('Times New Roman', 'Times New Roman');
			fontNamePlugin.addDefaultFont('Verdana', 'Verdana');

			emoticoninsertionPlugin.emoticonSet[0] = ('1_01.gif 1_02.gif 1_03.gif 1_04.gif 1_05.gif 1_06.gif 1_07.gif 1_08.gif 1_09.gif 1_10.gif '+'1_11.gif 1_12.gif 1_13.gif 1_14.gif 1_15.gif 1_16.gif 1_17.gif 1_18.gif 1_19.gif 1_20.gif '+'1_21.gif 1_22.gif 1_23.gif 1_24.gif 1_25.gif 1_26.gif 1_27.gif 1_28.gif 1_29.gif 1_30.gif '+'1_31.gif 1_32.gif 1_33.gif 1_34.gif 1_35.gif 1_36.gif 1_37.gif 1_38.gif 1_39.gif 1_40.gif '+	'1_41.gif 1_42.gif 1_43.gif 1_44.gif 1_45.gif 1_46.gif 1_47.gif 1_48.gif 1_49.gif 1_50.gif').split(' ');
			emoticoninsertionPlugin.emoticonSet[1] = ('2_01.gif 2_02.gif 2_03.gif 2_04.gif 2_05.gif 2_06.gif 2_07.gif 2_08.gif 2_09.gif 2_10.gif '+'2_11.gif 2_12.gif 2_13.gif 2_14.gif 2_15.gif 2_16.gif 2_17.gif 2_18.gif 2_19.gif 2_20.gif '+'2_21.gif 2_22.gif 2_23.gif 2_24.gif 2_25.gif 2_26.gif 2_27.gif 2_28.gif 2_29.gif 2_30.gif '+'2_31.gif 2_32.gif 2_33.gif 2_34.gif 2_35.gif 2_36.gif 2_37.gif 2_38.gif 2_39.gif 2_40.gif '+'2_41.gif 2_42.gif 2_43.gif 2_44.gif 2_45.gif 2_46.gif 2_47.gif 2_48.gif 2_49.gif 2_50.gif').split(' ');
			emoticoninsertionPlugin.emoticonSet[2] = ('3_01.gif 3_02.gif 3_03.gif 3_05.gif 3_06.gif 3_07.gif 3_08.gif 3_09.gif 3_10.gif '+'3_11.gif 3_12.gif 3_13.gif 3_14.gif 3_15.gif 3_16.gif 3_17.gif 3_18.gif 3_19.gif 3_20.gif '+'3_21.gif 3_22.gif 3_23.gif 3_24.gif 3_25.gif 3_26.gif 3_27.gif 3_28.gif 3_29.gif 3_30.gif '+'3_31.gif 3_32.gif 3_33.gif 3_34.gif 3_35.gif 3_36.gif 3_37.gif 3_38.gif 3_39.gif 3_40.gif '+'3_41.gif 3_42.gif 3_43.gif 3_44.gif 3_45.gif 3_46.gif 3_47.gif 3_48.gif').split(' ');
			emoticoninsertionPlugin.emoticonSet[3] = ('4_01.gif 4_02.gif 4_03.gif 4_04.gif 4_08.gif 4_09.gif 4_10.gif '+'4_11.gif 4_12.gif 4_13.gif 4_14.gif 4_15.gif 4_16.gif 4_17.gif 4_18.gif 4_19.gif 4_20.gif '+'4_21.gif 4_22.gif 4_23.gif 4_24.gif 4_25.gif 4_26.gif 4_27.gif 4_28.gif 4_29.gif 4_30.gif '+'4_31.gif 4_32.gif 4_33.gif 4_34.gif 4_35.gif 4_36.gif 4_37.gif 4_38.gif 4_39.gif '+'4_42.gif').split(' ');
			emoticoninsertionPlugin.emoticonSet[4] = ('5_01.gif 5_02.gif 5_03.gif 5_04.gif 5_05.gif 5_06.gif '+'5_17.gif '+'5_23.gif 5_26.gif '+''+'5_43.gif 5_44.gif 5_45.gif 5_46.gif 5_47.gif 5_48.gif 5_49.gif 5_50.gif').split(' ');
			emoticoninsertionPlugin.IMG_BASE_URL = sStaticDesignUrl+"/img/emoticon/";

			var oTagFilter = {
				_re : /<(applet|script|iframe|style|link|meta|body|base|plaintext|xmp|xml)\s*.*?>.*?<\/\1[^>]*>/ig,
				onSave : function(html) {
					return html.replace(this._re, '');
				}
			};
			oEditor.filter.register(oTagFilter);

			quoteFilter = {
				type01 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px;"><table cellspacing="0" cellpadding="0" width="100%"><tr><td style="width:2px;background:url('+sStaticEditorUrl+'/img/bg_quote01.gif) repeat;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote01.gif\',sizingMethod=\'scale\');_background:none"></td><td style="padding:1px 0 0 9px;color:#444444; line-height:1.2;">#string#</td></tr></table></blockquote>',
				type02 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px;"><table cellpadding="0" cellspacing="0" width="100%"><tr><td><div style="position:relative;_height:1px;padding:1px 12px 0 12px;color:#444444; line-height:1.4;background:url('+sStaticEditorUrl+'/img/bg_quote02.png) no-repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote02.png\',sizingMethod=\'crop\');">#string#<div style="position:absolute;width:9px;height:7px;background:url('+sStaticEditorUrl+'/img/bg_quote02_2.png) no-repeat;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote02_2.png\',sizingMethod=\'crop\');right:0;bottom:0;_background:none;"></div></div></td></tr></table></blockquote>',
				type03 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px;"><table cellspacing="0" cellpadding="0" width="100%"><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1"></td><td style="padding:11px 10px 10px 9px;color:#444444; line-height:1.4;">#string#</td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td></tr></table></blockquote>',
				type04 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px;"><table cellspacing="0" cellpadding="0" width="100%"><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1"></td><td style="padding:11px 10px 10px 9px; background:url(\''+sStaticEditorUrl+'/img/bg_quote_body_01.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote_body_01.png\',sizingMethod=\'scale\'); color:#444444; line-height:1.2;_background:none">#string#</td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" height="1"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="1" height="1"></td></tr></table></blockquote>',
				type05 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px;"><table cellspacing="0" cellpadding="0" width="100%"><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="2"></td><td style="padding:11px 10px 10px 9px;color:#444444; line-height:1.4;">#string#</td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote03.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote03.png\',sizingMethod=\'scale\');_background:none" width="2"></td></tr><tr><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td><td style="background:url(\''+sStaticEditorUrl+'/img/bg_quote04.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote04.png\',sizingMethod=\'scale\');_background:none" height="2"></td></tr></table></blockquote>',
				type07 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px; padding:11px 10px 10px 9px; border:1px dashed #B2B2B2; color:#B2B2B2; line-height:1.2;"><div style="color:#444444; line-height:1.4;">#string#</div></blockquote>',
				type08 : '<blockquote style="_width:100%;margin:14px 15px 20px 15px; border:1px dashed #B2B2B2;color:#B2B2B2;line-height:1.2;"><div style="_height:1px;padding:11px 10px 10px 9px;color:#444444;line-height:1.4;background:url(\''+sStaticEditorUrl+'/img/bg_quote_body_01.png\') transparent;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+sStaticEditorUrl+'/img/bg_quote_body_01.png\',sizingMethod=\'scale\');_background:none;">#string#</div></blockquote>',

				onLoad : function(sHTML) {
					return sHTML.replace(/<blockquote[^>]* class="?vview_quote([0-9]+)"?[^>]*>((?:\s|.)*?)<\/blockquote>/ig, function(m0,m1,m2){
						if (/<!--quote_txt-->((?:\s|.)*?)<!--\/quote_txt-->/ig.test(m2)) {
							return '<blockquote class="quote'+m1+'">'+RegExp.$1+'</blockquote>';
						} else {
							return '';
						}
					});
				},
				onSave : function(sHTML) {
					return sHTML.replace(/<blockquote[^>]* class="?quote([0-9]+)"?[^>]*>((?:\s|.)*?)<\/blockquote>/ig, function(m0,m1,m2){
						var str = '';

						if (quoteFilter['type'+m1]) {
							str = quoteFilter['type'+m1].replace('#string#', '<!--quote_txt-->'+m2+'<!--/quote_txt-->');

							return str.replace('<blockquote', '<blockquote class="vview_quote'+m1+'"');
						} else {
							return m0;
						}
					});
				}
			};
			oEditor.filter.register(quoteFilter);
		}
	}

	/**
	 * 파일 첨부 모듈 초기화 함수
	 */
	function initializeAttachModule(){
		if(bUsePhotoUpload || bUseFileUpload){
			if(!bUsePhotoUpload) $('elImageUploadButton').style.display = "none";

			if(bUseFileUpload){
				oFileUploader = new Ku.Upload('elFileUploadButton',{
					url  : sNormalUploadUrl,
					callback : sCallbackUrl,
					multiple : false,
					autosend : false,
					data : {'board_id' : sBoardId},
					onSelect : function(file) {
						if(file.	search(/(\%|\^|\&|\+|\'|\;|\#|\$)/) > 0){
							alert(oMessages['notAllowFileExtention']);
							oFileUploader.reset();
							return false;
						}else{
							oFileUploader.send();
							nFileUploadRequestCount = this.multiple?file.length:nFileUploadRequestCount + 1;
						}
					},
					onSuccess: function(file){
						file.file_type = 'normal';
						file.file_status = 'added';
						file.thumbnail_path = '';
						oAttachArea.addFile(file);
						nFileUploadRequestCount--;
					},
					onError : function(oError){
						alert(decodeURIComponent(oError.errstr));
						nFileUploadRequestCount = 0;
					}
				});
			}else{
				$('elFileUploadButton').style.display = "none";
			}

			oAttachArea = {
				_nAttachedIndex : -1,
				_currentSize : 0,
				_totalSize   : 1,
				_aAttachedFileList : [],

				init : function() {
				},
				setTotalSize : function(totalSize) {
					this._totalSize = totalSize;
					$('elTotalFileSize').innerHTML = this._totalSize/1024;

					this.paintGuage();
				},
				getFileSizeInformation : function(){
					return {'current':this._currentSize, 'total':this._totalSize}
				},
				getFileCount : function(){
					return this._aAttachedFileList.length;
				},
				paintGuage : function() {
					$('elCurrentFileSize').innerHTML = Math.round(this._currentSize/1024*10)/10;
					var nGuageWidth = Math.round(this._currentSize/this._totalSize*100);
					$('elFileSizeGuage').style.width = nGuageWidth>100?'100%':nGuageWidth+"%";
				},
				paintBox : function(){
					var bShowNormalArea = false, bShowThumbnailArea = false, nDeletedCount=0;
					for(var i=0; i<this._aAttachedFileList.length; i++){
						if(this._aAttachedFileList[i]['file_type'] == "normal" && this._aAttachedFileList[i]['file_status'] != "deleted") bShowNormalArea = true;
						else if(this._aAttachedFileList[i]['file_type'] == "image" && this._aAttachedFileList[i]['file_status'] != "deleted") bShowThumbnailArea = true;
						if(this._aAttachedFileList[i]['file_status'] == "deleted") nDeletedCount++;
					}

					if(bShowNormalArea == false && bShowThumbnailArea == true) $('elThumbnailFileListTemplate').style.borderTop = "";
					else $('elThumbnailFileListTemplate').style.borderTop = "solid 1px #DFDFDF";
					$('elNormalFileListTemplate').style.display = bShowNormalArea ? "" : "none";
					$('elThumbnailFileListTemplate').style.display = bShowThumbnailArea ? "" : "none";
					if(this._aAttachedFileList.length == 0 || this._aAttachedFileList.length == nDeletedCount){ $('elFileAttachedAreaTitle').style.display = 'none';$('elFileAttachedAreaList').style.display = 'none';}
					else{ $('elFileAttachedAreaTitle').style.display = '';$('elFileAttachedAreaList').style.display = '';}
					checkParentIFrame();
				},
				checkFileSize : function(){
					for(var i=0; i<this._aAttachedFileList.length; i++){
						if(this._aAttachedFileList[i].file_size > nLimitFileSize){
							alert('['+this._aAttachedFileList[i].file_name+'] '+oMessages[exceedIndividuallyFileSize].replace('_maxSize_', nLimitFileSize / 1024));
							return false;
						}
					}
					if(this._currentSize > this._totalSize){
						alert(oMessages['exceedFileSize']);
						return false;
					}
					return true;
				},
				checkContainImage : function(){
					for(var i=0; i<this._aAttachedFileList.length; i++){
						if(this._aAttachedFileList[i].file_type == "image" && this._aAttachedFileList[i]['file_status'] != "deleted") return true;
					}
					return false;
				},
				getImageFileList : function (){
					var aTmp = [];
					for(var i=0; i<this._aAttachedFileList.length; i++){
						if(this._aAttachedFileList[i].file_type == "image" && this._aAttachedFileList[i]['file_status'] != "deleted") aTmp.push(this._aAttachedFileList[i].file_directory+encodeURIComponent(this._aAttachedFileList[i].file_name))
					}
					return aTmp;
				},
				addFile : function(fileObj) {
					var oItem = {
						'index' : ++this._nAttachedIndex,
						'file_name' : decodeURIComponent(fileObj.file_name),
						'file_path' : decodeURIComponent(fileObj.file_path),
						'file_directory' : decodeURIComponent(fileObj.file_path).replace(decodeURIComponent(fileObj.file_name), ''),
						'file_size' : parseInt(fileObj.file_size),
						'file_type' : fileObj.file_type?fileObj.file_type:'',
						'file_status' : fileObj.file_status?fileObj.file_status:'',
						'thumbnail_path' : fileObj.thumbnail_path?decodeURIComponent(fileObj.thumbnail_path):''
					}

					if((oItem.file_size+this._currentSize) > this._totalSize){
						alert(oMessages['notAllowAttachFile']);
						return false;
					}

					var box = $((oItem.file_type == 'normal')?'elNormalFileListTemplate':'elThumbnailFileListTemplate');
					var tpl = box.getElementsByTagName('LI')[0].cloneNode(true);
					var div = $C('div');
					var cnt = box.getElementsByTagName('LI').length - 1;

					div.appendChild(tpl);
					tpl.style.display = '';
					if (cnt%2) tpl.className = '';

					// process template
					div.innerHTML = div.innerHTML.replace(/\$filename/g, "<a href='"+oItem.file_directory+fileObj.file_name+"' target='_blank'>"+oItem.file_name+"</a>");
					div.innerHTML = div.innerHTML.replace(/\$filesize/g, this.getFileSize(oItem.file_size));
					div.innerHTML = div.innerHTML.replace(/\$fileid/g, oItem.index);
					div.innerHTML = div.innerHTML.replace(/\$thumbnail/g, "src='"+oItem.thumbnail_path+"'");
					tpl = div.firstChild;

					// set fileid
					tpl.setAttribute('fileId', oItem.index);

					// add filesize
					this._currentSize += parseInt(oItem.file_size);
					this.paintGuage();

					this._aAttachedFileList.push(oItem);
					$('attachedFiles').value = this._aAttachedFileList.toJSON();
					box.appendChild(div.firstChild);
					this.paintBox();
					return true;
				},
				setFile : function(sAttachedInformation){
					if(sAttachedInformation){
						this._aAttachedFileList = eval(sAttachedInformation);

						if(this._aAttachedFileList != undefined){
							this._nAttachedIndex = this._aAttachedFileList.length - 1;
							for(var i=0; i<this._aAttachedFileList.length; i++){
								this.addFile(this._aAttachedFileList[i]);
							}
						}
					}
					this.paintBox();
				},
				deleteFile : function(fileId,boxId) {
					var box = $(boxId);
					var lis = box.getElementsByTagName('LI');
					var nKey = this.getIndexKey(fileId);

					var filenameEscape = function(str) {
						return str.replace(/([\.\(\)\[\]\+\-\=])/g,'\\'+'$1');
					}

					for(var i=1; i < lis.length; i++) {
						if (lis[i].getAttribute('fileId') == fileId) {
							box.removeChild(lis[i]);
							break;
						}
					}

					switch(this._aAttachedFileList[nKey]['file_type']){
					case "image":
						var sInsertedFilePath = filenameEscape(this._aAttachedFileList[nKey]['file_directory']+encodeURIComponent(this._aAttachedFileList[nKey]['file_name']));
						var oRemoveReg = new RegExp('<img[^>]+src="'+sInsertedFilePath+'"[^<>]+>','ig');
						oEditor.setContent(oEditor.getContent().replace(oRemoveReg,''));
						break;
					}

					if(this._aAttachedFileList[nKey]['file_status'] == "saved"){
						this._aAttachedFileList[nKey]['file_status'] = "deleted";
						this._currentSize -= this._aAttachedFileList[nKey]['file_size'];
					}else if(this._aAttachedFileList[nKey]['file_status'] == "added"){
						var aTemporary = [];
						for(var i=0; i<this._aAttachedFileList.length; i++){
							if(this._aAttachedFileList[i]['index'] == fileId) this._currentSize -= this._aAttachedFileList[i]['file_size'];
							else aTemporary.push(this._aAttachedFileList[i]);
						}
						this._aAttachedFileList = aTemporary;
					}

					var elList = $('elNormalFileListTemplate').getElementsByTagName('LI');
					for(var i=1; i<elList.length; i++){
						if((i + 1)%2) elList[i].className = '';
						else elList[i].className = elList[0].className;
					}

					$('attachedFiles').value = this._aAttachedFileList.toJSON();
					this.paintGuage();
					this.paintBox();
				},
				getFileSize: function(size) {
					var unit = ['B','KB','MB','GB'];
					var unit_idx = 0;
					while(size >= 1024){
						size = size / 1024;
						unit_idx++;
					}
					size = Math.round(size*10)/10;
					return size+' '+unit[unit_idx];
				},
				getIndexKey : function(nIndex){
					for(var i=0; i<this._aAttachedFileList.length; i++){
						if(this._aAttachedFileList[i]['index'] == nIndex){
							return i;
						}
					}
				}
			}

			oAttachArea.setTotalSize(nLimitTotalFileSize);
			if(aAttachedFiles.length){
				for(var i=0; i<aAttachedFiles.length; i++){
					oAttachArea.addFile(aAttachedFiles[i]);
				}
			}
		}else{
			$('elFileUploadButtonAreaTitle').style.display = "none";
			$('elFileUploadButtonAreaContent').style.display = "none";
			$('elFileAttachedAreaTitle').style.display = "none";
			$('elFileAttachedAreaList').style.display = "none";
		}
	}

	/**
	 * 현재 HTML 모드인지 체크하여 리턴
	 */
	function checkHtmlMode(){
		if($('elHtmlMode').checked){
			return true;
		}else{
			return false;
		}
	}

	/**
	 * aForbiddenWordsList의 단어들이 sContent 안에 들어있는지 검사하여 리턴
	 * @param {String} sContent
	 * @param {Array} aForbiddenWordsList
	 */
	function checkForbiddenWords(sContent, aForbiddenWordsList){
		if(aForbiddenWordsList.length == 0) return true;

		var sForbiddenWords = aForbiddenWordsList.join(':::');
		sForbiddenWords = sForbiddenWords.replace(/([\(\)\[\]\+\-\|\*\?\.\\])/g,'\\'+'$1').replace(/:::/g, '|');
		var aTmpList = sContent.replace(/(<[^>]+>|\s)*/gi,'').match(new RegExp('('+sForbiddenWords+').*?', 'gi'));
		var aCheckedList = [];
		if(aTmpList) for(var i=0; i<aTmpList.length; i++) if(!aCheckedList.has(aTmpList[i])) aCheckedList.push(aTmpList[i]);
		if(aCheckedList.length){
			alert(oMessages['deleteForbiddenWords'].replace('_forbiddenWords_',aCheckedList.join(', ')));
			return false;
		}else{
			return true;
		}
	}

	/**
	 * 게시물 등록 요청 및 폼 검사
	 * @param {String} sType
	 */
	function submitDocument(sType){
		if(sWriteDocumentDisallowReason){
			alert(sWriteDocumentDisallowReason);
			return false;
		}
		if(nFileUploadRequestCount){
			alert(oMessages['uploading']);
			return false;
		}
		//if(bUsePhotoUpload || bUseFileUpload) if(!oAttachArea.checkFileSize()) return false;

		var oForm = $("elWriteDocumentForm");
		for(var i=0; i<4; i++){
			if($('elCategory_'+i) && $('category'+i)){
				if(!$('elCategory_'+i).value){ alert(oMessages['notSelectCategory']); return false;}
				oForm['category'+i].value = $('elCategory_'+i).value;
			} else break;
		}

		oForm.writerOpenYn.value = ($("elCB_HideID").checked ? "0" : "1");
		if($("elCB_Best")) oForm.best.value = ($("elCB_Best").checked ? "1" : "0");
		//if($("elCB_Appropriate")) oForm..value = ($("elCB_Appropriate").checked ? "1" : "0");
		if($("elCB_RSS")) oForm.rssOpenYn.value = ($("elCB_RSS").checked ? "1" : "0");


		var oTitle = $("titleInput");
		if(oTitle.parentNode.parentNode.style.display != 'none') {
			if(oTitle.value.replace(/\s*/,'') == "" || oTitle.value == oMessages['defaultTitle']){
				alert(oMessages['enterTitle']);
				oTitle.focus();
				return false;
			} else if(!checkObjectValueMaxLengthInByte(oTitle, 300, oMessages['titleOverflow'])){
				return false;
			} else {
				oForm.title.value = oTitle.value;
			}
		}
		if(!checkForbiddenWords(oTitle.value, aDocumentForbiddenWords)) return false;

		var sContent = (oAgent.Safari || oAgent.IE55) ? $('textbox').value.replace(/\n/g,'<br>') : oEditor.getContent(true);
		if(sContent.replace(/<(?!table|img|div)[^>]*>|&nbsp;|\s*/gi, '')){
			oForm.content.value = sContent;
		}else{
			alert(oMessages['enterContent']);
			return false;
		}
		if(!checkMaxLengthInByte(sContent, (1024 * 1024), oMessages['contentOverflow'])) return false;
		if(!checkForbiddenWords(sContent, aDocumentForbiddenWords)) return false;


		if(sType == 'preview'){	//미리보기
			window.open("", "wndPreviewWindow", "status=0, toolbar=0, titlebar=0, location=0, scrollbars=1");
			oForm.action = sPreviewUrl;
			oForm.target = "wndPreviewWindow";
			oForm.submit();
			return false;
		}else{	 //일반게시판
			oForm.action = sSubmitUrl;
			oForm.target = "_self";
		}

		if(oAgent.Safari || oAgent.IE55){
			window.onbeforeunload = null;
		}else{
			oEditor.setUnloadWarn();
		}
		oForm.submit();
		$('elSubmitAnchor').onclick = function(){alert(oMessages['registering']);return false;};
	}

	/**
	 * 이미지 업로드 창을 열음
	 */
	function openImageUploadWindow(){
		if(checkHtmlMode()){
			alert(oMessages['notAllowAttachImageOnHTMLMode']);
			return false;
		}else{
			try{
				window.open(sImagePopupUrl, 'wndImageUpload', 'width=375, height=330, scrollbars=0, status=0, resizable=0, toolbar=0, titlebar=0, location=0');
			}catch(e){ }
		}
	}


	/***********************************************************************************************************************
	* 글 인쇄 페이지 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 글 인쇄 페이지 스크립트 초기화
	 */
	function initializePrintScript(){
		nHeight = $('qboard').offsetHeight > 730 ? 730 : $('qboard').offsetHeight + 20;
		setWindowSize($('n2_content').offsetWidth+($Agent().IE?61:40), nHeight);
		resizeAttachedImage();
 	}


	/***********************************************************************************************************************
	* 글 신고 페이지 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 글 신고 페이지 스크립트 초기화
	 */
	function initializeReportScript(){
		setDocumentDomain();
		setWindowSize($('qboard').offsetWidth, $('qboard').offsetHeight);
	}

	function checkChooseSubmit(oTarget){
		if(getByte($('questionerComment').value) > 300){
			alert(oMessages[''].replace(/{maxByte/, 300));
			$('questionerComment').focus();
			return false;
		}

		return true;
	}

	/***********************************************************************************************************************
	* 이미지 업로드 페이지 관련 스크립트
	***********************************************************************************************************************/

	/**
	 * 이미지 업로드 페이지 스크립트 초기화
	 */
	function initializeImageUploadScript(){
		setDocumentDomain();
		setWindowSize(380, 320);

		oImageUploader = new Ku.Upload('elImageUploadButton',{
			url  : opener.sImageUploadUrl,
			callback : opener.sCallbackUrl,
			multiple : false,
			autosend : false,
			data : {'board_id' : opener.sBoardId},
			onSelect : function(file) {
				var info = getBrowserInfo();
				// 2008.09.24 modified by duwonyi - Start
				/* FF3 patch by yiduwon*/
				if (info.firefox && info.version >= 3) {
					var m = file.match(/^.+\.([a-z0-9]+)$/ig);
					var sFileType = String(RegExp.$1).toLowerCase();
				} else {
					var m = file.match(/(\\|\/)([^\\\/]+)\.([a-z0-9]+)$/ig);
					var sFileType = String(RegExp.$3).toLowerCase();
				}
				if(['jpg','gif','png'].has(sFileType.toLowerCase())) {
					$('elImageUploadFile').value = file;
				}else{
					alert(oMessages['allowImageExtention']);
					return false;
				}
				// 2008.09.24 modified by duwonyi - End
			},
			onSuccess: function(file){
				if(opener.checkHtmlMode()){
					alert(oMessages['notAllowAttachImageOnHTMLMode']);
					return false;
				}
				file.file_type = 'image';
				file.file_status = 'added';

				var elAlign = document.getElementsByName('elAttachType');
				for(i=0; i<elAlign.length; i++){
					if(elAlign[i].checked) var sAlign = elAlign[i].value;
				}
				var bResult = opener.oAttachArea.addFile(file);

				if(bResult) insertImageToEditor(file.file_path, file.file_name, sAlign, file.width, file.height);
				self.close();
			},
			onError : function(oError){
				alert(decodeURIComponent(oError.errstr));
			}
		});
	}

	/**
	 * 이미지 첨부 방법을 변경
	 * @param {String} sType
	 */
	function changeAttachImageTab(sType){
		if(sType == "Upload"){
			$('elAttachImage_Upload').style.display = 'block';
			$('elAttachImage_Link').style.display = 'none';
			$('elTabUpload').className = 'on';
			$('elTabLink').className = '';
			setWindowSize(380, 320);
		}else{
			$('elAttachImage_Upload').style.display = 'none';
			$('elAttachImage_Link').style.display = 'block';
			$('elTabUpload').className = '';
			$('elTabLink').className = 'on';
			if($('elPreviewImageURL').value != 'http://' && $('elPreviewImageURL').value != '') $('elPreviewImageContainer').style.display = "none";
			setWindowSize(380, 225);
		}
	}

	/**
	 * 미리보기 이미지 토글
	 */
	function togglePreviewImageLayer(){
		if($('elPreviewImageContainer').style.display == "none"){
			if($('elPreviewImageURL').value != 'http://' && $('elPreviewImageURL').value != ''){
				if(bImageLoadCheck) return false;
				var oImagePreviewTemp = new Image();
				oImagePreviewTemp.onload = function() {
					bImageLoadCheck = true;
					$('elPreviewImageURL').image_width = this.width;
					$('elPreviewImageURL').image_height = this.height;
					oResult = resizeImage(this, 285, 200);
					$('elPreviewImageLayer').innerHTML = '<img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'">';
					$('elPreviewImageContainer').style.display = "";

					setWindowSize(380, document.body.scrollHeight + 15);
					bImageLoadCheck = false;
				}
				oImagePreviewTemp.onerror = function(){
					alert(oMessages['confirmImageURL']);
					bImageLoadCheck = false;
				}
				oImagePreviewTemp.src = $('elPreviewImageURL').value;
			}else{
				alert(oMessages['inputImageURL']);
				$('elPreviewImageURL').focus();
				return false;
			}
		}else{
			$('elPreviewImageContainer').style.display = "none";
			setWindowSize(380, $('qboard').offsetHeight);
		}
	}

	/**
	 * 에디터에 이미지 삽입
	 * @param {String} sUrl
	 * @param {String} sFilename
	 * @param {String} sAlign
	 * @param {Number} nWidth
	 * @param {Number} nHeight
	 */
	function insertImageToEditor(sPath, sFilename, sAlign, nWidth, nHeight){
		var sUrl = sPath ? (decodeURIComponent(sPath).replace(decodeURIComponent(sFilename), '')+encodeURIComponent(decodeURIComponent(sFilename))) : sFilename;
		var htmlSrc = '';

		var nMaxWidth = parseInt(opener.$('qboard').style.width) - 44;
		if(nWidth > nMaxWidth){
			nHeight = parseInt(nHeight * nMaxWidth / nWidth);
			nWidth = nMaxWidth;
		}

		var imgStr  = '<br><IMG height="'+nHeight+'" src="'+sUrl+'" width="'+nWidth+'" height="'+nHeight+'"><br clear="all">';

		switch (sAlign) {
			case 'top':
				htmlSrc = opener.oEditor.getContent();
				opener.oEditor.setContent(imgStr + htmlSrc);
				break;
			case 'bottom':
				htmlSrc = opener.oEditor.getContent();
				opener.oEditor.setContent(htmlSrc + imgStr);
				break;
			case 'left':
			case 'right':
				imgStr = imgStr.substr(0, imgStr.length - 17);
				opener.oEditor.execCommand('inserthtml', null, imgStr + ' style="display:block;margin:0px" align="' + sAlign + '"><br clear="all">');
				break;
			case 'now':
				opener.oEditor.execCommand('insertimage', null, sUrl);
				break;
		}
	}

	/**
	 * 업로드된 이미지 및 웹상의 이미지를 에디터 및 첨부 파일 목록에 추가
	 */
	function attachImage(){
		if($('elImageUploadFile').value){
			if($('elImageUploadFile').value.search(/(\%|\^|\&|\+|\'|\;|\#|\$)/) > 0){
				alert(oMessages['notAllowFileExtention']);
				return false;
			}
			oImageUploader.send();
			$('elImageUploadFile').value = '';
		}else{
			if($('elPreviewImageURL') == null){
				alert(oMessages['selectAttachImage']);
				return false;
			}

			if($('elPreviewImageURL').value != 'http://' && $('elPreviewImageURL').value != ''){
				if($('elPreviewImageURL').image_width){
					var elAlign = document.getElementsByName('elAttachType');
					for(i=0; i<elAlign.length; i++){
						if(elAlign[i].checked) var sAlign = elAlign[i].value;
					}
					insertImageToEditor($('elPreviewImageURL').value, '', sAlign, $('elPreviewImageURL').image_width, $('elPreviewImageURL').image_height);
					self.close();
				}else{
					alert(oMessages['checkImagePreview']);
					return false;
				}
			}else{
				alert(oMessages['inputImageURL']);
				return false;
			}
		}
	}

	function initializePreviewImageScript(sImageSrc){
		setDocumentDomain();
		var oImage = $(sImageSrc);
		var nRatioBase, nRatioWidth, nRatioHeight, nResizeWidth, nResizeHeight;

		if(oImage.offsetWidth > window.screen.availWidth || oImage.offsetHeight > window.screen.availHeight){
			nRatioWidth  = window.screen.availWidth / oImage.offsetWidth;
			nRatioHeight = window.screen.availHeight / oImage.offsetHeight;

			if(nRatioWidth > nRatioHeight) nRatioBase = nRatioHeight;
			else nRatioBase = nRatioWidth;

			nResizeWidth  = oImage.offsetWidth * nRatioBase;
			nResizeHeight = oImage.offsetHeight * nRatioBase;
		}else{
			nResizeWidth  = oImage.offsetWidth;
			nResizeHeight = oImage.offsetHeight;
			if(oAgent.IE){
				nResizeWidth += 4;
				nResizeHeight += 4
			}
		}
		setWindowSize(nResizeWidth, nResizeHeight, true);
	}

	/***********************************************************************************************************************
	* 공통 스크립트
	***********************************************************************************************************************/

	function popupLogin() {
		var url = sLoginPopupUrlPrefix.replace('_successCallback_', encodeURIComponent(sLoginCallbackUrl));
		var nTop = (window.screen.availHeight - 200) / 2;
		var nLeft = (window.screen.availWidth - 400) / 2;

		window.open(url, 'wndLoginWindow', 'width=400, height=200, scrollbars=0, status=0, resizable=0, toolbar=0, titlebar=0, location=0, left=' + nLeft + ', top=' + nTop);
	}

	function popupPrint(width) {
		window.open(sPrintPopupUrl, 'wndPrintWindow', 'width=' + width + ', height=50, status=0, toolbar=0, titlebar=0, location=0, scrollbars=1');
	}

	function popupReport(targetType, targetId, writer, title) {
		if(sLoginUserId){
			var nTop = (window.screen.availHeight - 200) / 2;
			var nLeft = (window.screen.availWidth - 400) / 2;
			window.open('', 'wndReportWindow', 'width=400, height=200, scrollbars=0, status=0, resizable=0, toolbar=0, titlebar=0, location=0, left=' + nLeft + ', top=' + nTop);

			var url;
			if(targetType == 'question') url = sReportQuestionUrlTemplate.replace('_questionId_', targetId);
			else if(targetType == 'answer') url = sReportAnswerUrlTemplate.replace('_answerId_', targetId);
			else if(targetType == 'comment') url = sReportCommentUrlTemplate.replace('_commentId_', targetId);
			else {alert('assertion fail : targetType = ' + targetType); return false;}

			var oForm = $('popupReportForm');
			oForm.action = url;
			oForm.target = 'wndReportWindow';
			if(title != null) {
				oForm.title.value = title;
			} else {
				oForm.title.value = null;
			}
			if(writer != null) {
				oForm.writer.value = writer;
			} else {
				oForm.writer.value = null;
			}

			oForm.submit();

		}else{
			popupLogin();
		}
	}

	/**
	 * 이미지 사이즈 조절 함수
	 * @param {Object} oTarget
	 * @param {Number} nMaxWidth
	 * @param {Number} nMaxHeight
	 */
	function resizeImage(oTarget, nMaxWidth, nMaxHeight){
		var nRatioBase, nRatioWidth, nRatioHeight, nResizeWidth, nResizeHeight;

		if(oTarget.width > nMaxWidth || oTarget.height > nMaxHeight){
			nRatioWidth  = nMaxWidth / oTarget.width;
			nRatioHeight = nMaxHeight / oTarget.height;

			if(nRatioWidth > nRatioHeight) nRatioBase = nRatioHeight;
			else nRatioBase = nRatioWidth;

			nResizeWidth  = oTarget.width * nRatioBase;
			nResizeHeight = oTarget.height * nRatioBase;
		}else{
			nResizeWidth  = oTarget.width;
			nResizeHeight = oTarget.height;
		}
		oTarget.width = parseInt(nResizeWidth);
		oTarget.height = parseInt(nResizeHeight);
		return {'nWidth':parseInt(nResizeWidth), 'nHeight':parseInt(nResizeHeight)};
	}

	/**
	 * 첨부된 이미지를 문서 사이즈에 맞게 리사이징
	 * @param {Boolean} bLink
	 */
	function resizeAttachedImage(bLink){
		var nMaxWidth = $('elPostOption').offsetWidth - 45;

		for(var i=0; i<aDocumentIDList.length; i++){
			var aImageList = $('elContent_'+aDocumentIDList[i]).getElementsByTagName('IMG');
			for(var j=0; j<aImageList.length; j++){
				if(aImageList[j].getAttribute('nhn_extra_image') != 'true'){
					resizeImage(aImageList[j], nMaxWidth)
/*
					if(aImageList[j].offsetWidth >= nMaxWidth){
						var nHeight = parseInt(aImageList[j].offsetHeight * (nMaxWidth / aImageList[j].offsetWidth));
						aImageList[j].width = nMaxWidth;
						aImageList[j].style.width = nMaxWidth + 'px';
						aImageList[j].height = nHeight;
						aImageList[j].style.height = nHeight + 'px';
					}
*/
					if(bLink){
						try{ aImageList[j].style.cursor = 'pointer';} catch(e){ aImageList[j].style.cursor = 'hand'; }
						aImageList[j].onclick = function(){
							var sUrl = sImagePopupUrl + (sImagePopupUrl.indexOf('?') >= 0 ? '&' : '?') + 'ImageURL=' + encodeURIComponent(this.src);
							window.open(sUrl, 'wndPreviewImage', 'top='+(window.screen.availHeight/2 - 90)+', left='+(window.screen.availWidth/2 - 130)+', width=260, height=180');
						}
					}
					if(aImageList[j].offsetWidth == nMaxWidth) aImageList[j].style.display = "block";
				}
			}
		}
	}

	/**
	 * 지정된 셀렉트박스 객체에 옵션 항목 추가
	 * @param {Object} oTarget
	 * @param {String} sValue
	 * @param {String} sText
	 */
	function addCategoryOption(oTarget, sValue, sText){
		if(oTarget && sText && sValue){
			var oOption = new Option();
			oOption.value = sValue;
			oOption.innerHTML = sText;
			oOption.text = sText;
			oTarget.appendChild(oOption);
		}
	}

	/**
	 * 지정된 셀렉트박스 객체의 옵션 항목 삭제
	 * @param {Object} oTarget
	 * @param {Number} nIndex
	 */
	function removeCategoryOption(oTarget, nIndex){
		if(nIndex) nIndex = 1;

		if(typeof(oTarget) == "object"){
			nLimit = oTarget.options.length - 1;
			for(var i=nLimit; i>=nIndex; i--){
				oTarget.removeChild(oTarget.options[i]);
			}
		}
	}

	function isValidCategory(categoryList, id){
		for(var i=0; i<categoryList.length; i++){
			if(categoryIdList[i]['id'] == id) return true;
		}
		return false;
	}

	/**
	 * 카테고리 값을 설정
	 */
	function setCategoryList(){
		// aCurrentCategory 정보가 있을 경우 셀렉트박스의 항목을 셋팅하고 선택함
		if(oCategory0 && aCurrentCategory[0] && isValidCategory(aCategoryList['0'], aCurrentCategory[0])){
			$('elCategory_0').value = aCurrentCategory[0];
			oCategory0.touch();
			if(oCategory1) changeCategory(0, aCurrentCategory[0]);
		} else return;

		if(oCategory1 && aCurrentCategory[1] && isValidCategory(aCategoryList[aCurrentCategory[0]], aCurrentCategory[1])){
			$('elCategory_1').value = aCurrentCategory[1];
			oCategory1.touch();
			if(oCategory2) changeCategory(1, aCurrentCategory[1]);
		} else return;

		if(oCategory2 && aCurrentCategory[2] && isValidCategory(aCategoryList[aCurrentCategory[1]], aCurrentCategory[2])){
			$('elCategory_2').value = aCurrentCategory[2];
			oCategory2.touch();
			if(oCategory3) changeCategory(2, aCurrentCategory[2]);
		} else return;

		if(oCategory3 && aCurrentCategory[3] && isValidCategory(aCategoryList[aCurrentCategory[2]], aCurrentCategory[3])){
			$('elCategory_3').value = aCurrentCategory[3];
			oCategory3.touch();
		}
	}

	/**
	 * 셀렉트박스의 선택값이 변경될 때 처리
	 * @param {Number} nStep
	 * @param {String} sCategoryID
	 */
	function changeCategory(nStep, sCategoryID){
		var oTarget;
		switch(nStep){
		case 0:
			oTarget = $("elCategory_0");
			if($("elCategory_1") != null) removeCategoryOption($("elCategory_1"), 1);
			if($("elCategory_2") != null) removeCategoryOption($("elCategory_2"), 1);
			if($("elCategory_3") != null) removeCategoryOption($("elCategory_3"), 1);
			break;
		case 1:
			oTarget = $("elCategory_1");
			if($("elCategory_2") != null) removeCategoryOption($("elCategory_2"), 1);
			if($("elCategory_3") != null) removeCategoryOption($("elCategory_3"), 1);
			break;
		case 2:
			oTarget = $("elCategory_2");
			if($("elCategory_3") != null) removeCategoryOption($("elCategory_3"), 1);
			break;
		}

		// sCategoryID 값이 있을 경우
		if(sCategoryID){
			if($("elCategory_"+(nStep + 1)) != null){
				// 카테고리 배열 정보를 참조하여 새로운 항목 추가
				if(typeof(aCategoryList[sCategoryID]) != "undefined"){
					for(var i=0; i<aCategoryList[sCategoryID].length; i++){
						addCategoryOption(oTarget, aCategoryList[sCategoryID][i].id, aCategoryList[sCategoryID][i].name);
					}
				}
			}
		}

		if(nStep == 0 && oCategory1 != null){
			$("elCategory_1").value = "";
			oCategory1.touch();
		}
		if((nStep == 0 || nStep == 1) && oCategory2 != null){
			$("elCategory_2").value = "";
			oCategory2.touch();
		}
		if((nStep == 0 || nStep == 1 || nStep == 2) && oCategory3 != null){
			$("elCategory_3").value = "";
			oCategory3.touch();
		}
	}

	/**
	 * 특정 객체의 최대 문자열을 체크하여 초과된 부분을 삭제 처리
	 * @param {Object} oTarget
	 * @param {Number} nMaxLength
	 */
	function checkMaxLength(oTarget, nMaxLength, sMessage){
		var sValue = oTarget.value;
		var nLength = sValue.length;

		if(nLength > nMaxLength){
			alert(replaceTextSizeMsg(sMessage, nMaxLength));
			sValue = sValue.replace(/\r\n$/,"");
			oTarget.value = sValue.substr(0, nMaxLength);
			oTarget.focus();
			return false;
		}
	}

	function checkObjectValueMaxLengthInByte(oTarget, nMaxLength, sMessage){
		var sValue = oTarget.value;
		var nLength = getByte(sValue);

		if(nLength > nMaxLength){
			alert(replaceTextSizeMsg(sMessage, nMaxLength));
			oTarget.focus();
			return false;
		}

		return true;
	}

	function checkMaxLengthInByte(sValue, nMaxLength, sMessage){
		var nLength = getByte(sValue);

		if(nLength > nMaxLength){
			alert(replaceTextSizeMsg(sMessage, nMaxLength));
			return false;
		}

		return true;
	}


	/**
	 * 윈도우 사이즈 변경 함수
	 * @param {Number} nWidth
	 * @param {Number} nHeight
	 */
	function setWindowSize(nWidth, nHeight, bMoveCenter){
		var oDocument = document.getElementsByTagName('HTML')[0];
 		var nTargetWidth = nWidth || oDocument.scrollWidth;
 		var nTargetHeight = nHeight || oDocument.scrollHeight;

 		var oRuler = document.body.appendChild(document.createElement('DIV'));
 		with(oRuler.style) {
 			position = 'absolute'; left = top = 0; width = height = '100%';
		}

		var nDifferentWidth = nTargetWidth - oDocument.offsetWidth;
		var nDifferentHeight = oAgent.IE ? nTargetHeight - Math.max(oDocument.offsetHeight, oRuler.offsetHeight) : nTargetHeight - oRuler.offsetHeight;
		//var nDifferentHeight =nTargetHeight - Math.max(oDocument.offsetHeight, oRuler.offsetHeight) : nTargetHeight - oRuler.offsetHeight;

		//alert("nDifferentWidth : "+nDifferentWidth+"\nnDifferentHeight : "+nDifferentHeight+"\nnTargetWidth : "+nTargetWidth+"\nnTargetHeight : "+nTargetHeight+"\noRuler.offsetWidth : "+oRuler.offsetWidth+"\noRuler.offsetHeight : "+oRuler.offsetHeight+"\nnWidth : "+nWidth+"\nnHeight : "+nHeight+"\noDocument.scrollWidth : "+oDocument.scrollWidth+"\noDocument.scrollHeight : "+oDocument.scrollHeight)
		if(nDifferentWidth || nDifferentHeight){
			resizeWindow(nTargetWidth, nTargetHeight, nDifferentWidth, nDifferentHeight, bMoveCenter);
		}

 		document.body.removeChild(oRuler);
	}

	/**
	 * 윈도우 사이즈 변경 함수
	 * @param {Object} nDifferentWidth
	 * @param {Object} nDifferentHeight
	 */
	var oResizingTimer;
	function resizeWindow(nWidth, nHeight, nDifferentWidth, nDifferentHeight, bMoveCenter){
		try{
			if(oAgent.IE){
				var nScreenTop = top.window.screenTop;
				var nScreenLeft = top.window.screenLeft;
				var nAvailableWidth = top.window.screen.availWidth;
				var nAvailableHeight = top.window.screen.availHeight;
				var nTitleBarHeight = oAgent.IE7 ? 28 : 0;
				var nAddressBarHeight = oAgent.IE7 ? 24 : 0;
				var nStatusBarHeight = oAgent.IE7 ? 24 : 0;
				var nBorder = 6;

				if(nWidth >= nAvailableWidth || (nHeight + nTitleBarHeight + nAddressBarHeight) >= nAvailableHeight){
					top.window.moveTo(nScreenLeft - 3, 0)
				}else{
					var nMovePositionX = ((nScreenLeft + nWidth + nBorder) > nAvailableWidth && nScreenLeft < nAvailableWidth) ? (nScreenLeft + nWidth) - nAvailableWidth : 0;
					var nMovePositionY = ((nScreenTop + nHeight + nStatusBarHeight) > nAvailableHeight) ? (nScreenTop + nHeight + nStatusBarHeight) - nAvailableHeight : 0;
					if(nMovePositionX != 0 || nMovePositionY != 0 || nScreenLeft > nAvailableWidth) top.window.moveBy(-nMovePositionX, -nMovePositionY);
				}

				if(nAvailableHeight < nHeight || nAvailableWidth < nWidth){
					top.window.moveTo(0, 0);
				}else{
					if(bMoveCenter){
						top.window.moveTo(nAvailableWidth/2 - nWidth/2, nAvailableHeight /2 - nHeight/2 - 40);
					}
				}
			}
			top.window.resizeBy(nDifferentWidth, nDifferentHeight);

			//document.title = (nHeight+" : "+top.window.screen.availHeight + " : "+ top.window.screenTop+" : "+nDifferentHeight+" : "+nMovePositionY)
		}catch(e){
			if(oResizingTimer == null){
				oResizingTimer = setTimeout('resizeWindow('+nWidth+', '+nHeight+', '+nDifferentWidth+', '+nDifferentHeight+', '+bMoveCenter+')', 100);
				oResizingTimer = null;
			}
		}
	}

	/**
	 * 이올라스 패치 관련 함수 (플래시 및 ActiveX 삽입 함수)
	 * @param {String} src
	 */
	function insertObjectTag(src){
		document.write(src);
	}

	/**
	 * 플래시 플레이어의 버전을 구해서 리턴
	 * @return {Number}
	 */
	function getFlashVersion(){
		if (navigator.plugins && navigator.plugins.length) {
			var x = navigator.plugins["Shockwave Flash"];
			if (x && x.description) {
				var y = x.description;
				return parseInt(y.charAt(y.indexOf('.')-1));
			}
		} else if (ActiveXObject){
			try {
				new ActiveXObject('ShockwaveFlash.ShockwaveFlash.9');
				return 9;
			} catch(e1) {
				try {
					new ActiveXObject('ShockwaveFlash.ShockwaveFlash.8');
					return 8;
				} catch(e2) {
					try {
						new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
						return 7;
					}catch(e3){
						return -1;
					}
				}
			}
		}

		return -1;
	}

	/**
	 * 아이프레임의 높이를 자동으로 변경
	 * @param {Object} oTarget
	 * @param {Number} nMinimunHeight
	 */
	function resizeIFrame(oTarget, nMinimunHeight) {
		nMinimunHeight = nMinimunHeight || 300;

		var getHeightByElement = function(body) {
			var oLast = body.lastChild;

			try {
				while (oLast.nodeType != 1) oLast = oLast.previousSibling;
				return oLast.offsetTop+oLast.offsetHeight;
			} catch(e) {
				return 0;
			}
		}

		var oTargetWindow = oTarget.contentWindow || oTarget;
		var oTargetDocument = oTargetWindow.document;
		if (oTargetDocument.location.href == 'about:blank') {
			oTarget.style.height = nMinimunHeight+'px';
			return;
		}

		var nHeight = Math.max(oTargetDocument.body.scrollHeight,getHeightByElement(oTargetDocument.body));

		if (/MSIE/.test(navigator.userAgent)) nHeight += oTargetDocument.body.offsetHeight - oTargetDocument.body.clientHeight;
		if (nHeight < nMinimunHeight) nHeight = nMinimunHeight;

		oTarget.style.height = nHeight + 'px';
		if (typeof resizeIFrame.check == 'undefined') resizeIFrame.check = 0;
		if (typeof oTarget._check == 'undefined') oTarget._check = 0;

		if (oTarget._check < 5) {
			oTarget._check++;
			setTimeout('resizeIFrame', 100, [oTarget,nMinimunHeight]); // check 5 times for IE bug
		} else {
			oTarget._check = 0;
		}
	}

	/**
	 * 현재 문서를 포함하는 아이프레임의 높이를 자동으로 변경
	 * @param {Object} oTarget
	 * @param {Number} nMinimunHeight
	 */
	function resizeParentIFrame(oTarget, nMinimunHeight){
		nMinimunHeight = nMinimunHeight || 300;

		if(oAgent.Safari) var nHeight = $('qboard').offsetHeight;
		else var nHeight = (/MSIE/.test(navigator.userAgent) ?  document.body.scrollHeight + (document.body.offsetHeight - document.body.clientHeight) : document.documentElement.scrollHeight || document.body.scrollHeight);
		oTarget.style.height = (nHeight < nMinimunHeight) ? nMinimunHeight+'px' : nHeight+'px';

		if (typeof resizeParentIFrame.check == 'undefined') resizeParentIFrame.check = 0;
		if (typeof oTarget._check == 'undefined') oTarget._check = 0;

		if (oTarget._check < 5) {
			oTarget._check++;
			setTimeout('resizeParentIFrame', 100, [oTarget,nMinimunHeight]); // check 5 times for IE bug
		} else {
			oTarget._check = 0;
		}
	}

	function checkAjaxError(oRequest){
		if(oRequest.status != 200) {
			alert(oMessages['serverError']);
			return false;
		}

		var sResult = oRequest.getResponseHeader('NBoardResult');
		if(sResult) {
			if(sResult == '599'){
				alert(oRequest.responseText.replace(/\r\n/g,''));
				return false;
			}
		}

		return true;
	}

	/**
	 * sUrl 페이지를 새창으로 열음
	 * @param {String} sUrl
	 * @param {Number} nWidth
	 * @param {Number} nHeight
	 * @param {String} sFeature
	 */
	function openWindow(sUrl, nWidth, nHeight, sFeature){
		sFeature = 'width='+nWidth+',height='+nHeight + (sFeature ? ','+sFeature : '');
		window.open(sUrl, null, sFeature);
	}

	/**
	 * sLayerID에 해당하는 레이어를 보여줌
	 * @param {String} sLayerID
	 * @param {Object} oBaseElement
	 * @param {Number} nTop
	 * @param {Number} nLeft
	 * @param {Number} nBaseAlign
	 */
	function showMessageLayer(sLayerID, oBaseElement, nTop, nLeft, nBaseAlign){
		if(oControlLayer == null) oControlLayer = new Ju.controlLayer({'bAutoAdjusting' : true});
		oControlLayer.show(sLayerID, oBaseElement, nTop, nLeft, nBaseAlign);
	}

	/**
	 * sLayerID에 해당하는 레이어를 숨김
	 * @param {String} sLayerID
	 */
	function hideMessageLayer(sLayerID){
		if(oControlLayer == null) return false;
		oControlLayer.hide(sLayerID)
	}

	/**
	 * sLayerID에 해당하는 레이어의 display 속성을 토글
	 * @param {String} sLayerID
	 */
	function toggleLayer(sLayerID){
		Element.toggle(sLayerID);
	}

	/**
	 * sParentFrame 값이 설정되었을 경우 현재 문서를 포함하는 상위 아이프레임의 높이를 변경
	 */
	function checkParentIFrame(){
		if(sParentFrame) {
			var oTarget = eval(sParentFrame);
			if(oTarget) resizeParentIFrame(oTarget);
		}
	}

	/**
	 * document.domain 설정 함수
	 */
	function setDocumentDomain(){
		var aDomain = document.domain.split('.');
		var nLength = aDomain.length;
		if(nLength > 2) document.domain = aDomain[nLength - 2] + '.' + aDomain[nLength - 1];
	}

	function initializeWindowDefaultScript(nWidth, nHeight, bCenter){
		setDocumentDomain();
		setWindowSize(nWidth, nHeight, bCenter);
	}

	function initializePreviewScript(){
		setDocumentDomain();
		setWindowSize($('n2_content').offsetWidth+65, Math.min($('qboard').offsetHeight + 20, 570), true);
		addClickPreventLayer($("elClickPreventArea"));
	}

	function addClickPreventLayer(oPreventArea){
		var oPreventClickLayer = document.createElement("DIV");

		oControlLayer = new Ju.controlLayer();
		var oPosition = oControlLayer.getRealPosition(oPreventArea);
		with(oPreventClickLayer.style){
			position = 'absolute';
			top = oPosition.top;
			left = 0;
			width = '100%';
			height = oPreventArea.offsetHeight;
			background = '#FFFFFF';
			filter =  'alpha(Opacity=0)';
			opacity = '0';
			zIndex = '1000';
		}
		document.body.appendChild(oPreventClickLayer);
	}

	function goLoginPage() {
		var nboardUrl = document.location.href;
		nboardUrl = nboardUrl + (nboardUrl.indexOf("?") == -1 ? "?" : "&") + "login=true";

		var successCallback;
		if(sWrapperLoginCallbackUrl) {
			successCallback = sWrapperLoginCallbackUrl + encodeURIComponent(nboardUrl);
		} else {
			successCallback = nboardUrl;
		}

		document.location.href = sLoginPageUrlTemplate.replace('_successCallback_', encodeURIComponent(successCallback));
	}

	function checkLogin() {
		if(oAgent.Safari){
			goLoginPage();
		}else{
			popupLogin();
		}
	}

	/**
	 * 모든 답변용 Flash UI의 isMaximum 값을 갱신하는 함수
	 * @param {String} sFlashID
	 */
	function changeMaximumButton(sFlashID){
		for(var i=1; i<aAnswerIDList.length; i++){
			if("elRecommendFlash_"+aAnswerIDList[i] == sFlashID){
				window['elRecommendFlash_'+aAnswerIDList[i]].changeMaximumButton(true);
			}else{
				window['elRecommendFlash_'+aAnswerIDList[i]].changeMaximumButton(false);
			}
		}
	}

	/**
	 * 문자열의 바이트 수를 구하여 리턴 (UTF-8 기준)
	 * @param {Object} sTargetString
	 */
	function getByte(sTargetString){
		var nByte = 0;
		for(var i=0; i<sTargetString.length; i++){
			var nCode = sTargetString.charCodeAt(i);
			if(nCode <= 127) nByte++;
			else if(nCode > 128 && nCode <= 2047) nByte+=2;
			else if(nCode > 2048 && nCode <= 65535) nByte+=3;
			else if(nCode > 65536 && nCode <= 111411) nByte+=4;
		}

		return nByte;
	}

	var sUserIdForUserLayer = null;
	function showUserLayer(sElementID, userId){
        sUserIdForUserLayer = userId;

		var labelSet = (sLoginUserId != "" && sLoginUserId == userId) ? "myself" : "normal";
		updateUserLayerLabel(labelSet);

   	    var oLayer = $('elUserLayer');
   	    var oBase = $(sElementID);
   	    var oPosition = oControlLayer.getRealPosition($(sElementID))
		oControlLayer.show('elUserLayer', null, oPosition.left, oPosition.top, 8);
		oLayer.style.left = (oPosition.left) + "px";

   	    var sDecidedPosition = sUserLayerPosition;
   	    if(sDecidedPosition == "DOWN"){
   	        var nHeight = (/MSIE/.test(navigator.userAgent) ?  document.body.scrollHeight + (document.body.offsetHeight - document.body.clientHeight) : document.body.offsetHeight);
   	        if(oPosition.top + oBase.offsetHeight + oLayer.offsetHeight > nHeight) {
   	            sDecidedPosition = "UP";
   	        }
   	    }
   	    if(sDecidedPosition == "UP"){
   	        if(oPosition.top < oLayer.offsetHeight) {
   	            sDecidedPosition = "DOWN";
   	        }
   	    }

   	    if(sDecidedPosition == "UP") {
			oLayer.className = "user_layer_up";
   	    	oLayer.style.top = (oPosition.top - oLayer.offsetHeight) + "px";
		} else  {
		    oLayer.className = "user_layer_down";
			oLayer.style.top = (oPosition.top + oBase.offsetHeight) + "px";
		}
    }

    function updateUserLayerLabel(labelSet) {
    	for(var i = 0; i < aUserLayerLabel[labelSet].length; i++) {
    		if($("elUserLayerItem_" + i)) {
    			$("elUserLayerItem_" + i).innerHTML = aUserLayerLabel[labelSet][i];
    		} else {
    			break;
    		}
    	}
    }

    function goUserLayerLink(nLinkIndex){
        Element.toggle('elUserLayer');
        window.top.location = aUserLayerLink[nLinkIndex].replace("_userId_", sUserIdForUserLayer);
    }

    function replaceTextSizeMsg(msg, maxLength) {
    	return msg.replace("_maxSize_", maxLength).replace("_1byteCharacterMaxLength_", maxLength).replace("_2byteCharacterMaxLength_", Math.floor(maxLength / 2)).replace("_3byteCharacterMaxLength_", Math.floor(maxLength / 3));
    }

    function showCategoryLayer(oBaseElement){
	oControlLayer.show('elCategoryLayer', oBaseElement, -7, -9, 5)
    }

	// 2008.09.24 modified by duwonyi - Start
	/**
	 * 웹브라우저에 대한 정보 객체를 반환하는 함수.
	 * added by Yiduwon
	 */
	function getBrowserInfo() {
		var info = new Object;
		var ver  = -1;
		var u    = navigator.userAgent;
		var v    = navigator.vendor || "";

		function f(s,h){ return ((h||"").indexOf(s) > -1) };

		info.opera     = (typeof window.opera != "undefined") || f("Opera",u);
		info.ie        = !info.opera && f("MSIE",u);
		info.safari    = f("Apple",v);
		info.mozilla   = f("Gecko",u) && !info.safari;
		info.firefox   = f("Firefox",u);
		info.camino    = f("Camino",v);
		info.netscape  = f("Netscape",u);
		info.omniweb   = f("OmniWeb",u);
		info.icab      = f("iCab",v);
		info.konqueror = f("KDE",v);

		try {
			if (info.ie) {
				ver = u.match(/(?:MSIE) ([0-9.]+)/)[1];
			} else if (info.firefox||info.opera||info.omniweb) {
				ver = u.match(/(?:Firefox|Opera|OmniWeb)\/([0-9.]+)/)[1];
			} else if (info.mozilla) {
				ver = u.match(/rv:([0-9.]+)/)[1];
			} else if (info.safari) {
				ver = parseFloat(u.match(/Safari\/([0-9.]+)/)[1]);
				if (ver == 100) {
					ver = 1.1;
				} else {
					ver = [1.0,1.2,-1,1.3,2.0,3.0][Math.floor(ver/100)];
				}
			} else if (info.icab) {
				ver = u.match(/iCab[ \/]([0-9.]+)/)[1];
			}

			info.version = parseFloat(ver);
			if (isNaN(info.version)) info.version = -1;
		} catch(e) {
			info.version = -1;
		}

		$Agent.prototype.navigator = function() {
			return info;
		};

		return info;
	};
	// 2008.09.24 modified by duwonyi - End
