window.onerror = null;

function flash(f, w, h, vars)
{
	document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000">'+
	'<param name="allowscriptaccess" value="samedomain" />'+
	'<param name="movie" value="/flash/'+f+'.swf" />'+
	'<param name="wmode" value="transparent" />'+
	'<param name="bgcolor" value="#5C1D01" />'+
	'<param name="swliveconnect" value="true" />'+
	(vars?'<param name="flashvars" value="'+vars+'" />':'')+
	'<embed src="/flash/'+f+'.swf" allowScriptAccess="samedomain" wmode="transparent" bgcolor="#5C1D01" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"'+(vars?' flashvars="'+vars+'"':'')+' width="'+w+'" height="'+h+'" swliveconnect="true" /></object>');
}

function vis(id, ob)
{
	var nob = document.getElementById(id);
	if (nob.style.display=='block')
	{
		nob.style.display = 'none';
		if (ob) ob.innerHTML = ob.show;
	}
	else
	{
		if (ob)
		{
			if (!ob.show) ob.show = ob.innerHTML;
			ob.innerHTML = ob.hide;
		}
		nob.style.display = 'block';
	}
	return false;
}

function check(val1, val2) { return !(val1==val2) }

function search_user(form)
{
	window.open('/forum/search.php?mode=searchuser'+(form?'&form_name='+form:''), '_phpbb_search', 'height=250,resizable=yes,width=400');
	return false
}

function down(el)
{
	document.onselectstart = function () {return false};
	document.onmouseup = function() {document.onmouseup = document.onselectstart = document.onmousemove = null};
	el.dX = el.win.style.pixelLeft-(event.clientX+document.body.scrollLeft);
	el.dY = el.win.style.pixelTop-(event.clientY+document.body.scrollTop);
	document.onmousemove = function() {el.move(event.clientX+document.body.scrollLeft, event.clientY+document.body.scrollTop)};
}

function move(el, newX, newY)
{
	newX += el.dX;
	newY += el.dY;
	var h = document.body.clientHeight+document.body.scrollTop-el.win.style.pixelHeight-105;
	var w = document.body.clientWidth+document.body.scrollLeft-el.win.style.pixelWidth;
	if (newX>w) newX = w;
	if (newY>h) newY = h;
	el.win.style.pixelLeft = newX;
	el.win.style.pixelTop = newY;
}

Login =
{
	created: false,
	dX: 0,
	dY: 0,
	win: null,
	username: null,

	create: function(redirect)
	{
		this.win = document.getElementById('login');
		this.win.innerHTML =
			'<form method="post" action="/login.php">' +
			'<input type="hidden" name="redirect" value="'+redirect+'" />'+
			'<table cellspacing="1" class="line" align="center">'+
			'<tr><th style="cursor:move" onmousedown="Login.down()" width="80">Вход</th><th style="cursor:move" onmousedown="Login.down()" width="200">&nbsp;</th><th><input class="but" style="width:22px;padding:0" type="button" onclick="Login.hide()" value="X"></th></tr>'+
			'<tr class="row1"><td><label for="username">Логин</label>:</td><td colspan="2"><input style="width:100%" class="post" type="text" id="username" name="username" /></td></tr>'+
			'<tr class="row1"><td><label for="password">Пароль</label>:</td><td colspan="2"><input style="width:100%" class="post" type="password" id="password" name="password" /></td></tr>'+
			'<tr class="row1"><td colspan="3"><label for="autologin">Автоматически входить</label> &nbsp; <input class="text" type="checkbox" id="autologin" name="autologin" /></td></tr>'+
			'<tr class="foot"><td colspan="3"><input type="submit" class="but" name="login" value="Войти!" /></td></tr>'+
			'</table></form>';
		this.win.style.pixelWidth = 330;
		this.win.style.pixelHeight = 100;
		this.username = document.getElementById('username');
		this.created = true;
	},

	show: function(redirect)
	{
		if (!this.created) this.create(redirect);
		if (this.win.style.visibility!='visible')
		{
			this.win.style.visibility = 'visible';
			this.win.style.display = 'block';
			this.dX = this.dY = 0;
			this.move(document.body.scrollLeft+event.clientX-165, document.body.scrollTop+event.clientY+15);
		}
		this.username.focus()
		return false;
	},

	hide: function()
	{
		this.win.style.visibility = 'hidden';
		this.win.style.display = 'none';
		return false;
	},

	down: function()
	{
		down(this);
	},

	move: function(newX, newY)
	{
		move(this, newX, newY);
	}
}

Popup =
{
	m: true,
	created: false,
	win: null,
	name: null,
	frame: null,
	status: null,
	type: 0,
	dX: 0,
	dY: 0,
	interval: 0,
	timeout: 0,
	widths: new Array('', 312, 1006),
	heights: new Array('', 335, 404),
	names: new Array('', '', 'Лог боя №'),
	srcs: new Array('', 'http://www.timezero.ru/info.swf?login=', 'http://www.timezero.ru/sbtl.swf?language=ru&battleid='),

	create: function()
	{
		this.win = document.getElementById('popup');
		this.win.innerHTML =
			'<table cellspacing="1" class="line" align="center">'+
			'<tr><th style="cursor:move" onmousedown="Popup.down()" id="name"></th><th><input class="but" style="width:22px;padding:0" type="button" onclick="Popup.hide()" value="X"></th></tr>'+
			'<tr><td colspan="2" id="frame" bgcolor="#5F6272">&nbsp;</td></tr>'+
			'<tr class="foot"><td colspan="2" style="text-align:left" id="status">&nbsp;</td></tr>'+
			'</table>';
		this.name = document.getElementById('name');
		this.frame = document.getElementById('frame');
		this.status =  document.getElementById('status');
		this.created = true;
	},

	show: function(id, type, m)
	{
		if (!id || !type) return false;
		if (!this.created) this.create();
		var n = false;
		if (this.name.innerHTML = this.names[type]+id)
		{
			if (this.type!=type)
			{
				switch (type)
				{
					case 1:
					case 2:
						this.win.style.pixelWidth = this.widths[type];
						this.win.style.pixelHeight = this.heights[type]-30;
						this.frame.style.pixelHeight = this.heights[type];
				}
				this.name.style.pixelWidth = this.win.style.pixelWidth-30;
				this.type=type;
			}
			this.frame.innerHTML = '&nbsp;';
			this.name.innerHTML = this.names[type]+id;
			this.load(id, type)
			n = true;
		}
		if (n || this.win.style.visibility!='visible')
		{
			if (!m)
			{
				this.dX = this.dY = 0;
				switch (type)
				{
					case 1: this.move(document.body.scrollLeft+event.clientX+15, document.body.scrollTop+event.clientY-15); break;
					case 2: this.move(document.body.clientWidth/2, document.body.clientHeight/2);
				}
			}
			this.m = m;
			this.win.style.visibility = 'visible';
			this.win.style.display = 'block';
		}
		return false;
	},

	changeTimeout: function()
	{
		this.status.innerHTML = 'Задержка запроса: '+(--this.timeout/10)+' секунд';
		if (this.timeout<=0)
		{
			this.status.innerHTML = '&nbsp;';
			clearInterval(this.interval);
		}
	},

	load: function(id, type)
	{
		setTimeout('Popup.frame.innerHTML = \'<iframe frameborder="0" height="100%" width="100%" scrolling="no" onunload="Popup.hide()" src="\'+Popup.srcs[\''+type+'\']+\''+id+'\'+\'"></iframe>\'', this.timeout*100);
		clearInterval(this.interval);
		if (this.timeout<=0) this.timeout = 30;
		this.interval = setInterval('Popup.changeTimeout()', 100);
	},

	hide: function()
	{
		if (this.m) window.close();
		else
		{
			this.win.style.visibility = 'hidden';
			this.win.style.display = 'none';
		}
		return false;
	},

	down: function()
	{
		down(this);
	},

	move: function(newX, newY)
	{
		move(this, newX, newY);
	}
}