// JavaScript Document
function FEGameBasic(__root,paraObj)
{
	FEFrameworkBasic.inherits(this,arguments)

	var _super = this.superObj ;
	var _this = this ;
	this.superObj = null ;
	this.loginFlag = false ;
	this.userBreakFlag = false ;
	this.username = null ;
	this.password = null ;
	this.rememberFlag = false ;
	this.guestFlag = false ;
	this.debug = false;
	
	this.setSockteObj = _setSockteObj ;
	this.sendSockte = _sendSockte ;
	
	this.getRoomUsingFlag = _getRoomUsingFlag ;
	this.getErrMsgList = _getErrMsgList ;
	this.autoFoundErrKey = _autoFoundErrKey ;
	this.autoGetErrText = _autoGetErrText ;
	this.getErrText = _getErrText ;
	this.getTextByLanguage = _getTextByLanguage ;
	this.clearRemember = _clearRemember ;
	this.rememberUser = _rememberUser ;
	this.rememberUserLongTime = _rememberUserLongTime ;
	this.getAutoLoginFlag = _getAutoLoginFlag ;
	this.autoLogin = _autoLogin ;
	this.getUserNickName = _getUserNickName ;
	this.getCookieUserName = _getCookieUserName ;

	this.checkCookieKey = "FreeElvenGameUserPage" ;
	this.usrenameCookieKey = "FreeElvenGameUserName" ;
	this.passwordCookieKey = "FreeElvenGameUserPassWord" ;
	this.rememberCookieKey = "FreeElvenGameRememberPassWord" ;
	
	this.getGameInfo = _getGameInfo ;
	this.getRuleRoomInfo = _getRuleRoomInfo ;
	this.getRuleInfo = _getRuleInfo ;
	this.getAllRuleInfo = _getAllRuleInfo ;
	this.getRoomInfo = _getRoomInfo ;

	var sockteObj = null ;
	
	var sockteTimerId = -1 ;
	var sockteInterval = 1000 ;
	var sockteList = new Array() ;
	
	var checkCookieFlag = false ;
	var checkCookieTimer = 50 ;
	var checkCookieTimerId = -1 ;
	var cObj = new FECookieHandler();
	var languageObj = new LanguageText()
	var roomNameObj = new LanguageGameRoomRuleName();

	main( paraObj ) ;
	function main( paraObj )
	{
		if( typeof autoCheckCookie == "boolean" && autoCheckCookie )
		{
			window.attachEvent( "onload" , cookieOnLoad ) ;
		}
		window.attachEvent( "onunload" , cookieOnUnLoad ) ;
	}
	
	function _sendSockte( xmlData )
	{
		sockteList[ sockteList.length ] = xmlData ;
		if( sockteList.length == 1 )
		{
			doSendSockteObj() ;
		}
	}
	function doSendSockteObj()
	{
		if( sockteObj == null )
		{
			return ;	
		}
		if( sockteList.length == 0 )
		{
			return ;	
		}
		var xmlData = sockteList.pop() ;
		//alert(xmlData)
		sockteObj.sendSockte( xmlData ) ;
		if( sockteList.length > 0 )
		{
			setTimeout( doSendSockteObj , sockteInterval ) ;
		}
	}
	
	function _getRoomUsingFlag()
	{
		cObj.initAllCookie() ;
		return cObj.getByKey( _this.checkCookieKey ) != null ;
	}
	
	function _autoGetErrText( xmlRoot , _splitStr )
	{
		return _getErrText( _getErrMsgList( xmlRoot ) , _splitStr )
	}
	
	function _getErrMsgList( xmlRoot )
	{
		return _super.getXMLHandler().getXmlNodesByName( xmlRoot , "err" ) ;
	}
	
	function _autoFoundErrKey(xmlRoot,key)
	{
		var list = _getErrMsgList( xmlRoot );
		for( var i = 0 ; i < list.length ; i++ )
		{
			if( _super.getXMLHandler().getXmlNodeText( list[ i ] ) == key )
			{
				return true ;	
			}
		}
		return false ;
	}
	
	function _getErrText( list , _splitStr )
	{
		var splitStr = _super.getOtherHandler().getVar( _splitStr , "<br/>" ) ;
		var result = "" ;
		for( var i = 0 ; i < list.length ; i++ )
		{
			var s = _getTextByLanguage( _super.getXMLHandler().getXmlNodeText( list[ i ] ) ) + splitStr ;
			result += s ;
		}
		return result ;
	}
	
	function _getTextByLanguage()
	{
		if( arguments.length <= 0 )
		{
			return "" ;	
		}
		var key = arguments[ 0 ] ;	
		var obj = languageObj[ key ] ;
		if( typeof obj == "undefined" )
		{
			return "" ;	
		}
		else if( typeof obj == "function" )
		{
			var paraStr = "" ;
			for( var i = 1 ; i < arguments.length ; i++ )
			{
				paraStr += "arguments[ " + i + " ] , " ;
			}
			paraStr = paraStr.replace( /(^[,\s]+)|([,\s]+$)/gi , "" ) ;
			var sss = eval( " obj( " + paraStr + " ) " ) ;
			//alert(sss)
			return sss ;
		}
		return obj ;
	}
		
	function _getGameInfo(key)
	{
		return typeof roomNameObj.getGameNameList()[key] != "undefined" ? roomNameObj.getGameNameList()[key]:null;
	}
	function _getRuleRoomInfo(key)
	{
		return typeof roomNameObj.getRuleRoomeList()[key] != "undefined" ? roomNameObj.getRuleRoomeList()[key]:null;
	}
	function _getRuleInfo(key)
	{
		return typeof roomNameObj.getRuleNameList()[key] != "undefined" ? roomNameObj.getRuleNameList()[key]:null;
	}
	function _getAllRuleInfo()
	{
		return roomNameObj.getRuleNameList();
	}
	function _getRoomInfo(key)
	{
		return typeof roomNameObj.getRoomList()[key] != "undefined" ? roomNameObj.getRoomList()[key]:null;
	}
	
	function cookieOnLoad()
	{
		checkUserPage() ;
	}
	
	function cookieOnUnLoad()
	{
		endCheckUserPage() ;
	}
	
	function _setSockteObj( id )
	{
		sockteObj = document.getElementById( id ) ;
	}
	
	function checkUserPage()
	{
		if( cObj.getByKey( _this.checkCookieKey ) != null )
		{
			alert( FEG.getTextByLanguage( "hadOpenLobby" ) , checkCookieTimer ) ;
			window.opener = null ;
			window.close();
			return ;
		}
		checkCookieFlag = true ;
		doCheckUserPage()
		checkCookieTimerId = setInterval( doCheckUserPage , checkCookieTimer * 1000 ) ;
	}
	function doCheckUserPage()
	{
		var d = _super.getOtherHandler().DateAdd( "s" , checkCookieTimer , ( new Date() ) )
		cObj.setByKey( _this.checkCookieKey , "true" , d ) ;
		_rememberUser()
	}
	function _clearRemember()
	{
		cObj.setByKey( _this.rememberCookieKey , _this.username , ( new Date() ) )
	}
	function _rememberUser()
	{
		var d = _super.getOtherHandler().DateAdd( "s" , checkCookieTimer , ( new Date() ) )
		var d2 = _super.getOtherHandler().DateAdd( "yyyy" , 3 , ( new Date() ) )
		if( !_this.rememberFlag && !_this.guestFlag && _this.username != null && _this.password != null )
		{
			cObj.setByKey( _this.usrenameCookieKey , _this.username , d2 ) ;
			cObj.setByKey( _this.passwordCookieKey , _this.password , d ) ;
		}
	}
	function _rememberUserLongTime()
	{
		var d = _super.getOtherHandler().DateAdd( "yyyy" , 3 , ( new Date() ) )
		if( _this.rememberFlag && !_this.guestFlag && _this.username != null && _this.password != null )
		{
			cObj.setByKey( _this.usrenameCookieKey , _this.username , d ) ;
			cObj.setByKey( _this.passwordCookieKey , _this.password , d ) ;
			cObj.setByKey( _this.rememberCookieKey , "true" , d ) ;
		}
	}
	function _getAutoLoginFlag()
	{
		return ( cObj.getByKey( _this.rememberCookieKey ) != null ) ;
	}
	function _autoLogin()
	{
		var sUserName = cObj.getByKey( _this.usrenameCookieKey ) ;
		var sPassWord = cObj.getByKey( _this.passwordCookieKey ) ;
		var sRemember = cObj.getByKey( _this.rememberCookieKey ) ;
		if( sUserName != null && sPassWord != null  )
		{
			if( typeof doSendLoginInfo == "function" )
			{
				doSendLoginInfo( sUserName , sPassWord , "0" , sRemember , "" ) ;
			}

		}
	}
	function endCheckUserPage()
	{
		if( checkCookieTimerId > 0 )
		{
			clearInterval( checkCookieTimerId ) ;
			checkCookieTimerId = -1 ;
		}
		if( checkCookieFlag )
		{
			cObj.setByKey( _this.checkCookieKey , "true" , ( new Date() ) )
		}
	}
	
	function _getCookieUserName()
	{
		return cObj.getByKey( _this.usrenameCookieKey ) ;
	}
	
	function _getUserNickName( u )
	{
		var pix = "" ;
		var name = "" ;
		if( typeof u.getAttribute != "undefined" )
		{
			pix = u.getAttribute( "nickNamePix" ) ;
			name = u.getAttribute( "userNickName" ) ;
		}
		else
		{
			pix = _super.getOtherHandler().getVar( u.nickNamePix , "" ) ;
			name = u.userNickName ;
		}
		if( pix != ""  )
		{
			pix = "<span style='color:#00CC00'>★" + pix + "★</span>" ;	
		}
		return pix + name ;
	}
}
