var g_loginkeydown;

function showLogin(islogin, rp, subj, form1, form2)
{

	var f = document.forms[form1];
	if (document.getElementById && f) 
	{
//		if (typeof(rp) != 'undefined') {
//			f.retpath.value = rp;
//		}
		
		
		if (form1 == 'login')
			f.subj.value = subj;

		x = document.getElementById(form2).style;
		x.top  = document.body.scrollTop  + document.body.clientHeight/2 - 10;
		x.left = document.body.scrollLeft + document.body.clientWidth/2 - 390;


		document.getElementById(form2).style.display = 'block';
		if (form1 == 'login')
			f.name.focus();
		
		// запоминаем старый onkeydown
		g_loginkeydown = document.onkeydown;
		// и навешиваем новый, который будет закрывать окно по нажатию на Esc
		document.onkeydown = function (e)
		{
			e = e || window.event;
			if ((e.keyCode == 27) && (!e.ctrlKey) && (!e.altKey)) { hideLogin(); }
		}
		
		return false;
	}

	var img = new Image();
	img.src = 'http://mzon.ru/click/dtype=morda/*https://mail.yandex.ru/';

	return true;
}

function hideLogin(form2)
{
    document.onkeydown = g_loginkeydown;
	document.getElementById(form2).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()) {
		document.location.href = 'http://mzon.ru/?ncrnd=' + Math.random();
		return false;
	}
	return showLogin(2, 'http://mzon.ru/');
}

function settime()
{
	document.forms['login'].timestamp.value = new Date().getTime();
}

function search_type(site)
{
	var f = document.forms['web'];
	if (f.text.value) {
		f.stype.value = site;
		f.submit();
		return false;
	}
	return true;
}

function unescape_opera(text) {
	if(typeof(RegExp) == 'function') {
		re = /quot;/g;  
		newstr=text.replace(re, ''); 
		re = /&/g; 
		return newstr.replace(re, '"');  
	} 
	else return text;
}

function r(a, w)
{
	var img = new Image();
	img.src = 'https://mzon.ru/click/dtype=' + w + '/*' + a.href;
}