/** 系统用脚本定义开始，普通用户不建议修改 **/
function ChatRoom()
{
	this.Title		;	// 房间名称
	this.URL		;	// 登录地址
	this.UserCount	;	// 在线人数
	this.MaxOnline	;	// 最高在线
	this.State		;	// 满员状态	0=正常 1=热闹 -1=满员禁止登录
	this.Topic		;	// 当前话题
	this.AdminNames ;	// 管理员名单
	this.RoomType	;	// 房间分类ID
	this.UserList = null ;	// 在线用户列表
}
function ChatServer()
{
	this.MaxOnline = 0 ;	// 最高在线
	this.RegUsers = 0 ;		// 总注册人数
	this.TotalUsers = 0 ;	// 当前在线人数
	
	this.m_pServer	= new Array();
	this.RoomsCount = function(){return this.m_pServer.length;}	// 房间数
	this.GetRoomObject = function(n) // 取得房间对象
	{	if(n < this.RoomsCount()) return this.m_pServer[n];
		return null;
	}
	this.SortRule= function(a, b)
	{	var n1 = a.UserCount ;
		var n2 = b.UserCount ;
		if(n1 == n2)	return 0 ;
		if(n1 > n2)		return -1 ;
		if(n1 < n2)		return 1;
	}
	this.Sort= function(){this.m_pServer.sort(this.SortRule);}
	this.Add = function(strTitle, strURL, nUserCount, nMax, nState, strTopic, strAdmins, nRoomType)
	{	var obj = new ChatRoom() ;
		obj.Title		= strTitle ;	// 房间名称
		obj.URL			= strURL;		// 登录地址
		obj.UserCount	= nUserCount ;	// 在线人数
		obj.MaxOnline	= nMax ;		// 最高在线
		obj.State		= nState ;		// 满员状态	0=正常 1=超员 -1=满员禁止登录
		obj.Topic		= strTopic ;	// 当前话题
		obj.AdminNames	= strAdmins ;	// 管理员名单
		obj.RoomType	= nRoomType ;	// 房间分类ID
		this.m_pServer[this.RoomsCount()] = obj ;
	}
	this.SetCount = function(nMax, nReg, nTotal)
	{	this.MaxOnline	= nMax ;
		this.RegUsers	= nReg ;
		this.TotalUsers = nTotal ;
	}
} 
var Server = new ChatServer() ;
/** 系统用脚本定义结束，普通用户不建议修改 **/

/* 请将本页所有 http://127.0.0.1:8888 替换为您已安装好的iChat聊天系统的任一端口 */
/*以下为系统变量和函数库，可以灵活调用,但不推荐修改*/
/*以下为功能模块，允许调整界面时适当修改*/
function OnLogin() // 登录聊天室
{	var n = login.roomlist.value ;
	if(n==-1){alert("请先选择房间后登录!") ;return;}
	if(!validstr(login.user))return ;
	var strBox = "" ;
	window.open("about:blank", "iChatMain", "toolbar=no,location=no,directories=no,menubar=no,resizable=yes") ;
	login.action = Server.GetRoomObject(n).URL + "Login" ;
	if(login.pass.value!="")
	{var pass = calcMD5(login.pass.value).slice(8,24).toLowerCase();
	login.pass.value=pass;}
	//alert(pass);
	login.submit() ;
}
function validstr(str) // 验证用户名
{ var s,i,j; s=" +=|'#&<>%*`^/\\\";,."; str1=str.value.toString();
  if (str.value.length <1){alert("呢称不能为空！");str.focus(); return false;}
  for (i=0; i<str1.length; i++)
  {	for(j=0;j<s.length;j++)
	{if (str1.charAt(i) == s.charAt(j))
     {	alert("名字中不能包含特殊字符: +=|'#&<>%*`^/\\\";,.空格.");
 		str.focus(); return false;
  }}}return true;
}
