var tm, tm2, tm3;
function getuser(){
	$.post("/frontmodule/chatroom/getonline.php?tm="+new Date(),{g:"Y"},function(data){
		if(data.length){
			str = "";
			for(i=0;i<data.length;i++){
				it = data[i];
				str += it+"<br />";
			}				
			$("#useronline").html(str);
		}
	},"json");
}
function getmsg(txtmsg){
	clearTimeout(tm3);
	
	if(!txtmsg) txtmsg = "";
	$.ajax({
		url: "/frontmodule/chatroom/getmsg.php?tm="+new Date(),
		global: false,
		type: "POST",
		data: ({msg:txtmsg}),
		dataType: "json",
		success: function(data){
			if(data.length){
				str = "";
				for(i=0;i<data.length;i++){
					it = data[i];
					str += '<tr>';
					str += '<td class="av"><img src="'+((it[3])? '/media/avatar/mini/'+it[3] : '/images/img30x30.gif')+'" width="25" height="25" /></td>';
					str += '<td class="c1">'+it[0]+'</td>';
					str += '<td>'+it[1]+' : '+it[2]+'</td>';
					str += '<tr>';
				}				
				$("#msglist").append(str);						
				$("#pnMsgList").animate({ scrollTop:$("#pnMsgList").attr("scrollHeight") }, 1000);
				$(window).focus();
			}
			tm3 = setTimeout(function(){getmsg();},3000);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			tm3 = setTimeout(function(){getmsg();},3000);
		}
	});
}
function send(){
	getmsg($("#msg").val());
	$("#msg").val("")
	return(false);
}
function addicon(iconcode){
	$("#msg").val($("#msg").val()+iconcode);
}