var storage = window.localStorage;
var Utl = Utl||{};

Utl.Config={};


Utl.Config.pre_bgm = "tsgame_bgm_";
Utl.Config.bgm = "";
Utl.Config.pre_sound = "tsgame_sound_";
Utl.Config.sound = "";

Utl.Config.pre_wxinfo = "tsgame_wxinfo_";
Utl.Config.wxinfo = "tsgame_wxinfo";
Utl.Config.maxtime = 48;//小时
Utl.Config.pre_validtime = "tsgame_validtime_";//有效时间（时间戳）
Utl.Config.validtime = "tsgame_validtime";//有效时间（时间戳）

Utl.Config.pre_visitorinfo = "tsgame_visitorinfo_";
Utl.Config.visitorinfo = "tsgame_visitorinfo";

Utl.Config.pre_roomtype = "tsgame_roomtype_";
Utl.Config.roomtype = "";

Utl.Config.pre_multiple = "tsgame_multiple_";
Utl.Config.multiple = "";

Utl.Config.pre_shake = "tsgame_shake_";
Utl.Config.shake = "";

Utl.Config.pre_voice = "tsgame_voice_";
Utl.Config.voice = "";

Utl.Config.pre_roomlist = "tsgame_roomlist_";
Utl.Config.roomlist = "";

Utl.Config.pre_playerid = "tsgame_playerid_";
Utl.Config.playerid = "";

Utl.Config.pre_gradeinfo = "tsgame_gradeinfo_";
Utl.Config.gradeinfo = "";

Utl.Config.pre_shortcode = "tsgame_shortcode_";
Utl.Config.shortcode = "";

Utl.Config.pre_ownerNote = "tsgame_ownerNote_";
Utl.Config.ownerNote = "";

Utl.Config.pre_machineId = "tsgame_machineId_";
Utl.Config.machineId = "";

Utl.Config.pre_tea = "tsgame_tea_";
Utl.Config.tea = "";

Utl.Config.pre_book = "tsgame_book_";
Utl.Config.book = "";

Utl.Config.pre_phoneInfo = "tsgame_phoneInfo_";
Utl.Config.phoneInfo = "";

Utl.Config.pre_ownerNoteTime = "tsgame_ownerNoteTime_";
Utl.Config.ownerNoteTime = "";

Utl.Config.pre_gameNoteTime = "tsgame_gameNoteTime_";
Utl.Config.gameNoteTime = "";

Utl.Config.pre_hallNoteTime = "tsgame_hallNoteTime_";
Utl.Config.hallNoteTime = "";

Utl.Config.pre_autoEnterOfc = "tsgame_autoEnterOfc_";
Utl.Config.autoEnterOfc = "";

Utl.Config.pre_vipRoom = "tsgame_vipRoom_";
Utl.Config.vipRoom = "";

Utl.Config.pre_vipCharm = "tsgame_vipCharm_";
Utl.Config.vipCharm = "";

Utl.Config.pre_rebateLimit = "tsgame_rebateLimit_";
Utl.Config.rebateLimit = "";

Utl.Config.pre_phoneCode = "tsgame_phoneCode_";
Utl.Config.phoneCode = "sgame_phoneCode";

Utl.Config.pre_devicePlayer = "tsgame_devicePlayer_";
Utl.Config.devicePlayer = "tsgame_devicePlayer";

Utl.Config.pre_phoneInfo1 = "tsgame_phoneInfo1_";
Utl.Config.phoneInfo1 = "tsgame_phoneInfo1";

Utl.Config.pre_dLogin = "tsgame_dLogin_";
Utl.Config.dLogin = "tsgame_dLogin";

Utl.SetStorage=function(){
	Utl.Config.bgm = Utl.Config.pre_bgm+GameData.GameId;
	Utl.Config.sound = Utl.Config.pre_sound+GameData.GameId+GameData.AgentId;
	Utl.Config.roomtype = Utl.Config.pre_roomtype+GameData.GameId+GameData.AgentId;
	Utl.Config.shake = Utl.Config.pre_shake+GameData.GameId+GameData.AgentId;
	Utl.Config.multiple = Utl.Config.pre_multiple+GameData.GameId+GameData.AgentId;
	Utl.Config.voice = Utl.Config.pre_voice+GameData.GameId+GameData.AgentId;
	Utl.Config.roomlist = Utl.Config.pre_roomlist+GameData.GameId+GameData.AgentId;
	Utl.Config.playerid = Utl.Config.pre_playerid+GameData.GameId+GameData.AgentId;
	Utl.Config.gradeinfo = Utl.Config.pre_gradeinfo+GameData.GameId+GameData.AgentId;
	Utl.Config.shortcode = Utl.Config.pre_shortcode+GameData.GameId+GameData.AgentId;
	Utl.Config.ownerNote = Utl.Config.pre_ownerNote+GameData.GameId+GameData.AgentId;
	Utl.Config.machineId = Utl.Config.pre_machineId;
	Utl.Config.tea = Utl.Config.pre_tea+GameData.GameId+GameData.AgentId;
	Utl.Config.book = Utl.Config.pre_book+GameData.GameId+GameData.AgentId;
	Utl.Config.phoneInfo = Utl.Config.pre_phoneInfo+GameData.GameId+GameData.AgentId;
	Utl.Config.ownerNoteTime = Utl.Config.pre_ownerNoteTime+GameData.GameId+GameData.AgentId;
	Utl.Config.gameNoteTime = Utl.Config.pre_gameNoteTime+GameData.GameId+GameData.AgentId;
	Utl.Config.hallNoteTime = Utl.Config.pre_hallNoteTime+GameData.GameId+GameData.AgentId;
	Utl.Config.autoEnterOfc = Utl.Config.pre_autoEnterOfc+GameData.GameId+GameData.AgentId;
	Utl.Config.vipRoom = Utl.Config.pre_vipRoom+GameData.GameId+GameData.AgentId;
	Utl.Config.vipCharm = Utl.Config.pre_vipCharm+GameData.GameId+GameData.AgentId;
	Utl.Config.rebateLimit = Utl.Config.pre_rebateLimit+GameData.GameId+GameData.AgentId;
	//Utl.Config.phoneCode = Utl.Config.pre_phoneCode+GameData.GameId+GameData.AgentId;
	//Utl.Config.devicePlayer = Utl.Config.pre_devicePlayer+GameData.GameId+GameData.AgentId;
	//Utl.Config.phoneInfo1 = Utl.Config.pre_phoneInfo1+GameData.GameId+GameData.AgentId;

}

Utl.SaveData = function(key,data){
	storage.setItem(key,data);
}
Utl.checkKey=function(key){
	if(storage.getItem(key)==null){
		return false;
	}else{
		return true;
	}
}
Utl.ReadData=function(key){
	return storage.getItem(key);
}
Utl.RemoveItemByKey=function(key){
	if(storage.getItem(key)!=null){
		storage.removeItem(key);
	}
}
Utl.removeItemFromArray = function(_array,_data){
	var index = _array.indexOf(_data);
	if(index>-1){
		var r_data = _array.splice(index,1);
		return r_data;
	}else{
		return null;
	}
}
Utl.ClearStorage=function(){
	storage.clear();
}
//对象克隆 
Utl.clone = function(myObj){
  if(typeof(myObj) != 'object') return myObj;
  if(myObj == null) return myObj;

  var myNewObj = new Object();

  for(var i in myObj)
     myNewObj[i] = Utl.clone(myObj[i]);

  return myNewObj;
}
Utl.getMyInfo=function(){//获取玩家自身信息 
	var obj_return = Utl.clone(C_Player);
	return obj_return;
}

Utl.setGrade=function(seat,grade){//设置游戏主界面玩家积分信息 
	var ind=Logic.ChangeToStatus(C_Player.seat,seat);
	set_self(436+ind,7,grade,0,0);
	if(ind==0){
		if(Game_Config.Info.myPositionDefault){
			set_self(436+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - String(grade).gblen()*Game_Config.Info.textwidth_2/2,0,0);
		}else{
			set_self(436+ind,18,Game_Config.Info.myPosition - String(grade).gblen()*Game_Config.Info.textwidth_2/2,0,0);
		}
	}else{
		if(Game_Config.Info.otherPositionDefault){
			set_self(436+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - String(grade).gblen()*Game_Config.Info.textwidth_2/2,0,0);
		}else{
			set_self(436+ind,18,Game_Config.Info.position[ind-1] - String(grade).gblen()*Game_Config.Info.textwidth_2/2,0,0);
		}
	}
}

//播放背景音乐
Utl.playMusic=function(){
	if(Utl.ReadData(Utl.Config.bgm)==1){
		if(get_self(149,37,0,0,0)==1){//游戏界面中
			Func.play_wav(Game_Config.soundList.MenuSceneMusic,-1);
			//Func.play_wav(Game_Config.soundList.MainSceneMusic,-1);
			Func.play_wav(Game_Config.soundList.MainSceneMusic,1);
		}else if(get_self(4,37,0,0,0)){
			Func.play_wav(Game_Config.soundList.MainSceneMusic,-1);
			//Func.play_wav(Game_Config.soundList.MenuSceneMusic,-1);
			Func.play_wav(Game_Config.soundList.MenuSceneMusic,1);
		}	
	}
}
//播放音效
Utl.playSound=function(src){
	if(Utl.ReadData(Utl.Config.sound)==1){
		Func.play_wav(src,0);
	}
}
//停止播放背景音乐
Utl.stopMusic=function(){
	Func.play_wav(Game_Config.soundList.MainSceneMusic,-1);
	Func.play_wav(Game_Config.soundList.MenuSceneMusic,-1);

}
//停止播放音效
Utl.stopSound=function(src){
	Func.play_wav(src,-1);
}
//获取游戏ID 
Utl.getGameID=function(){
	return GameData.GameId;
}
//获取代理商ID 
Utl.getAgentID=function(){
	return GameData.AgentId;
}
//获取房间内某个座位玩家的playerid 
Utl.getPlayeridBySeat=function(seat){
	var pobj=Desk.GetPlayerBySeat(seat);
	return pobj.playerid;
}
//获取房间内某个座位的玩家昵称 
Utl.getNicknameBySeat=function(seat){
	var pobj=Desk.GetPlayerBySeat(seat);
	return pobj.nickname;
}
//获取房间内某个座位的玩家性别 2为女性，其他都认为是男性
Utl.getSexBySeat=function(seat){
	var pobj=Desk.GetPlayerBySeat(seat);
	return pobj.sex;
}
//获取玩家playerid 
Utl.getMyPlayerid=function(){
	return C_Player.playerid;
}
//获取玩家playerid
Utl.getMySex=function(){
	return C_Player.sex;
}
//获得房间号 
Utl.getRoomcode=function(){
	//if(Desk.shortcode){
		//return Desk.shortcode;	
	//}
	return Desk.roomcode;
}
//获取玩家座位号 
Utl.getMySeat=function(){
	return C_Player.seat;
}
//玩家退出房间 
Utl.Exit=function(){
	var tmp = Desk.infinite; 
	//Func.exitRoom();
	Desk.Init();
	C_Player.BreakRoom();
	GameUI.JumpMenuScene(true);
	//if(GameData.matchInfo){
		//GameData.matchInfo = null;
		//Utl.openMatchUrl();
	//}
	if(tmp && GameData.hallConfig.worldRoomList){
		var data={};
		data.agentid = GameData.AgentId;
		data.playerid = C_Player.playerid;
		data.gameid = GameData.GameId;
		Net.Send_get_share_room(data);
	}
}
//设置LocalData
Utl.setCookie=function(name, value, exp_hour) {
    if (!exp_hour) {
        exp_hour = 48; //默认时效48小时
    }
    var exp = new Date();
    Utl.SaveData(Utl.Config.validtime,exp.getTime() + exp_hour*60*60*1000);
	Utl.SaveData(name,value);   
}

//读取LocalData
Utl.getCookie=function(name) {
	if(GameData.versionState == 0){
	    var vt=Utl.ReadData(Utl.Config.validtime);
	    if(vt==null){
			return null;
		}
	    var exp = new Date().getTime();
	    if(exp < vt){//
			return Utl.ReadData(name);
		}else{
			return null;
		}
	}else{
		return Utl.ReadData(name);
	}
}

//删除LocalData
Utl.delCookie=function(name) {
    Utl.RemoveItemByKey(Utl.Config.validtime);
    Utl.RemoveItemByKey(name);
}
Utl.getAppService=function(){//ture为前台状态 false、为后台状态 
	return GameData.appservice;
}

//关闭所有窗口
Utl.closeWindow=function(){
	GameUI.CloseSetting();
	set_group(29,37,0,0,0);
	set_self(223,37,0,0,0);
	GameUI.CloseInfo();
	GameUI.CloseChat();
	set_self(38,37,0,0,0);
	set_self(39,37,0,0,0);
	GameUI.CloseHelp();
}
Utl.changeToStatus = function(seat){//将座位转化为方位（以自己为原点0，逆时针旋转依次往上加） 
	return Logic.ChangeToStatus(C_Player.seat,seat); 
}

Utl.isMainScene = function(){//获取是否在游戏主界面 
	var rt = get_self(149,37,0,0,0);
	if(rt==1){
		return true;
	}
	return false;
}

Utl.getMyOpenid = function(){//获取玩家openid 
	return C_Player.openid;
}
Utl.getOnState = function(status){//获取玩家状态 
	return GameUI.onstate[status];//1-->离线 2-->通话 其他正常
}
Utl.saveRoomtype = function(_data){//保存创建房间时的房间类型 
	var rt={};
	rt.data = _data;
	rt = JSON.stringify(rt);
	Utl.SaveData(Utl.Config.roomtype,rt);
}
Utl.getRoomtype = function(){//获取上次创建的房间类型 
	var roomty =  Utl.ReadData(Utl.Config.roomtype);
	if(roomty){
		roomty = JSON.parse(roomty);
		//if(Game_Config.Max.SumOfRoomtype!=roomty.data.length){			
			//Utl.SaveData(Utl.Config.roomtype,"");
			//return null;
		//}else{
			return roomty.data;
		//}
			
	}
	return null;
}
Utl.delRoomtype = function(){//删除房间类型 
	Utl.RemoveItemByKey(Utl.Config.roomtype);
}
//获得计算器计算结果（传入需要计算的数组） 
Utl.getMultipleResult = function(inputArr){
	var mult = 1;
	GameData.OrgArr = [].concat(inputArr);
	if(Utl.checkKey(Utl.Config.multiple)){
		var rd = Utl.ReadData(Utl.Config.multiple);
		if(GameUI.checkNumber(rd)){
			var rt = Number(rd);
			if(rt>0){
				mult = rt;
			}else{
				Utl.SaveData(Utl.Config.multiple,"1");
			}
		}else{
			Utl.SaveData(Utl.Config.multiple,"1");
		}
	}else{
		Utl.SaveData(Utl.Config.multiple,"1");
	}
	var rtarr = [];
	rtarr.length = inputArr.length;
	for(var i=0;i<inputArr.length;i++){
		rtarr[i] = Func.accMul(inputArr[i],mult);
	}
	return rtarr;
}
//打开提示 
Utl.openTips = function(_msg,time,mode){
	GameUI.OpenTips(_msg,time,mode);
}
//关闭提示
Utl.closeTips = function(){
	GameUI.CloseTips();
}
//发送消息 
Utl.sendData = function(_app,_route,_rpc,_data){
	Net._SendData(_app,_route,_rpc,_data);
}
//获取某个座位玩家的头像资源id 
Utl.getHeadimgSrc = function(seat){
	if(Desk.GetPlayerBySeat(seat).avatar){
		var idx = Utl.changeToStatus(seat);
		return 116+idx;
	}else{
		return 170;
	}
}
//开启加载界面
Utl.startLoad = function(){
	GameUI.StartLoad();
}
//关闭加载界面
Utl.endLoad = function(){
	GameUI.EndLoad();
}
Utl.changePlayerState = function(state){//设置玩家是否可以直接退出房间 0->不可以1->可以 
	if(Desk.infinite == 1){C_Player.ChangeExit(1);return;}
	C_Player.ChangeExit(state);
}
Utl.getGameConfig = function(){//获取游戏配置 
	return GameData.gameConfig;
}
/*
{"address":"江西省南昌市青云谱区施尧路靠近上海浦东发展银行(长天支行)","city":"南昌市",
"cityCode":"0791","country":"中国","district":"青云谱区","latitude":28.623546,"longitude":115.900333,
"province":"江西省","street":"施尧路"}*/
Utl.getLocation = function(){//获取玩家定位信息 
	if(C_Player.addr){
		return Utl.clone(C_Player.addr);
	}else{
		return null;
	}
}
Utl.getMathInfo = function(){
	return Utl.clone(GameData.matchInfo);
}
Utl.getIsMathInfo = function(){
	if(Utl.clone(GameData.matchInfo)){
		return true;
	}
	return false;
}
Utl.getInfMode = function(){
	return GameData.infMode;
}
Utl.changeBean = function(_bean,seat){
	var ind = Logic.ChangeToStatus(C_Player.seat,seat);
	var pobj=Desk.GetPlayerBySeat(seat);
	pobj.bean = pobj.initialBean + _bean;
	var beanInfo = pobj.bean;
	pobj = null;
	if(get_self(216,37,0,0,0) == 1 && GameData.infoSeat == seat){
		set_self(511,7,GameData.starName+"："+beanInfo,0,0);
	}
	//switch(ind){
		//case 0:
			//C_Player.changeBean(_bean);
			//break;
		//default:
			//if(get_self(216,37,0,0,0) == 1 && GameData.infoSeat == seat){
				//set_self(511,7,GameData.starName+"："+beanInfo,0,0);	
			//}				
			//break;
	//}	
		
}
//关闭邀请显示 
Utl.closeInvitation = function(){
	set_self(183,37,0,0,0);
	set_self(195,37,0,0,0);	
}
//关闭互动显示
Utl.closeCommunication = function(type){
	set_self(152,37,0,0,0);
	if(!type){
		set_self(153,37,0,0,0);
	}
}
//跳转比赛网页
Utl.openMatchUrl = function(){
	if(ConstVal.isGameHall){return;}
	if(GameData.backUrl){
		Func.OpenurlTitleData(GameData.backUrl,"","");
		GameData.backUrl = "";
	}
}
//牌局回放进入主界面
Utl.openVideo = function(_playerList,_seat,_roomcode,roomtype){
	/*
	_playerList 格式： [[昵称,头像],[]...]
	*/
	if(roomtype){Desk.roomtype = roomtype;}
	Logic.updateMainSceneData(roomtype);
	for(var i=0;i<_playerList.length;i++){
		if(_playerList[i]){
			var pobj=Desk.GetPlayerBySeat(i);
			//pobj.SetDeskInfo(_playerList[i]);
			pobj.nickname = _playerList[i][0];
			pobj.avatar = _playerList[i][1];
			pobj = null;
		}
	}
	C_Player.seat = _seat;
	Desk.roomcode = _roomcode;
	//GameUI.HideNotice();
	//GameData.Battery=Func.getbattery();
	GameData.Battery = 1;
	if(GameData.Battery<=0.2){
		set_self(338,43,3,0,0);
	}else{
		set_self(338,43,2,0,0);
	}
	//GameData.NetWork=Func.getnetwork();
	GameData.NetWork = 1;
	if(GameData.NetWork==2){
		set_self(336,43,3,0,0);
		Func.getwifisignalLevel();
	}else{
		set_self(336,43,4,0,0);
	}
	if(GameData.OS == ConstVal.OS.apple){//苹果
		set_self(154,1,174,0,0);
		set_self(155,1,174,0,0);
		set_self(156,1,173,0,0);
	}else {//安卓
		set_self(154,1,69,0,0);
		set_self(155,1,69,0,0);
		set_self(156,1,70,0,0);
	}



	set_group(21,37,1,0,0);
	set_self(3115,37,0,0,0);
	set_self(3116,37,0,0,0);
	GameUI.updateSysNoticeCount2();
	set_self(150,37,0,0,0);
	set_self(151,37,0,0,0);
	set_self(152,37,0,0,0);
	set_self(153,37,0,0,0);
	set_self(107,37,0,0,0);
	for(var i=0;i<Desk.PlayerList.length;i++){
		if(Desk.PlayerList[i].nickname!="" ){
			var ind=Logic.ChangeToStatus(C_Player.seat,i);
			var text=Func.subString(Desk.PlayerList[i].nickname,Game_Config.Info.Mainnickname,true);
			set_self(406+ind,7,text,0,0);
			if(ind==0){
				if(Game_Config.Info.myPositionDefault){
					set_self(406+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - text.gblen()*Game_Config.Info.textwidth_1/2,0,0);
				}else{
					set_self(406+ind,18,Game_Config.Info.myPosition - text.gblen()*Game_Config.Info.textwidth_1/2,0,0);
				}
			}else{
				if(Game_Config.Info.otherPositionDefault){
					set_self(406+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - text.gblen()*Game_Config.Info.textwidth_1/2,0,0);
				}else{
					set_self(406+ind,18,Game_Config.Info.position[ind-1] - text.gblen()*Game_Config.Info.textwidth_1/2,0,0);
				}
			}

			set_self(436+ind,7,0,0,0);
			if(ind==0){
				if(Game_Config.Info.myPositionDefault){
					set_self(436+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - Game_Config.Info.textwidth_2/2,0,0);
				}else{
					set_self(436+ind,18,Game_Config.Info.myPosition - Game_Config.Info.textwidth_2/2,0,0);
				}
			}else{
				if(Game_Config.Info.otherPositionDefault){
					set_self(436+ind,18,get_self(376+ind,18,0,0,0) + get_self(376+ind,20,0,0,0)/2 - Game_Config.Info.textwidth_2/2,0,0);
				}else{
					set_self(436+ind,18,Game_Config.Info.position[ind-1] - Game_Config.Info.textwidth_2/2,0,0);
				}
			}
			Func.up_imgurl(116+ind,Desk.PlayerList[i].avatar);
			set_group(43+ind,37,1,0,0);
		}
	}
	play_ani123(1,156,35,255,100,1000,0,0,1);
	Utl.playMusic();
	set_self(3141,37,0,0,0);
	set_self(3142,37,0,0,0);
	if(Desk.roomcode){
		set_self(3141,7,Desk.roomcode,0,0);
	}
	GameUI.playTopInfoAnimation();
	Game_Modify.onEnterVideo();
	//GameData.Scene = 2;
	//Game_Modify.onEnterMainScene(Desk.roomtype);
} 
Utl.closeVideo =function(){
	Utl.playMusic();
	Desk.Init();
	C_Player.BreakRoom();
	set_group(21,37,0,0,0);
	for(var i=0;i<Game_Config.Max.PlayerCnt;i++){
		set_group(43+i,37,0,0,0);
	}
	
}

Utl.getPlayerCnt = function(){
	return Desk.playercnt;
}
//存储战绩 
Utl.saveGradeInfo = function(_data){
	var rData = Utl.readGradeInfo();
	if(rData){
		rData = JSON.parse(rData);
		rData.unshift(_data);
		var overLen = rData.length - 10;
		for(var i=0;i<overLen;i++){
		 	rData.pop();	
		}
	}
	Utl.SaveData(Utl.Config.gradeinfo,JSON.stringify(rData));
}
//读取战绩
Utl.readGradeInfo = function(){
	return Utl.ReadData(Utl.Config.gradeinfo);
} 
Utl.getPlayerReadyState = function(seat){
	var pobj = Desk.GetPlayerBySeat(seat);
	return pobj.isprepare;
}
//获取玩家是否拥有高级选项
Utl.getPlayerAdvanced = function(){
	return C_Player.advanced;
} 
//打开高级选项调用
Utl.openSnrOption = function(mode,roomtype,descrip,_profit){//mode0星星场1非星星场 
	GameData.snrOptionMode = mode;
	GameData.snrOptionRoomtype = roomtype;
	GameData.snrOptionDes = descrip;
	GameData.snrOptionProfit=_profit;
	var data = {}
	data.agentid = GameData.AgentId;
	data.gameid = GameData.GameId;
	data.playerid = C_Player.playerid;
	Net.Send_advanced_roomlist(data);
} 
//获取玩家是否拥有高级选项 0无高级选项>0有高级选项 
Utl.getAdvanced = function(){
	return C_Player.advanced;
}
//获取游戏是否为审核版本(0非审核1审核)
Utl.getVersionState = function(){
	return GameData.versionState;
} 
//获取游戏是否为h5版本(0->非h51->h5)
Utl.getH5Version = function(){
	return GameData.h5Version;
}
//游戏结算时调用
Utl.onGameFinished = function(inputArray,spidList){//结算信息[[昵称,输赢分数],.......] 
	if(!spidList){
		spidList=[];
	}
	if(GameData.h5Version == 1){
		var title = "";
		var desc  = "";
		if(inputArray.length>3){
			for(var i=0;i<5;i++){
				if(inputArray.length>i){
					if(i<2){
						title +=  inputArray[i][1]+":" +Func.subString(inputArray[i][0],24-String(inputArray[i][1]).length - 3,true) + "\n";
					}else{
						desc += inputArray[i][1] + ":" +Func.subString(inputArray[i][0],24-String(inputArray[i][1]).length - 3,true)  +"\n";
					}
	
				}
			}
		}else{
			title = Game_Config.Share.title;
			for(var i=0;i<3;i++){
				if(inputArray.length>i){
					desc += inputArray[i][1] + ":" +Func.subString(inputArray[i][0],24-String(inputArray[i][1]).length - 3,true)  +"\n";
				}
			}
		}
		GameData.shareAppMessage = Logic.getShareDataObj(title,desc);
		GameData.shareTimeline = Logic.getShareDataObj1(Game_Config.Share.title+Game_Config.Share.description,"");
		shareLink(GameData.shareTimeline,GameData.shareAppMessage);
		for(var i=0;i<Desk.PlayerList.length;i++){
			if(Desk.PlayerList[i].playerid != -1 ){
				var ind=Logic.ChangeToStatus(C_Player.seat,i);				
				//up_imgurl(116+ind,"assets/bmp/00170.png",1);
				set_self(116+ind,1,170,0,0);
			}
		}
		for(var i=0;i<spidList.length;i++){
			set_self(spidList[i],37,0,0,0);	
		}
	}
}
Utl.getBeanBySeat = function(seat){
	var pobj = Desk.GetPlayerBySeat(seat);	
	if(pobj){
		return pobj.bean;
	}
	return -1;
}
Utl.getIsDebugger = function(){
	return GameData.isDebugger;
}
//打开数字输入面板
Utl.openInputPanel = function(_msg,_callback,begin0){
	GameUI.openInputPanel(_msg,_callback,begin0);
} 
//关闭数字输入面板
Utl.closeInputPanel = function(){
	GameUI.closeInputPanel();
}
//获取房卡名称
Utl.getRoomCardName = function(){
	return GameData.roomCardName;
} 
//获取星星名称名称
Utl.getstarName = function(){
	return GameData.starName;
}
//获取房卡图片帧数
Utl.getNameImgFrame_1 = function(){
	return Number(GameData.nameImgFrame_1);
} 
//获取星星图片帧数
Utl.getNameImgFrame_2 = function(){
	return Number(GameData.nameImgFrame_2);
}
//子游戏活动的调用类型(在收到大局结算包调用、重画时不允许调用)
Utl.typeForActivity = function(type,data){
	//logmessage("typeForActivity"+type,1);
	GameData.activityType = type;
	GameData.activityData = data;
	GameData.shareTimes = 0;
	//switch(type){
		//case 1://大赢家 
			//GameData.activityType = type;
			//GameData.activityData = data;
			//break;
	//}
}
//设置玩家准备状态
Utl.setPlayerPrepare = function(seat,state){
	var pobj=Desk.GetPlayerBySeat(seat);
	pobj.isprepare = state;
	if(seat == C_Player.seat){
		C_Player.isprepare = state;
	}
	GameUI.SetIsprepare(seat,state);
	GameUI.showReady();

	//switch(state){
		//case 0:
			
			//break;
		//case 1:
			
			//break;
	//}
} 
//获取是否为无限局0非无限局1无限局 
Utl.getIsInfinite = function(){
	return Desk.infinite;
}
//复制到粘贴板
Utl.gameCopytext = function(text){
	Func.gameCopytext(text);
} 
Utl.openTips2 = function(_msg,time){
	GameUI.openTips2(_msg,time);
}
//关闭主界面按钮
Utl.closeMainSceneButton = function(){
	GameUI.HideStartScene();
	//GameUI.hideEscape();
	GameUI.hideReady();
	//GameUI.hideChangeRoom();
} 
//更改牌桌开战和玩家是否参与游戏(无限局)
Utl.setDeskStage = function(state){
	if(Desk.infinite == 0){return;}
	Desk.SetStage(state);
	switch(state){
		case 0://未开战 
			GameUI.showReady();
			//GameUI.showChangeRoom();
			//GameUI.showExitBtn();
			break;	
		case 1://已开战 
			if(C_Player.isprepare == 1){
				GameUI.hideReady();
				GameUI.HideStartScene();
				//GameUI.hideChangeRoom();
				GameUI.hideExitBtn();
				//GameUI.showExitBtn2();
			}else{
				GameUI.hideReady();
				//GameUI.showExitBtn();
				//GameUI.showChangeRoom();
			}
			break;
	}
} 
//获取吱口令
Utl.getPayCodeBySeat = function(seat){
	var pobj = Desk.GetPlayerBySeat(seat);
	return pobj.paycode;
} 
//设置文字精灵颜色
Utl.setFontColor = function(spid,value){//精灵id，字体颜色 
	ifast_getobj(spid).uidata.FontColor = value;
} 
//获取当前房间短号 非短号房返回null; 
Utl.getShortCode = function(){
	Desk.getShortCode();
}
//游戏大局结算时调用 
Utl.gameOver = function(){
	GameUI.CloseApplyResult();
	Func.exitRoom();
}
//不联网情况下进入主界面
Utl.mainScene = function(){
	GameUI.MainScene(true);
	GameUI.mainSceneLoaded();
	if(GameData.heartBeatTimer){
		window.clearTimeout(GameData.heartBeatTimer);
	}
	if(GameData.getConfigTimer){
		window.clearTimeout(GameData.getConfigTimer);
	}
} 
Utl.openInfo1=function(src,nickname,playerid,ip,sex,seat,bean){//打开个人信息
	Utl.playSound(Game_Config.ClickButton.src_2);
	GameData.infoSeat = seat;
	InfoSex=sex;
	//if(ind!=-1){
		//set_self(282,1,116+ind,0,0);
	//}else{
		//set_self(282,1,25,0,0);
	//}
	set_self(282,1,src,0,0);

	set_self(279,7,Func.subString(nickname,Game_Config.Max.Infonickname,true),0,0);
	set_self(280,7,"ID："+playerid,0,0);
	set_self(281,7,"IP："+ip,0,0);
	set_self(511,7,GameData.starName+"："+bean,0,0);
	set_self(216,21,220,0,0);
	set_group(77,37,1,0,0);
	//if(typeof(seat)!="undefined"){
		//var status = Logic.ChangeToStatus(C_Player.seat,seat);
		//if(status!=0){
			//GameData.InteractPlayer=seat;
			//set_self(216,21,325,0,0);
			//set_group(38,37,1,0,0);
		//}
	//}
	set_self(256,37,0,0,0);
	set_self(257,37,0,0,0);
	set_self(258,37,0,0,0);
	set_self(259,37,0,0,0);
	if(!GameData.hallConfig.enablePay){
		set_self(511,37,0,0,0);
	}

}
Utl.getPhoneInfo = function(){
	return min_copyjson(GameData.phoneInfo);
}

Utl.openInfo=function(seat,headSrc){//打开个人信息
	var pInfo = Desk.GetPlayerBySeat(seat);
	var nickname = pInfo.nickname;
	var playerid = pInfo.playerid;
	var ip       = pInfo.ip;
	var sex		 = pInfo.sex;
	var bean     = pInfo.bean;
	var cVal     = pInfo.charm;	
	Utl.playSound(Game_Config.ClickButton.src_2);
	GameData.infoSeat = seat;
	InfoSex=sex;

	set_self(282,1,headSrc,0,0);



	set_self(279,7,Func.subString(nickname,Game_Config.Max.Infonickname,true),0,0);
	set_self(280,7,"ID："+playerid,0,0);
	set_self(281,7,"IP："+ip,0,0);
	set_self(511,7,GameData.starName+"："+bean,0,0);

	set_self(216,21,220,0,0);
	set_group(77,37,1,0,0);
	GameUI.setShortRoom(GameData.infoSeat,cVal);
	//if(typeof(seat)!="undefined"){
		//var status = Logic.ChangeToStatus(C_Player.seat,seat);
		//if(status!=0){
			//GameData.InteractPlayer=seat;
			//set_self(216,21,325,0,0);
			//set_group(38,37,1,0,0);
		//}
	//}
	if(!GameData.hallConfig.enablePay){
		set_self(511,37,0,0,0);
	}

}
//通过座位号获取玩家信息 
Utl.getPlayerInfoBySeat = function(seat){
	return Desk.GetPlayerBySeat(seat);
}
Utl.enterShareRoom = function(roomInfo){
	var data={};
	data.agentid=GameData.AgentId;
	data.playerid=C_Player.playerid;
	data.gameid=GameData.GameId;
	data.type = roomInfo.type;
	data.roomtype = roomInfo.roomtype;
	Net.Send_quick_enter_share_room(data);
}
Utl.getShareRoom = function(){
	var data={};
	data.agentid = GameData.AgentId;
	data.playerid = C_Player.playerid;
	data.gameid = GameData.GameId;
	Net.Send_get_share_room(data);
}
Utl.getPlayerList = function(){
	return Desk.PlayerList;
}
Utl.updatePlayerInfoUI = function(){
	GameUI.updatePlayerInfoUI();
}
Utl.convertNumberToImg = function(val,bTemp){//bTemp正数是否显示正号 
	try{//0123456789+-.
		
		var rValue = String(val);
		rValue = min_replaceAll(String(rValue), "\\.", "d", false);
		rValue = min_replaceAll(String(rValue), "-", "c", false);
		if(bTemp && Number(val) >= 0){
			rValue = "b"+rValue;
		}
		
		return rValue;	
	}catch(e){
		console.log(e);
		return 0;	
	}
	
}

Utl.openTextInput = function(msg,callFun,len){
	GameUI.openTextInput(msg,callFun,len);
}
Utl.sendText = function(text){
	try{
		var data={};
		data.agentid=GameData.AgentId;
		data.gameid=GameData.GameId;
		data.playerid=C_Player.playerid;
		data.roomcode=Desk.roomcode;
		data.type=0;
		data.text = text;
		Net.Send_send_text(data);
	}catch(e){
		
	}
}
//是否可以显示退出按钮 
Utl.getExitVisible = function(){
	if(Desk.infinite == 1){
		return true;
	}
	return false;
}
//是否可以显示换房按钮
Utl.getChangeVisible = function(){
	if(Desk.infinite == 1 && !Desk.shortcode){
		return true;	
	}
	return false;
}
//发送退出房间
Utl.sendExitRoom = function(){
	var data={};
	data.agentid=GameData.AgentId;
	data.gameid=GameData.GameId;
	data.playerid=C_Player.playerid;
	data.roomcode=Desk.roomcode;
	Net.Send_self_exit_room(data);
} 
//发送换房
Utl.sendChangeRoom = function(){
	var data={};
	data.agentid = GameData.AgentId;
	data.playerid = C_Player.playerid;
	data.gameid = GameData.GameId;
	data.roomcode = Desk.roomcode;
	Net.Send_change_room(data);
}
//获取房间费范围 
Utl.getRebateRange = function(mult,mode){
	if(!GameData.sysConfig.rebateConfig){
		return [0,9999999];
	}
	if(Game_Config.sysConfig.vipInfinite){
		return [0,9999999];
	}
	if(mode){return [0,9999999];}
	return [parseInt(mult * GameData.sysConfig.rebateConfig.value/100),9999999];
}
//是否隐藏分享按钮 0->不隐藏  1-隐藏 
Utl.getShowShare = function(){
	return GameData.sysConfig.hideWxShare;
}





