var Lok="OK";
var Lcancel="Abbrechen";

var imagesPath="style/icons/dialog/";

var barList = new msgBarList();

function infoBox(text)
{
	var messageBar = new msgBar();
	messageBar.text = text;
	messageBar.Show();
	return messageBar;
}

function errorBox(text)
{
	var messageBar = new msgBar();
	messageBar.text = text;
	messageBar.icon = "error";
	messageBar.Show();
	return messageBar;
}

function messageBar(icon, text, OKFunction, cancel, close, lock)
{
	var messageBar = new msgBar();
	messageBar.icon = icon;
	messageBar.text = text;
	messageBar.OKFunction = OKFunction;
	messageBar.cancel = cancel;
	messageBar.close = close;
	messageBar.lock = lock;
	messageBar.Show();
	return messageBar;
}

function msgBarList()
{
	this.bars = new Array();
	
	this.add = function(bar)
	{
		return this.bars.push(bar);
	}
	
	this.length = function()
	{
		return this.bars.length;
	}
	
	this.Blink = function()
	{
		elements = document.getElementsByClassName('lock');

                if(elements.length == 0)
                    return;
                
		elements.each(function(element)
		{
			counter = 0;
			element.style.backgroundColor = "red";
			blinkInterval = window.setInterval(function()
			{
				switch(counter)
				{
					case 0: 
						element.style.backgroundColor = "#fffebf";
						break;
					case 1:
						element.style.backgroundColor = "red";
						break;
					case 2:
						element.style.backgroundColor = "#fffebf";
						window.clearInterval(blinkInterval);
				}
				counter++;
			}, 200);
		});
	}
}

function msgBar()
{
	this.id		= barList.add(this);
	
	this.icon	= "information";
	this.text	= "";
	this.cancel	= false;
	this.close	= true;
	this.lock	= false;
	this.divElement	= null;
	
	this.OKFunction	= function() { }
	
	this.doOK = function()
	{
		this.OKFunction();
		if(this.close)
			this.Close();
	}
	
	this.Show = function()
	{
		if(this.lock)
			$('lock').style.display = "block";
		
		var CloseString		= 'barList.bars[' + (this.id-1) + '].Close();';
		var OKfunctionString 	= 'barList.bars[' + (this.id-1) + '].doOK();';
		
		this.divElement = document.createElement('div');
		this.divElement.setAttribute('class', 'messageBar button' + ((this.lock)?' lock':''));
		if(isIE())
		{
			this.divElement.style.backgroundColor = "#fffebf";
			this.divElement.style.borderBottom = "1px dotted gray";
		}
		
		this.divElement.setAttribute('style', 'background-image: url(' + imagesPath + 'dialog-' + this.icon + '.png);');
		this.divElement.setAttribute('onkeydown', 'if(event.keyCode==13){' + OKfunctionString + '}');
		
		var ieOxMsgBar = "";
		var ieOxMsgBtn = "";
		var ieOxMsgBtnA = "";
		if(isIE())
		{
			
			ieOxMsgBar = ' height: 32px; position: relative; width: 100%; z-index: 20; background: #fffebf url(icons/dialog/dialog-error.png) no-repeat 20px center; display: block; border-bottom: 1px dotted gray;"';
			ieOxMsgBtn = ' style="position: absolute; right: 20px; z-index: 25;"';
			ieOxMsgBtnA = ' style="position:absolute; top: -31px; height: 32px; margin: 6px 0 6px 6px; padding: 3px 6px 3px 22px; top: 8px; position: relative; color: black; background: url(icons/dialog/dialog-ok.png) no-repeat 3px center; cursor: pointer;"';
		}
		
		var txt = '<div class="msgBarMessage"' + ieOxMsgBar + '>' + this.text + '</div><div class="msgBarButtons"' + ieOxMsgBtn + '><a onclick="' + OKfunctionString + '"' + ieOxMsgBtnA + '>' + Lok + '</a>';
		if(this.cancel)
			txt = txt + '<a style="background-image: url(' + imagesPath + 'dialog-cancel.png);" onclick="' + CloseString + '">' + Lcancel + '</a>';
		txt = txt + '</div>';
		
		this.divElement.innerHTML = txt;
		$('messageBars').appendChild(this.divElement);
		
//TODO: ie ox 
		if(this.divElement.down('input') != undefined)
		{
			this.divElement.down('input').focus();
		}
	}
	
	this.Close = function()
	{
		if(this.lock)
			$('lock').style.display = "none";
		
		$('messageBars').removeChild(this.divElement);
	}
	
	this.ShowId = function()
	{
		alert(this.id);
	}
	
	return this;
}

function wait()
{
	$('wait').style.display = "block";
}

function endWait()
{
	$('wait').style.display = "none";
}


function isIE()
{
	if(navigator.appName == "Microsoft Internet Explorer")
		return true;
	return false;
}	


