var msg = {
	content: '', 
	top: 100, 
	wait: 0,
	type: 'message',
	timeout: 0,
	mode: '',
	auto: null,
	
	defined: function(mode)
	{
		this.mode = mode;
		this.close();
		this.setcontent('');
		this.settype('');
		this.settitle('');

		switch(mode)
		{
			case 'unload':
				this.settitle('Bitte warten');
				this.setcontent('Die Seite wird geladen...');
			break;
			
			case 'test':
				this.setcontent('cool wa cool wa cool wa cool wa cool wa cool wa');
				this.autokill(3);
			break;		
		}
		this.display(true, 'message_box');
	},
	
	open: function(title, text, type, wait)
	{
		this.close();
		this.setcontent(text);
		this.settype(type);
		this.settitle(title);
				
		if(wait == 0)
		{
			this.display(true, 'message_box');
		}
		else
		{
			this.sleep(wait);
			this.display(true, 'message_box');
		}
	},
	
	display: function(status, div)
	{
		this.box = this.get(div);
		if(this.box)
		{
			if(status)
			{
				this.box.style.display = 'block';
				if(div == 'message_box' && this.mode != 'unload')
				{
					window.scrollTo(0, 0);
				}
			}
			else
			{
				this.box.style.display = 'none';
			}
		}
	},
	
	settype: function(type)
	{
		this.type = type;
		this.box = this.get('message_box');
		
		if(this.box)
		{
			switch(this.type)
			{
				case 'error':
					this.box.className = 'message error';
				break;
				
				case 'warning':
					this.box.className = 'message warning';
				break;
				
				default:
				case 'message':
					this.box.className = 'message';
				break;
			}
		}
	},
	
	settitle: function(title)
	{
		this.title = this.get('message_title');
		if (this.title)
		{
			if(title == '')
			{
				title = 'Information';
			}
		
			this.title.innerHTML = '<h2><span>'+title+'</span></h2>';
			this.display(true, 'message_title');
		}
	},
	
	setcontent: function(text)
	{
		this.content = this.get('message_content');
		if (this.content)
		{
			this.content.innerHTML = text;
		}
	},
	
	close: function(kill)
	{
		if(kill)
		{
			this.clearauto();
		}
		
		this.display(false, 'message_box');
		this.display(false, 'message_title');		
		this.settype('message');
		this.setcontent('');
	},
	
	sleep: function(sec)
	{
		var milisec = sec*1000;
		var date = new Date();
		var curDate = null;
		
		do { curDate = new Date(); }
		while(curDate-date < milisec);
	},
	
	autokill: function(sec)
	{
		this.auto = window.setInterval("msg.close(true)", sec*1000);
	},
	
	clearauto: function()
	{
		window.clearInterval(this.auto);
		this.auto = null;
	},
	
	get: function(id)
	{
		return document.getElementById(id);
	},
	
	set: function(id, inhalt)
	{
		return document.getElementById(id).innerHTML = inhalt;
	},
}