function display_msg_board(inhalt) {
	if (inhalt == 'default') {
		inhalt = default_anzeige;
	}
	document.getElementById('message_board').innerHTML = inhalt;
}

function openHelp(url,scrolling,width,height,windowName) {
	if (windowName == '')
		windowName = 'fotu_help';
	open(url, windowName, "resizable=no, menubar=no, locationbar=no, status=no, hotkeys=no, dependent=yes, width=" + width + ", height=" + height + ", screenX=0, screenY=0, scrollbars=" + scrolling)
}

var start_s = 0;
var start_m  = 0;
var start_h  = 0;

function ZeitInit()
{
	// ### Werte setzen
	start_s = zeitstempel.getSeconds();
	start_m  = zeitstempel.getMinutes();
	start_h  = zeitstempel.getHours();
	
	// ### Interval starten
	window.setInterval("ZeitStarten()", 1000);
}

function ZeitStarten() {
	start_s ++;
	if (start_s == 60) {
		start_s = 0;
		start_m ++;
		if (start_m == 60) {
			start_m = 0;
			start_h ++;
			if (start_h == 24) {
				start_h = 0;
			}
		}
	}
  	zeit= zweistellig(start_h)+":"+zweistellig(start_m)+":"+zweistellig(start_s);
  	if (document.getElementById("act_time"))
  		document.getElementById("act_time").innerHTML = zeit;
 
	// ### Notification?
	if (sTickNotification != '' && (start_m % 15 == 0) && start_s == 0)
	{
		// ### Sound abspielen!
		noCacheTime = new Date();
		document.getElementById('playSound').focus();
		document.getElementById('playSound').src = '/soundplayer.php?iCacheTime='+noCacheTime.getTime()+'&playSound='+sTickNotification;
	}
	
	// ### Kampf-Tick Beep?
	if (sKampfTickNotification != '' && (((start_m == 4) && (start_s == 30 || start_s == 40 || start_s == 50)) || ((start_m == 5) && (start_s == 0))))
	{
		// ### Sound abspielen!
		noCacheTime = new Date();
		document.getElementById('playSound').focus();
		document.getElementById('playSound').src = '/soundplayer.php?iCacheTime='+noCacheTime.getTime()+'&playSound='+sKampfTickNotification;
	}
}

// ### Countdown
var countTageLeft = 0;
var countSeksLeft = 0;
var countMinsLeft = 0;
var countHoursLeft = 0;
function startCountDown (tageLeft, seksLeft, minsLeft, hoursLeft, elementSet, addText)
{
	// ### Timer anstoßen
	window.setTimeout("countDown('"+elementSet+"', '"+addText+"')",1000);
	
	// ### Werte setzen und Timer starten
	countTageLeft = tageLeft;
	countSeksLeft = seksLeft - 1;
	countMinsLeft = minsLeft;
	countHoursLeft = hoursLeft;
}

// ### Countdown
function countDown(targetElement, addText) {
  window.setTimeout("countDown('"+targetElement+"', '"+addText+"')", 1000);
  countSeksLeft --;
  if (countSeksLeft == -1) {
    countSeksLeft = 59;
    countMinsLeft --;
    if (countMinsLeft == -1) {
      countMinsLeft = 59;
      countHoursLeft --;
      if (countHoursLeft == -1) {
         countHoursLeft = 23;
         countTageLeft--;
      }
    }
  }
  
  // ### Ziel erreicht?
  if (countTageLeft == -1)
  {
  	// ### Countdown ist abgelaufen!
  	displayZeit = '00:00:00';
  	
  	// ### Kommt noch ein text hinterher?
  	if (addText != '')
  		displayZeit += ' '+addText;
  	
  	// ### Inhalt setzen
  	document.getElementById(targetElement).innerHTML = displayZeit;
  }
  else
  {
  	// ### Anzeige zusammenbauen
  	displayZeit = '';
  	if (countTageLeft > 0)
  	{
  		// ### Mehr als ein Tag?
  		if (countTageLeft == 1)
  			displayZeit += '1 Tag, ';
  		else
  			displayZeit += countTageLeft + ' Tage, ';
  	}
  	
  	// ### Die Uhrzeit anhängen
  	displayZeit += zweistellig(countHoursLeft)+":"+zweistellig(countMinsLeft)+":"+zweistellig(countSeksLeft);
  	
  	// ### Kommt noch ein text hinterher?
  	if (addText != '')
  		displayZeit += ' '+addText;
  	
  	// ### Inhalt setzen
  	document.getElementById(targetElement).innerHTML = displayZeit;
  }
}

function zweistellig(wert) {
	if (wert < 10) {
		wert = "0" + wert;
	}
	return wert;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function rb (divID, ebene, type) {
	if (type == 'o') {
		document.getElementById(divID).style.backgroundImage = 'url("' + grafikpfad + ebene + 'n.gif")';
	}
	if (type == 'r') {
		document.getElementById(divID).style.backgroundImage = 'url("' + grafikpfad + ebene + 'r.gif")';
	}
}

function changeImage (imageID, new_src)
{
	// ### Neues Bild setzen
	document.getElementById(imageID).src = new_src;
}

function control_sub(divID, favID, img_name, menu_type) {
	if (document.getElementById(divID).style.display == 'inline') {
		document.getElementById(divID).style.display = 'none';
		document.getElementById(favID).style.display = 'inline';
		if (img_name != '') {
			if (menu_type == 'under') {
				document.getElementById(img_name).src = grafikpfad + 'plus.gif';
			}
			if (menu_type == 'head') {
				document.getElementById(img_name).src = grafikpfad + 'header_closed.gif';
			}
     	}
	}
	else {
		document.getElementById(divID).style.display = 'inline';
		document.getElementById(favID).style.display = 'none';
		if (img_name != '') {
			if (menu_type == 'under') {
				document.getElementById(img_name).src = grafikpfad + 'minus.gif';
			}
			if (menu_type == 'head') {
				document.getElementById(img_name).src = grafikpfad + 'header_opened.gif';
			}
     	}
	}
}
function check_koords (element) {
	if (element.name == "uni_block") { if (element.value.length == 1) { element.form.elements['koord1'].value = ''; element.form.elements['koord1'].focus(); } }
	if (element.name == "koord1") { if (element.value.length == 1) { element.form.elements['koord2'].value = ''; element.form.elements['koord2'].focus(); } }
	if (element.name == "koord2") { if (element.value.length == 1) { element.form.elements['koord3'].value = ''; element.form.elements['koord3'].focus(); } }
	if (element.name == "koord3") { if (element.value.length == 1) { element.form.elements['koord4'].value = ''; element.form.elements['koord4'].focus(); } }
}

function form_value (element, new_value) {
	element.value = new_value;
}

function FotU_HandleRequest (SentActions)
{
	for (var i = 0; i < SentActions.length; i++) {
		type = SentActions[i].getElementsByTagName("type")[0].firstChild.nodeValue;
		switch (type) {
			case "alert":
				alert(SentActions[i].getElementsByTagName("answer")[0].firstChild.nodeValue);
				break;
			case "renew":
				document.getElementById(SentActions[i].getElementsByTagName("element")[0].firstChild.nodeValue).innerHTML = SentActions[i].getElementsByTagName("answer")[0].firstChild.nodeValue;
				break;
			case "addContent":
				document.getElementById(SentActions[i].getElementsByTagName("element")[0].firstChild.nodeValue).innerHTML += SentActions[i].getElementsByTagName("answer")[0].firstChild.nodeValue;
				break;
			case "window":
				FotU_Ajax.SpawnWindow(SentActions[i].getElementsByTagName("element")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("answer")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("top")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("left")[0].firstChild.nodeValue)
				break;
			case "ress":
				document.getElementById('ress_min').innerHTML = SentActions[i].getElementsByTagName("min")[0].firstChild.nodeValue;
				document.getElementById('ress_ves').innerHTML = SentActions[i].getElementsByTagName("ves")[0].firstChild.nodeValue;
				document.getElementById('ress_met').innerHTML = SentActions[i].getElementsByTagName("met")[0].firstChild.nodeValue;
				break;
			case "time":
				// ### Element erneuern
				iNewS = Number(SentActions[i].getElementsByTagName("time_s")[0].firstChild.nodeValue);
				
				// ### Abweichung in der Sekundenzahl?
				if (iNewS > (start_s+3))
					start_s = start_s + 3;
				
				// ### Aber nur wenns jetzt nicht 60 ist!
				if (start_s >= 60)
					start_s = 59;
				
				break;
			case "buildstreet":
				BuildStreet(SentActions[i].getElementsByTagName("field")[0].firstChild.nodeValue);
				break;
			case "knockdownstreet":
				KnockDownStreet(SentActions[i].getElementsByTagName("field")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("belag")[0].firstChild.nodeValue);
				break;
			case "forward":
				document.location.href = SentActions[i].getElementsByTagName("answer")[0].firstChild.nodeValue;
				break;
			case "eventHandler":
				eventHandler(SentActions[i].getElementsByTagName("eventType")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("eventID")[0].firstChild.nodeValue, SentActions[i].getElementsByTagName("eventHandling")[0].firstChild.nodeValue);
				break;
			case "chatlines":
				break;
			case "none":
				break;
			default:
				// ### nothing
				alert('check');
				break;
		}
	}
}

// ### Anzeige der letzten Textlines
var a_Textlines = new Array();
var iActElement = 0;
var iLastElement = 0;
var iFaderID = 0;
function fadeLastTextlines ()
{
	// ### Neue Textline setzen
	if (a_Textlines[iActElement] != undefined && a_Textlines[iActElement] != '')
	{
		// ### Gleiches Element?
		if (document.getElementById('chat_last_line').innerHTML == a_Textlines[iActElement] && a_Textlines[iActElement+1] != undefined && a_Textlines[iActElement+1] != '')
			iActElement++;
		
		// ### Neue Zeile setzen
		document.getElementById('chat_last_line').innerHTML = a_Textlines[iActElement];
		iActElement++;
		if (a_Textlines[(iActElement-2)] != '')
			a_Textlines[(iActElement-2)] = '';
	}
}

// ### Eventhadler
function eventHandler (eventType, eventID, eventHandling)
{
	// ### Format entpuzzeln
	switch (eventType) {
		case "newlasttextlines":
			// ### Ist das anderer Text als das letzte Element?
			if (a_Textlines[iLastElement-1] != eventHandling)
			{
				// ### Neues Element setzen
				a_Textlines[iLastElement] = eventHandling;
				iLastElement++;
			}
			
			// ### Muss der Fader wieder gestartet werden?
			if (iFaderID == 0)
			{
				// ### Interval starten
				setInterval("fadeLastTextlines()", 5000);
				fadeLastTextlines();
				iFaderID = 1;
			}
			break;
	}
}

// ### Sync beginnen
function startSyncing ()
{
	// ### Textline-Sync starten!
	FotU_Ajax.GetLastChatLines();
}

// ### Scroll Slider!
var iScrollTimer = 0;
function scrollSlider(iScrollToLeft, iScrollToTop) {
	// ### Aktuelle Position
	iActPosTop = Number($('slider').style.top.replace(/px/, ''));
	iActPosLeft = Number($('slider').style.left.replace(/px/, ''));
	
	// ### Verschieben
	// new Effect.Move($('slider'), { x: iActPosLeft, y: iScrollPX, 'mode': 'absolute' });
	document.getElementById('slider').style.top = iScrollPX+'px';
}

// ### Start des Scrollings
function startScrollSlider ()
{
	// ### Läuft schon ein Timer?
	if (iScrollTimer != 0)
	{
		// ### Beenden
		window.clearTimeout(iScrollTimer);
		iScrollTimer = 0;
	}
	
	// ### Wo befindet sich der User gerade?
	if (document.documentElement.scrollTop)
		iActScroll = document.documentElement.scrollTop;
	else
		iActScroll = document.body.scrollTop;
	// iActScroll = document.body.scrollTop;
	iMaxScroll = $('main').offsetHeight - 100;
	iScrollPX = 0;
	if (iActScroll > 257)
	{
		// ### Um wieviel soll das Element wandern?
		iScrollPX = iActScroll - 257 + 229;
		if (iScrollPX > iMaxScroll)
			iScrollPX = iMaxScroll;
	}
	else
		iScrollPX = 229;
	
	// ### Timeout starten
	// scrollSlider(0, iScrollPX);
	iScrollTimer = window.setTimeout("scrollSlider(0, "+iScrollPX+")", 100);
}

// ### Slide öffnen
var sOpenedContent = '';
var a_SlideContents = new Array;
function openSlide (sOpenSlideContent)
{
	// ### Ist der Slide bereits aktiviert?
	if ($('slider_window').style.display == 'inline')
	{
		// ### Soll der Slide geschlossen werden?
		if (sOpenedContent == sOpenSlideContent || sOpenSlideContent == '')
		{
			// ### Ausblenden!
			$('slider_window').style.display = 'none';
			sOpenedContent = '';
			sOpenSlideContent = '';
		}
	}
	
	// ### Soll etwas geöffnet werden?
	if (sOpenSlideContent != '')
	{
		// ### Inhalt füllen
		$('slider_window_data').innerHTML = a_SlideContents[sOpenSlideContent];
		sOpenedContent = sOpenSlideContent;
		$('slider_window').style.display = 'inline';
	}
}

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;
}