function triggerForumPostform(key)
{
	toggleDisplay(document.getElementById('forum_postform'+key));
	var e=$('forumpostcontent'+key);
	if (e!=null)
		e.slide("show");
	return;
	if (document.getElementById('forum_postform'+key).style.display!='block')
	{
		$('forum_postform'+key).slide("hide");
		document.getElementById('forum_postform'+key).style.display="block";
	}
	$('forum_postform'+key).slide("toggle");
}
/*
function toggleDisplay(e)
{
	if (e.style.display=='block')
	{
		e.style.display='none';
	}
	else
	{
		e.style.display='block';
	}
}*/
function forum_displayLoadingAnimation(e){
	e.innerHTML='<img src="/images/loading.gif"/>';
}
function forum_ajaxGetPosts(ids)
{
	$$('.forumpostcontentwrapper').each(function(e){
		forum_displayLoadingAnimation(e);
	});
	var ajax=new forum_AjaxObject("/index.php?a=forum&do=ajposts&ids[]="+ids.join('&ids[]='));
	if (ajax.query())  {
	}	
}
function forum_ajaxGetPost(id)
{
	if ($('forumpostcontent'+id).innerHTML=='') {
		forum_displayLoadingAnimation($('forumpostcontent'+id));
		var ajax=new forum_AjaxObject("/index.php?a=forum&do=ajposts&ids[]="+id);
		if (ajax.query())  {
			//alert("drin");
		}	
//			var mySlide = new Fx.Slide('forumpostcontent'+id).hide();
	}
	else {
		$('forumpostcontent'+id).slide("toggle");
	}
}

function forum_AjaxObject (url) {
	this.url = url;
	/* Create a new XMLHttpRequest object to talk to the Web server */
	var xmlHttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
	  try {
	  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
	  xmlHttp = false;
	  }
	  }
	  @end @*/

	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp){
		alert('kein xmlhttprequest objekt');
	}


	this.query = function ()
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				var response = xmlHttp.responseXML;
				var knoten = response.getElementsByTagName("element");
				for (var i=0; i<knoten.length; i++) {
					var target, action, content;
					target = knoten[i].getAttribute("target");
					action = knoten[i].getAttribute("action");
					var e=document.getElementById(target);
					if (action=='set_visible')
					{
						e.style.display='block';
					}
					if (knoten[i].firstChild!=null)
					{
						content = knoten[i].firstChild.nodeValue;
						content=trim(content);
						if (action=='append')
						{
							e.innerHTML+=content;
						}
						if (action=='replace')
						{
							e.innerHTML=content;
						}
					}
				}

				return true;
			}

		};
		xmlHttp.send(null);
	}
}

function fetchSmilies(id)
{
	if(id==null)
		id='';
	var sb=$('smilieBox'+id);
	if (sb.innerHTML=='')
	{
		var ajax=new forum_AjaxObject("/index.php?a=forum&do=ajsmilies&id="+id);
		ajax.query();
		sb.style.height='200px';
	}
	else {
		toggleDisplay($('smilieBox'+id));
/*		if (sb.style.overflow="hidden")
		sb.style.overflow="auto";
		else
		sb.style.overflow="hidden";
		sb.slide("toggle");
		$('forumpostcontent'+id).slide("show");*/
	}
//	$('forum_postform'+id).slide("show");
	var e=$('forumpostcontent'+id);
	if (e!=null)
		e.slide("show");
}


function createForumPostform(parentid,threadid,forumid,title){
	var caption=(parentid>0?'Antworten':'Thema beginnen');

	var e = $('forum_postform'+parentid);
	if (e == null) return;

	if (!e.hasClass('hidden')){
		e.addClass('hidden');
		e=$('forumpostcontent'+parentid);
		if (e!=null)
			e.slide("show");
		return;
	}

	e.set('html',
		'<fieldset><legend>'+caption+'</legend><form action="/forum/?post" method="post" name="newpost"><input type="hidden" name="do" value="addpost"/><input type="hidden" name="parentid" value="'+parentid+'"/><input type="hidden" name="threadid" value="'+threadid+'"/><input type="hidden" name="forumid" value="'+forumid+'"/><div><label for="fp_title">&Uuml;berschrift</label><input type="text" name="title" id="fp_title" value="'+title+'"/></div><div><label for="fp_content">Beitrag</label><textarea name="content" id="fp_content'+parentid+'"></textarea></div><img src="/smilies/smiley_emoticons_wink.gif" onclick="addSmiley(\':wink:\','+parentid+');" title=":wink:"><img src="/smilies/smiley_emoticons_eek.gif" onclick="addSmiley(\':eek:\','+parentid+');" title=":eek:"><img src="/smilies/smiley_emoticons_skeptisch.gif" onclick="addSmiley(\':skeptisch:\','+parentid+');" title=":skeptisch:"><img src="/smilies/smiley_emoticons_thumbs1.gif" onclick="addSmiley(\':up:\','+parentid+');" title=":up:"><img src="/smilies/smiley_emoticons_down.gif" onclick="addSmiley(\':down:\','+parentid+');" title=":down:"><button onclick="fetchSmilies('+parentid+');return false;">Alle Smilies anzeigen</button><div class="smilieBox" id="smilieBox'+parentid+'"></div><div><button type="submit" onclick="return loadNotAllowed(this);">Eintragen</button></div><div><label>Beispiele zum Text formatieren</label><dl class="help"><dd>Bild einf&uuml;gen:</dd><dt>http://www.hilfsmotor.eu/pfad/bild.jpg</dt><dd>Video einf&uuml;gen:</dd><dt>http://www.youtube.com/watch?v=1uwOL4rB-go</dt><dd>Fetter Text:</dd><dt>[b]<strong>dies ist fett</strong>[/b]</dt><dd>Kursiver Text:</dd><dt>[i]<em>dies ist kursiv</em>[/i]</dt><dd>Zitieren:</dd><dt>[quote]dies ist ein zitat[/quote]</dt></dl></div></form></fieldset>');
	e.removeClass('hidden');
	

	e=$('forumpostcontent'+parentid);
	if (e!=null)
		e.slide("show");
}
