<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : MainMultiContentsPopupForm.html
 * @desc    : 메인전시 컨텐츠 멀티 팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.2.24    bin2107     최초 작성
 *******************************************************************************
 -->
	<div class="modalPopup" data-width="1500" >
		<div class="panelStyle">
			<div class="panelTitle">
				<h2 id="multiPopTitle" th:text="${contentsLoc}">Multi</h2>
				<button type="button" class="close" onclick="fnMainMultiContentsPopupFormClose()"><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" th:if="${contentsLoc == 'SMM007'}" onclick="fnAddBrand(this);">브랜드 추가</button> <!--id="btnBrandAddRow"-->
						<button type="button" class="btn btn btn-base btn-sm" th:if="${contentsLoc == 'SMM009' or contentsLoc == 'SMM012'}" onclick="fnAddBrand(this);">MD 탭 추가</button>
						<button type="button" class="btn btn btn-base btn-sm"
								th:if="${contentsLoc == 'SMM003' or contentsLoc == 'SBM007' or contentsLoc == 'SBM008' or contentsLoc == 'SBM009' or contentsLoc == 'SBM017' or contentsLoc == 'SBM018' or contentsLoc == 'SBM019' or contentsLoc == 'SOM002' or contentsLoc == 'SOM003' or contentsLoc == 'SCM002' or contentsLoc == 'SCM003'}"
								onclick="fnAddBrand(this);">컨텐츠 추가</button>
						<button type="button" class="btn btn btn-dark btn-sm" id="btnMultiPopSave">임시저장</button>
						<input type="hidden" name="uploadDefaultUrlMultiPop" id="uploadDefaultUrlMultiPop" th:value="${@environment.getProperty('upload.image.view') + '/contents/'}"/>
						<input type="hidden" name="uploadDefaultBrandUrlPop" id="uploadDefaultBrandUrlPop" th:value="${@environment.getProperty('upload.image.view') + '/contents/brand/'}"/>
						<input type="hidden" name="uploadDefaultPlanUrlPop" id="uploadDefaultPlanUrlPop" th:value="${@environment.getProperty('upload.image.view') + '/contents/planning/'}"/>
					</li>
				</ul>
			</div>
			<form style="height:600px; width:1470px; overflow:auto;" id="multiPopSortable">
				<input type="hidden" name="mdTitle">
			</form>
		</div>
	</div>

<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;
	let tableLen = 0;		// 테이블 ID
console.log('brandGroupNo:'+brandGroupNo);
	/**
	 * 컨텐츠 미리보기 리스트
	 */
	var fnGetMultiContentsPreviewList = function (){
		$("#multiPopSortable").html('');
		$("#multiPopSortable").html('');
		var data = {cateNo : cateNo
			,contentsLoc : contentsLoc
			,brandGroupNo : brandGroupNo
		};
		var jsonData = JSON.stringify(data);
		gagajf.ajaxJsonSubmit('/display/contents/preview/list', jsonData, fnCreatePopLayout);
	}

	var fnCreatePopLayout = function (result){
		var html = '';
		for(var i=0; i<result.length; i++){
			var dispStdt = result[i].dispStdt.split(" ");
			var dispEddt = result[i].dispEddt.split(" ");
			var brandGroupImg = result[i].brandGroupImg;

			html += '<table class="frmStyle tableTest" style="margin-bottom:30px" id="tabTable'+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" value="'+result[i].dispOrd+'"/>';
			html += '</td>';
			html += '<td class="aL">';
			if(contentsLoc=='SMM007') {
				html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddPlanRow2(\'#\',this, '+i+');">기획전/배너추가</button>';
				// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddPlanRow(\'#\',this);">기획전/배너추가</button>';
				// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddTitlePopRow(this);">타이틀추가</button>';
				// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddSubTextPopRow(this);">서브텍스트추가</button>';
			}
			html += '<button type="button" class="btn btn-base btn-lg" id="addGoodsBtn'+i+'" onclick="fnAddGoodsRow(this, '+i+');">상품추가</button>';
			html += '<button type="button" class="btn btn-danger btn-lg" onclick="fnDeleteBrandRow(this);">삭제</button></td>';
			html += '</tr>';
			if(contentsLoc=='SMM009' || contentsLoc=='SMM012'){
				html += '<tr>';
				html += '<th>MD탭문구</th>';
				html += '<td colspan="3"><input type="text" name="mdTitle" id="mdTitle" style="width:30%;" value="' + result[i].mdTitle + '"></td>';
				html += '</tr>';
			}
			if(contentsLoc=='SMM007') {
				html += '<tr>';
				html += '<th>브랜드코드</th>';
				html += '<td colspan="3"><input type="text" name="brandGroupNo" required="required" data-valid-name="브랜드코드" style="width:30%;" value="' + result[i].brandGroupNo + '">';
				html += '<button type="button" class="btn btnRight btn-success btn-lg" onclick="fnGetBrandGroup(this);">브랜드조회</button>';
				html += '</td>';
				html += '</tr>';
				/*html += fnAddBrandImgRow(result[i].brandGroupImg);*/
			}
			if(contentsLoc=='SCM002' || contentsLoc=='SCM003' || contentsLoc=='SOM003'){
				html += '		<tr>';
				html += '			<th>전시 설정</th>';
				html += '			<td>';
				if(result[i].useYn=='Y'){
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+i+'" value="Y" checked="checked"/>노출</label>';
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+i+'" value="N"/>비노출</label>';
				}else{
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+i+'" value="Y"/>노출</label>';
					html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+i+'" value="N" checked="checked"/>비노출</label>';
				}
				html += '			</td>';
				if(result[i].contentsLoc=='SCM003' || result[i].contentsLoc=='SOM003'){
					html += '			<th>상품 노출 개수</th>';
					html += '			<td>';
					if(result[i].strVar1=='10'){
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="10" checked="checked"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="20"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="30"/>30개</label>';
					}else if(result[i].strVar1=='20'){
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="10"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="20" checked="checked"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="30"/>30개</label>';
					}else{
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="10"/>10개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="20"/>20개</label>';
						html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+i+'" value="30" checked="checked"/>30개</label>';
					}
					html += '			</td>';
				}
				html += '		</tr>';
			}
			html += '</thead><tbody>';
			if(contentsLoc=='SMM007') {
				for (var j = 1; j < 8; j++) {
					var imgPath = eval("result[" + i + "].imgPath" + j);
					var strVar = eval("result[" + i + "].strVar" + j);
					var strTitle = eval("result["+i+"].strTitle" + j);
					var subText = eval("result["+i+"].subText" + j);

					if (!gagajf.isNull(strVar) || !gagajf.isNull(imgPath)) {
						// html += fnAddPlanRow(strVar, imgPath);
					}
					if(strTitle!=null && strTitle!='null' && strTitle!='' ){
						// html += fnAddTitlePopRow(strTitle);
					}
					if(subText!=null && subText!='null' && subText!='' ){
						// html += fnAddSubTextPopRow(subText);
					}
					if(!gagajf.isNull(strVar) || !gagajf.isNull(imgPath) || (strTitle!=null && strTitle!='null' && strTitle!='') || (subText!=null && subText!='null' && subText!='')){
						var src = '';
						var img_Path = '';
						if(!gagajf.isNull(imgPath)){
							src = $("#uploadDefaultPlanUrlPop").val().replace('/contents/planning/', '')+imgPath;
							img_Path = imgPath;
						}
						html += '<tr name="planRow" class="planTr'+i+'">';

						html += '<th rowspan="3">링크/이미지 <br> 타이틀 <br> 서브텍스트</th>';
						html += '<td><input type="text" name="planLink" id="planLink'+i+'" value="'+strVar+'" placeholder="링크"></td>';
						html += '<td><div class="uFile w300">';
						html += '<input id="planFile_'+i+'" name="file" type="file" class="uFileInput w300" onchange="fnPlanFileUpload(this, '+i+')"/>';
						html += '<label for="planFile_'+i+'" class="uFileLabel">파일선택</label>';
						html += '<input type="hidden" name="planImgPath" value="'+img_Path+'"/>';
						html += '<input type="hidden" name="planNewImgFile" value="" />';
						html += '</div>';
						html += '<div id="planImgViewPop_'+i+'" class=';
						if(src!=''){
							html += '"on">';
						}else{
							html += '"off">';
						}
						html += '<img id="planPreViewUrlPop_'+i+'" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'planPreimgViewPop\',$(this).attr(\'src\'));"/>';
						html += '</div></td>';
						html += '<td class="aL"><button type="button" class="btn icn" onclick="fnBrandPickDeleteTrRow(this,'+i+', '+i+');"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
						html += '</tr>';
						html += '<tr class="planTr'+i+'">';
						html += '<td><input name="title" type="text" maxlength="200" placeholder="타이틀" value="'+strTitle+'"/></td>';
						html += '</tr>';
						html += '<tr class="planTr'+i+'">';
						html += '<td><input type="text" name="subText" maxlength="200" placeholder="서브텍스트" value="'+subText+'"/></td>';
						html += '</tr>';
					}
				}
			}
			if(!gagajf.isNull(result[i].contentsGoodsList)){
				// console.log(fnAddGoodsRow(result[i].contentsGoodsList));
				html += fnAddGoodsRow(result[i].contentsGoodsList , i);
			}

			// var src = '';
			// var imgPath = '';
			// if(!gagajf.isNull(result[i].imgPath1)){
			// 	src = $("#uploadDefaultPlanUrlPop").val().replace('/contents/planning/', '')+result[i].imgPath1;
			// 	imgPath = result[i].imgPath1;
			// }
			// html += '<tr name="planRow" class="planTr'+i+'">';
			//
			// html += '<th rowspan="3">링크/이미지 <br> 타이틀 <br> 서브텍스트</th>';
			// html += '<td><input type="text" name="planLink" id="planLink'+i+'" value="'+result[i].strVar1+'" placeholder="링크"></td>';
			// html += '<td><div class="uFile w300">';
			// html += '<input id="planFile_'+i+'" name="file" type="file" class="uFileInput w300" onchange="fnPlanFileUpload(this, '+i+')"/>';
			// html += '<label for="planFile_'+i+'" class="uFileLabel">파일선택</label>';
			// html += '<input type="hidden" name="planImgPath" value="'+imgPath+'"/>';
			// html += '<input type="hidden" name="planNewImgFile" value="" />';
			// html += '</div>';
			// html += '<div id="planImgViewPop_'+i+'" class=';
			// if(src!=''){
			// 	html += '"on">';
			// }else{
			// 	html += '"off">';
			// }
			// html += '<img id="planPreViewUrlPop_'+i+'" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'planPreimgViewPop\',$(this).attr(\'src\'));"/>';
			// html += '</div></td>';
			// html += '<td class="aL"><button type="button" class="btn icn" onclick="fnBrandPickDeleteTrRow(this,'+i+', '+i+');"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
			// html += '</tr>';
			// html += '<tr class="planTr'+i+'">';
			// html += '<td><input name="title" type="text" maxlength="200" placeholder="타이틀" value="'+result[i].strTitle1+'"/></td>';
			// html += '</tr>';
			// html += '<tr class="planTr'+i+'">';
			// html += '<td><input type="text" name="subText" maxlength="200" placeholder="서브텍스트" value="'+result[i].subText1+'"/></td>';
			// html += '</tr>';

			html += '</tbody></table>';
		}
		$("#multiPopSortable").append(html);
		$("#multiPopSortable").sortable();
		$(".itemWrap").sortable({
			stop : function (event, table){
				$('.tableTest').each(function (i){
					$('#goodsListTd'+i).find('.goodsClass').each(function (j){
						$(this).find('input[name=dispOrdEdit]').val(j+1);
					});
				});
			}
		});
		$('.schDate').datepicker("destroy");
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});
		tableLen = $(".tableTest").length;
		planImgIndex2 = $(".tableTest").length;
	}

	/**
	 * 브랜드이미지 불러오기
	 */
	var brandImgIdx = 0;
	var fnAddBrandImgRow = function (param){
		var src = '';
		var imgPath = '';
		if(typeof param!='object'){
			src = $("#uploadDefaultBrandUrlPop").val().replace('/contents/brand/', '')+param;
			imgPath = param;
		}
		var html = '<tr name="brandImgRow">';
		html += '<th>브랜드이미지</th>';
		html += '<td colspan="3">';
		html += '	<div class="uFile w300">';
		html += '		<input id="brandFile_'+brandImgIdx+'" name="file" type="file" class="uFileInput w300" onchange="fnBrandImgFileUpload(this, '+brandImgIdx+')">';
		html += '		<label for="brandFile_'+brandImgIdx+'" class="uFileLabel">파일선택</label>';
		html += '		<input type="hidden" name="brandImgPath" value="'+imgPath+'">';
		html += '		<input type="hidden" name="brandNewImgFile" value="">';
		html += '	</div>';
		html += '	<div id="brandImgViewPop_'+brandImgIdx+'" class=';
		if (src != '') {
			html += '"on">';
		} else {
			html += '"off">';
		}
		html += '	<img id="brandPreViewUrlPop_'+brandImgIdx+'" src="'+src+'" style="height:100px; max-width:500px;" onclick="cfnOpenImagePreViewPopup(\'brandPreViewUrlPop\',$(this).attr(\'src\'));"/>';
		html += '	</div>';
		html += '</td>';
		html += '</tr>';

		return html;
	}

	/**
	 * 브랜드 추가 버튼
	 */
	var brandIdx = 0;
	var fnAddBrand = function (param) {
		brandIdx = tableLen;
		var src = '';
		var imgPath = '';
		if (typeof param != 'object') {
			src = $("#uploadDefaultBrandUrlPop").val().replace('/contents/brand', '') + param;
			imgPath = param;
		}

		var html = '<table class="frmStyle tableTest" style="margin-bottom:30px" id="tabTable'+brandIdx+'" >';
		html += '<input type="hidden" name="tableIdx" value="'+brandIdx+'" data-id="'+brandIdx+'">';
		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=='SMM007') {
			html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddPlanRow2(\'#\',this, '+brandIdx+');">기획전/배너추가</button>';
			// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddPlanRow(\'#\',this);">기획전/배너추가</button>';
			// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddTitlePopRow(this);">타이틀추가</button>';
			// html += '<button type="button" class="btn btn-base btn-lg" onclick="fnAddSubTextPopRow(this);">서브텍스트추가</button>';
		}
		html += '<button type="button" class="btn btn-base btn-lg" id="addGoodsBtn'+brandIdx+'" onclick="fnAddGoodsRow(this, '+brandIdx+');">상품추가</button>';
		html += '<button type="button" class="btn btn-danger btn-lg" onclick="fnDeleteBrandRow(this);">삭제</button></td>';
		html += '</tr>';
		if(contentsLoc=='SMM009' || contentsLoc=='SMM012'){
			html += '<tr>';
			html += '<th>MD탭문구</th>';
			html += '<td colspan="3"><input type="text" name="mdTitle" id="mdTitle" style="width:30%;"></td>';
			html += '</tr>';
		}
		if(contentsLoc=='SMM007'){
			html += '<tr>';
			html += '<th>브랜드코드</th>';
			html += '<td colspan="3"><input type="text" name="brandGroupNo" style="width:30%;" required="required" data-valid-name="브랜드코드">';
			html += '<button type="button" class="btn btnRight btn-success btn-lg" onclick="fnGetBrandGroup(this);">브랜드조회</button>';
			html += '</td>';
			html += '</tr>';
/*			html += '<tr name="brandImgRow">';
			html += '<th>브랜드이미지</th>';
			html += '<td colspan="3">';
			html += '	<div class="uFile w300">';
			html += '		<input id="brandFile_' + brandIdx + '" name="file" type="file" class="uFileInput w300" onchange="fnBrandImgFileUpload(this, ' + brandIdx + ')">';
			html += '		<label for="brandFile_' + brandIdx + '" class="uFileLabel">파일선택</label>';
			html += '		<input type="hidden" name="brandImgPath" value="' + imgPath + '">';
			html += '		<input type="hidden" name="brandNewImgFile" value="">';
			html += '	</div>';
			html += '	<div id="brandImgViewPop_' + brandIdx + '" class=';
			if (src != '') {
				html += '"on">';
			} else {
				html += '"off">';
			}
			html += '	<img id="brandPreViewUrlPop_' + brandIdx + '" src="" style="height:100px; max-width:500px;" onclick="cfnOpenImagePreViewPopup(\'brandPreViewUrlPop\',$(this).attr(\'src\'));"/>';
			html += '	</div>';
			html += '</td>';
			html += '</tr>';*/
		}
		if(contentsLoc=='SCM002' || contentsLoc=='SCM003' || contentsLoc=='SOM003'){
			html += '		<tr>';
			html += '			<th>전시 설정</th>';
			html += '			<td>';
			html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+brandIdx+'" value="Y" checked="checked"/>노출</label>';
			html += '				<label class="rdoBtn"><input type="radio" name="dispYn'+brandIdx+'" value="N"/>비노출</label>';
			html += '			</td>';
			if(contentsLoc=='SCM003' || contentsLoc=='SOM003'){
				html += '			<th>상품 노출 개수</th>';
				html += '			<td>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+brandIdx+'" value="10" checked="checked"/>10개</label>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+brandIdx+'" value="20"/>20개</label>';
				html += '				<label class="rdoBtn"><input type="radio" name="dispCnt'+brandIdx+'" value="30"/>30개</label>';
				html += '			</td>';
			}
			html += '		</tr>';
		}
		html += '</thead><tbody></tbody></table>';

		// brandIdx++;

		$("#multiPopSortable").prepend(html);
		$("#multiPopSortable").sortable();
		/*$("#multiPopSortable").sortable({
			stop : function (event, table){
				$(".tableTest").each(function(i){
					$(this).attr('id','tabTable'+i);
					console.log($(this).attr('id'));
				});
			}
		});*/
		$('.schDate').datepicker("destroy");
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});
		if(contentsLoc == 'SBM007' || contentsLoc == 'SBM008' || contentsLoc == 'SBM009' || contentsLoc == 'SBM017'|| contentsLoc == 'SBM018'|| contentsLoc == 'SBM019' || contentsLoc == 'SMM003' || contentsLoc == 'SMM007' || contentsLoc == 'SMM009'
				|| contentsLoc == 'SCM002' || contentsLoc == 'SCM003' || contentsLoc == 'SOM002' || contentsLoc == 'SOM003'){
			$("#addGoodsBtn"+brandIdx).click();
		}

		fnReloadIdx();

		tableLen = tableLen+1;
	}

	var fnReloadIdx = function (){
		$(".tableTest").each(function(i){
			// $(this).attr('id','tabTable'+i);
			$(this).find("input[name=dispOrd]").val(i+1);
			//console.log($(this).attr('id'));
			// if(contentsLoc == 'SBM007' || contentsLoc == 'SBM008' || contentsLoc == 'SBM009' || contentsLoc == 'SMM003' || contentsLoc == 'SMM007' || contentsLoc == 'SMM009'
			// 		|| contentsLoc == 'SCM002' || contentsLoc == 'SCM003' || contentsLoc == 'SOM003'){
			// 	var tableIdx = $(this).find('input[name=tableIdx]').val();
			// 	if(gagajf.isNull(tableIdx)){
			// 		tableIdx = 0;
			// 	}
			// 	goodsIdx = tableIdx;
			// 	console.log('tableIdx>>>'+tableIdx);
			// }
		});
	}

	/**
	 * 브랜드 이미지 첨부
	 */
	var fnBrandImgFileUpload = function (obj, ind){
		var file = obj.files[0];

		file.name = 'test';
		if (typeof(file) == 'undefined'){
			return;
		}
		// 파일 업로드
		gagajf.ajaxFileUpload('/common/file/upload?subDir=/contents/brand/'
				, file
				, function(result) {
					$(obj).closest('div').find('input:hidden[name=brandNewImgFile]').val(result.newFileName);
					$("#brandPreViewUrlPop_"+ind).attr('src', $("#uploadDefaultBrandUrlPop").val()+result.newFileName);
					$("#brandImgViewPop_"+ind).removeClass("off").addClass("on");
				}
				, 'image'
		);
	}

	/**
	 * 브랜드그룹 조회
	 */
	var tblNm;
	var fnGetBrandGroup = function (obj){
		tblNm = $(obj).closest("table").attr('id');
		//console.log('tblNm:::::'+tblNm);
		cfnOpenBrandGroupListPopup("callBackBrandGroup", "S", "S");
	}

	var callBackBrandGroup = function (result){
		$("#"+tblNm).find("input[name=brandGroupNo]").val(result[0].brandGroupNo);
	}

	/**
	 * 기획전/배너 추가
	 */
	var planImgIndex2 = 0;
	var fnAddPlanRow2 = function (strvar, param , tableIdx){
		var src = '';
		var imgPath = '';
		if(typeof param!='object'){
			src = $("#uploadDefaultPlanUrlPop").val().replace('/contents/planning/', '')+param;
			imgPath = param;
		}
		var html = '<tr name="planRow" class="planTr'+planImgIndex2+'">';

		html += '<th rowspan="3">링크/이미지 <br> 타이틀 <br> 서브텍스트</th>';
		html += '<td><input type="text" name="planLink" id="planLink'+planImgIndex2+'" value="'+strvar+'" placeholder="링크"></td>';
		html += '<td><div class="uFile w300">';
		html += '<input id="planFile_'+planImgIndex2+'" name="file" type="file" class="uFileInput w300" onchange="fnPlanFileUpload(this, '+planImgIndex2+')"/>';
		html += '<label for="planFile_'+planImgIndex2+'" class="uFileLabel">파일선택</label>';
		html += '<input type="hidden" name="planImgPath" value="'+imgPath+'"/>';
		html += '<input type="hidden" name="planNewImgFile" value="" />';
		html += '</div>';
		html += '<div id="planImgViewPop_'+planImgIndex2+'" class=';
		if(src!=''){
			html += '"on">';
		}else{
			html += '"off">';
		}
		html += '<img id="planPreViewUrlPop_'+planImgIndex2+'" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'planPreimgViewPop\',$(this).attr(\'src\'));"/>';
		html += '</div></td>';
		html += '<td class="aL"><button type="button" class="btn icn" onclick="fnBrandPickDeleteTrRow(this,'+planImgIndex2+', '+tableIdx+');"><i class="fa fa-times" aria-hidden="true"></i></button></td>';
		html += '</tr>';

		html += '<tr class="planTr'+planImgIndex2+'">';
		html += '<td><input name="title" type="text" maxlength="200" placeholder="타이틀" value=""/></td>';
		html += '</tr>';

		html += '<tr class="planTr'+planImgIndex2+'">';
		html += '<td><input type="text" name="subText" maxlength="200" placeholder="서브텍스트" value=""/></td>';

		html += '</tr>';

		if(typeof param == 'object'){
			if($(param).closest("table").find("tbody").find("tr[name=planRow]").length>4){
				mcxDialog.alert("기획전/배너는 5개까지 등록 가능합니다");
				return;
			}
			planImgIndex2++;
			$(param).closest("table").find("tbody").append(html);
		}else{
			planImgIndex2++;
			return html;
		}
	}

	/**
	 * 기획전/배너 추가
	 */
	var planImgIndex = 0;
	var fnAddPlanRow = function (strvar, param){
		var src = '';
		var imgPath = '';
		if(typeof param!='object'){
			src = $("#uploadDefaultPlanUrlPop").val().replace('/contents/planning/', '')+param;
			imgPath = param;
		}
		var html = '<tr name="planRow">';
		html += '<th>기획전/배너<br>링크/이미지</th>';
		html += '<td><input type="text" name="planLink" id="planLink'+planImgIndex+'" value="'+strvar+'"></td>';
		html += '<td><div class="uFile w300">';
		html += '<input id="planFile_'+planImgIndex+'" name="file" type="file" class="uFileInput w300" onchange="fnPlanFileUpload(this, '+planImgIndex+')"/>';
		html += '<label for="planFile_'+planImgIndex+'" class="uFileLabel">파일선택</label>';
		html += '<input type="hidden" name="planImgPath" value="'+imgPath+'"/>';
		html += '<input type="hidden" name="planNewImgFile" value="" />';
		html += '</div>';
		html += '<div id="planImgViewPop_'+planImgIndex+'" class=';
		if(src!=''){
			html += '"on">';
		}else{
			html += '"off">';
		}
		html += '<img id="planPreViewUrlPop_'+planImgIndex+'" src="'+src+'" style="height:100px; max-width:500px;"  onclick="cfnOpenImagePreViewPopup(\'planPreimgViewPop\',$(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($(param).closest("table").find("tbody").find("tr[name=planRow]").length>4){
				mcxDialog.alert("기획전/배너는 5개까지 등록 가능합니다");
				return;
			}
			planImgIndex++;
			$(param).closest("table").find("tbody").append(html);
		}else{
			planImgIndex++;
			return html;
		}
	}

	// 기획전/배너 파일첨부
	var fnPlanFileUpload = function (obj, ind){
		var file = obj.files[0];

		file.name = 'test';
		if (typeof(file) == 'undefined'){
			return;
		}
		// 파일 업로드
		gagajf.ajaxFileUpload('/common/file/upload?subDir=/contents/planning'
				, file
				, function(result) {
					$(obj).closest('div').find('input:hidden[name=planNewImgFile]').val(result.newFileName);
					$("#planPreViewUrlPop_"+ind).attr('src', $("#uploadDefaultPlanUrlPop").val()+result.newFileName);
					$("#planImgViewPop_"+ind).removeClass("off").addClass("on");
				}
				, 'image'
		);
	}

	/**
	 * 타이틀추가
	 */
	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 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 fnDeleteBrandRow = function (obj){
		mcxDialog.confirm('삭제시 전시순서가 초기화됩니다. 삭제하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				$(obj).closest("table").remove();
				fnReloadIdx();
			}
		});
	}

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

	var fnBrandPickDeleteTrRow = function (obj, planIdx, tableIdx){
		$("#tabTable"+tableIdx).find('.planTr'+planIdx).each(function (i){
			$(this).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;
	}

	// 창닫기
	var fnMainMultiContentsPopupFormClose = function (){
		uifnPopupClose('popupMainMultiContents');
	}

	// 전시 일시 체크
	function dateValidation(){
		var dateBool = true;
		let dupCnt = 0;
		$(".tableTest").each(function(i){
			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";

			let fromDate = dispStdt.replace(/[^0-9]/g, '');
			let toDate = dispEddt.replace(/[^0-9]/g, '');
			if(fromDate > toDate){
				mcxDialog.alert("시작일자는 종료일자 보다 클 수 없습니다.");
				$(this).find('input[name=dispStdt]').focus();
				// dateBool = false;
				dupCnt++;
				return false;
			}
		});
		// if(!dateBool){
		// 	return false;
		// }else{
		// 	return true;
		// }
		if(dupCnt==0){
			return true;
		}
	}

	// 몰메인 신상품 : 상품데이터 체크
	var goodsArrValidation = function (){
		var dataBool = true;
		let dupCnt = 0;
		$("#multiPopSortable .tableTest").each(function(i){
			var thisIdx = $(this).find("input[name=tableIdx]").val();

			if($("#tabTable"+thisIdx+" #goodsListTd"+thisIdx).find('ul').find('input[name=goodsCd]').length < 1){
				mcxDialog.alert((i+1)+"번째 컨텐츠영역의 상품 정보가 없습니다.");
				$(this).focus();
				// dataBool = false;
				dupCnt++;
				return false;
			}
		});

		// if(!dataBool){
		// 	return false;
		// }else{
		// 	return true;
		// }
		if(dupCnt==0){
			return true;
		}
	}

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

		// 전시일시 체크
		if(!dateValidation()){
			return false;
		}

		if(contentsLoc == 'SBM007' || contentsLoc == 'SBM008' || contentsLoc == 'SBM009'|| contentsLoc == 'SBM017'|| contentsLoc == 'SBM018'|| contentsLoc == 'SBM019' || contentsLoc == 'SMM003' || contentsLoc == 'SMM007' || contentsLoc == 'SMM009'
				|| contentsLoc == 'SCM002' || contentsLoc == 'SCM003' || contentsLoc == 'SOM002' || contentsLoc == 'SOM003'){
			if(!goodsArrValidation()){
				return false;
			}
		}

		dataArr = [];
		$("#multiPopSortable .tableTest").each(function(){	//$("#multiPopSortable table").each(function(){
			var newImgFileArr = [];
			var imgPath1 = '';
			var imgPath2 = '';
			var imgPath3 = '';
			var imgPath4 = '';
			var imgPath5 = '';
			var imgPath6 = '';
			var imgPath7 = '';
			var imgPath8 = '';
			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 goodsImgArr = [];
			var goodsCdArr = [];
			// var goodsNmArr = [];
			var goodsDispOrdArr = [];
			var i = 1;
			$(this).find('input[name=planImgPath]').each(function(){
				eval("imgPath" + i + "='"+$(this).val()+"'");
				i++;
			});

			$(this).find('input[name=planNewImgFile]').each(function(){
				newImgFileArr.push($(this).val());
			});
			i = 1;
			$(this).find('input[name=planLink]').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=title]').each(function(){
				var title = $(this).val().replace(/[\']/gi, "\\'");
				eval("strTitle" + i + "='"+title+"'");
				i++;
			});
			i = 1;
			$(this).find('input[name=subText]').each(function(){
				var subText = $(this).val().replace(/[\']/gi, "\\'");
				eval("subText" + i + "='"+subText+"'");
				i++;
			});

			// $(this).find('input[name=goodsImgPath]').each(function(){
			// 	goodsImgArr.push($(this).val());
			// });

			$(this).find('input[name=goodsCd]').each(function(){
				goodsCdArr.push($(this).val());
			});

			// $(this).find('input[name=goodsNm]').each(function(){
			// 	goodsNmArr.push($(this).val());
			// });

			$(this).find('input[name=dispOrdEdit]').each(function(){
				goodsDispOrdArr.push($(this).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();

			var brandGroupNo;
			if(contentsLoc=='SBM007'||contentsLoc=='SBM008'||contentsLoc=='SBM009'||contentsLoc=='SBM017'||contentsLoc=='SBM018'||contentsLoc=='SBM019'||contentsLoc=='SOM003'||contentsLoc=='SCM002'||contentsLoc=='SCM003'){
				brandGroupNo = [[${brandGroupNo}]];
			}else{
				brandGroupNo = $(this).find("[name=brandGroupNo]").val();
			}
			var brandGroupImg = $(this).find("[name=brandNewImgFile]").val();
			var mdTitle = $(this).find("[name=mdTitle]").val();

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

			var data = {cateNo : cateNo
				, contentsLoc : contentsLoc
				, dispStdt : dispStdt
				, dispEddt : dispEddt
				, newImgFileArr : newImgFileArr
				, imgPath1 : imgPath1
				, imgPath2 : imgPath2
				, imgPath3 : imgPath3
				, imgPath4 : imgPath4
				, imgPath5 : imgPath5
				, imgPath6 : imgPath6
				, imgPath7 : imgPath7
				, imgPath8 : imgPath8
				, 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
				, brandGroupNo : brandGroupNo
				, brandGroupImg : brandGroupImg
				, mdTitle : mdTitle
				, useYn : useYn
				, dispOrd : dispOrd
				, multiContentsYn : 'Y'
				, goodsCdArr : goodsCdArr
				// , goodsNmArr : goodsNmArr
				// , goodsImgArr : goodsImgArr
				, goodsDispOrdArr : goodsDispOrdArr
			};

			dataArr.push(data);
		});

		if(dataArr.length==0){
			var data = {cateNo : cateNo
				, contentsLoc : contentsLoc
			};
			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);
		mcxDialog.confirm('컨텐츠를 저장 하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
			gagajf.ajaxJsonSubmit('/display/contents/preview/save', jsonData, fnGetMultiContentsPreviewList);
			}
		});
	});

	var fnUpBtn = function (obj, idx){
		var ind = $(obj).closest('.item').index();
		if(ind>0){
			$('#goodsListTd'+idx).find(".item").eq(ind-1).before($('#goodsListTd'+idx).find(".item").eq(ind));
			$('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=setDispOrd]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=setDispOrd]").val())+1);
			$('#goodsListTd'+idx).find(".item").eq(ind-1).find("input[name=setDispOrd]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind-1).find("input[name=setDispOrd]").val())-1);
			$('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=dispOrdEdit]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=dispOrdEdit]").val())+1);
			$('#goodsListTd'+idx).find(".item").eq(ind-1).find("input[name=dispOrdEdit]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind-1).find("input[name=dispOrdEdit]").val())-1);
		}
	}

	var fnDownBtn = function (obj, idx){
		var ind = $(obj).closest('.item').index();
		if(ind<$("#goodsListTd"+idx).find('.goodsClass').length){
			$('#goodsListTd'+idx).find(".item").eq(ind+1).after($('#goodsListTd'+idx).find(".item").eq(ind));
			$('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=setDispOrd]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=setDispOrd]").val())-1);
			$('#goodsListTd'+idx).find(".item").eq(ind+1).find("input[name=setDispOrd]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind+1).find("input[name=setDispOrd]").val())+1);
			$('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=dispOrdEdit]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind).find("input[name=dispOrdEdit]").val())-1);
			$('#goodsListTd'+idx).find(".item").eq(ind+1).find("input[name=dispOrdEdit]").val(Number($('#goodsListTd'+idx).find(".item").eq(ind+1).find("input[name=dispOrdEdit]").val())+1);
		}
	}

	var fnUpdownBtn = function (obj, gubun, idx){
		if(gubun=='up'){
			var ind = $(obj).closest('.item').index();
			$('#goodsListTd'+idx).find(".item").eq(0).before($('#goodsListTd'+idx).find(".item").eq(ind));
			$('#goodsListTd'+idx).find('.goodsClass').each(function (j){
				$(this).find('input[name=dispOrdEdit]').val(j+1);
			});
		}else{
			var ind = $(obj).closest('.item').index();
			let lastNum = $("#goodsListTd"+idx).find('.goodsClass').length;
			$('#goodsListTd'+idx).find(".item").eq(lastNum-1).after($('#goodsListTd'+idx).find(".item").eq(ind));
			$('#goodsListTd'+idx).find('.goodsClass').each(function (j){
				$(this).find('input[name=dispOrdEdit]').val(j+1);
			});
		}

	}

	/**
	 * 상품추가
	 */
	var goodsIdx = 0;
	var fnAddGoodsRow = function (param , tableIndex){
		if(!gagajf.isNull(tableIndex)){
			goodsIdx = tableIndex;
		}
		var addRow = "goodsListTd"+goodsIdx;

		var html = '<tr name="goodsRow">';
		html += '<th>상품추가<br><button type="button" class="btn btn-base btn-lg" onclick="fnSearchGoods(\''+addRow+'\');">상품조회</button>';
		html += '<br></br><button type="button" class="btn btn-danger btn-lg" onclick="fnDeleteTrRow(this);">삭제</button>';
		html += '</th>';
		html += '<td colspan="3">';
		html += '<div class="sortableWrap" data-unit="7" style="overflow-y:scroll;">';
		html += '<div class="itemWrap" id="goodsListTd'+goodsIdx+'">';
		// if(typeof param!='object'){
			var imgPath = _goodsUrl;
			for(let i=0; i<param.length; i++){
				html += '<ul id="goodsUl'+i+'" class="item ui-state-default goodsClass" style="min-height:200px;"> ';
				html += '<li class="img">';
				html += '<img src="'+imgPath+ "/" +param[i].sysImgNm+'" onerror="this.src=\'/image/no.png\';"/>';
				html += '<div class="btnArea">';
				html += '<button type="button" class="icnSm" title="맨위로" onclick="fnUpdownBtn(this, \'up\', \''+goodsIdx+'\');"><i class="fa fa-play-circle fa-rotate-270" aria-hidden="true"></i></button>';
				html += '<button type="button" class="icnSm" title="위로" onclick="fnUpBtn(this, \''+goodsIdx+'\');"><i class="fa fa-arrow-up" aria-hidden="true"></i></button>';
				html += '<button type="button" class="icnSm" title="맨아래로" onclick="fnUpdownBtn(this, \'down\', \''+goodsIdx+'\');"><i class="fa fa-play-circle fa-rotate-90" aria-hidden="true"></i></button>';
				html += '<button type="button" class="icnSm" title="아래로" onclick="fnDownBtn(this, \''+goodsIdx+'\');"><i class="fa fa-arrow-down" aria-hidden="true"></i></button>';
				html += '</div>';
				html += '</li>';
				html += '<li class="cont">';
				html += '<ul>';
				html += '<li class="no" name="goodsCdLi"><span>'+param[i].goodsCd+'</span>';
				// html += '<input type="hidden" name="goodsImgPath" value="'+param[i].sysImgNm+'">';
				html += '<input type="hidden" name="goodsCd" value="'+param[i].goodsCd+'">';
				// html += '<input type="hidden" name="goodsNm" value="'+param[i].goodsNm+'">';
				html += '<span style="margin-left:5px;"><a href="javascript:void(0);" id="delId" onclick="fnRemoveGoods(this,'+i+');">X</a></span>';
				html += '</li>';
				html += '</li>';
				html += '<li class="title">'+param[i].goodsNm+'</li>';
				html += '<li>';
				html += '<span>전시순서 :</span>';
				html += '<input type="text" name="dispOrdEdit" value="'+param[i].contentsDispOrd+'" />';
				html += '<input type="hidden" name="setDispOrd" value="'+param[i].contentsDispOrd+'"/>';
				html += '</li>';
				html += '</ul>';
				html += '</ul>';
			}
		// }
		html += '</div>';
		html += '</div>';
		html += '</td>';
		html += '</tr>';
		if(typeof param == 'object'){
			if($(param).closest("table").find("tbody").find("tr[name=goodsRow]").length>0){
				mcxDialog.alert("상품추가 ROW는 1개 등록 가능합니다");
				return;
			}
			goodsIdx++;
			$(param).closest("table").find("tbody").append(html);
			return html;
		}else{
			goodsIdx++;
			return html;
		}

		fnReloadIdx();
	}

	/**
	 * 상품조회
	 */
	var addRowTd;
	var fnSearchGoods = function (obj){
		addRowTd = obj;
		cfnOpenGoodsPopup('fnAddMultiContentsGoods');
	}

	var firstOrd = '';
	//var uploadGoodsUrl = _goodsUrl [[${@environment.getProperty('upload.goods.view')}]];
	var fnAddMultiContentsGoods = function(result){
		let thisIdx = $("#"+addRowTd).parent().parent().parent().parent().parent().find('input[name=tableIdx]').val();
		// console.log('goodsRowIdx>>>>'+addRowTd);
		let goodsCnt = 0;
		if($("#"+addRowTd).find('.item').length > 0){
			goodsCnt = $("#"+addRowTd).find('.item').length;
		}

		var html='';
		for(let i = 0 ; i < result.length ; i++) {
			let dispOrdVal = 0;
			dispOrdVal = goodsCnt +(i+1);

			if(i==0){
				firstOrd = result[i].dispOrd;
			}
			html+='<ul id="goodsUl'+i+'" class="item ui-state-default goodsClass" style="min-height:200px;" ';
			if(result[i].goodsStat!="G008_90" || result[i].currStockQty<1){
				html += 'background:#f5f5f5;';
			}
			html += '">';
			html += '<li class="img">';
			var imgPath = '';
			//if(result[i].imgType=='A'){
				imgPath = _goodsUrl;
			//}
			html += '<img src="'+imgPath+ "/" +result[i].sysImgNm+'" onerror="this.src=\'/image/no.png\';"/>';
			html += '<div class="btnArea">';
			html += '<button type="button" class="icnSm" title="맨위로" onclick="fnUpdownBtn(this, \'up\', \''+thisIdx+'\');"><i class="fa fa-play-circle fa-rotate-270" aria-hidden="true"></i></button>';
			html += '<button type="button" class="icnSm" title="위로" onclick="fnUpBtn(this, \''+thisIdx+'\');"><i class="fa fa-arrow-up" aria-hidden="true"></i></button>';
			html += '<button type="button" class="icnSm" title="맨아래로" onclick="fnUpdownBtn(this, \'down\', \''+thisIdx+'\');"><i class="fa fa-play-circle fa-rotate-90" aria-hidden="true"></i></button>';
			html += '<button type="button" class="icnSm" title="아래로" onclick="fnDownBtn(this, \''+thisIdx+'\');"><i class="fa fa-arrow-down" aria-hidden="true"></i></button>';
			html += '</div>';
			html += '</li>';
			html += '<li class="cont">';
			html += '<ul>';
			html += '<li class="no" name="goodsCdLi"><span>'+result[i].goodsCd+'</span>';
			// html += '<input type="hidden" name="goodsImgPath" value="'+result[i].sysImgNm+'">';
			html += '<input type="hidden" name="goodsCd" value="'+result[i].goodsCd+'">';
			// html += '<input type="hidden" name="goodsNm" value="'+result[i].goodsNm+'">';
			html += '<span style="margin-left:5px;"><a href="javascript:void(0);" id="delId" onclick="fnRemoveGoods(this,'+i+');">X</a></span>';
			html += '</li>';
			html += '<li class="title">'+result[i].goodsNm+'</li>';
			html += '<li>';
			html += '<span>전시순서 :</span>';
			html += '<input type="text" name="dispOrdEdit" value="'+dispOrdVal+'" />';
			html += '<input type="hidden" name="setDispOrd" value="'+dispOrdVal+'"/>';
			html += '</li>';
			html += '</ul>';
			html += '</li>';
			html += '</ul>';
		}
		
		$("#"+addRowTd).append(html);
		// $("#"+addRowTd).sortable();
		$("#"+addRowTd).sortable({
			stop: function(event, ui) {
				if(gagajf.isNull(firstOrd)){
					firstOrd = 1;
				}else{
					firstOrd = Number(firstOrd);
				}
				$("#"+addRowTd+" .item").each(function(i){
					$(this).find("input[name=dispOrdEdit]").val(i+firstOrd);
				});
			}
		});
		$("#"+addRowTd).disableSelection();
		uifnPopupClose('popupGoods');
		fnReloadGoodsListIdx(addRowTd);
	}

	var fnReloadGoodsListIdx = function (obj){
		var tableId = obj
		$("#"+tableId +" .goodsClass").each(function (i){
			$(this).attr('id','goodsUl'+i);
			$(this).find("#delId").attr('onclick','fnRemoveGoods(this,'+i+');');
			$(this).find("input[name=dispOrdEdit]").val(i+1);
			$(this).find("input[name=setDispOrd]").val(i+1);
		});
	}

	var fnRemoveGoods = function (obj , idx){
		var divId = $(obj).closest('div').attr('id');
		$("#"+divId+" #goodsUl"+idx).remove();
		fnReloadGoodsListIdx(divId);
	}

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

		$("#multiPopSortable").sortable({
			stop: function(event, ui) {
				fnReloadIdx();
			}
		});
		$("#multiPopSortable").disableSelection();
		fnGetMultiContentsPreviewList();
		fnReloadIdx();
	});
/*]]>*/
</script>

</html>
