<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : PlanDetailForm.html
 * @desc    : 웹 수정 / 웹 등록 팝업 화면 Page
 *============================================================================
 * SISUN
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.02.04   sowon   최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1395" id="popupPlanDetail">
	<div class="panelStyle">
		<div class="panelTitle">
			<h2 th:text="${'기획전 ' + (mode == 'N' ? '등록' : '수정')}"></h2>
			<button type="button" class="close" onclick="uifnPopupClose('popupPlanDetail')"><i class="fa fa-times"></i></button>
		</div>
		
	<!-- 기획전 웹 수정 -->
		<div class="panelContent" th:if="${mode == 'U'}">
		<form th:object="${planInfo}" id="planUpdateForm" name="planUpdateForm" action="#" th:method="post">
			<input type="hidden" name="pImg" th:value="*{mainPimg}"/>
			<input type="hidden" name="mImg" th:value="*{mainMimg}"/>
			<input type="hidden" name="mode" th:value="${mode}"/>
			<input type="hidden" name="planSq" th:value="*{planSq}"/>
			<input type="hidden" name="cpnNm">

			<div class="cardArea" style="height: 700px;margin: -5px;">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%"/>
						<col style="width:40%;"/>
						<col style="width:10%;"/>
						<col style="width:35%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>사이트</th>
						<td>
							<select name="siteCd" th:field="*{siteCd}">
								<option value="">선택</option>
								<option th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>기획전구분<em class="required" title="필수"></em></th>
						<td>
							<select name="planGb" id="planGb" th:field="*{planGb}" onchange="fnChangePlanGb(this);">
								<option value="P">기획전</option>
								<option value="E">이벤트</option>
								<option value="C">출석체크</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>프론트 구분<em class="required" title="필수"></em></th>
						<td>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="P" th:text="PC웹"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="M" th:text="모바일웹"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb"  value="A" th:text="모바일앱"/>
							</label>
							
						</td>
						<th>전시순서</th>
						<td>
							<input type="text" name="dispOrd" class="w100 aR" th:value="*{dispOrd}"/>
						</td>
					</tr>
					<tr>
						<th>기획전명<em class="required" title="필수"></em></th>
						<td>
							<input type="text" name="planNm" id="planNm" th:field="*{planNm}"/>
						</td>
						<th>서브제목<em class="required" title="필수"></em></th>
						<td>
							<input type="text" name="dtlTitle1" id="dtlTitle1" th:value="*{dtlTitle1}"/>
						</td>
					</tr>
					<tr>
						<th>진행기간<em class="required" title="필수"></em></th>
						<td colspan="3">
							<input type="text" class="schDate w100" name="startSearchDate" maxlength="10" required="required" data-valid-name="노출기간" th:field="*{startSearchDate}"/>
							<select name="startSearchHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(dispStdt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="startSearchMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(dispStdt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
							~
							<input type="text" class="schDate w100" name="endSearchDate" maxlength="10" required="required" data-valid-name="노출기간" th:field="*{endSearchDate}"/>
							<select name="endSearchHour" required="required" data-valid-name="진행기간 종료시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(dispEddt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="endSearchMin" required="required" data-valid-name="진행기간 종료시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(dispEddt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
							<input type="hidden" name="dispStdt" id="dispStdt"/>
							<input type="hidden" name="dispEddt" id="dispEddt"/>
						</td>
						
					</tr>
					<tr>
						<th>코너명노출 여부<em class="required" title="필수"></em></th>
						<td>
							<select name="cornerNmDispYn" th:field="*{cornerNmDispYn}">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:selected="${oneData.cd} == 'Y'" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>노출여부<em class="required" title="필수"></em></th>
						<td>
							<select name="openYn" th:field="*{openYn}">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:selected="${oneData.cd} == 'Y'" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
					</tr>
					<tr>
						<th>사용고객등급구분</th>
						<td>
							<label class="chkBox" th:if="${usableCustGradeList}" th:each="oneData, status : ${usableCustGradeList}">
								<input type="checkbox" name="usableCustGradeArr" th:value="${oneData.cd}" th:text="${oneData.cdNm}"/>
							</label>
							<label class="chkBox">
								<input type="checkbox" name="usableCustGradeArr" value="G110_60" th:text="비회원"/>
							</label>
						</td>
						<th>사용가능고객구분<em class="required" title="필수"></em></th>
						<td>
							<label class="chkBox" th:if="${usableCustGbList}" th:each="oneData, status : ${usableCustGbList}">
								<input type="checkbox" name="usableCustGbArr" th:value="${oneData.cd}" th:text="${oneData.cdNm}"/>
							</label>
  						</td>
					</tr>
					<tr>
						<th>카테고리</th>
						<td>
							<label class="chkBox" th:if="${cateList}" th:each="oneData, status : ${cateList}">
								<input type="checkbox" name="cateList" th:value="${oneData.cateNo}" th:text="${oneData.cateNm}"/>
							</label>
						</td>
					</tr>
					<tr>
						<th>제휴채널</th>
						<td colspan="1">
							<!-- 수정시 프로모션명 입력 : before -->
							<div class="padding10"	style="display: inline-block; width: 100%;">
								<!--<span>공급업체 설정</span>-->
								<div class="padding10 inner-tb-solid">
									<span class="buttonSpan">
										<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddAf">제휴채널 추가</button>
										<button type="button" class="btn btnRight btn-success btn-lg"id="btnDeleteAf">선택삭제</button>
									</span> <br />
									<div id="gridAfPlanList" style="width: 100%; height: 200px;" class="ag-theme-balham"></div>
								</div>
							</div>
  						</td>
						<th style="display: none;" id="attendTh">혜택적용</th>
						<td colspan="1" style="display: none;" id="attendTd">
							<div class="padding10"	style="display: inline-block; width: 100%;">
								<div class="padding10 inner-tb-solid">
									<span class="buttonSpan">
										<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddRow">혜택 추가</button>
										<button type="button" class="btn btnRight btn-success btn-lg"id="btnDeleteAt">선택삭제</button>
									</span> <br />
									<div id="gridAttendPlanList" style="width: 100%; height: 200px;" class="ag-theme-balham"></div>
								</div>
							</div>
  						</td>
					</tr>
					<tr>
						<th>목록 이미지<i id="pMimgStar"></i><br/>[삭제여부<label class="chkBox"><input type="checkbox" name="orgMainPimgDelYn" value="Y"/></label>]</th>
						<td>
							<div th:if=*{mainPimg} id="mainPimgView" style="float:left;">
								<img id="PreMainPimgUrl" th:src="${@environment.getProperty('upload.image.view')} + *{mainPimg}" style="max-width:470px;"/>
							</div>
						</td>
						<td colspan="4">
							<div class="uFile w400">
								<input id="registerMainPimg" name="registerMainPimg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerMainPimg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="orgMainPimg" id="orgMainPimg" th:value="*{mainPimg}"/>
								<input type="hidden" name="mainPimg" id="mainPimg"/>
							</div>
						</td>
					</tr>
				<!-- 	<tr>
						<th>모바일 메인 이미지<i id="mMimgStar"></i><br/>[삭제여부<label class="chkBox"><input type="checkbox" name="orgMainMimgDelYn" value="Y"/></label>]</th>
						<td>
							<div th:if=*{mainMimg} id="imgFileView" style="float:left;">
								<img id="PreMainMimgUrl" th:src="${@environment.getProperty('upload.image.view')} + *{mainMimg}" style="max-width:470px;"/>
							</div>
						</td>
						<td colspan="4">
							<div class="uFile w400">
								<input id="registerMainMimg" name="registerMainMimg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerMainMimg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="orgMainMimg" id="orgMainMimg" th:value="*{mainMimg}"/>
								<input type="hidden" name="mainMimg" id="mainMimg"/>
							</div>
						</td>
					</tr> -->
					<tr id="pollTr" style="display: none;">
						<th>투표일련번호</th>
						<td colspan="3">
							<input type="text" class="w100 aR" name="pollSq" th:field="*{pollSq}"/>
						</td>
					</tr>
					<tr>
						<th class="custJoinTr" colspan="1">신규회원여부<em class="required" title="필수"></em></th>
						<td>
							<select name="newCustYn" id="newCustYn" onchange="newCustYnChange(this)" required="required" data-valid-name="신규회원여부" th:field="*{newCustYn}">
								<option value="Y" selected="selected">Y</option>
								<option value="N" >N</option>
							</select>
						</td>
						<th>댓글여부</th>
						<td>
							<select name="replyYn" th:field="*{replyYn}">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="custJoinDateTr">신규회원기간시작일시<em class="required" title="필수"></em></th>
						<td class="custJoinDateTr">
							<input type="hidden" name="custJoinStdt" id="custJoinStdt" data-valid-name="신규회원기간시작일시" >
							<input type="text" class="schDate w100" name="custJoinStDay" id="custJoinStDay" maxlength="10" />
							<select name="startJoinHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(custJoinStdt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="startJoinMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(custJoinStdt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
						<th class="custJoinDateTr">신규회원기간종료일시<em class="required" title="필수"></em></th>
						<td class="custJoinDateTr">
							<input type="hidden" id="custJoinEddt" name="custJoinEddt" data-valid-name="신규회원기간종료일시" >
							<input type="text" class="schDate w100" name="custJoinEdDay" id="custJoinEdDay" maxlength="10" />
							<select name="endJoinHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(custJoinEddt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="endJoinMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(custJoinEddt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
						</td>
					</tr>
					<tr style="display:none" id="append1">
						<th>댓글제목</th>
						<td>
							<input type="text" name="replyTitle1" id="replyTitle1" maxlength="50" required="required" th:field="*{replyTitle1}"/>
						</td>
						
						<th>댓글서브제목</th>
						<td>
							<input type="text" name="replyTitle2" id="replyTitle2" maxlength="50" required="required" th:field="*{replyTitle2}"/>
						</td>
					
					</tr>
					<tr style="display:none" id="append2">
						<th>댓글위치</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="replyLoc" value="U" />상품리스트 상단</label>
							<label class="rdoBtn"><input type="radio" name="replyLoc" value="D"/>상품리스트 하단</label>
						</td>
					</tr>
					<tr style="display:none" id="append3">
						<th>댓글이미지<br/>[삭제여부<label class="chkBox"><input type="checkbox" name="orgReplyImgDelYn" value="Y"/></label>]</th>
						<td>
							<div th:if=*{replyImg} id="replyImgView" style="float:left;">
								<img id="replyImgUrl" th:src="${@environment.getProperty('upload.image.view')} + *{replyImg}" style="max-width:720px;"/>
							</div>
						</td>
						<td colspan="5">
							<div class="uFile w400">
								<input id="registerReplyImg" name="registerReplyImg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerReplyImg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="orgReplyImg" id="orgReplyImg" th:value="*{replyImg}"/>
								<input type="hidden" name="replyImg" id="replyImg" th:value="*{replyImg}"/>
							</div>
						</td>
					
					</tr>
				</tbody>				
				</table>
				
				<div class="panelStyle" style="margin: unset;">
						<!-- TITLE -->
						<div class="panelTitle">
							<h2>기획전 컨텐츠 등록</h2>
							<span class="panelControl"> <i
								class="fa inner-fa-chevron-up"></i> <!-- 열림/닫힘 화살표 -->
							</span>
						</div>
						<!-- //TITLE -->
						<div class="inner-panelContent">
							<div class="panelContent">
								<table class="frmStyle">
									<colgroup>
										<col width="10%" />
										<col width="90%" />
									</colgroup>
									<tr>
										<th> &nbsp;기획전 &nbsp; 컨텐츠&nbsp;</th>
										<td>
											<!-- 수정시 프로모션명 입력 : before -->
											<div class="padding10"
												style="display: inline-block; width: 49%;">
												<!--<span>공급업체 설정</span>-->
												<div class="padding10 inner-tb-solid">
													<span class="buttonSpan">
														<button type="button"
															class="btn btnRight btn-success btn-lg"
															onclick="fnPlanTemplatePopup();">기획전 템플릿</button>
													</span> <br />
												</div>
											</div>
										</td>
									</tr>
								</table>
							</div>
						</div>
					</div>
				<div class="panelStyle" style="margin: unset;">
						<!-- TITLE -->
						<div class="panelTitle">
							<h2>브랜드 등록</h2>
							<span class="panelControl"> <i
								class="fa inner-fa-chevron-up"></i> <!-- 열림/닫힘 화살표 -->
							</span>
						</div>
						<!-- //TITLE -->
						<div class="panelContent">
							<table class="frmStyle">
								<colgroup>
									<col width="10%" />
									<col width="90%" />
								</colgroup>
								<tr>
									<th>브랜드</th>
									<td>
										<!-- 수정시 프로모션명 입력 : before -->
										<!-- <div class="padding10"
											style="display: inline-block; width: 49%;">
											<span>공급업체 설정</span>
											<div class="padding10 inner-tb-solid">
												<span class="buttonSpan">
													<button type="button"
														class="btn btnRight btn-success btn-lg"
														id="btnAddCate">카테고리 추가</button>
													<button type="button"
														class="btn btnRight btn-success btn-lg"
														id="btnDeleteCate">선택삭제</button>
												</span> <br />
												<div id="gridFGCateList"
													style="width: 100%; height: 200px;"
													class="ag-theme-balham"></div>
											</div>
										</div> -->
										<div class="padding10"
											style="display: inline-block; width: 49%;">
											<!--<span>브랜드 설정</span>-->
											<div class="padding10 inner-tb-solid">
												<span class="buttonSpan">
													<button type="button"
														class="btn btnRight btn-success btn-lg" id="btnAddBrand">브랜드
														추가</button>
													<button type="button"
														class="btn btnRight btn-success btn-lg"
														id="btnDeleteBrand">선택삭제</button>
												</span> <br />
												<div id="gridFGBrandList"
													style="width: 100%; height: 200px;"
													class="ag-theme-balham"></div>
											</div>
										</div>
									</td>
								</tr>
							</table>
						</div>
					</div>
			</div>
			<div style='margin: 13px;'>
			<ul class="panelBar">
				<li class="right" th:if="${mode == 'U'}">
					<button type="button" class="btn btn-success btn-lg" onclick="fnPlanSave('#planUpdateForm');">저장</button>
				</li>
			</ul>
			</div>
		</form>
	</div>
		
	
		<!-- 기획전 웹 등록 -->
		<div class="panelContent" th:if="${mode == 'N'}">
			<form id="planRegisterForm" name="planRegisterForm" th:method="post">
			<input type="hidden" name="mode" th:value="${mode}"/>
			<div>
				<table class="frmStyle">
					<colgroup>
						<col style="width:12.5%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>기존 기획전</th>
						<td>
							<input type="text" class="w100" name="searchTxt" id="searchTxt" maxlength="20" readonly="readonly"/>
							<input type="hidden" class="w100" name="planSq_Hideen" id="planSq_Hideen" maxlength="20"/>
							<button type="button" class="btn icn" id="btnPopupSearchPlan"><i class="fa fa-search"></i></button>
							<button type="button" class="btn btn-primary btn-lg" onclick="fnPlanCopyPopup();">기획전 복사</button>
						</td>
					</tr>
				</table>
			</div>
			<div class="cardArea">
				<table class="frmStyle">
					<colgroup>
						<col style="width:10%"/>
						<col style="width:40%;"/>
						<col style="width:10%;"/>
						<col style="width:35%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>사이트<i class="star"></i></th>
						<td>
							<select name="siteCd" required="required" data-valid-name="사이트">
								<option th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>기획전구분<em class="required" title="필수"></em></th>
						<td>
							<select name="planGb" required="required" data-valid-name="기획전구분" onchange="fnChangePlanGb(this);">
								<option value="P">기획전</option>
								<option value="E">이벤트</option>
								<option value="S">총알배송</option>
								<option value="C">출석체크</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>프론트 구분<em class="required" title="필수"></em></th>
						<td>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="P" th:text="PC웹" checked="checked"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb"  value="M" th:text="모바일웹" checked="checked"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="A" th:text="모바일앱" checked="checked"/>
							</label>
						</td>
						<th>전시순서</th>
						<td>
							<input type="text" class="w100 aR" name="dispOrd"/>
						</td>
					</tr>
					<tr>
						<th>기획전명<em class="required" title="필수"></em></th>
						<td>
							<input type="text" name="planNm" id="planNm" maxlength="50" required="required" />
						</td>
						<th>서브제목</th>
						<td>
							<input type="text" name="dtlTitle1" id="dtlTitle1" data-valid-name="서브제목"/>
						</td>
					</tr>
					<tr>
						<th>진행기간<em class="required" title="필수"></em></th>
						<td colspan="3">
							<input type="text" class="schDate w100" id="viewStartDtNew" name="startSearchDate" maxlength="10" required="required" data-valid-name="노출기간" />
							<select name="startSearchHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option  th:value="${#numbers.formatInteger(num,2)}" th:text="|${#numbers.formatInteger(num,2)}시|" >시간</option>
								</th:block>
							</select>
							<select name="startSearchMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option  th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" >분</option>
								</th:block>
							</select>
							~
							<input type="text" class="schDate w100" id="viewEndDtNew" name="endSearchDate" maxlength="10" required="required" data-valid-name="노출기간"/>
							<select name="endSearchHour" required="required" data-valid-name="진행기간 종료시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="${#numbers.formatInteger(num,2)}==23 ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="endSearchMin" required="required" data-valid-name="진행기간 종료시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="${#numbers.formatInteger(num,2)}==59 ? 'true'">분</option>
								</th:block>
							</select>
							<input type="hidden" name="dispStdt" id="dispStdt"/>
							<input type="hidden" name="dispEddt" id="dispEddt"/>
						</td>
						
					</tr>
					<tr>
						<th>코너명노출 여부<em class="required" title="필수"></em></th>
						<td>
							<select name="cornerNmDispYn" required="required" data-valid-name="코너명노출 여부">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:selected="${oneData.cd} == 'Y'" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>노출여부<em class="required" title="필수"></em></th>
						<td colspan="3">
							<select name="openYn" required="required" data-valid-name="오픈여부">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:selected="${oneData.cd} == 'N'" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						
					</tr>
					<tr>
						<th>사용고객등급구분</th>
						<td>
							<label class="chkBox" th:if="${usableCustGradeList}" th:each="oneData, status : ${usableCustGradeList}">
								<input type="checkbox" name="usableCustGradeArr" th:value="${oneData.cd}" th:text="${oneData.cdNm}" checked="checked"/>
							</label>
							<label class="chkBox">
								<input type="checkbox" name="usableCustGradeArr" value="G110_60" th:text="비회원" checked="checked"/>
							</label>
						</td>
						<th>사용가능고객구분<em class="required" title="필수"></em></th>
						<td>
							<label class="chkBox" th:if="${usableCustGbList}" th:each="oneData, status : ${usableCustGbList}">
								<input type="checkbox" name="usableCustGbArr" th:value="${oneData.cd}" th:text="${oneData.cdNm}" checked="checked"/>
							</label>
  						</td>
					</tr>
					<tr>
						<th>카테고리</th>
						<td>
							<label class="chkBox" th:if="${cateList}" th:each="oneData, status : ${cateList}">
								<input type="checkbox" name="cateList" th:value="${oneData.cateNo}" th:text="${oneData.cateNm}"/>
							</label>
						</td>
					</tr>
					<tr>
						<th>제휴채널</th>
						<td colspan="1">
							<!-- 수정시 프로모션명 입력 : before -->
							<div class="padding10"	style="display: inline-block; width: 100%;">
								<!--<span>공급업체 설정</span>-->
								<div class="padding10 inner-tb-solid">
									<span class="buttonSpan">
										<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddAf">제휴채널 추가</button>
										<button type="button" class="btn btnRight btn-success btn-lg"id="btnDeleteAf">선택삭제</button>
									</span> <br />
									<div id="gridAfPlanList" style="width: 100%; height: 200px;" class="ag-theme-balham"></div>
								</div>
							</div>
  						</td>
  						<th id="attendTh" style="display: none;">혜택적용</th>
						<td colspan="1" id="attendTd" style="display: none;">
							<div class="padding10"	style="display: inline-block; width: 100%;">
								<div class="padding10 inner-tb-solid">
									<span class="buttonSpan">
										<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddRow">혜택 추가</button>
										<button type="button" class="btn btnRight btn-success btn-lg"id="btnDeleteAt">선택삭제</button>
									</span> <br />
									<div id="gridAttendPlanList" style="width: 100%; height: 200px;" class="ag-theme-balham"></div>
								</div>
							</div>
  						</td>
					</tr>
					<tr>
						<th>목록 이미지<i id="pMimgStar"></i></th>
						<td colspan="5">
							<div class="uFile w400">
								<input id="registerMainPimg" name="registerMainPimg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerMainPimg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="mainPimg" id="mainPimg" value=""/>
							</div>
						</td>
					</tr>
					<!-- <tr>
						<th>모바일 메인 이미지<i id="mMimgStar"></i></th>
						<td colspan="5">
							<div class="uFile w400">
								<input id="registerMainMimg" name="registerMainMimg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerMainMimg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="mainMimg" id="mainMimg" value=""/>
							</div>
						</td>
					</tr> -->
					<tr id="pollTr" style="display: none;">
						<th>투표일련번호</th>
						<td>
							<input type="text" class="w100 aR" name="pollSq"/>
						</td>
					</tr>
					<tr>
						<th class="custJoinTr" colspan="1">신규회원여부<em class="required" title="필수"></em></th>
						<td>
							<select name="newCustYn" id="newCustYn" onchange="newCustYnChange(this)" required="required" data-valid-name="신규회원여부">
								<option value="Y" >Y</option>
								<option value="N" selected="selected">N</option>
							</select>
						</td>
						<th>댓글여부<em class="required" title="필수"></em></th>
						<td>
							<select name="replyYn">
								<option th:if="${useYnList}" th:each="oneData, status : ${useYnList}" th:value="${oneData.cd}" th:selected="${oneData.cd} == 'N'" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="custJoinDateTr">신규회원기간시작일시<em class="required" title="필수"></em></th>
						<td class="custJoinDateTr">
							<input type="hidden" name="custJoinStdt" id="custJoinStdt" data-valid-name="신규회원기간시작일시">
							<input type="text" class="schDate w100" name="custJoinStDay" id="custJoinStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
							<select name="startJoinHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(dispStdt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="startJoinMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(dispStdt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
						<th class="custJoinDateTr">신규회원기간종료일시<em class="required" title="필수"></em></th>
						<td class="custJoinDateTr">
							<input type="hidden" id="custJoinEddt" name="custJoinEddt" data-valid-name="신규회원기간종료일시">
							<input type="text" class="schDate w100" name="custJoinEdDay" id="custJoinEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
							<select name="endJoinHour" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num, index  : ${#numbers.sequence(0,23)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}시|" th:selected="*{#strings.substring(dispStdt, 11, 13)} == ${#strings.toString(num)} ? 'true'">시간</option>
								</th:block>
							</select>
							<select name="endJoinMin" required="required" data-valid-name="진행기간 시작시간">
								<th:block th:each="num: ${#numbers.sequence(0,59)}">
								<option th:value="${#numbers.formatInteger(num,2)}"  th:text="|${#numbers.formatInteger(num,2)}분|" th:selected="*{#strings.substring(dispStdt, 14, 16)} == ${#strings.toString(num)} ? 'true'">분</option>
								</th:block>
							</select>
						</td>
					</tr>
					<tr style="display:none" id="append1">
						<th>댓글제목<em class="required" title="필수"></em></th>
						<td>
							<input type="text" name="replyTitle1" id="replyTitle1" maxlength="50" required="required"/>
						</td>
						
						<th>댓글서브제목</th>
						<td>
							<input type="text" name="replyTitle2" id="replyTitle3" maxlength="50" required="required"/>
						</td>
					
					</tr>
					<tr style="display:none" id="append2">
						<th>댓글위치</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="replyLoc" value="U"/>상품리스트 상단</label>
							<label class="rdoBtn"><input type="radio" name="replyLoc" value="D"/>상품리스트 하단</label>
						</td>
					</tr>
					<tr style="display:none" id="append3">
						<th>댓글이미지</th>
						<td colspan="5">
							<div class="uFile w400">
								<input id="registerReplyImg" name="registerReplyImg" type="file" accept="image/*" class="uFileInput w400"/>
								<label for="registerReplyImg" class="uFileLabel w400">파일선택</label>
								<input type="hidden" name="replyImg" id="replyImg" value=""/>
							</div>
						</td>
					
					</tr>
				</tbody>
				<tbody>
				</table>
					<div class="panelStyle" style="margin: unset;">
						<!-- TITLE -->
						<div class="panelTitle">
							<h2>브랜드 등록</h2>
							<span class="panelControl"> <i
								class="fa inner-fa-chevron-up"></i> <!-- 열림/닫힘 화살표 -->
							</span>
						</div>
						<!-- //TITLE -->
						<div class="inner-panelContent">
							<div class="panelContent">
								<table class="frmStyle">
									<colgroup>
										<col width="10%" />
										<col width="90%" />
									</colgroup>
									<tr>
										<th>브랜드</th>
										<td>
											<!-- 수정시 프로모션명 입력 : before -->
										<!-- 	<div class="padding10"
												style="display: inline-block; width: 49%;">
												<span>공급업체 설정</span>
												<div class="padding10 inner-tb-solid">
													<span class="buttonSpan">
														<button type="button"
															class="btn btnRight btn-success btn-lg"
															id="btnAddCate">카테고리 추가</button>
														<button type="button"
															class="btn btnRight btn-success btn-lg"
															id="btnDeleteCate">선택삭제</button>
													</span> <br />
													<div id="gridFGCateList"
														style="width: 100%; height: 200px;"
														class="ag-theme-balham"></div>
												</div>
											</div> -->
											<div class="padding10"
												style="display: inline-block; width: 49%;">
												<!--<span>브랜드 설정</span>-->
												<div class="padding10 inner-tb-solid">
													<span class="buttonSpan">
														<button type="button"
															class="btn btnRight btn-success btn-lg" id="btnAddBrand">브랜드
															추가</button>
														<button type="button"
															class="btn btnRight btn-success btn-lg"
															id="btnDeleteBrand">선택삭제</button>
													</span> <br />
													<!-- 브랜드 선택 팝업(단수 선택 팝업... 복수를 새로 만들어야하는지 ? 아니면 변수처리해야하는지 ? -->
													<div id="gridFGBrandList"
														style="width: 100%; height: 200px;"
														class="ag-theme-balham"></div>
												</div>
											</div>
										</td>
									</tr>
								</table>
							</div>
						</div>
					</div>
				</div>
				<ul class="panelBar">
					<li class="right" th:if="${mode == 'N'}">
						<button type="button" class="btn btn-info btn-lg" onclick="fnPlanSave('#planRegisterForm');">저장</button>
					</li>
				</ul>
			</form>
		</div>
	</div>
</div>

<script type="text/javascript" src="/ux/plugins/summernote/summernote.js?v=2020103001"></script>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.summernote.js?v=2021053101"></script>
<script th:inline="javascript">
/*<![CDATA[*/

	var mode = [[${mode}]];
	var planInfo = [[${planInfo}]];
	var fsrcPc = [[${fsrcPc}]];
	var fsrcMobile = [[${fsrcMobile}]];
	var planBrandList = [[${planBrandList}]];
	var planCateList = [[${planCateList}]];
	var custGbList = [[${gbList}]];
	var custGradeList =	[[${gradeList}]]; 
	var afChannelList = [[${afChannelList}]]; 
	var benefitList = [[${benefitList}]];
	var snOptions;

	let useYnList = { "Y":"Yes", "N":"No" };
	let channelName = {"G053_01":"직접","G053_02":"네이버","G053_03":"다음","G053_04":"크리데오","G053_05":"카카오","G053_06":"인스타그램","G053_07":"페이스북","G053_08":"구글"
			          ,"G053_09":"바이럴","G053_10":"모비온","G053_11":"YES24","G053_12":"한세드림"}
	
	let columnAfDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-right', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "제휴채널코드", field: "afLinkCd", width: 100, cellClass: 'text-center'},
		{
			headerName: "제휴채널명", field: "afLinkNm", width: 180,
			cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{headerName: "상위제휴채널", field: "afChannel", width: 120, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(channelName) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(channelName, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(channelName, params.newValue); }	
		}

	];
	
	// 제휴채널 그리드 설정
	var gridOptionsAfList = gagaAgGrid.getGridOptions(columnAfDefs);
	gridOptionsAfList.rowSelection = "multiple";
	gridOptionsAfList.suppressRowClickSelection = true;
	
    
    
	// 카테고리 전시 여부
	var fnCataCheck = function(is, formId) {
		if (is.checked) {
			$(formId + ' input[name=cateDispYn]').val('Y');
			// 추후 카테고리 표시
		} else {
			$(formId + ' input[name=cateDispYn]').val('N');
		}
	}

	// 상품제한여부
	var fnGoodsCheck = function(is, formId) {
		if (is.checked) {
			$(formId + ' input[name=goodsLimitYn]').val('Y');
			$(formId + ' input[name=goodsLimitQty]').show();
			$(formId + ' input[name=goodsLimitQty]').focus();
			// 추후 카테고리 표시
		} else {
			$(formId + ' input[name=goodsLimitYn]').val('N');
			$(formId + ' input[name=goodsLimitQty]').hide();
		}
	}
	
	//템플릿 유형 설정
	var fnPlanTemplatePopup = function () {
		var actionUrl = "/marketing/planning/detail/template/form?mode=C&planSq=" + planInfo.planSq;
		cfnOpenModalPopup(actionUrl,'popupPlanTemplate');
	}
	
	// 기존 기획전 조회 선택시
	$('#btnPopupSearchPlan').on('click', function(result) {
		cfnOpenPlanPopup('popupPlan');
		
	});
	
	var popupPlan = function (result) {
		$("#planSq_Hideen").val(result[0].planSq);
		$("#searchTxt").val("[" + result[0].planSq + "] " +result[0].planNm);
		
	}

	// 댓글여부에 입력창 추가
	/* $('select[name=replyYn]').on('change', function() {
		if($('select[name=replyYn]').val() == 'Y'){
			$("#append1").removeAttr('style');
			$("#append2").removeAttr('style');
			$("#append3").removeAttr('style');
		}else{
			$("#append1").css('display','none');
			$("#append2").css('display','none');
			$("#append3").css('display','none');
		}
	}) */
	
	// 불러오기 댓글
	if($('#planUpdateForm select[name=replyYn]').val()=='Y'){
			/* $("#append1").removeAttr('style');
			$("#append2").removeAttr('style');
			$("#append3").removeAttr('style'); */
			
			var frontGbData = planInfo.frontGb.split('|');
			var chkboxCnt = $('#planUpdateForm input:checkbox[name=frontGb]').length;
			for(let i=0; i<chkboxCnt; i++){
				for(let j=0; j<frontGbData.length; j++){
					var data = frontGbData[j];
					if($('#planUpdateForm input:checkbox[name=frontGb]').eq(i).val() == data){
						$('#planUpdateForm input:checkbox[name=frontGb]').eq(i).prop('checked', true);
						$("#planUpdateForm input:checkbox[name=frontGb]").eq(i).parent().addClass('checked');
					}
				}
			}
			
			
			if(planInfo.replyLoc == "D"){
				$('#planUpdateForm input:radio[name=replyLoc]:radio[value="D"]').prop('checked', true);
			}else {
				$('#planUpdateForm input:radio[name=replyLoc]:radio[value="U"]').prop('checked', true);
			}
			
			if(custGbList.length > 0){
				var chkboxCnt = $('#planUpdateForm input:checkbox[name=usableCustGbArr]').length;
				var dataCnt = custGbList.length;
				for(let i=0; i<chkboxCnt; i++){
					for(let j=0; j<dataCnt; j++){
						var data = custGbList[j].custGb;
						if($('#planUpdateForm input:checkbox[name=usableCustGbArr]').eq(i).val() == data){
							$('#planUpdateForm input:checkbox[name=usableCustGbArr]').eq(i).prop('checked', true);
							$("#planUpdateForm input:checkbox[name=usableCustGbArr]").eq(i).parent().addClass('checked');
						}
					}
				}
			}
			
			if(custGradeList.length > 0){
				var chkboxCnt = $('#planUpdateForm input:checkbox[name=usableCustGradeArr]').length;
				var dataCnt = custGradeList.length;
				for(let i=0; i<chkboxCnt; i++){
					for(let j=0; j<dataCnt; j++){
						var data = custGradeList[j].custGrade;
						if($('#planUpdateForm input:checkbox[name=usableCustGradeArr]').eq(i).val() == data){
							$('#planUpdateForm input:checkbox[name=usableCustGradeArr]').eq(i).prop('checked', true);
							$("#planUpdateForm input:checkbox[name=usableCustGradeArr]").eq(i).parent().addClass('checked');
						}
					}
				}
			}
	}else if($('#planUpdateForm select[name=replyYn]').val()=='N'){
	/* 	$("#append1").css('display','none');
		$("#append2").css('display','none');
		$("#append3").css('display','none'); */
		
		var frontGbData = planInfo.frontGb.split('|');
		var chkboxCnt = $('#planUpdateForm input:checkbox[name=frontGb]').length;
		for(let i=0; i<chkboxCnt; i++){
			for(let j=0; j<frontGbData.length; j++){
				var data = frontGbData[j];
				if($('#planUpdateForm input:checkbox[name=frontGb]').eq(i).val() == data){
					$('#planUpdateForm input:checkbox[name=frontGb]').eq(i).prop('checked', true);
					$("#planUpdateForm input:checkbox[name=frontGb]").eq(i).parent().addClass('checked');
				}
			}
		}
		
		if(planInfo.newCustYn == 'Y'){
			$('.custJoinDateTr').css('display' , '');
			$('#custJoinStdt').attr('required' , true);
			$('#custJoinEddt').attr('required' , true);
		} else {
			$('.custJoinDateTr').css('display' , 'none');
			$('#custJoinStdt').attr('required' , false);
			$('#custJoinEddt').attr('required' , false);
		}
		
		if(planInfo.replyLoc == "D"){
			$('#planUpdateForm input:radio[name=replyLoc]:radio[value="D"]').prop('checked', true);
		}else {
			$('#planUpdateForm input:radio[name=replyLoc]:radio[value="U"]').prop('checked', true);
		}
		
		if(custGbList.length > 0){
			var chkboxCnt = $('#planUpdateForm input:checkbox[name=usableCustGbArr]').length;
			var dataCnt = custGbList.length;
			for(let i=0; i<chkboxCnt; i++){
				for(let j=0; j<dataCnt; j++){
					var data = custGbList[j].custGb;
					if($('#planUpdateForm input:checkbox[name=usableCustGbArr]').eq(i).val() == data){
						$('#planUpdateForm input:checkbox[name=usableCustGbArr]').eq(i).prop('checked', true);
						$("#planUpdateForm input:checkbox[name=usableCustGbArr]").eq(i).parent().addClass('checked');
					}
				}
			}
		}
		
		if(custGradeList.length > 0){
			var chkboxCnt = $('#planUpdateForm input:checkbox[name=usableCustGradeArr]').length;
			var dataCnt = custGradeList.length;
			for(let i=0; i<chkboxCnt; i++){
				for(let j=0; j<dataCnt; j++){
					var data = custGradeList[j].custGrade;
					if($('#planUpdateForm input:checkbox[name=usableCustGradeArr]').eq(i).val() == data){
						$('#planUpdateForm input:checkbox[name=usableCustGradeArr]').eq(i).prop('checked', true);
						$("#planUpdateForm input:checkbox[name=usableCustGradeArr]").eq(i).parent().addClass('checked');
					}
				}
			}
		}
	}/* else{
		$("#append1").css('display','none');
		$("#append2").css('display','none');
		$("#append3").css('display','none');
	} */
	

	// 기획전 복사
	var fnPlanCopyPopup = function() {
		var planSq = $("#planSq_Hideen").val(); 

		if (gagajf.isNull(planSq)) {
			mcxDialog.alert('복사할 기획전을 선택하세요.');
			return;
		}

		mcxDialog.confirm('선택 된 기획전을 복사 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var actionUrl = '/marketing/planning/copy';
				var data = {copyPlanSq : planSq};
				var jsonData = JSON.stringify(data);

				gagajf.ajaxJsonSubmit(actionUrl, jsonData, fnCopyCallback);
			}
		});
	}

	// 기획전 복사 callback
	var fnCopyCallback = function(result) {
		uifnPopupClose('popupPlanDetail');
		fnPlanListSearch();

		var actionUrl = "/marketing/planning/detail/form?mode=U&planSq=" + result.planSq;
		cfnOpenModalPopup(actionUrl,'popupPlan');
	}

	 var fnPlanSave = function(formId) {
		var attendData = gagaAgGrid.getAllRowData(gridOptionsAttendList);
		if ($('#planRegisterForm select[name=planGb]').val() == "C" || $('#planUpdateForm select[name=planGb]').val() == "C" ) {
			var arr = []; 
			$.each(attendData, function(idx, item) {
				arr[idx] = item.basDays;
			});
			
			var dupYn = false;
			for(let i = 0; i < arr.length; i++) {
			  const currElem = arr[i];
			  for(let j = i+1; j < arr.length; j++) {
				if (currElem != "" && arr[j] != "") {
					if(currElem === arr[j]) {
				      dupYn = true;
				      break;
				    }
				}
			    
			  }
			}
			
			if (dupYn == true) {
				mcxDialog.alert('혜택적용 일수가 동일합니다.');
				return;
			}
			
			for(let i = 0; i < attendData.length; i++) {

				if (attendData[i].benefitGb == 'A') {
					if (attendData[i].basDays == "") {
						mcxDialog.alert('혜택(포인트/혜택) 적용 일수를 입력하세요.');
						return false;
					}
					else if (attendData[i].cpnId == "") {
						mcxDialog.alert('혜택(포인트/혜택) 적용 쿠폰ID를 입력하세요.');
						return false;
					}
					else if (attendData[i].pntAmt == "") {
						mcxDialog.alert('혜택(포인트/혜택) 적용 포인트를 입력하세요.');
						return false;
					}else if (attendData[i].pntUsableDay == "") {
						mcxDialog.alert('혜택(포인트/혜택) 유효기간 일수를 입력하세요.');
						return false;
					}else if(attendData[i].cpnYn == "N"){
						mcxDialog.alert('혜택(포인트/혜택) 유효한 쿠폰ID를 입력하세요.');
						return false;
					}
				}
				if (attendData[i].benefitGb == 'P') {
					if (attendData[i].basDays == "") {
						mcxDialog.alert('혜택(포인트) 적용 일수를 입력하세요.');
						return false;
					}
					else if (attendData[i].pntAmt == "") {
						mcxDialog.alert('혜택(포인트) 적용 포인트를 입력하세요.');
						return false;
					}else if (attendData[i].pntUsableDay == "") {
						mcxDialog.alert('혜택(포인트) 유효기간 일수를 입력하세요.');
						return false;
					}
				}
				if (attendData[i].benefitGb == 'C') {
					if (attendData[i].basDays == "") {
						mcxDialog.alert('혜택(쿠폰) 적용 일수를 입력하세요.');
						return false;
					}
					else if (attendData[i].cpnId == "") {
						mcxDialog.alert('혜택(쿠폰) 적용 쿠폰ID를 입력하세요.');
						return false;
					}else if(attendData[i].cpnYn == "N"){
						mcxDialog.alert('혜택(쿠폰) 유효한 쿠폰ID를 입력하세요.');
						return false;
					}
				}
			}
		}
			
		
		// 날짜 유효성 체크
		var stDate = $(formId + ' input[name=startSearchDate]').val().replaceAll("-", "");
		var edDate = $(formId + ' input[name=endSearchDate]').val().replaceAll("-", "");
		var stDate2 = $(formId + ' input[name=custJoinStDay]').val().replaceAll("-", "");
		var edDate2 = $(formId + ' input[name=custJoinEdDay]').val().replaceAll("-", "");
		var toDate = _today.replaceAll("-", "");

		if (Number(stDate) > Number(edDate)) {
			mcxDialog.alert('종료일자는 시작일자 보다 클 수 없습니다.');
			return;
		}

		if (Number(stDate) < Number(toDate) && mode == 'N') {
			mcxDialog.alert('시작일자는 오늘포함 이후로 등록해주세요.');
			return;
		}

		if (Number(edDate) < Number(toDate) && mode == 'N') {
			mcxDialog.alert('종료일자는 오늘포함 이후로 등록해주세요.');
			return;
		}
		
		if (newCustYn == "Y") {
			if (Number(stDate2) > Number(edDate2)) {
				mcxDialog.alert('신규회원 종료일자는 시작일자 보다 클 수 없습니다.');
				return;
			}
			if (Number(edDate2) < Number(toDate) && mode == 'N') {
				mcxDialog.alert('신규회원 종료일자는 오늘포함 이후로 등록해주세요.');
				return;
			}
		}

		
		
		stDate = $(formId + ' input[name=startSearchDate]').val();
		edDate = $(formId + ' input[name=endSearchDate]').val();
		stDate2 = $(formId + ' input[name=custJoinStDay]').val();
		edDate2 = $(formId + ' input[name=custJoinEdDay]').val();
		$(formId + ' input[name=dispStdt]').val(stDate + ' ' + $(formId + ' select[name=startSearchHour]').val() + ':' + $(formId + ' select[name=startSearchMin]').val() + ':00');
		$(formId + ' input[name=dispEddt]').val(edDate + ' ' + $(formId + ' select[name=endSearchHour]').val() + ':' + $(formId + ' select[name=endSearchMin]').val() + ':59');
		$(formId + ' input[name=custJoinStdt]').val(stDate2 + ' ' + $(formId + ' select[name=startJoinHour]').val() + ':' + $(formId + ' select[name=startJoinMin]').val() + ':00');
		$(formId + ' input[name=custJoinEddt]').val(edDate2 + ' ' + $(formId + ' select[name=endJoinHour]').val() + ':' + $(formId + ' select[name=endJoinMin]').val() + ':59');

		
		if ($('#replyYn').val() == 'Y') {
			var replyLoc = $(':radio[name="replyLoc"]:checked').val();

			if (typeof replyLoc == 'undefined') {
				mcxDialog.alert('댓글 사용 시 댓글위치를 선택해야합니다.');
				return;
			}
		} 

		

		var privacyPolicy = '';
		var frontGb = $('#frontGb').val();
		if (mode =='U') {
			//if($("#planGb").val()=='E'){
			//	privacyPolicy = gagaSn.getContents('privacyPolicyDetail');
			//}
			
			// 이미지 처리
			if ((!$('input[name=orgMainPimgDelYn]').is(':checked') ? true : false) &&
				(gagajf.isNull($(formId + ' input[name=mainPimg]').val()) == true)   ) {
				$(formId + ' input[name=mainPimg]').val($(formId + ' input[name=orgMainPimg]').val());
			}

			if ((!$('input[name=orgMainMimgDelYn]').is(':checked') ? true : false) &&
				(gagajf.isNull($(formId + ' input[name=mainMimg]').val()) == true)  ) {
				$(formId + ' input[name=mainMimg]').val($(formId + ' input[name=orgMainMimg]').val());
			}

			if ((!$('input[name=orgDtlPimgDelYn]').is(':checked') ? true : false) &&
				(gagajf.isNull($(formId + ' input[name=dtlPimg]').val()) == true)  ) {
				$(formId + ' input[name=dtlPimg]').val($(formId + ' input[name=orgDtlPimg]').val());
			}

			if ((!$('input[name=orgDtlMimgDelYn]').is(':checked') ? true : false) &&
				(gagajf.isNull($(formId + ' input[name=dtlMimg]').val()) == true)  ) {
				$(formId + ' input[name=dtlMimg]').val($(formId + ' input[name=orgDtlMimg]').val());
			}

			if ((!$('input[name=orgReplyImgDelYn]').is(':checked') ? true : false) &&
				(gagajf.isNull($(formId + ' input[name=replyImg]').val()) == true) ) {
				$(formId + ' input[name=replyImg]').val($(formId + ' input[name=orgReplyImg]').val());
			}
		} 
		
		let allBrandData = gagaAgGrid.getAllRowData(gridOptionsFGBrandList);
		var multiBrand = [];
		$.each(allBrandData, function(idx, item) {
			multiBrand.push(item.brandGroupNo);
		});
		
		let allChannelData = gagaAgGrid.getAllRowData(gridOptionsAfList);
		var multiChannel = [];
		$.each(allChannelData, function(idx, item) {
			multiChannel.push(item.afLinkCd);
		});

		
		// poll 관리일련번호 유효성 체크
		if (!gagajf.isNull($(formId + ' input[name=pollSq]').val())) {
			gagajf.ajaxFormSubmit('/marketing/poll/list', formId, function(result) {
				if (result.length < 1) {
					mcxDialog.alert('입력하신 투표 일련번호가 존재 하지않습니다.');
					return false;
				}
			});
		} 
		
		// 기획전 등록
		if (formId == '#planRegisterForm') {
			mcxDialog.confirm('등록 하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function() {
					
					if( $('#planRegisterForm input[name=planNm]').val() == ''){
						mcxDialog.alert('기획전명을 입력하세요.');
						return false;
					}
					
					if($('#planRegisterForm select[name=planGb]').val() != 'S'){
						if ($('#planRegisterForm input[name=mainPimg]').val()=='') {
							mcxDialog.alert("목록 이미지를 등록하세요.");
							return false;
						}
					} 
					
					var chkFrontGb = $('#planRegisterForm input:checkbox[name=frontGb]:checked');
					if(chkFrontGb.length < 1){
						mcxDialog.alert("프론트구분을 체크해주세요.");
						return false;
					}
					
					var frontGb = '';
					for(let i=0; i< chkFrontGb.length; i++){
						frontGb += chkFrontGb.eq(i).val();
						if (i != (chkFrontGb.length-1) ) {
							frontGb += '|';
						}
					}
					
					
					var usableCustGradeArr = [];
					var chkCustGrade = $('#planRegisterForm input:checkbox[name=usableCustGradeArr]:checked');
					

					for(let i=0; i< chkCustGrade.length; i++){
						usableCustGradeArr.push(chkCustGrade.eq(i).val());
					}
					
					var chkCate = $('#planRegisterForm input:checkbox[name=cateList]:checked');
					var allCateData = [];
					for(let i=0; i< chkCate.length; i++){
						allCateData.push(chkCate.eq(i).val());
					}
					
					var usableCustGbArr = [];
					var chkCustGb = $('#planRegisterForm input:checkbox[name=usableCustGbArr]:checked');
					
					if(chkCustGb.length < 1){
						mcxDialog.alert("사용가능고객구분을 체크해주세요.");
						return false;
					}
					
					for(let i=0; i< chkCustGb.length; i++){
						usableCustGbArr.push(chkCustGb.eq(i).val());
					}
					
					let data = {
							 multiBrand : multiBrand
							,brandList : allBrandData
							,multiCate : allCateData
							//,CateList : allCateData
							,usableCustGradeArr : usableCustGradeArr
							,usableCustGbArr : usableCustGbArr
							,multiChannel : multiChannel
							,attendData : attendData
						    ,mode : $('#planRegisterForm input[name=mode]').val()
						    ,planSq : $('#planRegisterForm input[name=planSq]').val()
							,planGb	: $('#planRegisterForm select[name=planGb]').val()
							,frontGb : frontGb
							,planNm : $('#planRegisterForm input[name=planNm]').val()
							,startSearchDate : $('#planRegisterForm input[name=startSearchDate]').val()
							,endSearchDate : $('#planRegisterForm input[name=endSearchDate]').val()
							,custJoinStdt : $('#planRegisterForm input[name=custJoinStdt]').val()
							,custJoinEddt : $('#planRegisterForm input[name=custJoinEddt]').val()
							,custJoinEdDay : $('#planRegisterForm input[name=custJoinEdDay]').val()
							,custJoinStDay : $('#planRegisterForm input[name=custJoinStDay]').val()
							,dispStdt : $('#planRegisterForm input[name=dispStdt]').val()
							,dispEddt : $('#planRegisterForm input[name=dispEddt]').val()
							,dtlTitle1 : $('#planRegisterForm input[name=dtlTitle1]').val()
							,cornerNmDispYn :  $('#planRegisterForm select[name=cornerNmDispYn]').val()
							,openYn :  $('#planRegisterForm select[name=openYn]').val()
							,siteCd :$('#planRegisterForm select[name=siteCd]').val()
							,dispOrd : $('#planRegisterForm input[name=dispOrd]').val()
							,replyYn : $('#planRegisterForm select[name=replyYn]').val()
							,mainPimg :$('#planRegisterForm input[name=mainPimg]').val()
							,mainMimg : $('#planRegisterForm input[name=mainMimg]').val()
							,fsrcPc :  $('#planRegisterForm input[name=fsrcPc]').val()
							,fsrcMobile : $('#planRegisterForm input[name=fsrcMobile]').val()
							,replyImg : $('#planRegisterForm input[name=replyImg]').val()
							,replyLoc : $('#planRegisterForm input:radio[name="replyLoc"]:checked').val()
							,replyTitle1 : $('#planRegisterForm input[name=replyTitle1]').val()
							,replyTitle2 : $('#planRegisterForm input[name=replyTitle2]').val()
							,pollSq : $('#planRegisterForm input[name=pollSq]').val()
							,newCustYn :$('#planRegisterForm select[name=newCustYn]').val()
							 
						}	
					
					var jsonData =  JSON.stringify(data);
					
					gagajf.ajaxJsonSubmit("/marketing/planning/detail/create", jsonData, fnPlanDetailCallBack); 
					uifnPopupClose('popupPlanDetail');
					fnPlanListSearch();
					//fnPlanDetailClose();
				}
			});
		} else { // 기획전 수정
	
			mcxDialog.confirm('저장 하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function() {
					if( $('#planUpdateForm input[name=planNm]').val() == ''){
						mcxDialog.alert('기획전명을 입력하세요.');
						return false;
					}
					
					var chkFrontGb = $('#planUpdateForm input:checkbox[name=frontGb]:checked');
					
					if(chkFrontGb.length < 1){
						mcxDialog.alert("프론트구분을 체크해주세요.");
						return false;
					}
					
					var frontGb = '';
					for(let i=0; i< chkFrontGb.length; i++){
						frontGb += chkFrontGb.eq(i).val();
						if (i != (chkFrontGb.length-1) ) {
							frontGb += '|';
						}
					}
					
					var usableCustGradeArr = [];
					var chkCustGrade = $('#planUpdateForm input:checkbox[name=usableCustGradeArr]:checked');
					
							
					for(let i=0; i< chkCustGrade.length; i++){
						usableCustGradeArr.push(chkCustGrade.eq(i).val());
					}
					
					var chkCate = $('#planUpdateForm input:checkbox[name=cateList]:checked');
					var allCateData = [];
					for(let i=0; i< chkCate.length; i++){
						allCateData.push(chkCate.eq(i).val());
					}
					
					var usableCustGbArr = [];
					var chkCustGb = $('#planUpdateForm input:checkbox[name=usableCustGbArr]:checked');
					
					if(chkCustGb.length < 1){
						mcxDialog.alert("사용가능고객구분을 체크해주세요.");
						return false;
					}
					
					for(let i=0; i< chkCustGb.length; i++){
						usableCustGbArr.push(chkCustGb.eq(i).val());
					}
					let data = {
							 multiBrand : multiBrand
							,brandList : allBrandData
							,multiCate : allCateData
							,multiChannel : multiChannel
							,attendData : attendData
							//,CateList : allCateData
							,usableCustGradeArr : usableCustGradeArr
							,usableCustGbArr : usableCustGbArr
						    ,mode : $('#planUpdateForm input[name=mode]').val()
						    ,planSq : $('#planUpdateForm input[name=planSq]').val()
							,planGb	: $('#planUpdateForm select[name=planGb]').val()
							,frontGb : frontGb
							,planNm : $('#planUpdateForm input[name=planNm]').val()
							,startSearchDate : $('#planUpdateForm input[name=startSearchDate]').val()
							,startSearchHour : $('#planUpdateForm input[name=startSearchHour]').val()
							,startSearchMin : $('#planUpdateForm input[name=startSearchMin]').val()
							,endSearchDate : $('#planUpdateForm input[name=endSearchDate]').val()
							,endSearchHour : $('#planUpdateForm input[name=endSearchHour]').val()
							,endSearchMin : $('#planUpdateForm input[name=endSearchMin]').val()
							,custJoinStdt : $('#planUpdateForm input[name=custJoinStdt]').val()
							,startJoinHour : $('#planUpdateForm input[name=startJoinHour]').val()
							,startJoinMin : $('#planUpdateForm input[name=startJoinMin]').val()
							,custJoinEddt : $('#planUpdateForm input[name=custJoinEddt]').val()
							,endJoinHour : $('#planUpdateForm input[name=endJoinHour]').val()
							,endJoinMin : $('#planUpdateForm input[name=endJoinMin]').val()
							,dispStdt : $('#planUpdateForm input[name=dispStdt]').val()
							,dispEddt : $('#planUpdateForm input[name=dispEddt]').val()
							,dtlTitle1 : $('#planUpdateForm input[name=dtlTitle1]').val()
							,cornerNmDispYn :  $('#planUpdateForm select[name=cornerNmDispYn]').val()
							,openYn :  $('#planUpdateForm select[name=openYn]').val()
							,siteCd :$('#planUpdateForm select[name=siteCd]').val()
							,dispOrd : $('#planUpdateForm input[name=dispOrd]').val()
							,replyYn : $('#planUpdateForm select[name=replyYn]').val()
							,mainPimg :$('#planUpdateForm input[name=mainPimg]').val()
							,mainMimg : $('#planUpdateForm input[name=mainMimg]').val()
							,fsrcPc :  $('#planUpdateForm input[name=fsrcPc]').val()
							,fsrcMobile : $('#planUpdateForm input[name=fsrcMobile]').val()
							,replyImg : $('#planUpdateForm input[name=replyImg]').val()
							,replyLoc : $('#planUpdateForm input:radio[name="replyLoc"]:checked').val()
							,replyTitle1 : $('#planUpdateForm input[name=replyTitle1]').val()
							,replyTitle2 : $('#planUpdateForm input[name=replyTitle2]').val()
							,pollSq : $('#planUpdateForm input[name=pollSq]').val()
							,newCustYn : $('#planUpdateForm select[name=newCustYn]').val()
						}	
					
					
					var actionUrl = '/marketing/plan/detail/update';
					var jsonData =  JSON.stringify(data);
					gagajf.ajaxJsonSubmit(actionUrl, jsonData, fnPlanDetailCallBack); 
						uifnPopupClose('popupPlanDetail');
						fnPlanListSearch();
						//fnPlanDetailClose();
				}
			});
		}
	}

	// 이미지 첨부
	$('input[name=registerMainPimg],input[name=registerMainMimg],input[name=registerDtlPimg],input[name=registerDtlMimg],input[name=registerReplyImg]').on('change', function() {
		var name = $(this)[0].name;

		var file = this.files[0];

		gagajf.ajaxFileUpload('/common/file/upload?subDir=/planning'
				, file
				, function(result) {
					if (name == 'registerMainPimg'){
						$('input[name=mainPimg]').val(result.newFileName);
						$('input[name=pImg]').val(result.newFileName);
					}

					if (name == 'registerMainMimg'){
						$('input[name=mainMimg]').val(result.newFileName);
						$('input[name=mimg]').val(result.newFileName);
					}
						

					if (name == 'registerDtlPimg')
						$('input[name=dtlPimg]').val(result.newFileName);

					if (name == 'registerDtlMimg')
						$('input[name=dtlMimg]').val(result.newFileName);

					if (name == 'registerReplyImg')
						$('input[name=replyImg]').val(result.newFileName);
				}
				, 'image'
		);
	});

	var fnChangePlanGb = function(obj) {
		if($(obj).val() == 'C'){
			$("#attendTh").removeAttr('style');
			$("#attendTd").removeAttr('style');
		}else{
			$("#attendTh").css('display','none');
			$("#attendTd").css('display','none');
		}
		
		if($(obj).val()=='E'){
			$("#pollTr").show();
			$("#questionEventInsert").show();
			$("#questionEventUpdate").show();
			if (mode =='U') {
				if($("#privacyPolicyDetail").closest('div').children('#the_iframe').length==0){
					gagaSn.createSummernote(snOptions, '#privacyPolicyDetail');
				}
			}else{
				if($("#privacyPolicyRegister").closest('div').children('#the_iframe').length==0){
					gagaSn.createSummernote(snOptions, '#privacyPolicyRegister');
				}
			}
		}else{
			$("#questionEventInsert").hide();
			$("#questionEventUpdate").hide();
			$("#pollTr").hide();
		}
	}

	var fnAddRow = function(obj){
		var html = '<div>';
		html += '<input type="text" class="w200" name="planQtitle"/>';
		html += '<label class="chkBox"><input type="checkbox" onclick="fnAttachYnClick(this);" />첨부파일</label>';
		html += '<button type="button" class="btn icn" onclick="fnDeleteRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button>';
		html += '<input type="hidden" name="attachYn" value="N"/>';
		html += '</div>';
		$(obj).closest('td').append(html);
	}

	var fnDeleteRow = function(obj){
		$(obj).closest('div').remove();
	}

	var fnAttachYnClick = function(obj){
		var val = 'N';
		if($(obj).prop('checked')){
			val = 'Y';
		}
		$(obj).closest('div').find('input[name="attachYn"]').val(val);
	}

	var fnPlanDetailCallBack = function() {
		uifnPopupClose('planRegisterForm');
		fnPlanListSearch();
		
	}
	
	// 브랜드 리스트 설정
	var columnBrandList = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "브랜드그룹NO", field: "brandGroupNo", width: 110, cellClass: 'text-center'},
		{headerName: "브랜드그룹명", field: "brandGroupKnm", width: 120, cellClass: 'text-center'},
		{headerName: "브랜드영문명", field: "brandGroupEnm", width: 150, cellClass: 'text-center'},
		{headerName: "", field: "brandKnm", width: 150, cellClass: 'text-center'},
	];
	
	// 브랜드 그리드 설정
	var gridOptionsFGBrandList = gagaAgGrid.getGridOptions(columnBrandList);
	gridOptionsFGBrandList.rowSelection = "multiple";
	gridOptionsFGBrandList.suppressRowClickSelection = true;
	
	// 브랜드 추가 버튼 클릭시 (복수 브랜드때 수정 필요)
	$('#btnAddBrand').on('click', function() {
		cfnOpenBrandGroupListPopup("fnSetPopupBrandInfo", "S", "S");
	});
	
	 // 브랜드 설정 선택삭제 버튼 클릭시
    $('#btnDeleteBrand').on('click', function() {
        gridOptionsFGBrandList.api.updateRowData({remove:gagaAgGrid.selectedRowData(gridOptionsFGBrandList)});
    });
	
	// 브랜드 설정 / 브랜드 추가 콜백함수 (단수로 가져오므로 복수일 경우에 수정 확인 필요)
	var fnSetPopupBrandInfo = function(result) {
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(gridOptionsFGBrandList);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				if(gridListValue[j].brandGroupNo == result[i].brandGroupNo) {	addChk = false;	}					// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(gridOptionsFGBrandList, {"brandGroupNo" : result[i].brandGroupNo, "brandGroupKnm" : result[i].brandGroupKnm, "brandGroupEnm" : result[i].brandGroupEnm});
			}
		}
	};
	
	
	// 제휴채널 추가
	$('#btnAddAf').on('click' , function () {
		cfnOpenAfChannelPopup("callBackAf");
	});
	
	// 제휴채널 콜백
	var callBackAf = function(result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(gridOptionsAfList);		// 받아온 모든 데이터

			// 받아온 data for
			for(let j = 0 ; j < gridListValue.length ; j++) {
				// 동일한 data는 추가하지 않음
				if(gridListValue[j].afLinkCd == result[i].afLinkCd) {	addChk = false;	}		// 중복체크
			}

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(gridOptionsAfList, {"afLinkCd":result[i].afLinkCd , "afLinkNm":result[i].afLinkNm, "afChannel":result[i].afChannel});
			}
		}
	}
	
	// 제츄채널 선택삭제 버튼 클릭시
    $('#btnDeleteAf').on('click', function() {
    	gridOptionsAfList.api.updateRowData({remove:gagaAgGrid.selectedRowData(gridOptionsAfList)});
    });
	
	// 신규회원여부 변경시
	function newCustYnChange(pThis){
		var selectVal = $(pThis).val();

		if(typeof selectVal == "undefined") {
			if(mode == "U") {
				selectVal = cpnDetail.newCustYn;
			} else {
				selectVal = "N";
			}
		}

		if(selectVal == "Y" ) {
			$('.custJoinDateTr').css('display' , '');
			$('#custJoinStdt').attr('required' , true);
			$('#custJoinEddt').attr('required' , true);
		} else {
			$('.custJoinDateTr').css('display' , 'none');
			$('#custJoinStdt').attr('required' , false);
			$('#custJoinEddt').attr('required' , false);
		}
	}
	
	// 쿠폰혜택그리드
	var columnAttendList = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{headerName: "혜택", field: "benefit", width: 110, cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',cellEditorParams: { values: ['포인트', '쿠폰', '포인트/쿠폰'] },
	    },
	    {headerName: "", field: "benefitGb", width: 50, cellClass: 'text-center', hide:true	},
	    {headerName: "", field: "cpnYn", width: 50, cellClass: 'text-center', hide:true	},
	    {headerName: "일수", field: "basDays", width: 50, cellClass: 'text-center', cellEditor: 'numericCellEditor'},
		{headerName: "포인트", field: "pntAmt", width: 80, cellClass: 'text-center', cellEditor: 'numericCellEditor'
			,cellEditorParams: { maxlength: 3, required: true }
	    	, cellRenderer: function(params) { return gagajf.isNull(params.value) ? '' : params.value.addComma(); }
	    	, editable: function(params) { 
	    		if (params.data.benefit == '포인트' || params.data.benefit == '포인트/쿠폰') {
					return true;
				}else{false;}
	    	}
	    },
		{headerName: "쿠폰ID", field: "cpnId", width: 80, cellClass: 'text-center', cellEditor: 'numericCellEditor'
			,cellEditorParams: { maxlength: 3, required: true }
    	    , editable: function(params) { 
	    		if (params.data.benefit == '쿠폰' || params.data.benefit == '포인트/쿠폰') {
					return true;
				}else{false;}
    		}
    	},
    	{headerName: "유효기간(일수)", field: "pntUsableDay", width: 100, cellClass: 'text-center', cellEditor: 'numericCellEditor'
			,cellEditorParams: { maxlength: 3, required: true }
    	    , editable: function(params) { 
	    		if (params.data.benefit == '포인트' || params.data.benefit == '포인트/쿠폰') {
					return true;
				}else{false;}
    		}
    	},
	];

	
	// 브랜드 그리드 설정
	var gridOptionsAttendList = gagaAgGrid.getGridOptions(columnAttendList);
	gridOptionsAttendList.rowSelection = "multiple";
	gridOptionsAttendList.stopEditingWhenGridLosesFocus = true;
	gridOptionsAttendList.defaultColDef.editable = true;
	gridOptionsAttendList.suppressRowClickSelection = true;


	// 행추가
	$('#btnAddRow').on('click', function() {
		var allData = gagaAgGrid.getAllRowData(gridOptionsAttendList);

		if (allData.length >= 4) {
			mcxDialog.alert('혜택적용은 최대 4개까지 가능합니다.');
			return;
		} else {
	
			var data = { benefit: '포인트',benefitGb: 'P', cpnYn:'Y', basDays:'' ,pntAmt:'', cpnId: '', pntUsableDay:''};
			gagaAgGrid.addRowData(gridOptionsAttendList, data);
		}

	});

	
	// 혜택구분 선택삭제 버튼 클릭시
    $('#btnDeleteAt').on('click', function() {
    	gridOptionsAttendList.api.updateRowData({remove:gagaAgGrid.selectedRowData(gridOptionsAttendList)});
    });
	

 // Row 
	gridOptionsAttendList.onCellValueChanged = function(event) {
	
		if (event.colDef.field == "benefit"){
			if (event.data.benefit == "쿠폰"){
				gridOptionsAttendList.api.forEachNode(function(rowNode, index) {
					if (rowNode.data.benefit == "쿠폰"){
						event.data.benefitGb = "C";
						gridOptionsAttendList.api.updateRowData({update: [event.data]});
						return;
					}
				});
			}else if(event.data.benefit == "포인트"){
				gridOptionsAttendList.api.forEachNode(function(rowNode, index) {
					if (rowNode.data.benefit == "포인트"){
						event.data.benefitGb = "P";
						gridOptionsAttendList.api.updateRowData({update: [event.data]});
						return;
					}
				});
			}else{
				gridOptionsAttendList.api.forEachNode(function(rowNode, index) {
					if (rowNode.data.benefit == "포인트/쿠폰"){
						event.data.benefitGb = "A";
						gridOptionsAttendList.api.updateRowData({update: [event.data]});
						return;
					}
				});
			}	
		}
		
		if (event.colDef.field == "cpnId"){
			var param = {cpnId : event.data.cpnId};
			var jsonData = JSON.stringify(param);
			
			gagajf.ajaxJsonSubmit('marketing/planning/attend/coupon', jsonData, function(result) {
				if (result.length < 1) {
					mcxDialog.alert('입력하신 쿠폰 ID ' + event.data.cpnId + '은(는) 유효하지 않습니다.');
					event.data.cpnYn = "N";
					return false;
				}else{
					event.data.cpnYn = "Y";
				}
			});
		}
	}
	
	$(document).ready(function() {
		
		snOptions = gagaSn.getToolbarOptions('media');
		
		// 썸머노트 그리기
		gagaSn.createSummernote(snOptions, '#fsrcPcDetail');
		gagaSn.createSummernote(snOptions, '#fsrcMobileDetail');
		
		// 그리드 그리기
		gagaAgGrid.createGrid("gridFGBrandList", gridOptionsFGBrandList);
		//gagaAgGrid.createGrid("gridFGCateList", gridOptionsFGCateList);
		gagaAgGrid.createGrid("gridAfPlanList", gridOptionsAfList);
		gagaAgGrid.createGrid("gridAttendPlanList", gridOptionsAttendList);
		
		$('.custJoinDateTr').css('display' , 'none');
		$('#custJoinStdt').attr('required' , false);
		$('#custJoinEddt').attr('required' , false);
		
		
		 if (mode =='U') {
			 if(planInfo.newCustYn == 'Y'){
				 $('.custJoinDateTr').show();
				 $("#planUpdateForm input[name=custJoinStDay]").val(planInfo.custJoinStdt.split(' ')[0]);
				 $("#planUpdateForm input[name=custJoinEdDay]").val(planInfo.custJoinEddt.split(' ')[0]);
			 }
			 
			 if(planCateList.length > 0){
					var chkboxCnt = $('#planUpdateForm input:checkbox[name=cateList]').length;
					var dataCnt = planCateList.length;
					for(var i=0; i<chkboxCnt; i++){
						for(var j=0; j<dataCnt; j++){
							var data = planCateList[j].cateNo;
							if($('#planUpdateForm input:checkbox[name=cateList]').eq(i).val() == data){
								$('#planUpdateForm input:checkbox[name=cateList]').eq(i).prop('checked', true);
								$("#planUpdateForm input:checkbox[name=cateList]").eq(i).parent().addClass('checked');
							}
						}
					}
				}
			 
			 if (planInfo.planGb =='C') {
				 gridOptionsAttendList.api.setRowData(benefitList);
				 $("#attendTh").removeAttr('style');
				 $("#attendTd").removeAttr('style');
				
			}else{
				$("#attendTh").css('display','none');
				$("#attendTd").css('display','none');
			}
			 
			 if (planInfo.planGb =='E') {
				 $("#pollTr").show();
				
			}else{
				 $("#pollTr").hide();
			}
			 
			 
			
			 
			 
			gridOptionsFGBrandList.api.setRowData(planBrandList);
			//gridOptionsFGCateList.api.setRowData(planCateList);
			gridOptionsAfList.api.setRowData(afChannelList);

			if (planInfo.goodsLimitYn == 'N') {
				$('#planDetailForm input[name=goodsLimitQty]').hide();
			} else {
				$('#planDetailForm input[name=goodsLimitQty]').show();
			}

			if($("#planGb").val()!='E'){
				$("#questionEventInsert").hide();
				$("#questionEventUpdate").hide();
			}else{
				gagaSn.createSummernote(snOptions, '#privacyPolicyRegister');
			}

		} else {

			$("#viewStartDtNew").val(_today);
			$("#viewEndDtNew").val(_today);

			$("#questionEventInsert").hide();
			$("#questionEventUpdate").hide();
		} 
		$('#frontGb').trigger('change');
	});

/*]]>*/
</script>

</html>