function postShout()
{
	if($("nameShout").value=='')
	{
		alert("กรุณาใส่ชื่อ");
		$("nameShout").focus();
		return false;
	}
	else if($("msgShout").value=='')
	{
		alert("กรุณาใส่ข้อความ");
		$("msgShout").focus();
		return false;
	}

	$("submitShout").disabled=true;
//	$("msg").disabled=true;

	// CHECK NUM SHOUT

	var url="shout.php";
	var param="name="+encodeURIComponent($("nameShout").value);
	param+="&msg="+encodeURIComponent($("msgShout").value);
	param+="&action=postShout";

	$("msgShout").focus();
	$("msgShout").value='';

	postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"progressShout",path+"images/loading3.gif",
	function (text)
	{
		if(text=='error')
			alert("error");
		else
		{
;
			$("submitShout").disabled=false;
//			$("msg").disabled=false;
//			$("shoutBox").innerHTML=text;
			$("progressShout").innerHTML='';
			//goto1(path+"footerStat.php","x=27","footStatZone");
			updateMsg();
		}
	});


}

function postShout50()
{
	if($("nameShout").value=='')
	{
		alert("กรุณาใส่ชื่อ");
		$("nameShout").focus();
		return false;
	}
	else if($("message").value=='')
	{
		alert("กรุณาใส่ข้อความ");
		$("message").focus();
		return false;
	}

	$("submitShout").disabled=true;
//	$("message").disabled=true;

	// CHECK NUM SHOUT

	var url="shout50.php";
	var param="name="+encodeURIComponent($("nameShout").value);
	param+="&msg="+encodeURIComponent($("message").value);
	param+="&action=postShout";

	postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"progressShout",path+"images/loading3.gif",
	function (text)
	{
		if(text=='error')
			alert("error");
		else
		{
			$("submitShout").disabled=false;
//			$("message").disabled=false;
			$("message").value='';
			$("message").focus();
			$("shoutBox").innerHTML=text;
			$("progressShout").innerHTML='';
			goto1(path+"footerStat.php","x=27","footStatZone");
		}
	});


}

function delShout(num,id)
{
	if(num==0)
		var url="shout.php";
	else if(num==1)
		var url="shout50.php";

	goto2(url,"action=delShout&id="+id,"progressShout","shoutBox")
}

var updateMsgTime;
function updateMsg()
{
	var lastId=$j("#lastId").attr("value");

	$j.getJSON(path+"forum/shout.php?action=getJson&id="+lastId,
	function(data)
	{
		for(var i=0;i<data.amount;i++)
		{
			if(data.items[i].id>$("lastId").value)
			{
				var detail='<div id="chatMsg'+data.items[i].id+'" style="width:660px;position:relative;overflow:auto;"><table width="660" border="0" align="center"><tr bgcolor="#FFFFFF"><td align="left"><span style="font-size:14px;">'+data.items[i].name+' : '+data.items[i].detail+'</span></td><td align="right" width="70"><span style="font-size:14px;">'+data.items[i].postTime+'</span></td><td align="right" valign="middle" width="17">'+data.items[i].del+'</td></tr></table></div>';
				$j("#chatBox").append(detail);
				$("lastId").value=data.items[i].id;
			}
		}
		$("lastId").value=data.lastId;

		var varRefresh=data.refresh;

		$("xxxxx").innerHTML="Refresh Rate : " + (data.refresh/1000).toFixed(2) + " sec";
		$j("div#chatBox").scrollTop(3000000);

		if(updateMsgTime)
			clearTimeout(updateMsgTime);
		updateMsgTime=setTimeout("updateMsg()",data.refresh);
		
	});

//	alert("updateMsgTime : " + window.updateMsgTime);


//	$("xxxxx").innerHTML=escape($("chatBox").innerHTML);
//	$j("#chatBox div").scrollTop($j("#chatBox div")[0].scrollHeight);

}
var updateUserTime;
function updateUserChat()
{
	$j.getJSON(path+"forum/shout.php?action=listUser",
	function(data)
	{
		$("amountUser").innerHTML="สมาชิก&nbsp;" + data.numUser + "&nbsp;&nbsp;บุคคลทั่วไป&nbsp;" + data.numGuest;
		$("listName").innerHTML="";

		for(var i=0;i<data.numUser;i++)
		{
			var detail='<div style="padding:5px;"><img src="'+path+'user/getDisplayImg.php?img='+data.listUser[i].username+'.jpg&r=' + new Date().getTime() + '" border="2" width="50" class="preloadImg"><br>'+data.listUser[i].displayName+'</div>';

			$j("#listName").append(detail);
		}
		if(updateUserTime)
			clearTimeout(updateUserTime);
		updateUserTime=setTimeout("updateUserChat()",300000);
	});
}
