function init() {
        if (self.parent.frames.length != 0) {
                self.parent.location = document.location;
        }
        if (document.getElementById) {
                document.onkeydown = register;
        }
}

function register(e) {
        var code;
        if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;

		// shift + ctrl + E
		// ------------------
		// edit current page
		if((code == 69) && (e.ctrlKey == true) && (e.shiftKey == true)) {
			window.open('/hotkey.php?cmd=editpage&r='+escape(window.location.href),'hotkey');
		}
		// shift + ctrl + L
		// ------------------
		// edit current page
		if((code == 76) && (e.ctrlKey == true) && (e.shiftKey == true)) {
			ClickLogin();
		}
}

function PopUp(url, W, H) {
	W+=0;
	H+=0;
	var size="width="+W+",height="+H;
	window.open(url,"","status=no,scrollbars=no,resizable=yes,"+size);
	return false;
}

function showLogin(islogin)
{
	var f = document.forms['login'];
	if (document.getElementById && f) {
		var iss = getCookie('mkse_login');
		if(!iss || iss == 0) {
			if (islogin == 2) {
				var login = getCookie('mkse');
				islogin = (login && login.length > 1);
				if (islogin) {
					if (f.login.value != login) {
						f.login.value = login;
					}
				}
				f.pswrd.value = '';
			}
			document.getElementById('login-form').style.display = 'block';
			islogin ? f.pswrd.focus() : f.login.focus();
			return false;
		} else {
			return false;
		}
	}
	return true;
}

function hideLogin()
{
	if(document.getElementById('login-form')) document.getElementById('login-form').style.display = 'none';
	return false;
}

function getCookie(n)
{
	var c = document.cookie;
	if (c.length < 1) return false;

	var b = c.indexOf(n + '=');
	if (b == -1) return false;

	b += (n.length + 1);
	var e = c.indexOf(';', b);

	return unescape((e == -1) ? c.substring(b) : c.substring(b, e));
}

function CheckCookie()
{
	var sid = getCookie('Session_id');
	if (!sid) return false;
	var parts = sid.split('.');
	if (parts[2] == '1') return true;
    if (parts[2] == '3') return parseFloat(((new Date().getTime()) - parts[0] * 1000 - parts[1]) / 1000) < 1209600.0;
	return parseFloat(((new Date().getTime()) - parts[0] * 1000 - parts[1]) / 1000) < 7200.0;
}

function CheckSession(rp)
{
	if (!CheckCookie()) return showLogin(2, rp);
}

function ClickLogin()
{
	if (CheckCookie()) {
		return false;
	}
	return showLogin(2);
}

function imgOpen(imgURL,imgWidth,imgHeight,Title) {

var features;
  var top = (screen.height - imgHeight)/2, left = (screen.width - imgWidth)/2;
  if(top < 0) top = 0;
  if(left < 0) left = 0;
  features = ',top=' + top + ',left=' +left;

var imgWndw=window.open('','winblank','width='+imgWidth+',height='+
  imgHeight+',toolbar=no,menubar=no,location=no,status=no,'+
  'resizable=yes,scrollbars=no'+features);
var imgTitle=(Title)?Title:imgURL+": "+imgWidth+'x'+imgHeight;
with (imgWndw.document){
  open();
  write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
  '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+
  'rightmargin="0" bottommargin="0" marginwidth="0" '+
  'marginheight="0"><img src="'+imgURL+'" width="'+imgWidth+
  '" height="'+imgHeight+'" border="0" alt="'+imgTitle+
  '"></bo'+'dy></ht'+'ml>');
  close();
}
return false
}
