﻿// JavaScript File

var outerBox;

window.onload = function() {
	if(location.toString().indexOf('halsoportal') != -1 || location.toString().indexOf('test.htm') != -1) {
		var pageSize = getPageSize();
		var body = document.getElementsByTagName('body').item(0);
		
		outerBox = document.createElement('div');
		outerBox.setAttribute('id', 'outerBox');
		outerBox.style.display = 'none';
		outerBox.style.visibility = 'hidden';
		outerBox.style.position = 'absolute';
		outerBox.style.left = (pageSize[0] / 2) - 160 + 'px';
		outerBox.style.top = (pageSize[1] / 2) - 45 + 'px';
		outerBox.style.width = '320px';
		outerBox.style.height = '90px';
		outerBox.style.backgroundColor = '#FFFFFF';
		outerBox.style.padding = '10px';
		outerBox.style.zIndex = '100';
		
		body.appendChild(outerBox);
		
		var box = document.createElement('div');
		box.style.width = '308px';
		box.style.height = '78px';
		box.style.borderColor = 'lightSteelBlue';
		box.style.borderWidth = '1px';
		box.style.borderStyle = 'solid';
		box.style.backgroundColor = '#E5E6F4';
		box.style.padding = '4px';
		box.style.textAlign = 'left';
		box.style.fontFamily = 'Verdana, Arial, Sans-Serif';
		box.style.fontSize = '10px';
		
		box.innerHTML = '<span style="font-size:14px;font-weight:bold;">Du kommer att bli utloggad</span><br /><br />';
		box.innerHTML += 'Om någon minut kommer du automatiskt bli utloggad på grund av inaktivitet. Om du vill vill vara inloggad måste du ladda om sidan.';
		
		outerBox.appendChild(box);
	
		CheckActivity();
	}
}

var loadOnline = new Date();

function CheckActivity() {
	var nowOnline = new Date();
	var onlineTime = nowOnline.getTime() - loadOnline.getTime();
		
	var logoutTime = 900000;
	var alertTime = 840000;
	
	if(onlineTime >= logoutTime) {
		location.href = 'default.aspx?logout=1';
	} else if(onlineTime >= alertTime) {
		outerBox.style.display = '';
		outerBox.style.visibility = '';
		outerBox.focus();
		window.focus();
		setTimeout('CheckActivity()', 60000);
	} else {
		setTimeout('CheckActivity()', 60000);
	}
}

function getPageSize() {
	var xScroll, yScroll, windowWidth, windowHeight;;
	if(window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	if(self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
