/*

 * Popup Java Script by gagamel
 *
 * Copyright (c) 2010 gagamel
 *
 * $Date: 2019-08-06 $
 */

//체크박스 전체선택
function uifnAllCheck(id) {
	var $thisId = $("#" + id);
	if ($thisId.hasClass("checked")) {
		$thisId.removeClass("checked");
		$("input[name=" + id + "]").parent("label").removeClass("checked");
		$("input[name=" + id + "]").prop("checked", false);
	} else {
		$thisId.addClass("checked");
		$("input[name=" + id + "]").parent("label").addClass("checked");
		$("input[name=" + id + "]").prop("checked", true);
	};
	return false;
};

/**
 * @type   : function
 * @access : public
 * @desc   : 모달팝업 오픈
 * <pre>
 *     cfnOpenModalPopup('/goods/detail?goodsCd=G2019060500022', '');
 * </pre>
 * @param  : actionUrl - 로딩 URL
 * @param  : oTarget - 로딩 URL을 표시할 target ID
 * @since  : 2019/06/05
 * @author : gagamel
 */
var cfnOpenModalPopup = function(actionUrl, oTarget) {
	var str = '<div class="popupWrap" id="' + oTarget + '"></div>';

	if ($('#'+ oTarget).length == 0) {
		$('body').append(str);
	}

	$("#" + oTarget).load(actionUrl, function() {
		uifnPopupOpen(oTarget);
		
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});
	});
}

/**
 * @type   : function
 * @access : public
 * @desc   : MD 목록 팝업
 * <pre>
 *     cfnOpenMdListPopup();
 *     or
 *     cfnOpenMdListPopup('fnResult');
 *     or
 *     cfnOpenMdListPopup('fnResult', '홍길동');
 * </pre>
 * @since  : 2020/11/04
 * @author : gagamel
 */
var cfnOpenMdListPopup = function(callbackfn, userNm) {
	var actionUrl = '/business/md/list/form';
	if (typeof(callbackfn) != 'undefined') actionUrl += "?callbackFn=" + callbackfn;
	if (typeof(userNm) != 'undefined') actionUrl += "&mdNm=" + encodeURIComponent(userNm) + '&searchGb=userNm';
	cfnOpenModalPopup(actionUrl, "popupMdList");
}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품등록/복사 팝업 오픈
 * <pre>
 *     cfnOpenGoodsRegisterPopup('N', 'G2014120100098');
 * </pre>
 * @param  : mode - 모드(상세:U, 복사:C). 필수
 * @param  : goodsCd - 상품코드. 옵션
 * @since  : 2019/06/12
 * @author : eskim
 */
var cfnOpenGoodsDetailPopup = function(mode, goodsCd) {
	var actionUrl = "/goods/detail/form?mode=" + mode;

	if (typeof(goodsCd) != "undefined") {
		actionUrl += "&goodsCd=" + goodsCd;
	}
	uifnPopupClose('popupGoodsDetail');
	cfnOpenModalPopup(actionUrl, 'popupGoodsDetail');
}

//
/**
 * @type   : function
 * @access : public
 * @desc   : 엑셀업로드 팝업 호출
 * <pre>
 *     cfnExcelUploadPopup('infoRsvtGoodsSave', 'infoRsvtGoodsExcelSave');
 * </pre>
 * @param  : procJob - 업무명
 * @param  : callBackFun - CallBack 함수
 * @since  : 2019/07/29
 * @author : ESKIM
 */
var cfnExcelUploadPopup = function(procJob, callBackFun) {
	var params = "?procJob=" + procJob;
	if (typeof(callBackFun) != 'undefined' & callBackFun != ""){
		params += "&callBackFun=" + callBackFun;
	};
	var actionUrl = "/common/excel/upload/popup/form" ;
	cfnOpenModalPopup(actionUrl+ params,'popupExcelUpload');
};

/**
 * @type   : function
 * @access : public
 * @desc   : 주문 상세 팝업
 * <pre>
 *     cfnOpenOrderDetailPopup('주문번호');
 * </pre>
 * @param  : orderNo - 주문번호:필수
 * @since  : 2019/12/10
 * @author : yhkim
 */
var cfnOpenOrderDetailPopup = function(ordNo) {
	var actionUrl = "/order/detail/info";
	if (typeof(ordNo) != 'undefined') actionUrl += "?ordNo=" + ordNo;
	cfnOpenModalPopup(actionUrl, "popupOrderDetail");
}

/**
 * @type   : function
 * @access : public
 * @desc   : 이미지 미리보기  팝업 열기
 * <pre>
 *     cfnOpenImagePreViewPopup('custNo');
 * </pre>
 * @param  : Id - object id
 * @since  : 2019/12/12
 * @author : eskim
 */
//이미지 미리보기  팝업 열기
var cfnOpenImagePreViewPopup = function(id,imgUrl) {

	var str = '<div class="videoPopup" data-width="700" data-height="350" id="'+id+'" style="z-index:30">';
	str = str + '<button type="button" class="close" onclick="uifnPopupClose(\''+id+'\')"><i class="fa fa-times"></i></button>';
	str = str + '<img id="imagePreView" src="/image/no.gif"/>';
	str = str + '</div>';

	if ($('#'+ id).length == 0) {
		$('body').append(str);
	}

	var $thisId = $("#"+id + ">.videoPopup");
	var popW = parseInt( $thisId.attr("data-width") );
	var popH = parseInt( $thisId.attr("data-height") );
	$("#imagePreView").attr("src", imgUrl);
	//$($thisId).css({display:"block"});
	$("#"+id).css({display:"block"});
}

/**
 * @type   : function
 * @access : public
 * @desc   : 비디오 팝업
 * <pre>
 *     cfnOpenGoodsVideoPopup('goodsVideoView', 'videoUrl','#goodsDetailVideoForm', 'Y' );
 * </pre>
 * @param  : Id - object id
 * @since  : 2019/12/16
 * @author : eskim
 */
//비디오 팝업 열기
var cfnOpenGoodsVideoPopup = function(id, objId, formid, type, fullUrl) {
	
	var src = $(formid).find("#"+objId).val();
	var str = '';
	str += '<div class="videoPopup"  style="width:700px; height:350px"  id="'+id+'">';
	str += '<button type="button" class="close" onclick="uifnPopupClose(\''+id+'\')"><i class="fa fa-times"></i></button>';
	if(src.indexOf('http://')!=-1 || src.indexOf('https://')!=-1 && src.indexOf('youtube')==-1){
		str += '<video id="video" autoplay></video>';
	}else{
		str +='<iframe id="video" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
	}
	str += '</div>';

	if ($('#'+ id).length == 0) {
		$('body').append(str);
	}

	var $thisId = $("#"+id + ">.videoPopup");
	var popW = parseInt( $thisId.attr("data-width") );
	var popH = parseInt( $thisId.attr("data-height") );
	if(src.indexOf('//')!=-1 || src.indexOf('//')!=-1 && src.indexOf('youtube')==-1){
		$("#video").css({height:500, width:500});
		$("#video").attr("src", src);
	}else{
		$("#video").css({width:popW, height:popH});
		if (typeof(fullUrl) != 'undefined' && fullUrl != ""){
			$("#video").attr("src", src+"?enablejsapi=1&version=3&playerapiid=ytplayer");
		}else{
			src = 'https://www.youtube.com/embed/' + src + '?showinfo=0&rel=0&vp=hd1080&fs=0&wmode=opaque&enablejsapi=1';
			$("#video").attr("src", src+"&version=3&playerapiid=ytplayer");
		}
	}
	$("#"+id).css({display:"block"});
}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품 이미지 보기
 * <pre>
 *     cfnOpenGoodsImagePopup('G2014120100098','BK','BLACK','U');
 * </pre>
 * @param  : goodsCd - 상품코드. 옵션
 * @since  : 2020/12/22
 * @author : eskim
 */
var cfnOpenGoodsImagePopup = function(goodsCd, colorCd, colorNm, mode) {
	var actionUrl = "/goods/image/form?goodsCd=" + goodsCd +"&colorCd=" + colorCd +"&colorNm=" + encodeURIComponent(colorNm)  +"&mode=" + mode;

	uifnPopupClose('popupGoodsImage');
	cfnOpenModalPopup(actionUrl, 'popupGoodsImage');
}


/**
 * @type   : function
 * @access : public
 * @desc   : 상품 이미지 보기
 * <pre>
 *     cfnOpenGoodsImageMassPopup('G2014120100098');
 * </pre>
 * @param  : goodsCd - 상품코드. 옵션
 * @since  : 2020/11/27
 * @author : eskim
 */
//var cfnOpenGoodsImageMassPopup = function(goodsCd, colorCd, colorNm, mode) {
//	var actionUrl = "/goods/image/mass/form?goodsCd=" + goodsCd +"&colorCd=" + colorCd +"&colorNm=" + encodeURIComponent(colorNm)  +"&mode=" + mode;

//	uifnPopupClose('popupGoodsImageMass');
//	cfnOpenModalPopup(actionUrl, 'popupGoodsImageMass');
//}

/**
 * @type   : function
 * @access : public
 * @desc   : 카테고리 조회 팝업
 * <pre>
 *     cfnOpenCategoryPopup('callbackfunction');
 * </pre>
 * @param  : callbackfunction -콜백함수
 * @since  : 2019/12/20
 * @author : sasa004
 */
var cfnOpenCategoryPopup = function(callbackfun, siteCd) {
	var actionUrl = "/display/category/popup/form";
	if (typeof(callbackfun) == 'undefined'){
		return;
	}
	actionUrl += "?callBackFun=" + callbackfun;
	if (typeof(siteCd) != 'undefined') actionUrl += "&siteCd=" + siteCd;
	cfnOpenModalPopup(actionUrl, "popupCategory");
}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품평 상세팝업
 * <pre>
 *     cfnOpenReviewDetailPopup('reviewSq');
 * </pre>
 * @param  : callbackfunction -콜백함수
 * @since  : 2020/01/03
 * @author : jaewonHo
 */
var cfnOpenReviewDetailPopup = function(reviewSq) {
	var actionUrl = "/marketing/review/detail/form";

	if (typeof(reviewSq) != 'undefined') actionUrl += "?reviewSq=" + reviewSq;
	cfnOpenModalPopup(actionUrl, "popupReviewDetail");

}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품조회 팝업
 * <pre>
 *     cfnOpenGoodsPopup('goosCallbackFun');
 * </pre>
 * @param  : callbackfun - 콜백함수
 * @since  : 2020/01/17
 * @author : eskim
 */
var cfnOpenGoodsPopup = function(callbackfun) {
	var actionUrl = "/goods/popup/list/form";
	if (typeof(callbackfun) != 'undefined') actionUrl += "?callBackFun=" + callbackfun;

	cfnOpenModalPopup(actionUrl,'popupGoods');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 전시/기획전 상품 순서변경 팝업
 * <pre>
 *     cfnOpenGoodsDispOrdChangePopup('goosCallbackFun');
 * </pre>
 * @param  : callbackfun - 콜백함수
 * @since  : 2020/01/30
 * @author : sasa004
 */
var cfnOpenGoodsDispOrdChangePopup = function(callbackfun, params) {
	var actionUrl = "/display/goods/dispord/change/popup/form";
	if (typeof(callbackfun) != 'undefined') actionUrl += "?callBackFun=" + callbackfun;
	if (typeof(params) != 'undefined') actionUrl += "&" + params;
	cfnOpenModalPopup(actionUrl,'popupGoodsDispOrdChange');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 포인트 조회 상세 팝업
 * <pre>
 *     cfnOpenPointDetailPopup('callbackfunction');
 * </pre>
 * @param  : callbackfunction -콜백함수
 * @since  : 2020/02/07
 * @author : jaewonHo
 */
var cfnOpenPointDetailPopup = function(callbackfun, siteCd, custNo) {
	var actionUrl = "/marketing/point/detail/popup/form";
	if (typeof(callbackfun) == 'undefined'){
		return;
	}
	actionUrl += "?callBackFun=" + callbackfun;
	if (typeof(siteCd) != 'siteCd') actionUrl += "&siteCd=" + siteCd;
	if (typeof(siteCd) != 'custNo') actionUrl += "&custNo=" + custNo;
	cfnOpenModalPopup(actionUrl, "popupPointDetail");
}

/**
 * @type   : function
 * @access : public
 * @desc   : 쿠폰등록(수정) 팝업 cpnId존재시 수정모드
 * <pre>
 *     cfnCouponCreate(cpnId, 'couponCreateCallbackFun');
 * </pre>
 * @param  : callbackfun - 콜백함수
 * @since  : 2020/02/10
 * @author : LMC
 */
function cfnCouponCreatePopup(cpnId, callbackfun){
	var actionUrl = "/marketing/coupon/popup/form";
	if (typeof(callbackfun) != 'undefined') actionUrl += "?callBackFun=" + callbackfun;
	cfnOpenModalPopup(actionUrl,'CouponCreatePopup');
}


/**
 * @type   : function
 * @access : public
 * @desc   : LMS 팝업
 * <pre>
 *     var param = new Object();
 *     param.elementContent = 'textarea[name=content]';
 *     param.elementCellPhnno = 'input[name=cellPhnno]';
 *     param.elementCustNo = 'input[name=custNo]';
 *     cfnOpenLmsPopup(param);
 * </pre>
 * @since  : 2020/02/13
 * @author : jsshin
 */
var cfnOpenLmsPopup = function(param, division) {
	var actionUrl = '/customer/lms/popup/form?elementContent=' + encodeURIComponent(param.elementContent)
			+ '&elementCellPhnno=' + encodeURIComponent(param.elementCellPhnno)
			+ '&elementCustNo=' + encodeURIComponent(param.elementCustNo)
			+ '&division=' + division;
	cfnOpenModalPopup(actionUrl, 'popupLmsForm');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 메일 팝업
 * <pre>
 *     var param = new Object();
 *     param.elementRecipEmail = 'input[name=email]';
 *     param.elementCustNm = 'input[name=cellPhnno]';
 *     param.elementCustNo = 'input[name=custNo]';
 *     cfnOpenEmailPopup(param);
 * </pre>
 * @since  : 2020/02/13
 * @author : jsshin
 */
var cfnOpenEmailPopup = function(param, division) {
	var actionUrl = '/customer/email/popup/form?elementRecipEmail=' + encodeURIComponent(param.elementRecipEmail)
	+ '&elementCustNm=' + encodeURIComponent(param.elementCustNm)
	+ '&elementCustNo=' + encodeURIComponent(param.elementCustNo);
	+ '&division=' + division;
	cfnOpenModalPopup(actionUrl, 'popupEmailForm');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 쿠폰발급팝업
 * @since  : 2020/02/18
 * @author : 이명철
 */
var cfnCpnPubForCustPopup = function(){
	var actionUrl = '/marketing/coupon/cpnPubForCust/popup/form';
	cfnOpenModalPopup(actionUrl, 'CpnPubForCustPopup');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 포인트부여팝업
 * @since  : 2020/02/18
 * @author : 이명철
 */
var cfnGrantPointPopup = function(){
	var actionUrl = '/customer/point/grantPoint/popup/form';
	cfnOpenModalPopup(actionUrl, 'GrantPointPopup');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 일대일문의상세팝업
 * @since  : 2020/02/21
 * @author : 이대형
 */
var cfnOpenOneToOneAskDetailPopup = function(counselSq) {
	var actionUrl = '/customer/onetoone/ask/detail/form/' + counselSq;
	cfnOpenModalPopup(actionUrl, 'popupOneToOneAskDetail');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품문의상세팝업
 * @since  : 2020/08/14
 * @author : 이대형
 */
var cfnOpenGoodsQnaDetailPopup = function(counselSq) {
	var actionUrl = '/customer/goodsQna/detail/form/' + counselSq;
	cfnOpenModalPopup(actionUrl, 'popupGoodsQnaPopup');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 메인전시 컨텐츠 수정 팝업 오픈
 * <pre>
 *     cfnOpenMainContentsPopup(cateCd, contentsLoc);
 * </pre>
 * @param  : contentsLoc - 컨텐츠 위치
 * @since  : 2020/02/25
 * @author : sasa004
 */
var cfnOpenMainContentsPopup = function(cateCd, contentsLoc) {
	var actionUrl = "/display/main/contents/popup/form?cateCd="+cateCd+"&contentsLoc=" + contentsLoc;
	uifnPopupClose('popupMainContents');
	cfnOpenModalPopup(actionUrl, 'popupMainContents');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 룩북 배너 팝업 오픈
 * <pre>
 *     cfnOpenLookbookBannerPopup(lookbookSq,lookbookTitle);
 * </pre>
 * @param  : lookbookSq - 룩북 일련번호
 * @since  : 2020/02/25
 * @author : sasa004
 */
var cfnOpenLookbookBannerPopup = function(lookbookSq, lookbookTitle) {
	var actionUrl = "/display/lookbook/banner/popup/form?lookbookSq=" + lookbookSq;
	if (typeof(lookbookTitle) != 'undefined') actionUrl += "&lookbookTitle=" + encodeURIComponent(lookbookTitle);
	uifnPopupClose('popupLookbookBanner');
	cfnOpenModalPopup(actionUrl, 'popupLookbookBanner');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 회원상세 팝업
 * <pre>
 *     cfnOpenCustDetailPopup(custNo);
 * </pre>
 * @since  : 2020/03/02
 * @author : jsshin
 */
var cfnOpenCustDetailPopup = function(custNo) {
	var actionUrl = "/customer/detail/form?custNo=" + custNo;
	cfnOpenModalPopup(actionUrl,'popupCustDetail');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 매장POS 팝업
 * <pre>
 *     cfnOpenCustDetailPopup(delvLocCd);
 * </pre>
 * @since  : 2020/04/02
 * @author : jsshin
 */
var cfnPopPos =function(delvLocCd){
	var actionUrl = "/pos/login?delvLocCd="+delvLocCd;
	var popupWidth = 1830;
	var popupHeight = 850;

	var popupX = (window.screen.width / 2) - (popupWidth / 2);

	var popupY= (window.screen.height / 3) - (popupHeight / 3);

	if (typeof(delvLocCd) != 'undefined'){
		window.open(actionUrl, "_blank", "top="+popupY+", left="+popupX+", width="+popupWidth+", height="+popupHeight+", scrollbars=yes");
	}
}

/**
 * @type   : function
 * @access : public
 * @desc   : 쿠폰조회 팝업
 * <pre>
 *     var oParam = new Object();
 *     oParam.returnCode = 'input[name=sellStoreCd]'; // 반환할코드
 *     oParam.returnName = 'input[name=sellStoreNm]'; // 반환할코드명칭
 *     oParam.processType = 'DELV'; // 콜백함수처리유형
 *     cfnOpenCouponRetrievePopup($('input[name=sellStoreNm]').val(), oParam);
 * </pre>
 * @param sName - 명칭. 필수
 * @param oParam - 파라미터 오브젝트. 필수
 * @since  : 2020/04/14
 * @author : gagamel
 */
var cfnOpenCouponRetrievePopup = function(sName, oParam) {
	var oEvt = window.event;
	if (oEvt.type == 'click') sName = '';
	var returnCode = oParam.returnCode;
	var returnName = oParam.returnName;

	var actionUrl = '/marketing/coupon/retrieve/form?cpnNm=' + encodeURIComponent(sName)
			+ '&returnCode=' + encodeURIComponent(returnCode)
			+ '&returnName=' + encodeURIComponent(returnName);

	if (typeof(oParam.processType) != 'undefined')
		actionUrl += '&processType=' + oParam.processType;

	cfnOpenModalPopup(actionUrl, 'popupCoupon');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 기획전 조회 팝업
 * <pre>
 *     cfnOpenPlanPopup('CallbackFun');
 * </pre>
 * @param  : callbackfun - 콜백함수
 * @since  : 2020/04/14
 * @author : yujung
 */
var cfnOpenPlanPopup = function(callbackfun) {
	var actionUrl = "/marketing/plan/list/popup";
	if (typeof(callbackfun) != 'undefined') actionUrl += "?callBackFun=" + callbackfun;

	cfnOpenModalPopup(actionUrl,'popupPlan');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 세트상품구성 팝업
 * <pre>
 *     cfnOpenGoodsSetPopup();
 * </pre>
 * @since  : 2020/06/11
 * @author : eskim
 */
var cfnOpenGoodsSetPopup = function() {
	var actionUrl = "/goods/set/form";

	uifnPopupClose('popupGoodsSet');
	cfnOpenModalPopup(actionUrl, 'popupGoodsSet');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 딜상품구성 팝업
 * <pre>
 *     cfnOpenGoodsDealPopup();
 * </pre>
 * @since  : 2020/06/11
 * @author : eskim
 */
var cfnOpenGoodsDealPopup = function() {
	var actionUrl = "/goods/deal/form";

	uifnPopupClose('popupGoodsDeal');
	cfnOpenModalPopup(actionUrl, 'popupGoodsDeal');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 아이콘 팝업
 * <pre>
 *     cfnOpenIconPopup();
 * </pre>
 * @since  : 2020/06/15
 * @author : eskim
 */
var cfnOpenIconPopup = function() {
	var actionUrl = "/goods/icon/form";

	uifnPopupClose('popupIcon');
	cfnOpenModalPopup(actionUrl, 'popupIcon');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 기획전 응모이벤트 참여자 조회 팝업
 * <pre>
 *     cfnOpenPlanAnswerPopup('planSeq');
 * </pre>
 * @param  : planSeq - 기획전 코드
 * @since  : 2020/06/24
 * @author : sasa004
 */
var cfnOpenPlanAnswerPopup = function(planSq) {
	var actionUrl = "/marketing/plan/answer/list/popup?planSq="+planSq;
	cfnOpenModalPopup(actionUrl,'popupPlanAnswer');
}

/**
 * @type   : function
 * @access : public
 * @desc   : 상품상세 미리보기
 * <pre>
 *     cfnOpenFrontGoodsPopup('LCOPJ523_RE', '10');
 * </pre>
 * @param  : goodsCd - 상품코드
 * @param  : siteCd - 사이트코드
 * @since  : 2020/08/21
 * @author : swkim
 */
var cfnOpenFrontGoodsPopup = function(goodsCd, siteCd) {
	var actionUrl = _frontDomain +"/goods/detail/form?goodsCd=" + goodsCd + '&adminYn=Y';

	window.open(actionUrl);
}

/**
 * @type   : function
 * @access : public
 * @desc   : 브랜드 목록 팝업
 * <pre>
 *     cfnOpenBrandListPopup();
 *     or
 *     cfnOpenBrandListPopup('fnResult');
 *     or
 *     cfnOpenBrandListPopup('fnResult', 'TBJ');
 * </pre>
 * @since  : 2020/12/15
 * @author : eskim
 */
var cfnOpenBrandListPopup = function(callbackfn, searchTxt) {
	var actionUrl = '/business/brand/search/form';
	if (typeof(callbackfn) != 'undefined') actionUrl += "?callbackFn=" + callbackfn;
	if (typeof(searchTxt) != 'undefined') actionUrl += "&searchTxt=" + encodeURIComponent(searchTxt);
	cfnOpenModalPopup(actionUrl, "popupBrandList");
}
