//로그인 유효성체크 ALERT
function uifnAlertClose(id){
	$("#"+id).css({display:'none'});
	return true;
};

//MODAL & MODELESS POPUP 열기
function uifnPopupOpen(id){
	let $thisId = $(document).find("#"+id); //팝업ID
	let $fisrtChild = $thisId.children().first("div"); //modal or modeless
	let $firstPanel = $fisrtChild.find(">.panelStyle"); //first Panel
	let popW, popH;

	//넓이
	if ($fisrtChild.attr("data-width")) { //지정
		popW = parseInt( $fisrtChild.attr("data-width"));
		if ( isNaN(popW) ){ //full
			popW = $(window).width()-100;
		}
		$firstPanel.css({width:popW});
	} else { //auto
		popW = $fisrtChild.width();
		let maxW = $(window).width()-100;
		$firstPanel.css({maxWidth:maxW});
	};

	//높이
	if ( $fisrtChild.attr("data-height") ) { //지정
		popH = parseInt( $fisrtChild.attr("data-height"));
		if ( isNaN(popH) ){ //full
			popH = $(window).height()-100;
		}
		$firstPanel.css({height:popH});
	} else { //auto
		popH = $fisrtChild.height();
		let maxH = $(window).height()-100;
		$firstPanel.css({maxHeight:maxH});
	};

	//팝업 Open
	$thisId.children("div").css({display:"block"});
	$("body").addClass("scrollOff");

	//Modeless 위치
	if ($fisrtChild.hasClass("modelessPopup")){
		let popL = parseInt($fisrtChild.css("left")) - popW/2;
		let popT = parseInt($fisrtChild.css("top")) - popH/2;
		$fisrtChild.css({left:popL, top:popT});
	};

	//내부에 cardArea(이미지카드) 존재 : cardArea 컨텐츠 높이
	if ($thisId.find(".cardArea").length > 0) {
		let noticeH = 0;
		//공지 높이
		if ($firstPanel.find(".notice").length > 0){
			let noticeLen =  $thisId.children(":first").find(".notice li").length;
			noticeH = (noticeLen*24) + 30;
		};
		if ($thisId.children(":first").find(".panelBar").length > 0 ){ btnAreaH = 52 };
		popH = $firstPanel.height();
		let cardAreaH = popH-42-noticeH-37-43; //높이계산 : 팝업-타이틀 높이 - 안내문 높이 - 컬러명(테이블 첫행)높이 - 기타버튼영역
		$(".cardArea").css({height:cardAreaH});
	};

	//내부에 Tabs 존재 : Tabs 컨텐츠 높이
	if ( $firstPanel.find(".tabs").length > 0) {
		let topTbl=0, btnAreaH=0;
		if ( $fisrtChild.hasClass("modelessPopup") ){ //모덜리스팝업
			popH = $fisrtChild.height();
		} else { //모달팝업
			popH = $firstPanel.height();
		};
		if ( $firstPanel.find(".panelContent > .frmStyle:eq(0)").length > 0 ){
			topTbl = $firstPanel.find(".panelContent > .frmStyle:eq(0)").outerHeight() + 15;
		};
		if ( $firstPanel.find(".tabs > .panelBar").length > 0 ){
			 btnAreaH = $firstPanel.find(".tabs > .panelBar").outerHeight();
		};
		let tabContH = popH - 42 - topTbl - 35 - 25 - btnAreaH; //높이계산 : 팝업높이-타이틀-상단테이블-탭스높이-하단여백-버튼영역높이
		$firstPanel.find(".panelContent .tab > .panelStyle").css({height:tabContH});
	};
};

//POPUP CLOSE
function uifnPopupClose(id) {
	var $thisId = $("#"+id);
	if ( $thisId.hasClass("popupWrap") ) { //모달, 모덜리스  팝업
		$thisId.children("div").css({display:"none"});
		$thisId.children("div").remove();
		var modalLen = $(".modalPopup[style='display:block;']").length;
		var modalessLen = $(".modalPopup[style='display:block;']").length;
		if ( modalLen == 0 && modalessLen ==0 ){
			$("body").removeClass("scrollOff");
		};
	} else if ( $thisId.hasClass("videoPopup") ) {  //비디오팝업
		$thisId.css({display:"none"});
		$("#iframe_video").attr("src","");
	};
	$thisId.remove();
};

//비디오 팝업 열기
function viewVideoPopup(id){
	var $thisId = $("#"+id + ">.videoPopup");
	var popW = parseInt( $thisId.children().attr("data-width") );
	var popH = parseInt( $thisId.children().attr("data-height") );
	var iframeSrc = 'https://www.youtube.com/embed/' + $("#video_url").val() + '?showinfo=0&rel=0&vp=hd1080&fs=0&wmode=opaque&enablejsapi=1';
	$("#iframe_video").css({width:popW, height:popH});
	$("#iframe_video").attr("src", iframeSrc+"?enablejsapi=1&version=3&playerapiid=ytplayer");
	$("#"+id).css({display:"block"});
};

//SORTABLE LIST
function unfnModeless(){
	if ( $("#sortable").length > 0 ) {
		var mainW = $("#main").width();
		if ( $("#sortable").hasClass("sortable1") ) {
			mainW =  ((mainW / 1) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable2") ) {
			mainW =  ((mainW / 2) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable3") ) {
			mainW =  ((mainW / 3) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable4") ) {
			mainW =  ((mainW / 4) / mainW) * 100 ;
		};
		$(".secCell").css({"width":mainW +'%'});
	};
	$("#sortable").sortable();
	$("#sortable").disableSelection();
};

//LNB 활성화&비활성화
function lnbToggle(){
	if ( $("#lnb-wrapper").hasClass("on") ){
		$("#lnb-wrapper").removeClass("on");
		$("#main-wrapper").removeClass("on");
	} else {
		$("#lnb-wrapper").addClass("on");
		$("#main-wrapper").addClass("on");
	};
	//차트 리사이즈
	if ( $(document).find(".chartUnit").length > 0 ) {
		chartResize();
	};
};


//체크박스 전체선택 : 210401
function uifnAllCheck(el, grpId) {
	let $thisId = $("#"+grpId);
	$thisId.find('input').prop("checked", $(el).find("input").is(":checked"));
	uiChkCount(grpId);
};

//체크박스 선택된 갯수 출력 : 210401
function uiChkCount(grpId){
	let chkLen = $(".chkBox[data-group='"+grpId+"']").find("input:checked").length;//체크된 갯수
	if( $(".tagNum[data-count='"+grpId+"']") != undefined ){
		$(".tagNum[data-count='"+grpId+"']").text(chkLen);
	}
};

$(document).ready(function(){

	//MODELESS POPUP : draggable
	$(document).find(".draggable").draggable({containment:"#wrapper", scroll:false});

	//input readOnly 처리
	$(document).on("click", "[readonly='readonly']", function(){
		return false;
	});

	//그룹내 개별 체크박스 선택 : 210401
	$(document).on("click", ".chkBox", function(){
		if( $(this).attr("data-group") ) {
			let grpId = $(this).attr("data-group");
			let is_checked = true;
			let chkLen;
			$(".chkBox[data-group='"+grpId+"']").each(function(){
				is_checked = is_checked && $(this).find("input").is(":checked");
			});
			$("#"+grpId).find("input[name='전체선택']").prop("checked", is_checked); //전체선택 체크 또는 해제
			uiChkCount(grpId);
		}
	});

	//checkBoxList : More(+,-) 버튼
	$(document).on("click", ".checkBoxList .more", function(){
		var thisI = $(this).find("i");
		if( $(thisI).hasClass("fa-plus") ){
			$(this).parent().addClass("on");
			$(thisI).removeClass("fa-plus").addClass("fa-minus");
		} else {
			$(this).parent().removeClass("on");
			$(thisI).removeClass("fa-minus").addClass("fa-plus");
		}
	});

	//multiCheckBox : Header Click
	var mcbNowIdx;
	$(document).on("click", ".multiCheckBox .sltBtn", function(){
		//닫기-----
		if($(this).hasClass("on")){
			$(this).next("ul").css({display:"none"}); //체크 리스트 닫기
			let openObj = $(this).parents(".multiCheckBox");
			let frtTxt = openObj.find("label[data-group] input:checked").parent().eq(0).text();
			let chkLen = openObj.find("label[data-group] input:checked").length;
			let chkCnt = chkLen - 1;
			if ( chkLen == 0 ){		//체크 값이 없을때
				let btnNm = $(".multiCheckBox .sltBtn.on").attr("data-name");
				$(this).text(btnNm).removeClass("on");
			} else if ( chkLen == 1 ) {
				$(this).text(frtTxt).removeClass("on");
			} else {				//체크 값이 있을때
				$(this).text(frtTxt + " 외 " +chkCnt).removeClass("on");
			};
		}
		//열기-----
		else {
			//활성화된 타 multiCheckBox 처리-----------------
			let openObj = $(document).find(".multiCheckBox .sltBtn.on").parent(".multiCheckBox");
			let frtTxt = openObj.find("label[data-group] input:checked").parent().eq(0).text();
			let chkLen = openObj.find("label[data-group] input:checked").length;
			let chkCnt = chkLen - 1;
			openObj.find("ul").css({display:"none"}); //체크 리스트 닫기
			if ( chkLen == 0 ){		//체크 값이 없을때
				let btnNm = $(".multiCheckBox .sltBtn.on").attr("data-name");
				$(".multiCheckBox .sltBtn.on").text(btnNm).removeClass("on");
			} else if ( chkLen == 1 ) {
				$(".multiCheckBox .sltBtn.on").text(frtTxt).removeClass("on");
			} else {				//체크 값이 있을때
				$(".multiCheckBox .sltBtn.on").text(frtTxt + " 외 " +chkCnt).removeClass("on");
			};
			//현재 multiCheckBox 처리------------
			$(this).next("ul").css({display:"block"}); //체크 리스트 열기
			$(this).addClass("on");

			$(document).find(".multiCheckBox").each(function(i, e){
				if( $(this).find(".sltBtn").hasClass("on")){
					mcbNowIdx =  i;
					//console.log("버튼 클릭시 : "+ i);
				}
			});
		}
	});

	//Focus Out
	$(document).on("click", function(e){
		//multiCheckBox----------------------------------------------
		if ( $(document).find(".multiCheckBox") != undefined ) {
			let openObj = $(".multiCheckBox").eq(mcbNowIdx); //console.log("바닥 클릭시 : "+ mcbNowIdx);
			if ( $(e.target).parents(".multiCheckBox").length == 0 ) {
				let chkLen = openObj.find("label[data-group] input:checked").length;
				let chkCnt = chkLen - 1;
				let frtTxt = openObj.find("label[data-group] input:checked").parent().eq(0).text();
				openObj.find("ul").css({display:"none"});
				if ( chkLen == 0 ){		//체크 값이 없을때
					let btnNm = $(".multiCheckBox .sltBtn.on").attr("data-name");
					$(".multiCheckBox .sltBtn.on").text(btnNm).removeClass("on");
				} else if ( chkLen == 1 ) {
					$(".multiCheckBox .sltBtn.on").text(frtTxt).removeClass("on");
				} else {				//체크 값이 있을때
					$(".multiCheckBox .sltBtn.on").text(frtTxt + " 외 " +chkCnt).removeClass("on");
				};
			}
		}
	});


	//햄버거버튼 : LNB 숨김(전체화면 보기)
	$(document).on("click",".lnbClose",function(){
		lnbToggle();
	});

	//GNB Memu
	$(document).on("click",".header-menu .menu a",function(){
		$(".header-menu .menu a").removeClass("on");
		$(this).addClass("on");
		var menuIdx = $(this).parent("span").index()+1;
		$("#lnb"+menuIdx).addClass("on");
		if( !$("#lnb-wrapper").hasClass("on") ){
			lnbToggle(); // LNB Open
		};
	});

	//LNB 서브메뉴 보기 : dep2
	$(document).on("click",".dep2",function(){
		if ($(this).hasClass("on")){	//활성화된 상태
			$(this).removeClass("on");
			$(this).next(".dep3").slideUp(200).removeClass("on");
		} else {						//비활성화된 상태
			$(this).addClass("on");
			$(this).next(".dep3").slideDown(200).addClass("on");
		};
	});

	//LNB 서브메뉴 보기 : dep3
	$(document).on("click", ".dep3 > li > a", function(){
		if ($(this).hasClass("on")==false){
			$(".dep3 > li > a").removeClass("on");
			$(this).addClass("on");
		};
	});

	//다중셀렉박스 리스트 보이기,감추기
	$(document).on("click", ".mSelected", function(){
		$(this).find(".srchFld input").focus();
	});
	$(document).on("focusin", ".srchFld input", function(){
		$(this).parents(".mSelected").next(".mSelecting").css({display:'block'});
	});
	$(document).on("focusout", ".mSelectBox", function(){
		$(this).find(".mSelecting").slideUp(50);
	});
	//다중셀렉박스 리스트
	$(document).on("mousedown", ".mSelectWrap .mSelecting ul li", function(){
		if ( $(this).hasClass("deselect")==false ){
			var dataIdx = $(this).attr("data-index");
			var movePos = $(this).parents(".mSelecting").prev(".mSelected").find(".srchFld");
			$(this).parents(".mSelecting").prev(".mSelected").find("li[data-index="+dataIdx+"]").removeClass("off").insertBefore(movePos);
			$(this).parents(".mSelectWrap").find("select option[data-index="+dataIdx+"]").prop("selected", true);
			$(".mSelecting").slideUp(50);
			$(this).addClass("off");
			return false;
		};
	});
	//다중셀렉박스 닫기
	$(document).on("click", ".mSelectWrap .mSelected li a", function(){
		var dataIdx = $(this).parent("li").attr("data-index");
		$(this).parents(".mSelected").next(".mSelecting").find("ul li[data-index="+dataIdx+"]").removeClass("off")
		$(this).parents(".mSelectWrap").find("select option[data-index="+dataIdx+"]").prop("selected", false);
		$(this).parent("li").addClass("off")
		return false;
	});

	//TABS
	$(document).on("click", ".tabs .tabsNav li", function(e){
		e.preventDefault();
		if ( !$(this).hasClass("on") ) {
			let contIdx = $(this).index();
			let pTab = $(this).parents(".tabs");
			let thisTop = $(window).scrollTop();
			pTab.find(".tabsNav li").removeClass("on");
			pTab.find(".tabsCont > li").removeClass("on");
			$(this).addClass("on");
			pTab.find(".tabsCont > li").eq(contIdx).addClass("on");
			$('html, body').animate({scrollTop:thisTop}, 'fast');
		}
	});

	//TABSJR : 탭 하위 탭스
	$(document).on("click", ".tabsJr .tabsJrNav li", function(e){
		e.preventDefault();
		if ( !$(this).hasClass("on") ) {
			let contIdx = $(this).index();
			let pTab = $(this).parents(".tabsJr");
			let thisTop = $(window).scrollTop();
			pTab.find(".tabsJrNav li").removeClass("on");
			pTab.find(".tabsJrCont > li").removeClass("on");
			$(this).addClass("on");
			pTab.find(".tabsJrCont > li").eq(contIdx).addClass("on");
			$('html, body').animate({scrollTop:thisTop}, 'fast');
		}
	});

	//SORTABLE LIST
	if ( $("#sortable").length > 0 ) {
		var mainW = $("#main").width();
		if ( $("#sortable").hasClass("sortable1") ) {
			mainW =  ((mainW / 1) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable2") ) {
			mainW =  ((mainW / 2) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable3") ) {
			mainW =  ((mainW / 3) / mainW) * 100 ;
		};
		if ( $("#sortable").hasClass("sortable4") ) {
			mainW =  ((mainW / 4) / mainW) * 100 ;
		};
		$(".secCell").css({"width":mainW +'%'});
	};
	$("#sortable").sortable();
	$("#sortable").disableSelection();

	//파일선택
	$(document).on("change",".uFileInput", function() {
		let fileName = $(this).val().split('\\').pop();
		$(this).next('.uFileLabel').addClass("selected").html(fileName);
	});

	//베너 그룹 Up & Down
	$(document).on("click",".groupBtn", function() {
		var $gId = $(this).attr("id");
		var $gIcn = $(this).find("i");
		if ( $("table[data-child="+$gId+"]").hasClass("off") ){
			$("table[data-child="+$gId+"]").removeClass("off");
			$gIcn.attr("class","fa fa-chevron-down");
		} else  {
			$("table[data-child="+$gId+"]").addClass("off");
			$gIcn.attr("class","fa fa-chevron-up");
		};
	});

	//비디오팝업 배경 클릭시 닫기
	$(document).on("click",".videoClose", function() {
		var vId = $(this).attr("id");
		$("#"+vId).css({display:"none"});
		$("#"+vId).find("iframe").attr("src","");
	});

	//상단이동 버튼
	$(window).scroll(function () {
		if ($(this).scrollTop() > 300) { $("#btnTop").fadeIn() }
		else { $("#btnTop").fadeOut() };
	});
	//상단이동
	$(document).on("click","#btnTop", function() {
		$('html, body').animate({scrollTop:'0'}, 200);
	});

	//다중셀렉트박스 포커스인(접근성)
	$(document).on("focusin",".srchFld", function() {
		$(this).parents(".mSelectBox").addClass("outline");
	});
	//다중셀렉트박스 포커스아웃(접근성)
	$(document).on("focusout",".srchFld", function() {
		$(this).parents(".mSelectBox").removeClass("outline");
	});

	//패널영역 줄이기
	$(document).on("click",".panelControl .fa-chevron-up", function() {
		$(this).parents(".panelStyle").find(".panelContent").slideUp(100);
		$(this).attr("class","fa fa-chevron-down");
	});
	//패널영역 펼치기
	$(document).on("click",".panelControl .fa-chevron-down", function() {
		$(this).parents(".panelStyle").find(".panelContent").slideDown(100);
		$(this).attr("class","fa fa-chevron-up");
	});

	//패널영역 감추기
	$(document).on("click",".panelControl .fa-times", function() {
		$(this).parents(".panelStyle").fadeOut(100);
	});


	//Date Picker Start -----------------------------------------------------------
	function initDatePickers() {
		// datepicker Korean option
		$.datepicker.regional['ko'] = {
			monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
			monthNamesShort: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
			dayNames: ['일', '월', '화', '수', '목', '금', '토'],
			dayNamesShort: ['일', '월', '화', '수', '목', '금', '토'],
			dayNamesMin: ['일', '월', '화', '수', '목', '금', '토'],
			dateFormat: 'yy-mm-dd',
			firstDay: 1,
			//isRTL: false,
			//duration: 200,
			//showAnim: 'show',
			showMonthAfterYear: true,
			yearSuffix: '년 ',
			prevText: '이전달',
			nextText: '다음달',
			//showButtonPanel: true,
			//currentText: '오늘',
			//closeText: '닫기',
			showOn: 'both',
			buttonImage:'image/btn_calendar.png'
			//,buttonImageOnly: true
		};
		$.datepicker.setDefaults($.datepicker.regional['ko']);
		$('.schDate').datepicker({
			changeMonth: true,
			changeYear: true,
			defaultDate: $('.schDate').val()
		});
		// monthpicker and year selector start/end year (10 year ago)
		var currentYear = (new Date()).getFullYear();
		var startYear = currentYear - 10;
		var finalYear = currentYear + 10;
		var options = {
			startYear: startYear,
			finalYear: finalYear,
			pattern: 'yyyy-mm',
			monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월']
		};
		$('.schMonth').monthpicker(options);
		// make year selector
		for (var i = finalYear; i >= startYear; i--) {
			if (currentYear == i ) {
				$(".schYear").append("<option value='" + i + "' selected class='ui-state-highlight'>" + i + "</option>");
			} else {
				$('.schYear').append("<option value='" + i + "'>" + i + "</option>");
			}
		}
	};
	$(function() {
		(function($) {
			var methods = {
				init: function(options) {
					return this.each(function() {
						var $this = $(this),
							data = $this.data('monthpicker'),
							year = (options && options.year) ? options.year : (new Date()).getFullYear(),
							settings = $.extend({
								pattern: 'yyyy-mm',
								selectedMonth: null,
								selectedMonthName: '',
								selectedYear: year,
								startYear: year - 10,
								finalYear: year + 10,
								monthNames: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'],
								id: "monthpicker_" + (Math.random() * Math.random()).toString().replace('.', ''),
								openOnFocus: true,
								disabledMonths: []
							}, options);
						settings.dateSeparator = settings.pattern.replace(/(mmm|mm|m|yyyy|yy|y)/ig, '');
						// If the plugin hasn't been initialized yet for this element
						if (!data) {
							$(this).data('monthpicker', {
								'target': $this,
								'settings': settings
							});
							if (settings.openOnFocus === true) {
								$this.on('focus', function() {
									$this.monthpicker('show');
								});
							}
							$this.monthpicker('parseInputValue', settings);
							$this.monthpicker('mountWidget', settings);
							$this.on('monthpicker-click-month', function(e, month, year) {
								$this.monthpicker('setValue', settings);
								$this.monthpicker('hide');
							});
							// hide widget when user clicks elsewhere on page
							$this.addClass("mtz-monthpicker-widgetcontainer");
							$(document).unbind("mousedown.mtzmonthpicker").on("mousedown.mtzmonthpicker", function(e) {
								if (!e.target.className || e.target.className.toString().indexOf('mtz-monthpicker') < 0) {
									$(this).monthpicker('hideAll');
								}
							});
						}
					});
				},
				show: function() {
					$(this).monthpicker('hideAll');
					var widget = $('#' + this.data('monthpicker').settings.id);
					widget.css("top", this.offset().top + this.outerHeight());
					if ($(window).width() > (widget.width() + this.offset().left)) {
						widget.css("left", this.offset().left);
					} else {
						widget.css("left", this.offset().left - widget.width());
					}
					widget.show();
					//widget.find('select').focus();
					this.trigger('monthpicker-show');
				},
				hide: function() {
					var widget = $('#' + this.data('monthpicker').settings.id);
					if (widget.is(':visible')) {
						widget.hide();
						this.trigger('monthpicker-hide');
					}
				},
				hideAll: function() {
					$(".mtz-monthpicker-widgetcontainer").each(function() {
						if (typeof($(this).data("monthpicker")) != "undefined") {
							$(this).monthpicker('hide');
						}
					});
				},
				setValue: function(settings) {
					var month = settings.selectedMonth,
						year = settings.selectedYear;
					if (settings.pattern.indexOf('mmm') >= 0) {
						month = settings.selectedMonthName;
					} else if (settings.pattern.indexOf('mm') >= 0 && settings.selectedMonth < 10) {
						month = '0' + settings.selectedMonth;
					};
					if (settings.pattern.indexOf('yyyy') < 0) {
						year = year.toString().substr(2, 2);
					};
					if (settings.pattern.indexOf('y') > settings.pattern.indexOf(settings.dateSeparator)) {
						this.val(month + settings.dateSeparator + year);
					} else {
						this.val(year + settings.dateSeparator + month);
					};
					this.change();
				},
				disableMonths: function(months) {
					var settings = this.data('monthpicker').settings,
						container = $('#' + settings.id);
					settings.disabledMonths = months;
					container.find('.mtz-monthpicker-month').each(function() {
						var m = parseInt($(this).data('month'));
						if ($.inArray(m, months) >= 0) {
							$(this).addClass('ui-state-disabled');
						} else {
							$(this).removeClass('ui-state-disabled');
						}
					});
				},
				mountWidget: function(settings) {
					var monthpicker = this,
						container = $('<div id="' + settings.id + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" />'),
						header = $('<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all mtz-monthpicker" />'),
						combo = $('<select class="mtz-monthpicker mtz-monthpicker-year" />'),
						table = $('<table class="mtz-monthpicker" />'),
						tbody = $('<tbody class="mtz-monthpicker" />'),
						tr = $('<tr class="mtz-monthpicker" />'),
						td = '',
						selectedYear = settings.selectedYear,
						option = null,
						attrSelectedYear = $(this).data('selected-year'),
						attrStartYear = $(this).data('start-year'),
						attrFinalYear = $(this).data('final-year'),
						currYear = date.getFullYear();
						currMonth = date.getMonth()+1;
					if (attrSelectedYear) {
						settings.selectedYear = attrSelectedYear;
					}
					if (attrStartYear) {
						settings.startYear = attrStartYear;
					}
					if (attrFinalYear) {
						settings.finalYear = attrFinalYear;
					}
					container.css({
						position: 'absolute',
						//zIndex: 999999,
						whiteSpace: 'nowrap',
						//width: '250px',
						overflow: 'hidden',
						textAlign: 'center',
						display: 'none',
						top: monthpicker.offset().top + monthpicker.outerHeight(),
						left: monthpicker.offset().left
					});
					combo.on('change', function() {
						var months = $(this).parent().parent().find('td[data-month]');
						months.removeClass('ui-state-highlight');
						months.removeClass('ui-state-active');
						if ($(this).val() == settings.selectedYear) {
							months.filter('td[data-month=' + settings.selectedMonth + ']').addClass('ui-state-active');
						}
						//alert($(this).val() +','+ currYear);
						if ($(this).val() == currYear)  {
							months.filter('td[data-month=' + currMonth + ']').addClass('ui-state-highlight');
						}
						monthpicker.trigger('monthpicker-change-year', $(this).val());
					});
					// mount years combo
					for (var i = settings.startYear; i <= settings.finalYear; i++) {
						var option = $('<option class="mtz-monthpicker" />').attr('value', i).append(i);
						if (settings.selectedYear == i) {
							option.attr('selected', 'selected');
						}
						combo.append(option);
					}
					header.append(combo).appendTo(container);
					header.append('년').appendTo(container);
					// mount months table
					for (var i = 1; i <= 12; i++) {
						td = $('<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month"/>').attr('data-month', i);
						if (settings.selectedMonth == i) {
							td.addClass('ui-state-active');
						}
						if (settings.selectedYear == currYear && settings.selectedMonth == i) {
							td.addClass('ui-state-highlight');
						}
						td.append(settings.monthNames[i - 1]);
						tr.append(td).appendTo(tbody);
						if (i % 3 === 0) {
							tr = $('<tr class="mtz-monthpicker" />');
						}
					}
					tbody.find('.mtz-monthpicker-month').on('click', function() {
						var m = parseInt($(this).data('month'));
						if ($.inArray(m, settings.disabledMonths) < 0) {
							settings.selectedYear = $(this).closest('.ui-datepicker').find('.mtz-monthpicker-year').first().val();
							settings.selectedMonth = $(this).data('month');
							settings.selectedMonthName = $(this).text();
							monthpicker.trigger('monthpicker-click-month', $(this).data('month'));
							$(this).closest('table').find('.ui-state-active').removeClass('ui-state-active');
							$(this).addClass('ui-state-active');
						}
					});
					table.append(tbody).appendTo(container);
					container.appendTo('body');
				},
				destroy: function() {
					return this.each(function() {
						$(this).removeClass('mtz-monthpicker-widgetcontainer').unbind('focus').removeData('monthpicker');
					});
				},
				getDate: function() {
					var settings = this.data('monthpicker').settings;
					if (settings.selectedMonth && settings.selectedYear) {
						return new Date(settings.selectedYear, settings.selectedMonth - 1);
					} else {
						return null;
					}
				},
				parseInputValue: function(settings) {
					if (this.val()) {
						if (settings.dateSeparator) {
							var val = this.val().toString().split(settings.dateSeparator);
							if (settings.pattern.indexOf('m') === 0) {
								settings.selectedMonth = val[0];
								settings.selectedYear = val[1];
							} else {
								settings.selectedMonth = val[1];
								settings.selectedYear = val[0];
							}
						}
					}
				}
			};
			$.fn.monthpicker = function(method) {
				if (methods[method]) {
					return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
				} else if (typeof method === 'object' || !method) {
					return methods.init.apply(this, arguments);
				} else {
					$.error('Method ' + method + ' does not exist on jQuery.mtz.monthpicker');
				}
			};
		})(jQuery);
		Date.prototype.yyyymmdd = function() {
			var mm = this.getMonth() + 1; // getMonth() is zero-based
			var dd = this.getDate();

			return [this.getFullYear(),
							(mm>9 ? '' : '0') + mm,
							(dd>9 ? '' : '0') + dd
						 ].join('-');
		};
		var date = new Date();
		var schDate = date.yyyymmdd();
		$('.schDate').val(schDate);
		$('.schMonth').val(schDate.substr(0,7));
		initDatePickers();
	});

	//년-월
	$(".schBtn").on('click', function () {
		var thisId= $(this).attr("data-id");
		$('#'+thisId).monthpicker('show');
	});
	//Date Picker End-----------------------------------------------------------









});