




var SITE_URL = "http://www.evercs.com";
var SSL_URL = "https://www.evercs.com:1443";
function moveFocus(ln, o1, o2) {if (ln == o1.value.length) {document.getElementById(o2).focus();}}
function inputFocus() { this.style.background='#ecf2fb'; this.style.border="2px solid #5380c5"; }
function inputBlur() { this.style.background="#f4f4f4"; this.style.border="1px solid #f4f4f4"; }
function inputStyle() { $("input[type='text'],input[type='password'],input[type='file'],textarea").focusin(inputFocus); $("input[type='text'],input[type='password'],input[type='file'],textarea").focusout(inputBlur); }
function checkDigit(s){ s +=""; if(s.length == 1){ s = "0" + s; } return s; }
function getOffset(id) { var o = $(id); var p = o.offset(); p.width  = o.width(); p.height = o.height(); return p; }
var schedule = {};
schedule.dateList = [];
schedule.store = {};
schedule.weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

function getWeeknYear(d){ var ms1d = 86400000, ms3d = 3 * ms1d, ms7d = 7 * ms1d; var ret; var D3 = Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()) + ms3d; var wk = Math.floor(D3 / ms7d); with (new Date(wk * ms7d)) { var yy = getUTCFullYear(); } if(d.getDay()==0){ ret = 2 + wk - Math.floor((Date.UTC(yy, 0, 4) + ms3d) / ms7d); }else{ ret = 1 + wk - Math.floor((Date.UTC(yy, 0, 4) + ms3d) / ms7d); } return d.getFullYear() + "" + ret;}

schedule.createDateList = function() {
	var o = [];
	var y = schedule.currentYear;
	var m = schedule.currentMonth;
	
	var prevDate = new Date(y, m-1, 0);
	var prevLastDay = prevDate.getDate();
	
	var currentDate = new Date(y, m-1, 1);
	var weekday = currentDate.getDay();
	
	var lastDate = new Date(y, m, 0);
	var lastday = lastDate.getDate();
	var lastweekday = lastDate.getDay();
	
	var nextDate = new Date(y, m, 1);
	var startDay = prevLastDay - weekday + 1;
	
	for(var i=0; i < weekday; i++) {
		o.push({date:prevDate.getFullYear()+checkDigit(prevDate.getMonth()+1)+checkDigit(startDay + i), year:prevDate.getFullYear(), month:(prevDate.getMonth()+1), day:(startDay + i)});
	}
	for(var i=0; i < lastday; i++) {
		o.push({date:currentDate.getFullYear()+checkDigit(currentDate.getMonth()+1)+checkDigit(i+1), year:currentDate.getFullYear(), month:(currentDate.getMonth()+1), day:(i+1)});
	}
	var no = 1;
	for(var i = lastweekday; i < 6; i++) {
		o.push({date:nextDate.getFullYear() + checkDigit(nextDate.getMonth()+1) + checkDigit(no), year:nextDate.getFullYear(), month:(nextDate.getMonth()+1), day:(no)});
		no++;
	}
	schedule.dateList = o;
};

schedule.prevMonth = function() {
	if(this.currentMonth == 1) {
		schedule.currentYear -= 1;
		this.currentMonth = 12;
	} else {
		this.currentMonth -= 1;	
	}
	this.rebuildCalendar();
};

schedule.nextMonth = function() {
	if(this.currentMonth == 12) {
		schedule.currentYear += 1;
		this.currentMonth = 1;
	} else {
		this.currentMonth += 1;	
	}
	this.rebuildCalendar();
};

schedule.createLayer = function() {
	var div = document.createElement("div");
	div.id = "scheduleLayer";
	$(div).css("top", 79);
	$(div).css("left", 210);
	div.className = "schedule";
	var s = "";
    s += "<div class='top'>";
    s += "<p class='img'><img src='/share/images/schedule/text.png'/></p>";
    s += "<div class='date'>";
    s += "<a href='#none' onclick='schedule.prevMonth();' class='prev'>지난달</a>";
    s += "<p id='currentDate'></p>";
    s += "<a href='#none' onclick='schedule.nextMonth();' class='next'>다음달달</a>";
    s += "</div>";
    s += "<p class='close'><a href='javascript:schedule.closeLayer();'>창닫기</a></p>";
    s += "</div>";
    s += "<div id='calendarBox' class='calendar'></div>";
    
    div.innerHTML = s;
    document.body.appendChild(div);
    div.style.display = "block";
    
    this.calendarBox = document.getElementById("calendarBox");
    this.currentDateBox = document.getElementById("currentDate");
    $(this.currentDateBox).text(schedule.currentYear + "." + checkDigit(this.currentMonth));
};

schedule.createCalendar = function() {
	calTable = document.getElementById("calTable");
	if(calTable)
		this.calendarBox.removeChild(calTable);
	
	var table = document.createElement("table");
	table.id = "calTable";
	var thead = document.createElement("thead");
	var tr = document.createElement("tr");
	table.appendChild(thead);
	thead.appendChild(tr);
	
	for(var i = 0; i < 7; i++) {
		var th = document.createElement("th");
		th.innerText = this.weekdays[i];
		th.scope = "col";
		if(i == 0) th.className = "sun";
		tr.appendChild(th);
	};
	
	var tbody = document.createElement("tbody");
	var tr = document.createElement("tr");
	table.appendChild(tbody);
	
	var week = 0;
	for(var i = 0; i < this.dateList.length; i++){
		if((i%7) == 0){
			week++;
			tr = document.createElement("tr");
			tr.id = "week" + week;
			tbody.appendChild(tr);
		}
		if((i%7) == 6) {
			this.dateList[i].endWeekDay = "Y";
		}
		var td = document.createElement("td");
		td.id = "tdBox" + this.dateList[i].date;
		td.week = week;
		td.endWeekDay = this.dateList[i].endWeekDay || "N";
		td.innerHTML = "<em>"+this.dateList[i].day+"</em><ul id='T"+this.dateList[i].date+"'></ul>";
		tr.appendChild(td);
		
		this.lastTdBox = td;
	}
	this.calendarBox.appendChild(table);
};

var program = {"EP10":"basic", "EP20":"leader", "EP30":"special"};

schedule.dataLoad = function() {
	var _self = this;
	var sdate = schedule.currentYear + checkDigit(schedule.currentMonth);
	if(this.store[sdate]) {
		_self.scheduleData = this.store[sdate];
	} else {
		$.ajax({
			type: "POST",
			url: "/edu/scheduleJson.do",
			data: {sdate:sdate},
			dataType:'json',
			async:false,
			success: function(response){
				_self.scheduleData = response;
				_self.store[sdate] = response;
			},
			error: function(status, text) { alert(text); }
		});			
	}
};

schedule.createTitle = function() {
	var obj = this.scheduleData;
	for(var i = 0; i < obj.length; i++) {
		var li = document.createElement("li");
		obj[i].li = li;
		s = "<a href='#none' onclick='schedule.showLayer("+i+");' class='"+program[obj[i].pramgramCode]+"'>";
		if(obj[i].fromDate == obj[i].toDate) {
			s += "<span class='full'>"+obj[i].title+"</span>";
		} else {
			s += "<span class='left'>"+obj[i].title+"</span><span class='right'> ~ "+obj[i].toDate.substr(6, 2)+"</span>";
		}
		s += "</a>";
		li.innerHTML = s;
		document.getElementById("T"+obj[i].fromDate).appendChild(li);
	}
};

schedule.createToolTip = function() {
	var s = "";
	s = '<div class="Pupleft">'
    + '<p><img src="/share/images/schedule/s_imgb_01.png" alt="" id="popimg" /></p>'
    + '<p ><a id="link" href="#none" class="btn">상세보기</a></p>'
    + '</div>'
    + '<dl class="Pupright">'
    + '<dt id="title" class="ellipsis"></dt>'
    + '<dd id="info" class="ddColor"></dd>'
    + '<dd id="summary"></dd>'
    + '</dl>'
    + '<p ><a href="#none" onclick="schedule.hideLayer();" class="close">창닫기</a></p>';	
    
	var div = document.createElement("toolTipBox"); 
	
	div.id = "toolTipBox";
	div.style.position = "absolute";
	div.style.zIndex = 200;
	div.style.display = "none";
	div.innerHTML = s;
	document.body.appendChild(div);
	
	this.toolTipLayer = {};
	this.toolTipLayer.box = div;
	this.toolTipLayer.title = $(div).find("#title").get(0);
	this.toolTipLayer.info = $(div).find("#info").get(0);
	this.toolTipLayer.summary = $(div).find("#summary").get(0);
	this.toolTipLayer.popimg = $(div).find("#popimg").get(0);
	this.toolTipLayer.link = $(div).find("#link").get(0);
};

schedule.closeLayer = function() { schedule.hideLayer(); $("#scheduleLayer").hide(); };
schedule.hideLayer = function () { $("#titleLayer").hide(); $("#titleLayer2").hide(); $("#toolTipBox").hide(); };

schedule.showLayer = function(ln) {
	var o = this.scheduleData[ln];
	var fromBox = $("#tdBox"+o.fromDate).get(0);
	var toBox   = $("#tdBox"+o.toDate).get(0) || this.lastTdBox;
	var fromBoxPos = getOffset(fromBox);
	var toBoxPos   = (fromBox.week == toBox.week) 
						? getOffset(toBox) 
						: getOffset($(fromBox.parentNode).find("td:last-child"));
	var liBoxPos   = getOffset(o.li);
	// title 레이어 절대 위치 값
	var titleLayerTop   = liBoxPos.top;
	var titleLayerLeft  = liBoxPos.left;
	var titleLayerWidth = toBoxPos.left + toBoxPos.width - liBoxPos.left;
	var div = document.getElementById("titleLayer"); 
	if(!div) {
		div = document.createElement("div");
		div.id = "titleLayer";
		document.body.appendChild(div);
	}
	div.style.position = "absolute";
	div.style.zIndex = 150;
	div.style.pixelTop = titleLayerTop;
	div.style.pixelLeft = titleLayerLeft;
	div.style.pixelWidth = titleLayerWidth;
	div.style.pixelHeight = 14;
	div.className = program[o.pramgramCode] + " ellipsis" ;
	div.innerText = o.title + " ~ " + o.toDate.substr(6, 2);
	div.style.fontSize = "11px";
	div.style.color = "#fff";
	div.style.padding = "4px 0 0 4px";
	div.style.display = "block";
	
	var div2 = document.getElementById("titleLayer2"); 
	if(!div2) {
		div2 = document.createElement("div");
		div2.id = "titleLayer2";
		document.body.appendChild(div2);
	}
	div2.style.display = "none";
	
	if(fromBox.week != toBox.week) {
		fromBox2Pos = getOffset($(toBox.parentNode).find("td:first"));
		toBox2Pos   = $("#tdBox"+o.toDate).get(0) 
						? getOffset(toBox) 
						: getOffset($(toBox.parentNode).find("td:last"));
		
		
		var titleLayer2Top   = fromBox2Pos.top + 23;
		var titleLayer2Left  = fromBox2Pos.left;
		var titleLayer2Width = toBox2Pos.left + toBox2Pos.width - fromBox2Pos.left;
		
		div2.style.position = "absolute";
		div2.style.zIndex = 150;
		div2.style.pixelTop = titleLayer2Top;
		div2.style.pixelLeft = titleLayer2Left;
		div2.style.pixelWidth = titleLayer2Width;
		div2.style.pixelHeight = 14;
		div2.className = program[o.pramgramCode] + " ellipsis" ;
		div2.innerText = "";
		div2.style.fontSize = "11px";
		div2.style.color = "#fff";
		div2.style.padding = "4px 0 0 4px";
		div2.style.display = "block";
	}
	
	var toolTipPos   = getOffset(this.toolTipLayer.box);
	toolTipPos.width = 276;
	var schedulePos  = getOffset("#scheduleLayer");
	var toolTipLayerTop, toolTipLayerLeft, toolTipLayerClass;
	toolTipLayerTop = liBoxPos.top - 162; //(liBoxPos.top - toolTipPos.height);
	// 툴립영역이 scheduleLayer 영역을 벗어나는 경우 scheduleLayer 오른쪽 영역에 위치 시킴.	
	if( (schedulePos.left + schedulePos.width) < (liBoxPos.left + toolTipPos.width) ) {
		toolTipLayerLeft = (schedulePos.left + schedulePos.width) - toolTipPos.width + 20;
	} else {
		toolTipLayerLeft = fromBoxPos.left;
	}
	if(fromBox.endWeekDay == "Y") {
		toolTipLayerClass = program[o.pramgramCode] + "Pop02";
	} else {
		toolTipLayerClass = program[o.pramgramCode] + "Pop01";
	}
	var fromDate = o.fromDate.substr(4,2) + "." + o.fromDate.substr(6,2);
	var toDate = o.toDate.substr(4,2) + "." + o.toDate.substr(6,2);
	this.toolTipLayer.title.innerHTML = o.title;
	this.toolTipLayer.info.innerHTML = o.period + "(기본 "+o.trainingTime+"H) / "+o.courseNum+"명<br />"+fromDate+" ~ "+toDate+" / 강사 " + o.teacher;
	this.toolTipLayer.summary.innerHTML = o.summary;
	this.toolTipLayer.popimg.src = o.img;
	this.toolTipLayer.link.href = "javascript:viewCourse('"+o.pramgramCode+"', "+o.courseId+");";
	
	this.toolTipLayer.box.style.pixelTop  = toolTipLayerTop;
	this.toolTipLayer.box.style.pixelLeft = toolTipLayerLeft;
	this.toolTipLayer.box.className = toolTipLayerClass;
	this.toolTipLayer.box.style.display = "block";
};

schedule.rebuildCalendar = function() {
	this.hideLayer();
	$(this.currentDateBox).text(schedule.currentYear + "." + checkDigit(this.currentMonth));
	this.createDateList();
	this.createCalendar();
	schedule.dataLoad();
	this.createTitle();
};

schedule.init = function(y, m) {
	if($("#scheduleLayer").get(0)) {
		$("#scheduleLayer").show();
	} else {
		schedule.currentYear = y || (new Date()).getFullYear();
		schedule.currentMonth = m || ((new Date()).getMonth() + 1);
		schedule.createLayer();
		schedule.createDateList();
		schedule.createCalendar();
		schedule.dataLoad();
		schedule.createTitle();
		schedule.createToolTip();
	}
	window.scrollTo(0,0);
};
(function(c){c.fn.menuModel1=function(a){function m(b,d,f){c.each(b,function(l){this._type=d;this._id=l+1;this._parent=f;c(">ul>li>a",this.parentNode).size()>0&&n(c(">ul>li>a",this.parentNode).get(),3,this._id)})}function n(b,d,f){c.each(b,function(l){this._type=d;this._id=l+1;this._parent=f})}function o(b,d,f){d=RegExp(eval("/"+d+"/g"));if(d.exec(b)!=null)b=b.replace(d,f);return b}function h(b,d,f){c(">img",b).length>0&&c(">img",b).attr("src",o(c(">img",b).attr("src"),d,f))}function i(b){a.visibled&& a.visibled._id!=b._parent&&e(a.visibled);a.subVisibled&&a.subVisibled._parent!=b._id&&e(a.subVisibled);c(b).addClass(a.activeClass);a.model==1&&a.parentYN&&h(b,a.imgOff,a.imgOn);c("+ul",b).css(a.showOps);a.visibled=b}function j(b){a.subVisibled&&e(a.subVisibled);c(b).addClass(a.activeClass);a.model==1&&a.childYN&&h(b,a.imgOff,a.imgOn);c("+ul",b).css(a.showOps);a.subVisibled=b}function k(b){a.ssubVisibled&&e(a.ssubVisibled);c(b).addClass(a.activeClass);a.model==1&&a.childYN&&h(b,a.imgOff,a.imgOn); a.ssubVisibled=b}function e(b){c(b).removeClass(a.activeClass);c("+ul",b).css(a.hideOps);a.model==1&&h(b,a.imgOn,a.imgOff)}var g=c(this);a=c.extend({model:1,parentYN:true,childYN:true,defaultLightMoveYN:true,target_obj:this,visibled:"",subVisibled:"",ssubVisibled:"",activeClass:"hover",showspeed:1E3,hidespeed:0,imgOn:"_on.gif",imgOff:".gif",showOps:{"visibility":"visible"},hideOps:{visibility:"hidden","fontsize":"0","background":"#fff"},hightLight:{level_1:0,level_1_obj:"",level_2:0,level_2_obj:"",level_3:0,level_3_obj:""}},a||{});(function(b){c.each(b, function(d){this._type=1;this._id=d+1;this._parent=-1;c(">ul>li>a",this.parentNode).size()>0&&m(c(">ul>li>a",this.parentNode).get(),2,this._id)})})(c(">li>a",g).get());(function(){g[0].getElementsByTagName("a");c.each(g[0].getElementsByTagName("a"),function(){switch(this._type){case 1:this.onmouseover=function(){i(this)};this.onfocus=function(){i(this)};break;case 2:this.onmouseover=function(){j(this)};this.onfocus=function(){j(this)};break;case 3:this.onmouseover=function(){k(this)};this.onfocus= function(){k(this)};break;default:break}if(this._type==1&&this._id==a.hightLight.level_1)a.hightLight.level_1_obj=this;else if(this._type==2&&this._parent==a.hightLight.level_1&&this._id==a.hightLight.level_2)a.hightLight.level_2_obj=this;else if(this._type==3&&this._parent==a.hightLight.level_2&&this._id==a.hightLight.level_3)a.hightLight.level_3_obj=this})})();(function(){if(a.hightLight.level_1){c.each(g[0].getElementsByTagName("a"),function(){e(this)});if(a.hightLight.level_1_obj){i(a.hightLight.level_1_obj); if(a.hightLight.level_2_obj){j(a.hightLight.level_2_obj);a.hightLight.level_3_obj&&k(a.hightLight.level_3_obj)}}}else c.each(g[0].getElementsByTagName("a"),function(){e(this)})})();(function(){c(a.target_obj).hover(function(){},function(){if(a.visibled){e(a.visibled);if(a.hightLight.level_1_obj){i(a.hightLight.level_1_obj);if(a.subVisibled){e(a.subVisibled);if(a.hightLight.level_2_obj){j(a.hightLight.level_2_obj);if(a.ssubVisibled){e(a.ssubVisibled);k(a.hightLight.level_3_obj)}}}}}})})()}})(jQuery);
function goMain(){location.href=SITE_URL;};
function loginOut() { $.ajax({ url:"/member/loginOut.do", success:function(data) { goMain(); } }); }
function goLogin() { location.href = SSL_URL + "/member/login/" + "?rurl=" + encodeURIComponent(location.href); }
function isLogin() { var b = false; $.ajax({ url:"/member/isLogin.do", async:false, dataType:'json', success:function(data) { b = data.isLogin; } }); return b; }
function loginCheck(msg) { if(!isLogin()){ if(msg) { alert("로그인 세션이 종료 되었습니다.\n로그인 후 다시 이용해주세요.");} goLogin(); return false; } return true; }
function authLink(url) { if(isLogin()){ location.href = url; } else { location.href = SSL_URL + "/member/login/" + "?rurl=" + encodeURIComponent(url); } }
function getProgramLink(p) { if(p == "EP10" || !p) { return "/education/base/"; } else if(p == "EP20") { return "/education/leadership/"; } else if(p == "EP30") { return "/education/specialization/"; } }
function listProgram(p) { location.href = SITE_URL + getProgramLink(p); }
function appCourse(p, c, s) { s = s || 0; location.href = SSL_URL + getProgramLink(p) + "app.html?cid=" + c + "&sid=" + s; }
function viewCourse(p, c) { location.href = SITE_URL + getProgramLink(p) + "view.html?courseId="+c; }
var headerData = "";
function setHeader(m, s) { $("#header").html(headerData);   $('#gnb').menuModel1({ hightLight : { level_1 : m, level_2 : s, level_3 : 0 }, target_obj : '#header', showOps : { visibility : 'visible' }, hideOps : { visibility : 'hidden' } });}
function headerLoad(m, s) {if(!headerData) {$.ajax({url: "/edu/courseInfo.do?m="+m+"&s="+s,dataType:'html',success: function(response){headerData = response;setHeader(m, s);},error: function(status, text) {  }});} else {setHeader(m, s);}}
function gnbLoad(m, s, no) { headerLoad(m, s); }
function programLoad(m, s, no) { location.href = SITE_URL + "?m="+m+"&s="+s+"&infoId="+no; }
function lnbMenu() { var lastEvent = null; var slide  = "#lnb > li > ul"; var alink  = "#lnb > li > a"; function accordion(){ if (this == lastEvent) return false; lastEvent = this; setTimeout(function() {lastEvent = null;}, 400); if ($(this).attr('class') != 'active') { $(slide).slideUp(); $(this).next(slide).slideDown(); $(alink).removeClass('active'); $(this).addClass('active'); } else if ($(this).next(slide).is(':hidden')) { $(slide).slideUp(); $(this).next(slide).slideDown(); } else { /* $(this).next(slide).slideUp(); */ } } $(alink).click(accordion).focus(accordion); $('#lnb > li:last > a').addClass('stay'); $("#lnb").find("a[lnb1='on']").click(); $("#lnb").find("a[lnb2='on']").addClass("on"); $("#lnb").hover( function(){}, function(){ $("#lnb").find("a[lnb1='on']").click(); } ); }
function sendSns(s) {var title = $("#pageTitle").text();var link = location.href;if(s == "twitter") {var url = "http://twitter.com/share?text=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(link);window.open(url, "twitter", "width=820,height=350,scrollbars=no,resizable=no");} else if(s == "facebook") {var url = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(link) + "&t=" + encodeURIComponent(title);window.open(url, "");} else if(s == "me2day") {title = "\"" + title + "\":"+link;var url = "http://me2day.net/posts/new?new_post[body]=" + encodeURIComponent(title);window.open(url, "");}}
$(document).ready(function(){
	gnbLoad(1,1,0);
	lnbMenu();
	inputStyle();
	$("#lnbSchedule").load("/edu/scheduleList.do");
});

