var timeout_html;

/*
	Timeout
	=======
*/

function preload_timeout()
{
	timeout_html = tpl_load("/timeout.tpl");
}

function show_timeout()
{
	var ui_op = 65;

	if(document.getElementById("timeout_div"))
		return;

	setJumperState("disabled");

	var d = document.createElement("div");
	d.setAttribute("id", "timeout_div");
	d.setAttribute("align", "center");
	
	var h = document.body.clientHeight + 20;
	
	var style = "position: absolute; top: 0px; left: 0px; width: 100%; height: " + h + "px;";
	style += "background-color:#000000; filter:alpha(opacity=" + ui_op + ");-moz-opacity:." + ui_op + ";opacity:." + ui_op + ";";
	style += "color: #FFFFFF;";
	d.style.cssText = style;
	
	d.innerHTML = timeout_html;

	document.body.insertBefore(d, document.body.firstChild);
}





/*
	Töltősáv
	========
*/
function loader_mover()
{
	var d = document.getElementById("loader_div");
	d.style.cssText = loader_generate_style();
}

function loader_generate_style()
{
	var w = 200;
	var h = 100;

	var y = 0;
	var x = 0;
	if(isIE)
	{
		y += document.documentElement.scrollTop;
		y += document.documentElement.clientHeight/2 - 100;
		x += document.documentElement.clientWidth/2 - 100;
	}
	else
	{
		y += window.pageYOffset;
		y += window.innerHeight/2 - 100;
		x += window.innerWidth/2 - 100;
	}
	
	// Elhelyezés, méretek
	var style = "position: absolute; top: " + y + "px; left: " + x + "px; width: " + w + "px; height: " + h + "px;";
	style += "background-color:#EEEEEE; border: solid 2px #000000; vertical-align: middle; text-align: center;";
	style += "z-index: 10000;";
	
	return style;
}

function show_loader()
{
	if(document.getElementById("loader_div"))
		return;

	window.onscroll = loader_mover;

	var d = document.createElement("div");
	d.setAttribute("id", "loader_div");
	d.style.cssText = loader_generate_style();
	tpl = new Themeplaty3();
	tpl.setLabels(global_labels);
	tpl.setVar("theme", theme_name);
	html = tpl.parse(loader_tpl);
	if(isIE)
		d.innerHTML = "<br>" + html;
	else
		d.innerHTML = html;
	
	document.body.insertBefore(d, document.body.firstChild);
}

function hide_loader()
{
	d = document.getElementById("loader_div");
	document.body.removeChild(d);
	window.onscroll = null;
}





/*
	Üzenetablak
	===========
*/

function MessageBox(_instance)
{
	this.locked = false;
	this.instance_name = _instance;
	this.element_id = "message_box_" + this.instance_name;
}

MessageBox.prototype.open = function (_title, _html)
{
	if(document.getElementById(this.element_id))
		return;

	// Elem létrehozása
	var d = document.createElement("div");
	d.setAttribute("id", this.element_id);
	
	d.style.cssText = this.generateStyle();
	
	// Sablon letöltése
	tpl = new Themeplaty3();
	tpl.setVar("title", _title);
	tpl.setVar("html", _html);
	tpl.setVar("instance_name", this.instance_name);
	tpl.setVar("theme_name", theme_name);
	d.innerHTML = tpl.parse(message_box_tpl);
	
	// Beállítás
	this.locked = false;
	eval("window.onscroll = function () { " + this.instance_name + ".update(); }");
	document.body.insertBefore(d, document.body.firstChild);
}

MessageBox.prototype.close = function ()
{
	d = document.getElementById(this.element_id);

	document.body.removeChild(d);
	
	window.onscroll = null;
}

MessageBox.prototype.update = function ()
{
	var d = document.getElementById(this.element_id);
	d.style.cssText = this.generateStyle();
}

MessageBox.prototype.toggleLock = function ()
{
	this.locked = !this.locked;

	if(!this.locked)
		eval("window.onscroll = function () { " + this.instance_name + ".update(); }"); 	
	else
		window.onscroll = null;
}

MessageBox.prototype.generateStyle = function ()
{
	var w = (document.body.clientWidth-100);
	var op = 95;

	var y = 50;
	if(isIE)
		y += document.body.scrollTop;
	else
		y += window.pageYOffset;
		
	var style = "position: absolute; top: " + y + "px; left: 30px; width: " + w + "px;";
	style += "background-color:#EEEEEE; filter:alpha(opacity=" + op + ");-moz-opacity:." + op + ";opacity:." + op + "; ";
	style += "border: solid 2px #000000;";
	
	return style;
}

function MessageBoxFactory(_name)
{
	eval(_name + " = new MessageBox('" + _name + "');");
}
