///JS fuer Pinwand
//erstellt 25.09.2008 von Merlin Becker
function postNewMessage(element)
{
	with(new Ajax()){
		url=pinwand+"/index.php?PHPSESSID="+SID+"&gid="+gid+"&aktion=post_message";
		method="POST";
		params="nachricht="+element.nachricht.value+"&ort="+element.ort.value+"&name="+element.name.value;	
		onSuccess=fetchNewMessages;
		onError=function(txt,xml){alert('Fehler'+txt);};
		doRequest();
		}
}
function fetchNewMessages(txt,xml)
{
	with(new Ajax()){
		url=pinwand+"/index.php?PHPSESSID="+SID+"&gid="+gid+"&aktion=fetch_new_messages";
		method="POST";
		onSuccess=topMessages;
		onError=function(txt,xml){alert('Fehler'+txt);};
		doRequest();
		}
}
function fetchOldMessages()
{
	if(currentloaded<max_anzahl)
	{
	with(new Ajax()){
		url=pinwand+"/index.php?PHPSESSID="+SID+"&gid="+gid+"&aktion=fetch_messages";
		method="POST";
		params="currentloaded="+currentloaded;	
		onSuccess=appendMessages;
		onError=function(txt,xml){alert('Fehler'+txt);};
		doRequest();
		}
	}
}
function appendMessages(txt,xml)
{
	currentloaded+=stepsize;
	document.getElementById("messagestack").innerHTML+=txt;
}
function topMessages(txt,xml)
{
	document.getElementById("messagestack").innerHTML=txt+document.getElementById("messagestack").innerHTML;
}

function checkMessageForm(element)
{
	if(element.name.value!=""&&element.nachricht.value!="")
	{
		showHideMessageForm();
		postNewMessage(element);
	}
	else
	{
		alert("Bitte geben Sie einen Namen und eine Nachricht ein!");
	}
	return (false);
}
function fetchAvatarUploadForm()
{
	if (navigator.javaEnabled())
	{
		with(new Ajax()){
		url=pinwand;
		params="PHPSESSID="+SID+"&gid="+gid+"&aktion=get_PicUp&weiteraktion=create_avatar";	
		onSuccess=displayPicUp;
		onError=function(txt,xml){alert('Fehler'+txt);};
		doRequest();
		}
	}
	else
	{
		alert("Java 6 wird für den Bildupload benötigt!");
		window.open("http://www.java.com/de/download/","_blank");
	}
}
function displayPicUp(txt,xml)
{
	document.getElementById('PicUpContainer').innerHTML=txt;
	document.getElementById('AvatarUploadDialog').style.display='block';
}
function closeAndDisplayAvatar()
{
	closePicUp();
	displayAvatar();
}
function displayAvatar()
{
	with(new Ajax()){
		url=pinwand;
		params="PHPSESSID="+SID+"&gid="+gid+"&aktion=get_avatar";	
		onSuccess=function(txt,xml){document.getElementById('avatarContainer').innerHTML="<img src=\""+pinwand+"/daten/"+txt+"\">";};
		onError=function(txt,xml){alert('Fehler'+txt);};
		doRequest();
	}
}
function closePicUp()
{
	document.getElementById('AvatarUploadDialog').style.display='none';
}
function showHideMessageForm()
{
	var container=document.getElementById('newMessageFormContainer');
	if(container.style.display=="none")
	{
		container.style.display="block";
		document.getElementById("arrow").className="arrowdown";
	}
	else if(container.style.display=="block")
	{container.style.display="none";
	document.getElementById("arrow").className="arrowleft";
	}
	else
	{
	container.style.display="block";
	document.getElementById("arrow").className="arrowdown";
	}
}



