		$(document).ready(function(){
			timestamp = 0;
			updateMsg();
			$("form#chatform").submit(function(){
				$.post("backend.php",{
							message: $("#msg").val(),
							name: $("#author").val(),
							action: "postmsg",
							time: timestamp
						}, function(xml) {
					$("#msg").empty();
					addMessages(xml);
				});
				return false;
			});
		});
		function addMessages(xml) {
			if($("status",xml).text() == "2") return;
			timestamp = $("time",xml).text();
			$("message",xml).each(function(id) {
				message = $("message",xml).get(id);
				$("#messagewindow").prepend($(message).text());
			});
		}
		function addChat(xml) {
			if($("status",xml).text() == "2") return;
			timestamp = $("time",xml).text();
			$("chat",xml).each(function(id) {
				message = $("chat",xml).get(id);
				$("#chatwindow").prepend($(message).text());
			});
		}
		function updateMsg() {
			$.post("backend.php",{ time: timestamp }, function(xml) {
				$("#loading").remove();
				addMessages(xml);
				addChat(xml);
			});
			setTimeout('updateMsg()', 4000);
		}
		
var count = "150";   //Example: var count = "175";
function limiter(){
var tex = document.chatform.msg.value;
var len = tex.length;
if(len > count){
        tex = tex.substring(0,count);
        document.chatform.msg.value =tex;
        return false;
}

}		