	var requestRemainTimeCheckSecTerm = 25;//(Secs.)	
	//var dialogOpenTime = 120;//secs.	
	var dialogOpenTime = 75;//secs.
	var checkUrl = "/common/smgr/dummy.jsp";
	var logoutURL = "/common/login/logout.jsp";
	var logoutParam = null;
	var sessionType = null;
	
	//var dummyResult = new Array(5);
	
	
	var checkRemainsThread = null;
	var countDownThread = null;
	
	var currentCountDownSec = 0;
	
	var debugDivID = "smgrDebugDiv";

	var isSmgrDebug = false;
	var isOpenDialogMode = true; 
	
	var SmgrXMLHttp = null;		
	
	var failCount = 0;
	
	
	function crateSmgrXMLHttpRequest() {
         if (window.ActiveXObject) {
        	 SmgrXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
         else if (window.XMLHttpRequest) {
        	 SmgrXMLHttp = new XMLHttpRequest();               
         }
     }
	
	function isExistFrame()
	{
		var obj = null;
		try
		{
			obj = document;
			return true;
		} catch(e)
		{
			return false;
		}
	}
	
	
	function sleep(naptime)
	{
		naptime = naptime * 1000;
		var sleeping = true;
		var now = new Date();
		var alarm;
		var startingMSeconds = now.getTime();
		
		while(sleeping)
		{
		    alarm = new Date();
		    alarmMSeconds = alarm.getTime();
		    if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
		}
	}
	
	
	function checkRemainSecs()
	{			
		
		try
		{
			getRemainSeconds();
		} catch(e)
		{		
			//alert(e);
		}
	}
	
	
	
	
	function getRemainSeconds()
	{		
		var code = null;
		var remainSeconds = 0;
		var inactiveIntervalMin = 0;
		var sessionType = null;
		
		var param = "0=0";
		
		crateSmgrXMLHttpRequest();			
		if (SmgrXMLHttp) {
			SmgrXMLHttp.open("POST", checkUrl, false);		// false´Â °á°ú°¡ ³ª¿À±âÀü±îÁö ´ë±â
			SmgrXMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); // post¹æ½ÄÀº utf-8 ÇÊ¼ö ¼¼ÆÃ
			SmgrXMLHttp.onreadystatechange = responseRemanSeconds;
			SmgrXMLHttp.send(param);
		}
	}
	
	function responseRemanSeconds()
	{
		var dummyResult = new Array(5);
		var sessionType = null;
		var code = null;
		var remainSeconds = 0;
		var inactiveIntervalMin = 0;
		if (SmgrXMLHttp.readyState == 4)
		{
		      if (SmgrXMLHttp.status == 200)
		      {
		    	  	var xmlDoc = SmgrXMLHttp.responseXML;							
					code = xmlDoc.getElementsByTagName('status').item(0).firstChild.nodeValue;							
										
					var data = null;							
					if(code == 'true')
					{	
						data = xmlDoc.getElementsByTagName('data').item(0).firstChild.nodeValue;
						var dataSet = eval( "(" +  data + ")" );
						remainSeconds = dataSet.result[0].remainSeconds;
						inactiveIntervalMin = dataSet.result[0].inactiveIntervalMin;
						sessionType = dataSet.result[0].sessionType;							
						
						
					} else
					{		
						remainSeconds = -1;
						inactiveIntervalMin = -1;
					}
					
					dummyResult[0] = code;
					dummyResult[1] = remainSeconds;
					dummyResult[2] = inactiveIntervalMin;	
					dummyResult[3] = sessionType;					
					smgr_process(dummyResult);
		      } else if(SmgrXMLHttp.status == 400){
		          //alert("404 Error : " + SmgrXMLHttp.responseText);
		      } else if(SmgrXMLHttp.status == 12029)
		      {
		    	  failCount++;
		    	  if(failCount == 5)
		    	  {		    		  
			    	  alert('¼­¹ö¿Í ³×Æ®¿÷ÀÌ Á¾·áµÇ¾ú½À´Ï´Ù.\n³×Æ®¿÷ ¿¬°á »óÅÂ¸¦ È®ÀÎÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.');
			    	  stopThread();
		    	  }
		    	  
		      }
		      
		   }
		
		
	}
	
	function smgr_process(result)
	{		
		var isLogin = 'false';				
		var leftSeconds = 0;
		var inactiveIntervalMin = 0;
		var _sessionType = null;
		try
		{	
			isLogin = result[0];			
			leftSeconds = parseFloat(result[1]);			
			inactiveIntervalMin = result[2];
			_sessionType = result[3];
			sessionType = _sessionType; 
		} catch(e)
		{}
		
		
		
		if(_sessionType == null || _sessionType == '' || _sessionType == 'hts' ||_sessionType == 'mobile') 
		{
			
			stopThread();
			return;
		} else if(_sessionType=='esop')
		{
			logoutURL = "/esop/common/logout.jsp";			
			logoutParam = "?esop="+co_cd+"&enum="+login_id;

		} else
		{
			var logoutParamSearch = null;
			if(isExistFrame())
			{
				logoutParam = location.pathname;
				logoutParamSearch = location.search;				
				
				if(logoutParam != 'undefined')
					logoutParam = '/n_frame.jsp?'+ logoutParam;
								
				if(logoutParamSearch != 'undefined') 
					logoutParam = logoutParam+logoutParamSearch;
				
			} else
			{
				logoutParam = location.pathname;
				logoutParamSearch = location.search;
				if(logoutParam != 'undefined' && logoutParamSearch != 'undefined')
					logoutParam = logoutParam + logoutParamSearch;
			}
			
			if(logoutParam.indexOf('/koreastockgame/') == -1)
			{
				if(logoutParam != 'undefined') logoutParam = "?redirect="+encodeURIComponent(logoutParam);
				else logoutParam='';
			} else
			{
				logoutParam = "?redirect="+encodeURIComponent('/koreastockgame/');
			}
		}
		
		if(isExistFrame())
		{
			//top.frames["frm_main"].setParamObj(leftSeconds, inactiveIntervalMin, null);
			try
			{
				top.frames[0].document.getElementById('logout_confirm_maxInactiveMin').innerHTML = inactiveIntervalMin;
				top.frames[0].document.getElementById('logout_confirm_count').innerHTML = leftSeconds;
			} catch(e)
			{
					document.getElementById('logout_confirm_maxInactiveMin').innerHTML = inactiveIntervalMin;
					document.getElementById('logout_confirm_count').innerHTML = leftSeconds;
			}
		} else
		
		{
			//setParamObj(leftSeconds, inactiveIntervalMin, null);
			document.getElementById("logout_confirm_maxInactiveMin").innerHTML = inactiveIntervalMin;		
			document.getElementById("logout_confirm_count").innerHTML = leftSeconds;			
		}	
		
		//alert('leftSeconds:'+leftSeconds);
		
		
		if(leftSeconds > 1 && leftSeconds <= parseInt(dialogOpenTime))
		{ 		
			clearInterval(checkRemainsThread);			
			
			if(isOpenDialogMode)
			{
				if(isExistFrame())
				{
					openLogoutConfirmWindow();					
				}
				else
				{
					openLogoutConfirmWindow();
				}
			}
			
			if(countDownThread == null)
				wakeUpCountDownThread(leftSeconds);
			
			return;			
			
		} else if(leftSeconds <= 1)
		{
			stopThread();			
			return;
		} else
		{
			//alert('skip');
		}
		

		if(checkRemainsThread == null) {wakeUpCheckRemainsThread();}
	
	}
	
	function wakeUpCheckRemainsThread()
	{			
		
		checkRemainsThread = setInterval("checkRemainSecs()", 1000*parseInt(requestRemainTimeCheckSecTerm));			 
	}
	
	function wakeUpCountDownThread(leftSeconds)
	{			
		currentCountDownSec = leftSeconds;
		countDownThread = setInterval("countDown()", 1000);
	}

	function countDown()
	{				
		currentCountDownSec = parseInt(currentCountDownSec);
		
		if(currentCountDownSec <= 1)
		{
			clearInterval(countDownThread);
			if(isOpenDialogMode)
			{
				location.href = logoutURL+logoutParam;
			}
			return;
		}
		currentCountDownSec--;
		
		if(isExistFrame())
			document.getElementById('logout_confirm_count').innerHTML = currentCountDownSec;
			//top.frames["frm_main"].setParamObj(currentCountDownSec, null, null);
		else
			document.getElementById('logout_confirm_count').innerHTML = currentCountDownSec;
			//setParamObj(currentCountDownSec, null, null);
		
	}
	
	function stopThread()
	{	
		try
		{
			clearInterval(checkRemainsThread);
			checkRemainsThread = null;
		} catch(e)
		{}
		
		try
		{
			clearInterval(countDownThread);
			countDownThread = null;
		} catch(e)
		{}
		
	}
	

	
	
