function AutoLogout(containerid, _autologoutparameters) {
	var autologoutcontainer = $('#' + containerid);
	var autologoutstartparameters = _autologoutparameters;
	var remindertimer = null;
	var expirytimer = null;
	var remainingtimetimer = null;
	var usernameexpiringcookiename = 'Log4ProIS_Username_expirepending';
	var loggedinusernamecookiename = 'Log4ProIS_Username';
	var remainingtime;
	var remainingtimerefreshfrequency = 1;
	var $restartlogoutReminderButton;
	var $restartlogoutRemainingtime;
	var sessionlength;
	var remindertimeout;
	this.Start = function () {
		var autologoutparameters = autologoutcontainer.html();
		if (autologoutparameters === undefined || autologoutparameters === null) { autologoutparameters = autologoutstartparameters; }
		if (autologoutparameters === undefined || autologoutparameters === null) { autologoutparameters = "900,60"; }
		var autologoutparameterssplitted = autologoutparameters.split(',');
		sessionlength = 900; remindertimeout = 60;
		if (autologoutparameterssplitted.length >= 1) { sessionlength = autologoutparameterssplitted[0]; }
		if (autologoutparameterssplitted.length >= 2) { remindertimeout = autologoutparameterssplitted[1]; }
		if (sessionlength <= 0 || remindertimeout <= 0) { return; }

		var autologouthtml = $("<a id=\"restartlogoutReminderButton\" href=\"#\" class=\"float_but\" style=\"display: none;\"><i class=\"fa fa-plus-square my-float_bt2\"></i><i class=\"my-float_bt\"> logout in </i><i id=\"restartlogoutRemainingtime\" class=\"my-float_bt2\"></i><i class=\"my-float_bt\"> sec</i></a>");
		autologoutcontainer.append(autologouthtml);
		$restartlogoutReminderButton = $('#restartlogoutReminderButton');
		$restartlogoutRemainingtime = $('#restartlogoutRemainingtime');
		// logoutReminder Button click eseményre feliratkozás 
		$restartlogoutReminderButton.on('click', function () { restartlogoutReminder(sessionlength); });
		restartlogoutReminder(sessionlength);
	}
	function userLoggedIn() {
		var currentuser = Cookie.get(loggedinusernamecookiename);
		return currentuser !== null;
	}

	function restartlogoutReminder(sessionlength) {
		if (!userLoggedIn()) { return; }
		$restartlogoutReminderButton.hide();
		clearInterval(expirytimer);
		clearInterval(remindertimer);
		clearInterval(remainingtimetimer);
		Cookie.erase(usernameexpiringcookiename);
		extendcookieexpiration();
		remindertimer = setInterval(showlogoutReminder, sessionlength * 1000, sessionlength);
	}
	function showlogoutReminder(sessionlength) {
		clearInterval(remindertimer);
		Cookie.set(usernameexpiringcookiename, 'X', 2);
		remainingtime = sessionlength * 2 < remindertimeout ? sessionlength * 2 : remindertimeout;
		$restartlogoutRemainingtime.html(remainingtime);
		remainingtimetimer = setInterval(refreshremainingtime, remainingtimerefreshfrequency * 1000);
		//expirytimer = setInterval(removeloggedinusercookie, (2*sessionlength) * 1000);
		$restartlogoutReminderButton.show();
	}
	function refreshremainingtime() {
		$restartlogoutRemainingtime.html(remainingtime);
		remainingtime = remainingtime - remainingtimerefreshfrequency;
		if (remainingtime < 0) { removeloggedinusercookie(); }
	}
	function removeloggedinusercookie() {
		clearInterval(remainingtimetimer);
		clearInterval(remindertimer);
		clearInterval(expirytimer);
		Cookie.erase(loggedinusernamecookiename);
		Cookie.erase(usernameexpiringcookiename);
		logoutuser();
		reloadtimer = setInterval(reload, 2000);
	}
	function reload() { location.reload(true); clearInterval(reloadtimer); }
	function extendcookieexpiration() {
		var cookiecontent = Cookie.get(loggedinusernamecookiename);
		Cookie.set(loggedinusernamecookiename, cookiecontent, 0, 0, 0, parseInt(sessionlength) + parseInt(remindertimeout) + 5);
	}
	function logoutuser() {
		$.ajax({
			cache: false,
			url: '/Log4ProIS/UserAdministration/Account/LogoutJSON',
			type: 'post',
			contenttype: 'application/json',
			datatype: 'json',
			data: null,
			success: function (responseData) { },
			error: function (jqXHR, exception) {
				console.log('Ajax hívás sikertelen! ', jqXHR.responseText);
			}
		});
	}
	function loginextend(username) {
		$.ajax({
			cache: false,
			url: '/Log4ProIS/UserAdministration/Account/LoginExtendJSON',
			type: 'post',
			contenttype: 'application/json',
			datatype: 'json',
			data: { authenticationcookievalue: username },
			success: function (responseData) { },
			error: function (jqXHR, exception) {
				console.log('Ajax hívás sikertelen! ', jqXHR.responseText);
			}
		});
	}
	var Cookie = {
		set: function (name, value, days, hours, minutes, seconds) {
			var domain, domainParts, date, expires, host;

			if (days === undefined) { days = 0; }
			if (hours === undefined) { hours = 0; }
			if (minutes === undefined) { minutes = 0; }
			if (seconds === undefined) { seconds = 0; }
			if (days + hours + minutes + seconds == 0) { expires = ""; }
			else {
				date = new Date();
				date.setTime(date.getTime() + ((((days * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000));
				expires = "; expires=" + date.toGMTString();
			}

			host = location.host;
			if (host.split('.').length === 1) {
				document.cookie = name + "=" + value + expires + "; path=/";
			}// no "." in a domain - it's localhost or something similar
			else {
				// Remember the cookie on all subdomains.
				//
				// Start with trying to set cookie to the top domain.
				// (example: if user is on foo.com, try to set
				//  cookie to domain ".com")
				//
				// If the cookie will not be set, it means ".com"
				// is a top level domain and we need to
				// set the cookie to ".foo.com"
				domainParts = host.split('.');
				domainParts.shift();
				domain = '.' + domainParts.join('.');

				document.cookie = name + "=" + value + expires + "; path=/; domain=" + domain;

				// check if cookie was successfuly set to the given domain
				// (otherwise it was a Top-Level Domain)
				if (Cookie.get(name) == null || Cookie.get(name) != value) {
					// append "." to current domain
					domain = '.' + host;
					document.cookie = name + "=" + value + expires + "; path=/; domain=" + domain;
				}
			}
		},

		get: function (cookiename) {
			var nameEQ = cookiename + "=";
			var cookielist = document.cookie.split(';');
			for (var i = 0; i < cookielist.length; i++) {
				var cookie = cookielist[i];
				while (cookie.charAt(0) == ' ') { cookie = cookie.substring(1, cookie.length); }
				if (cookie.indexOf(nameEQ) == 0) return cookie.substring(nameEQ.length, cookie.length);
			}
			return null;
		},

		erase: function (name) {
			Cookie.set(name, '', -1);
		}
	};

}
