var g_dLastLoginTime=new Date();
function doLogin(){
	d=new Date();
	if ((d-g_dLastLoginTime)<1000){//prevent calling login 2 times from one submit
		return;
	}else{
		g_dLastLoginTime=d;
	}
	var oRoomId=document.frmLogin.roomid;
	var iRoomId;
	if(oRoomId.type.indexOf("select")>=0){
		iRoomId=oRoomId.options[oRoomId.selectedIndex].value;
	}else{
		iRoomId=oRoomId.value;
	}
	authorize(document.frmLogin.loginusername.value,document.frmLogin.loginpassword.value,false,iRoomId);
}
function ChatOnAuthorized(sUser,iUserType,iRoomId){
	if ((iUserType & CHAT_USRT_SUPERUSER) || (iUserType & CHAT_USRT_SITEADMIN)){
		document.location="admin.aspx";
	}else{
		var agent = navigator.userAgent.toLowerCase();
		var ns = ((agent.indexOf('mozilla')>=0) && ((agent.indexOf('spoofer')<0) && (agent.indexOf('compatible')<0)));
		var ns_old = (ns && (parseInt(navigator.appVersion) <= 4));
		var aMathes=agent.match(new RegExp("msie ([\\d\\.]+)",""));
		var ie_ver=((null==aMathes)?0:parseFloat(aMathes[1]));
		
		if(ns_old || (ie_ver>0 && ie_ver<4)){
			document.location="fschat.htm";
		}else if (ie_ver>0 && ie_ver<5.5){
			document.location="chat_botup.htm";
		}else{
			document.location="chat.aspx";
		}
	}
}
function ChatOnIdentityRet(bExist,iFirstRmId,sFirstRmName){
	elemDisplChng("idLoggedinMsg",bExist);
	if(!bExist){
		SiteRoomListRequest();
	}
}
function formatRoomList(aRooms,sCurrentUser){
	var iRoomId,oRoom,i,j=0;

	var oSelect=document.frmLogin.roomid;
	if(!oSelect) return formatRoomListRadio(aRooms,sCurrentUser);
	if(oSelect.type.indexOf("select")<0){
		return "";
	}
	oSelect.length=0;

	var indx=SortdRmIndx(aRooms);
	for(i=0; i<indx.length; i++){
		iRoomId=indx[i];
		oRoom=aRooms[iRoomId];
		if(oRoom && !oRoom.isPrivate){
			oSelect.options[j++]= new Option(oRoom.name + " (" + oRoom.userCount + ")",iRoomId);
		}
	}
	
	if (i>0 && oSelect.options[0]) oSelect.options[0].selected=true;
	document.frmLogin.loginusername.focus();
	return "";
}
function formatRoomListRadio(aRooms,sCurrentUser){
	var iRoomId,oRoom;

	var bIsFirst=true;
	var sHtml="<table border=0>";
	for(iRoomId in aRooms){
		if(!isNaN(parseInt(iRoomId))){
			oRoom=aRooms[iRoomId];
			if(null!=oRoom && !oRoom.isPrivate){
				sHtml+="<tr><td>&nbsp;<input type=\"radio\" name=\"roomid\" value=\"" + iRoomId + "\"";
				if (bIsFirst){
					sHtml+=" checked";
					bIsFirst=false;
				}
				sHtml+="> " + oRoom.name + " (" + oRoom.userCount +  ")</td></tr>";
			}
		}
	}
	sHtml+="</table>";
	return sHtml;
}