var ref = document.referrer.toLowerCase();
if (ref.indexOf('autosurf-ru.com') !=-1 || ref.indexOf('hitstream.net') !=-1)
	window.location.href = 'http://i.ua/r.php?3';

function i_showFloat(act, url, suf)
{
	if (typeof(suf) == 'undefined')
		suf = 'Login';

	var ab = document.getElementById('Float' + suf);
	var m = document.getElementById('FloatMask' + suf);
	var dis;

	if(act) {
		m.style.display = 'block';
		if (b.opera)
			m.style.background = 'none';
		var sHeight = !b.ie ? window.innerHeight : m.offsetHeight;
		var bHeight = self.document.body.offsetHeight;
		var bWidth = self.document.body.offsetWidth;
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		ab.style.overflow = 'auto';
		m.style.height = bHeight + 'px';
		ab.style.display = 'block';
		ab.style.left = (bWidth - ab.offsetWidth)/2 + 'px';
		if(!b.moz){
			ab.focus();
			ab.style.outline = 'none';
		}
		dis = 'hidden';
		if (url)
			document.lFloat._url.value = url;
		if (suf == 'Login')
			setTimeout('document.lFloat.login.focus();', 100);
	} else {
		ab.style.display = 'none';
		m.style.display = 'none';
		dis = 'visible';
	}

	toggleDisplay('SELECT', dis);
	toggleDisplay('OBJECT', dis);
	toggleDisplay('EMBED', dis);
	toggleDisplay('IFRAME', dis);

	return false;
}

function i_lForm(form)
{
	form._rand.value = Math.random();
	var pass = form.pass.value;
	if (!pass.match(/^\w+$/i) || !form.scode)
		return true;

	var crypt_pass = hex_md5(pass + form.scode.value);
	form.cpass.value = crypt_pass;
	form.pass.value = '';

	return true;
}

var i_blinkMail;
var i_blinkMailTimer;
var i_blinkMailStep;
function i_blinkM()
{
	if (!i_blinkMail) {
		i_blinkMail = document.getElementById('blinkMail');
		if (!i_blinkMail)
			return;
	}
	if (!i_blinkMailStep) {
		i_blinkMail.style.color='#778';
		i_blinkMailTimer = setTimeout(i_blinkM, 200);
	} else {
		i_blinkMail.style.color='#000';
		i_blinkMailTimer = setTimeout(i_blinkM, 1000);
	}

	i_blinkMailStep = !i_blinkMailStep;
}

var i_reqMail;
function i_checkNewMail()
{
	if (!window.i_user)
		return;
	if (!i_blinkMail) {
		i_blinkMail = document.getElementById('blinkMail');
//		if (!i_blinkMail) {
//			clearInterval(i_checkInterval);
//			return;
//		}
	}
	if (!i_reqMail)
		i_reqMail = new Subsys_JsHttpRequest_Js();

	i_reqMail.onreadystatechange = function() {
		if (i_reqMail.readyState == 4) {
			var count = i_reqMail.responseJS.unseen;
			if (count <= 0)
				count = 0;
			var newMail = document.getElementById('newMail');
			var title = document.title.replace(/\[\d+\]$/, '');
			if (i_blinkMailTimer) {
				clearTimeout(i_blinkMailTimer);
				i_blinkMailTimer = null;
				i_blinkMail.style.color='#000';
			}
			if (count > 0) {
//				alert(count);
				document.title = title + '[' + count + ']';
				i_blinkM();
				var elem = newMail.getElementsByTagName('A')[0];
				elem.title = elem.title.replace(/: \d+$/, ': ' + count);
				elem = newMail.getElementsByTagName('IMG')[0];
				elem.title = elem.title.replace(/: \d+$/, ': ' + count);
				newMail.style.display = '';
			} else {
				document.title = title;
				newMail.style.display = 'none';
			}
			if (i_blinkMail)
				i_blinkMail.title = i_blinkMail.title.replace(/: \d+$/, ': ' + count);

//			aaa
		}
	}

	i_reqMail.caching = false;
//	i_reqMail.open('POST', 'http://chk.i.ua/?request=check_mail', true);
	i_reqMail.open('GET', 'http://i.ua/check_mail.php', true);
	i_reqMail.send({ user: window.i_user });
}

var i_checkInterval = setInterval(i_checkNewMail, 300000);

var i_reqSCode;
function i_updateSCode()
{
	if (!i_reqSCode)
		i_reqSCode = new Subsys_JsHttpRequest_Js();

	i_reqSCode.onreadystatechange = function() {
		if (i_reqSCode.readyState == 4) {
			var scode = i_reqSCode.responseJS.scode;

			var form;
			for (var i = 0; i < document.forms.length; i++) {
				form = document.forms[i];

				if (form.name != 'lFloat' && form.name != 'lform')
					continue;

				var inp = form.scode;
				if (!inp)
					continue;

//				alert(form.name + ' ' + inp.value + ' ' + scode);
				inp.value = scode;
			}
		}
	}

	i_reqSCode.caching = false;
	i_reqSCode.open('GET', 'http://passport.i.ua/js/scode.js', true);
	i_reqSCode.send();
}

var i_sCodeInterval = setInterval(i_updateSCode, 3600000);

function i_removeDefVal(input)
{
	input.value = '';
	input.onfocus = null;
}

function i_keypress(e)
{
	if (!e)
		e = event;

//	DBG(e);
//	return;

	var keyCode = e.keyCode;
	if (e.which)
		keyCode = e.which;
	var tag = '';
	if (e.srcElement)
		tag = e.srcElement.tagName;
	else if (e.target)
		tag = e.target.tagName;

//	alert(keyCode);
//	alert(e.ctrlKey);
//	alert(tag);
//	return;

	switch (keyCode) {
	case 13:
		if (!e.ctrlKey)
			break;
	case 10:
		break;

		var text = null;
		if (window.getSelection) {
//			alert('window.getSelection');
			text = window.getSelection();
		} else if (document.getSelection) {
//			alert('document.getSelection');
			text = document.getSelection();
		} else if (document.selection.createRange) {
//			alert('document.selection.createRange');
			text = document.selection.createRange().text;
		}
		text = String(text);
		if (text.length > 0) {
			if (text.length > 256) {
				alert('Выделите текст меньшего размера.')
			} else {
				if (confirm('Oшибка на странице:\n"' + text + '"\n\nОтослать сообщение об ошибке службе поддержки?\nВаш броузер останется на той же странице.')) {
					var fakedImage = document.createElement('IMG');
					fakedImage.src = 'http://i.ua/page_error.php?text=' + escape(text) + '&url=' + escape(document.location.href);
//					alert(fakedImage.src);
				}
			}
		}

		break;
	case 37:
	case 39:
		if (!e.ctrlKey || tag == 'INPUT' || tag == 'TEXTAREA' || tag == 'SELECT')
			break;

		var link = document.getElementById(keyCode == 37 ? 'prevLink' : 'nextLink');
		if (!link || !link.href)
			break;

		window.location.href = link.href;

		break;
	}
}

if (!b || b.ie) {
	document.onkeydown = i_keypress;
} else {
	if (document.attachEvent)
		document.attachEvent('onkeydown', i_keypress);
	else
		document.addEventListener('keydown', i_keypress, false);
}

function i_showSections(elem)
{
//	alert('i_showSections');
	var allSec = document.getElementById('sections');
	if (!allSec)
		return;

	var cont = elem.parentNode.parentNode;
	var childs = cont.getElementsByTagName('LI');
//	alert(childs.length);
	for (var i = 1; i < childs.length; i++) {
		if (childs[i].className.match(/TopControl/))
			continue;

		childs[i].style.display = childs[i].style.display == 'none' ? 'block' : 'none';
	}
//	alert(cont.tagName);

//	alert(allSec.style.display);
	allSec.style.display = allSec.style.display == 'block' ? 'none' : 'block';
}

