var ns5 = true;
var dom = (document.getElementById) ? true : false;
var ope = ((navigator.userAgent.indexOf("Opera")>-1)) ? true: false;
ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var ns6 = ns5;
var ns6_1= (ns5 && navigator.userAgent.indexOf("6.1") != -1) ? true : false;
var ns6_2= (ns5 && navigator.userAgent.indexOf("6.2") != -1) ? true : false;
var ie6 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ns6 && !ns6_1 && !ns6_2 && !ie4 && !ie5 && !ie6) ? true : false;
//alert("ie4:"+ie4+"\nns4:"+ns4+"\nns5:"+ns5+"\nns6:"+ns6+"\nns6_1:"+ns6_1+"\nns6_2:"+ns6_2)
if (nodyn) { event = "nope" }
var tooltip='';
var div;
var off_x = 8; var off_y = 8;
g_timer = new Array();
c_timer = new Array();
clock_active=0;

function setDivText(div, text)
{	
	if (ie4 || ie5 || ie6 || ope) {
		var strDiv;
		strDiv=div.replace("'", "");
		tip = '<DIV CLASS="timer">' + text + '</DIV>';
		tooltip = document.getElementById(div);
		tooltip.innerHTML = tip;
	}
	if (ns4) {
		tooltip = document.div;
		tooltip.document.write(text);
	}
	if (ns5 || ns6 || ns6_1 || ns6_2) {
		tip = '<DIV CLASS="timer">' + text + '</DIV>';
		tooltip = document.getElementById(div);
		tooltip.innerHTML = tip;
	}
}

function setText(div, text)
{
	if (ie4 || ie5 || ie6 || ope) {
		var strDiv;
		strDiv=div.replace("'", "");
		tip = text;
		tooltip = document.getElementById(div);
		tooltip.innerHTML = tip;
	}
	if (ns4) {
		tooltip = document.div;
		tooltip.document.write(text);
	}
	if (ns5 || ns6 || ns6_1 || ns6_2) {
		tip = text;
		tooltip = document.getElementById(div);
		tooltip.innerHTML = tip;
	}
}

function addTimer(seconds, divName, button)
{
	for (i=0; i<g_timer.length; i++)
	{
		if (g_timer[i] == -1)
			break;
	}
	g_timer[i] = seconds;
	g_timer[i+1] = divName;
}

function activateClock(divName, akth, aktm, akts)
{
	c_timer[0]=divName;
	c_timer[1]=akth;
	c_timer[2]=aktm;
	c_timer[3]=akts;
	clock_active=1;
}

function countdown(ClockDiv)
{
	len = g_timer.length*2;
	for (i=0; i<len;i+=2)
	{
		if (g_timer[i] > 0)
		{
			if (--g_timer[i] > 0)
			{
				lSeconds = g_timer[i]%60;                // bisserl komplizierte Formatierung
				lMinutes = Math.floor(g_timer[i] / 60);
				lHours = Math.floor(lMinutes / 60);
				lMinutes%=60;
				lMinutes= ((lMinutes<10)? "0" : "" ) +  (lMinutes);
				lSeconds =((lSeconds<10)?"0":"") +  (lSeconds);
				if (lHours==0)
				{
					if (lMinutes==0)
					{
						setDivText(g_timer[i+1], "<span class='timer'>" + lSeconds +"s</span>");
					}
					else
					{
						setDivText(g_timer[i+1], "<span class='timer'>" + lMinutes + "m " + lSeconds +"s</span>");
					}
				}
				else
				{
					setDivText(g_timer[i+1], "<span class='timer'>" + lHours + "h " + lMinutes + "m " + lSeconds +"s</span>");
				}
			}
			else
			{
				setDivText(g_timer[i+1], "<span class='timer'>0s</span>");
				g_timer[i]=-1; // als 'wieder frei' markieren
			}
		}
	}
	
	
	//Uhrzeit
	if (clock_active==1)
	{
		if (c_timer[1]==23 && c_timer[2]==59 && c_timer[3]==59)
		{
			c_timer[3]=0;
			c_timer[2]=0;
			c_timer[1]=0;
		}
		else if (c_timer[2]==59 && c_timer[3]==59)
		{
			c_timer[1]++;
			c_timer[3]=0;
			c_timer[2]=0;
		}
		else if (c_timer[3]==59)
		{
			c_timer[2]++;
			c_timer[3]=0;
		}
		else
		{
			c_timer[3]++;
		}
		
		if (c_timer[3]<10)
			c_timer[3]='0'+parseInt(c_timer[3], 10);
		if (c_timer[2]<10)
			c_timer[2]='0'+parseInt(c_timer[2], 10);
		if (c_timer[1]<10)
			c_timer[1]='0'+parseInt(c_timer[1], 10);
		
		
		//alert("<span class='timer'>" + c_timer[1] + ":" + c_timer[2] + ":" + c_timer[3] +"</span>");
		setDivText(c_timer[0], "<span class='timer'>" + c_timer[1] + ":" + c_timer[2] + ":" + c_timer[3] +"</span>");
	}
	
	setTimeout("countdown()", 1000);
	
	
}

function handleClick(test) {
	test.style.visibility = "hidden";
}

function openHelp(t, id, l)
{
	win = window.open("help.asp?t="+t+"&id="+id, "win","width=400,height=350,scrollbars=yes,scrolling=auto,toolbar=no,menubar=no,screenX=50,screenY=50,left=50,top=50,resizable=no");
	win.focus();
}

function OpenWind(url)
{
	var name='opener';
	opener = window.open('', name, 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=320,height=480,left=0,top=0');
	opener.location.href=url;
	opener.focus();
}

function OpenFarb(url)
{
	var name='opener';
	opener = window.open('', name, 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=280,height=200,left=0,top=0');
	opener.location.href=url;
	opener.focus();
}

function dT(evt,txt,txg,xxt) {
	hT();
	
	var line;
	if (xxt=='0') { line = ""; }
	if (xxt=='1') { line = "<hr style=\"color: #000000; width:192px;\">"; }
	if (xxt=='2') { line = "<br>"; }
	
	var tip;
	if (ns4) {
		tip = '<TABLE BGCOLOR="#000000" CELLSPACING="0" CELLPADDING="1" BORDER="1"><TR><TD><TABLE BGCOLOR="#EDF6FD" WIDTH="100%" CELLSPACING="0" CELLPADDING="3" BORDER="0"><TR><TD CLASS="tip">'+ '<font face=Arial color=black size=2>' + txt + '</font>' + line + '<font face=Arial color=black size=2>' + txg +'</font></TD></TR></TABLE></TD></TR></TABLE>';
		tooltip = document.tipDiv;
		tooltip.document.write(tip);
		tooltip.document.close();
		if ((evt.pageX + off_x + tooltip.clip.width) > (window.innerWidth + window.pageXOffset)) {
			tooltip.left = evt.pageX - tooltip.clip.width;
		} else { tooltip.left = evt.pageX + off_x; }
		if ((evt.pageY + off_y + tooltip.clip.height) > (window.innerHeight + window.pageYOffset)) {
			tooltip.top = evt.pageY - tooltip.clip.height;
		} else { tooltip.top = evt.pageY + off_y; }
		tooltip.visibility = "show";
	}
	if (ie4 || ie5 || ie6 || ope) {
		evt = window.event;
		tip = '<DIV CLASS="tp">' + txt + line + txg + '</DIV>';
		tooltip = document.all.tipDiv;
		tooltip.innerHTML = tip;
		if ((evt.clientX + off_x + tooltip.style.pixelWidth) > (document.body.clientWidth) - 150) {
			tooltip.style.pixelLeft = (evt.clientX + document.body.scrollLeft) - tooltip.style.pixelWidth - 350;
		} else { tooltip.style.pixelLeft = evt.clientX + off_x + document.body.scrollLeft - 350; }
		if ((evt.clientY+off_y+tooltip.clientHeight) > (document.body.clientHeight) - 150) {
			tooltip.style.pixelTop = (evt.clientY + document.body.scrollTop) - tooltip.clientHeight - 200;
		} else { tooltip.style.pixelTop = evt.clientY + off_y + document.body.scrollTop - 200; }
		tooltip.style.visibility = "visible";
	}
	if (ns5 || ns6 || ns6_1 || ns6_2) 
	{
		tip = '<DIV CLASS="tp">' + txt + line + txg + '</DIV>';
		tooltip = document.getElementById('tipDiv');
		tooltip.innerHTML = tip;
		if ((evt.pageX + off_x + tooltip.offsetWidth) > (window.innerWidth + window.pageXOffset)) 
		{
			tooltip.style.left = evt.pageX - tooltip.offsetWidth;
		} 
		else 
		{ 
			tooltip.style.left = evt.pageX + off_x; 
		}
		if ((evt.pageY + off_y + tooltip.offsetHeight) > (window.innerHeight + window.pageYOffset)) 
		{
			tooltip.style.top = evt.pageY - tooltip.offsetHeight;
		} 
		else 
		{ 
			tooltip.style.top = evt.pageY + off_y; 
		}
		tooltip.style.visibility = "visible"; 
	}
}

function hT() {
	if (ns4) { 
		tooltip = document.tipDiv;
		tooltip.visibility = "hide";
	}
	if (ie4 || ie5 || ie6 || ope) {
		tooltip = document.all.tipDiv;
		tooltip.style.visibility = "hidden";
	}
	if (ns5 || ns6 || ns6_1 || ns6_2) {
		tooltip = document.getElementById('tipDiv');
		tooltip.style.visibility = "hidden";
	}
}

function xT() {
}

function AllMessages()
{
	for(var x=0;x<document.MI.elements.length;x++)
	{ var y=document.MI.elements[x];
		if(y.name!='ALLMSG') y.checked=document.MI.ALLMSG.checked;
	}
}

function number_format (number, decimals, dec_point, thousands_sep)
{
	var exponent = "";
	var numberstr = number.toString ();
	var eindex = numberstr.indexOf ("e");
	if (eindex > -1)
	{
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}
	
	if (decimals != null)
	{
		var temp = Math.pow (10, decimals);
		number = Math.round (number * temp) / temp;
	}
	var sign = number < 0 ? "-" : "";
	var integer = (number > 0 ? 
		Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	
	var fractional = number.toString ().substring (integer.length + sign.length);
	dec_point = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
		(dec_point + fractional.substring (1)) : "";
	if (decimals != null && decimals > 0)
	{
		for (i = fractional.length - 1, z = decimals; i < z; ++i)
			fractional += "0";
	}
	
	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
		thousands_sep : null;
	if (thousands_sep != null && thousands_sep != "")
	{
		for (i = integer.length - 3; i > 0; i -= 3)
			integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}
	
	return sign + integer + fractional + exponent;
}
