var gamehall_Logic = gamehall_Logic||{};
gamehall_Logic.gameinfo = "tsgame_gameinfo";
gamehall_Logic.launchGameId = "tsgame_launchgameid";
gamehall_Logic.agentConfig = "tsgame_agentConfig";
gamehall_Logic.isLocation = "tsgame_isLocation";
gamehall_Logic.initImgRes = function(){
	for(var i=0;i<gamehall_Const.GameList.sFrameImgRes.length;i++){
		set_self(76,1,gamehall_Const.GameList.sFrameImgRes[i],0,0);
	}
	for(var i=0;i<gamehall_Const.GameList.mFrameImgRes.length;i++){
		set_self(76,1,gamehall_Const.GameList.mFrameImgRes[i],0,0);
	}
}
gamehall_Logic.gameStart=function(){
	for(var i=0;i<gamehall_Const.unClickBtn.length;i++){
		set_self(gamehall_Const.unClickBtn[i],41,0,0,0);
	}
	var gameConfig = get_paravalue(GameData.serverConfig,"gameHallConfig");
	if(gameConfig){
		for(var key in gameConfig){
			gamehall_Data.gameHallConfig[key] = gameConfig[key];
		}
	}
	if(Utl.checkKey(gamehall_Logic.launchGameId)){
		gamehall_Data.gameidHistory =  Utl.ReadData(gamehall_Logic.launchGameId);
	}else{
		Utl.SaveData(gamehall_Logic.launchGameId,"");
		gamehall_Data.gameidHistory = "";
	}
	if(Utl.checkKey(gamehall_Logic.isLocation)){
		gamehall_Data.isLocation =  Number(Utl.ReadData(gamehall_Logic.isLocation));
	}else{
		Utl.SaveData(gamehall_Logic.isLocation,0);
		gamehall_Data.isLocation = 0;
	}
	var ac =  Utl.ReadData(gamehall_Logic.agentConfig);
		
		
	if(ac){
		ac = JSON.parse(ac);
		if(gamehall_Logic.isExitAgentCode(ac.agentCode)){
			gamehall_Data.agentConfig = ac;
		}else{
			if(gamehall_Data.gameHallConfig.agentConfig){
				Utl.SaveData(gamehall_Logic.agentConfig,JSON.stringify(gamehall_Data.gameHallConfig.agentConfig));
				gamehall_Data.agentConfig = gamehall_Data.gameHallConfig.agentConfig;
			}else{
				Utl.SaveData(gamehall_Logic.agentConfig,"");
				gamehall_Data.agentConfig = null;
			}
		}
				
		
	}else{
		if(gamehall_Data.gameHallConfig.agentConfig){
			Utl.SaveData(gamehall_Logic.agentConfig,JSON.stringify(gamehall_Data.gameHallConfig.agentConfig));
			gamehall_Data.agentConfig = gamehall_Data.gameHallConfig.agentConfig;
		}else{
			Utl.SaveData(gamehall_Logic.agentConfig,"");
			gamehall_Data.agentConfig = null;
		}
		
	}
	//gamehall_Logic.gameinfo += GameData.AgentId;
	gamehall_Const.GameList.clip_y = get_self(gamehall_Const.GameList.f_spid,19,0,0,0);
	//gamehall_Const.GameList.clip_h = get_self(gamehall_Const.GameList.bg_spid,21,0,0,0);
	//gamehall_Const.GameList.w = get_self(gamehall_Const.GameList.bg_spid,20,0,0,0);
	//gamehall_Const.GameList.h = get_self(gamehall_Const.GameList.bg_spid,21,0,0,0);
}
gamehall_Logic.saveGameinfo = function(data){
	Utl.SaveData(gamehall_Logic.gameinfo,data);
}
gamehall_Logic.clearGameinfo = function(){
	Utl.SaveData(gamehall_Logic.gameinfo,"");
}
gamehall_Logic.readGameinfo = function(){
	var rValue = Utl.ReadData(gamehall_Logic.gameinfo);
	if(rValue){
		for(var i=0;i<gamehall_Data.GameList.length;i++){
			if(gamehall_Data.GameList[i].gamedir == JSON.parse(rValue).gamedir){
				return rValue;
			}
		}
	}
	return null;
}	
gamehall_Logic.setGameList = function(){
	var _imgResList = get_paravalue(GameData.serverConfig,"imgResList");
	if(_imgResList){
		gamehall_Data.gameHallImgList = _imgResList;
	}else{
		gamehall_Data.gameHallImgList = [];
	}	
	for(var i=0;i<gamehall_Data.gameHallImgList.length;i++){
		//Func.up_imgurl(gamehall_Const.GameList.frame_begin_res+i,gamehall_Data.gameHallImgList[i]);
		//Func.up_imgurl(gamehall_Const.GameList.frame_begin_res+i,"http://192.168.1.6:58888/Projects/gamehall2/gamehall_yl0-8.png");
		up_imgurl(gamehall_Const.GameList.mFrameImgRes[i],gamehall_Data.gameHallImgList[i]);
	}	
	var _gameList = get_gamelist_gamehall(GameData.serverConfig, GameData.AgentId, GameData.ChannelId, GameData.marketID);
	//_gameList.length = 6;
	gamehall_Data.GameList = _gameList;
	gamehall_Data.gameImgList.length = gamehall_Data.GameList.length;
	var gameimageRes = 0;
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		//gamehall_Data.GameList[i].gameid = "";

		gamehall_Data.GameList[i].isDownload = 0;
		//gamehall_Data.GameList[i].imgres = gamehall_Const.GameList.begin_res+i;
		//gamehall_Data.GameList[i].frame_res = gamehall_Const.GameList.frame_begin_res+i;
		
		gamehall_Data.gameImgList[i] = 0;
		if(gamehall_Data.GameList[i].gameimage && !gamehall_Logic.isArray(gamehall_Data.GameList[i].res_frame)){
			//gamehall_Data.GameList[i].imgres = gamehall_Const.GameList.begin_res+gameimageRes;
			gamehall_Data.GameList[i].imgres = gamehall_Const.GameList.sFrameImgRes[gameimageRes];
			up_imgurl(gamehall_Data.GameList[i].imgres,gamehall_Data.GameList[i].gameimage);
			gameimageRes++;
		}
		//if(i == 0 && gamehall_Data.GameList[i].downloadimg){
			//up_imgurl(116,gamehall_Data.GameList[i].downloadimg);
		//}
		//if(i == 1 && gamehall_Data.GameList[i].downloadimg){
			//up_imgurl(117,gamehall_Data.GameList[i].downloadimg);
		//}
			
	}
	
}
function gamehall_logincallback(_msg,state,input_msg){
	if(typeof _msg == "string"){
		_msg = JSON.parse(_msg);
	}
		
	switch(_msg.rpc){
		case RpcList.player_login:
			/*
			GameData.AgentId=_msg.data.agentid;
			GameData.ChannelId=_msg.data.channelid;
			gamehall_Logic.setGameList(_msg.data.gamelist);
			if(_msg.data.scrollmsg){
				GameData.scrollmsg=_msg.data.scrollmsg;
			}else{
				GameData.scrollmsg="";
			}	
			if(_msg.data.noticemsg){
				GameData.Notice.lineSum = Math.ceil(Func.getKeywordCount(_msg.data.noticemsg,ConstVal.Notice.replaceOldWord)/2);
				GameData.Notice.heigth = GameData.Notice.lineSum*ConstVal.Notice.lineHeight+ConstVal.Notice.textHeight;
				var strArray = _msg.data.noticemsg.split(ConstVal.Notice.replaceOldWord);
				var max_length=0;
				for(var k=0;k<strArray.length;k++){
					var lenTemp=strArray[k].gblen();
					if(lenTemp>max_length){
						max_length = lenTemp;
					}
				}
				GameData.Notice.width = max_length*ConstVal.Notice.textWidth;
				Game_Config.Setting.board = min_replaceAll(_msg.data.noticemsg,ConstVal.Notice.replaceOldWord,ConstVal.Notice.replaceNewWord,false);
				//Game_Config.Setting.board = _msg.data.noticemsg;
			}else{
				Game_Config.Setting.board = "";
				GameData.isBoard=false;
			}
			if(_msg.data.hall_config){
				GameData.hallConfig = _msg.data.hall_config;
			}else{
				//GameData.hallConfig = {};
			}
			if(_msg.data.game_config){
				GameData.gameConfig = _msg.data.game_config;
				Game_Modify.onGameConfig(GameData.gameConfig);
			}else{
				GameData.gameConfig = Game_Modify.game_config;
			}
			*/
			gamehall_Logic.setGameList();
			Func.up_imgurl(502,gamehall_Data.gameHallConfig.topImgUrl);
			GameUI.JumpMenuScene();
			
			if(Logic.JudgeShow()){
				GameUI.OpenBoard(Game_Config.Setting.board);
			}
			break;
		case RpcList.kick_server:
			GameUI.EndLoad();
			Net[RpcList.kick_server](_msg);
			break;
	}
	
}
//获取游戏列表_游戏大厅
/*
function get_gamelist_gamehall(o_config, agentid, channelid, marketid){
	var gamelist = [];
	if (!o_config.data){
		return gamelist;
	}
	if (!o_config.data.agentlist){
		return gamelist;
	}
	for (var i = 0; i < o_config.data.agentlist.length; i++){
		if (o_config.data.agentlist[i].agentid == agentid){
			var _o_agent = o_config.data.agentlist[i];
			if (_o_agent.gamelist){
				for (var j = 0; j < _o_agent.gamelist.length; j++){
					var _o_game = _o_agent.gamelist[j];
					if (_o_game.gameid != "G2hw0ubng0zcoI0r4mx3H2yr4GejidwO"){
						var o_game = {};
						o_game.gameid      = _o_game.gameid;
						o_game.gamename    = _o_game.gamename;
						o_game.gamedir     = _o_game.game_hall_dir;
						o_game.gameimage   = _o_game.game_hall_image;
						o_game.gameversion = _o_game.game_version;
						o_game.gamezip     = _o_game.game_zip;
						o_game.zipsize     = _o_game.game_size;
						o_game.res_frame   = _o_game.game_hall_frame;
						o_game.downloadimg = _o_game.game_downloadimg;
						
						if(_o_game.webtype){
							o_game.webtype = _o_game.webtype;	
						}else{
							o_game.webtype = 0;
						}
						
						
						o_game.game_server_http = _o_game.game_server_http;
						o_game.othergametype = _o_game.othergametype;
						o_game.othergameurlurl = _o_game.othergameurlurl;
						if(_o_game.inAgent){
							o_game.inAgent = _o_game.inAgent;	
						}else{
							o_game.inAgent = [];
						}
						
						if(_o_game.category){
							o_game.category = _o_game.category;
						}else{
							o_game.category = 0;
						}
						if (_o_game.channellist){
							for (var k = 0; k < _o_game.channellist.length; k++) {
								var _o_channel = _o_game.channellist[k];
								if (_o_channel.channelid == channelid){
									if (_o_channel.game_version > 0){
										o_game.gameversion = _o_channel.game_version;
									}
									if (_o_channel.game_zip){
										o_game.gamezip = _o_channel.game_zip;
									}
									if (_o_channel.game_size){
										o_game.zipsize = _o_channel.game_size;
									}
									if (_o_channel.game_hall_frame){
										o_game.res_frame = _o_channel.game_hall_frame;
									}
									if (_o_channel.webtype){
										o_game.webtype = _o_channel.webtype;
									}
									if (_o_channel.game_server_http){
										o_game.game_server_http = _o_channel.game_server_http;
									}
									if (_o_channel.othergametype){
										o_game.othergametype = _o_channel.othergametype;
									}
									if (_o_channel.othergameurlurl){
										o_game.othergameurlurl = _o_channel.othergameurlurl;
									}
									if (_o_channel.category){
										o_game.category = _o_channel.category;
									}
									if (_o_channel.inAgent){
										o_game.inAgent = _o_channel.inAgent;
									}
									if (_o_channel.marketlist){
										for (var m = 0; m < _o_channel.marketlist.length; m++) {
											var _o_market = _o_channel.marketlist[m];
											if (_o_market.marketid == marketid){
												if (_o_market.game_version > 0){
													o_game.gameversion = _o_market.game_version;
												}
												if (_o_market.game_zip){
													o_game.gamezip = _o_market.game_zip;
												}
												if (_o_market.game_size){
													o_game.zipsize = _o_market.game_size;
												}
												if (_o_market.game_hall_frame){
													o_game.res_frame = _o_channel.game_hall_frame;
												}
												if (_o_market.webtype){
													o_game.webtype = _o_channel.webtype;
												}
												if (_o_market.game_server_http){
													o_game.game_server_http = _o_channel.game_server_http;
												}
												if (_o_market.othergametype){
													o_game.othergametype = _o_channel.othergametype;
												}
												if (_o_market.othergameurlurl){
													o_game.othergameurlurl = _o_channel.othergameurlurl;
												}
												if (_o_market.category){
													o_game.category = _o_channel.category;
												}
												if (_o_market.inAgent){
													o_game.inAgent = _o_channel.inAgent;
												}
												break;
											}
										}
									}
									gamelist.push(o_game);
									break;
								}
							}
						}
					}
				}
			}
			break;
		}
	}
	return gamelist;
}*/
function get_gamelist_gamehall(o_config, agentid, channelid, marketid){
	var gamelist = [];
	if (!o_config.data){
		return gamelist;
	}
	if (!o_config.data.agentlist){
		return gamelist;
	}
	for (var i = 0; i < o_config.data.agentlist.length; i++){
		if (o_config.data.agentlist[i].agentid == agentid){
			var _o_agent = o_config.data.agentlist[i];
			if (_o_agent.gamelist){
				for (var j = 0; j < _o_agent.gamelist.length; j++){
					var _o_game = _o_agent.gamelist[j];
					if (_o_game.gameid != "G2hw0ubng0zcoI0r4mx3H2yr4GejidwO"){
						var o_game = {};
						o_game.gameid      = _o_game.gameid;
						o_game.gamename    = _o_game.gamename;
						o_game.gamedir     = _o_game.game_hall_dir;
						o_game.gameimage   = _o_game.game_hall_image;
						o_game.gameversion = _o_game.game_version;
						o_game.gamezip     = _o_game.game_zip;
						o_game.zipsize     = _o_game.game_size;
						o_game.res_frame   = _o_game.game_hall_frame;
						o_game.downloadimg = _o_game.game_downloadimg;

						if(_o_game.webtype){
							o_game.webtype = _o_game.webtype;
						}else{
							o_game.webtype = 0;
						}


						o_game.game_server_http = _o_game.game_server_http;
						o_game.othergametype = _o_game.othergametype;
						o_game.othergameurlurl = _o_game.othergameurlurl;
						if(_o_game.inAgent){
							o_game.inAgent = _o_game.inAgent;
						}else{
							o_game.inAgent = [];
						}

						if(_o_game.category){
							o_game.category = _o_game.category;
						}else{
							o_game.category = 0;
						}
						if (_o_game.channellist){
							for (var k = 0; k < _o_game.channellist.length; k++) {
								var _o_channel = _o_game.channellist[k];
								if (_o_channel.channelid == channelid){
									if (_o_channel.game_version > 0){
										o_game.gameversion = _o_channel.game_version;
									}
									if (_o_channel.game_zip){
										o_game.gamezip = _o_channel.game_zip;
									}
									if (_o_channel.game_size){
										o_game.zipsize = _o_channel.game_size;
									}
									if (_o_channel.game_hall_frame){
										o_game.res_frame = _o_channel.game_hall_frame;
									}
									if (_o_channel.webtype){
										o_game.webtype = _o_channel.webtype;
									}
									if (_o_channel.game_server_http){
										o_game.game_server_http = _o_channel.game_server_http;
									}
									if (_o_channel.othergametype){
										o_game.othergametype = _o_channel.othergametype;
									}
									if (_o_channel.othergameurlurl){
										o_game.othergameurlurl = _o_channel.othergameurlurl;
									}
									if (_o_channel.category){
										o_game.category = _o_channel.category;
									}
									if (_o_channel.inAgent){
										o_game.inAgent = _o_channel.inAgent;
									}
									var isFound = false;
									if (_o_channel.marketlist){
										
										for (var m = 0; m < _o_channel.marketlist.length; m++) {
											var _o_market = _o_channel.marketlist[m];
											if (_o_market.marketid == marketid){
												isFound = true;
												if (_o_market.game_version > 0){
													o_game.gameversion = _o_market.game_version;
												}
												if (_o_market.game_zip){
													o_game.gamezip = _o_market.game_zip;
												}
												if (_o_market.game_size){
													o_game.zipsize = _o_market.game_size;
												}
												if (_o_market.game_hall_frame){
													o_game.res_frame = _o_channel.game_hall_frame;
												}
												if (_o_market.webtype){
													o_game.webtype = _o_channel.webtype;
												}
												if (_o_market.game_server_http){
													o_game.game_server_http = _o_channel.game_server_http;
												}
												if (_o_market.othergametype){
													o_game.othergametype = _o_channel.othergametype;
												}
												if (_o_market.othergameurlurl){
													o_game.othergameurlurl = _o_channel.othergameurlurl;
												}
												if (_o_market.category){
													o_game.category = _o_channel.category;
												}
												if (_o_market.inAgent){
													o_game.inAgent = _o_channel.inAgent;
												}
												break;
											}
										}
									}
									if(isFound){
										gamelist.push(o_game);
									}
									break;
								}
							}
						}
					}
				}
			}
			break;
		}
	}
	return gamelist;
}
gamehall_Logic.setInstallState = function(_gamename){
	if(app_gamesname.indexOf(_gamename) < 0){
		app_gamesname.push(_gamename);
	}
}
gamehall_Logic.isInstalled = function(_gamename){
	if(app_gamesname.indexOf(_gamename) > -1){
		return 1;
	}else{
		return 0;
	}
}
//function get_paravalue(o_config, paraname, agentid, gameid, channelid, marketid){
function get_paravalue(o_config, paraname){
	var agentid = GameData.AgentId;
	var gameid = GameData.GameId;
	var channelid = GameData.ChannelId;
	var marketid = GameData.marketID;
	var paravalue = null;
	//
	var do_get_para = function(arylist, keyname, keyvalue){
		if (arylist && keyname && keyvalue){
			for (var i = 0; i < arylist.length; i++){
				if (arylist[i][keyname] == keyvalue){
					if (arylist[i][paraname]){
						paravalue = arylist[i][paraname];
					}
					return arylist[i];
				}
			}		
		}
		return null;
	}

	if (!o_config.data){
		return paravalue;
	}
	if (o_config.data[paraname]){
		paravalue = o_config.data[paraname];
	}
	var _o_agent = do_get_para(o_config.data.agentlist, "agentid", agentid);
	if (!_o_agent){
		return paravalue;
	}
	var _o_game = do_get_para(_o_agent.gamelist, "gameid", gameid);
	if (!_o_game){
		return paravalue;
	}
	var _o_channel = do_get_para(_o_game.channellist, "channelid", channelid);
	if (!_o_channel){
		return paravalue;
	}
	var _o_market = do_get_para(_o_channel.marketlist, "marketid", marketid);						
	if (!_o_market){
		return paravalue;
	}

	return paravalue;		
}
gamehall_Logic.isArray = function isArray(o){
	return Object.prototype.toString.call(o)=='[object Array]';
}
gamehall_Logic.httpLogin = function(_msg){
	if(typeof _msg == "string"){
		_msg = JSON.parse(_msg);
	}
	gamehall_Data.isLogin = true;
	C_Player.SetMyInfo(_msg.data);
	gamehall_Logic.jumpOtherGame(gamehall_Data.gameInfo);
}
gamehall_Logic.jumpOtherGame = function(gameInfo){
	var _urlData = "channelId="+GameData.ChannelId+"&agentId="+GameData.AgentId+"&avatar="+min_encode(C_Player.avatar)+"&nickname="+min_encode(C_Player.nickname)+
			"&playerId="+C_Player.playerid+"&gameId="+gameInfo.gameid+"&openId="+C_Player.openid+"&unionId="+C_Player.unionid
			+"&sex="+C_Player.sex;
	Func.OpenurlTitleData(gameInfo.othergameurlurl+"?"+_urlData,"","");
}

var gameHallImport = {};
gameHallImport.appStart =function(){
	gamehall_Logic.initImgRes();
	gamehall_Const.Location.clip_x = get_self(gamehall_Const.Location.f_spid,18,0,0,0);
	gamehall_Const.Location.clip_y = get_self(gamehall_Const.Location.f_spid,19,0,0,0);
	gamehall_Const.Location.clip_w = get_self(gamehall_Const.Location.f_spid,20,0,0,0);
	gamehall_Const.Location.clip_h = get_self(gamehall_Const.Location.f_spid,21,0,0,0);

}
gameHallImport.jumpMenuScene =function(){
	if(Utl.getPlayerAdvanced()){
		set_self(1037,37,1,0,0);
	}else{
		set_self(1037,37,0,0,0);
	}
	set_self(145,37,0,0);
	gamehall_GameUI.updateHall();
	gamehall_GameUI.showGameHall();
	console.log(gamehall_Data.GameList);
	if(gamehall_Data.gameHallConfig.autoGame && !gamehall_Data.isAutoGame){
		gamehall_Data.isAutoGame = true;
		var gameinfo = gamehall_Logic.readGameinfo();
		if(!gameinfo){
			for(var i=0;i<gamehall_Data.GameList.length;i++){
				if(gamehall_Data.GameList[i].gameid == gamehall_Data.gameHallConfig.autoGame){
					var data={};
					var webtype = 3;
					if(gamehall_Data.GameList[i].webtype){
						webtype = gamehall_Data.GameList[i].webtype;
					}
					data.webtype = webtype;
					data.gamedir = gamehall_Data.GameList[i].gamedir;
					data.gameid = gamehall_Data.GameList[i].gameid;
					gamehall_Logic.saveGameinfo(JSON.stringify(data));
					break;
				}
			}
		}
	}
	if(gamehall_Data.isSwitch){
		var gameinfo = gamehall_Logic.readGameinfo();
		if(gameinfo){
			gameinfo = JSON.parse(gameinfo);
			var webtype = 3;
			if(gameinfo.webtype){
				webtype = gameinfo.webtype;
			}
			var data={};
			data.from=2;
			data.opt = "loginPlayerid";
			data.data = Utl.ReadData(gamehall_Logic.launchGameId);
			Func.SwitchOverGameData(webtype,gameinfo.gamedir,gameinfo.gameid,data);
			return;
		}
		gamehall_Data.isSwitch = false;
	}
}
gameHallImport.gameStart = function(){
	gamehall_Logic.gameStart();
}
gameHallImport.setGameList =function(){
	if(gamehall_Data.agentConfig){
		gamehall_Logic.setGameListByRgn(gamehall_Data.agentConfig.agentCode);
	}else{
		gamehall_Logic.setGameListByRgn();	
	}
	
	//gamehall_Logic.setGameList();
}
gameHallImport.clearGameinfo = function(){
	gamehall_Logic.clearGameinfo();
}
gameHallImport.getWebdata = function(data){
	//logmessage("getWebdata"+data,1);
	gamehall_GameUI.clearCategory();
	gamehall_Logic.saveGameinfo("");
	if(data){		
		if (typeof(data) == 'string'){
	        data = JSON.parse(data);
	    }
	    //logmessage("3:"+JSON.stringify(data),1);
		if(typeof data.from != "undefined"){
			//logmessage("3:"+data.from,1);
			switch(data.from){
				case 2://子游戏跳回大厅 
					switch(data.opt){
						case "updatePlayerInfo":
							//logmessage("updatePlayerInfo:",1);
							C_Player.updateHallData(data.data);
							gamehall_Logic.setInstallState(data.gamename);
							break;
						case "loginPlayerid":
							GameData.loginPlayerid = (data.data == GameData.GameId);
							break;
						case "saveGameId":
							gamehall_Logic.setInstallState(data.gamename);
							break;
					}
					
					break;
				default:
					/*
					var data={};
					data.agentid = GameData.AgentId;
					data.openid = C_Player.openid;
					data.gameid = GameData.GameId;
					data.nickname = C_Player.nickname;
					data.avatar = C_Player.avatar;
					data.sex = C_Player.sex;
					data.province = C_Player.province;
					data.unionid=C_Player.unionid;
					data.city = C_Player.city;
					data.version = GameData.versionCode;
					data.channelid = GameData.ChannelId;
					data.marketid = GameData.marketID;
					Net.Send_login(data);
				
					Utl.stopMusic();
					Utl.playMusic();
					gamehall_GameUI.updateHall();
					gamehall_GameUI.showGameHall();*/
					break;
			}
		}else{
			//gUtl.stopMusic();
			//Utl.playMusic();
			//gamehall_GameUI.updateHall();
			//gamehall_GameUI.showGameHall();
		}
	}else{
		//var data={};
		//data.agentid = GameData.AgentId;
		//data.openid = C_Player.openid;
		//data.gameid = GameData.GameId;
		//data.nickname = C_Player.nickname;
		//data.avatar = C_Player.avatar;
		//data.sex = C_Player.sex;
		//data.province = C_Player.province;
		//data.unionid=C_Player.unionid;
		//data.city = C_Player.city;
		//data.version = GameData.versionCode;
		//data.channelid = GameData.ChannelId;
		//data.marketid = GameData.marketID;
		//Net.Send_login(data);
	}
	Utl.playMusic();
	GameUI.JumpMenuScene();
	//gamehall_GameUI.updateHall();
	//gamehall_GameUI.showGameHall();
	//gamehall_GameUI.updateHall();
	//gamehall_GameUI.showGameHall();
}

gameHallImport.isInstalled = function(data){
	console.log("isInstalled");
	return gamehall_Logic.isInstalled(data);
}
gameHallImport.up_imgurl = function(recid,photo){
	console.log("up_imgurl");
		if(recid==25){
			up_imgurl(recid,"assets/bmp/00170.png",1);
			setTimeout(
			function(){
				if(photo){
					up_imgurl(recid,photo,1);
					GameData.playerHeadImgState = true;
				}else{
					up_imgurl(recid,"assets/bmp/00170.png",1);
				}
			},ConstVal.Max.headImgTimer);
		}else if(recid==115 || recid==5){
			up_imgurl(recid,photo,1);
		//}else if(recid>=gamehall_Const.GameList.beginID&&recid<=gamehall_Const.GameList.endID){
		}else if(gamehall_Const.exceptRes.indexOf(Number(recid)) >= 0){
				up_imgurl(recid,photo,1);
		}else{
			up_imgurl(recid,"assets/bmp/00170.png",1);
			setTimeout(
			function(){
				if(photo){
					up_imgurl(recid,photo,1);
				}else{
					up_imgurl(recid,"assets/bmp/00170.png",1);
				}
			}
			,ConstVal.Max.headImgTimer);
		}


}
gameHallImport.getphoto = function(recid,photo){
	console.log("getphoto");
	var obj =strToJson(photo);
	for(var i=0;i<obj.length;i++){
		var pho=obj[i];
		if(pho.photourl){
			if(Number(pho.pid)==25){
				if(pho.photourl){
						up_imgurl(Number(pho.pid),pho.photourl,1);
						GameData.playerHeadImgState = true;
					}else{
						up_imgurl(Number(pho.pid),"assets/bmp/00170.png",1);
					}
			}else if(Number(pho.pid)==115 || Number(pho.pid)==5){
				up_imgurl(Number(pho.pid),pho.photourl,1);
			}else if(gamehall_Const.exceptRes.indexOf(Number(pho.pid)) >= 0){
				up_imgurl(Number(pho.pid),pho.photourl,1);
			}else{
				//up_imgurl(Number(pho.pid),"assets/bmp/00170.png",1);
				setTimeout(
					function(){
						if(pho.photourl){
							up_imgurl(Number(pho.pid),pho.photourl,1);
						}else{
							up_imgurl(Number(pho.pid),"assets/bmp/00170.png",1);
						}
					}
				,ConstVal.Max.headImgTimer);
			}
		}
	}
}
gamehall_Logic.alyArea = function(pos){//[经度,纬度]
	if(!pos){return null;};
	/*
	var config = GameData.sysConfig.agentConfig;
	
	if(config){
		for(var i = 0;i < config.length;i++){
			var rgn = config[i].region;
			if(rgn){
				if(pos[0] >= rgn[0][0] && pos[0] <= rgn[1][0] && 
				pos[1] <= rgn[0][1] && pos[1] >= rgn[1][1]){
					return config[i];
				}
			}
		}
		return config[0];
	}else{
		return null;
	}
	*/
	var rValue = gamehall_Logic.travelAgentConfig(gamehall_Data.gameHallConfig.agentConfig,"region",pos);
	return rValue;
}
gamehall_Logic.saveAgentConfig = function(val){
	if(val){
		gamehall_Data.agentConfig = val;
		var valTemp = min_copyjson(val);
		if(valTemp.list){
			delete valTemp.list;
		}
		var val1 = JSON.stringify(valTemp);
		Utl.SaveData(gamehall_Logic.agentConfig,val1);
	}else{
		Utl.SaveData(gamehall_Logic.agentConfig,"");	
	}
}
//遍历配置找到键值对应值的配置 
gamehall_Logic.travelAgentConfig = function(config,key,val){
	if(!config){return null;}
	var rValue = null;
	if(key == "region"){//范围特殊处理
		var rgn = config[key]; 
		//第一层
		if(val[0] >= rgn[0][0] && val[0] <= rgn[1][0] &&
				val[1] <= rgn[0][1] && val[1] >= rgn[1][1]){
			rValue = config;
		}
		//else{
			//第二层
			if(config.list){
				for(var i=0;i<config.list.length;i++){
					rgn = config.list[i][key];
					if(val[0] >= rgn[0][0] && val[0] <= rgn[1][0] &&
						val[1] <= rgn[0][1] && val[1] >= rgn[1][1]){
						rValue = config.list[i];
					}
					//else{
						//第三层
						if(config.list[i].list){
							for(var j=0;j<config.list[i].list.length;j++){
								rgn = config.list[i].list[j][key];
								if(val[0] >= rgn[0][0] && val[0] <= rgn[1][0] &&
									val[1] <= rgn[0][1] && val[1] >= rgn[1][1]){
									rValue = config.list[i].list[j];
								}
								//else{
									//第四层
									if(config.list[i].list[j].list){
										for(var k=0;k<config.list[i].list[j].list.length;k++){
											rgn = config.list[i].list[j].list[k][key];
											if(val[0] >= rgn[0][0] && val[0] <= rgn[1][0] &&
												val[1] <= rgn[0][1] && val[1] >= rgn[1][1]){
												rValue = config.list[i].list[j].list[k];
											}
										}
									}
							//	}
							}
						}
					//}
				}
			}
	//	}
	return rValue;
	}else{
		//第一层 
		if(config[key] == val){
			return config;
		}else{
			//第二层 
			if(config.list){
				for(var i=0;i<config.list.length;i++){
					if(config.list[i][key] == val){
						return config.list[i];
					}else{
						//第三层 
						if(config.list[i].list){
							for(var j=0;j<config.list[i].list.length;j++){
								if(config.list[i].list[j][key] == val){
									return config.list[i].list[j];
								}else{
									//第四层 
									if(config.list[i].list[j].list){
										for(var k=0;k<config.list[i].list[j].list.length;k++){
											if(config.list[i].list[j].list[k][key] == val){
												return config.list[i].list[j].list[k];
											}else{
												
											}
										}
									}
								}
							}
						}	
					}
				}	
			}
		}
	}
	return null;
}
gamehall_Logic.isExitAgentCode = function(agentCode){
	/*
	if(gamehall_Data.gameHallConfig.agentConfig){
		for(var i=0;i<gamehall_Data.gameHallConfig.agentConfig.length;i++){
			if(gamehall_Data.gameHallConfig.agentConfig[i].agentCode == agentCode){
				return gamehall_Data.gameHallConfig.agentConfig[i];
			}
		}
		return gamehall_Data.gameHallConfig.agentConfig[0];
	}else{
		return null;
	}*/
	var rValue = gamehall_Logic.travelAgentConfig(gamehall_Data.gameHallConfig.agentConfig,"agentCode",agentCode);
	return rValue;
}
//根据代理区域设置游戏列表
gamehall_Logic.setGameListByRgn = function(agentCode){
	var _imgResList = get_paravalue(GameData.serverConfig,"imgResList");
	if(_imgResList){
		gamehall_Data.gameHallImgList = _imgResList;
	}else{
		gamehall_Data.gameHallImgList = [];
	}
	for(var i=0;i<gamehall_Data.gameHallImgList.length;i++){
		up_imgurl(gamehall_Const.GameList.mFrameImgRes[i],gamehall_Data.gameHallImgList[i]);
	}
	var _gameList = get_gamelist_gamehall(GameData.serverConfig, GameData.AgentId, GameData.ChannelId, GameData.marketID);
	var gList = [];
	var configTemp = gamehall_Logic.isExitAgentCode(agentCode);
	//已下载的需要添加到列表里
	if(configTemp){
		for(var i=0;i<_gameList.length;i++){
			if(!_gameList[i].othergameurlurl){
				if(_gameList[i].gameid){
					var dState = Func.getInstallInfo(_gameList[i].gamedir);
					//var dState = 0;
					if(dState){
						//不在所在地区代理游戏列表中 
						if(_gameList[i].inAgent.indexOf(agentCode) < 0){
							gList.push(_gameList[i]);
						}
							
					}
				}
			}
		}
	}
	if(configTemp){
		gamehall_Logic.saveAgentConfig(configTemp);
		for(var i=0;i<_gameList.length;i++){
			var aList = _gameList[i].inAgent;
			if(aList.indexOf(agentCode) > -1){
				gList.push(_gameList[i]);
			}
		}
		
	}else{
		gList = _gameList;
	}
	
	gamehall_Data.GameList = gList;
	gamehall_Data.gameImgList.length = gamehall_Data.GameList.length;
	var gameimageRes = 0;
	for(var i=0;i<gamehall_Data.GameList.length;i++){

		gamehall_Data.GameList[i].isDownload = 0;

		gamehall_Data.gameImgList[i] = 0;
		if(gamehall_Data.GameList[i].gameimage && !gamehall_Logic.isArray(gamehall_Data.GameList[i].res_frame)){
			gamehall_Data.GameList[i].imgres = gamehall_Const.GameList.sFrameImgRes[gameimageRes];
			up_imgurl(gamehall_Data.GameList[i].imgres,gamehall_Data.GameList[i].gameimage);
			gameimageRes++;
		}

	}

}













