﻿// COUNTER JScript File

/*****************************************************************************************************/

	var initialCountdown = 600;  //10 minutes = 600
	var count = initialCountdown;
	var counterLayer;
	var firstTime = 0;
 
 
 /****************************************************************************/
 /* AJAX function for refreshing the session state on the server             */
 /****************************************************************************/
  	var XMLHttpRequestObject = false;
	
	if (window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	function refreshServerSession(dataSource)
	{
		if(XMLHttpRequestObject) {
			
			XMLHttpRequestObject.open("GET", dataSource);
			XMLHttpRequestObject.onreadystatechange = function()
			{
				if (XMLHttpRequestObject.readyState == 4 &&
					XMLHttpRequestObject.status == 200) {
				}
			}			
			XMLHttpRequestObject.send(null);
		}
	}
 
	function startCountdown(pIsAuthenticated) {	    
	    	   	    
	    if(pIsAuthenticated == 'True')
	    {	
	        if(firstTime == 0 )
	        {
	            var firstTimeDate = new Date();	         
	            var Fhours = firstTimeDate.getHours();
	            var Fminu = firstTimeDate.getMinutes();
	            var Fsec = firstTimeDate.getSeconds();
	            
	            firstTime = (Fhours * 60 * 60 ) + (Fminu * 60) + Fsec ;
	            
	         }   
	         
		    count = 0;
		     		     
		    var currentTime = new Date();		    
            var Chours = currentTime.getHours();
            var Cminu = currentTime.getMinutes();
            var Csec = currentTime.getSeconds();
	            
	        var CTime = (Chours * 60 * 60 ) + (Cminu * 60) + Csec ;
	            
		    count = initialCountdown - (CTime - firstTime);
		    
		    s1 = Math.floor(count);
	        m = parseInt(s1 / 60 );
	        
	        s = s1 - (m * 60);	            
            
		    changeLayerContent('In ' + m + ' Minuten und ' + s + ' Sekunden werden Sie automatisch ausgeloggt.');
		    
		    if (count>0){		   
			    Id = window.setTimeout("startCountdown('" + pIsAuthenticated + "')",1000); 
		    } 
		    else {		
			    changeLayerContent('Sie sind ausgeloggt.');
		    }
		}	
	}	

	function resetCountdown() {			    
	    if(count>0)
	    {	        
	        firstTime = 0;	        
	        refreshServerSession('Reset.aspx');    	        
	    }
	    else
	    {
            var sPath = window.location.href.toLowerCase();
            if(sPath.indexOf('https://')>=0)
            {
                window.location= '../pages/OnLine.aspx?view=login';
                changeLayerContent('');
            }	
	    }
	        
	}
	
	function changeLayerContent(msg) {
		window.status = msg;
	}

/****************************************************************************************************/