var popup_check = true;
var ndl_login_flag = true;
var scroll_timer = null;
var scroll_timer2 = null;
var scroll_timer_index = 0;
// 페이지 접근 시 로그인 또는 로그아웃 글자 표시 및 메뉴 명칭 작성
function PageInit()
{		
	// 스크롤 맞추기
	loaded2();
}
// 헤더 로그인 하기 또는 로그아웃 하기 버튼을 클릭 하였을 경우
function header_login_submit(url)
{
	var menu_index = document.getElementById("menu_index");
	var menu = "";
	var loginflag  = document.getElementById("loginflag");
	
	
	if(navigator.deviceName == "iPhoneApp" || navigator.deviceName == "androidApp" ){		
		window.onunload = function()
		{
		  document = null;
		}
		if(loginflag.value == "false")
		{
			
			if(url != ""){
				document.AppPageForm.url.value=url;
			}
			document.AppPageForm.action="/login/login.jsp";
			document.AppPageForm.submit();
		
		}
		else
		{
			if(url != ""){
				document.AppPageForm.url.value=url;
			}
			document.AppPageForm.action="/login/logout.jsp";
			document.AppPageForm.submit();
		
		}
		
	}else{
		if(loginflag.value == "false")
		{
			if(menu_index != null)
				menu = menu_index.value;
			var settings ='toolbar=0,directories=0,status=no,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0';
			var url = '/login/login.jsp?move_menu_index='+ menu;
			winObject = window.open(url , "windows", settings);
		}
		else
		{
			var settings ='toolbar=0,directories=0,status=no,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0';
			var url = '/login/logout.jsp';
			winObject = window.open(url , "windows", settings);
		}
	}
}

// 메인 화면에서 로그인 체크
function checking_login()
{
	var loginflag  = document.getElementById("loginflag");
	
	
	if(navigator.deviceName == "iPhoneApp" || navigator.deviceName == "androidApp" ){	
		window.onunload = function()
		{
		  document = null;
		}
		if(loginflag.value == "false")
		{
			
			document.AppPageForm.action="/login/login.jsp?move_menu_index=7-6";
			document.AppPageForm.submit();
		}
		else
		{
			window.location.href = "/basketview.do";
		}
	}else{
		if(loginflag.value == "false")
		{
			var settings ='toolbar=0,directories=0,status=no,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0';
			var url = '/login/login.jsp?move_menu_index=7-6';
			winObject = window.open(url , "windows", settings);
		}
		else
		{
			var f = document.main_home;
			f.action = "/basketview.do";
			f.submit();
		}
	}

}

function checking_login2(menu_index)
{
	var loginflag  = document.getElementById("loginflag");
		
	
	if(loginflag.value == "false")
	{
		if(navigator.deviceName == "iPhoneApp" || navigator.deviceName == "androidApp" ){
			window.onunload = function()
			{
			  document = null;
			}
			
			document.AppPageForm.action="/login/login.jsp?move_menu_index="+menu_index;
			document.AppPageForm.submit();

		}else{
			var settings ='toolbar=0,directories=0,status=no,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0';
			var url = '/login/login.jsp?move_menu_index='+menu_index;
			winObject = window.open(url , "windows", settings);
		}
	}
	else
	{
		// 온라인신청
		if(menu_index == "7-6")
		{
			
			
			var f			   = document.main_home;
			var basketViewForm = document.basketViewForm;
			
			
			if(f != null && typeof(f) != 'undefined'){
				f.action = "/basketview.do";
				f.submit();	
			}
			
			if(basketViewForm != null && typeof(basketViewForm) != 'undefined'){
				basketViewForm.action = "/basketview.do";
				basketViewForm.submit();
			}
			
			
			
						
		}
		// 비치 희망 신청
		else if(menu_index == "7-7")
		{
			var f = document.main_home;
			f.action = "/furnish.do";
			f.submit();			
		}
		// 비치희망신청 확인
		else if(menu_index ==  '7-7-2'){
			window.location.href = "/furnishMng.do?method=furnishsearch";			                        
		}
		// 정보광장예약 메인 페이지 
		else if(menu_index == "7-6-1")
		{
			var f = document.main_home;
			f.action = "/reservation.do";
			f.submit();			
		}
		// 정보광장예약  디지털 도서관  예약 화면 
		else if(menu_index == "7-6-2")
		{
			var f = document.main_home;
			document.reservation.action = "/move_digital_location.do";
			document.reservation.submit();		
		}
		// 정보광장예약  미디어 편집실 예약 화면  
		else if(menu_index == "7-6-3")
		{
			var f = document.main_home;
			document.reservation.action = "/move_media_edit_loacation.do";
			document.reservation.submit();
		}
		// 정보광장예약  미디어 자료 이용실 예약 화면  
		else if(menu_index == "7-6-4")
		{
			var f = document.main_home;
			document.reservation.action = "/move_media_mat_loacation.do";
			document.reservation.submit();		
		}
		// 정보광장예약 예약 정보 확인 화면 
		else if(menu_index == "7-6-5")
		{
			var f = document.main_home;
			document.reservation.action = "/resv_confirm.do";
			document.reservation.submit();
		}
		// 정보광장예약 세미나실 예약 화면 
		else if(menu_index == "7-6-6")
		{
			var f = document.main_home;
			document.reservation.action = "/move_seminar_location.do";
			document.reservation.submit();
		}
		// 정보광장예약 복합 상영관 예약 화면 
		else if(menu_index == "7-6-7")
		{
			var f = document.main_home;
			document.reservation.action = "/move_multiplex_location.do";
			document.reservation.submit();		
		}
		// ucc 스튜디오
		else if(menu_index == "7-6-8")
		{
			var f = document.main_home;
			document.reservation.action = "/move_ucc_location.do";
			document.reservation.submit();
		}
		//봉사신청,견학신청 안내 메인 화면
		else if(menu_index == "7-8"){
			var f = document.main_home;
			f.action = "/move_volunteer.do";
			f.submit();			
		}
		//견학신청 관련 일정선택 달력 화면 
		else if(menu_index == "7-8-1"){
			window.location.href="/observationmng.do?method=moveCalender";	
		}
		//견학신청 이용자정보 입력화면 
		else if(menu_index == "7-8-2"){
			window.location.href="/observationmng.do?method=moveApplyPage";		
		}
		//견학신청 확인화면 
		else if(menu_index == "7-8-3"){
			window.location.href="/observationmng.do?method=moveConfirm";	
		}else if(menu_index == "7-8-4"){
			window.location.href= "/move_volunteer.do?tabindex=3";
		}
		//견학신청 관련 일정선택 달력 화면 
		else if(menu_index == "7-9-1"){
			window.location.href="/volunteermng.do?method=moveApplyPage";
		}
		//견학신청 이용자정보 입력화면 
		else if(menu_index == "7-9-2"){
			window.location.href="/volunteermng.do?method=moveConfirm";
		//자원봉사 입력 
		}else if(menu_index == "7-9-3"){
			window.location.href="/volunteerworkmng.do?method=moveApplyPage";
		//자원봉사 내역 
		}else if(menu_index == "7-9-4"){
			window.location.href="/volunteerworkmng.do?method=moveConfirm";
		}
		// 우편복사신청
		else if(menu_index == "7-10"){
			window.location.href="/post.do?method=getApplyPostList";
		}
		// 야간도서관신청(자료실당일신청)확인
		else if(menu_index == "7-11"){
			window.location.href="/nightLibMng.do?method=getApplyBookList";
		}
		// 보존용자료(예약-익일이용) 확인 
		else if(menu_index == "7-12"){
			window.location.href="/weeklyApplyMng.do?method=getApplyBookList";
		}
		// 고전운영실(보존예약-일주일후이용) 확인 
		else if(menu_index == "7-13"){
			window.location.href="/classicmanagementapply.do?method=getApplyBookList";
		}
		//내서제 메인 화면
		else if(menu_index ==  '8'){
			var f = document.main_home;
			f.action = "/mylibrary.do";
			f.submit();
		}
		//내서재 서비스이용내역
		else if(menu_index ==  '8-2'){
			window.location.href = "/myServiceLog.do";
		}
		//내서재 사이버 머니 
		else if(menu_index ==  '8-3'){
			window.location.href = "/mySyber.do?method=moveSyberPage";
		}
		//내서재 스크랩  
		else if(menu_index ==  '8-4'){
			window.location.href = "/myScrap.do?method=moveScrapPage";
		}
		//내서재 신청바구니 
		else if(menu_index ==  '8-5'){
			window.location.href = "/basketview.do";
		}
		//내서재 교육내역 
		else if(menu_index ==  '8-6'){
			window.location.href = "/myEducation.do?method=moveEducationPage";
		}
		//내서재ㅔ내가이용한 자료  
		else if(menu_index ==  '8-7'){
			window.location.href = "/myUseLog.do?method=moveUseLogPage";
		}
		
	
	}
	
}

// 로그인 완료 후 글자 변경 및 변수 변경 하기
function loginCheck(param_url)
{
	var login_msg  		    	= document.getElementById("login_msg");
	var loginflag  		    		= document.getElementById("loginflag");
	var logout_msg_view  		= document.getElementById("logout_msg_view");
	var move_menu_url       	= document.getElementById("move_menu_url");
	if(logout_msg_view != null)
	{
		// 로그 아웃 글자 변경
		login_msg.innerHTML = logout_msg_view.value;	
	}	
	// 로그인 플래그 변경
	loginflag.value = "true";
	popup_check = false;
	
	if(param_url!= null ){
		move_menu_url.value = param_url;
	}
	return;
}

//신착자료 메일 주소 리턴 함수
function loginCheck_mail(param_url,user_email)
{
	
	var login_msg  		    	= document.getElementById("login_msg");
	var loginflag  		    		= document.getElementById("loginflag");
	var logout_msg_view  		= document.getElementById("logout_msg_view");
	var move_menu_url       	= document.getElementById("move_menu_url");
	var email       					= document.getElementById("email");
	if(logout_msg_view != null)
	{
		// 로그 아웃 글자 변경
		login_msg.innerHTML = logout_msg_view.value;	
	}
	// 로그인 플래그 변경
	loginflag.value = "true";
	popup_check = false;
	//검색리스트로 이메일 전달
	email.value = user_email;

	if(param_url!= null ){
		move_menu_url.value = param_url;
	}
	
	return;
}

function popup_close()
{
	var loginflag  = document.getElementById("loginflag");
	var move_menu_url       = document.getElementById("move_menu_url");
	
	if(loginflag.value == "true")
	{
		if(popup_check == false)
		{
			if(navigator.deviceName == "iPhoneApp" || navigator.deviceName == "androidApp" ){
			//winObject.close();
			}else{
				winObject.close();
			}
			popup_check = true; 
			
			if(move_menu_url.value != "NOTMOVE")
			{
				var temp_url = move_menu_url.value ; 
				move_menu_url.value = "";				
				window.location.href = temp_url ;
			}
			else{
				
			}
			
		}
	}
}

// 로그아웃 완료 후 글자 변경 및 변수 변경 하기
function logoutCheck()
{
	var login_msg  		= document.getElementById("login_msg");
	var loginflag  		= document.getElementById("loginflag");
	var login_msg_view  	= document.getElementById("login_msg_view");
	// 로그인 글자 변경
	login_msg.innerHTML = login_msg_view.value;
	// 로그인 플래그 변경
	loginflag.value = "false";
	return;
}


function change_tab_2(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}

	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
	}else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
}


function change_tab_3(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}

	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
	}else if(index=="3"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="block";
		$("tab3_content").style.display="block";
	}else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
	
}

function change_tab_3_extends(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}

	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
	}else if(index=="3"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="block";
		$("tab3_content").style.display="block";
	}else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
	
	change_tab_3_next(index);
}


function change_tab_4(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}

	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";			
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="3"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="block";
		$("tab3_content").style.display="block";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="4"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="block";
		$("tab4_content").style.display="block";
	}	else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
}

function change_tab_4_extends(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}

	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";		
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="3"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="block";
		$("tab3_content").style.display="block";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="4"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="block";
		$("tab4_content").style.display="block";
	}else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
	
	change_tab_4_next(index);
}

function change_cms_tab_4(index) {

	if(index == null || index ==""){
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
	
	if(index=="1"){
		$("tab1").style.display="block";
		$("tab1_content").style.display="block";		
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";		
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";		
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";				
	}else if(index=="2"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="block";
		$("tab2_content").style.display="block";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="3"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="block";
		$("tab3_content").style.display="block";
		$("tab4").style.display="none";
		$("tab4_content").style.display="none";
	}else if(index=="4"){
		$("tab1").style.display="none";
		$("tab1_content").style.display="none";
		$("tab2").style.display="none";
		$("tab2_content").style.display="none";
		$("tab3").style.display="none";
		$("tab3_content").style.display="none";
		$("tab4").style.display="block";
		$("tab4_content").style.display="block";
	}	else{
		alert('페이지에 문제가 존재합니다. 관리자에게 문의하십시요');
		return;			
	}
}
/*
 * 
function header_login_submit()
{
	var menu_index = document.getElementById("menu_index");
	document.header_loginform.action = '/loginCheck.do?method=MoveLogin'+'&move_menu_index='+ menu_index.value;
	document.header_loginform.submit();
}
 * 
 * */
 
 function leftMenu(){
		var leftLibMenu =  document.getElementById("leftLibMenu");		
		if(leftLibMenu!=null ){		
			leftLibMenu.style.height = window.innerHeight+'px';
			scroll_timer= setInterval(scroll_timer_function,1000);
		}
	}

	function scroll_timer_function (){
		scroll_timer_index = scroll_timer_index +1;
		if(scroll_timer_index == 2){
			scroll_timer_index = 0;		
			clearInterval(scroll_timer);
			scroll_timer2 = setInterval(scroll_timer2_function,30);
		}	
	}
	function scroll_timer2_function (){
		
		var mainBody   = document.getElementById("mainBody");
		var leftLibMenu =  document.getElementById("leftLibMenu");
		var temp_top    =  leftLibMenu.style.top;
			
		temp_top    = temp_top.replaceAll("px","");
		temp_top    = temp_top.replaceAll("%","");
			
		if(temp_top == mainBody.scrollTop){				
			clearInterval(scroll_timer2);
			return false;
		}		 
			
		//alert("temp_top = " + temp_top + "\t\t mainBody.scrollTop=" + mainBody.scrollTop);
			
		if(parseInt(temp_top) < mainBody.scrollTop){
			temp_top = parseInt(temp_top)+1;
			leftLibMenu.style.top = temp_top+'px';
		}else if(parseInt(temp_top) > mainBody.scrollTop){
			temp_top = parseInt(temp_top)-1;
			leftLibMenu.style.top = temp_top+'px';
		}else{
			clearInterval(scroll_timer2);
			return false;
		}
			
			
		if(temp_top == mainBody.scrollTop){				
			clearInterval(scroll_timer2);
			return false;
		}		
		return false;
	}
function AppPageMove(url){
	if(navigator.deviceName == "iPhoneApp" || navigator.deviceName == "androidApp" ){
		document.AppPageForm.action = url;
		document.AppPageForm.submit();
	}else{
		document.AppPageForm.method="post";
		document.AppPageForm.action = url;
		document.AppPageForm.submit();
	}
}

