var watchChat_slideBar =$("#watchChat_slideBar");
watchChat_slideBar.mousedown(function(e){
	var offset = $(this).offset();
	var y = e.pageY - offset.top;
	var _Pub = $("#watchChat_pub");
	var _Pri = $("#watchChat_pri");
	var _PubH = _Pub.height();
	var _PriH = _Pri.height();
	var _top = watchChat_slideBar.position().top;
	$(document.body)[0].onselectstart=function(){
		return false;
	};
	$("body").addClass("NoSelect");
	$(document).bind("mousemove",function(ev){
		var _y = ev.pageY - y - offset.top;
		if((_PubH+_y)<100 || (_PriH-_y)< 45 ){return false;}
		_Pub.height(_PubH+_y);
		_Pri.height(_PriH-_y);
		watchChat_slideBar.css("top",(_top+_y));
		$("#priHandBox").css("top",(_top+_y+40));
	});
	$(document).bind("mouseup",function(ev){
		$(document).unbind("mousemove");
		$(document.body)[0].onselectstart=function() {
			return ;
		};
		$("body").removeClass("NoSelect");
	});
});

$("#ManagerNav").find("li").click(function(){
	$("#ManagerNav").find("li.on")[0].className="";
	$(this)[0].className="on";
	$("#SkinBg").css("display","none");
	$("#SkinTop").css("display","none");
	$("#RoomNotice").css("display","none");
	$("#RoomPass").css("display","none");
	$("#"+$(this).attr("r")).show();
});

$("#Msg_Input").setCaret();

$("#btFace").click(function(){
	var isFaceShow = $("#faces").css("display")=="none"?true:false;
	if(isFaceShow)
	{
		$("#faces").css("display","block");
		$(document).bind("mouseup",function(e){
			if($(e.target).attr("isface")!="1" && $(e.target).attr("isface")!="2")
			{
				$("#faces").css("display","none");
				$(document).unbind("mouseup");
			}
			else if($(e.target).attr("isface")=="1")
			{
				$("#Msg_Input").insertAtCaret("/"+$(e.target).attr("title"));
			}
		});
	}
	else
	{
		$("#faces").css("display","none");
		$(document).unbind("mouseup");
	}
});

function faceTab(e,v)
{
	$("#faces").find("table").css("display","none");
	$("#faceRePage").find("a.on").removeClass("on");
	$("#FaceT"+e).css("display","block");
	$(v).addClass("on");
}

var pubHandBox = $("#pubHandBox");
var watchChat_pub = $("#watchChat_pub");
pubHandBox.mouseover(function(){
	$(this).css("display","block");
});
watchChat_pub.mouseover(function(){
	pubHandBox.css("display","block");
});
watchChat_pub.mouseout(function(){
	pubHandBox.css("display","none");
});
$(pubHandBox.find("button")[0]).click(function(){
	$("#PubChatList").html("");
});
$(pubHandBox.find("button")[1]).click(function(){
	var e = $(this).attr("class")=="rollAutoBtn";
	AutoRoll = !e;
	$(this).attr("class",e?"rollPauseBtn":"rollAutoBtn");
	
});

var priHandBox = $("#priHandBox");
var watchChat_pri = $("#watchChat_pri");
priHandBox.mouseover(function(){
	$(this).css("display","block");
});
watchChat_pri.mouseover(function(){
	priHandBox.css("display","block");
});
watchChat_pri.mouseout(function(){
	priHandBox.css("display","none");
});
$(priHandBox.find("button")[0]).click(function(){
	$("#PriChatList").html("");
});

var Fav = new Object();
Fav.set = function(e)
{
	if(iInfo.IsLogin==false){alert('游客无法进行关注!');return false;}
	var RUID=$("#RoomUserID")[0].value;
	if(RUID==iInfo.UserID){alert('不可关注自己!');return false;}
	////ajax--------------------------------------------------------------------------------------------------------------------------------------------------
	var Re=false;
	$.get("/Handle/A.asp", {rid:RUID,ac:'Attention',v:e,t:getDataTimes()},function(){
		var FavLink = $("#favorite");
		var Hstr = e?'已关注<a href="" onclick="Fav.set(false);return false;">取消</a><em></em>':'<a href="" onclick="Fav.set(true);return false;">+关注</a><em></em>';
		e?FavLink.addClass("favoriteOk"):FavLink.removeClass("favoriteOk");
		FavLink.html(Hstr);
	},"script");
};

function initFav(e)
{
	var FavLink = $("#favorite");
	var Hstr = e?'已关注<a href="" onclick="Fav.set(false);return false;">取消</a><em></em>':'<a href="" onclick="Fav.set(true);return false;">+关注</a><em></em>';
	e?FavLink.addClass("favoriteOk"):FavLink.removeClass("favoriteOk");
	FavLink.html(Hstr);
}

$($("#watchtitle").find("a")[0]).click(function(){
	$("#watchtitle").find("a.on").removeClass("on");
	this.className="on";
	$("#watchGift").css("display","none");
	$("#watchChat").css("display","block");
});

$($("#watchtitle").find("a")[1]).click(function(){
	$("#watchtitle").find("a.on").removeClass("on");
	this.className="on";
	$("#watchChat").css("display","none");
	$("#watchGift").css("display","block");
});

$($("#usertitle").find("a")[0]).click(function(){
	$("#usertitle").find("a.on").removeClass("on");
	this.className="on";
	$("#watchSpectator_people").css("display","none");
	$("#watchSpectator_manager").css("display","block");
});

$($("#usertitle").find("a")[1]).click(function(){
	$("#usertitle").find("a.on").removeClass("on");
	this.className="on";
	$("#watchSpectator_manager").css("display","none");
	$("#watchSpectator_people").css("display","block");
	///////////////////////////////$(this).find("span").text($("#watchSpectator_people").find("ul")[0].childNodes.length);
});

$("#FlyBtn").click(function(){
	PostMsg("Fly");
});

var GiftBox = $("#giftBox");
var GifftTab = GiftBox.find("ul.tab");
GifftTab.find("a").each(function(i,n){
	$(this).click(function(){
		GifftTab.find("a.on").removeClass("on");
		this.className="on";
		GiftBox.find("ul.gift").css("display","none");
		$(GiftBox.find("ul")[i+1]).css("display","block");
	});
});

$("#GiftNum").keyup(function(){     
        var tmptxt=$(this).val();     
        $(this).val(tmptxt.replace(/\D|^0/g,''));     
    }).bind("paste",function(){     
        var tmptxt=$(this).val();     
        $(this).val(tmptxt.replace(/\D|^0/g,''));     
}).css("ime-mode", "disabled");  


GiftBox.find("ul.gift").find("li").click(function(){
	if($("a.giftName").text() == $(this).find("span").text())
	{
		$("#GiftNum").attr("value",Number($("#GiftNum").attr("value"))+1);
		return ;
	}
	else
	{
		$("#GiftNum").attr("value",1);
	}
	$("#GiftPrice").attr({value:$(this).attr("price"),GiftID:$(this).attr("GiftID"),GiftClass:$(this).attr("GiftClass")})
	$("a.giftName").text($(this).find("span").text());
});

$("#SendGift").click(function(){
	var o = new Object();
	var GiftPrice = $("#GiftPrice");
	var guid = $("#GiftReceiveUser").attr("uid");
	if(GiftPrice.attr("GiftID") == "" || $("#GiftReceiveUser").attr("value") == ""){return false;}
	o.Msg = $("a.giftName").text() + ' <img class="' + $("#GiftPrice").attr("GiftClass") + ' giftSmall" src="/images/pixel.gif"> 共' + $("#GiftNum").attr("value") + "个" ;
	if(!/^(\+|-)?\d+$/.test(guid)){alert("无法向游客赠送礼物！");return false;}
	if(iInfo.IsLogin==false){alert("游客无法赠送礼物！");return false;}
	//ajax返回判断///////////////////////////////
	$.get("/Handle/SendGift.asp",{ac:'SendGift',guid:guid,giftid:GiftPrice.attr("GiftID"),giftnum:$("#GiftNum").attr("value"),giftname:$("a.giftName").text(),t:GetSendTime()},function(){
		if(SgRe==true)
		{
			PostMsg("Gift",o);
			o.GiftClass = $("#GiftPrice").attr("GiftClass");
			o.Msg = $("#GiftNum").attr("value") + "个" + $("a.giftName").text();
			_Sys_PostInfo("Sys_GiftRecord",o);
		}
		else
		{
			alert(SgRe);
			return false;
		}
	},"script");
	
});

var btfans30=$("#btsuperfans30");
var btfans=$("#btsuperfans");
var fans30=$("#superfans30");
var fans=$("#superfans");
btfans30.click(function(){
	btfans[0].className='';
	fans.css("display","none");
	this.className='on';
	fans30.css("display","block");
});


btfans.click(function(){
	btfans30[0].className='';
	fans30.css("display","none");
	this.className='on';
	fans.css("display","block");
});

////////////////bind over
var FaceArry=["狂笑","大笑","惊讶","害羞","窃笑","发怒","大哭","色色","坏笑","火大","汗","奸笑","欢迎","再见","白眼","挖鼻","顶","胜利","欧耶","抱拳","囧","淡定","美女","靓仔","神马","开心","给力","飞吻","眨眼","V","来吧","围观","飘过","地雷","菜刀","帅","审视","无语","无奈","亲亲","勾引","后后","吐血","啊哦","媚眼","愁人","肿么了","调戏","抽"];
var FaceTemplateStr='<img align="absmiddle" src="http://vr0.6.cn/imges/live/face_v13/{0}.gif">';
function ReplaceMsgToFace(str)
{
	var tstr=str;
	for(var i=0;i<str.split("/").length;i++)
	{
		$.each(FaceArry,function(i,e){
			if(tstr.indexOf("/"+e)>-1){tstr=tstr.replace("/"+e,$.format(FaceTemplateStr,i));}
		});
	}
	return tstr;
}

var LayerOvering = false;
var userManager = $("#userManager");
userManager.mouseover(function(){
	$(this).css("display","block");
	LayerOvering = true;
});

userManager.mouseout(function(){
	$(this).css("display","none");
	LayerOvering = false;
});

function LayerOver(m)
{
	if(m.id == "" || m.id == iInfo.UserID){return ;}
	InitLayer(m.id,$(m).find("a").text(),$(m).attr("roomid"));
	userManager.css({display:"block",top:$(m).offset().top,left:$("#watchSpectator_").offset().left - $("#watchSpectator_").width()-2});
	LayerOvering = true;
}

function LayerOut()
{
	userManager.css("display","none");
	LayerOvering = false;
}

function LayerClick(e)
{
	if(e.id == "" || e.id == iInfo.UserID){return ;}
	SetRUidPanel(false,$.trim($(e).find("a").text()),$(e).attr("id"));
}

function LinkLayerClick(m)
{
	//if(m.id == "" || m.id == iInfo.UserID || !(/^(\+|-)?\d+$/.test(m.id))){return ;}
	if(m.id == "" || m.id == iInfo.UserID ){return ;}
	var uid = m.id;
	m = $(m);
	InitLayer(uid,m.text(),m.attr("roomid"));
	userManager.css({display:"block",top:m.offset().top,left:m.offset().left + m.width()});
	SetRUidPanel(false,m.text(),uid);
}

function SetRUidPanel(e,uname,uid)//true public ,false private
{
	if(uid == iInfo.UserID){return ;}
	$("#IsPriMsg").attr("disabled",e);
	e?$("#IsPriMsg").attr("checked",false):"";
	$("#Msg_ReceiveUname").attr("value",e?"所有人":uname);
	$("#Msg_ReceiveUname").attr("GetUID",e?"0":uid);
	$("#Msg_ChangeTypeButton").css("display",e?"none":"block");
}

$("#Msg_ChangeTypeButton").click(function(){
	SetRUidPanel(true,"");
});


function InitLayer(uid,uname,roomid)
{
	$("#CurrentlayerUID").attr({value:uid,roomid:roomid,nick:uname});
	userManager.find("h6").text(uname);
	if(roomid){
		$("#into_room").attr("href","/"+roomid);
	}
	else
	{
		$("#into_room").attr("href","javascript:void(0)");
	}
}

$(document).click(function(e){
	var ev = document.all?window.event:e; 
	var ob = ev.srcElement?ev.srcElement:ev.target
	if(!LayerOvering && ob.className !="u")
	{
		userManager.hide();
	}
});

function SetGiftParam()
{
	var uid = $("#CurrentlayerUID").attr("value");
	var roomid = $("#CurrentlayerUID").attr("roomid");
	if(uid == iInfo.UserID){return ;}
	$("#GiftReceiveUser").attr({value:userManager.find("h6").text(),uid:uid,roomid:roomid});
	userManager.hide();
}



//private params
var AutoRoll = true;//is Auto Rool
var PostLoading = false;//Post Msg Space Time
var FlashLoaded = false;//Flash is Loaded
var _iLivePlayer,_iFlyMsgPlayer;

var MsgFormatStr = new Object();
MsgFormatStr.Normal = '<li class=""><span class="t">{1} </span><img src="/images/pixel.gif" class="{2}" style="display:none"><a href="javascript://" onclick="LinkLayerClick(this)" class="u" id="{3}">{4}</a> 对 <a href="javascript://" onclick="LinkLayerClick(this)" class="u" id="{5}">{6}</a><span class="urid">({5})</span> 说：<span>{8}</span></li>';
MsgFormatStr.NormalUnReceiveUID = '<li class=""><span class="t">{1} </span><img class="{2}" style="display:none" src="/images/pixel.gif"><a id="{3}" class="u" href="javascript://" onclick="LinkLayerClick(this)">{4}</a>： <span>{8}</span></li>';
MsgFormatStr.NormalPri = '<li class="undefined"><span class="t">{1} </span><img src="/images/pixel.gif" style="display:none" class="uIco {2}"><a id="{3}" class="u" href="javascript://" onclick="LinkLayerClick(this)">{4} </a><span class="urid">({3})</span> 对你说：{8}</li>';
MsgFormatStr.NormalPri2 = '<li class="undefined"><span class="t">{1} </span>你对<img src="/images/pixel.gif" style="display:none" class="uIco"><a id="{5}" class="u" href="javascript://" onclick="LinkLayerClick(this)">{6} </a><span class="urid">({5})</span> 说：{8}</li>';
MsgFormatStr.Sys = '<li class="notice"><span class="t">{1}</span><span class="sys">系统消息：{8}</span></li>';
MsgFormatStr.EnterRoom = '<li class="notice"><span class="t">{1} </span>欢迎 <img src="/images/pixel.gif" class="rich0 {2}"> "{4}" 进入房间</li>';
MsgFormatStr.Gift = '<li class="gift"><span class="t">{1} </span><a id="{3}" class="u" onclick="LinkLayerClick(this)" href="javascript://">{4} </a>向 <a id="{6}" class="u" onclick="LinkLayerClick(this)" href="javascript://">{5}</a> 送 {8}</li>';
MsgFormatStr.Fans = '';
MsgFormatStr.Sys_GiftRecord = '<li><a href="/{11}" target="_blank">{4}<span>({10})</span>  送给 {5}<span>({11})</span> {8}</a>  <img src="/images/pixel.gif" class="{7} giftSmall">  {1}</li>';
MsgFormatStr.AddUser = '<li onclick="LayerClick(this)" onmouseout="LayerOut()" onmouseover="LayerOver(this)" id="{0}" LevelID="{6}" roomid="{7}"  class=""><p><img src="/images/pixel.gif" class="rich0 {2} userLevelSmall"><img src="/images/pixel.gif" class="{3} vip0 userLevelSmall"><span class="urid1">{4}</span></p><p class="u"><img src="{5}" class="flogo"> <a>{1}</a></p></li>';
MsgFormatStr.Guest = '<li onclick="LayerClick(this)" onmouseout="LayerOut()" onmouseover="LayerOver(this)" id="{0}" LevelID="{6}" class=""><p><img src="/images/pixel.gif" class="rich0 {2} userLevelSmall"><img src="/images/pixel.gif" class="{3} vip0 userLevelSmall"><span class="urid1">{4}</span></p><p class="u"><img src="{5}" class="flogo"> <a style="color:#424542">{1}</a></p></li>';
MsgFormatStr.MoreUser = '<li class="userList_arrow" title="显示更多观众" onclick="getAllUser(this)"><img class="userList_arrow_down" src="/images/pixel.gif"></li>';

var UserListArr = new Array();
function AddUserList(e)
{
	e = Object(e);
	UserListArr.push(e);
	var NewMsgHtml = $.format(e.IsLogin?MsgFormatStr.AddUser:MsgFormatStr.Guest,e.UserID,e.UserNickName,e.LevelClass,e.VIPIcon,e.BestAccount,e.FixIcon,e.LevelID,e.RoomID);
	
	ListAddSort($("#UserList"),e,NewMsgHtml);
	if(e.IsManager)
	{
		ListAddSort($("#ManagerList"),e,NewMsgHtml);
		SetManagerNum($("#ManagerList").find("li").length);
	}
	EnterRoom(e);
}

function LeaveUser(peerid)
{
	var e = Object(GetUserListArrByPeerID(peerid));
	if(e.UserID==parseInt($("#RoomUserID").attr("value")))
	{
		var tstr='<li class="notice"><span class="t">'+GetSendTime()+'</span><span class="sys">系统消息：<a href="javascript:void(0)">对方离开了房间！</a></span></li>';
		_iLivePlayer._IsLive(false);
		$("#PubChatList").append(tstr);
		var Control=$("#watchChat_pub").find("ul");
		AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
	}
	$("#UserList")[0].removeChild($("#UserList").find("#"+e.UserID)[0]);
	if(e.IsManager)
	{
		$("#ManagerList")[0].removeChild($("#ManagerList").find("#"+e.UserID)[0]);
		SetManagerNum($("#ManagerList").find("li").length);
	}
}

function ClearUserList()
{
	var e = iInfo;
	$("#UserList")[0].innerHTML="";
	$("#ManagerList")[0].innerHTML="";
	AddUserList(e);
	SetUserNum($("#UserList").find("li").length);
	SetManagerNum($("#ManagerList").find("li").length);
}

function EnterRoom(o)
{
	if(o.PeerID == iInfo.PeerID || Number(o.EnterTime) < Number(iInfo.EnterTime) ){return ;}
	var e = new Object();
	e.Type = "Enter";//0
	e.Class = "";//1
	e.Time = GetSendTime();//2
	e.LevelClass = o.VIPIcon;//3
	e.PostUID = o.UserID;//4
	e.PostUName = o.UserNickName;//5
	e.ReceiveUID = "";//6
	e.ReceiveUName = "";//7
	e.ReceiveRID = "";//8
	e.Msg = "";//9
	e.SysMsgLinkUrl = "";//10
	e.GiftClass = "";//11
	e.IsPublic = true;//12
	e.IsGiftRecord = false;//13
	ReceiveInfo(e);
}

function ListAddSort(List,e,Html)
{
	try
	{
		List.find("#"+e.UserID).remove();
	}
	catch(err){}
	var MaxDom;
	if(Number(List.find("li:first").attr("LevelID"))<Number(e.LevelID)||Number(iRoomID)==Number(e.RoomID))
	{
		List.prepend(Html);
	}
	else if(Number(List.find("li:last").attr("LevelID"))>Number(e.LevelID))
	{
		List.append(Html);
	}
	else
	{
		List.find("li").each(function(){
			if(Number($(this).attr("LevelID"))>Number(e.LevelID))
			{
				MaxDom = $(this);
			}
		});
		if(MaxDom)
		{
			MaxDom.after(Html);
		}
		else
		{
			List.prepend(Html);
		}
	}
}


function GetUserListArrByPeerID(e)
{
	var Re = new Object();
	var Ri = -1;
	$.each(UserListArr,function(i,n){
		if(String(n.PeerID)==String(e))
		{
			Re = n;
			Ri = i;
		}
	});
	UserListArr.splice(Ri,1);
	return Re;
}

function DisLive(e,paramstr)
{
	if(!e)
	{
		$("#LivePlayer").html("");
		return ;
	}
	var strtime = getDataTimes();
	var swfVersionStr = "11.1.0";
	var xiSwfUrlStr = "/swf/playerProductInstall.swf";
	var flashvars = {};
	var params = {};
	params.quality = "high";
	params.wmode = "Opaque";
	params.bgcolor = "#000000";
	params.allowscriptaccess = "sameDomain";
	params.allowfullscreen = "true";
	var attributes = {};
	attributes.id = "iLivePlayer";
	attributes.name = "iLivePlayer";
	attributes.align = "middle";
	var Live_Type="3";
	swfobject.embedSWF("/swf/LivePlayer_2.3.swf?"+paramstr+"Live_Type="+Live_Type+"&"+strtime, "TLivePlayer","460", "345", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
}
/*e.Class   //0
e.Time   //1
e.LevelClass   //2
e.PostUID   //3
e.PostUName   //4
e.ReceiveUID   //5
e.ReceiveUName   //6
e.GiftClass   //7
e.Msg   //8
*/
function ReceiveInfo(e)
{
	//e = Object(e);
	if(e.ReceiveUID == iInfo.UserID)
	{
		switch(e.Type)
		{
			case "Nosay":
				NoSay();
				break;
			case "Say":
				Say();
				break;
			case "Kick":
				Kick();
				break;
		}
	}
	switch(e.Type)
	{
		case "Manager":
			Manager(e.Msg);
			return false;
			break;
		case "NoManager":
			NoManager(e.Msg);
			return false;
			break;
	}
	var FormatStr = "";
	var ControlStr = "";
	var Control;
	var NewMsgHtml;
	var UlMaxNum;
	if(e.IsGiftRecord)
	{
		FormatStr = MsgFormatStr.Sys_GiftRecord;
		ControlStr = "#gxzi1pcy";
		UlMaxNum = 4;
	}
	else
	{
		if(e.IsPublic)
		{
			switch(e.Type)
			{
				case "Msg":
					FormatStr = e.ReceiveUID == "0"?MsgFormatStr.NormalUnReceiveUID:MsgFormatStr.Normal;
					ControlStr = "#watchChat_pub";
					e.Msg=ReplaceKeys(e.Msg);//replace keys
					e.Msg = ReplaceMsgToFace(e.Msg);
					UlMaxNum = 40;
					break;
				case "Enter":
					FormatStr = MsgFormatStr.EnterRoom;
					ControlStr = "#watchChat_pub";
					UlMaxNum = 40;
					break;
				case "Gift":
					FormatStr = MsgFormatStr.Gift;
					ControlStr = "#watchChat_pub";
					UlMaxNum = 40;
					break;
				case "Sys":
					FormatStr = MsgFormatStr.Sys;
					ControlStr = "#watchChat_pub";
					UlMaxNum = 40;
					e.Time = GetSendTime();
					break;
				case "Fly":
					PlySwf.show();
					e.Msg=ReplaceKeys(e.Msg);//replace keys
					e.Msg = ReplaceMsgToFace(e.Msg);
					_iFlyMsgPlayer.jsExec(e.PostUName+"："+e.Msg,48);
					return false;
					break;
				case "Fans":
					break;
			}
		}
		else
		{
			switch(e.Type)
			{
				case "Msg":
					if(e.PostUID == iInfo.UserID)
					{
						FormatStr = MsgFormatStr.NormalPri2;
						ControlStr = "#watchChat_pri";
						UlMaxNum = 20;
					}
					else if(e.ReceiveUID == iInfo.UserID)
					{
						FormatStr = MsgFormatStr.NormalPri;
						ControlStr = "#watchChat_pri";
						UlMaxNum = 20;
					}
					e.Msg=ReplaceKeys(e.Msg);//replace keys
					e.Msg = ReplaceMsgToFace(e.Msg);
					break;
				case "Sys":
					FormatStr = MsgFormatStr.Sys;
					ControlStr = "#watchChat_pri";
					UlMaxNum = 20;
					e.Time = GetSendTime();
					break;
			}
		}
	}
	NewMsgHtml = $.format(FormatStr,e.Class,e.Time,e.LevelClass,e.PostUID,e.PostUName,e.ReceiveUID,e.ReceiveUName,e.GiftClass,e.Msg,e.FixIcon,e.PostUserRoomID,e.ReceiveUserRoomID);
	Control = $(ControlStr);
	var ControlUl = Control.find("ul");
	ControlUl.append(NewMsgHtml);
	AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
	if(AutoRoll && ControlUl[0].childNodes.length>UlMaxNum)
	{
		for(i=0;i<(ControlUl[0].childNodes.length-UlMaxNum);i++)
		{
			ControlUl[0].removeChild(ControlUl[0].firstChild);
		}
	}
}

function CheckMsg()
{
	if(CheckNoSay())
	{
		PostMsg('Msg');
	}
	return false;
}

function CheckNoSay()
{
	if($.cookie("NoSay_"+iRoomID))
	{
		if(new Date().format("yyyy-MM-dd hh:mm:ss").localeCompare($.cookie("NoSay_"+iRoomID))==-1)
		{
			alert("您被管理员禁言到"+$.cookie("NoSay_"+iRoomID));
			return false;
		}
	}
	return true;
}

function PostMsg(MsgType,o)
{
	if(PostLoading || !FlashLoaded){return false;}
	var o = Object(o);
	var e = new Object();
	e.Type = MsgType;//0
	e.Class = "";//1
	e.Time = GetSendTime();//2
	e.LevelClass = iInfo.LevelClass;//3
	e.PostUID = iInfo.UserID;//4
	e.PostUName = iInfo.UserNickName;//5
	e.ReceiveUID = $("#Msg_ReceiveUname").attr("getuid");//6
	e.ReceiveUName = $("#Msg_ReceiveUname").attr("value");//7
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	e.Msg = o.Msg?o.Msg:$("#Msg_Input").attr("value");//9
	e.SysMsgLinkUrl = "";//10
	e.GiftClass = "";//11
	e.IsPublic = MsgType == "Fly"?true:!$("#IsPriMsg").attr("checked");//12
	e.IsGiftRecord = false;//13
	e.FixIcon = iInfo.FixIcon;
	if(MsgType == "Gift")
	{
		e.ReceiveUID = $("#GiftReceiveUser").attr("value");//6
		e.ReceiveUName = $("#GiftReceiveUser").attr("uid");//7
		e.IsPublic = true;//12
	}
	if(MsgType=="Msg"&&e.Msg==""){alert("请输入聊天内容！");return false;}
	if(MsgType=="Msg"&&e.Msg.length>100){alert("聊天内容不得超过100个字符！");return false;}
	if(MsgType == "Fly"&&iInfo.IsLogin==false){alert("游客不允许发送飞屏！");return false;}
	if(!e.IsPublic&&iInfo.IsLogin==false){alert("游客不允许私聊！");return false;}
	if(!e.IsPublic&&/^(\+|-)?\d+$/.test(e.ReceiveUID))
	{
		var tRe=true;
		$.get("/Handle/GetUserBlackList.asp",{ac:"GetUserBlackList",uid:e.ReceiveUID,t:GetSendTime},function(){
			BLRe=BLRe.split(",");
			$.each(BLRe,function(i,e){
				if(parseInt(iInfo.UserID)==parseInt(e)){tRe = false;}
			});
			if(!tRe){alert("对方不允许私聊！");return false;}
			//////////////
			_iLivePlayer._PostInfo(e);
			$("#Msg_Input").focus();
			ReceiveInfo(e);
			if(!o.PostLoading)
			{
				PostLoading = true;
				$("#Msg_Input").attr("value","");
				$("#Msg_SendButton").addClass("actBtn-skin-gray");
				setTimeout(function(){$("#Msg_SendButton").removeClass("actBtn-skin-gray");PostLoading = false;},3000);
			}
			/////////
		},"script");
	}
	else if(MsgType == "Fly")
	{
		var tRe=true;
		$.get("/Handle/SendFly.asp",{ac:"SendFly",guid:e.ReceiveUID,t:GetSendTime},function(){
			if(FlyRe==true)
			{
				//////////////
				_iLivePlayer._PostInfo(e);
				$("#Msg_Input").focus();
				ReceiveInfo(e);
				if(!o.PostLoading)
				{
					PostLoading = true;
					$("#Msg_Input").attr("value","");
					$("#Msg_SendButton").addClass("actBtn-skin-gray");
					setTimeout(function(){$("#Msg_SendButton").removeClass("actBtn-skin-gray");PostLoading = false;},3000);
				}
				/////////
			}
			else
			{
				alert(FlyRe);
				return false;
			}
		},"script");
	}
	else if(MsgType == "Gift")
	{
		///////////
		_iLivePlayer._PostInfo(e);
		$("#Msg_Input").focus();
		ReceiveInfo(e);
		///////////
	}
	else
	{
		///////////
		_iLivePlayer._PostInfo(e);
		$("#Msg_Input").focus();
		ReceiveInfo(e);
		if(!o.PostLoading)
		{
			PostLoading = true;
			$("#Msg_Input").attr("value","");
			$("#Msg_SendButton").addClass("actBtn-skin-gray");
			setTimeout(function(){$("#Msg_SendButton").removeClass("actBtn-skin-gray");PostLoading = false;},3000);
		}
		///////////
	}
	return false;
}

function _Sys_PostInfo(MsgType,o)/////////////////////////////-------------------------------------------------------------------------
{
	var e = new Object();
	e.Type = MsgType;//0
	e.Class = "";//1
	e.Time = GetSendTime();//2
	e.LevelClass = iInfo.LevelClass;//3
	e.PostUID = iInfo.UserID;//4
	e.PostUName = iInfo.UserNickName;//5
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	e.Msg = o.Msg?o.Msg:$("#Msg_Input").attr("value");//9
	e.SysMsgLinkUrl = "";//10
	e.GiftClass = o.GiftClass;//11
	e.IsPublic = !$("#IsPriMsg").attr("checked");//12
	e.FixIcon = iInfo.FixIcon;
	e.ReceiveUID = $("#Msg_ReceiveUname").attr("getuid");//6
	e.ReceiveUName = $("#Msg_ReceiveUname").attr("value");//7
	
	if(MsgType == "Sys_GiftRecord")
	{
		e.Type = "Sys";
		e.ReceiveUID = $("#GiftReceiveUser").attr("value");//6
		e.ReceiveUName = $("#GiftReceiveUser").attr("uid");//7
		e.GiftClass = o.GiftClass;//11
		e.IsGiftRecord = true;//13
		e.PostUserRoomID = iInfo.RoomID;
		e.ReceiveUserRoomID = $("#GiftReceiveUser").attr("roomid");
		e.IsPublic = true;
	}
	_iLivePlayer._Sys_PostInfo(e);
	ReceiveInfo(e);
	return false;
}

function SetUserNum(e)
{
	$("#UserNum").text(e);
	if(e>100){$("#UserList").append(MsgFormatStr.MoreUser);}
}

function SetManagerNum(e)
{
	$("#ManagerNum").text(e);
}

function _FlashLoaded()
{
	_iLivePlayer = getSWF("iLivePlayer");
	_iFlyMsgPlayer = getSWF("iFlyMsgPlayer");
	FlashLoaded = true;
	$("#Msg_SendButton").removeClass("actBtn-skin-gray");
	PlySwf.remove();
	setTimeout('UpdateRoomOnline()',10000);//update room online user num,10second later	
	window.setInterval('UpdateRoomOnline()',300000);//update room online user num,5minute later	
	_iLivePlayer._IsLive(IsLive);
}

function UpdateRoomOnline()
{
	$.get("/Handle/UpdateRoomOnline.asp",{ac:'uproomnum',t:getDataTimes(),rid:iInfo.Live_NG_ID,v:$("#UserNum").text()});
}

var PlySwf = new Object();
PlySwf.show = function()
{
	$(_iFlyMsgPlayer).css("visibility","visible");
};
PlySwf.remove = function()
{
	$(_iFlyMsgPlayer).css("visibility","hidden");
};

function InFlyMsg()
{
	var strtime = getDataTimes();
	var swfVersionStr = "10.0.0";
	var xiSwfUrlStr = "/swf/playerProductInstall.swf";
	var flashvars = {};
	var params = {};
	params.quality = "high";
	params.wmode = "transparent";
	params.bgcolor = "#000000";
	params.allowscriptaccess = "sameDomain";
	params.allowfullscreen = "true";
	var attributes = {};
	attributes.id = "iFlyMsgPlayer";
	attributes.name = "iFlyMsgPlayer";
	attributes.align = "middle";
	swfobject.embedSWF("/swf/FlyMsg.swf?"+"&"+strtime, "iFlyMsgPlayer","100%", "100%", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
}

function AddFriend()
{
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	if(iInfo.IsLogin==false){alert("游客无法添加好友！");return false;}
	if(!/^(\+|-)?\d+$/.test(tCurrentUID)){alert("无法添加游客为好友！");return false;}
	$.get("/Handle/MenuAddFriend.asp",{ac:'AddFriend',uid:tCurrentUID,rid:iRoomID,t:GetSendTime()},function(){
		if(addfriendRe==true)
		{
			alert('操作成功！');
		}
		else
		{
			alert(addfriendRe);
		}
	},"script");
}

function Attention()
{
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	if(iInfo.IsLogin==false){alert("游客无法关注！");return false;}
	if(!/^(\+|-)?\d+$/.test(tCurrentUID)){alert("无法关注游客！");return false;}
	$.get("/Handle/MenuAttention.asp",{ac:'Attention',uid:tCurrentUID,rid:iRoomID,t:GetSendTime()},function(){
		if(AttentionRe==true)
		{
			alert('操作成功！');
		}
		else
		{
			alert(AttentionRe);
		}
	},"script");
}

function Black()
{
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	if(iInfo.IsLogin==false){alert("游客无法设置黑名单！");return false;}
	if(!/^(\+|-)?\d+$/.test(tCurrentUID)){alert("无法将游客设置为黑名单！");return false;}
	$.get("/Handle/MenuBlack.asp",{ac:'Black',uid:tCurrentUID,rid:iRoomID,t:GetSendTime()},function(){
		if(BlackRe==true)
		{
			alert('操作成功！');
		}
		else
		{
			alert(BlackRe);
		}
	},"script");
}

function GetNewTime(AddMinute)
{
	var d = new Date(new Date() - AddMinute * 60 * 1000 * -1);
	return d.format("yyyy-MM-dd hh:mm:ss");
}

function NoSay()
{
	if(iRoomID==iInfo.RoomID){return false;}
	$.cookie("NoSay_"+iRoomID, GetNewTime(5), { path: '/', expires: 365 });
	var tstr='<li class="notice"><span class="t">'+GetNewTime(0)+'</span><span class="sys">系统消息：您被管理员禁言到 '+$.cookie("NoSay_"+iRoomID)+'！</span></li>';
	$("#PubChatList").append(tstr);
	var Control=$("#watchChat_pub").find("ul");
	AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
}

function Say()
{
	if(iRoomID==iInfo.RoomID){return false;}
	$.cookie("NoSay_"+iRoomID, GetNewTime(0), { path: '/', expires: 365 });
	var tstr='<li class="notice"><span class="t">'+GetNewTime(0)+'</span><span class="sys">系统消息：您被管理员恢复了发言！</span></li>';
	$("#PubChatList").append(tstr);
	var Control=$("#watchChat_pub").find("ul");
	AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
}

function Kick()
{
	if(iRoomID==iInfo.RoomID){return false;}
	$.cookie("Kick_"+iRoomID, GetNewTime(60), { path: '/', expires: 365 });
	location.href="/i/v2/Kick.html";
}

function SetNosay()
{
	if(!iInfo.IsManager){alert("您不是该房间管理员,无权限进行操作！");return false;}
	if(parseInt($("#CurrentlayerUID").attr("value"))==parseInt($("#RoomUserID").attr("value"))){alert("无权限！");return false;}
	var e = new Object();
	e.Type = "Nosay";//0
	e.Time = GetSendTime();//2
	e.PostUID = iInfo.UserID;//4
	e.ReceiveUID = $("#CurrentlayerUID").attr("value");//6
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	_iLivePlayer._PostInfo(e);
	userManager.hide();
}

function Setsay()
{
	if(!iInfo.IsManager){alert("您不是该房间管理员,无权限进行操作！");return false;}
	if(parseInt($("#CurrentlayerUID").attr("value"))==parseInt($("#RoomUserID").attr("value"))){alert("无权限！");return false;}
	var e = new Object();
	e.Type = "Say";//0
	e.Time = GetSendTime();//2
	e.PostUID = iInfo.UserID;//4
	e.ReceiveUID = $("#CurrentlayerUID").attr("value");//6
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	_iLivePlayer._PostInfo(e);
	userManager.hide();
}

function SetKick()
{
	if(!iInfo.IsManager){alert("您不是该房间管理员,无权限进行操作！");return false;}
	if(parseInt($("#CurrentlayerUID").attr("value"))==parseInt($("#RoomUserID").attr("value"))){alert("无权限！");return false;}
	var e = new Object();
	e.Type = "Kick";//0
	e.Time = GetSendTime();//2
	e.PostUID = iInfo.UserID;//4
	e.ReceiveUID = $("#CurrentlayerUID").attr("value");//6
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	_iLivePlayer._PostInfo(e);
	userManager.hide();
}

function SetNoManager()
{
	if(iInfo.RoomID!=iRoomID){alert("您不是该房间创建者,无权限进行操作！");return false;}
	if(parseInt($("#CurrentlayerUID").attr("value"))==parseInt($("#RoomUserID").attr("value"))){alert("无权限！");return false;}
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	if(!/^(\+|-)?\d+$/.test(tCurrentUID)){alert("无法对游客进行设置！");return false;}
	$.get("/Handle/MenuSetNoManager.asp",{ac:'SetNoManager.asp',uid:tCurrentUID,t:GetSendTime()},function(){
		if(ManagerRe==true)
		{
			alert('操作成功！');
		}
		else
		{
			alert(ManagerRe);
		}
	},"script");
}

function SetManager()
{
	if(iInfo.RoomID!=iRoomID){alert("您不是该房间创建者,无权限进行操作！");return false;}
	if(parseInt($("#CurrentlayerUID").attr("value"))==parseInt($("#RoomUserID").attr("value"))){alert("无权限！");return false;}
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	if(!/^(\+|-)?\d+$/.test(tCurrentUID)){alert("无法将游客设置为管理员！");return false;}
	$.get("/Handle/MenuSetManager.asp",{ac:'SetManager',uid:tCurrentUID,t:GetSendTime()},function(){
		if(ManagerRe==true)
		{
			alert('操作成功！');
		}
		else
		{
			alert(ManagerRe);
		}
	},"script");
}

function NoManager(e)
{
	var tstr='<li class="notice"><span class="t">'+GetNewTime(0)+'</span><span class="sys">系统消息：<a>'+e+' 被取消了本房间的管理员身份！</a></span></li>';
	$("#PubChatList").append(tstr);
	var Control=$("#watchChat_pub").find("ul");
	AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
}

function Manager(e)
{
	var tstr='<li class="notice"><span class="t">'+GetNewTime(0)+'</span><span class="sys">系统消息：<a>'+e+' 被设置为了本房间管理员！</a></span></li>';
	$("#PubChatList").append(tstr);
	var Control=$("#watchChat_pub").find("ul");
	AutoRoll?Control[0].scrollTop = Control[0].scrollHeight:"";
}

function PostManager(ReceiveUID)
{
	var e = new Object();
	e.Type = "Manager";//0
	e.Time = GetSendTime();//2
	e.PostUID = iInfo.UserID;//4
	e.ReceiveUID = ReceiveUID;//6
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	e.Msg = $("#UserList").find("#"+ReceiveUID).find("a").text();
	_iLivePlayer._PostInfo(e);
	Manager(e.Msg);
}

function PostNoManager(ReceiveUID)
{
	var e = new Object();
	e.Type = "NoManager";//0
	e.Time = GetSendTime();//2
	e.PostUID = iInfo.UserID;//4
	e.ReceiveUID = ReceiveUID;//6
	e.ReceiveRID = iInfo.Live_NG_ID;//8
	e.Msg = $("#UserList").find("#"+ReceiveUID).find("a").text();
	_iLivePlayer._PostInfo(e);
	NoManager(e.Msg);
}

function PubSay()
{
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	var tCueentNick =$("#CurrentlayerUID").attr("nick");
	SetRUidPanel(false,tCueentNick,tCurrentUID);
	$("#IsPriMsg").attr("checked",false)
}

function PriSay()
{
	if(iInfo.IsLogin==false){alert("游客无法私聊！");return false;}
	var tCurrentUID =$("#CurrentlayerUID").attr("value");
	var tCueentNick =$("#CurrentlayerUID").attr("nick");
	SetRUidPanel(false,tCueentNick,tCurrentUID);
	$("#IsPriMsg").attr("checked",true)
}

function LivePublish()
{
	$.get("/Handle/UpdateLiveTime.asp",{ac:'UpdateLiveTime',t:GetSendTime()},function(){},"script");
	UpdateLiveTime();
	window.setInterval('UpdateLiveTime()',5*60*1000);
}
function UpdateLiveTime()
{
	$.get("/Handle/UpdateForTime.asp",{ac:'UpdateForTime',t:GetSendTime()},function(){},"script");
}

function StopPublish()
{
	$.get("/Handle/UpdateLiveTime.asp",{ac:'StopLiveTime',t:GetSendTime()},function(){},"script");
}

function ReplaceKeys(istr)
{
	istr=htmlencode(istr)
	var rarr=rKeys.split("_");
	for(var c=0;c<rarr.length;c++)
	{
		while(istr.indexOf(rarr[c])>-1)
		{
			istr = istr.replace(rarr[c],'*');
		}
	}
	return istr;
}

function htmlencode(str) {
	while(str.indexOf('&')>-1){str = str.replace(/&/g, '&amp;');}
	while(str.indexOf('!')>-1){str = str.replace(/!/g, '！');}
	while(str.indexOf('<')>-1){str = str.replace(/</g, '&lt;');}
	while(str.indexOf('>')>-1){str = str.replace(/>/g, '&gt;');}
	str = str.replace(/(?:t| |v|r)*n/g, '<br/>');
	while(str.indexOf('  ')>-1){str = str.replace(/  /g, '&nbsp;');}
	str = str.replace(/x22/g, '&quot;');
	str = str.replace(/x27/g, '&#39;');
	return str;
}

//AddUserList(iInfo);
SetRUidPanel(true,"");
DisLive(true,"");
InFlyMsg();

/*var arr = new Array();
arr[10]="cc";
arr[99]="bbb"
alert(arr[10]+":"+arr.join(","));*/