function thumbfull(el) {
	document.getElementById(el).style.opacity = "1";
	document.getElementById(el).style.filter = "alpha(opacity=100)";
}
function thumbdark(el) {
	document.getElementById(el).style.opacity = "0.35";
	document.getElementById(el).style.filter = "alpha(opacity=35)";
}

function ShowComments(Id) {
	var KlappText = document.getElementById('commentsid'+Id);

	if (KlappText.style.display == 'none') {
		KlappText.style.display = 'block';
	} else {
		KlappText.style.display = 'none';
	}
}

function mediaplayer(width,height,url) {
	var w = 480, h = 340;
	w = screen.width;
	h = screen.height; 

	var leftPos = (w-width)/2, topPos = (h-height)/2;

	fenster = window.open(url, "_blank", "width="+width+",height="+height+",top="+topPos+",left="+leftPos+",status=yes,scrollbars=no,resizable=no");
	fenster.focus();
}

function newXmlHttpRequestObject() {
	var obj = null;
	try {
		obj = new ActiveXObject('Microsoft.XMLHTTP');
	}
	catch(e) {
		try {
			obj = new ActiveXObject('MSXML2.XMLHTTP');
		}
		catch(e) {
			try {
				obj = new XMLHttpRequest();
			}
			catch(e) {
				alert('Dieser Browser unterstützt die nötigen AJAX-Funktionen für diese Seite leider nicht :(');
			}
		}
	} 
	return obj;
}

var req = newXmlHttpRequestObject();

function loadcontent(type,id) {
	req.open('post', 'inc/'+type+'.php');
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
	req.onreadystatechange = function() {
		if ((req.readyState == 4) && (req.status == 200)) {			
			document.getElementById('m1').innerHTML = req.responseText;
			if(type == 'gallerie' || type == 'news') {
				$(document).ready(function() {
					$("a.zoom").fancybox({'overlayColor':'#000'});
                }); 
			}
		}
	}
	req.send('id='+id);
	document.getElementById('m1').innerHTML = '<div style="width:100%; text-align:center;"><img src="gfx/loading.gif" alt="loading" /><br /><br /><span class="headline">loading...</span></div>';
}

function newsscroll(limit) {
	req.open('post', 'inc/newsscroll.php');
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
	req.onreadystatechange = function() {
		if ((req.readyState == 4) && (req.status == 200)) {			
			document.getElementById('newsthumbs').innerHTML = req.responseText;
		}
	}
	req.send('limit='+limit);
	document.getElementById('newsthumbs').innerHTML = '<div style="width:100%; text-align:center;"><img src="gfx/loading.gif" alt="loading" /></div>';
}

function treescroll(id,round) {
	req.open('post', 'inc/1on1.php');
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
	req.onreadystatechange = function() {
		if ((req.readyState == 4) && (req.status == 200)) {			
			document.getElementById('m1').innerHTML = req.responseText;
		}
	}
	req.send('id='+id+'&round='+round);
	document.getElementById('m1').innerHTML = '<div style="width:100%; text-align:center;"><img src="gfx/loading.gif" alt="loading" /><br /><br /><span class="headline">loading...</span></div>';
}

function showinfo(id, type)
{
	popup = document.getElementById(id);
	document.getElementById(id+'img').src = 'gfx/'+type+'.png';

	pxstart = 70;
	timer1 = setInterval('slide_down()', 50);
	pxstop = -60;
	setTimeout('hideinfo()', 4000);
}

function hideinfo()
{
	timer2 = setInterval('slide_up()', 50);
}

function slide_down()
{	
	if (parseInt(popup.style.top) < pxstart)
	{
		popup.style.top = (parseInt(popup.style.top) + 5) + 'px';
	}
	else
	{
		clearInterval(timer1);
	}
}

function slide_up()
{	
	if (parseInt(popup.style.top) > pxstop)
	{
		popup.style.top = (parseInt(popup.style.top) - 5) + 'px';
	}
	else
	{
		clearInterval(timer2);
	}
}

function closeRecruit()
{
	if(document.getElementById('recruithide').checked)
	{
		var a = new Date();
		a = new Date(a.getTime() +1000*60*60*24*365);
		document.cookie = 'dm_recruit_show=false; expires='+a.toGMTString()+';'; 
	}
	else
	{	
		document.cookie = 'dm_recruit_show=false;'; 
	}
	document.getElementById('recruit').style.display = 'none';
}

function armorystats(div)
{
	if (document.getElementById('basis'))
	{
		var option=['basis','nahkampf','distanz','zauber','verteidigung'];
		for(var i=0; i<option.length; i++)
		{ 
			obj=document.getElementById(option[i]);
			obj.style.display=(option[i]==div)? "block" : "none";
		}
	}
}

function newsinsert(aTag, eTag) {
  var input = document.forms['formular'].elements['news'];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}
