<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CouponPopupForm.html
 * @desc    : 쿠폰 등록 팝업 화면
 *============================================================================
 * ISTYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.23   xyzp1539       최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1500">
	<div class="panelStyle" style="height: 750px;">
		<div class="panelTitle">
			<h2 th:text="${'쿠폰 ' + (mode == 'N' ? '등록' : '수정')}">쿠폰등록</h2>
			<button type="button" class="close" onclick="uifnPopupClose('CouponRegForm')"><i class="fa fa-times"></i></button>
		</div>
		<div class="panelContent">
			<form id="CouponForm" name="CouponForm" action="#" th:action="@{'/marketing/coupon/save'}" >
				<input type="hidden" name="supplyCompList" id="supplyCompList">
				<input type="hidden" name="brandList" id="brandList">
				<input type="hidden" name="applyGoodsList" id="applyGoodsList">
				<input type="hidden" name="exceptGoodsList" id="excepGoodsList">
				<input type="hidden" name="burdenList" id="burdenList">
				<input type="hidden" name="cateList" id="cateList">
				<input type="hidden" name="rdCpnNm" id="rdCpnNm">
				<input type="hidden" name="cpnId" id="cpnId" th:if="${cpnDetail}" th:value="${cpnDetail.cpnId}">
				<input type="hidden" name="mode" th:value="${mode}"/>

				<div class="tabs">
					<div class="tabsNav">
						<ul>
							<li class="on"><a href="#coupontab1">기본정보</a></li>
							<li><a href="#coupontab2">적용대상</a></li>
							<li><a href="#coupontab3">입점업체분담율</a></li>
							<li class="randomCpnTab" style="display:none;"><a href="#coupontab4">시리얼및난수</a></li>
							<li class="limitedTimeCpnTab" style="display:none;"><a href="#coupontab5">선착순쿠폰</a></li>	<!--style="display:none;"-->
						</ul>
					</div>
					<ul class="tabsCont">
						<li class="tab on" id="coupontab1">
							<div class="panelStyle">
								<table class="frmStyle">
									<colgroup>
										<col style="width:10%">
										<col style="width:45%;">
										<col style="width:10%">
										<col style="width:35%;">
									</colgroup>
									<tbody>
										<tr th:if="${cpnDetail}">
											<th>쿠폰번호</th>
											<td colspan="5">
												<span th:if="${cpnDetail}" th:text="${cpnDetail.cpnId}"></span>
											</td>
										</tr>
										<tr>
											<th>쿠폰명<em class="required" title="필수"></em></th>
											<td>
												<input type="text" name="cpnNm" id="cpnNm" required="required" data-valid-name="쿠폰명">
											</td>
											<th>사이트<em class="required" title="필수"></em></th>
											<td>
												<select name="siteCd" id="siteCd" required="required" data-valid-name="사이트">
													<option th:if="${siteCdList}" th:each="oneData , status : ${siteCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
												</select>
											</td>
										</tr>
										<tr>
											<th>쿠폰설명</th>
											<td>
												<input type="text" name="cpnDesc" id="cpnDesc" data-valid-name="쿠폰설명">
											</td>
											<th>만료알림여부<em class="required" title="필수"></em></th>
											<td>
												<select name="endAlimYn" id="endAlimYn" required="required" data-valid-name="만료알림여부">
													<option value="Y">Y</option>
													<option value="N" selected="selected">N</option>
												</select>
											</td>
										</tr>
										<tr>
											<th>쿠폰유형<em class="required" title="필수"></em></th>
											<td>
												<input type="hidden" id="cpnType" name="cpnType" required="required"  data-valid-name="쿠폰유형">
												<label class="rdoBtn" th:if="${cpnTypeList}" th:each="oneData, status : ${cpnTypeList}"> <input type="radio" name="rdoCpnType"  th:text="${oneData.cdNm}" th:value="${oneData.cd}"/></label>

											</td>
											<th class="limitedTimeCpnArea" style="display: none;">선착순쿠폰</th>
											<td class="limitedTimeCpnArea" style="display: none;">
												<label class="chkBox limitedTimeCpnBox" id="limitedTimeCpnBox"><input type="checkbox" name="limitedTimeCpnYn" id="limitedTimeCpnYn" value="N"/>선착순쿠폰</label>
											</td>
										</tr>
										<tr class="dcCdGb" style="display:none;">
											<th>할인쿠폰유형<em class="required" title="필수"></em></th>
											<td class="normalCol">
												<input type="hidden" id="dcCd" data-valid-name="할인쿠폰유형">
												<label class="rdoBtn" th:if="${dcCdList}" th:each="oneData, status : ${dcCdList}"> <input type="radio" name="dcCdGb"  th:text="${oneData.cdNm}" th:value="${oneData.cd}"/></label>
											</td>
											<th class="randomCpnArea">난수생성수량<em class="required" title="필수"></em></th>
											<td class="randomCpnArea">
												<input type="text" name="randomCpnQty" class="w300" data-valid-name="난수생성수량" data-valid-type="numeric">
											</td>
										</tr>
										<tr class="serialCpnArea" style="display:none;">
											<th>시리얼쿠폰키워드<em class="required" title="필수"></em></th>
											<td>
												<input type="text" name="serialCpnNm" class="w300" maxlength="10" data-valid-name="시리얼쿠폰키워드">
											</td>
											<th>시리얼쿠폰발급수량<em class="required" title="필수"></em></th>
											<td>
												<input type="text" name="serialCpnQty" class="w300" data-valid-name="시리얼쿠폰발급수량" data-valid-type="numeric">
											</td>
										</tr>
										<tr>
											<th class="usableCustGbArea">사용가능고객구분<em class="required" title="필수"></em></th>
											<td class="usableCustGbArea">
												<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>
											<th class="usableCustGradeArea">사용고객등급구분<em class="required" title="필수"></em></th>
											<td class="usableCustGradeArea">
												<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>
											</td>
										</tr>
										<tr>
											<th>할인방식<em class="required" title="필수"></em></th>
											<td>
												<input type="hidden" name="dcWay" id="dcWay" required="required" data-valid-name="할인방식">
												<label class="rdoBtn" th:if="${dcWayList}" th:each="oneData, status : ${dcWayList}"> <input type="radio" name="rdoDcWay"  th:text="${oneData.cdNm}" th:value="${oneData.cd}"/></label>
											</td>
											<th>할인값(PC)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcPval" name="dcPval" value="0" required="required" data-valid-name="할인값(PC)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcPvalSpan">원</span>
												<button type="button" class="btn btn-default btn-lg" id="applySameValueBtn">동일적용</button>
											</td>
										</tr>
										<tr>
											<th>할인값(모바일웹)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcMval" name="dcMval" value="0" required="required" data-valid-name="할인값(모바일웹)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcMvalSpan">원</span>
											</td>
											<th>할인값(모바일앱)<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" id="dcAval" name="dcAval" value="0" required="required" data-valid-name="할인값(모바일앱)" data-valid-type="numeric" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);"><span id="dcAvalSpan">원</span>
											</td>
										</tr>
										<tr>
											<th class="buyLimitAmtArea">구매제한금액<em class="required" title="필수"></em></th>
											<td class="buyLimitAmtArea">
												<input type="text" id="buyLimitAmt" name="buyLimitAmt" class="w200" required="required" value="0" style="text-align: right;" data-valid-name="구매제한금액" data-valid-type="numeric">원
											</td>
											<th class="maxDcAmtArea">최대할인금액<em class="required" title="필수"></em></th>
											<td class="maxDcAmtArea">
												<input type="text" class="w200" id="maxDcAmt" name="maxDcAmt" value="0" required="required" data-valid-name="최대할인금액" data-valid-type="numeric" style="text-align: right;"><span id="maxDcAmtSpan">원</span>
											</td>
										</tr>
										<tr>
											<th class="downStdtArea">다운로드시작일시<em class="required" title="필수"></em></th>
											<td class="downStdtArea">
												<input type="hidden" name="downStdt" id="downStdt" required="required" data-valid-name="다운로드시작일시">
												<input type="text" class="schDate w100" name="downStDay" id="downStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="downStHH" id="downStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="downStMM" id="downStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											<th class="downEddtArea">다운로드종료일시<em class="required" title="필수"></em></th>
											<td class="downEddtArea">
												<input type="hidden" id="downEddt" name="downEddt" required="required" data-valid-name="다운로드종료일시">
												<input type="text" class="schDate w100" name="downEdDay" id="downEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="downEdHH" id="downEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="downEdMM" id="downEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr>
											<th class="pdGbArea">기간/일수구분<em class="required" title="필수"></em></th>
											<td class="pdGbArea">
												<select name="pdGb" id="pdGb" onchange="pdGbChange(this)" required="required" data-valid-name="기간/일수구분">
													<option value="P">기간</option>
													<option value="D">일수</option>
												</select>
											</td>
											<th class="availDaysArea">유효기간일수<em class="required" title="필수"></em></th>
											<td class="availDaysArea">
												<input type="text" name="availDays" id="availDays" class="w200" data-valid-type="numeric" data-valid-name="유효기간일수">
											</td>
										</tr>
<!--										<tr class="availDayTr" style="display: none;">-->
<!--											<th>유효기간일수<em class="required" title="필수"></em></th>-->
<!--											<td>-->
<!--												<input type="text" name="availDays" id="availDays" class="w200" data-valid-name="유효기간일수">-->
<!--											</td>-->
<!--										</tr>-->
										<tr>
											<th class="availDateTr">유효기간시작일시<em class="required" title="필수"></em></th>
											<td class="availDateTr">
												<input type="hidden" name="availStdt" id="availStdt" data-valid-name="유효기간시작일시">
												<input type="text" class="schDate w100" name="availStDay" id="availStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="availStHH" id="availStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="availStMM" id="availStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											<th class="availDateTr">유효기간종료일시<em class="required" title="필수"></em></th>
											<td class="availDateTr">
												<input type="hidden" id="availEddt" name="availEddt" data-valid-name="유효기간종료일시">
												<input type="text" class="schDate w100" name="availEdDay" id="availEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="availEdHH" id="availEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="availEdMM" id="availEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr class="firstBuyTr">
											<th>첫구매여부<em class="required" title="필수"></em></th>
											<td>
												<select name="firstOrdYn" id="firstOrdYn" onchange="firstOrdYnChange(this)" required="required" data-valid-name="첫구매여부">
													<option value="Y">Y</option>
													<option value="N" selected="selected">N</option>
												</select>
											</td>
										</tr>
										<tr>
											<th class="buyDateTr">첫구매기간시작일시<em class="required" title="필수"></em></th>
											<td class="buyDateTr">
												<input type="hidden" name="buyStdt" id="buyStdt" data-valid-name="첫구매기간시작일시">
												<input type="text" class="schDate w100" name="buyStDay" id="buyStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="buyStHH" id="buyStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="buyStMM" id="buyStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											<th class="buyDateTr">첫구매기간종료일시<em class="required" title="필수"></em></th>
											<td class="buyDateTr">
												<input type="hidden" id="buyEddt" name="buyEddt" data-valid-name="첫구매기간종료일시">
												<input type="text" class="schDate w100" name="buyEdDay" id="buyEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
												<select name="buyEdHH" id="buyEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="buyEdMM" id="buyEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr class="custJoinTr">
											<th>신규회원여부<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>
										</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="custJoinStHH" id="custJoinStHH">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
												<select name="custJoinStMM" id="custJoinStMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</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="custJoinEdHH" id="custJoinEdHH" onclick="fnChangeEdHH(this);">
													<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
													<option th:text="24시" th:value="24"></option>
												</select>
												<select name="custJoinEdMM" id="custJoinEdMM">
													<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
												</select>
											</td>
										</tr>
										<tr class="dcCdCheck1">
											<th>총발행제한수량<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" name="totPubLimitQty" id="totPubLimitQty" value="0" required="required" data-valid-name="총발행제한수량" data-valid-type="numeric" style="text-align: right;">개
												<label class="chkBox" id="chkBoxTotPubQty"><input type="checkbox" id="chkNoLimitTotPubLimitQty"/>제한없음</label>
											</td>
											<th>1인당발행제한수량<em class="required" title="필수"></em></th>
											<td>
												<input type="text" class="w200" name="custPubLimitQty" id="custPubLimitQty" value="0" required="required" data-valid-name="1인당발행제한수량" data-valid-type="numeric" style="text-align: right;">개
												<label class="chkBox" id="chkBoxCustPubQty"><input type="checkbox" id="chkNoLimitCustPubLimitQty"/>제한없음</label>
											</td>
										</tr>
										<tr>
											<th class="dcCdCheck2">1회발행수량<em class="required" title="필수"></em></th>
											<td class="dcCdCheck2">
												<input type="text" class="w200" name="onePubQty" id="onePubQty" value="1" required="required" data-valid-name="1회발행수량" data-valid-type="numeric" style="text-align: right;">개
											</td>
											<th class="downAblArea">다운로드가능여부<em class="required" title="필수"></em></th>
											<td class="downAblArea">
												<select name="downAblYn" id="downAblYn" required="required" data-valid-name="다운로드가능여부">
													<option value="Y">Y</option>
													<option value="N" selected="selected">N</option>
												</select>
											</td>
										</tr>
										<!--<tr>
											<th>재발급여부<em class="required" title="필수"></em></th>
											<td>
												<select name="reissuance" id="reissuance" required="required" data-valid-name="재발급여부" >
													<option th:if="${reissuanceList}" th:each="oneData , status : ${reissuanceList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
												</select>
											</td>
											<th>다운로드구분<em class="required" title="필수"></em></th>
											<td>
												<select name="dnGb" id="dnGb" required="required" data-valid-name="다운로드구분">
													<option th:if="${dnGbList}" th:each="oneData , status:${dnGbList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
												</select>
											</td>
										</tr>-->
										<tr class="payTypeTr" style="display: none;">
											<th>결제수단<em class="required" title="필수"></em></th>
											<td colspan="5">
												<label class="chkBox" th:if="${payTypeList}" th:each="oneData, status : ${payTypeList}">
													<input type="checkbox" name="payTypeArr" th:value="${oneData.cd}" th:text="${oneData.cdNm}" checked="checked"/>
												</label>
											</td>
										</tr>
										<tr>
											<th class="linkAfArea">제휴채널</th>
											<td colspan="1" class="linkAfArea">
												<!-- 수정시 프로모션명 입력 : 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="afChannelList" style="width: 100%; height: 200px;" class="ag-theme-balham"></div>
													</div>
												</div>
											</td>
										</tr>
										<tr>
											<th>쿠폰상태<em class="required" title="필수"></em></th>
											<td>
												<label class="rdoBtn" th:if="${cpnStatList}" th:each="oneData, status : ${cpnStatList}" >
													<input type="radio" id="disCpnStat" name="disCpnStat" th:value="${oneData.cd}" th:text="${oneData.cdNm}" data-valid-name="상태" disabled="disabled"/>
												</label>
												<input type="hidden" id="cpnStat" name="cpnStat"/>
											</td>
											<!--<th>제휴링크코드<em class="required" title="필수"></em></th>
											<td>
												<select name="afChannel" id="afChannel" onchange="fnChangeAfLinkCdList()" data-valid-name="제휴링크코드" required="required">
													<option th:if="${upperAfLinkCdList}" th:each="oneData , status : ${upperAfLinkCdList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
												</select>
												<select name="afLinkCd" id="afLinkCd">
												</select>
											</td>-->
										</tr>
									</tbody>
								</table>
								<!--<div class="mdPopBtnB aR">
									<button type="button" class="btn btn-info btn-lg" onclick="fnPubCustListPopUp();" th:if="${mode == 'U'}">발급받은회원</button>
									<button type="button" class="btn btn-info btn-lg" onclick="fnCustomerIssuePopUp();" th:if="${mode == 'U' && cpnDetail.dcCdGb == 'G233_00'}">쿠폰발행</button>
									<button type="button" class="btn btn-info btn-lg" onclick="fnCouponCreate();" th:if="${mode == 'N'}">등록</button>
									<button type="button" class="btn btn-info btn-lg" onclick="fnCouponUpdate();" th:if="${mode == 'U'}">수정</button>
								</div>-->
							</div>
						</li>
						<!-- 쿠폰적용대상-->
						<li class="tab" id="coupontab2" >
							<div class="panelStyle">
								<div class="inner-panelContent">
									<div class="panelContent">
										<div class="panelBar">
											<h4>적용 대상 상품 등록</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
												<tr>
													<th>적용범위<em class="required" title="필수"></em></th>
													<td>
														<input type="hidden" name="applyScope" id="applyScope" required="required" data-valid-name="적용범위">
														<label class="rdoBtn"> <input type="radio" name="rdoApplyScope" value="A"/>전체</label>
														<label class="rdoBtn"> <input type="radio" name="rdoApplyScope" value="I"/>개별</label>
													</td>
												</tr>
												<tr class="supplyTrArea">
													<th>공급처</th>
													<td>
														<div class="padding10 inner-tb-solid">
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnSupplyAdd">공급처 추가</button>
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnSupplyDel">선택삭제</button>
															<br/>
															<div id="supplyGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
														</div>
													</td>
												</tr>
												<tr class="brandTrArea">
													<th>브랜드</th>
													<td>
														<div class="padding10 inner-tb-solid">
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnBrandAdd">브랜드 추가</button>
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnBrandDel">선택삭제</button>
															<br/>
															<div id="brandGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
														</div>
													</td>
												</tr>
												<tr class="categoryTrArea">
													<th>카테고리</th>
													<td>
														<div class="padding10 inner-tb-solid">
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnCateAdd">카테고리 추가</button>
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnCateDel">선택삭제</button>
															<br/>
															<div id="cateGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
														</div>
													</td>
												</tr>
												<tr class="goodsTrArea">
													<th>적용상품</th>
													<td>
														<div class="padding10 inner-tb-solid">
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnGoodsAdd">상품 추가</button>
															<button type="button" class="btn btnRight btn-success btn-lg" id="btnGoodsDel">선택삭제</button>
															<br/>
															<div id="goodsGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</div>
								<div class="inner-panelContent exceptArea">
									<div class="panelContent">
										<div class="panelBar">
											<h4>적용 대상 상품 등록</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
											<tr>
												<th>제외상품</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnExcepGoodsAdd">제외상품 추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnExcepGoodsDel">선택삭제</button>
														<br/>
														<div id="excepGoodsGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</li>
						<!-- 쿠폰적용대상끝-->
						<!-- 입점업체분담율-->
						<li class="tab" id="coupontab3">
							<div class="panelStyle">
								<div class="inner-panelContent">
									<div class="panelContent">
										<div class="panelBar">
											<h4>업체 분담율</h4>
										</div>
										<table class="frmStyle">
											<colgroup>
												<col style="width:15%;">
												<col style="width:85%;">
											</colgroup>
											<tbody>
											<tr>
												<th>업체 분담율</th>
												<td>
													<div class="padding10 inner-tb-solid">
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddApplyBurden">업체추가</button>
														<button type="button" class="btn btnRight btn-success btn-lg" id="btnDelApplyBurden">선택삭제</button>
														<br/>
														<div id="inComGridList" style="width:100%; height:200px;" class="ag-theme-balham"></div>
													</div>
												</td>
											</tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</li>
						<!-- 입점업체분담끝-->
						<!-- 난수 및 네임쿠폰 설정 -->
						<li class="tab" id="coupontab4">
							<div class="panelStyle">
								<span>
									<div id="randomCpnList" style="width: 100%; height: 500px" class="ag-theme-balham"></div>
								</span>
							</div>
						</li>
						<!-- 난수 및 네임쿠폰 설정-->
						<!-- 선착순 쿠폰 설정 START -->
						<li class="tab" id="coupontab5">
							<div class="panelStyle">
								<span class="limitedTimeCpnSpan">
									<button type="button" class="btn btnRight btn-success btn-lg" id="btnAddLimitedTimeCpnRow">행추가</button>
									<button type="button" class="btn btnRight btn-success btn-lg" id="btnDelLimitedTimeCpnRow">행삭제</button>
								</span>
								<br/>
								<div id="limitedTimeCpnList" style="width: 100%; height: 500px" class="ag-theme-balham"></div>
							</div>
						</li>
						<!-- 선착순 쿠폰 설정 END -->
					</ul>
				</div>
				<div class="mdPopBtnB aR">
					<button type="button" class="btn btn-info btn-lg" onclick="fnPubCustListPopUp();" th:if="${mode == 'U'}">발급받은회원</button>
					<button type="button" class="btn btn-info btn-lg" onclick="fnCustomerIssuePopUp();" th:if="${mode == 'U' and cpnDetail.dcCdGb == 'G233_00' and cpnDetail.cpnStat=='G232_11'}">쿠폰발행</button>  <!-- 난수유형과 시리얼 유형에서는 쿠폰발행기능 X -->
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponSave" onclick="fnCouponCreate();" th:text="${mode == 'N' ? '등록' : '수정'}"></button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnChangeStatIng" style="display: none;">진행</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponDelete" style="display: none;">삭제</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponStop" style="display: none;">중지</button>
					<button type="button" class="btn btnRight btn-success btn-lg couponButton" id="btnCouponEnd" style="display: none;">종료</button>
				</div>

			</form>
		</div>
	</div>
</div>
<script th:inline="javascript">
	/*<![CDATA[*/
	// 상세조회 리스트
	var mode = [[${mode}]];
	var cpnDetail = [[${cpnDetail}]];
	var cpnDtlRefvalSupplyCompList = [[${cpnDtlRefvalSupplyCompList}]];
	var cpnDtlRefvalApplyGoodsList = [[${cpnDtlRefvalApplyGoodsList}]];
	var cpnDtlRefvalCateList = [[${cpnDtlRefvalCateList}]];
	var cpnDtlRefvalBrandList = [[${cpnDtlRefvalBrandList}]];
	var cpnDtlRefvalExceptGoodsList = [[${cpnDtlRefvalExceptGoodsList}]];
	var cpnDtlBurdenList = [[${cpnDtlBurdenList}]];
	var randomCpnList = [[${randomCpnList}]];
	var issueCnt = [[${issueCnt}]];

	var cpnCustGbList = [[${cpnCustGbList}]];
	var cpnCustGradeList = [[${cpnCustGradeList}]];
	var cpnPayTypeList = [[${cpnPayTypeList}]];
	var limitedTimeCpnList = [[${limitedTimeCpnList}]];
	var afChannelList = [[${afChannelList}]];

	// 공통코드 리스트
	var ibSupplyComList = gagajf.convertToArray([[${ibSupplyCompList}]]);
	var formalGbList = gagajf.convertToArray([[${formalGbList}]]);
	var cateGbList = gagajf.convertToArray([[${cateGbList}]]);
	var delYnList = { "Y":"Yes", "N":"No" };
	var siteCdList = gagajf.convertToArray([[${siteCdList}]]);
	var selfBrandList = gagajf.convertToArray([[${selfBrandList}]]);
	let channelName = gagajf.convertToArray([[${channelList}]]);

	// ag-grid 입점업체분담율 컬럼
	var columnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "입점업체코드" , field:"supplyCompCd" , width:150, cellClass:"text-center"
			// cellEditor: 'agRichSelectCellEditor',
			// cellEditorParams: { values: gagaAgGrid.extractValues(ibSupplyComList) },
			// valueFormatter: function (params) { return gagaAgGrid.lookupValue(ibSupplyComList, params.value); },
			// valueParser: function (params) { return gagaAgGrid.lookupKey(ibSupplyComList, params.newValue);}
		} ,
		{ headerName: "입점업체명"  , field: "supplyCompNm" , width: 120 , cellClass: 'text-center'},
		{ headerName: "쿠폰분담율(%)", field:"burdenRate" , width:150, cellClass: "text-center" , required: true
			,valueFormatter: function(params) {
				if(params.value && params.value > 0) {
					if(params.value > 100){
						mcxDialog.alert('할인율은 100이하로 설정해주세요.');
						params.data.burdenRate = '0';
						return '0';
					}
					return params.value.addComma();
				} else {
					return '0';
				}
			},
			cellEditorParams: { maxlength: 4, validType: 'numeric'}
			// cellEditorParams: { maxlength: 10, required: true }
		} ,
		/*{ headerName: "삭제여부" , field: "delYn"  , width:150, cellClass: "text-center" ,
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(delYnList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(delYnList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(delYnList, params.newValue); }
		} ,*/
		{ headerName: "쿠폰번호"  , field: "cpnId" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 공급처 컬럼
	var supplyColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName : "공급업체코드" , field: "supplyCompCd" , width:150, cellClass: 'text-center'} ,
		{ headerName: "공급업체명" , field: "supplyCompNm" , width:150, cellClass: 'text-center'},
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 브랜드 컬럼
	var brandSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName : "브랜드ID" , field: "brandCd" , width: 120, cellClass : 'text-center'} ,
		{ headerName : "브랜드명" , field: "brandEnm" , width: 120, cellClass: 'text-center'} ,
		//{ headerName : "공급업체명", field: "supplyCompNm" , width: 150, cellClass: 'text-center' } ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 적용상품 컬럼
	var goodsSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "상품구분" , field: "goodsGb" , width: 100, cellClass: 'text-center'} ,
		{ headerName: "Product ID" , field: "goodsCd" , width: 120, cellClass: 'text-center'},
		{ headerName: "상품명"  , field: "goodsNm" , width: 250 , cellClass: 'text-center'} ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 카테고리 컬럼
	var cateSelColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "사이트" , field: "siteCd" , width: 100 , cellClass: 'text-center' ,
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(siteCdList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(siteCdList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(siteCdList, params.newValue); }
		},
		{ headerName: "카테고리구분" , field: "cateGb" , width: 100 , cellClass: 'text-center' ,
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(cateGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(cateGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(cateGbList, params.newValue); }
		},
		{ headerName: "카테고리코드" , field: "cateNo" , width: 100 , cellClass: 'text-center'} ,
		{ headerName: "카테고리명" , field: "cateNm" , width: 120 , cellClass: 'text-center'},
		{ headerName: "이월/정상구분" , field: "formalGb" , width: 120 , cellClass: 'text-center',
			cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(formalGbList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(formalGbList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(formalGbList, params.newValue); }
		},
		{ headerName: "브랜드명" , field:"brandCd" , width:150, cellClass: "text-center", required: true ,
			editable: true, cellEditor: 'agRichSelectCellEditor',
			cellEditorParams: { values: gagaAgGrid.extractValues(selfBrandList) },
			valueFormatter: function (params) { return gagaAgGrid.lookupValue(selfBrandList, params.value); },
			valueParser: function (params) { return gagaAgGrid.lookupKey(selfBrandList, params.newValue); }
		},
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 제외상품 컬럼
	var excepGoodsColumnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "상품구분" , field: "goodsGb" , width: 100, cellClass: 'text-center'} ,
		{ headerName: "Product ID" , field: "goodsCd" , width: 120, cellClass: 'text-center'},
		{ headerName: "상품명"  , field: "goodsNm" , width: 250 , cellClass: 'text-center'} ,
		{ headerName: "쿠폰대상일련번호"  , field: "cpnRefvalSq" , width: 120 , cellClass: 'text-center' , hide:true},
		{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
	];

	// ag-grid 시리얼 및 난수 리스트
	var randomCouponDefs = [
		{ headerName : "생성쿠폰키워드" , field: "rdCpnNm" , width:150, cellClass: 'text-center'} ,
		{ headerName: "지급고객번호" , field: "custNm" , width:150, cellClass: 'text-center'},
		{ headerName: "고객아이디" , field: "custId" , width:150, cellClass: 'text-center'},
		{ headerName: "고객명" , field: "custNm" , width:150, cellClass: 'text-center'},
		{ headerName: "지급일" , field: "regDt" , width:150, cellClass: 'text-center'},
		{ headerName: "쿠폰사용일" , field: "usedDt" , width:150, cellClass: 'text-center'}
	];

	// 선착순 쿠폰 리스트
	var limitedTimeCpnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "쿠폰시퀀스", field: "cpnId", width: 150, cellClass: 'text-center'},	//, hide: true
		{ headerName: "선착순쿠폰명" , field: "limitCpnNm" , width: 200, cellClass: 'text-center'
			,cellEditorParams: { maxlength: 20}
		} ,
		{ headerName: "시작일" , field: "downStDate" , width: 200, cellClass: 'text-center'
			,cellEditor: 'datePicker'
			,cellEditorParams: { maxlength: 10, required: true }
		},
		{ headerName: "시작시간" , field: "downStTime" , width: 200, cellClass: 'text-center'
			,cellEditor: 'dateTimer'
			,cellEditorParams: { maxlength: 8, required: true }
		},
		{ headerName: "종료일"  , field: "downEdDate" , width: 200 , cellClass: 'text-center'
			,cellEditor: 'datePicker'
			,cellEditorParams: { maxlength: 10, required: true }
		} ,
		{ headerName: "종료시간"  , field: "downEdTime" , width: 200 , cellClass: 'text-center'
			,cellEditor: 'dateTimer'
			,cellEditorParams: { maxlength: 8, required: true }
			// ,valueFormatter: function (params) {
			// 	params.value = params.value.replace(/[^0-9]/g, '');
			// 	params.value = params.value.substr(0,2)+':'+params.value.substr(2,2)+':59';
			// 	return params.value;
			// }
		} ,
		{ headerName: "다운로드가능수량"  , field: "downLimitQty" , width: 150 , cellClass: 'text-center'
			,cellEditorParams: { maxlength: 4, validType: 'numeric'}
		},
		{ headerName: "선착순시퀀스", field: "limitCpnId", width: 150, cellClass: 'text-center' , hide: true}
		,{ headerName: "삭제여부"  , field: "delYn" , width: 120 , cellClass: 'text-center' , hide:true}
		,{headerName: "시작일시", field: "downStdt", width: 150, cellClass: 'text-center' , hide:true}
		,{headerName: "종료일시", field: "downEddt", width: 150, cellClass: 'text-center' , hide:true}
	];

	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 inComGridOptions = gagaAgGrid.getGridOptions(columnDefs);
	var cateGridOptions = gagaAgGrid.getGridOptions(cateSelColumnDefs);
	var goodsGridOptions = gagaAgGrid.getGridOptions(goodsSelColumnDefs);
	var brandGridOptions = gagaAgGrid.getGridOptions(brandSelColumnDefs);
	var supplyGridOptions = gagaAgGrid.getGridOptions(supplyColumnDefs);
	var excepGoodsGridOptions = gagaAgGrid.getGridOptions(excepGoodsColumnDefs);
	var randomCouponGridOptions = gagaAgGrid.getGridOptions(randomCouponDefs);
	var limitedTimeCpnGridOptions = gagaAgGrid.getGridOptions(limitedTimeCpnDefs);
	// 제휴채널 그리드 설정
	var afLinkOptions = gagaAgGrid.getGridOptions(columnAfDefs);
	afLinkOptions.rowSelection = "multiple";
	afLinkOptions.suppressRowClickSelection = true;

	inComGridOptions.defaultColDef.editable = true;
	inComGridOptions.rowSelection = "multiple";
	goodsGridOptions.rowSelection = "multiple";
	supplyGridOptions.rowSelection = "multiple";
	excepGoodsGridOptions.rowSelection = "multiple";
	cateGridOptions.rowSelection = "multiple";
	brandGridOptions.rowSelection = "multiple";
	inComGridOptions.stopEditingWhenGridLosesFocus = true;
	limitedTimeCpnGridOptions.defaultColDef.editable = true;
	limitedTimeCpnGridOptions.rowSelection = "multiple";

	// 삭제버튼 클릭시
	// 1.공급업체
	$('#btnSupplyDel').on('click', function() {
		supplyGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(supplyGridOptions)});
	});
	// 2.브랜드
	$('#btnBrandDel').on('click', function() {
		brandGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(brandGridOptions)});
	});
	// 3.카테고리
	$('#btnCateDel').on('click', function() {
		cateGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(cateGridOptions)});
	});
	// 4.적용상품
	$('#btnGoodsDel').on('click', function() {
		goodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(goodsGridOptions)});
	});
	// 5.제외상품
	$('#btnExcepGoodsDel').on('click', function() {
		excepGoodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(excepGoodsGridOptions)});
	});
	// 업체분담율 선택삭제 버튼 클릭시
	$('#CouponForm #btnDelApplyBurden').on('click', function() {
		inComGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(inComGridOptions)});
	});
	// 7.선착순
	$('#btnDelLimitedTimeCpnRow').on('click', function() {
		limitedTimeCpnGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(limitedTimeCpnGridOptions)});
	});

	// 제휴채널 선택삭제 버튼 클릭시
	$('#btnDeleteAf').on('click', function() {
		afLinkOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(afLinkOptions)});
	});

	// 선착순 쿠폰 행추가
	$('#btnAddLimitedTimeCpnRow').on('click', function() {
		var data = { cpnId: 1 ,limitCpnNm: null, downStDate: _today, downStTime: '00:00:00', downEdDate: _today, downEdTime: '23:59:59', downLimitQty: null, limitCpnId: null, delYn: 'N' };
		gagaAgGrid.addRowData(limitedTimeCpnGridOptions, data, "limitCpnNm");
	});
	// 업체분담율 추가 버튼 클릭시
	$('#CouponForm #btnAddApplyBurden').on('click', function() {
		cfnOpenCompanyListPopup("fnSetPopupApplyBurdenInfo" ,"M");
	});

	// 선착순 쿠폰 행삭제
	/*$('#btnDelLimitedTimeCpnRow').on('click', function() {
		var selectedData = limitedTimeCpnGridOptions.api.getSelectedRows();
		if (selectedData.length == 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}
		var removedData = gagaAgGrid.removeRowData(limitedTimeCpnGridOptions, false);
		var arrLimitCpnId = [];

		$.each(selectedData, function(idx, item) {
			arrLimitCpnId.push(item.limitCpnId);
		});

		if (removedData.length > 0) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					var data = { arrLimitCpnId : arrLimitCpnId
						,cpnId : $('#CouponForm input[name=cpnId]').val()
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/limitedtime/coupon/update', jsonData);
				}
			});
		}
	});
	*/

	// 분담업체율 설정 / 업체 추가 콜백함수
	var fnSetPopupApplyBurdenInfo = function(result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(inComGridOptions);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(inComGridOptions, {"supplyCompCd" : result[i].supplyCompCd, "supplyCompNm" : result[i].supplyCompNm, "delYn" : result[i].delYn});
			}
		}
	};

	// 선착순 쿠폰 체크박스 클릭시
	$("#CouponForm #limitedTimeCpnBox").bind('click', function (){
		var chkBox= document.getElementById('limitedTimeCpnYn').checked;

		if(chkBox){	//true 체크가 되어있었는데 해제됐어 -> 탭을 숨겨
			$("#CouponForm .limitedTimeCpnTab").show();
			$("#limitedTimeCpnYn").val("Y");
			$("#CouponForm #totPubLimitQty").val(0);
			$("#CouponForm input[id=chkBoxTotPubQty]").prop("disabled", true);
			$("#CouponForm input[id=totPubLimitQty]").prop("disabled", true);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', true);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', true);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', true);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', true);
		}else{	//false 체크가 안되어있었는데 체크됐어 -> 탭을 보여줘
			$("#CouponForm .limitedTimeCpnTab").hide();
			$("#limitedTimeCpnYn").val("N");
			$("#CouponForm #totPubLimitQty").val(0);
			$("#CouponForm input[id=chkBoxTotPubQty]").prop("disabled", false);
			$("#CouponForm input[id=totPubLimitQty]").prop("disabled", false);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").removeClass("checked");
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', false);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', false);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', false);
			$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', false);
		}
	});

	// 종료시간 클릭시
	var fnChangeEdHH = function (obj){
		var selectId = obj.id;
		var changeId = "";
		if(selectId == "downEdHH"){
			changeId = "downEdMM";
		}else if(selectId == "availEdHH"){
			changeId = "availEdMM";
		}else if(selectId == "buyEdHH"){
			changeId = "buyEdMM";
		}else{
			changeId = "custJoinEdMM";
		}
		if(obj.value == 24) {
			$("#CouponForm #"+changeId+" option").hide();
			$('#CouponForm #'+changeId+' option:first').show().prop("selected", true);
		} else {
			$("#CouponForm #"+changeId+" option").show();
		}
	};

	// 총발행 제한수량 -> 제한없음 처리
	$("#CouponForm #chkBoxTotPubQty").bind('click', function (){
		var chkBox= document.getElementById('chkNoLimitTotPubLimitQty').checked;

		var cpnStat = $('#CouponForm input:radio[name="disCpnStat"]:checked').val();
		if(cpnStat=='G232_10'){
			if(chkBox){ //true 체크가 되어있었는데 해제됐어 -> 값0 inputbox disabled 해제
				$("#CouponForm #totPubLimitQty").val(0);
				$("#CouponForm input[id=totPubLimitQty]").prop("disabled", true);
				$("#CouponForm input[id=totPubLimitQty]").prop("readonly", true);
			}else{	//false 체크가 안되어있었는데 체크됐어 -> 값0 inputbox disabled
				$("#CouponForm #totPubLimitQty").val(0);
				$("#CouponForm input[id=totPubLimitQty]").prop("disabled", false);
				$("#CouponForm input[id=totPubLimitQty]").prop("readonly", false);
			}
		}

	});

	// 1인당발행 제한수량 -> 제한없음 처리
	$("#CouponForm #chkBoxCustPubQty").bind('click', function (){
		var chkBox= document.getElementById('chkNoLimitCustPubLimitQty').checked;
		var cpnStat = $('#CouponForm input:radio[name="disCpnStat"]:checked').val();
		if(cpnStat=='G232_10'){
			if(chkBox){ //true 체크가 되어있었는데 해제됐어 -> 값0 inputbox disabled 해제
				$("#CouponForm #custPubLimitQty").val(0);
				$("#CouponForm input[id=custPubLimitQty]").prop("disabled", true);
				$("#CouponForm input[id=custPubLimitQty]").prop("readonly", true);
			}else{	//false 체크가 안되어있었는데 체크됐어 -> 값0 inputbox disabled
				$("#CouponForm #custPubLimitQty").val(0);
				$("#CouponForm input[id=custPubLimitQty]").prop("disabled", false);
				$("#CouponForm input[id=custPubLimitQty]").prop("readonly", false);
			}
		}
	});

	// 할인방식 할인율 일때, 할인값 체크
	var fnDcValOnkeyUp = function (obj){
		var inputName = $(obj).attr("name");
		var rdoDcWay = $('#CouponForm input:radio[name="rdoDcWay"]:checked').val();
		var dcVal = $("#CouponForm input[name="+inputName+"]").val();
		if(rdoDcWay == "G240_11"){
			if(dcVal > 100){
				mcxDialog.alert('할인율은 100을 넘을수 없습니다.');
				$("#CouponForm input[name="+inputName+"]").val('');
				$("#CouponForm input[name="+inputName+"]").focus();
				return;
			}
		}
	}

	// 할인값 동일적용
	$("#applySameValueBtn").bind('click change', function () {
		var cdPval = $("#CouponForm input[name=dcPval]").val();
		$("#CouponForm input[name=dcMval]").val(cdPval);
		$("#CouponForm input[name=dcAval]").val(cdPval);
	});

	function checkValidation2(){
		// 쿠폰명 체크
		var chkCpnNm = $('#CouponForm input[name=cpnNm]').val();
		if(gagajf.isNull(chkCpnNm)){
			mcxDialog.alert("쿠폰명을 입력해주세요.");
			$('#CouponForm input[name=cpnNm]').focus();
			return false;
		}

		// 할인금액, 할인율 체크
		var chkDcPval = $('#CouponForm input[name=dcPval]').val();
		var chkDcMval = $('#CouponForm input[name=dcMval]').val();
		var chkDcAval = $('#CouponForm input[name=dcAval]').val();
		if(gagajf.isNull(chkDcPval) || chkDcPval < 1){
			mcxDialog.alert("할인값(PC)을 입력해주세요.");
			$('#CouponForm input[name=dcPval]').focus();
			return false;
		}
		if(gagajf.isNull(chkDcMval) || chkDcMval < 1){
			mcxDialog.alert("할인값(모바일웹)을 입력해주세요.");
			$('#CouponForm input[name=dcMval]').focus();
			return false;
		}
		if(gagajf.isNull(chkDcAval) || chkDcAval < 1){
			mcxDialog.alert("할인값(모바일앱)을 입력해주세요.");
			$('#CouponForm input[name=dcAval]').focus();
			return false;
		}

		if($('#CouponForm input:radio[name="rdoApplyScope"]:checked').val() == 'I'){
			// 적용대상 체크
			let targetCnt = 0;
			let target1 = gagaAgGrid.getAllRowData(supplyGridOptions);
			let target2 = gagaAgGrid.getAllRowData(brandGridOptions);
			let target3 = gagaAgGrid.getAllRowData(cateGridOptions);
			let target4 = gagaAgGrid.getAllRowData(goodsGridOptions);

			targetCnt = target1.length + target2.length + target3.length + target4.length;
			if(targetCnt < 1){
				mcxDialog.alert("적용대상을 설정해주세요.");
				return false;
			}
		}

		return true;
	}

	// 즉시할인쿠폰일때 데이터 validation 체크
	var checkValidation10 = function (){
		var stdt = $('#CouponForm #availStDay').val();
		var eddt = $('#CouponForm #availEdDay').val();
		if(gagajf.isNull(stdt)){
			mcxDialog.alert("유효기간 시작일시를 입력해주세요.");
			return false;
		}
		if(gagajf.isNull(eddt)){
			mcxDialog.alert("유효기간 종료일시를 입력해주세요.");
			return false;
		}
		if(stdt>eddt){
			mcxDialog.alert("시작일시가 종료일시보다 클 수 없습니다.");
			return false;
		}

		return true;
	}

	var checkValidation20 = function (cpnType){
		// 사용가능고객구분 체크박스 체크
		var usableCustGbCnt = $('#CouponForm input:checkbox[name=usableCustGbArr]:checked').length;
		if(usableCustGbCnt<1){
			mcxDialog.alert("사용가능 고객구분을 체크해주세요.");
			$('#CouponForm input:checkbox[name=usableCustGbArr]').focus();
			return false;
		}
		// 사용가능고객등급 체크박스 체크
		var usableCustGradeCnt = $('#CouponForm input:checkbox[name=usableCustGradeArr]:checked').length;
		if(usableCustGradeCnt<1){
			mcxDialog.alert("사용가능 고객등급을 체크해주세요.");
			$('#CouponForm input:checkbox[name=usableCustGradeArr]').focus();
			return false;
		}

		if(cpnType == 'G230_20'){
			// 결제수단 체크박스 체크
			var payTypeCnt = $('#CouponForm input:checkbox[name=payTypeArr]:checked').length;
			if(payTypeCnt<1){
				mcxDialog.alert("결제수단을 체크해주세요.");
				$('#CouponForm input:checkbox[name=payTypeArr]').focus();
				return false;
			}
		}

		if($('#CouponForm select[name="pdGb"] option:selected').val() == 'D'){
			if(gagajf.isNull($("#availDays").val()) || $("#availDays").val() < 1){
				mcxDialog.alert("유효기간 일수를 입력해주세요.");
				$('#CouponForm input[name=availDays]').focus();
				return false;
			}
		}

		//다운로드일시 validation 체크
		var downFromDate = $('#CouponForm input[name=downStDay]').val();
		var downToDate = $('#CouponForm input[name=downEdDay]').val();

		if (gagajf.isNull(downFromDate) || gagajf.isNull(downToDate)) {
			mcxDialog.alertC("다운로드 시작일자와 종료일자를 입력하세요.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$('#CouponForm input[name=downStDay]').focus();
				}
			});
			return false;
		}

		if (downFromDate > downToDate) {
			mcxDialog.alertC("다운로드 시작일자는 종료일자 보다 클 수 없습니다.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$('#CouponForm input[name=downEdDay]').focus();
				}
			});
			return false;
		}

		//신규가입 지급한다면 validation 체크
		if( $('#newCustYn option:selected').val() == "Y" ){
			var fromDate = $('#CouponForm input[name=custJoinStDay]').val();
			var toDate = $('#CouponForm input[name=custJoinEdDay]').val();

			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("신규가입기간 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=custJoinStDay]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("등록 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=custJoinEdDay]').focus();
					}
				});
				return false;
			}
		}

		// 첫구매 지급하면 validation 체크
		if( $('#firstOrdYn option:selected').val() == "Y" ){
			var fromDate = $('#CouponForm input[name=buyStDay]').val();
			var toDate = $('#CouponForm input[name=buyEdDay]').val();

			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("신규가입기간 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=buyStDay]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("등록 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=buyEdDay]').focus();
					}
				});
				return false;
			}
		}

		// 할인율 validation 체크 (100을 넘길수없음)
		if($('#dcWay').val() == 'G240_11') {
			if($('#dcPval').val() > 100) {
				mcxDialog.alert('PC할인율은 100을 초과할수없습니다.');
				$('#dcPval').focus();
				return false;
			} else if( $('#dcMval').val() > 100) {
				mcxDialog.alert('모바일(웹)할인율은 100을 초과할수없습니다.');
				$('#dcMval').focus();
				return false;
			}  else if( $('#dcAval').val() > 100) {
				mcxDialog.alert('모바일(앱)할인율은 100을 초과할수없습니다.');
				$('#dcAval').focus();
				return false;
			}
		}

		// 할인쿠폰 유형에 따른 총 발행수량 수정 (주문서 쿠폰이고 난수쿠폰일 경우)
		if($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_20") {
			if($("#CouponForm input[name=randomCpnQty]").val() == "" || $("#CouponForm input[name=randomCpnQty]").val() < 1) {
				mcxDialog.alert('쿠폰의 발급 수량을 입력해주세요.');
				$("#CouponForm input[name=randomCpnQty]").focus();
				return false;
			}
			if($("#CouponForm input[name=randomCpnQty]").val() > 10000) {
				mcxDialog.alert('쿠폰의 발급 수량은 10000장을 초과할 수 없습니다.');
				$("#CouponForm input[name=randomCpnQty]").focus();
				return false;
			}

		} else if ($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_10") {		// 주문서 쿠폰이고 시리얼 유형일 경우
			if($("#CouponForm input[name=serialCpnNm]").val().length > 10) {
				mcxDialog.alert('시리얼쿠폰키워드는 10글자를 넘을 수 없습니다.');
				$("#CouponForm input[name=serialCpnNm]").focus();
				return false;
			}
			if($("#CouponForm input[name=serialCpnQty]").val() == "" || $("#CouponForm input[name=serialCpnQty]").val() < 1) {
				mcxDialog.alert('쿠폰의 발급 수량을 입력해주세요.');
				$("#CouponForm input[name=serialCpnQty]").focus();
				return false;
			}
			if($("#CouponForm input[name=randomCpnQty]").val() > 10000) {
				mcxDialog.alert('쿠폰의 발급 수량은 10000장을 초과할 수 없습니다.');
				$("#CouponForm input[name=serialCpnQty]").focus();
				return false;
			}
		} else if ($('#CouponForm #cpnType').val() == "G230_11" && $("#limitedTimeCpnYn").val() == "Y") {	// 상품쿠폰이고 선착순쿠폰 체크되어 있을때
			let cpnData = gagaAgGrid.getAllRowData(limitedTimeCpnGridOptions);
			if(cpnData.length < 1){
				mcxDialog.alert("선착순 쿠폰을 설정해주세요.");
				return false;
			}else{
				for(i=0; i<cpnData.length; i++){

					if(gagajf.isNull(cpnData[i].limitCpnNm)){
						mcxDialog.alert(i+1 + "번 행의 선착순 쿠폰명을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downStDate)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드시작일을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downEdDate)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드시작일을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downStTime)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드시작일을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downEdTime)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드종료일을 입력해주세요.");
						return false;
					}
					//
					// cpnData[i].downStDt = (cpnData[i].downEdDate).replace(/[^0-9]/g, '') + (cpnData[i].downStTime).replace(/[^0-9]/g, '');
					// var stdt = (cpnData[i].downEdDate).replace(/[^0-9]/g, '') + (cpnData[i].downStTime).replace(/[^0-9]/g, '');
					// console.log('cpnData[i].downStDt>>'+cpnData[i].downStDt);
					//
					// var eddt = '';
					// if(gagajf.isNull(cpnData[i].downEdTime)){
					// 	mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드종료일을 입력해주세요.");
					// 	return false;
					// }else{
					// 	var tempEddt = cpnData[i].downEdTime.replace(/[^0-9]/g, '');
					// 	console.log('tempEddt>>'+tempEddt.substr(0,4));
					// 	if(tempEddt.substr(0,4) == '0000'){
					// 		tempEddt = cpnData[i].downEdDate.replace(/[^0-9]/g, '') +'235959';
					// 		cpnData[i].downEdDt = tempEddt;
					// 		eddt = tempEddt;
					// 	}else{
					// 		cpnData[i].downEdDt = (cpnData[i].downEdDate).replace(/[^0-9]/g, '') + (cpnData[i].downEdTime).replace(/[^0-9]/g, '');
					// 		eddt = (cpnData[i].downEdDate).replace(/[^0-9]/g, '') + (cpnData[i].downEdTime).replace(/[^0-9]/g, '');
					// 	}
					// }
					// console.log('cpnData[i].downEdDt>>'+cpnData[i].downEdDt);

					if(gagajf.isNull(cpnData[i].downLimitQty)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드가능수량을 입력해주세요.");
						return false;
					}else{
						if(cpnData[i].downLimitQty<1){
							mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드가능수량을 1개이상 입력해주세요.");
							return false;
						}
					}
				}
				limitedTimeCpnGridOptions.api.setRowData(cpnData);
			}
		}

		var chkLimitCpnCnt = document.getElementById('chkNoLimitTotPubLimitQty').checked;
		if(!chkLimitCpnCnt){
			let cnt = $("#CouponForm").find("[name=totPubLimitQty]").val();
			if(cnt < 1){
				mcxDialog.alert("총발행 제한수량은 0보다 커야합니다.");
				return false;
			}
		}

		var chkCustLimitCpnCnt = document.getElementById('chkNoLimitCustPubLimitQty').checked;
		if(!chkCustLimitCpnCnt){
			let cnt = $("#CouponForm").find("[name=custPubLimitQty]").val();
			if(cnt < 1){
				mcxDialog.alert("1인당 발행 제한수량은 0보다 커야합니다.");
				return false;
			}
		}

		var chkIssueCnt = $("#CouponForm").find("[name=onePubQty]").val();
		if(chkIssueCnt < 1){
			mcxDialog.alert("1회발행 제한수량은 0보다 커야합니다.");
			return false;
		}

		return true;
	}

	// 분담율 합 체크
	var fnBurdenValueCheck = function (){
		let burdenData = gagaAgGrid.getAllRowData(inComGridOptions);
		let totalValue = 0;
		$.each(burdenData, function(idx, item) {
			totalValue += parseInt(item.burdenRate);
		});

		if(totalValue > 100) {
			mcxDialog.alert("업체분담율의 합이 100을 넘을수 없습니다.");
			return false;
		}

		return true;
	};

	// 쿠폰 등록
	function fnCouponCreate(){
		// 필수값들 셋팅
		setReqValue();

		// 데이터 validation 체크
		if(!checkValidation2()) {
			return false;
		}

		var chkCpnType = $("#CouponForm input[name=rdoCpnType]:checked").val();
		if(chkCpnType != 'G230_10'){	// 즉시할인쿠폰제외
			if(!checkValidation20(chkCpnType)){
				return false;
			}
		}

		// 유효기간 체크
		if(!checkValidation10()){
			return false;
		}

		// 업체분담율 토탈 100% 넘는지 체크
		if(!fnBurdenValueCheck()) {
			return false;
		}

		mcxDialog.confirm('저장하시겠습니까?' , {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function () {
				var usableCustGbArr = [];
				var chkCustGb  = $('#CouponForm input:checkbox[name=usableCustGbArr]:checked');
				for(let i=0; i< chkCustGb.length; i++){
					usableCustGbArr.push(chkCustGb.eq(i).val());
				}

				var usableCustGradeArr = [];
				var chkCustGrade = $('#CouponForm input:checkbox[name=usableCustGradeArr]:checked');
				for(let i=0; i< chkCustGrade.length; i++){
					usableCustGradeArr.push(chkCustGrade.eq(i).val());
				}

				var payTypeArr = [];
				var chkPayType = $('#CouponForm input:checkbox[name=payTypeArr]:checked');
				for(let i=0; i< chkPayType.length; i++){
					payTypeArr.push(chkPayType.eq(i).val());
				}

				var data = {
					cpnId : $('#CouponForm input[name=cpnId]').val()
					,cpnNm : $('#CouponForm input[name=cpnNm]').val()
					,cpnDesc : $('#CouponForm input[name=cpnDesc]').val()
					,siteCd : $('#CouponForm select[name=siteCd]').val()
					// ,afLinkCd : $('#CouponForm select[name=afLinkCd]').val()
					,cpnType : $('input:radio[name="rdoCpnType"]:checked').val()
					,applyScope : $('input:radio[name="rdoApplyScope"]:checked').val()
					,dcWay : $('input:radio[name="rdoDcWay"]:checked').val()
					,dcPval : $('#CouponForm input[name=dcPval]').val().replaceAll(',','')
					,dcMval : $('#CouponForm input[name=dcMval]').val().replaceAll(',','')
					,dcAval : $('#CouponForm input[name=dcAval]').val().replaceAll(',','')
					,maxDcAmt : $('#CouponForm input[name=maxDcAmt]').val().replaceAll(',','')
					,pdGb : $('#CouponForm select[name=pdGb]').val()
					,availStdt : $('#CouponForm input[name=availStdt]').val()
					,availEddt : $('#CouponForm input[name=availEddt]').val()
					,availDays : $('#CouponForm input[name=availDays]').val().replaceAll(',','')
					,custPubLimitQty : $('#CouponForm input[name=custPubLimitQty]').val().replaceAll(',','')
					,totPubLimitQty : $('#CouponForm input[name=totPubLimitQty]').val().replaceAll(',','')
					,onePubQty : $('#CouponForm input[name=onePubQty]').val().replaceAll(',','')
					,downStdt : $('#CouponForm input[name=downStdt]').val()
					,downEddt : $('#CouponForm input[name=downEddt]').val()
					,buyLimitAmt : $('#CouponForm input[name=buyLimitAmt]').val().replaceAll(',','')
					,cpnStat : $('input:radio[name="disCpnStat"]:checked').val()
					,endAlimYn : $('#CouponForm select[name=endAlimYn]').val()
					,firstOrdYn : $('#CouponForm select[name=firstOrdYn]').val()
					,downAblYn : $('#CouponForm select[name=downAblYn]').val()
					,custJoinStdt : $('#CouponForm input[name=custJoinStdt]').val()
					,custJoinEddt : $('#CouponForm input[name=custJoinEddt]').val()
					,buyStdt : $('#CouponForm input[name=buyStdt]').val()
					,buyEddt : $('#CouponForm input[name=buyEddt]').val()
					,newCustYn : $('#CouponForm select[name=newCustYn]').val()
					// ,afChannel : $('#CouponForm select[name=afChannel]').val()
					,dcCdGb : $('input:radio[name="dcCdGb"]:checked').val()
					,rdCpnNm : $('input[name="serialCpnNm"]').val()
					,supplyCompList : gagaAgGrid.getAllRowData(supplyGridOptions)
					,brandList : gagaAgGrid.getAllRowData(brandGridOptions)
					,applyGoodsList : gagaAgGrid.getAllRowData(goodsGridOptions)
					,exceptGoodsList : gagaAgGrid.getAllRowData(excepGoodsGridOptions)
					,cateList : gagaAgGrid.getAllRowData(cateGridOptions)
					,burdenList : gagaAgGrid.getAllRowData(inComGridOptions)
					,usableCustGbArr : usableCustGbArr
					,usableCustGradeArr : usableCustGradeArr
					,payTypeArr : payTypeArr
					,limitedTimeCpnList : gagaAgGrid.getAllRowData(limitedTimeCpnGridOptions)
					,afChannelList : gagaAgGrid.getAllRowData(afLinkOptions)
					,mode : $('#CouponForm input[name=mode]').val()
					,scmYn : 'N'
				};
				var jsonData = JSON.stringify(data);
				gagajf.ajaxJsonSubmit($('#CouponForm').prop('action'), jsonData, fnCouponSaveCollback);
			}
		});
	}

	var fnCouponSaveCollback = function (result){
		uifnPopupClose('CouponRegForm');
		$('#btnSearch').trigger('click');
	}

	// 쿠폰 수정 시
	function fnCouponUpdate(){
		mcxDialog.confirm('수정하시겠습니까?' , {
			cancelBtnText:"취소",
			sureBtnText:"확인",
			sureBtnClick: function () {
				gagajf.removeCommaAtNumberFormattedInput('#CouponForm');
				// disabled 해제
				$("#CouponForm * ").attr("readonly" , false);
				$("#CouponForm * ").prop("disabled" , false);
				// 필수값들 셋팅
				setReqValue();
				// 필수값 validation 체크
				if (!gagajf.validation('#CouponForm')) {
					return false;
				}
				if(!checkValidation()) {
					return false;
				}

				gagajf.ajaxFormSubmit($('#CouponForm').prop('action'), '#CouponForm', function() {
					uifnPopupClose('CouponRegForm');
					$('#btnSearch').trigger('click');
				});
			}
		});
	}
	// disabled 해제
	function setDisabledFalse(){ //debugger;


	}

	function checkValidation(){
		// 사용가능고객구분 체크박스 체크
		var usableCustGbCnt = $('#CouponForm input:checkbox[name=usableCustGbArr]').length;
		if(usableCustGbCnt<1){
			mcxDialog.alert("사용가능고객구분을 체크해주세요.");
			$('#CouponForm input:checkbox[name=usableCustGbArr]').focus();
			return false;
		}
		// 사용가능고객등급 체크박스 체크
		var usableCustGradeCnt = $('#CouponForm input:checkbox[name=usableCustGradeArr]').length;
		if(usableCustGradeCnt<1){
			mcxDialog.alert("사용가능고객등급을 체크해주세요.");
			$('#CouponForm input:checkbox[name=usableCustGradeArr]').focus();
			return false;
		}
		// 결제수단 체크박스 체크
		var payTypeCnt = $('#CouponForm input:checkbox[name=payTypeArr]').length;
		if(payTypeCnt<1){
			mcxDialog.alert("사용가능고객등급을 체크해주세요.");
			$('#CouponForm input:checkbox[name=payTypeArr]').focus();
			return false;
		}

		//신규가입 지급한다면 validation 체크
		if( $('#newCustYn option:selected').val() == "Y" ){
			var fromDate = $('#CouponForm input[name=custJoinStdt]').val();
			var toDate = $('#CouponForm input[name=custJoinEddt]').val();

			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("신규가입기간 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=custJoinStdt]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("등록 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=custJoinEddt]').focus();
					}
				});
				return false;
			}
		}

		// 첫구매 지급하면 validation 체크
		if( $('#firstOrdYn option:selected').val() == "Y" ){
			var fromDate = $('#CouponForm input[name=buyStdt]').val();
			var toDate = $('#CouponForm input[name=buyEddt]').val();

			if (gagajf.isNull(fromDate) || gagajf.isNull(toDate)) {
				mcxDialog.alertC("신규가입기간 시작일자와 종료일자를 입력하세요.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=buyStdt]').focus();
					}
				});
				return false;
			}

			if (fromDate > toDate) {
				mcxDialog.alertC("등록 시작일자는 종료일자 보다 클 수 없습니다.", {
					sureBtnText: "확인",
					sureBtnClick: function() {
						$('#CouponForm input[name=buyEddt]').focus();
					}
				});
				return false;
			}
		}

		// 할인율 validation 체크 (100을 넘길수없음)
		if($('#dcWay').val() == 'G240_11') {
			if($('#dcPval').val() > 100) {
				mcxDialog.alert('PC할인율은 100을 초과할수없습니다.');
				$('#dcPval').focus();
				return false;
			} else if( $('#dcMval').val() > 100) {
				mcxDialog.alert('모바일(웹)할인율은 100을 초과할수없습니다.');
				$('#dcMval').focus();
				return false;
			}  else if( $('#dcAval').val() > 100) {
				mcxDialog.alert('모바일(앱)할인율은 100을 초과할수없습니다.');
				$('#dcAval').focus();
				return false;
			}
		}

		// 할인쿠폰 유형에 따른 총 발행수량 수정 (주문서 쿠폰이고 난수쿠폰일 경우)
		if($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_20") {
			if($("#CouponForm input[name=randomCpnQty]").val() == "" || $("#CouponForm input[name=randomCpnQty]").val() < 1) {
				mcxDialog.alert('쿠폰의 발급 수량을 입력해주세요.');
				$("#CouponForm input[name=randomCpnQty]").focus();
				return false;
			}
			if($("#CouponForm input[name=randomCpnQty]").val() > 10000) {
				mcxDialog.alert('쿠폰의 발급 수량은 10000장을 초과할 수 없습니다.');
				$("#CouponForm input[name=randomCpnQty]").focus();
				return false;
			}

		} else if ($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_10") {		// 주문서 쿠폰이고 시리얼 유형일 경우
			if($("#CouponForm input[name=serialCpnNm]").val().length > 10) {
				mcxDialog.alert('시리얼쿠폰키워드는 10글자를 넘을 수 없습니다.');
				$("#CouponForm input[name=serialCpnNm]").focus();
				return false;
			}
			if($("#CouponForm input[name=serialCpnQty]").val() == "" || $("#CouponForm input[name=serialCpnQty]").val() < 1) {
				mcxDialog.alert('쿠폰의 발급 수량을 입력해주세요.');
				$("#CouponForm input[name=serialCpnQty]").focus();
				return false;
			}
			if($("#CouponForm input[name=randomCpnQty]").val() > 10000) {
				mcxDialog.alert('쿠폰의 발급 수량은 10000장을 초과할 수 없습니다.');
				$("#CouponForm input[name=serialCpnQty]").focus();
				return false;
			}
		} else if ($('#CouponForm #cpnType').val() == "G230_11" && $("#limitedTimeCpnYn").val() == "Y") {	// 상품쿠폰이고 선착순쿠폰 체크되어 있을때
			let cpnData = gagaAgGrid.getAllRowData(limitedTimeCpnGridOptions);
			if(cpnData.length < 1){
				mcxDialog.alert("선착순 쿠폰을 설정해주세요.");
				return false;
			}else{
				for(i=0; i<cpnData.length; i++){

					if(gagajf.isNull(cpnData[i].limitCpnNm)){
						mcxDialog.alert(i+1 + "번 행의 선착순 쿠폰명을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downStdt)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드시작일을 입력해주세요.");
						return false;
					}

					if(gagajf.isNull(cpnData[i].downEddt)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드종료일을 입력해주세요.");
						return false;
					}else{
						var tempEddt = cpnData[i].downEddt.replace(/[^0-9]/g, '');
						if(tempEddt.substr(8,14) == '000000'){
							tempEddt = tempEddt.substr(0,8)+'235959';
							cpnData[i].downEddt = tempEddt;
						}
					}

					if(gagajf.isNull(cpnData[i].downLimitQty)){
						mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드가능수량을 입력해주세요.");
						return false;
					}else{
						if(cpnData[i].downLimitQty<1){
							mcxDialog.alert(i+1 + "번 행의 선착순쿠폰 다운로드가능수량을 1개이상 입력해주세요.");
							return false;
						}
					}
				}
				limitedTimeCpnGridOptions.api.setRowData(cpnData);
			}
		}

		return true;
	}

	// 할인방식 변경
	$("#CouponForm input[name=rdoDcWay]").bind('click change', function () {
		var radioValue = $(this).val();
		//발급이력이있으면 수정안됨
		if(issueCnt > 0 ) {
			return false;
		}

		if(radioValue == 'G240_10') {		//할인금액
			$('#dcPvalSpan').text("원");
			$('#dcMvalSpan').text("원");
			$('#dcAvalSpan').text("원");
			$('#dcPval').val(0);
			$('#dcMval').val(0);
			$('#dcAval').val(0);
			$('#maxDcAmt').val(0);
			// if($("#CouponForm input[name=rdoCpnType]:checked").val() == 'G230_10'){
			// 	$("#CouponForm .maxDcAmtArea").hide();
			// }else{
			// 	$("#CouponForm .maxDcAmtArea").show();
			// }
			$("#CouponForm .maxDcAmtArea").hide();
		} else {		//할인율
			$('#dcPvalSpan').text("%");
			$('#dcMvalSpan').text("%");
			$('#dcAvalSpan').text("%");
			$('#dcPval').val(0);
			$('#dcMval').val(0);
			$('#dcAval').val(0);
			$('#maxDcAmt').val(0);

			if($("#CouponForm input[name=rdoCpnType]:checked").val() == 'G230_10'){
				$("#CouponForm .maxDcAmtArea").hide();
			}else{
				$("#CouponForm .maxDcAmtArea").show();
			}
		}
	});

	// 쿠폰 상태 변경
	$("#CouponForm input[name=rdoCpnType]").bind('click change', function () {
		var radioValue = $(this).val();

		if(mode == "U") {
			radioValue = cpnDetail.cpnType;
		}

		// 즉시할인아닌 쿠폰들 할인금액체크시 최대할인금액 숨김
		var rdoDcWayVal = $("#CouponForm input[name=rdoDcWay]:checked").val();

		// 즉시할인쿠폰일때 유효기간 노출, 그외 유효기간/일수 선택
		var pgGbVal = $('#CouponForm select[name="pdGb"] option:selected').val();
		if(pgGbVal == 'P') {	//기간
			$('#CouponForm .availDaysArea').hide();
			$('#CouponForm .availDateTr').show();
		}else{	//일수
			$('#CouponForm .availDateTr').hide();
			$('#CouponForm .availDaysArea').show();
		}

		// 즉시할인 쿠폰일때
		if(radioValue == 'G230_10'){
			$('#CouponForm .custJoinTr').hide();
			$('#CouponForm .custJoinDateTr').hide();
			$('#CouponForm .firstBuyTr').hide();
			$('#CouponForm .buyDateTr').hide();
			$('#CouponForm .dcCdCheck1').hide();
			$('#CouponForm .limitedTimeCpnArea').hide();
			$('#CouponForm .pdGbArea').hide();
			$('#CouponForm .availDaysArea').hide();
			// $("#CouponForm").find("input:radio[name='rdoApplyScope']:radio[value='A']").attr('disabled', true);
			// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
			$('#CouponForm .downStdtArea').hide();
			$('#CouponForm .downEddtArea').hide();
			$('#CouponForm .pdGbArea').hide();
			$('#CouponForm .buyLimitAmtArea').hide();
			$('#CouponForm .usableCustGbArea').hide();
			$('#CouponForm .usableCustGradeArea').hide();
			$('#CouponForm .downAblArea').hide();
			$('#CouponForm .linkAfArea').hide();
			$('#CouponForm .dcCdCheck2').hide();
			$('#CouponForm .maxDcAmtArea').hide();
			$('#CouponForm .availDateTr').show();
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=I]").prop('checked', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', true);
		}else{
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=I]").prop('checked', true);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', false);
			$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', false);

			if(radioValue == 'G230_11'){ // 상품쿠폰일때 선착순쿠폰 등록 가능
				$('#CouponForm .limitedTimeCpnArea').show();
			}else{
				$('#CouponForm .limitedTimeCpnArea').hide();
			}

			if(radioValue == 'G230_30'){	// 배송비쿠폰일때 할인금액만 적용
				$("#CouponForm input:radio[name='rdoDcWay']:radio[value=G240_10]").prop('checked', true);
				$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('disabled', true);
				$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('readonly', true);
				$('#CouponForm .maxDcAmtArea').hide();
				// 적용대상 탭
				$("#CouponForm .supplyTrArea").show();
				$("#CouponForm .brandTrArea").hide();
				$("#CouponForm .categoryTrArea").hide();
				$("#CouponForm .goodsTrArea").hide();
				$("#CouponForm .exceptArea").hide();
			}else{
				$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('disabled', false);
				$("#CouponForm").find("input:radio[name='rdoDcWay']").attr('readonly', false);
				$('#CouponForm .maxDcAmtArea').show();
				// 적용대상 탭
				$("#CouponForm .supplyTrArea").show();
				$("#CouponForm .brandTrArea").show();
				$("#CouponForm .categoryTrArea").show();
				$("#CouponForm .goodsTrArea").show();
				$("#CouponForm .exceptArea").show();
			}

			$('#CouponForm .custJoinTr').show();
			$('#CouponForm .firstBuyTr').show();
			$('#CouponForm .dcCdCheck1').show();
			$('#CouponForm .pdGbArea').show();
			// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
			$('#CouponForm .downStdtArea').show();
			$('#CouponForm .downEddtArea').show();
			$('#CouponForm .buyLimitAmtArea').show();
			$('#CouponForm .usableCustGbArea').show();
			$('#CouponForm .usableCustGradeArea').show();
			$('#CouponForm .downAblArea').show();
			$('#CouponForm .linkAfArea').show();
			$('#CouponForm .dcCdCheck2').show();

			// 즉시할인아닌 쿠폰들 할인금액체크시 최대할인금액 숨김
			if(rdoDcWayVal == 'G240_10'){
				$('#CouponForm .maxDcAmtArea').hide();
			}else{
				$('#CouponForm .maxDcAmtArea').show();
			}
		}

		// 즉시할인쿠폰만 개별, 나머진 전체/개별
		if(radioValue == 'G230_10') {
			$("input:radio[name='rdoApplyScope']:radio[value='I']").prop('checked', true);
		} else {
			$("input:radio[name='rdoApplyScope']:radio[value='I']").prop('checked', true);
		}

		// 주문서 쿠폰 선택시 결제수단 노출
		if(radioValue == 'G230_20') {
			$('#CouponForm .payTypeTr').show();
			$('#CouponForm #payType').attr('required' , true);
			$("#CouponForm .dcCdGb").show();		// 할인쿠폰유형 노출
		} else {
			$('#CouponForm .payTypeTr').hide();
			$('#CouponForm #payType').attr('required' , false );
			$("#CouponForm .dcCdGb").hide();		// 할인쿠폰유형 숨김
			$("#CouponForm input:radio[name='dcCdGb']:radio[value='G233_00']").prop('checked', true);		// 주문서 쿠폰이 아닐 경우 일반 쿠폰으로 설정
		}

		// 선착순 쿠폰 비노출
		$("#CouponForm .limitedTimeCpnTab").hide();
		$('#CouponForm input:checkbox[name=limitedTimeCpnYn]').prop('checked', false);
		$("#limitedTimeCpnYn").val("N");
		$("#CouponForm #totPubLimitQty").val(0);
		$("#CouponForm input[id=chkBoxTotPubQty]").prop("disabled", false);
		$("#CouponForm input[id=totPubLimitQty]").prop("disabled", false);
		$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").removeClass("checked");
		$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', false);
		$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', false);
		$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', false);

		$('#CouponForm #cpnType').val(radioValue);
	});

	// 할인 쿠폰 유형 변경
	$("#CouponForm input[name=dcCdGb]").bind('click change', function () {
		if(this.value == "G233_00") {			// 일반 유형
			$("#CouponForm .dcCdCheck1").show();
			$("#CouponForm .dcCdCheck2").show();
			$("#CouponForm .serialCpnArea").hide();
			$("#CouponForm .randomCpnArea").hide();
			$("#CouponForm #newCustYn").parent().attr("colspan", "");
			$("#CouponForm .normalCol").attr("colspan", "5");
			$('#CouponForm input[name="serialCpnNm"]').attr('required' , false);
			$('#CouponForm input[name="serialCpnQty"]').attr('required' , false);
			$('#CouponForm input[name="randomCpnQty"]').attr('required' , false);
		} else {
			if(this.value == "G233_10") {		// 시리얼 유형
				$("#CouponForm .serialCpnArea").show();
				$("#CouponForm .randomCpnArea").hide();
				$("#CouponForm .normalCol").attr("colspan", "5");
				$('#CouponForm input[name="serialCpnNm"]').attr('required' , true);
				$('#CouponForm input[name="serialCpnQty"]').attr('required' , true);
				$('#CouponForm input[name="randomCpnQty"]').attr('required' , false);
			} else {							// 난수 유형
				$("#CouponForm .serialCpnArea").hide();
				$("#CouponForm .randomCpnArea").show();
				$("#CouponForm .normalCol").attr("colspan", "");
				$('#CouponForm input[name="serialCpnNm"]').attr('required' , false);
				$('#CouponForm input[name="serialCpnQty"]').attr('required' , false);
				$('#CouponForm input[name="randomCpnQty"]').attr('required' , true);
			}
			$("#CouponForm .dcCdCheck1").hide();								// 총발행제한수량, 1회발행수량, 1인당발행제한수량 숨김
			$("#CouponForm .dcCdCheck2").hide();								// 총발행제한수량, 1회발행수량, 1인당발행제한수량 숨김
			$("#CouponForm #newCustYn").parent().attr("colspan", "5");		// 총발행제한 수량을 없애면서 신규회원여부 colspan 수정
		}
	});

	// 적용대상 - 브랜드 추가 버튼시
	$('#btnBrandAdd').on('click' , function(){
		cfnOpenBrandListPopup("fnSetPopupBrandInfo", "M");
	});

	// 브랜드 설정 / 브랜드 추가 콜백함수 (단수로 가져오므로 복수일 경우에 수정 확인 필요)
	var fnSetPopupBrandInfo = function(result) {
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(brandGridOptions);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(brandGridOptions, {"brandCd" : result[i].brandCd, "brandEnm" : result[i].brandEnm, "supplyCompNm" : result[i].supplyCompNm});
			}
		}
	};

	// 적용대상 - 브랜드 삭제 버튼시
	/*$('#btnBrandDel').on('click' , function(){
		var selectVal = brandGridOptions.api.getSelectedRows();

		if(selectVal.length == 0) {
			mcxDialog.alert("선택된 행이 없습니다");
			return;
		}

		if(cpnDetail != null ) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagaAgGrid.removeRowData(brandGridOptions , false);
					var cpnRefvalSqArr = [];

					$.each(selectVal , function(idx , item){
						cpnRefvalSqArr.push(item.cpnRefvalSq);
					});
					var data = { cpnRefvalSqArr : cpnRefvalSqArr
						,cpnId : cpnDetail.cpnId
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/refval/update', jsonData);
				}
			});
		} else {
			// 신규화면이면 그리드상 삭제
			brandGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(brandGridOptions)});
		}
	});
	*/

	// 적용대상 - 공급처 추가 버튼시
	$('#btnSupplyAdd').on('click' , function (){
		cfnOpenCompanyListPopup("fnSetPopupComapnyInfo" , "M");
	});

	// 공급업체 설정 / 업체 추가 콜백함수
	var fnSetPopupComapnyInfo = function(result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(supplyGridOptions);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(supplyGridOptions, {"supplyCompCd" : result[i].supplyCompCd, "supplyCompNm" : result[i].supplyCompNm});
			}
		}
	};

	// 적용대상 - 공급처 삭제시시
	/*$('#btnSupplyDel').on('click' , function () {
		var selectVal = supplyGridOptions.api.getSelectedRows();

		if(selectVal.length == 0) {
			mcxDialog.alert("선택된 행이 없습니다");
			return;
		}

		if(cpnDetail != null ) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagaAgGrid.removeRowData(supplyGridOptions , false);
					var cpnRefvalSqArr = [];

					$.each(selectVal , function(idx , item){
						cpnRefvalSqArr.push(item.cpnRefvalSq);
					});

					var data = { cpnRefvalSqArr : cpnRefvalSqArr
						,cpnId : $('#CouponForm #cpnId').val()
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/refval/update', jsonData);
				}
			});
		} else {
			// 신규화면이면 그리드상 삭제
			supplyGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(supplyGridOptions)});
		}
	});*/

	// 적용대상 - 카테고리 추가시
	$('#btnCateAdd').on('click' , function () {
		cfnOpenCategoryPopup("fnSetPopupCategoryInfo");
	});

	// 카테고리 추가 콜백 함수
	var fnSetPopupCategoryInfo = function (result) {
		// 기존 리스트 데이터 for
		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(cateGridOptions);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(cateGridOptions, {"siteCd":result[i].siteCd , "cateGb":result[i].cateGb , "cateNo":result[i].cateNo, "cateNm":result[i].cateNm , "formalGb":result[i].formalGb , "brandEnm":null});
			}
		}
	}

	// 적용대상 - 카테고리 삭제시
	/*$('#btnCateDel').on('click' , function () {
		var selectVal = cateGridOptions.api.getSelectedRows();

		if(selectVal.length == 0) {
			mcxDialog.alert("선택된 행이 없습니다");
			return;
		}
		if(cpnDetail != null) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagaAgGrid.removeRowData(cateGridOptions , false);

					var cpnRefvalSqArr = [];

					$.each(selectVal , function(idx , item){
						cpnRefvalSqArr.push(item.cpnRefvalSq);
					});

					var data = { cpnRefvalSqArr : cpnRefvalSqArr
						,cpnId : $('#CouponForm #cpnId').val()
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/refval/update', jsonData);
				}
			});
		} else {
			cateGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(cateGridOptions)});
		}
	});
	*/

	// 적용대상 - 상품 추가시
	$('#btnGoodsAdd').on('click' , function () {
		cfnOpenGoodsPopup("fnSetPopupApplyGoodsInfo");
	});

	// 적용 상품 리스트 콜백함수
	var fnSetPopupApplyGoodsInfo = function(result) {
		gridAddGoodsList(goodsGridOptions, result , "apply");
	};

	// 적용대상 - 상품 삭제 시
	/*$('#btnGoodsDel').on('click' , function () {
		var selectVal = goodsGridOptions.api.getSelectedRows();

		if(selectVal.length == 0) {
			mcxDialog.alert("선택된 행이 없습니다");
			return;
		}
		if(cpnDetail != null ) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagaAgGrid.removeRowData(goodsGridOptions , false);
					var cpnRefvalSqArr = [];

					$.each(selectVal , function(idx , item){
						cpnRefvalSqArr.push(item.cpnRefvalSq);
					});
					var data = { cpnRefvalSqArr : cpnRefvalSqArr
						,cpnId : $('#CouponForm #cpnId').val()
					};

					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/refval/update', jsonData);
				}
			});
		} else {
			goodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(goodsGridOptions)});
		}
	});
	 */

	// 적용대상 - 제외상품 추가시
	$('#btnExcepGoodsAdd').on('click' , function(){
		cfnOpenGoodsPopup("fnSetPopupExceptGoodsInfo");
	});
	// 적용 상품 리스트 콜백함수
	var fnSetPopupExceptGoodsInfo = function(result) {
		gridAddGoodsList(excepGoodsGridOptions, result , "except");
	};

	// 적용대상 - 제외상품 삭제시
	/*$('#btnExcepGoodsDel').on('click' , function () {
		var selectVal = excepGoodsGridOptions.api.getSelectedRows();

		if(selectVal.length == 0) {
			mcxDialog.alert("선택된 행이 없습니다");
			return;
		}

		if(cpnDetail != null ) {
			mcxDialog.confirm('삭제하시겠습니까?', {
				cancelBtnText: "취소",
				sureBtnText: "확인",
				sureBtnClick: function(){
					gagaAgGrid.removeRowData(excepGoodsGridOptions , false);
					var cpnRefvalSqArr = [];

					$.each(selectVal , function(idx , item){
						cpnRefvalSqArr.push(item.cpnRefvalSq);
					});

					var data = { cpnRefvalSqArr : cpnRefvalSqArr
						,cpnId : $('#CouponForm #cpnId').val()
					};

					var jsonData = JSON.stringify(data);

					gagajf.ajaxJsonSubmit('/marketing/coupon/refval/update', jsonData);
				}
			});
		} else {
			excepGoodsGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(excepGoodsGridOptions)});
		}
	});
	*/

	// ag-grid 상품관련 list 콜백함수
	function gridAddGoodsList(OriginGridListOption, result, gubun) {
		var goodsGbVal = "G800_10";
		if(gubun == 'except'){
			goodsGbVal = "G800_30";
		}

		let addCnt = 0;
		let failCnt = 0;
		let dupliCnt = 0;

		for(let i = 0 ; i < result.length ; i++) {
			let addChk = true, gridListValue = gagaAgGrid.getAllRowData(OriginGridListOption);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(OriginGridListOption, {"goodsGb": goodsGbVal, "goodsCd" : result[i].goodsCd, "goodsNm" : result[i].goodsNm});
				addCnt++;
			}
		}
		uifnPopupClose('popupGoods');
		failCnt = result.length - addCnt - dupliCnt;
		mcxDialog.alert("데이터가 적용되었습니다.<br/>" + addCnt + "건 성공, "+ dupliCnt + "건 중복, " + failCnt + "건 실패");
	}

	// 기간 일수 변경시
	function pdGbChange(pThis){
		var selectVal = $(pThis).val();

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

		if(selectVal == "P") {
			$('.availDateTr').css('display' , '');
			$("#CouponForm .availDaysArea").hide();
			// $('.availDayTr').css('display' , 'none');
			$('#CouponForm #availDays').attr('required' , false);
			$('#CouponForm #availStDay').attr('required' , true);
			$('#CouponForm #availEdDay').attr('required' , true);
			$('#CouponForm #availStdt').attr('required' , true);
			$('#CouponForm #availEddt').attr('required' , true);
		} else {
			$('.availDateTr').css('display' , 'none');
			// $('.availDayTr').css('display' , '');
			$("#CouponForm .availDaysArea").show();
			$('#CouponForm #availDays').attr('required' , true);
			$('#CouponForm #availStDay').attr('required' , false);
			$('#CouponForm #availEdDay').attr('required' , false);
			$('#CouponForm #availStdt').attr('required' , false);
			$('#CouponForm #availEddt').attr('required' , false);
		}
	}

	// 첫구매여부 변경시
	function firstOrdYnChange(pThis){
		var selectVal = $(pThis).val();

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

		if(selectVal == "Y" ) {
			$('.buyDateTr').css('display' , '');
			$('#buyStdt').attr('required' , true);
			$('#buyEddt').attr('required' , true);
		} else {
			$('.buyDateTr').css('display' , 'none');
			$('#buyStdt').attr('required' , false);
			$('#buyEddt').attr('required' , false);
		}
	}

	// 신규회원여부 변경시
	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);
		}
	}

	// 행추가시
	$('#btnAddRow').on('click' , function(){
		var data = { supplyCompCd: null , burdenRate : null , delYn : 'N'};
		gagaAgGrid.addRowData(inComGridOptions , data , "supplyCompCd" );
	});
	// 행삭제시
	/*$('#btnDelRow').on('click' , function(){
		inComGridOptions.api.updateRowData({remove:gagaAgGrid.selectedRowData(inComGridOptions)});
	});*/

	// 제휴링크채널 수정 (제휴링크가 꼭필요한지 확인필요)
	// function fnChangeAfLinkCdList(){
	// 	var actionUrl = "/business/aflink/list" + '?' + $('#afChannel').serialize();
	// 	var tag = "";
	//
	// 	$("#CouponForm #afLinkCd").children('option').remove();
	//
	// 	gagajf.ajaxJsonSubmit(actionUrl, '', function(data) {
	// 		for (let i = 0; i < data.length; i++) {
	// 			if (data[i].useYn == 'Y') {
	// 				tag += '<option value="' + data[i].afLinkCd + '">[' + data[i].afLinkCd + '] ' + data[i].afLinkNm + '</option>';
	// 			}
	// 		}
	//
	// 		$("#CouponForm #afLinkCd").append(tag);
	// 		$("#CouponForm #afLinkCd option:first").attr("selected" , "selected");
	//
	// 	});
	// }

	// 발급받은회원 팝업
	var fnPubCustListPopUp = function (){
		let cpnId = $("#CouponForm #cpnId").val();
		var actionUrl = "/marketing/coupon/pubCust/popup/form?cpnId=" + cpnId;
		cfnOpenModalPopup(actionUrl, 'CpnPubCustListPopup');
	};

	// 쿠폰발행팝업
	function fnCustomerIssuePopUp(){
		cfnCpnPubForCustPopup();
	};

	// 전송시 값 세팅
	function setReqValue(){
		// 쿠폰유형값 세팅
		$('#CouponForm #cpnType').val($('#CouponForm input:radio[name="rdoCpnType"]:checked').val());
		// 할인방식값 세팅
		$('#CouponForm #dcWay').val($('#CouponForm input:radio[name="rdoDcWay"]:checked').val());
		// 적용범위값 세팅
		$('#CouponForm #applyScope').val($('#CouponForm input:radio[name="rdoApplyScope"]:checked').val());
		// 쿠폰상태
		$('#CouponForm input[name=cpnStat]').val($('input:radio[name="disCpnStat"]:checked').val());
		// 다운로드기간 세팅
		let downStdt = "";
		let downEddt = "";
		downStdt = $('#CouponForm input[name=downStDay]').val()+$('#CouponForm select[name=downStHH]').val()+$('#CouponForm select[name=downStMM]').val()+'00';
		if($('#CouponForm select[name=downEdHH]').val() == "24"){
			downEddt = $('#CouponForm input[name=downEdDay]').val()+'235959';
		}else{
			downEddt = $('#CouponForm input[name=downEdDay]').val()+$('#CouponForm select[name=downEdHH]').val()+$('#CouponForm select[name=downEdMM]').val()+'00';
		}
		downStdt = downStdt.replace(/[^0-9]/g, '');
		downEddt = downEddt.replace(/[^0-9]/g, '');
		$('#CouponForm #downStdt').val(downStdt);
		$('#CouponForm #downEddt').val(downEddt);

		// 유효기간 세팅
		let availStdt = "";
		let availEddt = "";
		if($("#CouponForm #pdGb").val() == 'P') {
			availStdt = $('#CouponForm input[name=availStDay]').val()+$('#CouponForm select[name=availStHH]').val()+$('#CouponForm select[name=availStMM]').val()+'00';
			if($('#CouponForm select[name=availEdHH]').val() == "24"){
				availEddt = $('#CouponForm input[name=availEdDay]').val()+'235959';
			}else{
				availEddt = $('#CouponForm input[name=availEdDay]').val()+$('#CouponForm select[name=availEdHH]').val()+$('#CouponForm select[name=availEdMM]').val()+'00';
			}
			availStdt = availStdt.replace(/[^0-9]/g, '');
			availEddt = availEddt.replace(/[^0-9]/g, '');
			$('#CouponForm #availStdt').val(availStdt);
			$('#CouponForm #availEddt').val(availEddt);
			$('#CouponForm #availDays').val('');
		} else {
			$('#CouponForm #availStdt').val('');
			$('#CouponForm #availEddt').val('');
		}

		// 첫구매기간세팅
		let buyStdt = "";
		let buyEddt = "";
		buyStdt = $('#CouponForm input[name=buyStDay]').val()+$('#CouponForm select[name=buyStHH]').val()+$('#CouponForm select[name=buyStMM]').val()+'00';
		if($('#CouponForm select[name=buyEdHH]').val() == "24"){
			buyEddt = $('#CouponForm input[name=buyEdDay]').val()+'235959';
		}else{
			buyEddt = $('#CouponForm input[name=buyEdDay]').val()+$('#CouponForm select[name=buyEdHH]').val()+$('#CouponForm select[name=buyEdMM]').val()+'00';
		}
		buyStdt = buyStdt.replace(/[^0-9]/g, '');
		buyEddt = buyEddt.replace(/[^0-9]/g, '');
		$('#CouponForm #buyStdt').val(buyStdt);
		$('#CouponForm #buyEddt').val(buyEddt);

		// 신규회원기간 세팅
		let custJoinStdt = "";
		let custJoinEddt = "";
		custJoinStdt = $('#CouponForm input[name=custJoinStDay]').val()+$('#CouponForm select[name=custJoinStHH]').val()+$('#CouponForm select[name=custJoinStMM]').val()+'00';
		if($('#CouponForm select[name=custJoinEdHH]').val() == "24"){
			custJoinEddt = $('#CouponForm input[name=custJoinEdDay]').val()+'235959';
		}else{
			custJoinEddt = $('#CouponForm input[name=custJoinEdDay]').val()+$('#CouponForm select[name=custJoinEdHH]').val()+$('#CouponForm select[name=custJoinEdMM]').val()+'00';
		}
		custJoinStdt = custJoinStdt.replace(/[^0-9]/g, '');
		custJoinEddt = custJoinEddt.replace(/[^0-9]/g, '');
		$('#CouponForm #custJoinStdt').val(custJoinStdt);
		$('#CouponForm #custJoinEddt').val(custJoinEddt);

		// 할인쿠폰 유형에 따른 총 발행수량 수정 (주문서 쿠폰이고 난수쿠폰일 경우)
		if($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_20") {
			$('#CouponForm input[name="totPubLimitQty"]').val($('#CouponForm input[name="randomCpnQty"]').val());	// 총 발행수량 난수 생성수량으로 변경
			$('#CouponForm input[name="custPubLimitQty"]').val(1);		// 1인당 발행제한수량 1개 고정
			$('#CouponForm input[name="onePubQty"]').val(1);			// 1회발행수량 1개 고정
		} else if ($('#CouponForm #cpnType').val() == "G230_20" && $('#CouponForm input:radio[name="dcCdGb"]:checked').val() == "G233_10") {		// 주문서 쿠폰이고 시리얼 유형일 경우
			$('#CouponForm input[name="rdCpnNm"]').val($('#CouponForm input[name="serialCpnNm"]').val());			// 시리얼유형쿠폰명 저장
			$('#CouponForm input[name="totPubLimitQty"]').val($('#CouponForm input[name="serialCpnQty"]').val());	// 총 발행수량 랜덤쿠폰발급수량으로 변경
			$('#CouponForm input[name="custPubLimitQty"]').val(1);		// 1인당 발행제한수량 1개 고정
			$('#CouponForm input[name="onePubQty"]').val(1);			// 1회발행수량 1개 고정
		}

		// 적용대상 - 공급처 그리드 전체값 세팅
		/*var supplyAllData = gagaAgGrid.getAllRowData(supplyGridOptions);
		var jsonSupplyCompData = JSON.stringify(supplyAllData);
		$('#CouponForm #supplyCompList').val(jsonSupplyCompData);*/
		$('#CouponForm #supplyCompList').val(gagaAgGrid.getAllRowData(supplyGridOptions));
		// 적용대상 - 브랜드 그리드 전체값 세팅
		/*var brandAllData = gagaAgGrid.getAllRowData(brandGridOptions);
		var jsonBrandData = JSON.stringify(brandAllData);
		$('#CouponForm #brandList').val(jsonBrandData);*/
		$('#CouponForm #brandList').val(gagaAgGrid.getAllRowData(brandGridOptions));
		// // 적용대상 - 카테고리 그리드 전체값 세팅
		/*var cateAllData = gagaAgGrid.getAllRowData(cateGridOptions);
		var jsonCateData = JSON.stringify(cateAllData);
		$('#CouponForm #cateList').val(jsonCateData);*/
		$('#CouponForm #cateList').val(gagaAgGrid.getAllRowData(cateGridOptions));
		// 적용대상 - 적용상품 그리드 전체값 세팅
		/*var goodsAllData = gagaAgGrid.getAllRowData(goodsGridOptions);
		var jsonGoodsData = JSON.stringify(goodsAllData);
		$('#CouponForm #applyGoodsList').val(jsonGoodsData);*/
		$('#CouponForm #applyGoodsList').val(gagaAgGrid.getAllRowData(goodsGridOptions));
		// 적용대상 - 제외상품 그리드 전체값 세팅
		/*var exceptGoodsAllData = gagaAgGrid.getAllRowData(excepGoodsGridOptions);
		var jsonExceptGoodsData = JSON.stringify(exceptGoodsAllData);
		$('#CouponForm #excepGoodsList').val(jsonExceptGoodsData);*/
		$('#CouponForm #excepGoodsList').val(gagaAgGrid.getAllRowData(excepGoodsGridOptions));
		// 입점업체분담율 그리드 전체값 세팅
		/*var inCompBurdenAllData = gagaAgGrid.getAllRowData(inComGridOptions);
		var jsonInCompBurdenData = JSON.stringify(inCompBurdenAllData);
		$('#CouponForm #burdenList').val(jsonInCompBurdenData);*/
		$('#CouponForm #burdenList').val(gagaAgGrid.getAllRowData(inComGridOptions));

	}

	$(document).ready(function() {
		gagaAgGrid.createGrid('inComGridList', inComGridOptions);
		gagaAgGrid.createGrid('brandGridList', brandGridOptions);
		gagaAgGrid.createGrid('cateGridList', cateGridOptions);
		gagaAgGrid.createGrid('supplyGridList', supplyGridOptions);
		gagaAgGrid.createGrid('goodsGridList', goodsGridOptions);
		gagaAgGrid.createGrid('excepGoodsGridList', excepGoodsGridOptions);
		gagaAgGrid.createGrid('randomCpnList', randomCouponGridOptions);
		gagaAgGrid.createGrid('limitedTimeCpnList', limitedTimeCpnGridOptions);
		gagaAgGrid.createGrid('afChannelList', afLinkOptions );

		// 일단 버튼 숨김
		$(".couponButton").hide();

		// 초기화시 데이터 세팅
		if (mode == "N") {
			$('input[name=rdoCpnType]').eq(0).attr("checked", true);
			$('input[name=dcCdGb]').eq(0).attr("checked", true);
			$('input[name=rdoDcWay]').eq(0).attr("checked", true);
			$('input[name=rdoApplyScope]').eq(0).attr("checked", true)
			$('#CouponForm #availEdHH option:last').attr("selected", "selected");
			$('#CouponForm #availEdMM option').hide();
			$('#CouponForm #availEdMM option:first').show().prop("selected", true);
			$('#downEdHH option:last').attr("selected", "selected");
			$('#downEdMM option').hide();
			$('#downEdMM option:first').show().prop("selected", true);
			$('#custJoinEdHH option:last').attr("selected", "selected");
			$('#custJoinEdMM option').hide();
			$('#custJoinEdMM option:first').show().prop("selected", true);
			$('#buyEdHH option:last').attr("selected", "selected");
			$('#buyEdMM option').hide();
			$('#buyEdMM option:first').show().prop("selected", true);
			$("#CouponForm #afChannel option:first").attr("selected" , "selected");
			$("#CouponForm .normalCol").attr("colspan", "5");
			$("#CouponForm .randomCpnArea").hide();
			$("#CouponForm .maxDcAmtArea").hide();
			$("input:radio[name='disCpnStat']:radio[value='G232_10']").prop('checked', true); // 선택하기
			if($('input:radio[name="rdoCpnType"]:checked').val() == 'G230_10'){
				$('#CouponForm .custJoinTr').hide();
				$('#CouponForm .custJoinDateTr').hide();
				$('#CouponForm .firstBuyTr').hide();
				$('#CouponForm .buyDateTr').hide();
				$('#CouponForm .dcCdCheck1').hide();
				// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
				$('#CouponForm .downStdtArea').hide();
				$('#CouponForm .downEddtArea').hide();
				$('#CouponForm .pdGbArea').hide();
				$('#CouponForm .buyLimitAmtArea').hide();
				$('#CouponForm .usableCustGbArea').hide();
				$('#CouponForm .usableCustGradeArea').hide();
				$('#CouponForm .downAblArea').hide();
				$('#CouponForm .linkAfArea').hide();
				$('#CouponForm .dcCdCheck2').hide();
				$('#CouponForm .maxDcAmtArea').hide();
				// $("#CouponForm #afLinkCd").attr('disabled', true);
				$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=I]").prop('checked', true);
				$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('disabled', true);
				$("#CouponForm").find("input:radio[name='rdoApplyScope']").attr('readonly', true);
			}
			$("#btnCouponSave").show();	// 저장버튼
			$("#CouponForm .buttonSpan").show();

		} else {
			if(cpnDetail.cpnStat == "G232_10"){
				$("#btnCouponSave").show();		// 저장버튼
				$("#btnChangeStatIng").show();	// 진행버튼
				$("#btnCouponDelete").show();	// 삭제버튼
				$("#btnCouponEnd").show();		// 종료버튼
				$("#CouponForm .buttonSpan").show();	//행추가,삭제버튼
			}else if(cpnDetail.cpnStat == "G232_11"){
				$("#btnCouponSave").hide();		// 저장버튼
				$("#btnCouponStop").show();		// 중지버튼
				$("#btnCouponDelete").show();	// 삭제버튼
				$("#btnCouponEnd").show();		// 종료버튼
				$("#CouponForm .buttonSpan").hide();	//행추가,삭제버튼
			}else{
				$("#CouponForm .buttonSpan").hide();	//행추가,삭제버튼
			}

			// 사용가능고객구분 체크박스 체크 제거
			$('#CouponForm input:checkbox[name=usableCustGbArr]').prop('checked', false);
			if(cpnCustGbList.length > 0){
				var chkboxCnt = $('#CouponForm input:checkbox[name=usableCustGbArr]').length;
				var dataCnt = cpnCustGbList.length;
				for(let i=0; i<chkboxCnt; i++){
					for(let j=0; j<dataCnt; j++){
						var data = cpnCustGbList[j].usableCustGb;
						if($('#CouponForm input:checkbox[name=usableCustGbArr]').eq(i).val() == data){
							$('#CouponForm input:checkbox[name=usableCustGbArr]').eq(i).prop('checked', true);
							$("#CouponForm input:checkbox[name=usableCustGbArr]").eq(i).parent("label").addClass('checked');
						}
					}
				}
			}

			// 사용고객등급구분 체크박스 체크 제거
			$('#CouponForm input:checkbox[name=usableCustGradeArr]').prop('checked', false);
			if(cpnCustGradeList.length > 0){
				var chkboxCnt = $('#CouponForm input:checkbox[name=usableCustGradeArr]').length;
				var dataCnt = cpnCustGradeList.length;
				for(let i=0; i<chkboxCnt; i++){
					for(let j=0; j<dataCnt; j++){
						var data = cpnCustGradeList[j].usableCustGrade;
						if($('#CouponForm input:checkbox[name=usableCustGradeArr]').eq(i).val() == data){
							$('#CouponForm input:checkbox[name=usableCustGradeArr]').eq(i).prop('checked', true);
							$("#CouponForm input:checkbox[name=usableCustGradeArr]").eq(i).parent().addClass('checked');
						}
					}
				}
			}

			// 결제수단 체크박스 체크 제거
			$('#CouponForm input:checkbox[name=payTypeArr]').prop('checked', false);
			if(cpnPayTypeList.length > 0){
				var chkboxCnt = $('#CouponForm input:checkbox[name=payTypeArr]').length;
				var dataCnt = cpnPayTypeList.length;
				for(let i=0; i<chkboxCnt; i++){
					for(let j=0; j<dataCnt; j++){
						var data = cpnPayTypeList[j].payType;
						if($('#CouponForm input:checkbox[name=payTypeArr]').eq(i).val() == data){
							$('#CouponForm input:checkbox[name=payTypeArr]').eq(i).prop('checked', true);
							$("#CouponForm input:checkbox[name=payTypeArr]").eq(i).parent().addClass('checked');
						}
					}
				}
			}

			// 수정모드시 그리드 세팅
			inComGridOptions.api.setRowData(cpnDtlBurdenList);
			supplyGridOptions.api.setRowData(cpnDtlRefvalSupplyCompList);
			goodsGridOptions.api.setRowData(cpnDtlRefvalApplyGoodsList);
			excepGoodsGridOptions.api.setRowData(cpnDtlRefvalExceptGoodsList);
			brandGridOptions.api.setRowData(cpnDtlRefvalBrandList);
			cateGridOptions.api.setRowData(cpnDtlRefvalCateList);
			randomCouponGridOptions.api.setRowData(randomCpnList);
			limitedTimeCpnGridOptions.api.setRowData(limitedTimeCpnList);
			afLinkOptions.api.setRowData(afChannelList);

			if(cpnDetail.cpnType == "G230_30"){
				$("#CouponForm .supplyTrArea").show();
				$("#CouponForm .brandTrArea").hide();
				$("#CouponForm .categoryTrArea").hide();
				$("#CouponForm .goodsTrArea").hide();
				$("#CouponForm .exceptArea").hide();
			}

			// 기본정보 세팅
			$("#CouponForm input:radio[name='rdoDcWay']:radio[value=" + cpnDetail.dcWay + "]").prop('checked', true);
			$("#CouponForm input:radio[name='rdoCpnType']:radio[value=" + cpnDetail.cpnType + "]").prop('checked', true);
			$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=" + cpnDetail.applyScope + "]").prop('checked', true);
			$("#CouponForm #dcPval").val(cpnDetail.dcPval);
			$("#CouponForm #dcMval").val(cpnDetail.dcMval);
			$("#CouponForm #dcAval").val(cpnDetail.dcAval);
			$("#CouponForm #maxDcAmt").val(cpnDetail.maxDcAmt);
			$("#CouponForm #totPubLimitQty").val(cpnDetail.totPubLimitQty);
			$("#CouponForm #custPubLimitQty").val(cpnDetail.custPubLimitQty);

			if(cpnDetail.cpnStat!='G232_10'){
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', true);
				$("#CouponForm #totPubLimitQty").attr('readonly', true);
				$("#CouponForm #totPubLimitQty").attr('disabled', true);

				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").attr('readonly', true);
				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('disabled', true);
				$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent().prop('disabled', true);
				$("#CouponForm #custPubLimitQty").attr('readonly', true);
				$("#CouponForm #custPubLimitQty").attr('disabled', true);
				if(cpnDetail.totPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', true);
				}else{
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', false);
				}

				if(cpnDetail.custPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', true);
				}else{
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', false);
				}
			}else{
				if(cpnDetail.totPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', true);
					$("#CouponForm #totPubLimitQty").attr('readonly', true);
					$("#CouponForm #totPubLimitQty").attr('disabled', true);
				}else{
					$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('checked', false);
					$("#CouponForm #totPubLimitQty").attr('readonly', false);
					$("#CouponForm #totPubLimitQty").attr('disabled', false);
				}

				if(cpnDetail.custPubLimitQty<1){
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").parent("label").addClass("checked");
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', true);
					$("#CouponForm #custPubLimitQty").attr('readonly', true);
					$("#CouponForm #custPubLimitQty").attr('disabled', true);
				}else{
					$("#CouponForm input[id=chkNoLimitCustPubLimitQty]").prop('checked', false);
					$("#CouponForm #custPubLimitQty").attr('readonly', false);
					$("#CouponForm #custPubLimitQty").attr('disabled', false);
				}
			}

			$("#CouponForm #onePubQty").val(cpnDetail.onePubQty);
			$("#CouponForm #usableCustGb").val(cpnDetail.usableCustGb).prop("selected", true);
			$("#CouponForm #usableCustGrade").val(cpnDetail.usableCustGrade).prop("selected", true);
			$("#CouponForm #endAlimYn").val(cpnDetail.endAlimYn).prop("selected", true);
			$("#CouponForm #firstOrdYn").val(cpnDetail.firstOrdYn).prop("selected", true);
			$("#CouponForm #reissuance").val(cpnDetail.reissuance).prop("selected", true);
			$("#CouponForm #dnGb").val(cpnDetail.dnGb).prop("selected", true);
			//$("#CouponForm #cpnStat").val(cpnDetail.cpnStat).prop("selected", true);
			$("input:radio[name='disCpnStat']:radio[value="+cpnDetail.cpnStat+"]").prop('checked', true); // 선택하기
			$("#CouponForm #newCustYn").val(cpnDetail.newCustYn).prop("selected", true);
			$("#CouponForm #pdGb").val(cpnDetail.pdGb).prop("selected", true);
			$("#CouponForm #siteCd").val(cpnDetail.siteCd).prop("selected", true);
			$("#CouponForm #afChannel").val(cpnDetail.afChannel).prop("selected", true);
			$("#CouponForm #cpnNm").val(cpnDetail.cpnNm);
			$("#CouponForm #downAblYn").val(cpnDetail.downAblYn);
			$("#CouponForm #buyLimitAmt").val(cpnDetail.buyLimitAmt);
			$("#CouponForm #cpnId").val(cpnDetail.cpnId);
			$("#CouponForm #cpnDesc").val(cpnDetail.cpnDesc);

			if(cpnDetail.cpnType == "G230_10"){
				$('#CouponForm .custJoinTr').hide();
				$('#CouponForm .custJoinDateTr').hide();
				$('#CouponForm .firstBuyTr').hide();
				$('#CouponForm .buyDateTr').hide();
				$('#CouponForm .dcCdCheck1').hide();
				$('#CouponForm .limitedTimeCpnArea').hide();
				$('#CouponForm .pdGbArea').hide();
				$('#CouponForm .availDaysArea').hide();
				// $("#CouponForm").find("input:radio[name='rdoApplyScope']:radio[value='A']").attr('disabled', true);
				// 다운로드 시작,종료 , 기간/일수 , 제휴채널, 고객 등급, 구매제한 , 할인율일때 구매제한한도, 1회발행수량, 다운로드 가능여부 숨기기
				$('#CouponForm .downStdtArea').hide();
				$('#CouponForm .downEddtArea').hide();
				$('#CouponForm .pdGbArea').hide();
				$('#CouponForm .buyLimitAmtArea').hide();
				$('#CouponForm .usableCustGbArea').hide();
				$('#CouponForm .usableCustGradeArea').hide();
				$('#CouponForm .downAblArea').hide();
				$('#CouponForm .linkAfArea').hide();
				$('#CouponForm .dcCdCheck2').hide();
				$('#CouponForm .maxDcAmtArea').hide();
				$('#CouponForm .availDateTr').show();
			}else{
				$('#CouponForm .custJoinTr').show();
				$('#CouponForm .custJoinDateTr').show();
				$('#CouponForm .firstBuyTr').show();
				$('#CouponForm .buyDateTr').show();
				$('#CouponForm .dcCdCheck1').show();
				if(cpnDetail.cpnType == "G230_30"){
					$('#CouponForm .maxDcAmtArea').hide();
				}
				if(cpnDetail.cpnType == "G230_20"){
					$('#CouponForm .payTypeTr').show();
				}
			}

			if(limitedTimeCpnList.length>0 && cpnDetail.cpnType == "G230_11"){  //상품쿠폰이고 선착순쿠폰일때
				$("#CouponForm #limitedTimeCpnYn").val("Y");
				$("#CouponForm .limitedTimeCpnTab").show();
				$('#CouponForm .limitedTimeCpnArea').show();
				$("#CouponForm input[id=limitedTimeCpnYn]").parent("label").addClass("checked");
				$("#CouponForm input[id=limitedTimeCpnYn]").attr('readonly', true);
				$("#CouponForm input[id=limitedTimeCpnYn]").prop('disabled', true);
				$("#CouponForm input[id=limitedTimeCpnYn]").parent().prop('disabled', true);
				$("#CouponForm input[id=totPubLimitQty]").prop("disabled", true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent("label").addClass("checked");
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").attr('readonly', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").prop('disabled', true);
				$("#CouponForm input[id=chkNoLimitTotPubLimitQty]").parent().prop('disabled', true);
			}else{
				$("#CouponForm #limitedTimeCpnYn").val("N");
				$("#CouponForm .limitedTimeCpnTab").hide();
				$('#CouponForm .limitedTimeCpnArea').hide();
			}

			// 한번 저장되면 쿠폰유형, 할인쿠폰유형, 난수 생성수량, 시리얼명, 시리얼쿠폰발급수량 수정 불가 처리
			$("#CouponForm input:radio[name='rdoCpnType']").attr('readonly', true);
			$("#CouponForm input:radio[name='rdoCpnType']").prop('disabled', true);
			$("#CouponForm input:radio[name='rdoCpnType']").parent().prop('disabled', true);
			$("#CouponForm input:radio[name='dcCdGb']").attr('readonly', true);
			$("#CouponForm input:radio[name='dcCdGb']").prop('disabled', true);
			$("#CouponForm input:radio[name='dcCdGb']").parent().prop('disabled', true);
			$("#CouponForm input:radio[name='dcCdGb']:radio[value=" + cpnDetail.dcCdGb + "]").prop('checked', true);
			$("#CouponForm input[name='serialCpnNm']").prop("disabled", true);
			$("#CouponForm input[name='serialCpnQty']").prop("disabled", true);
			$("#CouponForm input[name='randomCpnQty']").prop("disabled", true);

			// 할인방식이 할인율이면 최대할인금액 노출
			if(cpnDetail.dcWay == "G240_11"){
				$("#CouponForm .maxDcAmtArea").show();
			}
			// 주문서 쿠폰이면 할인쿠폰유형 노출
			if(cpnDetail.cpnType == "G230_20") {
				$("#CouponForm .dcCdGb").show();
			}
			// 할인코드유형이 일반유형이 아니면
			if(cpnDetail.dcCdGb != "G233_00" ) {
				$("#CouponForm .randomCpnTab").show();							// 시리얼 및 난수 TAB 노출
				$("#CouponForm .dcCdCheck1").hide();								// 총발행제한수량, 1회발행수량, 1인당발행제한수량 숨김
				$("#CouponForm .dcCdCheck2").hide();								// 총발행제한수량, 1회발행수량, 1인당발행제한수량 숨김
				if(cpnDetail.dcCdGb == "G233_10") {		// 시리얼 유형
					$("#CouponForm input[name='serialCpnQty']").val(cpnDetail.totPubLimitQty);
					$("#CouponForm input[name='serialCpnNm']").val(cpnDetail.rdCpnNm);
					$("#CouponForm .normalCol").attr("colspan", "5");
					$("#CouponForm .serialCpnArea").show();
					$("#CouponForm .randomCpnArea").hide();
				} else if (cpnDetail.dcCdGb == "G233_20") {
					$("#CouponForm input[name='randomCpnQty']").val(cpnDetail.totPubLimitQty);
					$("#CouponForm .normalCol").attr("colspan", "");
					$("#CouponForm .randomCpnArea").show();
					$("#CouponForm .serialCpnArea").hide();
				}
			}

			if($("#CouponForm input[name=rdoDcWay]:checked").val() == 'G240_10') {
				$("#CouponForm .maxDcAmtArea").hide();
			}else{
				$('#dcPvalSpan').text("%");
				$('#dcMvalSpan').text("%");
				$('#dcAvalSpan').text("%");
			}

			// 쿠폰다운 날짜
			let edDtArr;
			if(!gagajf.isNull(cpnDetail.downEddt)){
				edDtArr = cpnDetail.downEddt.split(" ");
				if(edDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #downEdMM option").hide();
					$('#CouponForm #downEdMM option:first').show().prop("selected", true);
				}
			}

			// 유효 날짜
			let availEdDtArr;
			if(!gagajf.isNull(cpnDetail.availEddt)){
				availEdDtArr = cpnDetail.availEddt.split(" ");
				if(availEdDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #availEdMM option").hide();
					$('#CouponForm #availEdMM option:first').show().prop("selected", true);
				}
			}

			// 첫구매 날짜
			let firstBuyEdDtArr;
			if(!gagajf.isNull(cpnDetail.buyEddt)){
				firstBuyEdDtArr = cpnDetail.buyEddt.split(" ");
				if(firstBuyEdDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #buyEdMM option").hide();
					$('#CouponForm #buyEdMM option:first').show().prop("selected", true);
				}
			}

			// 신규가입 날짜
			let custJoinEdDtArr;
			if(!gagajf.isNull(cpnDetail.custJoinEddt)){
				custJoinEdDtArr = cpnDetail.custJoinEddt.split(" ");
				if(custJoinEdDtArr[1] == "23:59:59") {
					edHour = "24";
					edMinute = "00";
					$("#CouponForm #custJoinEdMM option").hide();
					$('#CouponForm #custJoinEdMM option:first').show().prop("selected", true);
				}
			}

			// 만약 쿠폰 발급한 내역이 있으면 쿠폰수정못하게 readonly , disabled 속성 추가
			if (issueCnt > 0) {
				$("#CouponForm #usableCustGb").attr('readonly', true);
				$("#CouponForm #usableCustGb").attr('disabled', true);
				$("#CouponForm #afChannel").attr('readonly', true);
				$("#CouponForm #afChannel").attr('disabled', true);
				$("#CouponForm #usableCustGrade").attr('readonly', true);
				$("#CouponForm #usableCustGrade").attr('disabled', true);
				$("#CouponForm #endAlimYn").attr('readonly', true);
				$("#CouponForm #endAlimYn").attr('disabled', true);
				$("#CouponForm #firstOrdYn").attr('readonly', true);
				$("#CouponForm #firstOrdYn").attr('disabled', true);
				$("#CouponForm #reissuance").attr('readonly', true);
				$("#CouponForm #reissuance").attr('disabled', true);
				$("#CouponForm #dnGb").attr('readonly', true);
				$("#CouponForm #dnGb").attr('disabled', true);
				$("#CouponForm #newCustYn").attr('readonly', true);
				$("#CouponForm #newCustYn").attr('disabled', true);
				$("#CouponForm #pdGb").attr('readonly', true);
				$("#CouponForm #pdGb").attr('disabled', true);
				$("#CouponForm #downAblYn").attr('readonly', true);
				$("#CouponForm #downAblYn").attr('disabled', true);
				$("#CouponForm #siteCd").attr('readonly', true);
				$("#CouponForm #siteCd").attr('disabled', true);
				$("#CouponForm #cpnNm").attr('readonly', true);
				$("#CouponForm #cpnNm").attr('disabled', true);
				$("#CouponForm #dcPval").attr('readonly', true);
				$("#CouponForm #dcPval").attr('disabled', true);
				$("#CouponForm #dcMval").attr('readonly', true);
				$("#CouponForm #dcMval").attr('disabled', true);
				$("#CouponForm #dcAval").attr('readonly', true);
				$("#CouponForm #dcAval").attr('disabled', true);
				$("#CouponForm #maxDcAmt").attr('readonly', true);
				$("#CouponForm #maxDcAmt").attr('disabled', true);
				$("#CouponForm #totPubLimitQty").attr('readonly', true);
				$("#CouponForm #totPubLimitQty").attr('disabled', true);
				$("#CouponForm #custPubLimitQty").attr('readonly', true);
				$("#CouponForm #custPubLimitQty").attr('disabled', true);
				$("#CouponForm #onePubQty").attr('readonly', true);
				$("#CouponForm #onePubQty").attr('disabled', true);
				$("#CouponForm #downStDay").attr('readonly', true);
				$("#CouponForm #downStDay").attr('disabled', true);
				$("#CouponForm #downStHH").attr('readonly', true);
				$("#CouponForm #downStHH").attr('disabled', true);
				$("#CouponForm #downStMM").attr('readonly', true);
				$("#CouponForm #downStMM").attr('disabled', true);
				$("#CouponForm #downEdDay").attr('readonly', true);
				$("#CouponForm #downEdDay").attr('disabled', true);
				$("#CouponForm #downEdHH").attr('readonly', true);
				$("#CouponForm #downEdHH").attr('disabled', true);
				$("#CouponForm #downEdMM").attr('readonly', true);
				$("#CouponForm #downEdMM").attr('disabled', true);
				$("#CouponForm #buyLimitAmt").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoDcWay']").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoApplyScope']").attr('readonly', true);
				$("#CouponForm .rdoBtn").css('cursor', 'auto');
				$("#CouponForm #cpnId").attr('readonly', true);
				$("#CouponForm #cpnId").attr('disabled', true);
				$("#CouponForm input:checkbox[name='cpnCreateType']").attr('readonly', true);
				$("#CouponForm input:checkbox[name='cpnCreateType']").attr('disabled', true);
				$("#CouponForm input:checkbox[name=cpnCreateType]").attr('checked', true);
				$("#CouponForm input:checkbox[name=cpnCreateType]").parent().addClass('checked');
				$("#btnAddAf").hide();
				$("#btnDeleteAf").hide();
				$("#btnSupplyAdd").hide();
				$("#btnSupplyDel").hide();
				$("#btnBrandAdd").hide();
				$("#btnBrandDel").hide();
				$("#btnCateAdd").hide();
				$("#btnCateDel").hide();
				$("#btnGoodsAdd").hide();
				$("#btnGoodsDel").hide();
				$("#btnExcepGoodsAdd").hide();
				$("#btnExcepGoodsDel").hide();
				$("#btnAddApplyBurden").hide();
				$("#btnDelApplyBurden").hide();
			}
			// 다운로드기간 세팅
			splitDate("start", cpnDetail.downStdt, "down");
			splitDate("end", cpnDetail.downEddt, "down");
			// 유효기간이 날짜인경우 날짜 세팅
			if (cpnDetail.pdGb == "P") {
				splitDate("start", cpnDetail.availStdt, "avail");
				splitDate("end", cpnDetail.availEddt, "avail");
				if(issueCnt > 0) {
					$("#CouponForm #availStDay").attr('readonly', true);
					$("#CouponForm #availStDay").attr('disabled', true);
					$("#CouponForm #availStHH").attr('readonly', true);
					$("#CouponForm #availStHH").attr('disabled', true);
					$("#CouponForm #availStMM").attr('readonly', true);
					$("#CouponForm #availStMM").attr('disabled', true);
					$("#CouponForm #availEdDay").attr('readonly', true);
					$("#CouponForm #availEdDay").attr('disabled', true);
					$("#CouponForm #availEdHH").attr('readonly', true);
					$("#CouponForm #availEdHH").attr('disabled', true);
					$("#CouponForm #availEdMM").attr('readonly', true);
					$("#CouponForm #availEdMM").attr('disabled', true);
				}
			} else {
				$("#CouponForm #availDays").val(cpnDetail.availDays);
				$('#CouponForm #availEdHH option:last').attr("selected", "selected");
				$('#CouponForm #availEdMM option:last').attr("selected", "selected");

			}
			// 첫구매여부 적용하는 경우 날짜 세팅
			if (cpnDetail.firstOrdYn == "Y") {
				splitDate("start", cpnDetail.buyStdt, "buy");
				splitDate("end", cpnDetail.buyEddt, "buy");
				if(issueCnt > 0) {
					$("#CouponForm #buyStDay").attr('readonly', true);
					$("#CouponForm #buyStDay").attr('disabled', true);
					$("#CouponForm #buyStHH").attr('readonly', true);
					$("#CouponForm #buyStHH").attr('disabled', true);
					$("#CouponForm #buyStMM").attr('readonly', true);
					$("#CouponForm #buyStMM").attr('disabled', true);
				}
			}
			// 신규회원여부 적용하는 경우 날짜 세팅
			if (cpnDetail.newCustYn == "Y") {
				splitDate("start", cpnDetail.custJoinStdt, "custJoin");
				splitDate("end", cpnDetail.custJoinEddt, "custJoin");
				if(issueCnt > 0) {
					$("#CouponForm #custJoinStDay").attr('readonly', true);
					$("#CouponForm #custJoinStDay").attr('disabled', true);
					$("#CouponForm #custJoinStHH").attr('readonly', true);
					$("#CouponForm #custJoinStHH").attr('disabled', true);
					$("#CouponForm #custJoinStMM").attr('readonly', true);
					$("#CouponForm #custJoinStMM").attr('disabled', true);
				}
			}

			// 대기상태 아닐 때 , 체크박스 disabled, 입력불가
			if(cpnDetail.cpnStat != 'G232_10'){
				$("#CouponForm").find("input[name=usableCustGbArr]").each(function (){
					$(this).attr('disabled', true);
				});
				$("#CouponForm").find("input[name=usableCustGradeArr]").each(function (){
					$(this).attr('disabled', true);
				});
				$("#CouponForm").find("input[name=payTypeArr]").each(function (){
					$(this).attr('disabled', true);
				});

				$("#CouponForm #usableCustGb").attr('readonly', true);
				$("#CouponForm #usableCustGb").attr('disabled', true);
				$("#CouponForm #afChannel").attr('readonly', true);
				$("#CouponForm #afChannel").attr('disabled', true);
				$("#CouponForm #usableCustGrade").attr('readonly', true);
				$("#CouponForm #usableCustGrade").attr('disabled', true);
				$("#CouponForm #endAlimYn").attr('readonly', true);
				$("#CouponForm #endAlimYn").attr('disabled', true);
				$("#CouponForm #firstOrdYn").attr('readonly', true);
				$("#CouponForm #firstOrdYn").attr('disabled', true);
				$("#CouponForm #reissuance").attr('readonly', true);
				$("#CouponForm #reissuance").attr('disabled', true);
				$("#CouponForm #dnGb").attr('readonly', true);
				$("#CouponForm #dnGb").attr('disabled', true);
				$("#CouponForm #newCustYn").attr('readonly', true);
				$("#CouponForm #newCustYn").attr('disabled', true);
				$("#CouponForm #pdGb").attr('readonly', true);
				$("#CouponForm #pdGb").attr('disabled', true);
				$("#CouponForm #downAblYn").attr('readonly', true);
				$("#CouponForm #downAblYn").attr('disabled', true);
				$("#CouponForm #siteCd").attr('readonly', true);
				$("#CouponForm #siteCd").attr('disabled', true);
				$("#CouponForm #cpnNm").attr('readonly', true);
				$("#CouponForm #cpnNm").attr('disabled', true);
				$("#CouponForm #dcPval").attr('readonly', true);
				$("#CouponForm #dcPval").attr('disabled', true);
				$("#CouponForm #dcMval").attr('readonly', true);
				$("#CouponForm #dcMval").attr('disabled', true);
				$("#CouponForm #dcAval").attr('readonly', true);
				$("#CouponForm #dcAval").attr('disabled', true);
				$("#CouponForm #maxDcAmt").attr('readonly', true);
				$("#CouponForm #maxDcAmt").attr('disabled', true);
				$("#CouponForm #totPubLimitQty").attr('readonly', true);
				$("#CouponForm #totPubLimitQty").attr('disabled', true);
				$("#CouponForm #custPubLimitQty").attr('readonly', true);
				$("#CouponForm #custPubLimitQty").attr('disabled', true);
				$("#CouponForm #onePubQty").attr('readonly', true);
				$("#CouponForm #onePubQty").attr('disabled', true);
				$("#CouponForm #downStDay").attr('readonly', true);
				$("#CouponForm #downStDay").attr('disabled', true);
				$("#CouponForm #downStHH").attr('readonly', true);
				$("#CouponForm #downStHH").attr('disabled', true);
				$("#CouponForm #downStMM").attr('readonly', true);
				$("#CouponForm #downStMM").attr('disabled', true);
				$("#CouponForm #downEdDay").attr('readonly', true);
				$("#CouponForm #downEdDay").attr('disabled', true);
				$("#CouponForm #downEdHH").attr('readonly', true);
				$("#CouponForm #downEdHH").attr('disabled', true);
				$("#CouponForm #downEdMM").attr('readonly', true);
				$("#CouponForm #downEdMM").attr('disabled', true);
				$("#CouponForm #buyLimitAmt").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoDcWay']").attr('readonly', true);
				$("#CouponForm input:radio[name='rdoApplyScope']").attr('readonly', true);
				$("#CouponForm .rdoBtn").css('cursor', 'auto');
				$("#CouponForm #cpnId").attr('readonly', true);
				$("#CouponForm #cpnId").attr('disabled', true);
				$("#CouponForm input:checkbox[name='cpnCreateType']").attr('readonly', true);
				$("#CouponForm input:checkbox[name='cpnCreateType']").attr('disabled', true);
				$("#CouponForm input:checkbox[name=cpnCreateType]").attr('checked', true);
				$("#CouponForm input:checkbox[name=cpnCreateType]").parent().addClass('checked');
				$("#CouponForm #availStDay").attr('readonly', true);
				$("#CouponForm #availStDay").attr('disabled', true);
				$("#CouponForm #availStHH").attr('readonly', true);
				$("#CouponForm #availStHH").attr('disabled', true);
				$("#CouponForm #availStMM").attr('readonly', true);
				$("#CouponForm #availStMM").attr('disabled', true);
				$("#CouponForm #availEdDay").attr('readonly', true);
				$("#CouponForm #availEdDay").attr('disabled', true);
				$("#CouponForm #availEdHH").attr('readonly', true);
				$("#CouponForm #availEdHH").attr('disabled', true);
				$("#CouponForm #availEdMM").attr('readonly', true);
				$("#CouponForm #availEdMM").attr('disabled', true);

				$("#btnAddAf").hide();
				$("#btnDeleteAf").hide();
				$("#btnSupplyAdd").hide();
				$("#btnSupplyDel").hide();
				$("#btnBrandAdd").hide();
				$("#btnBrandDel").hide();
				$("#btnCateAdd").hide();
				$("#btnCateDel").hide();
				$("#btnGoodsAdd").hide();
				$("#btnGoodsDel").hide();
				$("#btnExcepGoodsAdd").hide();
				$("#btnExcepGoodsDel").hide();
				$("#btnAddApplyBurden").hide();
				$("#btnDelApplyBurden").hide();
			}
		}
		// 기본세팅
		pdGbChange();
		firstOrdYnChange();
		newCustYnChange();
		// fnChangeAfLinkCdList();

		// 제휴채널2뎁스 기본세팅
		if(cpnDetail != null ) {
			$("#CouponForm #afLinkCd").val(cpnDetail.afLinkCd).prop("selected", true);
			if(issueCnt > 0 ) {
				$("#CouponForm #afLinkCd").attr('readonly', true);
				$("#CouponForm #afLinkCd").attr('disabled', true);
			}
		}
	});

	// 날짜분리 ( 시작/종료날짜구분(start , end) , 날짜String , 적용타겟대상 )
	function splitDate(stedGb , date , targetGb ){
		var str = date;
		var dateStr = str.split(' ');
		var timeArr = dateStr[1].split(':');

		if(stedGb == "start") {
			$("#CouponForm #"+targetGb+"StDay").val(dateStr[0]);
			$("#CouponForm #"+targetGb+"StHH").val(timeArr[0]);
			$("#CouponForm #"+targetGb+"StMM").val(timeArr[1]);
		} else {
			$("#CouponForm #"+targetGb+"EdDay").val(dateStr[0]);
			$("#CouponForm #"+targetGb+"EdHH").val(timeArr[0]);
			$("#CouponForm #"+targetGb+"EdMM").val(timeArr[1]);
		}
	}
	// 제한없음 문구 변경
	$("input[name=totPubLimitQty],input[name=custPubLimitQty],input[name=buyLimitAmt],input[name=onePubQty]").change(function(){
		if($(this).val() == "0"){
			$("#"+$(this).attr("name")+"Span").html("*제한없음");
		}else{
			$("#"+$(this).attr("name")+"Span").html("");
		}
		$("#"+$(this).attr("name")+"Span").css("color", "red");
	});
	setTimeout(function(){
		$("input[name=totPubLimitQty],input[name=custPubLimitQty],input[name=buyLimitAmt],input[name=onePubQty]").change();
	}, 1);

	// 콤마 찍어주기
	$(function(){
		setComma("CouponForm" , true);
	});

	function setComma(formId, pBoolean){
		setTimeout(function(){
			//숫자타입 콤마 찍어주기
			$("#"+formId+" [data-valid-type=numeric]").each(function(){
				$(this).change(function(){
					if(pBoolean){
						$(this).val($(this).val().addComma());
					}else{
						$(this).val($(this).val().removeComma());
					}
				});
				if(pBoolean){
					$(this).val($(this).val().addComma());
				}else{
					$(this).val($(this).val().removeComma());
				}
			});
		}, 300);
	}

	// 진행 버튼 클릭
	$("#btnChangeStatIng").on("click", function() {
		mcxDialog.confirmC("쿠폰을 진행하시겠습니까?<br/>진행 후에는 수정이 제한될 수 있습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat : "G232_11"				// 진행
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);					
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 중지 버튼 클릭
	$("#btnCouponStop").on("click", function() {
		mcxDialog.confirmC("쿠폰 진행을 중지하시겠습니까?<br/>중지 후에는 진행으로 복원하실 수 없습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat : "G232_12"			// 중지
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 삭제 버튼 클릭
	$("#btnCouponDelete").on("click", function() {
		mcxDialog.confirmC("쿠폰을 삭제하시겠습니까?<br/>삭제한 프로모션은 복원하실 수 없습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat: "G232_14"			// 삭제
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 종료 버튼 클릭
	$("#btnCouponEnd").on("click", function() {
		mcxDialog.confirmC("쿠폰을 종료하시겠습니까?<br/>종료한 프로모션은 복원하실 수 없습니다.", {
			btn: ["아니오","예"],
			btnClick: function(index) {
				if(index == 2) {
					let data = { cpnStat: "G232_13"			// 종료
						, cpnId : $('#CouponForm input[name=cpnId]').val()
					}
					var jsonData = JSON.stringify(data);
					gagajf.ajaxJsonSubmit('/marketing/coupon/changeStat', jsonData, fnCouponSaveCollback);
				}
			}
		});
	});

	// 제휴채널 추가
	$('#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(afLinkOptions);		// 받아온 모든 데이터

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

			// 중복되지 않은 데이터 리스트에 추가
			if(addChk) {
				gagaAgGrid.addRowData(afLinkOptions, {"afLinkCd":result[i].afLinkCd , "afLinkNm":result[i].afLinkNm, "afChannel":result[i].afChannel});
			}
		}
	}

	// 적용범위 클릭 시
	$("#CouponForm input[name=rdoApplyScope]").bind('click', function () {
		if($('#CouponForm input:radio[name="rdoApplyScope"]:checked').val() == 'A'){ //전체적용일때
			supplyGridOptions.api.updateRowData({remove:gagaAgGrid.getAllRowData(supplyGridOptions)});
			brandGridOptions.api.updateRowData({remove:gagaAgGrid.getAllRowData(brandGridOptions)});
			cateGridOptions.api.updateRowData({remove:gagaAgGrid.getAllRowData(cateGridOptions)});
			goodsGridOptions.api.updateRowData({remove:gagaAgGrid.getAllRowData(goodsGridOptions)});
			excepGoodsGridOptions.api.updateRowData({remove:gagaAgGrid.getAllRowData(excepGoodsGridOptions)});
			$("#CouponForm .supplyTrArea").hide();
			$("#CouponForm .brandTrArea").hide();
			$("#CouponForm .categoryTrArea").hide();
			$("#CouponForm .goodsTrArea").hide();
			$("#CouponForm .exceptArea").hide();
		}else{ //개별적용일때
			var radioValue = $("#CouponForm input[name=rdoCpnType]:checked").val();
			// 배송비 쿠폰일때
			if(radioValue == 'G230_30'){
				$("#CouponForm .supplyTrArea").show();
			}else{
				$("#CouponForm .supplyTrArea").show();
				$("#CouponForm .brandTrArea").show();
				$("#CouponForm .categoryTrArea").show();
				$("#CouponForm .goodsTrArea").show();
				$("#CouponForm .exceptArea").show();
			}
		}
	});

	/*]]>*/
</script>
</html>