<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<c:set var="pageKorName" scope="request">민원신고 답변 문구 관리</c:set>
<div class="content-wrapper" data-doctx="${pageName}">
	<div class="container-xxl flex-grow-1 px-0" name="wrapper">
		<div class="card wrapper-list">

		    <form name="frmSearch">
		        <div class="container-search">
                    <div class="row g-1">
                        <div class="col-12">
                            <span class="form-label fw-bold form-search-title w-px-120 text-end">업무구분</span>
                            <span class="form-search-linebox">
								<c:forEach items="${TaskListForSgg}" var="item">
									<label>
										<input name="taskSeCd" type="radio" value="${item.code}"
										class="form-check-input" alt="업무구분"
										onchange="pageObject['${pageName}'].fnResetAndChangeBiz(this.value);">
										${item.value}
									</label>
								</c:forEach>
                            </span>
                        </div>
                    </div>
		        </div>
		    </form>

			<div class="container-page-btn mt-3">
		        <button type="button" name="btnReset" class="btn btn-outline-dark w-px-120" title="초기화">
		        초기화
		        </button>
		        <span class="container-window-btn-right"></span>
		    </div>

		    <span class="d-flex justify-content-center">
			    <div class="nav-align-top mb-1 w-px-1300">
					<ul class="nav nav-tabs" role="tablist">
						<li class="nav-item">
							<button type="button" name="btnAnsBasicTab" class="nav-link active"
							role="tab" data-bs-toggle="tab">
								머리말/꼬리말
							</button>
						</li>
						<li class="nav-item">
							<button type="button" name="btnLevyAnsBodyTab" class="nav-link"
							role="tab" data-bs-toggle="tab">
								부과건 답변내용
							</button>
						</li>
						<li class="nav-item">
							<button type="button" name="btnWarningAnsBodyTab" class="nav-link"
							role="tab" data-bs-toggle="tab">
								계도건 답변내용
							</button>
						</li>
						<li class="nav-item">
							<button type="button" name="btnNonlevyAnsBodyTab" class="nav-link"
							role="tab" data-bs-toggle="tab">
								미부과처리건 답변내용
							</button>
						</li>
					</ul>
				</div>
		    </span>

		    <div class="h-px-500 mt-1">

		    	<!-- 머리말,꼬리말 영역 -->
		    	<span class="area-answerbasic">
		    		<div class="d-flex flex-row justify-content-center h-100">
						<div class="card p-4 justify-content-center align-items-center w-px-1300">
							<form name="frmEditAnsBasic">
								<div class="w-px-900">
									<div class="row">
										<div class="col-12">
											<label is="name-label" for="headerCn"
											class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end align-top"
											>머리말</label>
											<textarea is="id-textarea" name="headerCn"
											rows="5" cols="80%" class="form-control" required
											placeholder="머리말이 없습니다."
											></textarea>
										</div>
									</div>
									<div class="row">
										<div class="col-12">
											<label is="name-label" for="footerCn"
											class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end align-top"
											>꼬리말</label>
											<textarea is="id-textarea" name="footerCn"
											rows="5" cols="80%" class="form-control" required
											placeholder="꼬리말이 없습니다."
											></textarea>
										</div>
									</div>
									<div class="row justify-content-end">
										<div class="col-12">
											<button type="button" name="btnSaveAnsBasic"
								        	class="btn btn-primary float-end" title="적용">적용</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
		    	</span>

		    	<!-- 본문처리 영역 -->
		    	<span class="area-answerbody area-answerbody-common">
		    		<div class="d-flex flex-row justify-content-center h-100">
						<div class="card p-4 d-flex flex-row w-px-1300">
							<!-- 그리드 영역 -->
							<div class="card-datatable text-nowrap d-inline-flex border-card">
								<div class="dataTables_wrapper dt-bootstrap5 no-footer">
									<!-- 부과건 그리드 -->
									<span class="area-answerbody area-levy">
										<div class="table-responsive oy-auto h-100"
											style="width:470px;">
											<table name="vltnTable" class="datatables-ajax table table-bordered dataTable no-footer">
												<thead class="sticky-thead">
													<tr>
														<th style="width:50px;"></th>
														<th style="min-width: 300px;">위반내용</th>
													</tr>
												</thead>
							                    <tbody name="vltnTbody"></tbody>
												<template is="curly-brackets" name="vltnRow">
													<tr data-index="DATA-INDEX">
														<td class="text-center min-w-px-50 mw-px-50">
															<input type="radio" name="levyRadio" value="DATA-INDEX"
															onchange />
														</td>
							                    		<td onclick class="text-center">VLTN_CASE_NM</td>
							                    	</tr>
												</template>
												<template name="vltnNotFound">
													<tr>
														<td valign="top" colspan="2"
														class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
													</tr>
												</template>
											</table>
										</div>
									</span>
									<!-- 계도건 그리드 -->
									<span class="area-answerbody area-warning">
										<div class="table-responsive oy-auto h-100"
											style="width:470px;">
											<table name="warningTable" class="datatables-ajax table table-bordered dataTable no-footer">
												<thead class="sticky-thead">
													<tr>
														<th style="width:50px;"></th>
														<th style="min-width: 300px;">계도내용</th>
													</tr>
												</thead>
							                    <tbody name="warningTbody"></tbody>
												<template is="curly-brackets" name="warningRow">
													<tr data-index="DATA-INDEX">
														<td class="text-center min-w-px-50 mw-px-50">
															<input type="radio" name="warningRadio" value="DATA-INDEX"
															onchange />
														</td>
							                    		<td onclick class="text-center">LEVY_EXCL_RSN_NM</td>
							                    	</tr>
												</template>
												<template name="warningNotFound">
													<tr>
														<td valign="top" colspan="2"
														class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
													</tr>
												</template>
											</table>
										</div>
									</span>
									<!-- 미부과처리건 그리드 -->
									<span class="area-answerbody area-nonlevy">
										<div class="table-responsive oy-auto h-100"
											style="width:470px;">
											<table name="nonlevyTable" class="datatables-ajax table table-bordered dataTable no-footer">
												<thead class="sticky-thead">
													<tr>
														<th style="width:50px;"></th>
														<th style="min-width: 300px;">미부과사유</th>
														<th style="min-width: 100px;">답변여부</th>
													</tr>
												</thead>
							                    <tbody name="nonlevyTbody"></tbody>
												<template is="curly-brackets" name="nonlevyRow">
													<tr data-index="DATA-INDEX">
														<td class="text-center min-w-px-50 mw-px-50">
															<input type="radio" name="nonlevyRadio" value="DATA-INDEX"
															onchange />
														</td>
														<td onclick class="text-center">LEVY_EXCL_RSN_NM</td>
							                    		<td onclick class="text-center">USE_YN</td>
							                    	</tr>
												</template>
												<template name="nonlevyNotFound">
													<tr>
														<td valign="top" colspan="3"
														class="dataTables_empty text-center">정보를 찾지 못했습니다.</td>
													</tr>
												</template>
											</table>
										</div>
									</span>
								</div>
						    </div>

					    	<!-- 답변내용 표시영역 -->
						    <div class="w-px-800 d-inline-flex">
					    		<div class="container-md d-flex justify-content-between flex-column">
							    	<div class="row g-1 h-px-400 oy-auto border-separator-b">
								    	<div class="col-12">
								    		<form name="frmEditAnsBody">
								    			<input type="hidden" name="ansRsnCd" />
								    			<input type="hidden" name="dstrbncYn" />
								    			<input type="hidden" name="ansWordsId" />
								    			<label is="name-label" for="prcsRsltCn"
								    			class="w-px-130 bg-lighter pe-2 col-form-label text-sm-center">
								    			답변내용
								    			</label>
								    			<br/>
								    			<textarea is="id-textarea" name="prcsRsltCn"
								    			class="form-control w-100" required rows="15"
								    			></textarea>
								    		</form>
								    	</div>
							    	</div>
							    	<div class="row g-1 py-2">
							    		<div class="col-12">
							    			<div class="btns float-start">
							    				<button type="button" name="btnRemove"
								            		class="btn btn-primary area-answerbody area-nonlevy"
								            		title="답변대상 제외">답변대상 제외</button>
							    			</div>
							    			<div class="btns float-end">
							    				<button type="button" name="btnOpenPreviewPop"
								            		class="btn btn-primary" title="미리보기">미리보기</button>
								            	<button type="button" name="btnSaveAnsBody"
								            		class="btn btn-primary" title="적용">적용</button>
							    			</div>
						    			</div>
					            	</div>
				            	</div>
							</div>
					    </div>
					</div>
		    	</span>
		    </div>

		    <!-- 매크로 삽입 버튼 영역 -->
		    <div class="mt-4 d-flex flex-row justify-content-center align-items-center">
				<div class="card ps-3 py-3 w-px-1300">
					<div class="row">
						<div class="col-12 btns">
							<strong>[매크로 문자 삽입]</strong>
							<label name="macroTarget" for="" hidden></label>

							<button type="button" name="btnInsertMacro1"
			            		class="btn btn-primary" title="일련번호 삽입">일련번호</button>
			            	<button type="button" name="btnInsertMacro2"
			            		class="btn btn-primary" title="사용자 전화번호 삽입">사용자 전화번호</button>
			            	<button type="button" name="btnInsertMacro3"
			            		class="btn btn-primary" title="사용자 성명 삽입">사용자 성명</button>
						</div>
	            	</div>
				</div>
			</div>
			<div class="toast-container position-fixed bottom-0 end-0 p-3">
			  <div name="divToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
			    <div class="toast-body bg-black text-white">
			      저장 되었습니다.
			    </div>
			  </div>
			</div>
		</div>
	</div>

  	<div class="content-backdrop fade"></div>

  	<template name="previewDialogTemplate">
		<form name="frmView">
			<div class="card">
				<textarea name="preview" rows="15"
				></textarea>
			</div>
			<div>
				<span class="container-page-btn">
					<span class="container-window-btn-right">
						<button type="button" class="btn btn-primary" name="btnClose" title="닫기">닫기</button>
					</span>
				</span>
			</div>
		</form>
	</template>
</div>

<script>
LoadScript("cvlc05010Script","/resources/js/fims/cvlc/cvlc05010.js?ver=${ver}");
/**************************************************************************
* Global Variable
**************************************************************************/
pageObject["${pageName}"] = newDoctxFinder("${pageName}");

$(document).ready(function(){

	var $P = pageObject["${pageName}"];

	$P.toast = new bootstrap.Toast($P.findn("divToast"), {
        animation: true,
        autohide: true,
        delay: 2000
    });

	/**************************************************************************
	* DatasetControl, DatasetSupport, FormFields
	**************************************************************************/
	var ctrl = newCvlc05010Control($P);

	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.fnResetAndChangeBiz = (taskSeCd) => {
		ctrl.urls = {};
		ctrl.urls.load = wctx.url("/cvlc/cvlc05/010/info.do");
		ctrl.urls.update = wctx.url("/cvlc/cvlc05/010/save.do");
		ctrl.urls.remove = wctx.url("/cvlc/cvlc05/010/remove.do");

		$P.fnReset();
	}

	$P.fnReset = () => {
		$P.$findn("btnAnsBasicTab").trigger("click");
		ctrl.levy.setData([]);
		ctrl.warning.setData([]);
		ctrl.nonlevy.setData([]);

		$P.renderAnsBodyList(0,'levy');
	    $P.renderAnsBodyList(0,'warning');
	    $P.renderAnsBodyList(0,'nonlevy');

	    $P.$findn("frmEditAnsBasic").find("input, textarea").val("");
	    $P.$findn("frmEditAnsBody").find("input, textarea").val("");

	    $P.searchWordsStng();
	}

	$P.getParams = () => {
		var formFields = new FimsFormFields($P.selectorn("frmSearch"));
		var data = formFields.get();
		return data;
	}

	$P.searchWordsStng = () => {
		var taskSeCd = $P.$findn("frmSearch").find("input[name='taskSeCd']:checked").val();

		ajax.get({
			url : ctrl.urls.load,
			data : {"taskSeCd" : taskSeCd},
			success : (resp) => {

				$P.$findn("headerCn").val(resp.headerCn);
				$P.$findn("footerCn").val(resp.footerCn);

				ctrl.levy.setData(resp.levyCaseList);
				ctrl.warning.setData(resp.warningCaseList);
				ctrl.nonlevy.setData(resp.nonlevyCaseList);

				$P.renderAnsBodyList(resp.levyCaseList.length,'levy');
			    $P.renderAnsBodyList(resp.warningCaseList.length,'warning');
			    $P.renderAnsBodyList(resp.nonlevyCaseList.length,'nonlevy');

			    if(resp.levyCaseList.length > 0){
			    	var current = ctrl.levy.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'levy');
			    }
				if(resp.warningCaseList.length > 0){
					var current = ctrl.warning.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'warning');
			    }
				if(resp.nonlevyCaseList.length > 0){
					var current = ctrl.nonlevy.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'nonlevy');
				}
			}
		});
	}

	$P.renderAnsBodyList = (total, renderDataType) => {

		var notFoundName = "";
		var foundName = "";
		var tbodyName = "";
		if(renderDataType == "levy"){
			notFoundName = "vltnNotFound";
			foundName = "vltnRow";
			tbodyName = "vltnTbody";
		} else if(renderDataType == "warning"){
			notFoundName = "warningNotFound";
			foundName = "warningRow";
			tbodyName = "warningTbody";
		} else if(renderDataType == "nonlevy"){
			notFoundName = "nonlevyNotFound";
			foundName = "nonlevyRow";
			tbodyName = "nonlevyTbody";
		} else {
			return;
		}

		var ansBodyDS = ctrl[renderDataType].dataset;
		var empty = ansBodyDS.empty;
		var notFound = [$P.findn(notFoundName).innerHTML];
		var found = $P.findn(foundName).innerHTML;

		var replacer = () => {};
		if(renderDataType == "levy"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('{DATA-INDEX}','levy');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('{DATA-INDEX}','levy');");
		} else if(renderDataType == "warning"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('{DATA-INDEX}','warning');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('{DATA-INDEX}','warning');");
		} else if(renderDataType == "nonlevy"){
			replacer = (str, dataItem) => str
			.replace(/{onclick}/gi, "pageObject['${pageName}'].clickAnsBodyList('{DATA-INDEX}','nonlevy');")
			.replace(/{onchange}/gi, "pageObject['${pageName}'].radioClickAnsBodyList('{DATA-INDEX}','nonlevy');");
		}

		var trs = empty ? notFound : ansBodyDS.inStrings(found, replacer);
		$P.$findn(tbodyName).html(trs.join());
	}

	$P.radioClickAnsBodyList = (dataIndex, gridType) => {

		ctrl[gridType].setCurrent(dataIndex);

		var tbodyName = "";
		if(gridType == "levy"){
			tbodyName = "vltnTbody";
		} else if(gridType == "warning"){
			tbodyName = "warningTbody";
		} else if(gridType == "nonlevy"){
			tbodyName = "nonlevyTbody";
		} else {
			return;
		}
		$P.$findn(tbodyName).setCurrentRow(dataIndex);

		if(gridType == "levy" && $P.currentDisplay == "levyAnsBody"){
			$P.changeAnsBodyText();
		} else if(gridType == "warning" && $P.currentDisplay == "warningAnsBody"){
			$P.changeAnsBodyText();
		} else if(gridType == "nonlevy" && $P.currentDisplay == "nonlevyAnsBody"){
			$P.changeAnsBodyText();
		}
	}

	$P.clickAnsBodyList = (dataIndex, gridType) => {
		var radioName = "";
		if(gridType == "levy"){
			radioName = "levyRadio";
		} else if(gridType == "warning"){
			radioName = "warningRadio";
		} else if(gridType == "nonlevy"){
			radioName = "nonlevyRadio";
		} else {
			return;
		}

		$P.$findn("wrapper").find(":radio[name='"+radioName+"'][value='"+dataIndex+"']").prop("checked",true);

		if(gridType == "levy" && $P.currentDisplay == "levyAnsBody"){
			$P.$findn("wrapper").find(":radio[name='"+radioName+"'][value='"+dataIndex+"']").focus();
		} else if(gridType == "warning" && $P.currentDisplay == "warningAnsBody"){
			$P.$findn("wrapper").find(":radio[name='"+radioName+"'][value='"+dataIndex+"']").focus();
		} else if(gridType == "nonlevy" && $P.currentDisplay == "nonlevyAnsBody"){
			$P.$findn("wrapper").find(":radio[name='"+radioName+"'][value='"+dataIndex+"']").focus();
		}

		$P.radioClickAnsBodyList(dataIndex, gridType);
	}

	$P.changeAnsBodyText = () => {
		var curData = null;
		var rnsRsnCd = "";
		var dstrbncYn = "";

		if($P.currentDisplay == "levyAnsBody"){
			curData = ctrl.levy.getCurrent();
		} else if($P.currentDisplay == "warningAnsBody"){
			curData = ctrl.warning.getCurrent();
		} else if($P.currentDisplay == "nonlevyAnsBody"){
			curData = ctrl.nonlevy.getCurrent();
		}

		if(curData == null){
			$P.$findn("ansRsnCd").val("");
			$P.$findn("dstrbncYn").val("");
			$P.$findn("ansWordsId").val("");
			$P.$findn("prcsRsltCn").val("");
			return;
		}

		if($P.currentDisplay == "levyAnsBody"){
			if(curData["VLTN_CASE_ID"].endsWith("D")){
				rnsRsnCd = "3" + curData["VLTN_CASE_ID"].substring(0,2);
				dstrbncYn = "Y";
			} else {
				rnsRsnCd = "3" + curData["VLTN_CASE_ID"];
				dstrbncYn = "N";
			}
		} else if($P.currentDisplay == "warningAnsBody"){
			rnsRsnCd = curData["LEVY_EXCL_RSN_CD"]
		} else if($P.currentDisplay == "nonlevyAnsBody"){
			rnsRsnCd = curData["LEVY_EXCL_RSN_CD"]

			if(curData["ANS_WORDS_ID"] == null){
				$P.$findn("btnRemove").prop("disabled",true);
			} else {
				$P.$findn("btnRemove").prop("disabled",false);
			}
		}

		$P.$findn("ansRsnCd").val(rnsRsnCd);
		$P.$findn("dstrbncYn").val(dstrbncYn);
		$P.$findn("ansWordsId").val(curData["ANS_WORDS_ID"]);
		$P.$findn("prcsRsltCn").val(curData["PRCS_RSLT_CN"]);
	}

	$P.refreshAnsWordsInfo = () => {
		var cursor1 = ctrl.levy.getCurrent("item").index;
		var cursor2 = ctrl.warning.getCurrent("item").index;
		var cursor3 = ctrl.nonlevy.getCurrent("item").index;

		var taskSeCd = $P.$findn("frmSearch").find("input[name='taskSeCd']:checked").val();

		ajax.get({
			url : ctrl.urls.load,
			data : {"taskSeCd" : taskSeCd},
			success : (resp) => {

				$P.$findn("headerCn").val(resp.headerCn);
				$P.$findn("footerCn").val(resp.footerCn);

				ctrl.levy.setData(resp.levyCaseList);
				ctrl.warning.setData(resp.warningCaseList);
				ctrl.nonlevy.setData(resp.nonlevyCaseList);

				$P.renderAnsBodyList(resp.levyCaseList.length,'levy');
			    $P.renderAnsBodyList(resp.warningCaseList.length,'warning');
			    $P.renderAnsBodyList(resp.nonlevyCaseList.length,'nonlevy');

			    if(resp.levyCaseList.length > 0){
			    	ctrl.levy.setCurrent(cursor1);
			    	var current = ctrl.levy.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'levy');
			    }
				if(resp.warningCaseList.length > 0){
					ctrl.warning.setCurrent(cursor2);
					var current = ctrl.warning.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'warning');
			    }
				if(resp.nonlevyCaseList.length > 0){
					ctrl.nonlevy.setCurrent(cursor3);
					var current = ctrl.nonlevy.getCurrent("item");
			    	$P.clickAnsBodyList(current.index,'nonlevy');
				}
			}
		});
	}

	//적용
	$P.fnSave = (isBasicWords) => {

		var formName = "";
		var confirmMessage = "";

		if(isBasicWords){
			confirmMessage = "머리말/꼬리말 내용을 저장하시겠습니까?";
			formName = "frmEditAnsBasic";
		} else {
			confirmMessage = "본문내용을 저장하시겠습니까?"
			formName = "frmEditAnsBody";
		}


		if(!AppSupport.customValidate($P.$findn(formName).find("input, select, textarea"))) return;
		var info = (new FimsFormFields($P.selectorn(formName))).get();
		if(isBasicWords){
			info.saveData = "basic";
		} else {
			info.saveData = "body";
		}
		info.taskSeCd = $P.$findn("frmSearch").find("input[name='taskSeCd']:checked").val();

		dialog.alert({
			content : confirmMessage,
			init : function() {
				AppSupport.focusOK();
			},
			onOK: () => {

				ajax.get({
					url : ctrl.urls.update,
					data : info,
					success : (resp) => {
						if(resp.saved){
							$P.toast.show();
							AppSupport.sleep(1000).then(() => $P.refreshAnsWordsInfo());
						}
					}
				});
			}
		});
	}

	//답변대상 제외
	$P.fnRemove = () => {

		if(!AppSupport.customValidate($P.$findn("frmEditAnsBody").find("input, select, textarea"))) return;
		var info = (new FimsFormFields($P.selectorn("frmEditAnsBody"))).get();

		dialog.alert({
			content : "해당 미부과사유를 답변대상에서 제외하시겠습니까?",
			init : function() {
				AppSupport.focusOK();
			},
			onOK: () => {
				ajax.get({
					url : ctrl.urls.remove,
					data : info,
					success : (resp) => {
						if(resp.saved){
							$P.toast.show();
							AppSupport.sleep(1000).then(() => $P.refreshAnsWordsInfo());
						}
					}
				});
			}
		});
	}

	//미리보기 팝업 호출
	$P.fnOpenPreviewPop = () => {

		var result = fnMacroWordsReplace(
			$P.$findn("headerCn").val(),
			$P.$findn("footerCn").val(),
			$P.$findn("prcsRsltCn").val(),
			"${currentUserTelno}",
			"${currentUserName}"
		);

		let dialogName = "previewDialog";
		let dialogId = dialogName+"-"+uuid();

		dialog.open({
			id : dialogId,
			title : "답변 내용 미리보기",
			content : $P.findn("previewDialogTemplate").innerHTML,
			size : "lg",
			init : () => {
				$("#"+dialogId).attr("name", dialogName);
				$("#"+dialogId).attr("data-ref-doctx","${pageName}");
				let refDlgId = $P.refDlgId(dialogName);
				$("#"+refDlgId).find("[name='preview']").val(result);

				$("#"+refDlgId).find("[name='btnClose']").on("click", () => dialog.close(refDlgId));
			},
			onOk : () => {},
			onClose : () => {}
		});
	}

	/**************************************************************************
	* element.on
	**************************************************************************/
	$P.$findn("btnReset").on('click', () => $P.fnReset());

	//탭 버튼
    $P.$findn("btnAnsBasicTab").on('click', (event) => {

    	$P.$findn("wrapper").find(".area-answerbasic").show();
    	$P.$findn("wrapper").find(".area-answerbody").hide();

    	$P.currentDisplay = "ansBasic";

    	$P.$findn("macroTarget").attr("for","");
    });

    $P.$findn("btnLevyAnsBodyTab").on('click', (event) => {

    	$P.$findn("wrapper").find(".area-answerbasic").hide();
    	$P.$findn("wrapper").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-levy")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});

		$P.currentDisplay = "levyAnsBody";

		$P.$findn("wrapper").find(":radio[name='levyRadio']:checked").focus();

		$P.changeAnsBodyText();

		$P.$findn("macroTarget").attr("for","");
	});
    $P.$findn("btnWarningAnsBodyTab").on('click', (event) => {

    	$P.$findn("wrapper").find(".area-answerbasic").hide();
    	$P.$findn("wrapper").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-warning")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});

		$P.currentDisplay = "warningAnsBody";

		$P.$findn("wrapper").find(":radio[name='warningRadio']:checked").focus();

		$P.changeAnsBodyText();

		$P.$findn("macroTarget").attr("for","");
	});
    $P.$findn("btnNonlevyAnsBodyTab").on('click', (event) => {

    	$P.$findn("wrapper").find(".area-answerbasic").hide();
    	$P.$findn("wrapper").find(".area-answerbody").each(function(){
			if($(this).hasClass("area-answerbody-common") || $(this).hasClass("area-nonlevy")){
				$(this).show();
			} else {
				$(this).hide();
			}
		});

		$P.currentDisplay = "nonlevyAnsBody";

		$P.$findn("wrapper").find(":radio[name='nonlevyRadio']:checked").focus();

		$P.changeAnsBodyText();

		$P.$findn("macroTarget").attr("for","");
	});

	//업무처리 버튼
    $P.$findn("btnSaveAnsBasic").on("click", () => $P.fnSave(true));
    $P.$findn("btnSaveAnsBody").on("click", () => $P.fnSave(false));
    $P.$findn("btnRemove").on("click", () => $P.fnRemove());
    $P.$findn("btnOpenPreviewPop").on("click", () => $P.fnOpenPreviewPop());

    $($P.selfElement()).find("[name='headerCn'],[name='footerCn'],[name='prcsRsltCn']").on("focus", (event) => {
    	$P.$findn("macroTarget").attr("for", event.target.id);
    });

    $P.$findn("btnInsertMacro1").on("click", () => {
		var macroTarget = $P.$findn("macroTarget").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_SEQ);
    });
    $P.$findn("btnInsertMacro2").on("click", () => {
		var macroTarget = $P.$findn("macroTarget").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_TELNO);
    });
    $P.$findn("btnInsertMacro3").on("click", () => {
		var macroTarget = $P.$findn("macroTarget").attr("for");
		if(macroTarget == ""){ return; }
		fnMacroStringInsert(macroTarget, MACRO_STRING.MACRO_PIC_NM);
    });

	/**************************************************************************
	* 초기화
	**************************************************************************/
    var defaultBizValue = $("#layout-navbar input[name='taskSeCd']:checked").val();
    $P.$findn("frmSearch").find("input[name='taskSeCd'][value='" + defaultBizValue + "']").prop("checked",true);
	$P.fnResetAndChangeBiz(defaultBizValue);

	$P.$findn("frmSearch").find("input[name='taskSeCd']").each(function(i) {
		$(this).prop("disabled", "true");
	});
});


</script>