$(document).ready
(
	function()
	{
		if($("#shoutbox").attr("name")=="shoutbox")
		{
			$("#napisz").click
			(
				function()
				{
					var text=$("#textm").attr("value");
					text=jQuery.trim(text);
					if(text!='')
					{
						var nick=$("#nick").attr("value");
						nick=jQuery.trim(nick);
						if(nick!='')
						{
							getMessages1(text, nick);
						}
						else
						{
							getMessages(text);
						}
					}
				}
			);
			$("#textm").keypress
			(
				function(e)
				{
					if(e.which==13)
					{
						var text=$("#textm").attr("value");
						text=jQuery.trim(text);
						if(text!='')
						{
							var nick=$("#nick").attr("value");
							nick=jQuery.trim(nick);
							if(nick!='')
							{
								getMessages1(text, nick);
							}
							else
							{
								getMessages(text);
							}
						}
					}
					else
					{
						return true;
					}
				}
			);
			setInterval("getMessages0()",5000);
			getMessages0();
		}
	}
);


function getMessages1(text, nick)
{
	var e='';
	$("#textm").attr("value", e);
	nick=encodeURI(nick);
	text=encodeURI(text);
	$("#shoutbox").load("shoutbox.php?text="+text+"&nick="+nick);
	$("#shoutbox").ajaxStop(function(){$("#shoutbox").scrollTop(300000);});
};

function getMessages(text)
{
	var e='';
	$("#textm").attr("value", e);
	text=encodeURI(text);
	$("#shoutbox").load("shoutbox.php?text="+text);
	$("#shoutbox").ajaxStop(function(){$("#shoutbox").scrollTop(300000);});
};

function getMessages0()
{
	var i=Math.random();
	$("#shoutbox").load("shoutbox.php?i="+i);
	$("#shoutbox").ajaxStop(function(){$("#shoutbox").scrollTop(300000);});
};

