<!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       최초 작성
 *******************************************************************************
 -->
 
<!-- 상품쿠폰,장바구니쿠폰,배송비쿠폰 -->
<table class="frmStyle G230_20">
	<colgroup>
		<col style="width:165px;">
		<col style="width:45%;">
		<col style="width:165px;">
		<col>
	</colgroup>
	<tbody>
		<tr>
			<th>쿠폰명<em class="required" title="필수"></em></th>
			<td>
				<input type="text" name="cpnNm" required="required" data-valid-name="쿠폰명">
			</td>
			<th>사이트<em class="required" title="필수"></em></th>
			<td>
				<select name="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" data-valid-name="쿠폰설명">
			</td>
			<th>만료알림여부<em class="required" title="필수"></em></th>
			<td>
				<select name="endAlimYn" required="required" data-valid-name="만료알림여부">
					<option value="Y">Y</option>
					<option value="N" selected="selected">N</option>
				</select>
			</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="시리얼쿠폰발급수량" style="text-align: right" onkeyup="inputNumberFormat(this);">
			</td>
		</tr>
		<tr class="randomCpnArea" style="display:none;">
			<th >난수생성수량<em class="required" title="필수"></em></th>
			<td colspan="3">
				<input type="text" name="randomCpnQty" class="w300" data-valid-name="난수생성수량" style="text-align: right" onkeyup="inputNumberFormat(this);">
			</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" 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" name="dcPval" value="0" required="required" data-valid-name="할인값(PC)" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);inputNumberFormat(this);">
				<span class="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" name="dcMval" value="0" required="required" data-valid-name="할인값(모바일웹)" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);inputNumberFormat(this);">
				<span class="dcMvalSpan">원</span>
			</td>
			<th>할인값(모바일앱)<em class="required" title="필수"></em></th>
			<td>
				<input type="text" class="w200" name="dcAval" value="0" required="required" data-valid-name="할인값(모바일앱)" style="text-align: right" onkeyup="fnDcValOnkeyUp(this);inputNumberFormat(this);">
				<span class="dcAvalSpan">원</span>
			</td>
		</tr>
		<tr>
			<th class="maxDcAmtArea">최대할인금액<em class="required" title="필수"></em></th>
			<td class="maxDcAmtArea">
				<input type="text" class="w200" name="maxDcAmt" value="0" required="required" data-valid-name="최대할인금액" style="text-align: right;" onkeyup="inputNumberFormat(this);"><span>원</span>
			</td>
			<th class="buyLimitAmtArea">구매제한금액<em class="required" title="필수"></em></th>
			<td class="buyLimitAmtArea">
				<input type="text" name="buyLimitAmt" class="w200" required="required" value="0" style="text-align: right;" data-valid-name="구매제한금액" onkeyup="inputNumberFormat(this);">원
			</td>
		</tr>
		<tr>
			<th class="downStdtArea">다운로드시작일시<em class="required" title="필수"></em></th>
			<td class="downStdtArea">
				<input type="hidden" name="downStdt" required="required" data-valid-name="다운로드시작일시">
				<input type="text" class="schDate w100" name="downStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
				<select name="downStHH">
					<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
				</select>
				<select name="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" name="downEddt" required="required" data-valid-name="다운로드종료일시">
				<input type="text" class="schDate w100" name="downEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
				<select name="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" selected></option>
				</select>
				<select name="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" colspan="3">
				<select name="pdGb" id="pdGb" onchange="pdGbChange(this)" required="required" data-valid-name="기간/일수구분">
					<option value="P">기간</option>
					<option value="D">일수</option>
				</select>
			</td>
		</tr>
		<tr class="availDaysArea" style="display:none;">
			<th>유효기간일수<em class="required" title="필수"></em></th>
			<td colspan="3">
				<input type="text" name="availDays" class="w200" data-valid-name="유효기간일수" style="text-align: right;" onkeyup="inputNumberFormat(this);">
			</td>
		</tr>
		<tr>
			<th class="availDateTr">유효기간시작일시<em class="required" title="필수"></em></th>
			<td class="availDateTr">
				<input type="hidden" name="availStdt" data-valid-name="유효기간시작일시">
				<input type="text" class="schDate w100" name="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" 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" selected></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 colspan="3">
				<select name="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 class="buyDateTr" style="display:none;">
			<th >첫구매기간시작일시<em class="required" title="필수"></em></th>
			<td>
				<input type="hidden" name="buyStdt" data-valid-name="첫구매기간시작일시">
				<input type="text" class="schDate w100" name="buyStDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
				<select name="buyStHH">
					<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
				</select>
				<select name="buyStMM">
					<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
				</select>
			<th>첫구매기간종료일시<em class="required" title="필수"></em></th>
			<td>
				<input type="hidden" name="buyEddt" data-valid-name="첫구매기간종료일시">
				<input type="text" class="schDate w100" name="buyEdDay" maxlength="10" th:value="${#calendars.format(#calendars.createNow(), 'yyyy-MM-dd')}"/>
				<select name="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" selected></option>
				</select>
				<select name="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 colspan="3">
				<select name="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 class="custJoinDateTr" style="display:none;">
			<th >신규회원기간시작일시<em class="required" title="필수"></em></th>
			<td>
				<input type="hidden" name="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">
					<option th:if="${hhList}" th:each="oneData , status : ${hhList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
				</select>
				<select name="custJoinStMM">
					<option th:if="${mmList}" th:each="oneData , status : ${mmList}" th:text="${oneData.cdNm}" th:value="${oneData.cd}"></option>
				</select>
			<th>신규회원기간종료일시<em class="required" title="필수"></em></th>
			<td>
				<input type="hidden" 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" 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" selected></option>
				</select>
				<select name="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" value="0" required="required" data-valid-name="총발행제한수량" style="text-align: right;" onkeyup="inputNumberFormat(this);">개
				<label class="chkBox" id="chkBoxTotPubQty"><input type="checkbox" name="chkNoLimitTotPubLimitQty"/>제한없음</label>
			</td>
			<th>1인당발행제한수량<em class="required" title="필수"></em></th>
			<td>
				<input type="text" class="w200" name="custPubLimitQty" value="1" required="required" data-valid-name="1인당발행제한수량" style="text-align: right;" onkeyup="inputNumberFormat(this);">개
				<label class="chkBox" id="chkBoxCustPubQty"><input type="checkbox" name="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" value="1" required="required" data-valid-name="1회발행수량" style="text-align: right;" onkeyup="inputNumberFormat(this);">개
			</td>
			<th class="downAblArea">다운로드가능여부<em class="required" title="필수"></em></th>
			<td class="downAblArea">
				<select name="downAblYn" required="required" data-valid-name="다운로드가능여부">
					<option value="Y">Y</option>
					<option value="N" selected="selected">N</option>
				</select>
				<em style="color:red"> *상품상세 페이지내</em>
			</td>
		</tr>
		<tr class="payTypeTr" style="display:none;">
			<th>결제수단</th>
			<td colspan="3">
				<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>
	</tbody>
</table>
<!-- //기본정보 -->

<script th:inline="javascript">

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

// 할인방식 할인율 일때, 할인값 체크
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;
		}
	}
}

// 기간 일수 변경시
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();
		$('#CouponForm select[name=availDays]').attr('required' , false);
		$('#CouponForm select[name=availStDay]').attr('required' , true);
		$('#CouponForm select[name=availEdDay]').attr('required' , true);
		$('#CouponForm select[name=availStdt]').attr('required' , true);
		$('#CouponForm select[name=availEddt]').attr('required' , true);
	} else {
		$('.availDateTr').css('display' , 'none');
		$("#CouponForm .availDaysArea").show();
		$('#CouponForm select[name=availDays]').attr('required' , true);
		$('#CouponForm select[name=availStDay]').attr('required' , false);
		$('#CouponForm select[name=availEdDay]').attr('required' , false);
		$('#CouponForm select[name=availStdt]').attr('required' , false);
		$('#CouponForm select[name=availEddt]').attr('required' , false);
	}
}

// 종료시간 클릭시
var fnChangeEdHH = function (obj){
	var selectId = $(obj).attr("name");
	
	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 select[name="+changeId+"] option").hide();
		$("#CouponForm select[name="+changeId+"] option:first").show().prop("selected", true);
	} else {
		$("#CouponForm select[name="+changeId+"] option").show();
	}
};

// 첫구매여부 변경시
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' , '');
		$('#CouponForm select[name=buyStdt]').attr('required' , true);
		$('#CouponForm select[name=buyEddt]').attr('required' , true);
	} else {
		$('.buyDateTr').css('display' , 'none');
		$('#CouponForm select[name=buyStdt]').attr('required' , false);
		$('#CouponForm select[name=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' , '');
		$('#CouponForm select[name=custJoinStdt]').attr('required' , true);
		$('#CouponForm select[name=custJoinEddt]').attr('required' , true);
	} else {
		$('.custJoinDateTr').css('display' , 'none');
		$('#CouponForm select[name=custJoinStdt]').attr('required' , false);
		$('#CouponForm select[name=custJoinEddt]').attr('required' , false);
	}
}

// 시리얼 쿠폰 사용
$("#CouponForm input[name=serialCpnNm]").bind("keyup",function(){
	re = /[~!@\#$%^&*\()\-=+_']/gi;
	var temp = $(this).val();
	
	// 특수문자가 포함되면 삭제하여 값으로 다시셋팅
	if (re.test(temp)) { 
		$(this).val(temp.replace(re,""));
	}
	
	$(this).val($(this).val().replaceAll(" ", ""));
});

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

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

//2021.08.17 초기화설정 변경
$(document).ready(function() {
	if (cpnDetail != null && cpnDetail.cpnId != null) {
		
		// 기본정보 세팅
		$("#CouponForm input[name=cpnNm]").val(cpnDetail.cpnNm);
		$("#CouponForm input[name=cpnDesc]").val(cpnDetail.cpnDesc);
		$("#CouponForm input:radio[name='rdoDcWay']:radio[value=" + cpnDetail.dcWay + "]").prop('checked', true);
		$("#CouponForm input:radio[name='rdoApplyScope']:radio[value=" + cpnDetail.applyScope + "]").prop('checked', true);
		$("#CouponForm input[name=dcPval]").val(cpnDetail.dcPval.addComma());
		$("#CouponForm input[name=dcMval]").val(cpnDetail.dcMval.addComma());
		$("#CouponForm input[name=dcAval]").val(cpnDetail.dcAval.addComma());
		$("#CouponForm input[name=maxDcAmt]").val(cpnDetail.maxDcAmt.addComma());
		$("#CouponForm input[name=buyLimitAmt]").val(cpnDetail.buyLimitAmt.addComma());
		$("#CouponForm input[name=onePubQty]").val(cpnDetail.onePubQty.addComma());
		$("#CouponForm input[name=randomCpnQty]").val(cpnDetail.totPubLimitQty.addComma());
		$("#CouponForm input[name=serialCpnQty]").val(cpnDetail.totPubLimitQty.addComma());
		$("#CouponForm input[name=serialCpnNm]").val(cpnDetail.rdCpnNm);

		// 금액할인
		if (cpnDetail.dcWay == 'G240_10') {
			strAmtType = "원";
			$("#CouponForm input[name=maxDcAmt]").attr("disabled", true);
		}
		// 율할인
		else {
			strAmtType = "%";
			$("#CouponForm input[name=maxDcAmt]").attr("disabled", false);
		}
		
		$('.dcPvalSpan').text(strAmtType);
		$('.dcMvalSpan').text(strAmtType);
		$('.dcAvalSpan').text(strAmtType);
		
		$("#CouponForm input[name=totPubLimitQty]").val(cpnDetail.totPubLimitQty.addComma());
		$("#CouponForm input[name=custPubLimitQty]").val(cpnDetail.custPubLimitQty.addComma());
		
		$("#CouponForm select[name=pdGb]").val(cpnDetail.pdGb).prop("selected", true);
		$("#CouponForm select[name=siteCd]").val(cpnDetail.siteCd).prop("selected", true);
		$("#CouponForm select[name=endAlimYn]").val(cpnDetail.endAlimYn).prop("selected", true);
		$("#CouponForm select[name=firstOrdYn]").val(cpnDetail.firstOrdYn).prop("selected", true);
		$("#CouponForm select[name=newCustYn]").val(cpnDetail.newCustYn).prop("selected", true);
		$("#CouponForm select[name=downAblYn]").val(cpnDetail.downAblYn).prop("selected", true);
		
		// 유효기간이 날짜인경우 날짜 세팅
		if (cpnDetail.pdGb == "P") {
			splitDate("start"	, cpnDetail.availStdt, "avail");
			splitDate("end"		, cpnDetail.availEddt, "avail");
		} else {
			$("#CouponForm #availDays").val(cpnDetail.availDays);
			$('#CouponForm #availEdHH option:last').attr("selected", "selected");
			$('#CouponForm #availEdMM option:last').attr("selected", "selected");
		}
		
		// 유효기간이 날짜인경우 날짜 세팅
		splitDate("start"	, cpnDetail.downStdt, "down");
		splitDate("end"		, cpnDetail.downEddt, "down");
		
		// 사용가능고객구분 체크박스 체크 제거
		$('#CouponForm input:checkbox[name=usableCustGbArr]').prop('checked', false);
		if (cpnCustGbList != null) {
			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 != null) {
			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');
						}
					}
				}
			}
		}
		
		// 첫구매여부
		if (cpnDetail.firstOrdYn == "Y") {
			$('.buyDateTr').css('display' , '');
			$('#CouponForm select[name=buyStdt]').attr('required' , true);
			$('#CouponForm select[name=buyEddt]').attr('required' , true);
			
			splitDate("start"	, cpnDetail.buyStdt, "buy");
			splitDate("end"		, cpnDetail.buyEddt, "buy");
		}
		
		// 신규회원여부
		if (cpnDetail.newCustYn == "Y") {
			$('.custJoinDateTr').css('display' , '');
			$('#CouponForm select[name=custJoinStdt]').attr('required' , true);
			$('#CouponForm select[name=custJoinEddt]').attr('required' , true);
			
			splitDate("start"	, cpnDetail.custJoinStdt, "custJoin");
			splitDate("end"		, cpnDetail.custJoinEddt, "custJoin");
		}
		
		// 총발행제한수량
		if (cpnDetail.totPubLimitQty == 0) {
			$('#CouponForm input:checkbox[name=chkNoLimitTotPubLimitQty]').prop("checked", true);
			$("#CouponForm input[name=totPubLimitQty]").val(0);
			$("#CouponForm input[name=totPubLimitQty]").prop("disabled", true);
			$("#CouponForm input[name=totPubLimitQty]").prop("readonly", true);
		}
		
		// 1인당발행제한수량
		if (cpnDetail.custPubLimitQty == 0) {
			$('#CouponForm input:checkbox[name=chkNoLimitCustPubLimitQty]').prop("checked", true);
			$("#CouponForm input[name=custPubLimitQty]").val(0);
			$("#CouponForm input[name=custPubLimitQty]").prop("disabled", true);
			$("#CouponForm input[name=custPubLimitQty]").prop("readonly", true);
		}
		
		// 비활성화처리 대기상태가아닐때 동작
		if (cpnDetail.cpnStat != 'G232_10' || issueCnt > 0) {
			$("#CouponForm input[name=cpnNm]").attr("disabled", true);
			$("#CouponForm input[name=cpnDesc]").attr("disabled", true);
			$("#CouponForm input:radio[name='rdoDcWay']").attr("disabled", true);
			$("#CouponForm input:radio[name='rdoApplyScope']").attr("disabled", true);
			$("#CouponForm input[name=dcPval]").attr("disabled", true);
			$("#CouponForm input[name=dcMval]").attr("disabled", true);
			$("#CouponForm input[name=dcAval]").attr("disabled", true);
			$("#CouponForm input[name=maxDcAmt]").attr("disabled", true);
			$("#CouponForm input[name=buyLimitAmt]").attr("disabled", true);
			$("#CouponForm input[name=onePubQty]").attr("disabled", true);
			$("#CouponForm input[name=randomCpnQty]").attr("disabled", true);
			$("#CouponForm input[name=serialCpnQty]").attr("disabled", true);
			$("#CouponForm input[name=serialCpnNm]").attr("disabled", true);
			
			$('#CouponForm input:checkbox[name=usableCustGbArr]').attr("disabled", true);
			$('#CouponForm input:checkbox[name=usableCustGradeArr]').attr("disabled", true);
			
			$('#CouponForm input:checkbox[name=chkNoLimitTotPubLimitQty]').attr("disabled", true);
			$('#CouponForm input:checkbox[name=chkNoLimitCustPubLimitQty]').attr("disabled", true);
			
			$("#CouponForm input[name=totPubLimitQty]").attr("disabled", true);
			$("#CouponForm input[name=custPubLimitQty]").attr("disabled", true);
			
			$("#CouponForm select[name=pdGb]").attr("disabled", true);
			$("#CouponForm select[name=siteCd]").attr("disabled", true);
			$("#CouponForm select[name=endAlimYn]").attr("disabled", true);
			$("#CouponForm select[name=firstOrdYn]").attr("disabled", true);
			$("#CouponForm select[name=newCustYn]").attr("disabled", true);
			$("#CouponForm select[name=downAblYn]").attr("disabled", true);
			
			$("#CouponForm input[name=downStDay]").attr('readonly', true);
			$("#CouponForm input[name=downStDay]").attr('disabled', true);
			$("#CouponForm select[name=downStHH]").attr('readonly', true);
			$("#CouponForm select[name=downStHH]").attr('disabled', true);
			$("#CouponForm select[name=downStMM]").attr('readonly', true);
			$("#CouponForm select[name=downStMM]").attr('disabled', true);
			$("#CouponForm input[name=downEdDay]").attr('readonly', true);
			$("#CouponForm input[name=downEdDay]").attr('disabled', true);
			$("#CouponForm select[name=downEdHH]").attr('readonly', true);
			$("#CouponForm select[name=downEdHH]").attr('disabled', true);
			$("#CouponForm select[name=downEdMM]").attr('readonly', true);
			$("#CouponForm select[name=downEdMM]").attr('disabled', true);
			
			$("#CouponForm input[name=availStDay]").attr('readonly', true);
			$("#CouponForm input[name=availStDay]").attr('disabled', true);
			$("#CouponForm select[name=availStHH]").attr('readonly', true);
			$("#CouponForm select[name=availStHH]").attr('disabled', true);
			$("#CouponForm select[name=availStMM]").attr('readonly', true);
			$("#CouponForm select[name=availStMM]").attr('disabled', true);
			$("#CouponForm input[name=availEdDay]").attr('readonly', true);
			$("#CouponForm input[name=availEdDay]").attr('disabled', true);
			$("#CouponForm select[name=availEdHH]").attr('readonly', true);
			$("#CouponForm select[name=availEdHH]").attr('disabled', true);
			$("#CouponForm select[name=availEdMM]").attr('readonly', true);
			$("#CouponForm select[name=availEdMM]").attr('disabled', true);
			
			$("#CouponForm input[name=buyStDay]").attr('readonly', true);
			$("#CouponForm input[name=buyStDay]").attr('disabled', true);
			$("#CouponForm select[name=buyStHH]").attr('readonly', true);
			$("#CouponForm select[name=buyStHH]").attr('disabled', true);
			$("#CouponForm select[name=buyStMM]").attr('readonly', true);
			$("#CouponForm select[name=buyStMM]").attr('disabled', true);
			$("#CouponForm input[name=buyEdDay]").attr('readonly', true);
			$("#CouponForm input[name=buyEdDay]").attr('disabled', true);
			$("#CouponForm select[name=buyEdHH]").attr('readonly', true);
			$("#CouponForm select[name=buyEdHH]").attr('disabled', true);
			$("#CouponForm select[name=buyEdMM]").attr('readonly', true);
			$("#CouponForm select[name=buyEdMM]").attr('disabled', true);
			
			$("#CouponForm input[name=custJoinStDay]").attr('readonly', true);
			$("#CouponForm input[name=custJoinStDay]").attr('disabled', true);
			$("#CouponForm select[name=custJoinStHH]").attr('readonly', true);
			$("#CouponForm select[name=custJoinStHH]").attr('disabled', true);
			$("#CouponForm select[name=custJoinStMM]").attr('readonly', true);
			$("#CouponForm select[name=custJoinStMM]").attr('disabled', true);
			$("#CouponForm input[name=custJoinEdDay]").attr('readonly', true);
			$("#CouponForm input[name=custJoinEdDay]").attr('disabled', true);
			$("#CouponForm select[name=custJoinEdHH]").attr('readonly', true);
			$("#CouponForm select[name=custJoinEdHH]").attr('disabled', true);
			$("#CouponForm select[name=custJoinEdMM]").attr('readonly', true);
			$("#CouponForm select[name=custJoinEdMM]").attr('disabled', true);
		}
	}
});
</script>
</html>











