var commandQueue = new Array();
var currentCommand = 0;
var cc_timeout = 50;

function doQueue()
{
	if(commandQueue[currentCommand])
	{
		if(eval(commandQueue[currentCommand]))
		{
			currentCommand++;
			//alert(commandQueue[currentCommand]);
		}
		window.setTimeout('doQueue();', cc_timeout);
	}
}

function wait(t)
{
	t -= cc_timeout;
	if(t == 0)
	{
		return true;
	}
	else
	{
		commandQueue[currentCommand] = "wait(" + t + ");";
		return false;
	}
}

function moveBox(id, x, y)
{
	var obj = document.getElementById(id);
	var cury = obj.offsetLeft;
	var curx = obj.offsetLeft;
	if(Math.abs(cury - y) > 5 || Math.abs(curx - x) > 5)
	{
		obj.style.top = Math.round(cury + (y - cury) / 5) + "px";
		obj.style.left = Math.round(curx + (x - curx) / 5) + "px";
		return false;
	}
	else
	{
		return true;
	}
}

function fade(id, end, speed)
{
	speed = parseFloat(speed);
	end = parseFloat(end);
	var to = 50;
	var obj = document.getElementById(id);

	if(obj.filters && !obj.filters.alpha)
		obj.style.filter = "Alpha(opacity=100)";
	if (obj.filters)
		var opacity = parseFloat(obj.filters.alpha.opacity);
	else if (document.defaultView.getComputedStyle && document.defaultView.getComputedStyle(obj, null).getPropertyValue("opacity"))
		var opacity = parseFloat(document.defaultView.getComputedStyle(obj, null).getPropertyValue("opacity")) * 100;
	else
		return true;
	if(isNaN(opacity))
		opacity = 100;
	
	if(opacity != end)
	{
		var dir = (end - opacity) / Math.abs(end - opacity);
		opacity += speed * dir;
		if(obj.filters)
			obj.filters.alpha.opacity = opacity;
		else
			obj.style.opacity = opacity / 100;
		return false;
	}
	else
	{
		return true;
	}
}

function destroyBox(id)
{
	if(document.getElementById(id))
		document.getElementsByTagName("body")[0].removeChild(document.getElementById(id));
	return true;
}

function waitForBody()
{
	var ret = document.getElementsByTagName("body").length > 0 ? true : false;
	return ret;
}

var _inddls = new Array();
var _inlbs = new Array();

var hideCounter=0;

function hideDropDownLists() {
	if (navigator.appName != "Microsoft Internet Explorer") return true;
	var element;

    _inddls = document.getElementsByTagName("select");

	if (++hideCounter != 1 || typeof(_inddls) == "undefined" || _inddls.length == 0) return true;
	for (var i=0; i < _inddls.length; i++) {
		element = _inddls[i];
		if (element != null) {
			var tb = document.createElement("input");
			tb.type = "text";
			tb.value = element.options[element.selectedIndex].text;
			tb.style.width = element.offsetWidth;
			tb.style.height = element.offsetHeight - 5;
			element.parentNode.insertBefore(tb, element);
			element.style.display = "none";
		}
	}

	return true;
}

function showDropDownLists() {
	if (navigator.appName != "Microsoft Internet Explorer") return true;
	var element;

	if (--hideCounter != 0 || typeof(_inddls) == "undefined" || _inddls.length == 0) return true;
	for (var i=0; i < _inddls.length; i++) {
		element = _inddls[i];
		if (element != null) {
			element.parentNode.removeChild(element.previousSibling);
			element.style.display = "inline";
		}
	}
	return true;
}

function transHack()
{
if(!document.getElementsByTagName("body")[0].filters && !document.defaultView.getComputedStyle(document.getElementsByTagName("body")[0], null).getPropertyValue("opacity"))
{
	var th = document.createElement("div");
	th.id = "transhack";
	document.getElementsByTagName("body")[0].appendChild(th);
}
return true;
}

function createBox(id, str, centered)
{
	var body = document.getElementsByTagName("body");
	var div = document.createElement("div");
	div.style.opacity = "0";
	div.style.filter = "Alpha(opacity = 0)";
	div.id = id;
	div.innerHTML = '<table style="border: solid black 1px; width: 250px;" height="50" class="box_wo" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="tl"></td><td class="tc"></td><td class="tr"></td></tr><tr height="100%" valign="middle"><td><table border="0" cellpadding="0" cellspacing="0" height="100%"><tbody><tr><td class="tcl"></td></tr><tr><td class="l"></td></tr><tr valign="middle"><td class="bcl"></td></tr></tbody></table></td><td class="content" align="center">' + str + '</td><td><table border="0" cellpadding="0" cellspacing="0" height="100%"><tbody><tr><td class="tcr"></td></tr><tr><td class="r"></td></tr><tr><td class="bcr"></td></tr></tbody></table></td></tr><tr><td class="bl"></td><td class="bc"></td><td class="br"></td></tr></tbody></table>';
	body[0].appendChild(div);

	div.style.position = "absolute";
	div.style.top = "80px";
	div.style.left = "100px";

	return true;
}

function statusMessage(text)
{
	commandQueue[commandQueue.length] = "waitForBody();";
	commandQueue[commandQueue.length] = "hideDropDownLists();";
	commandQueue[commandQueue.length] = "createBox('status', '" + text + "');";
	commandQueue[commandQueue.length] = "transHack();";
	commandQueue[commandQueue.length] = "fade('content', 40, 10);";
	commandQueue[commandQueue.length] = "fade('status', 100, 20);";
	commandQueue[commandQueue.length] = "wait(2000);";
	commandQueue[commandQueue.length] = "fade('status', 0, 20);";
	commandQueue[commandQueue.length] = "fade('content', 100, 10);";
	commandQueue[commandQueue.length] = "showDropDownLists();";
	commandQueue[commandQueue.length] = "destroyBox('status');";
	commandQueue[commandQueue.length] = "destroyBox('transhack');";
	doQueue();
}

function statusMessageFragebogen(text)
{
	commandQueue[commandQueue.length] = "waitForBody();";
	commandQueue[commandQueue.length] = "hideDropDownLists();";
	commandQueue[commandQueue.length] = "createBoxFragebogen('status', '" + text + "');";
	commandQueue[commandQueue.length] = "transHack();";
	commandQueue[commandQueue.length] = "fade('maintable', 40, 10);";
	commandQueue[commandQueue.length] = "fade('status', 100, 20);";
	commandQueue[commandQueue.length] = "wait(2000);";
	commandQueue[commandQueue.length] = "fade('status', 0, 20);";
	commandQueue[commandQueue.length] = "fade('maintable', 100, 10);";
	commandQueue[commandQueue.length] = "showDropDownLists();";
	commandQueue[commandQueue.length] = "destroyBox('status');";
	commandQueue[commandQueue.length] = "destroyBox('transhack');";
	doQueue();
}

function createBoxFragebogen(id, str, centered)
{
	var body = document.getElementsByTagName("body");
	var div = document.createElement("div");
	div.style.opacity = "0";
	div.style.filter = "Alpha(opacity = 0)";
	div.id = id;
	div.innerHTML = '<table style="border: solid red 1px; width: 250px;" height="50" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="100%" valign="middle"><td class="content" align="center">' + str + '</td></td></tr></tbody></table>';
	body[0].appendChild(div);

	div.style.position = "absolute";
	div.style.left = "220px";
	
	var scrollYPos;
	var height;
	
	if (typeof window.pageYOffset != 'undefined')
	{
		scrollYPos = window.pageYOffset;
		height = window.innerHeight;
	}
	else if (document.compatMode && document.compatMode != 'BackCompat')
	{
		scrollYPos = document.documentElement.scrollTop;
		height = document.documentElement.offsetHeight;
	}
	else
	{
		scrollYPos = document.body.scrollTop;
		height = document.body.offsetHeight;
		
	}
	newHeight = scrollYPos + height / 2 - 20;
	
	div.style.top = newHeight + "px";
	
	return true;
}

function showFeedback()
{
	if(document.all)
	{
		hideDropDownLists();
		document.all.brf.style.visibility = "hidden";
		document.all.toptable.style.filter = "Alpha(opacity=40)";
		document.all.maintable.style.filter = "Alpha(opacity=40)";
		document.all.feedback.style.filter = "Alpha(opacity=100)";
		document.getElementById('feedback').style.display='block';
	}
	else
	{
		commandQueue[commandQueue.length] = "waitForBody();";
		commandQueue[commandQueue.length] = "hideDropDownLists();";
		commandQueue[commandQueue.length] = "transHack();";
		commandQueue[commandQueue.length] = "document.getElementById('feedback').style.display='block';";
		commandQueue[commandQueue.length] = "fade('brf', 0, 50);";
		commandQueue[commandQueue.length] = "fade('maintable', 40, 20);fade('toptable', 40, 20);";
		commandQueue[commandQueue.length] = "fade('feedback', 100, 50);";
		doQueue();
	}
}

function hideFeedback(total)
{
	if(document.all)
	{
		document.all.toptable.style.filter = "Alpha(opacity=100)";
		document.all.maintable.style.filter = "Alpha(opacity=100)";
		if(!total)
		{
			document.all.brf.style.visibility = "visible";
			document.getElementById('brf').firstChild.id='flup';
		}
		showDropDownLists();
		document.getElementById('feedback').style.display='none';
		window.setTimeout('startGif();', 500);
	}
	else
	{
		commandQueue[commandQueue.length] = "fade('feedback', 0, 50);";
		commandQueue[commandQueue.length] = "fade('maintable', 100, 20);fade('toptable', 100, 20);";
		if(!total)
		{
			commandQueue[commandQueue.length] = "document.getElementById('brf').firstChild.id='flup';";
			commandQueue[commandQueue.length] = "fade('brf', 100, 50);";
		}
		commandQueue[commandQueue.length] = "showDropDownLists();";
		commandQueue[commandQueue.length] = "destroyBox('transhack');";
		commandQueue[commandQueue.length] = "document.getElementById('feedback').style.display='none';";
		doQueue();
	}
}

function startGif()
{
	document.all.rf_but.src='/img/t.gif';
	document.all.rf_but.src='/img/feedback/rf_button.gif';
}