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

//차트 리사이징
function chartResize(){
	if ( $(document).find(".chartUnit").length > 0 ) {
		let elLen = $(".chartUnit").length;
		for (let i=0; i<elLen; i++){
			let thisId = eval($(".chartUnit").eq(i).attr("id"));
			let liW = Math.floor( $(".chartUnit").eq(i).parent("li").width());
			thisId.resize({width:liW});
			$(".c3-regions rect").attr("width",liW);
		}
	}
};

//MODAL & MODELESS POPUP 열기
function uifnPopupOpen(id){
	var $thisId = $(document).find("#"+id);
	var popW = parseInt( $thisId.children().attr("data-width"));
	var popH = parseInt( $thisId.children().attr("data-height"));

	//팝업사이즈
	if (!popW && !popH) { //가로&세로 미지정(풀사이즈 출력)
		popW = $(window).width()-100;
		popH = $(window).height()-100;
		if (popW % 2 != 0 )	{popW = popW+1}; //짝수 변환(border 두께 영향)
		if (popW < 1180)	{popW = 1180 };  //최소넓이
		if (popH % 2 != 0 )	{popH = popH+1}; //짝수 변환(border 두께 영향)
		if (popH < 488)	{ popH = 488 };  	//최소높이
		$thisId.children().find(" > .panelStyle").css({width:popW, height:popH});
	} else if (popW && popH) { 		//가로,세로 둘다 지정(지정된 사이즈로 출력)
		$thisId.children().find(".panelStyle").css({width:popW, height:popH});
	} else { 	//가로만 지정(세로는 auto)
		$thisId.children().find("> .panelStyle").css({width:popW});
	};

	if ($thisId.children().hasClass("modelessPopup")){ //모덜리스 팝업의 경우
		if (isNaN(popW)){popW = $thisId.children().width(); }
		if (isNaN(popH)){popH = $thisId.children().height(); }
		let popL = $(window).width()/2 - popW/2;
		let popT = $(window).height()/2 - popH/2;
		$thisId.children().css({left:popL, top:popT});
	};

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

	//이미지카드가 있는 팝업일때 내부 컨텐츠 높이 지정
	if ($thisId.children().find(".cardArea").length > 0) {
		var popH=0, noticeH=0, btnAreaH=0;
		if ($thisId.children().find(".notice").length > 0){
			var noticeLen =  $thisId.children().find(".notice li").length;
			noticeH = (noticeLen*24) + 30;
		};
		if ($thisId.children().hasClass("modelessPopup")){ //모덜리스 팝업의 경우
			popH = $thisId.children().height();
		} else {
			popH = $thisId.children().find(".panelStyle").height();
		};
		if ($thisId.children().find(".panelBar").length > 0 ){ btnAreaH = 52 };

		var cardAreaH = popH-42-noticeH-37-btnAreaH; //높이계산 : 팝업-타이틀-안내문-컬러명TR-기타버튼영역
		$(".cardArea").css({height:cardAreaH});
	};

	//tab이 있는 팝업일때 내부 컨텐츠 높이 지정
	if ($thisId.children().find(".tabsCont").length > 0) {
		var mdConH=0, topTbl=0, popH=0, btnAreaH=0;
		if ($thisId.children().hasClass("modelessPopup")){ //모덜리스 팝업의 경우
			popH = $thisId.children().height();
		} else {
			popH = $thisId.children().find(".panelStyle").height();
		};
		if ($thisId.children().find(".panelContent > .frmStyle:eq(0)").length > 0 ){
			topTbl = $thisId.children().find(".panelContent > .frmStyle:eq(0)").outerHeight() + 15;
		};
		if ($thisId.children().find(".panelBar").length > 0 ){ btnAreaH = 52 };

		//console.log(topTbl);
		var tabContH = popH-42-topTbl-35-btnAreaH; //높이계산 : 팝업높이-타이틀-상단테이블-탭스높이-버튼
		$(".tab > .panelStyle").css({height:tabContH});
	};

};

//MODAL 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");
	};
	setTimeout( chartResize, 300); //차트 리사이징
};

$(document).ready(function(){

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


	//chart resizing
	$(window).resize(function(){
		setTimeout( chartResize, 300);	//차트 리사이징
	});

	//체크박스(단일), 라디오버튼 : readOnly 처리
	$(document).on("click", "[type=checkbox][readonly],[type=radio][readonly]", function(){
		return false;
	});

	$(document).on("click", ".chkBox", function(e){
		let cntId = $(this).parent().parent("ul").attr("data-count-id");
		let cntLen;

		if ( $(this).find("input").is('[id]') ){ // ---------------전체선택ID
			let $id = $(this).find("input").attr("id");
			if ( $(this).hasClass("checked") ) { //체크된 경우
				$("input[id="+$id+"]").parent("label").removeClass("checked");
				$("input[id="+$id+"]").prop("checked", false);
				$("input[name="+$id+"]").parent("label").removeClass("checked");
				$("input[name="+$id+"]").prop("checked", false);
			} else {
				$("input[id="+$id+"]").parent("label").addClass("checked");
				$("input[id="+$id+"]").prop("checked", true);
				$("input[name="+$id+"]").parent("label").addClass("checked");
				$("input[name="+$id+"]").prop("checked", true);
			};
			//선택된 개수 출력 (checkBoxList)
			if (cntId != undefined ) {
				cntLen =  $("input[name="+$id+"]:checked").length; //체크된 개수
				$("#"+cntId).text(cntLen);
			};
			return false;

		} else {	// ---------------개별선택
			let $name = $(this).find("input").attr("name");
			let totLen = $("input[name="+$name+"]").length; //전체 개수
			if ( $(this).hasClass("checked")) {
				$(this).removeClass("checked");
				$(this).find("input").prop("checked", false);
				$("input[id="+$name+"]").prop("checked", false);
				$("input[id="+$name+"]").parent("label").removeClass("checked");
			} else {
				$(this).addClass("checked");
				$(this).find("input").prop("checked", true);
				cntLen =  $("input[name="+$name+"]:checked").length; //체크된 개수
				if (totLen == cntLen ){
					$("input[id="+$name+"]").prop("checked", true);
					$("input[id="+$name+"]").parent("label").addClass("checked");
				}
			};
			//선택된 개수 출력 (checkBoxList)
			if (cntId != undefined ) {
				cntLen =  $("input[name="+$name+"]:checked").length; //체크된 개수
				if (totLen > cntLen ) {
					$("#"+cntId).text(cntLen);
				} else if  (totLen == cntLen ) {
					$("#"+cntId).text(totLen);
				};
			};
			return false;
		};
	});


	/* CheckBox List : 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");
		}
	});

	/* Multi CheckBox - 다중선택 체크박스 */
	$(document).on("click", ".multiCheckBox .sltBtn", function(){
		if($(this).hasClass("on")){
			$(this).removeClass("on");
			$(this).parent().find("ul").css({display:"none"});
		}else{
			$(".multiCheckBox .sltBtn").removeClass("on");
			$(".multiCheckBox ul").css({display:"none"});
			$(this).addClass("on");
			$(this).parent().find("ul").css({display:"block"});
		}
	});

	//햄버거버튼 : 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","");
	});

	//상단이동 버튼
	$(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-----------------------------------------------------------









});