<!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  2021.05.06   sowon   최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1395" id="planRegisterFormDiv">
	<div class="panelStyle">
		<div class="panelTitle">
			<h2 th:text="${'기획전 ' + (mode == 'N' ? '등록' : '수정')}"></h2>
			<button type="button" class="close" onclick="uifnPopupClose('planRegisterFormDiv')"><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 th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="|${oneData.cdNm}|"></option>
							</select>
						</td>
						<th>기획전구분</th>
						<td>
							<select name="planGb" id="planGb" th:field="*{planGb}" disabled="disabled">
								<option value="P">기획전</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>프론트 구분</th>
						<td>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="P" th:text="PC웹" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="M" th:text="모바일웹" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb"  value="A" th:text="모바일앱" checked="checked" disabled="disabled"/>
							</label>
							
						</td>
						<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>기획전명<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>코너명노출 여부</th>
						<td>
							<select name="cornerNmDispYn" required="required" data-valid-name="코너명노출 여부" disabled="disabled">
								<option value="Y">Yes</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}" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox">
								<input type="checkbox" name="usableCustGradeArr" value="G110_60" th:text="비회원" checked="checked" disabled="disabled"/>
							</label>
						</td>
						<th>브랜드</th>
						<td>
						<select name="supplyCompCd" id="supplyCompCd">
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<span id="multiBrand"></span>
						</td>			
					</tr>
					<tr>
						<th>사용가능고객구분</th>
						<td  colspan="3">
							<label class="chkBox">
								<input type="checkbox" name="usableCustGbArr" value="G100_10" th:text="일반회원" checked="checked" disabled="disabled"/>
							</label>
  						</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>
				</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>
									</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>기획전구분</th>
						<td>
							<select name="planGb" required="required" data-valid-name="기획전구분" disabled="disabled">
								<option value="P">기획전</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>프론트 구분</th>
						<td>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="P" th:text="PC웹" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb"  value="M" th:text="모바일웹" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox" >
								<input type="checkbox" name="frontGb" value="A" th:text="모바일앱" checked="checked" disabled="disabled"/>
							</label>
						</td>
						<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>기획전명<em class="required" title="필수"></em></th>
						<td>
							<input type="text" name="planNm" id="planNm" maxlength="50" required="required" data-valid-name="기획전명"/>
						</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>코너명노출 여부</th>
						<td>
							<select name="cornerNmDispYn" required="required" data-valid-name="코너명노출 여부" disabled="disabled">
								<option value="Y">Yes</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} == '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}" checked="checked" disabled="disabled"/>
							</label>
							<label class="chkBox">
								<input type="checkbox" name="usableCustGradeArr" value="G110_60" th:text="비회원" checked="checked" disabled="disabled"/>
							</label>
						</td>
						<th>브랜드</th>
						<td>
						<select name="supplyCompCd" id="supplyCompCd">
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
							<span id="multiBrand"></span>
						</td>						
					</tr>
					<tr>
						<th>사용가능고객구분</th>
						<td  colspan="3">
							<label class="chkBox">
								<input type="checkbox" name="usableCustGbArr" value="G100_10" th:text="일반회원" checked="checked" disabled="disabled"/>
							</label>
  						</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>
					
				</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>
										</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 benefitList = [[${benefitList}]];
	var supplyCompList = [[${supplyCompList}]];
	var snOptions;
	var sessRoleCd = [[${sessionInfo.roleCd}]];

	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":"한세드림"}

    
	// 카테고리 전시 여부
	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);
		
	}
	

	// 기획전 복사
	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('planRegisterFormDiv');
		fnPlanListSearch();

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

	 var fnPlanSave = function(formId) {
		/* if (!gagajf.validation(formId))
			return;  */

		// 날짜 유효성 체크
		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 (Number(stDate2) > Number(edDate2)) {
			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');

	

		var privacyPolicy = '';
		var frontGb = $('#frontGb').val();
		if (mode =='U') {
			
			// 이미지 처리
			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());
			}
			
		} 

		// 기획전 등록
		if (formId == '#planRegisterForm') {
			mcxDialog.confirm('등록 하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function() {
					if(!validationPlanDetail()){
						return false;
					}
					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 usableCustGbArr = [];
					var chkCustGb = $('#planRegisterForm input:checkbox[name=usableCustGbArr]:checked');
					

					for(let i=0; i< chkCustGb.length; i++){
						usableCustGbArr.push(chkCustGb.eq(i).val());
					
					}
					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 chkBrand = $('#planRegisterForm input:checkbox[name=multiBrand]:checked');
					var allBrandData = [];
					for(let i=0; i< chkBrand.length; i++){
						allBrandData.push(chkBrand.eq(i).val());
					}
					
					let data = {
							 multiCate : allCateData
							,multiBrand : allBrandData
							,usableCustGradeArr : usableCustGradeArr
							,usableCustGbArr : usableCustGbArr
						    ,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()
							,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()
							,mainPimg :$('#planRegisterForm input[name=mainPimg]').val()
							,mainMimg : $('#planRegisterForm input[name=mainMimg]').val()
							,fsrcPc :  $('#planRegisterForm input[name=fsrcPc]').val()
							,fsrcMobile : $('#planRegisterForm input[name=fsrcMobile]').val()
							 
						}	
					
					var jsonData =  JSON.stringify(data);
					gagajf.ajaxJsonSubmit("/marketing/planning/detail/create", jsonData, fnPlanDetailCallBack); 
					uifnPopupClose('planRegisterFormDiv');
					fnPlanListSearch();
					//fnPlanDetailClose();
				}
			});
		} else { // 기획전 수정
	
			mcxDialog.confirm('저장 하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function() {
					if(!validationPlanDetail()){
						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 usableCustGbArr = [];
					var chkCustGb = $('#planUpdateForm input:checkbox[name=usableCustGbArr]:checked');
					
					
					for(let i=0; i< chkCustGb.length; i++){
						usableCustGbArr.push(chkCustGb.eq(i).val());
					}
					
					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 chkBrand = $('#planUpdateForm input:checkbox[name=multiBrand]:checked');
					var allBrandData = [];
					for(let i=0; i< chkBrand.length; i++){
						allBrandData.push(chkBrand.eq(i).val());
					}
					let data = {
							 multiCate : allCateData
							,multiBrand : allBrandData
							,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()
							,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()
							,mainPimg :$('#planUpdateForm input[name=mainPimg]').val()
							,mainMimg : $('#planUpdateForm input[name=mainMimg]').val()
							,fsrcPc :  $('#planUpdateForm input[name=fsrcPc]').val()
							,fsrcMobile : $('#planUpdateForm input[name=fsrcMobile]').val()
						}	
					
					
					var actionUrl = '/marketing/plan/detail/update';
					var jsonData =  JSON.stringify(data);
					gagajf.ajaxJsonSubmit(actionUrl, jsonData, fnPlanDetailCallBack); 
						uifnPopupClose('planRegisterFormDiv');
						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 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();
		
	}
	
	// validation 체크
	function validationPlanDetail() {
		if( $('#planUpdateForm input[name=planNm]').val() == '' || $('#planRegisterForm input[name=planNm]').val() == ''){
			mcxDialog.alert('기획전명을 입력하세요.');
			return false;
		}
		return true;
	} 
	
	$(document).ready(function() {
		var actionUrl = '/renderer/supplyCompany/brand/list/' + $(this).val();

		if (sessRoleCd == "G001_B000") {
			actionUrl = '/renderer/brand/AuthBrandlist';
		}
		
		cfnCreateMultiCombo(actionUrl,"multiBrand",  "[전체]",null, 'Y');
		snOptions = gagaSn.getToolbarOptions('media');
		
		// 썸머노트 그리기
		gagaSn.createSummernote(snOptions, '#fsrcPcDetail');
		gagaSn.createSummernote(snOptions, '#fsrcMobileDetail');
		
		// 그리드 그리기
		//gagaAgGrid.createGrid("gridFGCateList", gridOptionsFGCateList);
		
		 if (mode =='U') {
			 

				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(planBrandList.length > 0){
					setTimeout(function(){
						var chkboxCnt = $('input:checkbox[name=multiBrand]').length;
						var dataCnt = planBrandList.length;
						for(var i=0; i<10; i++){
							for(var j=0; j<dataCnt; j++){
								var data = planBrandList[j].brandCd;
								if($('input:checkbox[name=multiBrand]').eq(i).val() == data){
									$('input:checkbox[name=multiBrand]').eq(i).prop('checked', true);
									$("input:checkbox[name=multiBrand]").eq(i).parent().addClass('checked');
								}
							}
						}
					}, 1000);
					
				}
				
			//gridOptionsFGCateList.api.setRowData(planCateList);
			
			
			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>