$(document).ready(function() {
	div_Tooltip		=  "<div id='div_Tooltip' style='vertical-align: middle'><table border=0 cellspacing=0 cellpadding=0><tr><td align=right colspan=5><img id=BtnMypin src=/images/mypin_up.gif class=cursor>&nbsp;&nbsp;<img id=BtnClose_div_Tooltip src=/tpcourse/btn_close.gif></td></tr><tr>    <td width=12 height=12><img src=../include/skin/table/heavy_blue_round/1_1.gif height=12 width=12 border=0></td>	<td background=../include/skin/table/heavy_blue_round/1_2.gif></td>	    <td width=12><img src=../include/skin/table/heavy_blue_round/1_3.gif height=12 width=12 border=0></td>	</tr><tr>    <td width=12 background=../include/skin/table/heavy_blue_round/2_1.gif></td>		    <td style=padding:0px  bgcolor=#FFFFFF>		         <table width=100% cellpadding=0 cellspacing=0 border=0>             <tr><td>			 <div id=div_ClassDetail  style='vertical-align:middle' ></div>             </td></tr>         </table>    </td>	<td width=12 background=../include/skin/table/heavy_blue_round/2_3.gif></td>	</tr><tr>		    <td width=12 height=12><img src=../include/skin/table/heavy_blue_round/3_1.gif height=12 width=12 border=0></td>		<td background=../include/skin/table/heavy_blue_round/3_2.gif></td>			<td width=12><img src=../include/skin/table/heavy_blue_round/3_3.gif height=12 width=12 border=0></td></tr></table></div>";
	div_Loading	=	"<div class='loading' style='display:none'><img src='/images/loading.gif'></div>";
	notAssigned	=	 '<span class=notAssigned>미배정</span>';
	btnEnroll			=	"<img id=btnEnroll src=/images/btn_ok.gif class=cursor>";

	$("body").append(div_Tooltip);
	$('#div_ClassDetail').addClass('ClassDetail');
	$('#div_Tooltip').addClass('Tooltip');
    divTooltip('hide');
	$('#BtnMypin').addClass('pinUp');
	$('#btnSaveClassManually').addClass('cursor');
	showCourseSubMenu(1);		// 교육안내 메뉴에서 첫번째 서브메뉴만 보이도록 함
	showExamSubMenu(1);		// 시험안내 메뉴에서 첫번째 서브메뉴만 보이도록 함
	showCenterSubMenu(1);		// 교육센터안내 메뉴에서 첫번째 서브메뉴만 보이도록 함
	showSurveySubMenu(1);		// 교육센터안내 메뉴에서 첫번째 서브메뉴만 보이도록 함
	showMyclassSubMenu(1);		// 강사용 myclass 메뉴에서 첫번째 서브메뉴만 보이도록 함

/*$('#test_number').change(function() {	// 시험신청에서 test-number 를 고르면 관련 항목(language, description) 을 바꾸어준다.
		testSeq		=		$(this).val();
		$.post('/tpcourse/change_test_number.php', {testSeq: testSeq}, function(data) {
//				alert(data);
				$('#test_description').val(data);
		});

});
*/

$('[name=showTeacher]').click(function() {	// 관리자용, 달력목록에서 강사보기 체크박스를 클릭하면,
		if ($(this).is(':checked'))  $('[name=divCalendarTeacher]').show();
		else	$('[name=divCalendarTeacher]').hide();
});

$('[name=showClassroom]').click(function() {	// 관리자용, 달력목록에서 강의장보기 체크박스를 클릭하면,
		if ($(this).is(':checked'))  $('[name=divCalendarClassroom]').show();
		else	$('[name=divCalendarClassroom]').hide();
});

$('[name=showEnrollCnt]').click(function() {	// 관리자용, 달력목록에서 신청자 수 보기 체크박스를 클릭하면,
		if ($(this).is(':checked'))  $('[name=divCalendarEnrollCnt]').show();
		else	$('[name=divCalendarEnrollCnt]').hide();
});

$('#paymentMethod').change(function() {	// 교육, 시험 신청시 결재방법에 '쿠폰' 을 선택하면 voucher number를 입력하도록 함.
	if ($('#paymentMethod :selected').text() == '쿠폰') {
		$('#TD_voucher_number').show();
	}
	else
		$('#TD_voucher_number').hide();
	
});

$('#btnApplyCourse').click(function() {	// 수강신청 폼에서 "수강신청" 버튼을 클릭하면, 결재방법이 "쿠폰" 인 경우 voucher 란에 값을 넣었는지 check
	if ($('#paymentMethod :selected').text() == '쿠폰') {
		if ($('#voucher_number').val() == ''){
			$('#voucher_number').focus();
			alert('voucher number를 입력하세요.')
			return false;
		}
	}
});

$('#btnEducationInfo').click(function() {
	//AAA
});
$('#teacher_seq').change(function() {	//	강사용 나의강의실에서 선생님선택이 바뀌면 해당 선생님이 강의하는 과목리스트만 보이도록 함.
		teacher_seq		=		$('#teacher_seq :selected').val();
		ack = $.ajax(    // 
				{
			        url: '/tpcourse/makeCourseList.php',
					type: "POST",
					data: ({teacher_seq: teacher_seq}),
					async: false
			    }).responseText;

//		alert(ack);
		$('#courseFromTeacher').html(ack);
		$('#courseFromTeacher').trigger('change');

});

$('#courseFromTeacher').change(function() {
		teacher_seq		=		$('#teacher_seq :selected').val();
//		alert($(this).val());
		if ($(this).val()	==	'')		return false;
		courseSeq		=		$('#courseFromTeacher :selected').val();
		$.post('/tpcourse/makeCourseScheduleList.php', {courseSeq: courseSeq, teacher_seq: teacher_seq}, function(data) {
//				alert(data);
				$('#courseScheduleFromCourseList2').html(data);
		});
		
});

$('#courseScheduleFromCourseList').change(function() {	 // 원래 이 필드는 relation_serial_1 으로 검색용이었으나, 같은 relation_serial_1 이 2개 이상 있으면 검색이 안되므로 사용자필드로 만들고 change 시 hidden 의 relation_serial_1에 값을 넘겨주고 검색토록 함. 문제는 조회 후 relation_serial_1 에 값이 게속 남아 있어서 조건없이 조회 할 때 문제가 될 수 있다.
				$('#classForAll').val($('#courseScheduleFromCourseList :selected').val());		
});
$('#courseScheduleFromCourseList2').change(function() {  // 원래 이 필드도 relation_serial_1 으로 검색용이었으나, 같은 relation_serial_1 이 2개 이상 있으면 검색이 안되므로 사용자필드로 만들고 change 시 hidden 의 relation_serial_1에 값을 넘겨주고 검색토록 함. 문제는 조회 후 relation_serial_1 에 값이 게속 남아 있어서 조건없이 조회 할 때 문제가 될 수 있다.
				$('#classForAll').val($('#courseScheduleFromCourseList2 :selected').val());		
});

$('#courseFromCategory').change(function() {
		courseSeq		=		$('#courseFromCategory :selected').val();
		$.post('/tpcourse/makeCourseScheduleList.php', {courseSeq: courseSeq}, function(data) {
//				alert(data);
				$('#courseScheduleFromCourseList').html(data);
		});
		
});

$('[name^=category_]').change(function() {	 // 분류에서 category_ 가 change되면 과정명 select list 만들기
		var	seq = $(this).attr('name').substr(Number($(this).attr('name').lastIndexOf('_')) + 1);
		var	category_1		=		'';
		var	category_2		=		'';
		if (seq		==		11)	{
				category_1		=		$('[name=category_11] :selected').val();
				category_2		=		'';
		}
		else if (seq		==		22)	{
				category_1		=		$('[name=category_11] :selected').val();
				category_2		=		(category_1=='')?'':$('[name=category_22] :selected').val();
		}
//		alert(seq+'##'+category_1+'##'+category_2);
		ack = $.ajax(    // 
				{
			        url: '/tpcourse/makeCourseList.php',
					type: "POST",
					data: ({category_1: category_1, category_2: category_2}),
					async: false
			    }).responseText;

//		alert(ack);
		$('#courseFromCategory').html(ack);
		$('#courseFromCategory').trigger('change');
});

$('#btnPrevWeek').click(function() {		//  관리자 -> ILT일정관리에서 검색시, 시작일을 편리하게 입력하기 위해 "지난주" 버튼을 클릭하면
		mydate							=		new Date();
		today								=		mydate.getDay();
		firstDayOfTheWeek		=		mydate.getDate();
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getYear();
if (year < 2000)
year = year + 1900;
var offset = today.getDay();
var week;

if(offset != 0) {
day = day - offset;
if ( day < 1) {
if ( month == 1) day = 31 + day;
if (month == 2) day = 31 + day;
if (month == 3) {
if (( year == 00) || ( year == 04)) {
day = 29 + day;
}
else {
day = 28 + day;
   }
}
if (month == 4) day = 31 + day;
if (month == 5) day = 30 + day;
if (month == 6) day = 31 + day;
if (month == 7) day = 30 + day;
if (month == 8) day = 31 + day;
if (month == 9) day = 31 + day;
if (month == 10) day = 30 + day;
if (month == 11) day = 31 + day;
if (month == 12) day = 30 + day;
if (month == 1) {
month = 12;
year = year - 1;
}
else {
month = month - 1;
      }
   }
}

fromDate				=		week = year + "-" + js_lpad(month,2,'0') + "-" + js_lpad(day,2,'0');
toDate					=		fromDate + 1;
		alert(week+'##');

});

 
$('#btnThisWeek').click(function() {		//  관리자 -> ILT일정관리에서 검색시, 시작일을 편리하게 입력하기 위해 "금주" 버튼을 클릭하면
//		common_fns_inside('href', 'http://$root?design_file=34060.php&SCH_open_date_1=$date_this_week[0]&SCH_open_date_2=$date_this_week[1]');
		date_this_week		=	new Array(2);
		date_this_week[0]	=	getYear()+js_lpad(getMonth()+1,2,'0')+getDate();
		date_this_week[1]	=	'';
//		location.href	=	'http://work3u.abuilder.kr?design_file=34060.php&SCH_open_date_1='+date_this_week[0]'+&SCH_open_date_2='+date_this_week[1];
});

$('#btnMainSurvey').click(function() {		//  사용자 -> 나의강의실 버튼을 클릭하면.
		if (common_fns_inside('is_login')  != '1') 	{
			alert ('로긴 후 이용 할 수 있습니다');
			return false;
		}
});

$('#btnCourseSub_4').click(function() {		//  사용자 -> 수강신청확인 버튼을 클릭하면.
		$('#btnMainSurvey').trigger('click');
});

$('[id^=btnDoSurvey_]').click(function() {		//  사용자 -> 나의수강이력보기 화면에서 설문하기 버튼을 클릭하면.
		var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		classSeq			=			$('#classSeq_'+seq).val();		// 과정seq
		participantSeq	=		$('#participantSeq_'+seq).val();		// 수강자seq
		courseName	=			$('#courseName_'+seq).text();	 // 과정명
		openDate		=			$('#openDate_'+seq).text();		// 과정시작일
		email				=			$('[name=email]').val();				//$('#email_'+seq).val();				// 이메일
		phone_3			=			$('[name=phone_3]').val();			//$('#phone_3_'+seq).val();		// 휴대전화
		etc_4				=			$('[name=biz_company]').val();	//$('#company_'+seq).val();				// 회사명
		etc_6				=			$('[name=address]').val();			//$('#address_'+seq).val();				// 주소
		writer_name	=			$('[name=mb_name]').val();		//$('#writer_name_'+seq).val();				// 작성자(수강자)
		mb_serial_num		=			$('[name=mb_serial_num]').val();			//$('#user_id_'+seq).val();				// 회원seq
//		alert(participantSeq+'#'+mb_serial_num+'#classid='+classSeq);
		$.post('/tpcourse/surveyAnswer.php', {participantSeq: participantSeq, classSeq: classSeq, courseName: courseName, openDate: openDate, 
			email: email, phone_3: phone_3, etc_4: etc_4, etc_6: etc_6, writer_name: writer_name}, function(data) {
				$('#survey_content').html(data);
		});
		showSurveySubMenu(3);
/*		$('#surveyCourse').val($('#classSeq_'+seq).text());
		$('#surveyOpenDate').val($('#openDate_'+seq).text());
		$('#btnSurveySub_3').trigger('click');
*/
});

$('[id^=surveyDate_]').each(function() {		// 사용자에서 나의수강이력보기 중 설문이 안된 과정에 "설문하기"버튼 보이도록 함.
																		// 단, 신청상태가 "수강중" 이고, 오늘 날자가 수강기간내 있어야 한다.
		var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		var	mydate							=		new Date();
		var	today								=		String(mydate.getFullYear()).substr(2)+'.'+js_lpad(mydate.getMonth()+1, 2, '0')+'.'+js_lpad(mydate.getDate(), 2, '0');
//		alert(seq+'#'+$('#openDate_'+seq).text()+'#'+$('#closeDate_'+seq).text()+'#'+today);
/*					$('#btnDoSurvey_'+seq).show();
					$('#enrollStatus_'+seq).css({'color':'blue'}).text('수강중');
*/
		if ($('#enrollStatus_'+seq).text()	!=	'신청중'  && $(this).text()	==	'' && $('#closeDate_'+seq).text() == today)	{ // 수업 마지막날이면 "설문하기" 보임
					$('#btnDoSurvey_'+seq).show();
					$('#enrollStatus_'+seq).css({'color':'blue'}).text('수강중');
		}
		else if ($('#enrollStatus_'+seq).text()	!=	'신청중' && $(this).text()	==	'' && $('#openDate_'+seq).text() <= today && $('#closeDate_'+seq).text() >= today)	{ // 수업 마지막날이 아니면 "설문대기" 보임
					$('#btnWaitSurvey_'+seq).show();
					$('#enrollStatus_'+seq).css({'color':'blue'}).text('수강중');
		}

	if ($('#openDate_'+seq).text() >= today)	{	// 아직 수업시작 전이면 취소 가능
					$('#btnEnrollCancel_'+seq).show();
	}
});

$('[id^=exam_openDate_]').each(function() {		// 사용자에서 나의 "시험" 이력보기에서 시험 날자가 지나지 않았을 때에만 "취소" 버튼이 보이도록 함.
		var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		var	mydate							=		new Date();
		var	today								=		String(mydate.getFullYear()).substr(2)+'.'+js_lpad(mydate.getMonth()+1, 2, '0')+'.'+js_lpad(mydate.getDate(), 2, '0');
		if ($(this).text() >= today)	{	// 아직 시험시작 전이면 취소 가능
					$('#btnExamCancel_'+seq).show();
		}
//		alert($('#exam_openDate_'+seq).text());

});

	$('#surveyType').change(function() {	 // 설문에서 유형 select 를 고르면 (선다형, 주관식 등)
						showhideAllChoiceTR();

	});

	$('[name=surveyCopyFrom]').change(function() {	 // 설문에서 보기항목 복사하기 select 를 고르면
				choiceCnt		=		$(this).val().substr(0, $(this).val().indexOf('`'));
				fromPos			=		$(this).val().indexOf('`')+1;
				toPos				=		$(this).val().indexOf('`', fromPos);
				betweenLength					=		toPos - fromPos;
				for (i=1; i <= choiceCnt; i++ )	{
//					alert('fromPos=>'+fromPos+'  betweenLength=>'+betweenLength);
							fromValue		=		$(this).val().substr(fromPos, betweenLength);
							$('[name=BDU_choice'+i+'_text]').val(fromValue);
							fromPos					=		toPos+1;
							toPos						=		$(this).val().indexOf('`', toPos+1);
							betweenLength		=		$(this).val().indexOf('`', toPos) - fromPos;
				}
				$('#surveyChoiceCnt').val($(this).text().substr($(this).text().lastIndexOf(':') + 1));
	});
	
	$('#surveyChoiceCnt').change(function() {	 // 설문에서 보기항목수를 선택하는 select 박스가 변경되면 항목수만큼 보기입력 row 를 보여준다.
				$('[id^=TR_surveyChoice_]').each(function() {
							if ($('#surveyChoiceCnt :selected').val() >= Number($(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1))) {
									$(this).show();
							}
							else {
									$(this).hide();
							}
				});
	});

	$('#adminCourseSub4_1').click(function() {	 // 관리자 과정관리 메뉴에서 ILT일정보기(달력) 서브메뉴의 컨텐트를 ajax로 call 한다.	
				$.get('/insiter.php', {design_file:'34069.php'}, function(data) {
							$('#admin_content').html(data);
				});	
	});

	$('#adminCourseSub4_2').click(function() {	 // 관리자 과정관리 메뉴에서 ILT일정보기(달력) 서브메뉴의 컨텐트를 ajax로 call 한다.	
				$('#admin_content').hide()
				$.get('/insiter.php', 
						{design_file:'34105.php'}, function(data) {
								$('#admin_content').html(data).fadeIn('slow');
					});	
	});

/*	$('#adminSurveySub_1').click(function() {	 // 관리자 과정관리 메뉴에서 설문 작성메뉴 클릭	Ajax 사용하려고 했는데 안함.
				$.get('/insiter.php', 
						{design_file:'34151.php'}, function(data) {
								$('#admin_content').html(data);
				});	
	});
*/
	$('#myclass_writer_name').click(function() {	 // 강사의 myclass에서 학생목록에서 한 학생을 클릭하면 실행.
			if ($('#TD_myclassSub_1').css('display')		!=	'none')	{	//	수강생목록보기중이었으면
					$('#writer_nameSelectStudentList').val($(this).val());
					$('#btnSelectStudentList').trigger('click');
			}
			else if ($('#TD_myclassSub_2').css('display')	!=	 'none')	{		// 수강생상세보기 중이었으면
/*					serial_num		=		$('#serial_num').val();
					$('#btnStudentDetail').trigger('click');
					$.get('http://work3u.abuilder.kr/insiter.php', 
						{design_file:'34099.php', article_num: serial_num}, function(data) {
								$('#TD_myclassSub_2').html(data);
					});
					showMyclassSubMenu(2);*/
			}
	});

	$('#btnShowStdList').click(function() {	 // 강사의 myclass에서 학생목록보기 체크박스를 클릭하면 실행.
			if ($(this).is(':checked')) {
					$('.TD_showStdList').fadeIn();
			}
			else	 $('.TD_showStdList').fadeOut();
	});

	$('#chooseFromCalendar').click(function() {	 // 수강신청 시 달력에서고르기를 클릭하면 실행.
			$('#btnCourseSub_1').trigger('click');
	});

	$('#chooseFromExamCalendar').click(function() {	 // 시험신청 시 달력에서고르기를 클릭하면 실행.
			$('#btnExamSub_1').trigger('click');
	});
	
	$('[id^=btnEnroll_]').live('click', function() {		// 교육안내 --> 교육일정(달력)에서 신청 버튼을 누르면
			if (common_fns_inside('is_login')  != '1') 	{
				alert ('로긴 후 수강신청을 할 수 있습니다');
				return false;
			}
			divTooltip('hide');
	       var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
//		   alert($('#calendarCourseSerial_num_'+seq).val());
			$('#btnCourseSub_3').trigger('click');
			$('#enrollClass').val($('#calendarCourseSerial_num_'+seq).val());	//relation_serial_1(수강신청테이블의 반(class) 항목)
			$('#courseName').val($('#calendarClassName_'+seq).text());
			$('#openDate').val($('#calendarOpenDate_'+seq).val());
			$('#closeDate').val($('#calendarCloseDate_'+seq).val());
	});

	$('[id^=btnEnrollExam_]').live('click', function() {		// 시험안내 --> 시험일정에서 신청 버튼을 누르면
			divTooltip('hide')
	       var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
			$('#btnExamSub_2').trigger('click');
			$('#enrollExam').val($('#calendarExamSerial_num_'+seq).val());
	});

	$('#BtnMypin').toggle(function(e) {
	      var src = ($(this).attr("src") === "/images/mypin_down.gif") 
		            ? "/images/mypin_up.gif"	: "/images/mypin_down.gif"; 
	      $(this).attr("src", src); 

		   var  x = $('#div_Tooltip').css('x');	//e.pageX;
		   var  y = $('#div_Tooltip').css('y');	//e.pageY;
		   $('#div_Tooltip').css({'left':x, 'top':y});
		   $(this).removeClass().addClass('pinDown'); },
		function() {
			var src = ($(this).attr("src") === "/images/mypin_down.gif") 
						? "/images/mypin_up.gif"  : "/images/mypin_down.gif"; 
			$(this).attr("src", src); 
			$(this).removeClass().addClass('pinUp');
	});

$('#menuCourseSchedule').click(function() {		// 관리자에서 교육일정 메뉴 클릭시 "교육일정" 서브메뉴로 가기
		$.get('/insiter.php', {design_file:'34069.php', OTSKIN:'layout_empty.php'}, function(data) {
				$('#admin_content').html(data);
		});
});

// insiter.php?design_file=34094.php&sub_bins=001

$('[id^=btnCourseSub_]').click(function() {	// 교육안내메뉴에서 서브메뉴를 클릭하면
		var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
/*		$.get('/insiter.php', {design_file:'34069.php', OTSKIN:'layout_empty.php'}, function(data) {
//				document.write(data);
				$('#div_courseSub').html(data);
		});*/
		if (seq	==	'3') {
				if (common_fns_inside('is_login')  != '1') 	{
				alert ('로긴 후 수강신청을 할 수 있습니다');
				return false;
				}
		}
		divTooltip('hide')
		showCourseSubMenu(seq);
});

$('[id^=btnSurveySub_]').click(function() {		// 강의평가및 설문메뉴에서 서브메뉴를 클릭하면
		var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		if (seq	==	'3') {		//  사용자에서 설문 서브메뉴클릭시
				$.post('/tpcourse/surveyAnswer.php', {}, function(data) {
						$('#survey_content').html(data);
				});
		}
		else		showSurveySubMenu(seq);
});

$('[id^=btnExamSub_]').click(function() {		// 시험안내메뉴에서 서브메뉴를 클릭하면
		var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		if (seq	==	'2') {
				if (common_fns_inside('is_login')  != '1') 	{
				alert ('로긴 후 시험신청을 할 수 있습니다');
				return false;
				}
		}
		divTooltip('hide')
		showExamSubMenu(seq);
});

$('[id^=btnMycalssSub_]').click(function() {		// 강사의 myclass 메뉴에서 서브메뉴를 클릭하면
		var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		showMyclassSubMenu(seq);
});

$('[id^=btnCenterSub_]').click(function() {		// 교육센터소개메뉴에서 서브메뉴를 클릭하면
		var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		showCenterSubMenu(seq);
});

$('.course_table td').each(function() {
		if ($(this).text() == '')
		{
			$(this).html('&nbsp');
		}
   });

   $('*[id^=className_]').live('mouseover', function(e) {
	   alert('class name');
       var	seq					= $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
//	   alert(seq);
	   var	x						= e.pageX;
	   var	y						= e.pageY - $('#div_ClassDetail').css('height').replace('px','') - 20;
	   var	courseTitle		=  $(this).text();
	   var	classRoom		=  $('#classRoom_'+seq).val()?$('#classRoom_'+seq).val():notAssigned;
	   var	teacherName  =   $('#teacher_'+seq).val()?$('#teacher_'+seq).val():notAssigned;
       $('#div_ClassDetail').html('<strong>과목명</strong> : '+courseTitle+'<br> ---------------------<br><strong>강의장</strong> : '+classRoom+'<br> --------------------- <br><strong>강&nbsp;&nbsp;사</strong> : '+teacherName);
		$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
		$('#BtnMypin').removeClass('IsNotShow');
		$('#div_Tooltip').css({'left':x, 'top':y}).show();
    });

   $('*[id^=calendarClassNameShort_]').live('mouseover', function(e) { // 교육일정(달력)에서 과정명에 마우스를 올리면
       var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
//	   alert($('#calendarClassName_'+seq).val());
	   var  x						=		e.pageX + 10;
	   var  y						=		e.pageY - 230;
	   var  courseTitleShort  =		$(this).text();
	   var  courseTitle		=		$('#calendarClassName_'+seq).val()?$('#calendarClassName_'+seq).val():notAssigned;
	   var  classRoom			=		$('#calendarCourseSerial_num_'+seq).val()?$('#calendarCourseSerial_num_'+seq).val():notAssigned;
	   var  classRoom			=		$('#calendarClassRoom_'+seq).val()?$('#calendarClassRoom_'+seq).val():notAssigned;
	   var  teacherName		=		$('#calendarTeacher_'+seq).val()?$('#calendarTeacher_'+seq).val():notAssigned;
		var	open_date		=		$('#calendarOpenDate_'+seq).val()?$('#calendarOpenDate_'+seq).val():notAssigned;
		var	close_date		=		$('#calendarCloseDate_'+seq).val()?$('#calendarCloseDate_'+seq).val():notAssigned;
		var	enrollCnt		=		$('#calendarEnrollCnt_'+seq).val()?$('#calendarEnrollCnt_'+seq).val():'0';
		var	user_level		=		$('#calendarUserLevel_'+seq).val();
		var	lineLength		=		countLength(courseTitleShort) > 10?countLength(courseTitleShort)+19:10+19;
		var	user_level		=		$('#calendarUserLevel_'+seq).val();
		var	mydate			=		new Date();
		var	today				=		String(mydate.getFullYear())+'-'+js_lpad(mydate.getMonth()+1, 2, '0')+'-'+js_lpad(mydate.getDate(), 2, '0');

		divContent		  =	'<strong>과목명</strong> : '+courseTitleShort;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>강의장</strong> : '+classRoom;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>강&nbsp;&nbsp;사</strong> : '+teacherName;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>시작일</strong> : '+open_date;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>종료일</strong> : '+close_date;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
//		alert(close_date+'#'+today);
		if (user_level	==	0)	{	// 사용안하기 위해 0으로 설정, 원래는 1임. 유저레벨이 관리자면 수강신청 버튼대신에 수강신청현황을 보도록 한다.
				divContent		+=	'<strong>신청자</strong> : '+'<a href=insiter.php?design_file=34098.php&SCH_relation_serial_1='+$('#calendarCourseSerial_num_'+seq).val()+">"+enrollCnt.replace('(','').replace(')','')+"명</a>";
//				divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
//				divContent		+=	'<center>'+'<img id=btnViewDetail_'+seq+' src=/images/btn_detailview_list_over.gif class=cursor>'+'</center>';
				$('#calendarEnrollCnt_'+seq).show();
		}
		else if (close_date < today) // 이미 과정이 종료되었으면 "신청" 버튼이 보이지 않고 "과정 종료" 라고 표시 함.
		{
				divContent		+=	'<center>'+'과정종료'+'</center>';
				$('#calendarEnrollCnt_'+seq).hide();
		}
		else {
				divContent		+=	'<center>'+'<img id=btnEnroll_'+seq+' src=/images/btn_ok.gif class=cursor>'+'</center>';
				$('#calendarEnrollCnt_'+seq).hide();
		}

	   $('#div_ClassDetail').html(divContent);

//	   $('#div_ClassDetail').html('<strong>과목명</strong> : '+courseTitle+'<br> -------------------- <br><strong>강의장</strong> : '+classRoom+'<br /> -------------------- <br /><strong>강&nbsp;&nbsp;사</strong> : '+teacherName + '<br> -------------------- <br><strong>시작일</strong> : '+open_date + '<br> -------------------- <br><strong>종료일</strong> : '+close_date+ '<br> --------------------- <br><center>'+'<img id=btnEnroll_'+seq+' src=/images/btn_ok.gif class=cursor>'+'</center>');
//			$('#div_ClassDetail').addClass('ClassDetail');
			$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
			$('#BtnMypin').removeClass('IsNotShow');
			if	($('#BtnMypin').hasClass('pinUp'))	
						$('#div_Tooltip').css({'left':x, 'top':y, 'position':'absolute'});
			else		$('#div_Tooltip').css({'position':'absolute'});

			divTooltip('show');

    });
   $('*[id^=calendarClassNameShort_]').live('click', function(e) { // 교육일정(달력)에서 과정명을 클릭하면
//			showCourseSubMenu(5);

//{$root}insiter.php?design_file=34094.php&article_num={$Ref_value[courseSeq]}&sub_bins=004'
    });

   $('*[id^=calendarExamCode_]').live('mouseover', function(e) { // 시험일정(달력)에서 시험명에 마우스를 올리면
		var	seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
//	   alert($('#calendarClassName_'+seq).val());
		var	x								=		e.pageX + 10;
		var	y								=		e.pageY - 230;
		var	examTitleShort		=		$(this).text();
		var	examTitle				=		$('#calendarExamName_'+seq).val()?$('#calendarExamName_'+seq).val():notAssigned;
		var	examSerial				=		$('#calendarExamSerial_num_'+seq).val()?$('#calendarExamSerial_num_'+seq).val():notAssigned;
		var	examRoom				=		$('#calendarExamRoom_'+seq).val()?$('#calendarExamRoom_'+seq).val():notAssigned;
		var	examOpen_date	=		$('#calendarExamOpenDate_'+seq).val()?$('#calendarExamOpenDate_'+seq).val():notAssigned;
		var	examTime				=		$('#calendarExamTime_'+seq).val()?$('#calendarExamTime_'+seq).val():notAssigned;
		var	lineLength				=		countLength(examTitle) > 10?countLength(examTitle)+19:10+19;
		divContent		  =	'<strong>시험명</strong> : '+examTitle;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>시험장</strong> : '+examRoom;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>시험일</strong> : '+examOpen_date;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<strong>시험시간</strong> : '+examTime;
		divContent		+=	drawLine(lineLength, 1);		// <br /> tag를 포함하여 줄긋기
		divContent		+=	'<center>'+'<img id=btnEnrollExam_'+seq+' src=/images/btn_ok.gif class=cursor>'+'</center>';

	   $('#div_ClassDetail').html(divContent);
//			$('#div_ClassDetail').addClass('ClassDetail');
			$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
			$('#BtnMypin').removeClass('IsNotShow');
			if	($('#BtnMypin').hasClass('pinUp'))	
						$('#div_Tooltip').css({'left':x, 'top':y, 'position':'absolute'});
			else		$('#div_Tooltip').css({'position':'absolute'});

			divTooltip('show');

    });

	$('#div_Tooltip').mouseover(function() {
					$('#div_Tooltip').css('cursor', 'pointer');
	});

	$('#div_Tooltip').mousedown(function() {
					drag_layer(0,event, 'div_Tooltip');
	});

	$('#div_Tooltip').mouseup(function() {
			stop_layer();
	});

   $('*[id^=openday_]').live("click", function(e) {	// ILT일정보기(연간) 에서 각 월의 cell 에 있는 일정 날자를 클릭하면 해당일정을 수정할 수 있는 popup 출력
																				// 쓰기 폼을 함께 사용하고, 버튼이름만 "수정" 으로 고쳐서 사용함
       var  seq					=		$(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
       var  TDseq				=		$(this).parent().attr('id').substr(Number($(this).parent().attr('id').lastIndexOf('_')) + 1);
	   var  x							=		e.pageX;
	   var  y							=		e.pageY - $('#div_ClassDetail').css('height').replace('px','') - 20;
	   var  classroomID		=		$('#classroomID_'+seq).val();
	   var  classRoom		=		$('#classRoom_'+seq).val()?$('#classRoom_'+seq).val():'';
	   var  teacherID			=		$('#teacherID_'+seq).val();
	   var  teacherName	=		encodeURI($('#teacher_'+seq).val()?$('#teacher_'+seq).val():'미배정');
   		var  courseId			=		$('#courseId_'+seq).val();
	   var  courseTitle		=		encodeURI($('#courseName_'+seq).val());
		var  pos					=		popupPosition(e.pageX, e.pageY, 250, 200);
//		var  popupStyle		=		"top="+pos[1]+" ,left="+pos[0]+" ,width=250,height=200 ,resizable=yes"
		var  popupStyle		=		"dialogTop:"+pos[1]+"px ;dialogLeft:"+pos[0]+"px ;dialogWidth:350px;dialogHeight:300px ;resizable=yes"

		var  open_date		=		$('#open_date'+seq).val()?$('#open_date'+seq).val():'null';
		var  close_date		=		$('#close_date'+seq).val()?$('#close_date'+seq).val():'null';
		var  classSerialNum =	$('#classSerialNum_'+seq).val();
		var	open_date_ym			=		open_date.substr(0,7).replace('-','');

//       $('#div_ClassDetail').html('<strong>과목명</strong> : '+courseTitle+' <br> ---------------------<br><strong>강의장</strong> : '+classRoom+' <br> --------------------- <br><strong>강&nbsp;&nbsp;사</strong> : '+teacherName + ' <br> --------------------- <br><strong>시작일</strong> : '+open_date + '<br> --------------------- <br><strong>종료일</strong> : '+close_date);
//       $('#div_Tooltip').css({'left':x, 'top':y}).show();

			openerWindowWidth			=		$(window).width();
			openerWindowHeight		=		$(window).height();

/*			$.get('/insiter.php', {design_file:'34085.php', dml: 'update', courseId: courseId, classroomID: classroomID, teacherID: teacherID, teacherName: teacherName, TDseq: TDseq, 
				courseTitle: courseTitle, open_date: open_date, classSerialNum: classSerialNum, seq: seq, open_date_ym: open_date_ym, 
				close_date: close_date, openerWindowWidth: openerWindowWidth, openerWindowHeight: openerWindowHeight}, function(data) {
					$('#div_ClassDetail').html(data);
			});
	       $('#div_Tooltip').css({'left':x, 'top':y}).show(); */

//       $('#div_Tooltip').hide();
//			window.open ("http://work8.abuilder.kr/insiter.php?design_file=34086.php&serial_num="+courseId+"&courseId="+courseId+"&courseTitle="+courseTitle+"&open_date="+open_date+"&close_date="+close_date, "modifyWindow", popupStyle); 
			//e.preventDefault();
//			return false;

			divTooltip('hide');
			ModalDialog	=	window.showModalDialog ("/insiter.php?design_file=34085.php&dml=update"+"&courseId="+courseId+
				"&courseTitle="+courseTitle+"&classroomID="+classroomID+"&teacherID="+teacherID+"&teacherName="+teacherName+"&TDseq="+TDseq+
				"&open_date="+open_date+"&close_date="+close_date+"&classSerialNum="+classSerialNum+"&seq="+seq+"&open_date_ym="+open_date_ym+
				"&close_date="+close_date+"&openerWindowWidth="+openerWindowWidth+"&openerWindowHeight="+openerWindowHeight,
				window, popupStyle); 

			return false;
});

   $('*[id^=openday_]').live('mouseover', function(e) {  
       var	seq					=		$(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
	   var  x							=		e.pageX + 10;
	   var  y							=		e.pageY - 230;
	   var  courseTitle		=		$('#courseName_'+seq).val();
	   var  classRoom		=		$('#classRoom_'+seq).val()?$('#classRoom_'+seq).val():notAssigned;
	   var  teacherName	=		$('#teacher_'+seq).val()?$('#teacher_'+seq).val():notAssigned;
		var	open_date				=		$('#open_date'+seq).val()?$('#open_date'+seq).val():notAssigned;
		var	close_date				=		$('#close_date'+seq).val()?$('#close_date'+seq).val():notAssigned;
		$(this).addClass('cursor');
       $('#div_ClassDetail').html('<strong>과목명</strong> : '+courseTitle+'<br> ---------------------<br><strong>강의장</strong> : '+classRoom+'<br> --------------------- <br><strong>강&nbsp;&nbsp;사</strong> : '+teacherName + '<br> --------------------- <br><strong>시작일</strong> : '+open_date + '<br> --------------------- <br><strong>종료일</strong> : '+close_date);
//			$('#div_ClassDetail').addClass('ClassDetail');
		$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
		$('#BtnMypin').removeClass('IsNotShow');
		if	($('#BtnMypin').hasClass('pinUp'))	{$('#div_Tooltip').css({'left':x, 'top':y}); }
		divTooltip('show');

});

   $('#BtnClose_div_Tooltip').click(function() {
         divTooltip('hide');
    });

   $('#seq').click(function() {
		window.dialogArguments.$('#calendarTD_'+$('#seq').val()).load('/tpcourse/refreshCalendarTD.php');
   });
   
   $('#TDSeq').click(function() {
	   alert($('#TDSeq').val());
   });
   $('#btnSaveClass').click(function() {
		$.post('/tpcourse/refreshCalendarTD.php', {courseId: $('#courseId').val(), courseTitle: $('#view_courseTitle').val(), open_date_ym: $('#open_date_ym').val(), seq:$('#seq').val()}, function(data) {
//				alert(data);
						window.dialogArguments.$('#calendarTD_'+$('#seq').val()).html(data);
		});

//		window.dialogArguments.$('#calendarTD_'+$('#seq').val()).load('/tpcourse/refreshCalendarTD.php');

    });
   $('#btnSaveClassManually').click(function() {	// insert 또는 update 에 모두 쓰이는 버튼을 클릭하면 실행
		var	openYMD				=		$('[name=open_date_year]').val()+js_lpad($('[name=open_date_month]').val(), 2, '0')+js_lpad($('[name=open_date_day]').val(), 2, '0');
		var	closeYMD				=		$('[name=close_date_year]').val()+js_lpad($('[name=close_date_month]').val(), 2, '0')+js_lpad($('[name=close_date_day]').val(), 2, '0');
		var	writer_id					=		'wams_work3u';
		var	relation_table_1		=		'BD34033';
		var	courseId					=		$('#courseId').val();
		var	classroomID			=		$('#classroomID').val();
		var	teacherID				=		$('#teacherID').val();
		var	dml							=		$('#dml').val();
		var	open_date_ym		=		$('#open_date_ym').val();
		var	classSerialNum		=		$('#classSerialNum').val();  // 60테이블(반)의 serial_num

//		alert(classroomID+'==='+teacherID);
		$.post('/tpcourse/refreshCalendarTD.php', 
			{dml: dml, courseId: courseId, courseTitle: $('#view_courseTitle').val(), 
					open_date_ym: open_date_ym, 
					seq: $('#seq').val(), TDseq: $('#TDseq').val(), classSerialNum: classSerialNum,
					openYMD: openYMD, closeYMD: closeYMD, writer_id: writer_id, 
					relation_table_1: relation_table_1, classroomID: classroomID, teacherID: teacherID},  function(data) {
//							if (data.substr(0,3)	 ==	'<td')
//							{
									displayDivOpener(dml+'Success', $('#openerWindowWidth').val(),  $('#openerWindowHeight').val());
									window.dialogArguments.$('#calendarTD_'+$('#TDseq').val()).html(data);
									window.close();   // 이 문장을 $.post 밖에 기술하면 window는 close 되지만 $.post 의 작업이 정상적이지 않는다.
//							}
//							else {
//									alert(data);
//							}
		});


//		window.dialogArguments.$('#calendarTD_'+$('#seq').val()).load('/tpcourse/refreshCalendarTD.php');

    });

   $('#btnDeleteClass').click(function() {
		if(confirm('해당 class(반)을 삭제하시겠습니까?')) {
			var	classSerialNum		=		$('#classSerialNum').val();  // 60테이블(반)의 serial_num
			var	dml							=		'delete';
			var	relation_serial_1		=		$('#relation_serial_1').val();   // course의 ID값 60테이블의 relation_serial_1에 해당
			var	open_date_ym		=		$('#open_date_ym').val();
			var	courseId					=		$('#courseId').val();
			var	courseTitle				=		encodeURI($('#view_courseTitle').val());

//			alert(classSerialNum+'--'+relation_serial_1+'--'+open_date_ym+'--'+$('#TDseq').val());

			$.post('/tpcourse/refreshCalendarTD.php', 
				{dml: dml, classSerialNum: classSerialNum,  courseTitle: courseTitle, 
				seq: $('#Seq').val(), TDseq: $('#TDseq').val(), courseId: courseId, 
				relation_serial_1: relation_serial_1, open_date_ym: open_date_ym},  function(data) {
//							if (data.substr(0,3)	 ==	'<td')
//							{
									displayDivOpener('deleteSuccess', $('#openerWindowWidth').val(),  $('#openerWindowHeight').val());
									window.dialogArguments.$('#calendarTD_'+$('#TDseq').val()).html(data);
									window.close();   // 이 문장을 $.post 밖에 기술하면 window는 close 되지만 $.post 의 작업이 정상적이지 않는다.
//							}
//							else {
//									alert(data);
//							}
			});
//		window.close();
		}
    });

$('*[id^=calendarTD_]').live('click', function(e) {	// ILT일정보기(연간) 에서 각 월의 cell 을 클릭하면 신규일정을 등록할 수 있는 popup 출력
		seq							=		$(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
		TDseq						=		$(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);
//		alert('#divCalendarTd_'+seq);
//		alert($('#calendarTD_'+seq).html());
//		 $('#hiddenSeq').val(seq);
		var  x						=		e.pageX;	 
		var  y						=		e.pageY - $('#div_ClassDetail').css('height').replace('px','') - 20;
		var  pos					=		popupPosition(e.pageX, e.pageY, 250, 200);
		var  popupStyle		=		"dialogTop"+pos[1]+"px ;dialogLeft:"+pos[0]+"px ;dialogWidth:350px;dialogHeight:300px ;resizable=yes"
		var  courseId			=		$('#courseId_'+seq).val();
		var  courseTitle		=		encodeURI($('#courseName_'+seq).val());
		var  open_date		=		$('#open_date'+seq).val()?$('#open_date'+seq).val():'null';
		var  close_date		=		$('#close_date'+seq).val()?$('#close_date'+seq).val():'null';
		var	open_date_ym			=		open_date.substr(0,7).replace('-','');

		 //입력(insert) 용 팝업 또는 div display
				$('#div_ClassDetail').html('');
/*				$.ajax({ 
					type:	"GET", 
			        url:		"/insiter.php", 
			        data:	{design_file:'34085.php', courseId:courseId, courseTitle:courseTitle},
			        contentType: "text/html;charset=utf-8", 
			        dataType: "html", 
			        success: function(data) { $('#div_ClassDetail').html(data); }
				}); */

/*				$.get('/insiter.php', {design_file:'34085.php', courseId:courseId, courseTitle:courseTitle}, function(data) {
						$('#div_ClassDetail').html(data);
				});
		       $('#div_Tooltip').css({'left':x, 'top':y}).show(); */

			openerWindowWidth		=		$(window).width();
			openerWindowHeight		=		$(window).height();

			divTooltip('hide');
			ModalDialog	=	window.showModalDialog ("/insiter.php?design_file=34085.php&dml=insert"+"&courseId="+courseId+
				"&courseTitle="+courseTitle+"&open_date="+open_date+"&close_date="+close_date+"&seq="+seq+"&TDseq="+TDseq+"&open_date_ym="+open_date_ym+
				"&openerWindowWidth="+openerWindowWidth+"&openerWindowHeight="+openerWindowHeight,
				window, popupStyle); 
});

$('.designer_IB_text_onlyNumber').keypress(function(event) {		// 숫자만 입력해야 하는 필드에 부여된 class 에서 key press 가 발생하면 실행
																											// 보통 주민번호, 전화번호, 카드번호 등에 이 class 가 적용되어 있다.
		inputNumberOnly(event);
});
$('.onlyNumber').keypress(function(event) {		// 숫자만 입력해야 하는 필드에 부여된 class 에서 key press 가 발생하면 실행
																											// 보통 주민번호, 전화번호, 카드번호 등에 이 class 가 적용되어 있다.
		inputNumberOnly(event);
});

});	//document.ready 끝

	function yyyymmddType1(yyyymmdd) {
			return yyyymmdd.substr(0,4)+"."+yyyymmdd.substr(4,2)+"."+yyyymmdd.substr(6,2)+".";
	}

	function popupPosition(mouseX, mouseY, popupWidth, popupHeight) {
			var	pos		=		new Array(2);
			pos[0]			=		300;		//mouseX;
			pos[1]			=		mouseY - 100;
			return pos;
	}

	function displayDivOpener(type, windowWidth, windowHeight) {
			switch (type)
			{
			case 'insertSuccess': 
					$msg	=	"저장이 완료되었습니다";
					break;
			case 'updateSuccess': 
					$msg	=	"수정이 완료되었습니다";
					break;
			case 'deleteSuccess': 
					$msg	=	"삭제가 완료되었습니다";
					break;
			}

			whichDiv		=		window.dialogArguments.$('#div_Tooltip');
			//setCenter(whichDiv , windowWidth, windowHeight);

			whichDiv.addClass('centered');//css({'left':  (windowWidth - $msg.length)/2, 'top': (windowHeight- document.body.scrollTop)/2});
			window.dialogArguments.$('#div_ClassDetail').removeClass().addClass('ClassDetailSize2').html($msg);
			window.dialogArguments.$('#BtnClose_div_Tooltip').addClass('IsNotShow');
			window.dialogArguments.$('#BtnMypin').addClass('IsNotShow');
//			$('#div_Tooltip').addClass('centered');
			whichDiv.fadeIn('slow');
			whichDiv.fadeOut(2000);
//			where+$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
			window.dialogArguments.$('#div_ClassDetail').addClass('ClassDetail');
//			$('#BtnClose_div_Tooltip').removeClass('IsNotShow');
//			$('#BtnMypin').removeClass('IsNotShow');
	}


	/* 
 * 주어진 문자열의 왼쪽을 padding 문자로 채운다
 */



function js_lpad(str, n, padding)
{
	str = String(str);
    if (str.length >= n)
        return str;
    else
    {
        var len = n - str.length;
        var pad_str = str;
        for (var i=0; i<len; i++)
            pad_str = padding + pad_str;

        return pad_str;
    }
}
function setCenter(whichDiv, windowWidth, windowHeight) {
	var newX = (windowWidth - $(whichDiv).width())/2;
	var newY = (windowHeight - $(whichDiv).height())/2;
	whichDiv.css({'left': newX, 'top':newY});
}

function inputNumberOnly(e) {
	var code = (e.keyCode ? e.keyCode : e.which);
/*	if (code < 48 || code > 57) {    
		e.preventDefault();
	}*/
	 if ((code >= 48 && code <= 57) || (code == 13 || code == 37 || code == 38 || code == 39 || code == 40 || code == 8 || code == 109 || code == 46 || code == 189)) {return true; } 
	 else e.preventDefault();

}

function showCourseSubMenu(menu) {
	seq		=		1;
//	alert($('[id^=TD_courseSub]').length+'#');
	$('[id^=TD_courseSub]').each(function() {
//		alert(seq);
			if (seq		==		menu) {
					$('#TD_courseSub'+seq).fadeIn('slow');//show();
			}
			else {
					$('#TD_courseSub'+seq).hide();
			}
			seq++;
	});
}


function showExamSubMenu(menu) {
	seq		=		1;
	$('[id^=TD_examSub]').each(function() {
			if (seq		==		menu) {
					$('#TD_examSub'+seq).fadeIn('slow');//show();
			}
			else {
					$('#TD_examSub'+seq).hide();
			}
			seq++;
	});
}

function showSurveySubMenu(menu) {
	seq		=		1;
	$('[id^=TD_surveySub]').each(function() {
			if (seq		==		menu) {
					$('#TD_surveySub'+seq).fadeIn('slow');//show();
			}
			else {
					$('#TD_surveySub'+seq).hide();
			}
			seq++;
	});
}

function showMyclassSubMenu(menu) {
	seq		=		1;
	$('[id^=TD_myclassSub_]').each(function() {
			if (seq		==		menu) {
					$('#TD_myclassSub_'+seq).fadeIn('slow');//show();
			}
			else {
					$('#TD_myclassSub_'+seq).hide();
			}
			seq++;
	});
}

function showCenterSubMenu(menu) {
	seq		=		1;
	$('[id^=TD_centerSub]').each(function() {
			if (seq		==		menu) {
					$('#TD_centerSub'+seq).show();
			}
			else {
					$('#TD_centerSub'+seq).hide();
			}
			seq++;
	});
}

function divTooltip(mode) {
	if (mode	==	'show') {
			if ($('[name=showDivTooptip]').is(':checked')) {
					$('#div_Tooltip').show();
			}
			else	 {
					$('#div_Tooltip').hide();
			}
	}
	else	 {
			$('#div_Tooltip').hide();
	}
}

function divLoading(mode) {
		if (mode	==	'show') {
				$('#div_Loading').show();
		}
		else	 {
				$('#div_Loading').hide();
		}
}

function defaultEnrollStatus() {
		$.post('/tpcourse/defaultEnrollStatus.php', {}, function(data) {
			alert(data);
				$('#enrollStatus').val(data);
		});
}

function doScheduling() {  // 일정등록, 수정, 삭제 php 의 마지막에서 call 되는 함수.
		var  fm  =  document.TCBOARD_BD34060_WRITE_index145;
		if (fm.dml.value == 'insert') {
				courseSchduleTitle.innerHTML  =  '일정 등록';
				fm.btnSaveClassManually.style.display = '';
				fm.btnDeleteClass.style.display = 'none';
		}
		else if (fm.dml.value == 'update') {
			courseSchduleTitle.innerHTML  =  '일정 수정';
			fm.btnSaveClassManually.style.display = '';
			fm.btnDeleteClass.style.display = 'none';
//			$('#btnSaveClassManually').attr('src', '/template/DESIGN_type_1/resource/AB_btn_modify.gif');
//			fm.btnSaveClassManually.src  =  '/template/DESIGN_type_1/resource/AB_btn_modify.gif';
		}
}

function countLength(obj){
   var cnt = 0;
   var objvalue = obj;    //원래는 obj.value를 assign 함. jquery 방식으로 이곳에 올때에는 그냥 value 값을 전달하기 때문

   for(var k=0; k < objvalue.length; k++){
         var tmp = objvalue.substring(k, k+1);
         if(checkKoreanOnly(tmp)==true){
            cnt += 2;
         } else {
            cnt += 1;
         }
   }
   return cnt;
}

function checkKoreanOnly(koreanChar) {
   
   if ( koreanChar == null ) return false ;
   
   for(var i=0; i < koreanChar.length; i++){ 

     var c=koreanChar.charCodeAt(i); 

     //( 0xAC00 <= c && c <= 0xD7A3 ) 초중종성이 모인 한글자 
     //( 0x3131 <= c && c <= 0x318E ) 자음 모음 

     if( !( ( 0xAC00 <= c && c <= 0xD7A3 ) || ( 0x3131 <= c && c <= 0x318E ) ) ) {      
        return false ; 
     }
   }  
   return true ;
}

function drawLine(num, br) {
	line	=	br?'<br />&nbsp;':'&nbsp;';
	for (i=0; i < num; i++)	{
			line	+=	'-'
	}
	line	+=	br?'&nbsp;<br />':'&nbsp;';
	return line;
}

function checkChoiceCnt() {
//	alert('aaa');
			$('[id^=TR_surveyChoice_]').each(function() {
							if ($('#surveyChoiceCnt :selected').val() >= Number($(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1))) {
									$(this).show();
							}
							else $(this).hide();
			});

}

function showhideAllChoiceTR(numOfChoice) {
		$('[id^=TR_surveyChoice_]').each(function() {
				var	 seq = $(this).attr('id').substr(Number($(this).attr('id').lastIndexOf('_')) + 1);

				if		 ($('#surveyType :selected').text() ==	'주관식')	$(this).hide();
				else if (Number(seq) > Number(numOfChoice))	$(this).hide();
				else								 		$(this).show();
		});
}

function common_fns_inside(code, param) {
		ack = $.ajax(  
				{
			        url: '/tpcourse/common_fns_inside.php',
					type: "POST",
					data: ({code : code, param: param}),
					async: false
			    }).responseText;	
		return	ack;
}


UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};




/*
일일관리 에서 남은 좌석 수 보이기.
(numOfSeats - enrollCnt) availSeats from (select ifnull(etc_1,0) as numOfSeats from TCBOARD_BD34071 where serial_num = {AV_relation_serial_2}) classroom, (select ifnull(count(*),0) enrollCnt from TCBOARD_BD34098 where category_3 = {AV_serial_num} group by category_3) enroll
availSeats
availSeats
*/
//수강신청 목록에서 신청상태 : serial_num, case name when '신청중' then concat('<span color=red>',name,'</span>') else name end as title from TCSYSTEM_board_ct_1

