﻿function Marquee (divMarquee)
{
	this.bEnabled = true;
	this.iMarqueeDelay = 80;
	this.divMarquee = divMarquee;

	var me = this;

	this.Init = function()
	{
		me.divMarquee.parentNode.style.position = "relative";
		me.divMarquee.parentNode.style.overflow = "hidden";

		me.divMarquee.style.position = "absolute";
		me.divMarquee.style.whiteSpace = "nowrap";
		me.divMarquee.style.left = Math.floor(GetLayerWidth(me.divMarquee.parentNode)) + "px";
		AddEvent(me.divMarquee, "mouseover", me.Disable);
		AddEvent(me.divMarquee, "mouseout", me.Enable);
		me.MoveMarquee();
	}
	
	this.Enable = function()
	{
		me.bEnabled = true;
		me.MoveMarquee();
	}
	
	this.Disable = function()
	{
		me.bEnabled = false;
	}
	
	this.MoveMarquee = function()
	{
		if(me.bEnabled)
		{
			var iParentWidth = GetLayerWidth(me.divMarquee.parentNode);
			var iLeft = GetLayerLeft(me.divMarquee);
			var iWidth = GetLayerWidth(me.divMarquee);
			if(iWidth < iParentWidth)  // Középre igazítás
			{
				me.divMarquee.style.left = Math.floor((iParentWidth - iWidth)/2) + "px";
				me.bEnabled = false;
			}
			else // Mozgatás
			{
				if(iLeft < -iWidth)
					iLeft = iParentWidth;
				else
					iLeft -= 2;
				me.divMarquee.style.left = iLeft + "px";
				window.setTimeout(me.MoveMarquee, me.iMarqueeDelay);
			}
		}
	}
	me.Init();
}


function ImgButton(img, iWidth, iHeight, srcDefault, srcOver, srcDown, srcActive, strAlt, bTransparent)
{
	this.img = img;
	this.iWidth = iWidth;
	this.iHeight = iHeight;
	this.srcDefault =  srcDefault;
	this.srcOver = (srcOver != undefined ? srcOver : null);
	this.srcDown = (srcDown != undefined ? srcDown : null);
	this.srcActive = (srcActive != undefined && srcActive != null && srcActive.length > 0 ? srcActive : srcDefault);
	this.strAlt = (strAlt != undefined ? strAlt : null);
	this.bTransparent = (bTransparent != undefined ? bTransparent: false);
	this.bActive = false;

	var me = this;
	
	this.SetImage = function(src)
	{
		if(me.bTransparent)
		{
			SetTransparentPng(me.img, src, me.iWidth, me.iHeight, me.strAlt);
		}
		else
		{
			SetImage(me.img, src, me.iWidth, me.iHeight, me.strAlt);
		}
	}

	this.OnMouseOver = function()
	{
		if(!me.bActive)
		{
			if(me.srcOver != null)
				me.SetImage(me.srcOver);
		}
	}
	this.OnMouseOut = function()
	{
		if(me.bActive)
			me.SetImage(me.srcActive);
		else
			me.SetImage(me.srcDefault);
	}
	this.OnMouseDown = function()
	{
		if(me.srcDown != null)
			me.SetImage(me.srcDown);
	}
	this.OnMouseUp = function()
	{
		if(me.srcOver != null)
			me.SetImage(me.srcOver);
	}

	this.SetActive = function(bActive)
	{
		me.bActive = bActive;
		if(me.bActive)
			me.SetImage(me.srcActive);
		else
			me.SetImage(me.srcDefault);
	}
	
	this.IsActive = function()
	{
		return me.bActive;
	}
	
	this.Init = function()
	{
		me.SetImage(me.srcDefault);
		AddEvent(me.img, "mouseover", me.OnMouseOver);
		AddEvent(me.img, "mouseout", me.OnMouseOut);
		AddEvent(me.img, "mousedown", me.OnMouseDown);
		AddEvent(me.img, "mouseup", me.OnMouseUp);
	}
	
	
	me.Init();
}

function ImgLink(a, iWidth, iHeight, srcDefault, srcOver, srcDown, srcActive, strAlt, bTransparent)
{
	this.a = a;
	this.imgButton = null;
	
	var me = this;
	
	this.Create = function(a, iWidth, iHeight, srcDefault, srcOver, srcDown, srcActive, strAlt, bTransparent)
	{
		a.setAttribute('href', 'javascript:void(0)');
		var img = NewTag('img', a);
		//img.className = 'UI_icon';
		img.className = 'UI_input';		
		me.imgButton = new ImgButton(img, iWidth, iHeight, srcDefault, srcOver, null,    srcActive, /*strAlt*/"", bTransparent);
		AddEvent(img, "mouseover", function () {Tip(strAlt);});
		AddEvent(img, "mouseout", function () {UnTip();});
		AddEvent(a, "click", UnTip);
	}
	this.SetActive = function(bActive)
	{
		me.imgButton.SetActive(bActive);
	}
	me.Create(a, iWidth, iHeight, srcDefault, srcOver, srcDown, srcActive, strAlt, bTransparent)
}

function TextButton(divParent, divBefore)
{
	this.strText = null;
	this.strTextActive = null;
	//this.span = null;
	this.divImgParent = null;
	this.divImgBefore = null;

	this.divTextParent = null;
	this.divTextBefore = null;
	
	this.imgButton = null;
	this.aText = null;
	this.aImage = null;
	
	this.strHref = "";
	
	this.OnClick = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		if(divParent != null)
		{
			me.divImgParent = me.divTextParent = divParent;
			me.divImgBefore = me.divTextBefore = divBefore;
			//me.span = NewTag('span', divParent, divBefore);
		}
	}
	
	this.SetHref = function(strLink)
	{
		me.strHref = strLink;
	}
	
	this.AddHref = function(a)
	{
		if(me.strHref != "")
		{
			a.setAttribute('href', me.strHref);
			a.setAttribute('target', '_blank');
		}
		else
			a.setAttribute('href', 'javascript:void(0)');
	}

	this.OnClickInternal = function()
	{
		if(me.OnClick)
			me.OnClick(me);
	}
	
	this.SetActive = function(bActive)
	{
		me.imgButton.SetActive(bActive);
		me.ShowText();
	}
	
	this.IsActive = function()
	{
		return me.imgButton.IsActive();
	}
	
	this.SetImgParent = function(divParent, divBefore)
	{
		me.divImgParent = divParent;
		me.divImgBefore = divBefore;
	}

	this.SetTextParent = function(divParent, divBefore)
	{
		me.divTextParent = divParent;
		me.divTextBefore = divBefore;
	}

	this.CreateImage = function(iWidth, iHeight, srcDefault, srcOver, srcDown, srcActive, bTransparent)
	{
		var a = NewTag('a', me.divImgParent, me.divImgBefore);
		me.AddHref(a);
		me.aImage = a;
		var img = NewTag('img', a);
		img.className = 'UI_icon';
		me.imgButton = new ImgButton(img, iWidth, iHeight, srcDefault, srcOver, null, srcActive, "", bTransparent);
		AddEvent(a, "click", me.OnClickInternal);
		return img;
	}

	this.CreateText = function(strText, strTextActive)
	{
		me.strText = strText;
		if(strTextActive == undefined || strTextActive == null)
			me.strTextActive = strText;
		else
			me.strTextActive = strTextActive;
	
		var a = NewTag('a', me.divTextParent, me.divTextBefore);
		me.AddHref(a);
		AddEvent(a, "click", me.OnClickInternal);
		AddEvent(a, "mouseover", me.imgButton.OnMouseOver);
		AddEvent(a, "mouseout", me.imgButton.OnMouseOut);
		AddEvent(a, "mousedown", me.imgButton.OnMouseDown);
		AddEvent(a, "mouseup", me.imgButton.OnMouseUp);
		me.aText = a;
		me.ShowText();
		return a;
	}
	
	this.ShowText = function()
	{
		if(me.aText)
		{
			while(me.aText.firstChild)
				me.aText.removeChild(me.aText.firstChild);
			
			if(me.imgButton.IsActive())
				NewTextTag(me.strTextActive, me.aText);
			else
				NewTextTag(me.strText, me.aText);
		}
	}
	me.Create(divParent, divBefore);
}

function Panel(divParent, divBefore)
{
	this.table = null;
	this.tr = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_panel_table';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);

		me.table = table;
		me.tr = tr;
	}

	this.CreateCaption = function(strText, strImageUrl, iWidth, iHeight)
	{
		var td = NewTag('td', me.tr);
		td.className = "strong";
		if(strImageUrl != null && strImageUrl.length > 0)
		{
			var img = NewTag('img', td);
			img.className = 'UI_icon';
			SetImage(img, strImageUrl, iWidth, iHeight, "");
		}
		var span = NewTag('span', td);
		return NewTextTag(strText, span);
	}

	me.Create(divParent, divBefore);
}

function ColorPanel(divParent, divBefore)
{
	this.table = null;
	this.td = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table, tbody, tr, td;
		table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_colorpanel';
		me.table = table;

		tbody = NewTag('tbody', table);
		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel_top';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';

		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		me.td = td;
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';

		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel_bottom';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';
	}

	this.CreateCaption = function(strText, strImageUrl, iWidth, iHeight)
	{
		var div = NewTag('div', me.td);
		div.className = "strong";
		if(strImageUrl != null && strImageUrl.length > 0)
		{
			var img = NewTag('img', div);
			img.className = 'UI_icon';
			SetImage(img, strImageUrl, iWidth, iHeight, "");
		}
		return NewTextTag(strText, div);
	}

	me.Create(divParent, divBefore);
}

function WhitePanel(divParent, divBefore)
{
	this.table = null;
	this.td = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table, tbody, tr, td;
		table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_whitepanel';
		me.table = table;

		tbody = NewTag('tbody', table);
		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel_top';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';

		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		me.td = td;
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';

		tr = NewTag('tr', tbody);
		tr.className = 'UI_panel_bottom';
		td = NewTag('td', tr);
		td.className = 'UI_panel_left';
		td = NewTag('td', tr);
		td.className = 'UI_panel';
		td = NewTag('td', tr);
		td.className = 'UI_panel_right';
	}
	me.Create(divParent, divBefore);
}


function InputBox(divParent, divBefore)
{
	this.table = null;
	this.tr = null;
	this.tdInput = null;
	this.tdLeftRound = null;
	this.tdRightRound = null;
	this.input = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_input_container';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);
		me.table = table;
		me.tr = tr;
		
		me.CreateInput();
	}
	
	this.CreateInput = function()
	{
		var td = NewTag('td', me.tr);
		td.style.padding = "0px";
		td.style.width = "3px";
		var img = NewTag('img', td);
		img.className = 'UI_input';
		SetImage(img, "design/UI_input_text_left.gif", 3, 22, "");
		me.tdLeftRound = td;
		
		td = NewTag('td', me.tr);
		td.className = 'UI_input_text_container';
		td.style.padding = "0px";
		var input = NewTag('input');
		input.setAttribute('type', 'text');
		input.className = 'UI_input_text';
		AddTag(input, td);
		me.tdInput = td;

		var td = NewTag('td', me.tr);
		td.style.padding = "0px";
		td.style.width = "3px";
		var img = NewTag('img', td);
		img.className = 'UI_input';
		SetImage(img, "design/UI_input_text_right.gif", 3, 22, "");
		me.tdRightRound = td;

		me.input = input;
	}
	
	this.AppendTd = function()
	{
		var td = NewTag('td', me.tr, null);
		return td;
	}
	this.InsertTd = function()
	{
		var td = NewTag('td', me.tr, me.tdInput.previousSibling);
		return td;
	}
	
	this.AppendIconTd = function()
	{
		var img = me.tdRightRound.firstChild;
		img.setAttribute('src', "design/UI_input_icon_right.gif");
		var td = NewTag('td', me.tr, me.tdRightRound);
		return td;
	}
	
	me.Create(divParent, divBefore);
}

function PasswordBox(divParent, divBefore)
{
	this.table = null;
	this.tr = null;
	this.tdInput = null;
	this.tdLeftRound = null;
	this.tdRightRound = null;
	this.input = null;

	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_input_container';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);
		
		var td = NewTag('td', tr);
		td.style.padding = "0px";
		td.style.width = "3px";
		var img = NewTag('img', td);
		img.className = 'UI_input';
		SetImage(img, "design/UI_input_text_left.gif", 3, 22, "");
		me.tdLeftRound = td;
		
		td = NewTag('td', tr);
		td.className = 'UI_input_text_container';
		td.style.padding = "0px";
		var input = NewTag('input');
		input.setAttribute('type', 'password');
		input.className = 'UI_input_text';
		AddTag(input, td);
		me.tdInput = td;

		var td = NewTag('td', tr);
		td.style.padding = "0px";
		td.style.width = "3px";
		var img = NewTag('img', td);
		img.className = 'UI_input';
		SetImage(img, "design/UI_input_text_right.gif", 3, 22, "");
		me.tdRightRound = td;

		me.table = table;
		me.tr = tr;
		me.input = input;
	}

	this.InsertTd = function()
	{
		var td = NewTag('td', me.tr, me.tdInput.previousSibling);
		return td;
	}

	me.Create(divParent, divBefore);
}

function Menu(divParent, divBefore)
{
	this.table = null;
	this.tr = null;
	this.tdMiddle = null;

	var me = this;
	
	this.OnMenuItemClick = function(pEvent)
	{
		var links = me.tr.getElementsByTagName('a');
		for(var i=0; i<links.length; i++)
		{
			if(links[i].className == "selected")
				links[i].className = "";
		}
		var a = GetEventSourceElement(pEvent);
		a.className = "selected";
	}
	
	this.CreateTdLeft = function()
	{
		if(me.tr)
		{
			var td = NewTag('td', me.tr, me.tdMiddle);
			td.className = 'UI_main_menu';
			var td_sep = NewTag('td', me.tr, me.tdMiddle);
			td_sep.className = 'UI_main_menu_separator';
			return td;
		}
	}

	this.CreateTdRight = function()
	{
		if(me.tr)
		{
			var td_sep = NewTag('td', me.tr, me.tr.lastChild);
			td_sep.className = 'UI_main_menu_separator';
			var td = NewTag('td', me.tr, me.tr.lastChild);
			td.className = 'UI_main_menu';
			return td;
		}
	}

	this.AddMenuItemLeft = function(strText, onClick, strLink)
	{
		var td = me.CreateTdLeft();
		var a = NewTag('a', td);
		if(strLink != null)
		{
			a.setAttribute('href', strLink);
			a.setAttribute('target', '_blank');
		}
		else
			a.setAttribute('href', 'javascript:void(0)');
		if(onClick != null)
			AddEvent(a, "click", onClick);
		if(strLink == null)
			AddEvent(a, "click", me.OnMenuItemClick);
		NewTextTag(strText, a);
		return a;
	}

	this.AddMenuItemRight = function(strText, onClick)
	{
		var td = me.CreateTdRight();
		var a = NewTag('a', td);
		a.setAttribute('href', 'javascript:void(0)');
		if(onClick != null)
			AddEvent(a, "click", onClick);
		AddEvent(a, "click", me.OnMenuItemClick);
		NewTextTag(strText, a);
		return a;
	}
		
	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'UI_main_menu_container';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		td.className = 'UI_main_menu_left';
		
		td = NewTag('td', tr);
		td.className = 'UI_main_menu';
		/*td.style.width = '100%';*/
		this.tdMiddle = td;
		
		td = NewTag('td', tr);
		td.className = 'UI_main_menu_right';
		
		me.table = table;
		me.tr = tr;
	}
	me.Create(divParent, divBefore);
}

function Note(divParent, divBefore)
{
	this.table = null;
	this.th = null;
	this.td = null;
	
	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'note';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);
		var th = NewTag('th', tr);
		tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		me.table = table;
		me.th = th;
		me.td = td;
	}
	
	this.CreateCaption = function(strText, strImageUrl, iWidth, iHeight)
	{
		var td = NewTag('td', me.tr);
		td.className = "strong";
		if(strImageUrl != null && strImageUrl.length > 0)
		{
			var img = NewTag('img', td);
			img.className = 'UI_icon';
			SetImage(img, strImageUrl, iWidth, iHeight, "");
		}
		NewTextTag(strText, td);
	}
	
	me.Create(divParent, divBefore);
}


function Alert(divParent, divBefore)
{
	this.table = null;
	this.th = null;
	this.td = null;
	
	var me = this;

	this.Create = function(divParent, divBefore)
	{
		var table = NewTag('table', divParent, divBefore);
		table.cellPadding = 0;
		table.cellSpacing = 0;
		table.className = 'alert';
		var tbody = NewTag('tbody', table);
		var tr = NewTag('tr', tbody);
		var th = NewTag('th', tr);
		tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		me.table = table;
		me.th = th;
		me.td = td;
	}
	
	this.CreateCaption = function(strText, strImageUrl, iWidth, iHeight)
	{
		var td = NewTag('td', me.tr);
		td.className = "strong";
		if(strImageUrl != null && strImageUrl.length > 0)
		{
			var img = NewTag('img', td);
			img.className = 'UI_icon';
			SetImage(img, strImageUrl, iWidth, iHeight, "");
		}
		NewTextTag(strText, td);
	}
	
	me.Create(divParent, divBefore);
}

function AddThreeColRow(table, strCssClass)
{
	var strCssBase = strCssClass;
	var strEnd = "_container";
	var iPos = strCssClass.length - strEnd.length;
	if(iPos >= 0 && strCssClass.substr(iPos) == strEnd)
		strCssBase = strCssClass.substr(0,iPos);

	var tbody = table.firstChild;
	if(!tbody)
		tbody = NewTag('tbody', table);
	var tr = NewTag('tr', tbody);
	var td = NewTag('td', tr);
	td.className = strCssBase +'_left';
	var img = NewTag('img', td);
	SetImage(img, GetAbsUrl('design/clear.gif'), 1, 1);

	var tdMain = NewTag('td', tr);
	tdMain.className = strCssBase;

	var td = NewTag('td', tr);
	td.className = strCssBase + '_right';
	var img = NewTag('img', td);
	SetImage(img, GetAbsUrl('design/clear.gif'), 1, 1);

	return tdMain;
}
