<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : MainContentsPopupForm.html
 * @desc    : 메인전시 컨텐츠 수정 팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.2.23    bin2107     최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1500" >
	<div class="panelStyle">
		<div class="panelTitle">
			<h2 id="popTitle" th:text="${contentsLoc}"></h2>
			<button type="button" class="close" onclick="fnMainContentsPopupFormClose()"><i class="fa fa-times"></i></button>
		</div>
		<div class="panelContent">
			<ul class="panelBar">
				<li class="aL">
					<span class="cBlue">* 상단으로 드래그&amp;드랍하여 순서 변경 가능합니다.</span>
				</li>
				<li class="aR">
					<button type="button" class="btn btn btn-base btn-sm" id="btnPopAddRow">컨텐츠 추가</button>
					<button type="button" class="btn btn btn-dark btn-sm" id="btnPopSave">임시저장</button>
					<input type="hidden" name="uploadDefaultUrlPop" id="uploadDefaultUrlPop" th:value="${@environment.getProperty('upload.image.view') + '/contents/'}"/>
				</li>
			</ul>
		</div>
		<form style="height:600px; width:1470px; overflow:auto;" id="popSortable">
		</form>
	</div>
</div>

<script type="text/javascript" src="/ux/plugins/summernote/summernote.js?v=2020103001"></script>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.summernote.js?v=2020103001"></script>
<script type="text/javascript" src="/ux/plugins/gaga/gaga.kollus.js"></script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var cateNo = [[${cateNo}]];
	var contentsLoc = [[${contentsLoc}]];
	var brandGroupNo = [[${brandGroupNo}]];
	var contentsLocArr = gagajf.convertToArray([[${contentsLocList}]]);
	var tdWidth = $("#sortable").find("td").width();
	var tdDeleteWidth = parseInt(tdWidth/11, 10);
	tdWidth = tdWidth - tdDeleteWidth;
	var cate1List = [[${cate1List}]];

	var tableLen = 0;		// 테이블 ID

	// 컨텐츠 미리보기 리스트
	var fnGetContentsPreviewList = function() {
		$("#popSortable").html('');
		var data = {cateNo : cateNo
			,contentsLoc : contentsLoc
			,brandGroupNo : brandGroupNo
		};
		var jsonData = JSON.stringify(data);
		gagajf.ajaxJsonSubmit('/display/contents/preview/list', jsonData, fnCreatePopLayout);
	}

	var createIdx = 0;
	var fnCreatePopLayout = function(result) {
		var html = '';
		var descIdx = '';

		for(var i=0; i<result.length; i++){
			descIdx = i;
			var dispStdt = result[i].dispStdt.split(" ");
			var dispEddt = result[i].dispEddt.split(" ");
			var cate1No = result[i].contentsType;
			html += '<table class="frmStyle mcTable" style="margin-bottom:30px" id="mcTable'+i+'">';
			html += '<input type="hidden" name="tableIdx" value="'+i+'" data-id="'+i+'">';
			html += '<colgroup>';
			html += '<col style="width:10%;"/>';
			html += '<col style="width:55%;"/>';
			html += '<col/>';
			html += '</colgroup>';
			html += '<thead><tr><th>전시일시</th><td><input name="dispStdt" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출시작일" data-valid-type="calendar" value="'+dispStdt[0]+'"/>';
			html += '<select name="stTimeHour" required="required" data-valid-name="노출기간 시작시간">';
			html += fnCreateTimeOption(24, dispStdt[1].split(":")[0]);
			html += '</select>';
			html += '<select name="stTimeMin" required="required" data-valid-name="노출기간 시작시간">';
			html += fnCreateTimeOption(60, dispStdt[1].split(":")[1]);
			html += '</select>';
			html += '<span> ~ </span>';
			html += '<input name="dispEddt" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출종료일" data-valid-type="calendar" value="'+dispEddt[0]+'"/>';
			html += '<select name="edTimeHour" required="required" data-valid-name="노출기간 종료시간">';
			html += fnCreateTimeOption(24, dispEddt[1].split(":")[0]);
			html += '</select>';
			html += '<select name="edTimeMin" required="required" data-valid-name="노출기간 종료시간">';
			html += fnCreateTimeOption(60, dispEddt[1].split(":")[1]);
			html += '</select>';
			html += '<input name="dispOrd" type="text" class="w80"placeholder="전시순서" style="margin-left:5px; text-align:center"/>';
			html += '</td>';
			if(contentsLoc!='SCM002' && contentsLoc!='SCM003'){
				html += '<td class="aL">';
				if(contentsLoc!='SMM005'  && contentsLoc!='SMM011' && contentsLoc!='SBM012' && contentsLoc!='SBMM012'){
					html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddTitlePopRow(this);">타이틀추가</button>';
				}
				if(contentsLoc=='SMM001' || contentsLoc=='SMM002' || contentsLoc=='SBM004' || contentsLoc=='SBMM004' || contentsLoc=='SCM001' || contentsLoc=='SOM001'){
					html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddSubTextPopRow(this);">서브텍스트추가</button>';
				}
				if(contentsLoc=='SBM005' || contentsLoc=='SBMM005'){
					html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddBrandDescRow(this);">브랜드소개추가</button>';
				}
				if(contentsLoc!='SMM005' && contentsLoc!='SBM005' && contentsLoc!='SBMM005' && contentsLoc!='SGNB001' && contentsLoc!='SGNB002'  && contentsLoc!='SMM011' && contentsLoc!='SBM012' && contentsLoc!='SBMM012'){
					html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddImgPopRow(this);">이미지추가</button>';
				}
				if(contentsLoc!='SMM011' && contentsLoc!='SBM012' && contentsLoc!='SBMM012'){
					html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddLinkPopRow(this);">링크추가</button>';
				}
				html += '<button type="button" class="btn btn-danger btn-lg" onclick="fnDeleteContentsRow(this);">삭제</button></td>';
			}
			html += '</tr>';
			if(contentsLoc=='SBM004' || contentsLoc=='SBM005' || contentsLoc=='SBMM004' || contentsLoc=='SBMM005'){
				html += '<tr class="cateTypeTr">';
				html += '	<th>클릭시<br>페이지창</th>';
				html += '	<td colspan="3">';
				if(result[i].contentsType=='SELF'){
					html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+i+'" value="SELF" checked="checked"/>현재창</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+i+'" value="BLANK" />새창</label>';
				}else{
					html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+i+'" value="SELF" />현재창</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+i+'" value="BLANK" checked="checked"/>새창</label>';
				}
				html += '	</td>';
				html += '</tr>';
			}
			if(contentsLoc=='SMM011' || contentsLoc=='SBM012' || contentsLoc=='SBMM012'){
				html += '<tr class="cateTypeTr">';
				html += '	<th>동영상구분</th>';
				html += '	<td colspan="3">';
				if(result[i].strVar1=='Y'){
					html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+i+'" value="Y" onclick="fnChangeTvPlayer(this,'+i+');" checked="checked" />YouTube</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+i+'" value="M" onclick="fnChangeTvPlayer(this,'+i+');"/>MP4</label>';
				}else{
					html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+i+'" value="Y" onclick="fnChangeTvPlayer(this,'+i+');" />YouTube</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+i+'" value="M" onclick="fnChangeTvPlayer(this,'+i+');" checked="checked" />MP4</label>';
				}
				html += '	</td>';
				html += '</tr>';
				html += '<tr class="cateTypeTr" name="tvY'+i+'">';
				html += '	<th>미디어<br>컨텐츠키</th>';
				html += '	<td colspan="3">';
				html += '		<input name="tvMediaKey'+i+'" type="text" class="w150" maxlength="200" data-valid-name="미디어 컨텐츠키" value="'+result[i].strVar2+'"/>';
				html += '	</td>';
				html += '</tr>';
				if(result[i].strVar1=='M'){
					html += '<tr class="cateTypeTr" name="tvM'+i+'">';
					html +='	<th>파일첨부<em className="required" title="필수"></em></th>';
					html +='	<td className="infoTxt" colSpan="5">';
					html +='		<div className="uFile w300">';
					html +='			<input id="file'+i+'" name="file" type="file" className="uFileInput w300" onchange="fnVideoFileUpload(this, '+i+')"/>';
					html +='			<label htmlFor="file'+i+'" className="uFileLabel">파일선택</label>';
					html +='			<input type="hidden" name="kufKey" value="'+result[i].strVar3+'"/>';
					html +='			<input type="hidden" name="kmcKey"/>';
					html +='		</div>';
					html +='	</td>';
					html += '</tr>';
				}
			}
			if(contentsLoc=='SGNB001'){
				var src = '';
				var src2 = '';
				html += '<tr class="cateTypeTr">';
				html += '	<th>유형선택</th>';
				html += '	<td colspan="3">';
				html += '		<label class="rdoBtn"><input type="radio" name="cateType'+i+'" value="OPEN" onclick="fnChangeGnbCateType(this,'+i+');"';
				if(result[i].contentsType=='OPEN'){
					html += ' checked="checked" ';
				}
				html += '/>오픈배너</label>';
				html += '		<label class="rdoBtn"><input type="radio" name="cateType'+i+'" value="IMG" onclick="fnChangeGnbCateType(this,'+i+');" ';
				if(result[i].contentsType=='IMG'){
					html += ' checked="checked" ';
				}
				html += '/>이미지배너</label>';
				html += '		<label class="rdoBtn"><input type="radio" name="cateType'+i+'" value="TEXT" onclick="fnChangeGnbCateType(this,'+i+');" ';
				if(result[i].contentsType=='TEXT'){
					html += ' checked="checked" ';
				}
				html += '/>텍스트배너</label>';
				html += '	</td>';
				html += '</tr>';

				if(!gagajf.isNull(result[i].imgPath1)){
					src = $("#uploadDefaultUrlPop").val().replace('/contents/', '')+result[i].imgPath1;
					src2 = $("#uploadDefaultUrlPop").val().replace('/contents/', '')+result[i].imgPath2;
				}
				console.log('src::'+src);

				html += '<tr name="imgPopRow" id="openBanner0" ';
				if(result[i].contentsType=='TEXT'){
					html += '	style="display:none;"';
				}
				html += '>';
				html += '	<th>띠배너<br>이미지</th>';
				html += '	<td><div class="uFile w300">';
				html += '			<input id="filePop_0" name="file" type="file" class="uFileInput w300" onchange="fnPopFileUpload(this, 0)"/>';
				html += '			<label for="filePop_0" class="uFileLabel">파일선택</label>';
				html += '			<input type="hidden" name="imgPath" value="'+result[i].imgPath1+'"/>';
				html += '			<input type="hidden" name="newImgFile" value="" />';
				html += '		</div>';
				html += '	<div id="imgViewPop_0" class=';
				if(src!=''){
					html += '"on">';
				}else{
					html += '"off">';
				}
				html += '		<img id="bannerPreViewUrlPop_0" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'bannerPreimgViewPop\',$(this).attr(\'src\'));"/>';
				html += '	</div></td>';
				html += '</tr>';

				html += '<tr class="cateTypeTr" name="openBannerTypeTr'+i+'" id="openBannerTypeTr" ';
				if(result[i].contentsType!='OPEN'){
					html += '	style="display:none;"';
				}
				html += '>';
				html += '	<th>확장형 배너<br>유형</th>';
				html += '	<td colspan="3">';
				if(result[i].strVar7=='IMG'){
					html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+i+'" value="IMG" onclick="fnChangeOpenBannerType(this,'+i+');" checked="checked"/>이미지형</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+i+'" value="HTML" onclick="fnChangeOpenBannerType(this,'+i+');"/>HTML형</label>';
				}else{
					html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+i+'" value="IMG" onclick="fnChangeOpenBannerType(this,'+i+');" />이미지형</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+i+'" value="HTML" onclick="fnChangeOpenBannerType(this,'+i+');" checked="checked"/>HTML형</label>';
				}
				html += '	</td>';
				html += '</tr>';

				html += '<tr name="imgPopRow" id="openBanner1" ';
				if(result[i].contentsType!='OPEN' && result[i].strVar7!='IMG'){
					html += '	style="display:none;"';
				}
				html +='>';
				html += '	<th>오픈배너<br>이미지</th>';
				html += '	<td><div class="uFile w300">';
				html += '			<input id="filePop_1" name="file" type="file" class="uFileInput w300" onchange="fnPopFileUpload(this, 1)"/>';
				html += '			<label for="filePop_1" class="uFileLabel">파일선택</label>';
				html += '			<input type="hidden" name="imgPath" value="'+result[i].imgPath2+'"/>';
				html += '			<input type="hidden" name="newImgFile" value="" />';
				html += '		</div>';
				html += '	<div id="imgViewPop_1" class=';
				if(src!=''){
					html += '"on">';
				}else{
					html += '"off">';
				}
				html += '		<img id="bannerPreViewUrlPop_1" src="'+src2+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'bannerPreimgViewPop\',$(this).attr(\'src2\'));"/>';
				html += '	</div></td>';
				html += '</tr>';

				html += '<tr name="imgPopRow" id="openBanner2" ';
				if(result[i].contentsType!='OPEN' || result[i].strVar7!='HTML'){
					html += '	style="display:none;"';
				}
				html += '>';
				html += '	<input type="hidden" name="htmlDesc'+i+'" id="htmlDesc'+i+'" value="'+result[i].html+'">';
				html += '	<th>오픈배너<br>HTML</th>';
				html += '	<td class="padT10"><div class="tabJrContArea">';
				html += '		<textarea class="textareaR3 summernote" name="openBannerDesc'+i+'" id="openBannerDesc'+i+'" ></textarea>';
				html += '	</div>';
				html += '	</td>';
				html += '</tr>';

				html += '	<tr name="tabBgColorRow'+i+'"';
				if(result[i].contentsType=='TEXT'){
					html += 'style="display:none;"';
				}
				html += ' >';
				html += '		<th>배경 RGB코드</th>';
				html += '		<td><input name="gnbBgColor' + i + '" type="text" maxlength="200" data-valid-name="배경 RGB코드" value="' + result[i].strVar5 + '"/></td>';
				html += '	</tr>';

				html += '	<tr name="tabShowYnRow'+i+'"';
				if(result[i].contentsType!='OPEN'){
					html += 'style="display:none;"';
				}
				html += ' >';
				html += '		<th>닫기 버튼<br>노출여부</th>';
				html += '		<td>';
				if(result[i].strVar8=='Y'){
					html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+i+'" value="Y" checked="checked"/>노출</label>';
					html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+i+'" value="N" />비노출</label>';
				}else{
					html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+i+'" value="Y" />노출</label>';
					html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+i+'" value="N" checked="checked"/>비노출</label>';
				}

				html += '		</td>';
				html += '	</tr>';
			}
			if(contentsLoc=='SCM002' || contentsLoc=='SCM003'){
				html += '		<tr>';
				html += '			<th>전시 설정</th>';
				html += '			<td>';
				if(result[i].useYn=='Y'){
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="Y" checked="checked"/>노출</label>';
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="N"/>비노출</label>';
				}else{
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="Y"/>노출</label>';
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="N" checked="checked"/>비노출</label>';
				}
				html += '			</td>';
				if(result[i].contentsLoc=='SCM003'){
					html += '			<th>상품 노출 개수</th>';
					html += '			<td>';
					if(result[i].strVar1=='10'){
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="10" checked="checked"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="20"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="30"/>30개</label>';
					}else if(result[i].strVar1=='20'){
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="10"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="20" checked="checked"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="30"/>30개</label>';
					}else{
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="10"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="20"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="30" checked="checked"/>30개</label>';
					}
					html += '			</td>';
				}
				html += '		</tr>';
			}
			if(contentsLoc=='SMM001' || contentsLoc=='SOM001'){
				html += '<tr>';
				html += '	<th>컨텐츠유형</th>';
				html += '	<td class="planArea" name="planArea" id="planArea'+i+'" colspan="3">';
				if(result[i].strVar5=='P'){
					html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+i+'" value="P" onclick="fnChangeContentsType(this,'+i+');" checked="checked"/>기획전</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+i+'" value="E" onclick="fnChangeContentsType(this,'+i+');"/>이벤트</label>';
				}else{
					html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+i+'" value="P" onclick="fnChangeContentsType(this,'+i+');" />기획전</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+i+'" value="E" onclick="fnChangeContentsType(this,'+i+');" checked="checked"/>이벤트</label>';
				}
				if(result[i].strVar5=='P') {
					html += '		<input type="text" class="w100 inputPlan" name="planSq' + i + '" value="' + result[i].strVar6 + '"/>';
					html += '		<button type="button" class="btn btn btn-dark btn-sm btnPlan" onclick="fnSearchPlan(' + i + ');">기획전검색</button>';
				}else{
					html += '		<input type="text" class="w100 inputPlan" name="planSq' + i + '" value="" style="display: none;"/>';
					html += '		<button type="button" class="btn btn btn-dark btn-sm btnPlan" onclick="fnSearchPlan(' + i + ');" style="display: none;">기획전검색</button>';
				}
				html += '	</td>';
				html += '</tr>';
				html += '<tr>';
				html += '	<th>썸네일 <br>글자 색상</th>';
				html += '	<td colspan="3">';
				if(result[i].strVar7=='BLACK'){
					html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+i+'" value="BLACK" checked="checked"/>BLACK</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+i+'" value="WHITE" />WHITE</label>';
				}else{
					html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+i+'" value="BLACK" />BLACK</label>';
					html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+i+'" value="WHITE" checked="checked"/>WHITE</label>';
				}
				html += '	</td>';
				html += '</tr>';
			}
			if(contentsLoc=='SMM005'){
					html += '<tr>';
					html += '	<th>배너유형</th>';
					html += '	<td class="bannerArea" id="bannerArea'+i+'">';
					if(result[i].contentsType=='1'){
						html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+i+'" value="1" checked="checked">1단</label>';
						html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+i+'" value="2" >2단</label>';
					}else{
						html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+i+'" value="1" >1단</label>';
						html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+i+'" value="2" checked="checked">2단</label>';
					}
					html += '	</td>';
					html += '</tr>';
			}
			html += '</thead><tbody>';
			if(contentsLoc!='SCM002' && contentsLoc!='SCM003' && contentsLoc!='SMM011' && contentsLoc!='SBM012' && contentsLoc!='SBMM012'){
				for(var j=1; j<5; j++){
					var strTitle = eval("result["+i+"].strTitle" + j);
					var imgPath = eval("result["+i+"].imgPath" + j);
					var strVar = eval("result["+i+"].strVar" + j);
					var subText = eval("result["+i+"].subText" + j);
					if(strTitle!=null && strTitle!='null' && strTitle!='' ){
						html += fnAddTitlePopRow(strTitle);
					}
					if(contentsLoc!='SGNB001'){
						if(imgPath!=null && imgPath!='null' && imgPath!='' ){
							html += fnAddImgPopRow(imgPath);
						}
					}
					if(strVar!=null && strVar!='null' && strVar!='' ){
						html += fnAddLinkPopRow(strVar);
					}
					if(subText!=null && subText!='null' && subText!='' ){
						html += fnAddSubTextPopRow(subText);
					}
				}
			}

			html += '</tbody></table>';
		}
		$("#popSortable").append(html);
		$("#popSortable").sortable();
		$('.schDate').datepicker("destroy");
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});

		// SGNB001 일때 확장형 배너 summernote
		if(contentsLoc=='SGNB001'){
			fnOpenBannerSummernote();
		}

		tableLen = $(".mcTable").length;
	}

	var fnOpenBannerSummernote = function (){
		$('.mcTable').each(function(){
			let idx = $(this).find('[name=tableIdx]').val();
			let bannerCateType = $("#mcTable"+idx).find('input:radio[name=cateType'+idx+']:checked').val();

			// if(bannerCateType=='OPEN'){
			// 	let bannerType = $("#mcTable"+idx).find('input:radio[name=openBannerType'+idx+']:checked').val();
			// 	if(bannerType=='HTML'){
			// 		let htmlDesc = $("#mcTable"+idx).find('input[name=htmlDesc'+idx+']').val();
			// 		gagaSn.setContents('#openBannerDesc'+idx, '');
			// 		$('#openBannerDesc'+idx).summernote('code', htmlDesc);
			// 	}
			// }
			let htmlDesc = $("#mcTable"+idx).find('input[name=htmlDesc'+idx+']').val();
			gagaSn.setContents('#openBannerDesc'+idx, '');
			$('#openBannerDesc'+idx).summernote('code', htmlDesc);
		});
	}

	var fnChangeTvPlayer = function (obj,idx){
		let tvPlayer = $("#mcTable"+idx).find("input:radio[name=tvPlayer"+idx+"]:checked").val();

		if(tvPlayer == 'Y'){
			$(obj).closest("table").find("[name=tvY"+idx+"]").show();
			$(obj).closest("table").find("[name=tvM"+idx+"]").hide();
		}else{
			$(obj).closest("table").find("[name=tvY"+idx+"]").show();
			$(obj).closest("table").find("[name=tvM"+idx+"]").show();
		}
	}

	var fnChangeOpenBannerType = function (obj, idx){
		let openBannerType = $("#mcTable"+idx).find("input:radio[name=openBannerType"+idx+"]:checked").val();

		if(openBannerType == 'IMG'){
			$(obj).closest("table").find("[id=openBanner1]").show();
			$(obj).closest("table").find("[id=openBanner2]").hide();
		}else{
			$(obj).closest("table").find("[id=openBanner1]").hide();
			$(obj).closest("table").find("[id=openBanner2]").show();
		}
	}

	var fnChangeGnbCateType = function (obj, idx){
		let cateType = $("#mcTable"+idx).find("input:radio[name=cateType"+idx+"]:checked").val();

		if(cateType=='OPEN'){
			$(obj).closest("table").find("[name=tabBgColorRow"+idx+"]").show();
			$(obj).closest("table").find("[name=tabShowYnRow"+idx+"]").show();
			$(obj).closest("table").find("[name=openBannerTypeTr"+idx+"]").show();
			$(obj).closest("table").find("input:radio[name=openBannerType"+idx+"]:input[value=IMG]").prop('checked',true);
			$(obj).closest("table").find("[id=openBanner0]").show();
			$(obj).closest("table").find("[id=openBanner1]").show();
			$(obj).closest("table").find("[id=openBanner2]").hide();
			$(obj).closest("table").find("[name=file]").closest('div').find('label').text('파일선택');
			$(obj).closest("table").find("[name=imgPath]").val('');
			$(obj).closest("table").find("[name=newImgFile]").val('');
			$("#bannerPreViewUrlPop_0").attr('src', '');
			$("#imgViewPop_0").removeClass("on").addClass("off");
			$("#bannerPreViewUrlPop_1").attr('src', '');
			$("#imgViewPop_1").removeClass("on").addClass("off");
		}else if(cateType=='IMG'){
			$(obj).closest("table").find("[name=tabBgColorRow"+idx+"]").show();
			$(obj).closest("table").find("[name=tabShowYnRow"+idx+"]").hide();
			$(obj).closest("table").find("[name=openBannerTypeTr"+idx+"]").hide();
			$(obj).closest("table").find("input:radio[name=openBannerType"+idx+"]:input[value=IMG]").prop('checked',true);
			$(obj).closest("table").find("[id=openBanner0]").show();
			$(obj).closest("table").find("[id=openBanner1]").hide();
			$(obj).closest("table").find("[id=openBanner2]").hide();
			$(obj).closest("table").find("[name=file]").closest('div').find('label').text('파일선택');
			$(obj).closest("table").find("[name=imgPath]").val('');
			$(obj).closest("table").find("[name=newImgFile]").val('');
			$("#bannerPreViewUrlPop_0").attr('src', '');
			$("#imgViewPop_0").removeClass("on").addClass("off");
			$("#bannerPreViewUrlPop_1").attr('src', '');
			$("#imgViewPop_1").removeClass("on").addClass("off");
		}else if(cateType=='TEXT'){
			$(obj).closest("table").find("[name=tabBgColorRow"+idx+"]").hide();
			$(obj).closest("table").find("[name=tabShowYnRow"+idx+"]").hide();
			$(obj).closest("table").find("[name=openBannerTypeTr"+idx+"]").hide();
			$(obj).closest("table").find("input:radio[name=openBannerType"+idx+"]:input[value=IMG]").prop('checked',true);
			$(obj).closest("table").find("[id=openBanner0]").hide();
			$(obj).closest("table").find("[id=openBanner1]").hide();
			$(obj).closest("table").find("[id=openBanner2]").hide();
			$(obj).closest("table").find("[name=file]").closest('div').find('label').text('파일선택');
			$(obj).closest("table").find("[name=imgPath]").val('');
			$(obj).closest("table").find("[name=newImgFile]").val('');
			$("#bannerPreViewUrlPop_0").attr('src', '');
			$("#imgViewPop_0").removeClass("on").addClass("off");
			$("#bannerPreViewUrlPop_1").attr('src', '');
			$("#imgViewPop_1").removeClass("on").addClass("off");
		}
	}

	/**
	 * 컨텐츠 추가 버튼
	 */
	var dataIdx=0;
	$("#btnPopAddRow").on("click", function (){
		dataIdx = tableLen;
		if(contentsLoc=='SCM002' || contentsLoc=='SCM003'){
			if($(".mcTable").length > 0){
				mcxDialog.alert('컨텐츠 추가를 1개 이상 할 수 없습니다.');
				return;
			}
		}

		var html = '<table class="frmStyle mcTable" style="margin-bottom:30px" id="mcTable'+dataIdx+'">';
		html += '<input type="hidden" name="tableIdx" value="'+dataIdx+'" data-id="'+dataIdx+'">';
		html += '<colgroup>';
		html += '<col style="width:10%;"/>';
		html += '<col style="width:55%;"/>';
		html += '<col/>';
		html += '</colgroup>';
		html += '<thead><tr><th>전시일시</th><td><input name="dispStdt" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출시작일" data-valid-type="calendar"/>';
		html += '<select name="stTimeHour" required="required" data-valid-name="노출기간 시작시간">';
		html += fnCreateTimeOption(24);
		html += '</select>';
		html += '<select name="stTimeMin" required="required" data-valid-name="노출기간 시작시간">';
		html += fnCreateTimeOption(60);
		html += '</select>';
		html += '<span> ~ </span>';
		html += '<input name="dispEddt" type="text" class="w80 schDate" maxlength="10" required="required" data-valid-name="노출종료일" data-valid-type="calendar"/>';
		html += '<select name="edTimeHour" required="required" data-valid-name="노출기간 종료시간">';
		html += fnCreateTimeOption(24,23);
		html += '</select>';
		html += '<select name="edTimeMin" required="required" data-valid-name="노출기간 종료시간">';
		html += fnCreateTimeOption(60,59);
		html += '</select>';
		html += '<input name="dispOrd" type="text" class="w80"placeholder="전시순서" style="margin-left:5px; text-align:center"/>';
		html += '</td>';
		html += '<td class="aL">';
		if(contentsLoc!='SCM002' && contentsLoc!='SCM003' && contentsLoc!='SMM011' && contentsLoc!='SBM012' && contentsLoc!='SBMM012'){
			if(contentsLoc!='SMM005'){
				html += '<button type="button" class="btn btn-base btn-lg" id="addTitle'+dataIdx+'" onclick="fnAddTitlePopRow(this);">타이틀추가</button>';
			}
			if(contentsLoc=='SMM001' || contentsLoc=='SMM002' || contentsLoc=='SBM004' || contentsLoc=='SBMM004' || contentsLoc=='SCM001' || contentsLoc=='SOM001'){
				html += '<button type="button" class="btn btn-base btn-lg" id="addSubText'+dataIdx+'" onclick="fnAddSubTextPopRow(this);">서브텍스트추가</button>';
			}
			if(contentsLoc=='SBM005' || contentsLoc=='SBMM005'){
				html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddBrandDescRow(this);">브랜드소개추가</button>';
			}
			if(contentsLoc!='SBM005' && contentsLoc!='SBMM005' && contentsLoc!='SGNB001') {
				html += '<button type="button" class="btn btn-base btn-lg" id="addImg'+dataIdx+'" onclick="fnAddImgPopRow(this);">이미지추가</button>';
			}
				html += '<button type="button" class="btn btn-base btn-lg" id="addLink'+dataIdx+'" onclick="fnAddLinkPopRow(this);">링크추가</button>';
		}
		html += '<button type="button" class="btn btn-danger btn-lg" onclick="fnDeleteContentsRow(this);">삭제</button></td>';
		html += '</tr>';
		if(contentsLoc=='SBM004' || contentsLoc=='SBM005' || contentsLoc=='SBMM004' || contentsLoc=='SBMM005'){
			html += '<tr class="cateTypeTr">';
			html += '	<th>클릭시<br>페이지창</th>';
			html += '	<td colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+dataIdx+'" value="SELF" checked="checked"/>현재창</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="pageTarget'+dataIdx+'" value="BLANK" />새창</label>';
			html += '	</td>';
			html += '</tr>';
		}
		if(contentsLoc=='SMM011' || contentsLoc=='SBM012' || contentsLoc=='SBMM012'){
			html += '<tr class="cateTypeTr">';
			html += '	<th>동영상구분</th>';
			html += '	<td colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+dataIdx+'" value="Y" onclick="fnChangeTvPlayer(this,'+dataIdx+');" checked="checked" />YouTube</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="tvPlayer'+dataIdx+'" value="M" onclick="fnChangeTvPlayer(this,'+dataIdx+');"/>MP4</label>';
			html += '	</td>';
			html += '</tr>';
			html += '<tr class="cateTypeTr" name="tvY'+dataIdx+'">';
			html += '	<th>미디어<br>컨텐츠키</th>';
			html += '	<td colspan="3">';
			html += '		<input name="tvMediaKey'+dataIdx+'" type="text" class="w150" maxlength="200" data-valid-name="미디어 컨텐츠키" value=""/>';
			html += '	</td>';
			html += '</tr>';
			html += '<tr class="cateTypeTr" name="tvM'+dataIdx+'" style="display: none;">';
			html +='	<th>파일첨부<em className="required" title="필수"></em></th>';
			html +='	<td className="infoTxt" colSpan="5">';
			html +='		<div className="uFile w300">';
			html +='			<input id="file'+dataIdx+'" name="file" type="file" className="uFileInput w300" onchange="fnVideoFileUpload(this, '+dataIdx+')"/>';
			html +='			<label htmlFor="file'+dataIdx+'" className="uFileLabel">파일선택</label>';
			html +='			<input type="hidden" name="kufKey"/>';
			html +='			<input type="hidden" name="kmcKey"/>';
			html +='		</div>';
			html +='	</td>';
			html += '</tr>';
		}
		if(contentsLoc=='SGNB001'){
			html += '<tr class="cateTypeTr">';
			html += '	<th>유형선택</th>';
			html += '	<td colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="cateType'+dataIdx+'" value="OPEN" onclick="fnChangeGnbCateType(this,'+dataIdx+');" checked="checked"/>오픈배너</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="cateType'+dataIdx+'" value="IMG" onclick="fnChangeGnbCateType(this,'+dataIdx+');"/>이미지배너</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="cateType'+dataIdx+'" value="TEXT" onclick="fnChangeGnbCateType(this,'+dataIdx+');"/>텍스트배너</label>';
			html += '	</td>';
			html += '</tr>';

			var src = '';
			html += '<tr name="imgPopRow" id="openBanner0">';
			html += '	<th>띠배너<br>이미지</th>';
			html += '	<td><div class="uFile w300">';
			html += '			<input id="filePop_0" name="file" type="file" class="uFileInput w300" onchange="fnPopFileUpload(this, 0)"/>';
			html += '			<label for="filePop_0" class="uFileLabel">파일선택</label>';
			html += '			<input type="hidden" name="imgPath" value=""/>';
			html += '			<input type="hidden" name="newImgFile" value="" />';
			html += '		</div>';
			html += '	<div id="imgViewPop_0" class=';
			if(src!=''){
				html += '"on">';
			}else{
				html += '"off">';
			}
			html += '		<img id="bannerPreViewUrlPop_0" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'bannerPreimgViewPop\',$(this).attr(\'src\'));"/>';
			html += '	</div></td>';
			html += '</tr>';

			html += '<tr class="cateTypeTr" name="openBannerTypeTr'+dataIdx+'" id="openBannerTypeTr">';
			html += '	<th>확장형 배너<br>유형</th>';
			html += '	<td colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+dataIdx+'" value="IMG" onclick="fnChangeOpenBannerType(this,'+dataIdx+');" checked="checked"/>이미지형</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="openBannerType'+dataIdx+'" value="HTML" onclick="fnChangeOpenBannerType(this,'+dataIdx+');"/>HTML형</label>';
			html += '	</td>';
			html += '</tr>';

			html += '<tr name="imgPopRow" id="openBanner1">';
			html += '	<th>오픈배너<br>이미지</th>';
			html += '	<td><div class="uFile w300">';
			html += '			<input id="filePop_1" name="file" type="file" class="uFileInput w300" onchange="fnPopFileUpload(this, 1)"/>';
			html += '			<label for="filePop_1" class="uFileLabel">파일선택</label>';
			html += '			<input type="hidden" name="imgPath" value=""/>';
			html += '			<input type="hidden" name="newImgFile" value="" />';
			html += '		</div>';
			html += '	<div id="imgViewPop_1" class=';
			if(src!=''){
				html += '"on">';
			}else{
				html += '"off">';
			}
			html += '		<img id="bannerPreViewUrlPop_1" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'bannerPreimgViewPop\',$(this).attr(\'src\'));"/>';
			html += '	</div></td>';
			html += '</tr>';

			html += '<tr name="imgPopRow" id="openBanner2" style="display: none;">';
			html += '	<input type="hidden" name="htmlDesc'+dataIdx+'" id="htmlDesc'+dataIdx+'" value="">';
			html += '	<th>오픈배너<br>HTML</th>';
			html += '	<td class="padT10"><div class="tabJrContArea">';
			html += '		<textarea class="textareaR3 summernote" name="openBannerDesc'+dataIdx+'" id="openBannerDesc'+dataIdx+'"></textarea>';
			html += '	</div>';
			html += '	</td>';
			html += '</tr>';

			html += '	<tr name="tabBgColorRow'+dataIdx+'">';
			html += '		<th>배경 RGB코드</th>';
			html += '		<td><input name="gnbBgColor'+dataIdx+'" type="text" maxlength="200" data-valid-name="배경 RGB코드" value=""/></td>';
			html += '	</tr>';
			html += '	<tr name="tabShowYnRow'+dataIdx+'">';
			html += '		<th>오늘하루 보지않기<br>노출여부</th>';
			html += '		<td>';
			html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+dataIdx+'" value="Y" checked="checked"/>노출</label>';
			html += '			<label class="rdoBtn"><input type="radio" name="todayYn'+dataIdx+'" value="N" />비노출</label>';
			html += '		</td>';
			html += '	</tr>';
		}
		if(contentsLoc=='SCM002' || contentsLoc=='SCM003'){
			html += '		<tr>';
			html += '			<th>전시 설정</th>';
			html += '			<td>';
			html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="Y" checked="checked"/>노출</label>';
			html += '				<label class="rdoBtn"><input type="radio" name="dispYn" value="N"/>비노출</label>';
			html += '			</td>';
			if(contentsLoc=='SCM003'){
				html += '			<th>상품 노출 개수</th>';
				html += '			<td>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="10" checked="checked"/>10개</label>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="20"/>20개</label>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt" value="30"/>30개</label>';
				html += '			</td>';
			}
			html += '		</tr>';
		}
		if(contentsLoc=='SMM001' || contentsLoc=='SOM001'){
			html += '<tr>';
			html += '	<th>컨텐츠유형</th>';
			html += '	<td class="planArea" name="planArea" id="planArea'+dataIdx+'" colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+dataIdx+'" value="P" onclick="fnChangeContentsType(this,'+dataIdx+');" checked="checked"/>기획전</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="contentsType'+dataIdx+'" value="E" onclick="fnChangeContentsType(this,'+dataIdx+');"/>이벤트</label>';
			html += '		<input type="text" class="w100 inputPlan" name="planSq'+dataIdx+'" value=""/>';
			html += '		<button type="button" class="btn btn btn-dark btn-sm btnPlan" onclick="fnSearchPlan('+dataIdx+');">기획전검색</button>';
			html += '	</td>';
			html += '</tr>';
			html += '<tr>';
			html += '	<th>썸네일 <br>글자 색상</th>';
			html += '	<td colspan="3">';
			html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+dataIdx+'" value="BLACK" checked="checked"/>BLACK</label>';
			html += '		<label class="rdoBtn"><input type="radio" name="thumTextColor'+dataIdx+'" value="WHITE" />WHITE</label>';
			html += '	</td>';
			html += '</tr>';
		}
		if(contentsLoc=='SMM005'){
			html += '<tr>';
			html += '	<th>배너유형</th>';
			html += '	<td class="bannerArea" id="bannerArea'+dataIdx+'">';
			html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+dataIdx+'" value="1" checked="checked">1단</label>';	/*onclick="fnChangeBannerType(this,1);"*/
			html += '		<label class="rdoBtn"><input type="radio" name="bannerType'+dataIdx+'" value="2" >2단</label>';
			html += '	</td>';
			html += '</tr>';
		}
		html += '</thead><tbody>';
		html += '</tbody></table>';

		$("#popSortable").prepend(html);
		$("#popSortable").sortable();
		$('.schDate').datepicker("destroy");
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});
		if(contentsLoc=='SMM001' || contentsLoc=='SOM001'){
			$("#addTitle"+dataIdx).click();
			$("#addSubText"+dataIdx).click();
			$("#addLink"+dataIdx).click();
			$("#addImg"+dataIdx).click();
		}

		if(contentsLoc=='SGNB001'){
			gagaSn.setContents('#openBannerDesc'+dataIdx, '');
		}

		tableLen = tableLen+1;
	});

	var fnVideoFileUpload = function (obj, idx){
		var file = obj.files[0];
		gagaKollus.upload('Display', file, $(obj).find('input[name=kufKey]'));
	}

	var fnChangeBannerType = function (obj, idx){
		if(idx==1){
			$(obj).closest("table").find("[id=bannerImgTr1]").show();
			$(obj).closest("table").find("[id=bannerLinkTr1]").show();
			$(obj).closest("table").find("[id=bannerImgTr2]").hide();
			$(obj).closest("table").find("[id=bannerLinkTr2]").hide();
		}else{
			$(obj).closest("table").find("[id=bannerImgTr1]").show();
			$(obj).closest("table").find("[id=bannerLinkTr1]").show();
			$(obj).closest("table").find("[id=bannerImgTr2]").show();
			$(obj).closest("table").find("[id=bannerLinkTr2]").show();
		}
	}

	// 몰메인>메인롤링배너 컨텐츠유형 선택시
	var fnChangeContentsType = function (obj, idx){
		var radioVal = $(obj).closest("td").find("input[name=contentsType"+idx+"]:checked").val();
		if(radioVal=='P'){
			$("#planArea"+idx+" .inputPlan").show();
			$("#planArea"+idx+" .btnPlan").show();
		}else{
			$("#planArea"+idx).find("input[name=planSq"+idx+"]").val('');
			$("#planArea"+idx+" .inputPlan").hide();
			$("#planArea"+idx+" .btnPlan").hide();
		}
	}

	// 몰메인>메인롤링배너 기획전 조회
	var tableDataId = 0;
	var fnSearchPlan = function (idx){
		cfnOpenPlanPopup('callbackPlanPopup');
		tableDataId = idx;
	}

	var callbackPlanPopup = function (result){
		$("#mcTable"+tableDataId+" .planArea").find("input[name=planSq"+tableDataId+"]").val(result[0].planSq);
		$("#mcTable"+tableDataId).find("tr[name=titlePopRow]").find("input[name=title]").val(result[0].planNm);
		$("#mcTable"+tableDataId).find("tr[name=subTextPopRow]").find("input[name=subText]").val(result[0].dtlTitle1);
		$("#mcTable"+tableDataId).find("tr[name=linkPopRow]").find("input[name=link]").val('/planning/detail/form?planSq='+result[0].planSq);
		$("#mcTable"+tableDataId).find("tr[name=imgPopRow]").find("input[name=imgPath]").val(result[0].mainPimg);
		$("#mcTable"+tableDataId).find("#bannerPreViewUrlPop_"+tableDataId).attr('src',$("#uploadDefaultUrlPop").val().replace('/contents/', '')+result[0].mainPimg);
		$("#mcTable"+tableDataId).find("#imgViewPop_"+tableDataId).removeClass("off").addClass("on");

		let stdt = result[0].dispStdt.split(" ");
		let eddt = result[0].dispEddt.split(" ");
		let stdtTime;
		let eddtTime;

		$("#mcTable"+tableDataId).find("[name=dispStdt]").val(stdt[0]);
		$("#mcTable"+tableDataId).find("[name=dispEddt]").val(eddt[0]);
		if(!gagajf.isNull(stdt[1])){
			stdtTime = stdt[1].split(":");
		}
		if(!gagajf.isNull(eddt[1])){
			eddtTime = eddt[1].split(":");
		}
		$("#mcTable"+tableDataId).find("[name=stTimeHour]").val(stdtTime[0]+'시').prop("selected", true);
		$("#mcTable"+tableDataId).find("[name=stTimeMin]").val(stdtTime[1]+'분').prop("selected", true);
		$("#mcTable"+tableDataId).find("[name=edTimeHour]").val(eddtTime[0]+'시').prop("selected", true);
		$("#mcTable"+tableDataId).find("[name=edTimeMin]").val(eddtTime[1]+'분').prop("selected", true);
	}

	// SMM001 데이터 validation 체크
	function smm001DataValidation(){
		$(".mcTable").each(function(i){
			var thisIdx = $(this).find("input[name=tableIdx]").val();
			var contentsTypeVal = $(this).find("input:radio[name=contentsType"+thisIdx+"]:checked").val();
			var textColorVal = $(this).find("input:radio[name=thumTextColor"+thisIdx+"]:checked").val();

			if(gagajf.isNull(contentsTypeVal)){
				mcxDialog.alert('컨텐츠 유형을 선택해주세요.');
				return false;
			}
			if(contentsTypeVal=='P'){
				if(gagajf.isNull($(this).find("input[name=planSq"+thisIdx+"]").val())){
					mcxDialog.alert('기획전 번호를 입력해주세요.');
					return false;
				}
			}
			if(gagajf.isNull(textColorVal)){
				mcxDialog.alert('썸네일 글자 색상을 선택해주세요.');
				return false;
			}
		});

		return true;
	}

	/**
	 * 임시저장
	 */
	var dataArr = [];
	$("#btnPopSave").on("click", function (){
		if (!gagajf.checkRequired("#popSortable")) {
			return;
		}

		if(contentsLoc=='SMM001' || contentsLoc=='SOM001'){
			if(!smm001DataValidation()){
				return false;
			}
		}

		var titleBool = true;
		$("#popSortable").find('input[name=title]').each(function(idx, title) {
			if ($(title).val()==''){
				titleBool = false;
				$(title).focus();
				gagajf.alertMessage($(title), 'input');
				return;
			}
		});
		if(!titleBool){
			return false;
		}
		dataArr = [];
		$("#popSortable table").each(function(){
			var newImgFileArr = [];
			var imgPath1 = '';
			var imgPath2 = '';
			var imgPath3 = '';
			var imgPath4 = '';
			var strVar1 = '';
			var strVar2 = '';
			var strVar3 = '';
			var strVar4 = '';
			var strVar5 = '';
			var strVar6 = '';
			var strVar7 = '';
			var strVar8 = '';
			var strTitle1 = '';
			var strTitle2 = '';
			var strTitle3 = '';
			var strTitle4 = '';
			var subText1 = '';
			var subText2 = '';
			var subText3 = '';
			var subText4 = '';
			var contentsType = '';
			var useYn = 'Y';
			var html = '';
			var i = 1;
			$(this).find('input[name=imgPath]').each(function(){
				eval("imgPath" + i + "='"+$(this).val()+"'");
				i++;
			});
			$(this).find('input[name=newImgFile]').each(function(){
				newImgFileArr.push($(this).val());
			});
			i = 1;
			$(this).find('input[name=title]').each(function(){
				var title = $(this).val().replace(/[\']/gi, "\\'");
				eval("strTitle" + i + "='"+title+"'");
				i++;
			});
			i = 1;
			$(this).find('input[name=link]').each(function(){
				_mall = [[${@environment.getProperty('domain.front')}]];
				var val = $(this).val();
				val = val.replace('https:'+_mall, '');
				val = val.replace('http:'+_mall, '');
				val = val.replace(_mall, '');
				eval("strVar" + i + "='"+val+"'");
				i++;
			});
			i = 1;
			$(this).find('input[name=subText]').each(function(){
				var subText = $(this).val().replace(/[\']/gi, "\\'");
				eval("subText" + i + "='"+subText+"'");
				i++;
			});

			if(contentsLoc=='SMM011' || contentsLoc=='SBM012' || contentsLoc=='SBMM012'){
				var thisIdx = $(this).find("input[name=tableIdx]").val();
				strVar1 = $(this).find("input:radio[name=tvPlayer"+thisIdx+"]:checked").val();
				strVar2 = $(this).find("input[name=tvMediaKey"+thisIdx+"]").val();
				strVar3 = $(this).find("input[name=kufKey]").val();
			}

			var dispStdt = $(this).find("[name=dispStdt]").val().replace(/[^0-9]/g, '') + "" +$(this).find("[name=stTimeHour]").val().replace('시', '') + "" +$(this).find("[name=stTimeMin]").val().replace('분', '') + "00";
			var dispEddt = $(this).find("[name=dispEddt]").val().replace(/[^0-9]/g, '') + "" +$(this).find("[name=edTimeHour]").val().replace('시', '') + "" +$(this).find("[name=edTimeMin]").val().replace('분', '') + "59";

			var dispOrd = $(this).find("[name=dispOrd]").val();

			if(contentsLoc=='SBM004' || contentsLoc=='SBM005' || contentsLoc=='SBMM004' || contentsLoc=='SBMM005'){
				var thisIdx = $(this).find("input[name=tableIdx]").val();
				contentsType = $(this).find("input:radio[name=pageTarget"+thisIdx+"]:checked").val();
			}
			if(contentsLoc=='SGNB001'){
				var thisIdx = $(this).find("input[name=tableIdx]").val();
				contentsType = $(this).find("input:radio[name=cateType"+thisIdx+"]:checked").val();
				strVar5 = $(this).find("input[name=gnbBgColor"+thisIdx+"]").val();
				strVar6 = $(this).find("input[name=gnbTextColor"+thisIdx+"]").val();
				strVar8 = $(this).find("input:radio[name=todayYn"+thisIdx+"]:checked").val();
				strVar7 = $(this).find("input:radio[name=openBannerType"+thisIdx+"]:checked").val();
				if($(this).find("input:radio[name=openBannerType"+thisIdx+"]:checked").val() == 'HTML'){
					html = $(this).find("textarea[name=openBannerDesc"+thisIdx+"]").val();
				}
			}

			if(contentsLoc=='SMM001' || contentsLoc=='SOM001'){
				var thisIdx = $(this).find("input[name=tableIdx]").val();
				strVar5 = $(this).find("input:radio[name=contentsType"+thisIdx+"]:checked").val();
				strVar6 = $(this).find("input[name=planSq"+thisIdx+"]").val();
				strVar7 = $(this).find("input:radio[name=thumTextColor"+thisIdx+"]:checked").val();
			}

			if(contentsLoc=='SMM005'){
				var thisIdx = $(this).find("input[name=tableIdx]").val();
				contentsType = $(this).find("input:radio[name=bannerType"+thisIdx+"]:checked").val();
			}

			if(contentsLoc=='SCM002' || contentsLoc=='SCM003'){
				useYn = $(this).find("input:radio[name=dispYn]:checked").val();
			}
			if(contentsLoc=='SCM003'){
				strVar1 = $(this).find("input:radio[name=dispCnt]:checked").val();
			}

			var data = {cateNo : cateNo
				, contentsLoc : contentsLoc
				, contentsType : contentsType
				, dispStdt : dispStdt
				, dispEddt : dispEddt
				, newImgFileArr : newImgFileArr
				, imgPath1 : imgPath1
				, imgPath2 : imgPath2
				, imgPath3 : imgPath3
				, imgPath4 : imgPath4
				, strVar1 : strVar1
				, strVar2 : strVar2
				, strVar3 : strVar3
				, strVar4 : strVar4
				, strVar5 : strVar5
				, strVar6 : strVar6
				, strVar7 : strVar7
				, strVar8 : strVar8
				, strTitle1 : strTitle1
				, strTitle2 : strTitle2
				, strTitle3 : strTitle3
				, strTitle4 : strTitle4
				, subText1 : subText1
				, subText2 : subText2
				, subText3 : subText3
				, subText4 : subText4
				, useYn : useYn
				, dispOrd : dispOrd
				, brandGroupNo : brandGroupNo
				, html : html
			};

			dataArr.push(data);
		});

		if(dataArr.length==0){
			var data = {cateNo : cateNo
				, contentsLoc : contentsLoc
				, brandGroupNo : brandGroupNo
			};
			dataArr.push(data);
		}else{
			var dataArrSort = [];
			dataArr.forEach(function(item, index){
				if(dataArr[index].dispOrd>0){
					for(var i=1; i<dataArr.length; i++){
						if(i>index){
							if(dataArr[index].dispOrd==dataArr[i].dispOrd){
								dataArr[i].dispOrd = Number(dataArr[i].dispOrd) + 1;
							}
						}
					}
				}
			});
			dataArr.forEach(function(item, index){
				if(dataArr[index].dispOrd != ''){
					dataArrSort[dataArr[index].dispOrd-1] = item;
				}
			});
			dataArr.forEach(function(item, index){
				if(dataArr[index].dispOrd == ''){
					var empty = false;
					for(var i=0; i<dataArrSort.length; i++){
						if(typeof dataArrSort[i] == 'undefined'){
							dataArrSort[i] = item;
							empty = true;
							break;
						}
					};
					if(!empty){
						dataArrSort.push(item);
					}
				}
			});
			dataArr = dataArrSort;
		}

		var jsonData = JSON.stringify(dataArr);
		console.log('jsonData::'+jsonData);
		mcxDialog.confirm('컨텐츠를 저장 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				gagajf.ajaxJsonSubmit('/display/contents/preview/save', jsonData, fnGetContentsPreviewList);
			}
		});
	});

	/**
	 * 파일첨부
	 */
	var fnPopFileUpload = function (obj, ind){
		var file = obj.files[0];
		file.name = 'test';
		if (typeof(file) == 'undefined'){
			return;
		}
		// 파일 업로드
		gagajf.ajaxFileUpload('/common/file/upload?subDir=/contents'
				, file
				, function(result) {
					$(obj).closest('div').find('input:hidden[name=newImgFile]').val(result.newFileName);
					$("#bannerPreViewUrlPop_"+ind).attr('src', $("#uploadDefaultUrlPop").val()+result.newFileName);
					$("#imgViewPop_"+ind).removeClass("off").addClass("on");
				}
				, 'image'
		);
	}

	/**
	 * 링크추가
	 */
	var fnAddLinkPopRow = function (param){
		var val = typeof param=='object'?'#':param;
		var html = '<tr name="linkPopRow">';
		html += '<th>링크 (없으면 #)</th>';
		html += '<td><input name="link" type="text" maxlength="200" required="required" data-valid-name="링크" value="'+val+'"/></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnDeleteTrRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if(contentsLoc=='SMM005'){
				if($(param).closest("table").find("tbody").find("tr[name=linkPopRow]").length>1){
					mcxDialog.alert("링크는 최대 2개까지 등록 가능합니다");
					return;
				}
			}else{
				if($(param).closest("table").find("tbody").find("tr[name=linkPopRow]").length>3){
					mcxDialog.alert("링크는 4개까지 등록 가능합니다");
					return;
				}
			}

			$(param).closest("table").find("tbody").append(html);
		}else{
			return html;
		}
	}

	/**
	 * 서브텍스트추가
	 */
	var fnAddSubTextPopRow = function (param){
		var val = typeof param=='object'?'':param;
		var html = '<tr name="subTextPopRow">'
		html += '<th>서브텍스트</th>';
		html += '<td><input type="text" name="subText" maxlength="200" value="'+val+'"/></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnDeleteTrRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if($(param).closest("table").find("tbody").find("tr[name=subTextPopRow]").length>3){
				mcxDialog.alert("서브텍스트는 4개까지 등록 가능합니다");
				return;
			}
			$(param).closest("table").find("tbody").append(html);
		}else{
			return html;
		}
	}

	/**
	 * 브랜드 소개추가
	 */
	var fnAddBrandDescRow = function (param){
		var val = typeof param=='object'?'':param;
		var html = '<tr name="subTextPopRow">'
		html += '<th>브랜드소개</th>';
		html += '<td><input type="text" name="subText" maxlength="200" value="'+val+'"/></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnDeleteTrRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if($(param).closest("table").find("tbody").find("tr[name=subTextPopRow]").length>0){
				mcxDialog.alert("브랜드소개는 1개까지 등록 가능합니다");
				return;
			}
			$(param).closest("table").find("tbody").append(html);
		}else{
			return html;
		}
	}

	/**
	 * 이미지 추가
	 */
	var imgIndex = 0;
	var fnAddImgPopRow = function (param){
		var src = '';
		var imgPath = '';
		if(typeof param!='object'){
			src = $("#uploadDefaultUrlPop").val().replace('/contents/', '')+param;
			imgPath = param;
		}
		var html = '<tr name="imgPopRow">';
		html += '<th>이미지';
		html += '</th>';
		html += '<td><div class="uFile w300">';
		html += '<input id="filePop_'+imgIndex+'" name="file" type="file" class="uFileInput w300" onchange="fnPopFileUpload(this, '+imgIndex+')"/>';
		html += '<label for="filePop_'+imgIndex+'" class="uFileLabel">파일선택</label>';
		html += '<input type="hidden" name="imgPath" value="'+imgPath+'"/>';
		html += '<input type="hidden" name="newImgFile" value="" />';
		html += '</div>';
		html += '<div id="imgViewPop_'+imgIndex+'" class=';
		if(src!=''){
			html += '"on">';
		}else{
			html += '"off">';
		}
		html += '<img id="bannerPreViewUrlPop_'+imgIndex+'" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'bannerPreimgViewPop\',$(this).attr(\'src\'));"/>';
		html += '</div></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnDeleteTrRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if(contentsLoc=='SMM005'){
				if($(param).closest("table").find("tbody").find("tr[name=imgPopRow]").length>1){
					mcxDialog.alert("이미지는 최대 2개까지 등록 가능합니다");
					return;
				}
			}else{
				if($(param).closest("table").find("tbody").find("tr[name=imgPopRow]").length>3){
					mcxDialog.alert("이미지는 4개까지 등록 가능합니다");
					return;
				}
			}
			imgIndex++;
			$(param).closest("table").find("tbody").append(html);
		}else{
			imgIndex++;
			return html;
		}
	}

	/**
	 * 타이틀추가
	 */
	var fnAddTitlePopRow = function (param){
		var val = typeof param=='object'?'':param;
		var html = '<tr name="titlePopRow">';
		html += '<th>타이틀</th>';
		html += '<td><input name="title" type="text" maxlength="200" data-valid-name="타이틀" value="'+val+'"/></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnDeleteTrRow(this);"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if($(param).closest("table").find("tbody").find("tr[name=titlePopRow]").length>3){
				mcxDialog.alert("타이틀은 4개까지 등록 가능합니다");
				return;
			}
			$(param).closest("table").find("tbody").append(html);
		}else{
			return html;
		}
	}

	// 컨텐츠 행삭제
	var fnDeleteContentsRow = function (obj){
		$(obj).closest("table").remove();
	}

	// 행삭제
	var fnDeleteTrRow = function (obj){
		$(obj).closest("tr").remove();
	}

	// 컨텐츠 추가 날짜 설정
	var fnCreateTimeOption = function(val, sel) {
		var html = '';
		for(var i=0; i<val; i++){
			var time = 0;
			if(i<10){
				time = '0'+i;
			}else {
				time = i;
			}
			var select = false;
			if(sel==time){
				select = true;
			}
			if(val==24){
				time += '시';
			}else if(val==60){
				time += '분';
			}
			html += '<option value="'+time+'"';
			if(select){
				html += 'selected="selected"';
			}
			html += '>'+time+'</option>';
		}
		return html;
	}

	// 동영상파일 선택 시
	$('#popSortable input[name=file]').on('change', function() {
		var file = this.files[0];
		gagaKollus.upload('Display', file, $('input[name=kufKey]'));
	});

	// 창닫기
	var fnMainContentsPopupFormClose = function (){
		uifnPopupClose('popupMainContents');
	}

	$(document).ready(function() {
		$("#popTitle").text("["+contentsLoc+"] "+gagaAgGrid.lookupValue(contentsLocArr, contentsLoc));

		$("#popSortable").disableSelection();
		fnGetContentsPreviewList();


	});
	/*]]>*/
</script>

</html>
