﻿document.domain='xunlei.com';

var noServerList = false;
var PageConfig={
	isIE         : (document.all && document.attachEvent),
	loginURL     : 'http://svr.game.xunlei.com/login.webGameLogin',
	loginOutURL  : 'http://svr.game.xunlei.com/logout.webGameLogin',
	validURL     : 'http://svr.game.xunlei.com/loginWithUsername.webGameLogin',
	gameLoginV   : 'http://svr.game.xunlei.com/loginWithServerid.webGameLogin',
	pvURL        : 'http://svr.game.xunlei.com/newRegister.webGameUnionStat',
	pvURL1       : 'http://svr.game.xunlei.com/newRelation.webGameUnionStat',
	//pvURL2       : 'http://svr.game.xunlei.com/newRelation.webGameAdvStat?advid=xunlei&uname=fonfftong&gameid=003219',
	pvURL2       : 'http://svr.game.xunlei.com/newRelation.webGameAdvStat',
	pvURL3       : 'http://svr.game.xunlei.com/newRegister.webGameAdvStat',
	lastSvrCk    : 'lastLoginS',
	xmlAgent     : null,
	userIsLogin  : false,			//用户登录状态
	cookieTimeOut: 10000,
	loginUname   : '',
	validPic     : 'http://verify.xunlei.com/image?',
	validImg     : 'img_verify',		//验证码图片ID
	validImgH    : 'img_verify_h',
	loginBtn     : 'loginBtn',
	usernameTxt  : 'txt_uname',
	userpwdTxt   : 'txt_pwd',
	vcodeTxt     : 'txt_validCode',
	frmProxyAgent: 'frProxy',
	maskDiv      : 'mask',
	loadingBar   : 'loading',
	pnlUser      : 'sith-login',               //用户登陆后的面板ID
	pnlUsername  : 'p_userPanel_name',          //登陆用户名
	pnlUserexit  : 'p_userPanel_exit',          //用户信息面板中退出按钮的ID
	pnlUserReg   : 'regBtn',
	topUserReg   : 'regID',
	pnlUsernewserver: 'gameList0',    //用户面板中最新开区服务器列表
	pnlUserserver: 'gameList1',    //用户面板中双线服务器列表
	pnlLoading   : 'p_loginLoading',            //
	pnlLogin     : 'p_userLogin',
	gameID	     : '000019',					//三国风云ID
	cookieLastUN : 'lastLgUN',   
	gameINFO     : null,
	pvImg        : 'pv_img',
	newUserCook  : 'statusername',
	cookie1      : 'location',
	regURL       : 'http://i.xunlei.com/register/register.htm',
	serverNum    : 'numOfServers',   //服务器数
	gameListPnl  : 'gameListP',  //游戏列表面板
	gameListPnlL : 'gmlistUL',
	gameListPnlL1 : 'gmlistUL1',
	gamePnlcloser  : 'clpnlbtn',
	gamePnlcloser1 : 'clpnlbtn_1',
	gamePnlcloser2 : 'clpnlbtn_2',
	showServerPnl: 'btnshowServerPnl',
	newUser      : '',
	USER_NAME    : '请输入迅雷帐号',
	USER_PWD     : '请输入登陆密码',
	GameAddFav   : 'addGameFav',
	gServerPerPg : 12,            //左侧游戏服务器列表每页显示的记录数
	curServerPGNo: 1,			  //服务器列表 页当前页码
	newServerList: [],			  //新服列表
	ServerList   : [],             //双线列表
	floatLoginPnl: 'login',        //浮动登陆框
	floginPnlcl  : 'lgbtn_close',   //浮动窗口关闭按钮
	loginNewSvrs : null,  //用户登陆后列新开服务器的面板
	loginNewSvrsI: 'newServerListLog',  //用户登陆后列新开服务器的面板
	loginGameSURL: '',
	loginGameSID : -1,
	logNewSvrsArr: [],
	loginType    : 0,               //登陆形式 1为浮层登陆
	loginedSvrCK : '_loginedSvrs',
	SvrIDInfo    : {},
	loginMsg     : '',
	loginedSvrs  : []               //登陆过的服务器
};

var UVALID_MSG  = {1:'用户名不存在或密码错误',2:'密码错误',3:'用户名错误',4:'网络故障',5:'验证码错误',6:'未知错误'};
var SCONNET_MSG = {CONNECTERR:'登录验证失败,请重新登录!',CONNECTTIMEOUT:'链接服务器超时，请稍候重试!'};

function setUserName(um){
	var ureged;
	var o = $(PageConfig.usernameTxt);
	if(o){
		if(!o.value){
			ureged = (um || UserLogin.getCookie(PageConfig.cookieLastUN));				
			o.value = ureged?ureged:PageConfig.USER_NAME;
		}
		o.select();
	}
}

function doSPReg(){
	document.location.href="http://webgame.xunlei.com/sgfy/redirect.html?pgn="+encodeURIComponent(document.location.search)+'&advid='+_GET['advid'];return false;
}
//页面初始化入口
function body_initialize(){	
	PageConfig.loginNewSvrs = $(PageConfig.loginNewSvrsI);
	PageConfig.floatLoginPnl = $(PageConfig.floatLoginPnl);
	//验证码点击事件
	$(PageConfig.validImg).onclick = function(){reloadImg();return false;};
	//$(PageConfig.validImgH).onclick = function(){reloadImg();return false;};
	try{
	$(PageConfig.validImg).src = PageConfig.validPic+'?'+Date.parse(new Date());
	$(PageConfig.loginBtn).onclick = login;
	$(PageConfig.gameListPnl).style.display = 'none';
	
	$(PageConfig.floginPnlcl).onclick = function(){showLoginPnl(false);return false;};
	$('lgsubbtn').onclick = function(){pnlLogin();}
	
	//$(PageConfig.gamePnlcloser1).onclick = $(PageConfig.gamePnlcloser).onclick = 
	
	//alert(btnc);
	
	$(PageConfig.showServerPnl).onclick = function(){showServerList(true);return false;}
	//$(PageConfig.pnlUsername).onclick = function(){this.select();}
	//$(PageConfig.usernameTxt).value = PageConfig.USER_NAME;
	//$(PageConfig.userpwdTxt).value = PageConfig.USER_PWD;

	$(PageConfig.usernameTxt).onclick = function(){if(this.value==PageConfig.USER_NAME){this.value='';}else{}}
	$(PageConfig.usernameTxt).onfocus = function(){if(this.value==PageConfig.USER_NAME){this.value='';}else{this.select();}reloadImg();return false;} //
	$(PageConfig.usernameTxt).onblur = function(){if(!this.value){this.value=PageConfig.USER_NAME}else{}}
	
	$(PageConfig.userpwdTxt).onfocus = function(){this.select();}  
	$(PageConfig.vcodeTxt).onkeydown = function () {
		var event=document.all?window.event:arguments[0]; 
		if (event.keyCode==13){login();}
	};
	
	
	//退出按钮事件
	$(PageConfig.pnlUserexit).onclick = loginout;

	var regFun = function(){document.location.href="redirect.html?pgn="+encodeURIComponent(document.location.search)+'&advid='+_GET['advid'];return false;};

	//注册按钮事件
	if($(PageConfig.pnlUserReg)){
		var lk = $(PageConfig.pnlUserReg);
		lk.setAttribute('href',"redirect.html?pgn="+encodeURIComponent(document.location.search)+'&advid='+_GET['advid']);
		lk.setAttribute('target','_regPage');
		//$(PageConfig.pnlUserReg).onclick = regFun;
	}
	//$(PageConfig.topUserReg).onclick = regFun;

	//设置验证地址
	UserLogin.loginURL    = PageConfig.loginURL;
	UserLogin.validURL    = PageConfig.validURL;
	UserLogin.loginOutURL = PageConfig.loginOutURL;

	
	//设置验证触发事件
	UserLogin.onBeforeLogin = beforeLogin;
	UserLogin.onAfterLogin  = afterLogin;
	
	UserLogin.onBeforeValid = beforeValid;
	UserLogin.onAfterValid  = afterValid;

	UserLogin.onBeforeLogOut = beforeLogout;
	UserLogin.onAfterLogOut  = afterLogout;
	
	}catch(e){
		alert(e);
	}
	
	try{
		document.body.onscroll = setPnlPos;
	}catch(e){}
	
	//注册用户PV统计
	/**************************************************/	
	try{		
		var ureged=UserLogin.getCookie(PageConfig.newUserCook); 
		if(!ureged.isEmpty()){
			_GET['gid']    = (_GET['gid']==undefined?'':_GET['gid']);
			_GET['cflag']  = (_GET['cflag']==undefined?'':_GET['cflag']);
			PvCount((_GET['gid'].isEmpty()?'xunlei':_GET['gid']),(_GET['cflag'].isEmpty()?'000':_GET['cflag']),ureged);
			pvCount1(ureged);
			UserLogin.setCookie(PageConfig.newUserCook,'',0);
			$(PageConfig.usernameTxt).value = ureged;			
		}else{			
			ureged = UserLogin.getCookie(PageConfig.cookieLastUN);
		}
		setUserName(ureged);
		//$(PageConfig.usernameTxt).value = ureged?ureged:PageConfig.USER_NAME;
	}catch(e){}


	initPhb();
	setPH_init();
	renderServerList();
	//initLoginedSvr();
	initServerList();
}

function beforeLogout(){
	showLoading(true);
}
function clsFun(){
	showServerList(false);
	$('showAllBtn').style.display = 'block';
	$('allServerList').style.display = 'none';
	$('quanbu_fw_img').style.display = 'none';
	//$(PageConfig.gameListPnlL1).innerHTML = '';//清除全部服务器的内容
	$(PageConfig.gameListPnlL).innerHTML = '';//清除全部服务器的内容
	return false;
}
function showServerList(flag){
	flag = (flag==undefined?true:flag);
	var mask = $(PageConfig.maskDiv);
	if(mask){
		mask.style.width  = document.body.scrollWidth.toString()+'px';
		mask.style.height = document.body.scrollHeight.toString()+'px';
	}
	mask.style.display = (flag?'block':'none');
	
	var gmpnl = $(PageConfig.gameListPnl);
	if(gmpnl){
		gmpnl.style.display = (flag?'block':'none');
		if(flag){
			refreshServerData();			
			setPnlPos();			
		}
	}
}

function _intPnl(){
	if(this.getAttribute('readyState')=='loaded'){
		setPnlPos();			
		scroll(0,0);
		initServerList();

		try{
			if(!PageConfig.isIE){
				this.parentNode.removeChild(this);
			}
		}catch(e){}
	}
}

function refreshServerData(){
	var sc = null;
	var newSC = false;
	if(refreshServerData['so'] && PageConfig.isIE){
		sc = refreshServerData['so'];
		sc.setAttribute('src','');
	}else{
		newSC = true;
		sc = document.createElement('script');	
		sc.setAttribute('type','text/javascript');
		sc.setAttribute('charset','UTF-8');
		refreshServerData['so'] = sc;
	}
	sc.setAttribute('src','http://mygame.xunlei.com/jsdata/gameservers/webgame/000019.js?'+Date.parse(new Date()));
	if(PageConfig.isIE){
		sc.onreadystatechange = function(){_intPnl.apply(sc,[]);};
	}else{
		sc.setAttribute('readyState','loaded');
		sc.onload = function(){_intPnl.apply(sc,arguments);};
		sc.onerror = function(){_intPnl.apply(sc,arguments);};		
	}
	if(newSC){
		document.getElementsByTagName('head')[0].appendChild(sc);
	}
}


function setPnlPos(){
	var gmpnl = $(PageConfig.gameListPnl);
	if(gmpnl){
		gmpnl.style.left = ((document.body.offsetWidth - gmpnl.offsetWidth)/2 + document.body.scrollLeft) + 'px';
		gmpnl.style.top  = 120 + 'px';
	}
}
function afterLogout(){
	UserLogin.removeCookie(UserLogin.cookieName);
	PageConfig.loginUname = '';			//清除页面变量

	ureged = UserLogin.getCookie(PageConfig.cookieLastUN);
	setUserName();
	//$(PageConfig.usernameTxt).value = ureged?ureged:PageConfig.USER_NAME;
	$(PageConfig.userpwdTxt).value = '';
	reloadImg();
	showUserInfoPanel(0,1);				//显示用户登陆面板	
	showLoading(false);
	var lkPnl = $('linksarea');
	if(lkPnl){
		lkPnl.style.display = 'block';
	}
	$(PageConfig.gameListPnl).style.display = 'none';
	PageConfig.loginGameSURL = '';
	PageConfig.loginType = 0;
	return false;
}


//用户退出登陆
function loginout(){
	UserLogin.loginOut(PageConfig.loginUname,PageConfig.gameID);
	UserLogin.setCookie('_loginStatus_','0');//记录为已登录状态
	return false;
}


//登陆游戏
function gameLogin(serverid,serverurl){		
	if(PageConfig.loginUname){
		if(PageConfig.loginType){
			var o = getServerInfo(serverid);
			if(o && o['remark']){
				PageConfig.loginMsg = o.remark;
			}else{
				PageConfig.loginMsg = '';
			}
		}
		var gmpnl = $(PageConfig.gameListPnl);
		if(gmpnl){
			gmpnl.style.display = 'none';
		}
		var frm=$(PageConfig.frmProxyAgent);
		if(!frm) return;
		var objA = new SyAjax(frm.contentWindow.remoteProxy);
		objA._method='GET';
		var strP = '';

		objA.onBeginPost = beforeGameLoginValid;
		objA.onPosted    = afterGameLoginValid;

		strP = 'username=' + encodeURIComponent(PageConfig.loginUname);
		strP+= '&serverid=' + serverid;
		strP+= '&vcodestr=2';
		strP+= '&vcode=1';
		strP+= '&Random=' + getRandomizChar();
		strP+= '&loginurl=' + encodeURIComponent(serverurl);
		strP+= '&gameid=' + encodeURIComponent(PageConfig.gameID);
		objA.post(PageConfig.gameLoginV,strP);
		
		//将登陆服务器ID写入Cookie
		//var info = getServerInfo();
		setLoginedSid(serverid);
		UserLogin.setCookie(PageConfig.lastSvrCk+'_'+PageConfig.gameID+'_'+PageConfig.loginUname,serverid);
	}else{
		showLoginPnl();
		PageConfig.loginGameSURL = serverurl;
		PageConfig.loginGameSID  = serverid;
		//alert('登陆!');
	}
}


//登陆游戏前
function beforeGameLoginValid(){
	showLoading(true);
}

//登陆游戏后
function afterGameLoginValid(obj){

	var altMSG='';
    var retStr=obj.responseText;
	try{
		eval('var ret='+retStr);
	}catch(e){
		ret=null;
	}

	if(!ret){
		altMSG = SCONNET_MSG['CONNECTTIMEOUT'];
	}else{
		if(ret.gameLoginStatus == 0){
			//验证cookie登陆成功
			var loginURL='';
			try{
				loginURL=ret.gameLoginURL;
			}catch(e){}

			if(!loginURL){
                altMSG = SCONNET_MSG['CONNECTERR'];
			}else{
			
				//var info = getServerInfo();
				//setLoginedSid
				if(PageConfig.loginType && PageConfig.loginMsg){
					alert(PageConfig.loginMsg);
					PageConfig.loginMsg = '';
				}
				var win=null;
				_GET['gid']    = (_GET['gid']==undefined?'':_GET['gid']);
				_GET['cflag']  = (_GET['cflag']==undefined?'':_GET['cflag']);
				
				pvCount1(PageConfig.loginUname,PageConfig.gameID);
				PvCount((_GET['gid'].isEmpty()?'xunlei':_GET['gid']),(_GET['cflag'].isEmpty()?'000':_GET['cflag']),PageConfig.loginUname,PageConfig.gameID);
				try{
					win=window.open(loginURL);
				}catch(e){}
				
				if(!win){
					document.location.href=loginURL;
				}
			}			
		}else{
			altMSG = SCONNET_MSG['CONNECTERR'];
		}
	}
	clsFun();//关闭服务器列表，有清空全部服务器的动作，
	showLoading(false);
	if(!altMSG.isEmpty()){
		alert(altMSG);
		if(altMSG==SCONNET_MSG['CONNECTERR']){
			showPanel(PageConfig.maskDiv,true);
			document.location.reload();
		}
	}
}


//用户登陆
function login(){
  var uname = $(PageConfig.usernameTxt).value;
  var pwd   = $(PageConfig.userpwdTxt).value;
  var vcode = $(PageConfig.vcodeTxt).value;  
  
  var selT  = PageConfig.usernameTxt;
  var vResult='';

  if(uname.isEmpty()){
	  vResult='用户名、密码不能为空!\n';
  }else if(pwd.isEmpty()){
	  selT  = PageConfig.userpwdTxt;
	  vResult='用户名、密码不能为空!\n';
  }else if(vcode.isEmpty()){
	  selT  = PageConfig.vcodeTxt;
      vResult='验证码不得为空!\n';
  }

  if(vResult){
	  alert(vResult);
	  try{
			$(selT).focus();
	  }catch(e){}
	  return;
  }else{
	  UserLogin.loginURL=PageConfig.loginURL;
	  seeds = getRandomizChar();
	  PageConfig.loginType = 0;
	  PageConfig.loginGameSURL = '';
	  PageConfig.loginGameSID  = -1;
	  
	  UserLogin.login(uname,pwd,vcode,seeds,PageConfig.gameID);		//加入seeds防止缓存

	  PageConfig.loginUname=uname;
  }
}

//设置xml代理
function setAgent(){
	PageConfig.loginNewSvrs = $(PageConfig.loginNewSvrsI);
	var ureged=UserLogin.getCookie(PageConfig.newUserCook); 

	var frm=$(PageConfig.frmProxyAgent);
	if(!frm) return;
	if(frm.readyState=='complete'){
		if(frm.contentWindow.remoteProxy){
			UserLogin.initialize(frm.contentWindow.remoteProxy);				
			//验证登陆状态
			UserLogin.loginURL = PageConfig.loginURL;
	        UserLogin.validURL = PageConfig.validURL;

			UserLogin.onBeforeValid = beforeValid;
	        UserLogin.onAfterValid  = afterValid;
			if(!ureged.isEmpty() || PageConfig.newUser){
				showUserInfoPanel(0,1);
				return;
			}else{
				UserLogin.validLoginCache(PageConfig.gameID);
			}
		}else{
//            alert('创建对象失败!');	
		}
	}
}

//设置xml代理
function setAgentF(){
	PageConfig.loginNewSvrs = $(PageConfig.loginNewSvrsI);
	var ureged=UserLogin.getCookie(PageConfig.newUserCook); 

	if(PageConfig.isIE){
		return false;
	}
	var frm=$(PageConfig.frmProxyAgent);	
	if(!frm) return;
	var objW = frm.contentWindow;
	if(objW){
		if(objW.window.remoteProxy){
			UserLogin.initialize(objW.window.remoteProxy);

			//验证登陆状态
			UserLogin.loginURL = PageConfig.loginURL;
	        UserLogin.validURL = PageConfig.validURL;

			UserLogin.onBeforeValid = beforeValid;
	        UserLogin.onAfterValid  = afterValid;
			if(!ureged.isEmpty() || PageConfig.newUser){
				showUserInfoPanel(0,1);
				return;
			}else{
				UserLogin.validLoginCache(PageConfig.gameID);
			}
		}else{
  //          alert('创建对象失败!');	
		}
	}
}

//用户登陆前触发事件
function beforeLogin(){
	showLoading(true);
}

//HTML编码
function HTMLencode(str){	
	var obj=document.createElement('span');
	obj.innerText=str;
	return obj.innerHTML;
}

//登陆后触发事件
function afterLogin(sFlag){
	var altMsg='';
	//alert(sFlag);
	if(typeof(sFlag)=='object'){
		var retStr=sFlag.responseText;
		
		try{
			eval('var ret='+retStr);
		}catch(e){
			ret=null;

		}
		//验证登陆
		if(!ret){
		//验证失败
			altMsg=UVALID_MSG[5];
			reloadImg();
			showLoading(false);
		}else{
			if(ret.loginStatus==0){
			//登陆验证成功
				//将用户名写入cookie
				UserLogin.setCookie(PageConfig.cookieLastUN,PageConfig.loginUname,PageConfig.cookieTimeOut);
				UserLogin.setCookie(UserLogin.cookieName,PageConfig.loginUname,PageConfig.cookieTimeOut);
				UserLogin.setCookie('_loginStatus_','1');//记录为已登录状态
				showUserInfoPanel(1);
				showLoading(false);
				initUserInfo();
				if(typeof(selfafterlogin)=='function'){
					selfafterlogin();
				}
				if(typeof(noServerList)!='undefine' && noServerList) showServerList(false);
				var lkPnl = $('linksarea');
				if(lkPnl){
					lkPnl.style.display = 'none';
				}
				try{
				if(PageConfig.loginType && PageConfig.loginGameSURL){
					return function(){
						gameLogin(PageConfig.loginGameSID,PageConfig.loginGameSURL);
						PageConfig.loginGameSID = -1;
						PageConfig.loginGameSURL = '';
					}
				}
				}catch(e){alert(e);}
			}else{
				//错误信息
				altMsg=UVALID_MSG[ret.loginStatus];
				if(altMsg.isEmpty()){
					altMsg=LANG['UNEXPECTEDERR'];
				}
				reloadImg();
				showLoading(false);
			}
			delete(ret);
		}
	}else{
		altMsg = LANG['UNEXPECTEDERR'];
		showLoading(false);
	}
	if(!altMsg.isEmpty()){
		alert(altMsg);
		if(PageConfig.loginType){
			showLoginPnl();
		}else{
			try{
				$(PageConfig.usernameTxt).focus();
			}catch(e){}
		}
	}
	
}


function addSpecialChar(v){
	v = v.replace(/\\/gi,'\\\\');
	v = v.replace(/\'/gi,"\\'");
	v = v.replace(/\"/gi,'\\"');
	return v;
}

function showLeftServers(){
	var serverP   = $(PageConfig.pnlUserserver);
	
	PageConfig.curServerPGNo = (PageConfig.curServerPGNo || 1);
	
	
	
	var totalPs  = Math.ceil(PageConfig.ServerList.length/PageConfig.gServerPerPg);
	serverP.innerHTML ='';

	
	//列当前页双线服务器列表
	var idxBeg = (PageConfig.curServerPGNo - 1) * PageConfig.gServerPerPg;
	var idxEnd = PageConfig.curServerPGNo * PageConfig.gServerPerPg;
	
	if(idxEnd >= PageConfig.ServerList.length){
		idxEnd = PageConfig.ServerList.length;
	}
	
	for(var i=idxBeg;i<idxEnd;i++){
		var o = document.createElement('li');
		var al = document.createElement('a');
		al.href = "#";
		al.innerHTML = PageConfig.ServerList[i]['servername'];
		o.appendChild(al);
		
		var func = new Function('return false;');
		if(PageConfig.ServerList[i]['inuse']){
			o.onclick = new Function("gameLogin('"+String(PageConfig.ServerList[i]['serverid'])+"','"+String(PageConfig.ServerList[i]['serveraddress'])+"');return false;");
		}else{
			o.onclick = func;
		}
		
		serverP.appendChild(o);
	}
	
	var pger = $('server_pager');   //服务器列表翻页
	pger.innerHTML = '';
	//初始化翻页
	if(totalPs<=0){
			return ;
	}
	if(pger){	
		pger.innerHTML ='';
	}
	//显示翻页
	var pgHTML = '';
	if(PageConfig.curServerPGNo<=1){
		pgHTML +='<a href="#" onclick="return false;">&lt;&lt;</a>';
	}else{
		pgHTML +='<a href="#" onclick="PageConfig.curServerPGNo--;showLeftServers();return false;">&lt;&lt;</a>';
	}
	for(var i=0;i<totalPs;i++){
		if(i+1==PageConfig.curServerPGNo){
			pgHTML +='<a href="#" onclick="return false;">'+String(i+1)+'</a>';
		}else{
			pgHTML += '<a href="#" onclick="PageConfig.curServerPGNo='+(i+1)+';showLeftServers();return false;">'+String(i+1)+'</a>';
		}
	}
	if(PageConfig.curServerPGNo>=totalPs){
		pgHTML +='<a href="#" onclick="return false;">&gt;&gt;</a>';
	}else{
		pgHTML +='<a href="#" onclick="PageConfig.curServerPGNo++;showLeftServers();return false;">&gt;&gt;</a>';
	}
	
	pger.innerHTML = pgHTML;
}

function initRecomServers(){
	var serListPnl = $(PageConfig.gameListPnl);
	if(!serListPnl){return;}
	
	var lastLoginSid = UserLogin.getCookie(PageConfig.lastSvrCk+'_'+PageConfig.gameID+'_'+PageConfig.loginUname);
	var gid       = PageConfig.gameID;
	var gul =  $(PageConfig.gameListPnlL);
	$('showAllBtn').style.display = 'block';
	$('clpnlbtn_2').style.display = 'block';
	$('allServerList').style.display = 'none';
	$('quanbu_fw_img').style.display = 'none';
	$(PageConfig.gameListPnlL1).innerHTML = '';
	var ul = document.createElement('ul');
	$(PageConfig.gameListPnlL1).appendChild(ul);
	var ServerInfo = [];
	ServerInfo = getRecommendServerInfo();
	for(var i=0;i<ServerInfo.length;i++){
		var li = document.createElement('li');
		var sid  = ServerInfo[i]['serverid'];
		var surl = ServerInfo[i]['serveraddress'];
		var imgURL = 'http://img.yx.xunlei.com/images/icon_02.png';
		var altInfo = '服务器开启';
		var label = document.createElement('label');
		if (ServerInfo[i]['status']==-1 || ServerInfo[i]['status']==1){
			label.innerTHML = '服务器维护';
			label.className='weihu_fw';
		}else if (sid==lastLoginSid){
			label.innerTHML = '我的服务器';
			label.className='login_fw';
		}else if (ServerInfo[i]['isnew']==1){
			label.innerTHML = '新开服务器';
			label.className='new_fw';
		}
		li.appendChild(label);
		var la = document.createElement('a');
		la.href="#";
		
		if(ServerInfo[i]['status'] == 0){
			imgURL = 'http://img.yx.xunlei.com/images/icon_01.png';
			altInfo = '空闲';
		}else if(ServerInfo[i]['status'] == 2){
			imgURL = 'http://img.yx.xunlei.com/images/icon_02.png';
			altInfo = '繁忙';
		}else if(ServerInfo[i]['status'] == 3){
			imgURL = 'http://img.yx.xunlei.com/images/icon_03.png';
			altInfo = '拥挤';
		}
		
		var remark = ServerInfo[i]['remark'];
		
		var lk = document.createElement('a');
		la.innerHTML = ServerInfo[i]['servername'];
		
		var pp = document.createElement('p');
		pp.className = 'p1';
		
		var lkHTML = ServerInfo[i]['servername'];
		//标红
		if(ServerInfo[i]['redtitle']){
			lkHTML = '<img src="' +imgURL+ '" alt ="' +altInfo+ '" /><span class="sname">' + lkHTML + '</span>';
		}else{
			lkHTML = '<img src="' +imgURL+ '" alt ="' +altInfo+ '" />' + lkHTML ;
		}
		
		pp.innerHTML = lkHTML;
		lk.appendChild(pp);
		
		
		var p = document.createElement('p');
		p.innerHTML = '在线';
		p.className = 'p2';
		p.innerHTML += '<em>' + (ServerInfo[i]['online']==-1?'未知':ServerInfo[i]['online']) + '</em>';
		lk.appendChild(p);
		
		var func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+'return false;');
		li.appendChild(lk);
		try{
			if(ServerInfo[i]['inuse']){
					func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+"gameLogin('"+String(sid)+"','"+String(surl)+"');return false;");
			}else{
					func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+'return false;');
			}
		}catch(e){}
		li.onclick = func;
		ul.appendChild(li);
	}
}
function getRecommendServerInfo(){
	var ServerInfo = [];
	var recommendServerInfo = [];
	try{
		ServerInfo = webgameRecommendGameServers;
	}catch(e){ServerInfo = [];}
	var lastLoginSid = UserLogin.getCookie(PageConfig.lastSvrCk+'_'+PageConfig.gameID+'_'+PageConfig.loginUname);
	if (lastLoginSid){
		recommendServerInfo[recommendServerInfo.length] = getServerInfo(lastLoginSid);
	}
	for(var i=0;i<ServerInfo.length && recommendServerInfo.length<3;i++){
	  if(ServerInfo[i]['serverid'] == lastLoginSid){
		continue;
	  }
	 recommendServerInfo[recommendServerInfo.length] = ServerInfo[i];
	}
	return recommendServerInfo;
}
function showAllServerList(){
	var ServerInfo = [];
	var lastLoginSid = UserLogin.getCookie(PageConfig.lastSvrCk+'_'+PageConfig.gameID+'_'+PageConfig.loginUname);
	var gid       = PageConfig.gameID;
	try{
		ServerInfo = webgameSingleGameServers;
	}catch(e){ServerInfo = [];}
	
	var serListPnl = $(PageConfig.gameListPnl);
	if(!serListPnl){return;}
	initRecomServers();
	$(PageConfig.gameListPnlL).innerHTML = '';
	$('showAllBtn').style.display = 'none';
	$('clpnlbtn_2').style.display = 'none';
	$('allServerList').style.display = 'block';
	$('quanbu_fw_img').style.display = 'block';
	var gul = document.createElement('ul');
	$(PageConfig.gameListPnlL).appendChild(gul);
	for(var i=0;i<ServerInfo.length;i++){
		var li = document.createElement('li');
		var sid  = ServerInfo[i]['serverid'];
		var surl = ServerInfo[i]['serveraddress'];
		var imgURL = 'http://img.yx.xunlei.com/images/icon_02.png';
		var altInfo = '服务器开启';
		var label = document.createElement('label');
		if (ServerInfo[i]['status']==-1 || ServerInfo[i]['status']==1){
			label.innerTHML = '服务器维护';
			label.className='weihu_fw';
		}else if (sid==lastLoginSid){
			label.innerTHML = '我的服务器';
			label.className='login_fw';
		}else if (ServerInfo[i]['isnew']==1){
			label.innerTHML = '新开服务器';
			label.className='new_fw';
		}
		li.appendChild(label);
		var la = document.createElement('a');
		la.href="#";
		
		if(ServerInfo[i]['status'] == 0){
			imgURL = 'http://img.yx.xunlei.com/images/icon_01.png';
			altInfo = '空闲';
		}else if(ServerInfo[i]['status'] == 2){
			imgURL = 'http://img.yx.xunlei.com/images/icon_02.png';
			altInfo = '繁忙';
		}else if(ServerInfo[i]['status'] == 3){
			imgURL = 'http://img.yx.xunlei.com/images/icon_03.png';
			altInfo = '拥挤';
		}
		
		var remark = ServerInfo[i]['remark'];
		
		var lk = document.createElement('a');
		la.innerHTML = ServerInfo[i]['servername'];
		
		var pp = document.createElement('p');
		pp.className = 'p1';
		
		var lkHTML = ServerInfo[i]['servername'];
		//标红
		if(ServerInfo[i]['redtitle']){
			lkHTML = '<img src="' +imgURL+ '" alt ="' +altInfo+ '" /><span class="sname">' + lkHTML + '</span>';
		}else{
			lkHTML = '<img src="' +imgURL+ '" alt ="' +altInfo+ '" />' + lkHTML ;
		}
		
		pp.innerHTML = lkHTML;
		lk.appendChild(pp);
		
		
		var p = document.createElement('p');
		p.innerHTML = '在线';
		p.className = 'p2';
		p.innerHTML += '<em>' + (ServerInfo[i]['online']==-1?'未知':ServerInfo[i]['online']) + '</em>';
		lk.appendChild(p);
		
		var func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+'return false;');
		li.appendChild(lk);
		try{
			if(ServerInfo[i]['inuse']){
					func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+"gameLogin('"+String(sid)+"','"+String(surl)+"');return false;");
			}else{
					func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+'return false;');
			}
		}catch(e){}
		li.onclick = func;
		gul.appendChild(li);
	}
}
function renderServerList(){
	var serListPnl = $(PageConfig.gameListPnl);
	if(!serListPnl){return;}
	serListPnl.innerHTML = '';
	var c='';
	c+='<h2><span><a href="#" id="addGameFav"><img src="http://img.yx.xunlei.com/images/sc_game_btn.gif" alt="收藏游戏" /></a>';
	c+='<a href="http://yx.xunlei.com/down/yingxiong.exe" id="addShortCut" onclick="setHome(this,\'http://yx.xunlei.com\')" target="_blank"><img src="http://img.yx.xunlei.com/images/zuomian_btn.gif" alt="添加桌面排行榜" /></a></span>';
	c+='<img src="http://img.yx.xunlei.com/images/tuijian_fw.png"  alt="推荐服务器"/></h2>';
	c+='<div class="item" id="gmlistUL1"></div>';
	c+='<div class="d-btns"><a href="#" id="showAllBtn" class="qb_fw"></a><a href="#" id="clpnlbtn_2" class="close">关闭</a><img src="http://img.yx.xunlei.com/images/quanbu_fw.png" alt="全部服务器" id="quanbu_fw_img" style="disaplay:none" class="fl"/><img src="http://img.yx.xunlei.com/images/intro.gif" alt=""  class="intro"/> </div>';
	c+='<div id="allServerList" style="display:none"><div class="item" id="gmlistUL"></div>';
	c+= '<div class="d-btns" id="allBtns"><img src="http://img.yx.xunlei.com/images/fw_intro.gif" alt="" /><br /><br /><a href="#" class="close" id="clpnlbtn_1">关闭</a></div></div>';
	c+= '<a href="#" class="a-close" id="clpnlbtn" title="关闭">关闭</a>';
	serListPnl.innerHTML = c;
	$('showAllBtn').onclick=function(){showAllServerList();return false;}
	$(PageConfig.GameAddFav).onclick=function(){myAddBookmark(document.title,document.location.href);return false;}
	$(PageConfig.gamePnlcloser).onclick = clsFun;
	$(PageConfig.gamePnlcloser1).onclick = clsFun;
	$(PageConfig.gamePnlcloser2).onclick = clsFun;
}
function initServerList(){
	var ServerInfo = [];
	var lastLoginSid = UserLogin.getCookie(PageConfig.lastSvrCk+'_'+PageConfig.gameID+'_'+PageConfig.loginUname);
	var gid       = PageConfig.gameID;
	
	try{
		ServerInfo = webgameSingleGameServers;
	}catch(e){ServerInfo = [];}
	
	
	PageConfig.newServerList = [];
	PageConfig.ServerList    = [];
	PageConfig.logNewSvrArr  = []; //登陆框中服务器列表
	
	var serverP   = $(PageConfig.pnlUserserver);
	var servernewP   = $(PageConfig.pnlUsernewserver);
	var serListPnl = $(PageConfig.gameListPnl);
	//serListPnl.innerHTML = '';//清除原来的内容
	serverP.innerHTML = '';   //清除原来的内容
	servernewP.innerHTML = '';   //清除原来的内容
	PageConfig.SvrIDInfo = {};
	for(var i=0;i<ServerInfo.length;i++){
		PageConfig.SvrIDInfo[ServerInfo[i]['serverid']] = ServerInfo[i];
		var sid  = ServerInfo[i]['serverid'];
		var surl = ServerInfo[i]['serveraddress'];
		var isNew = false;
		var li = document.createElement('li');
		var lli;
		var lla;
		if(PageConfig.logNewSvrArr.length<5){
			lli = document.createElement('li');
			lla = document.createElement('a');
			lla.href = '#';
			lla.innerHTML = ServerInfo[i]['servername'];
			lli.appendChild(lla);
			PageConfig.logNewSvrArr.push(lli);
		}
		var remark = ServerInfo[i]['remark'];
		var func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+'return false;');
		try{
			if(ServerInfo[i]['inuse']){
					func = new Function((remark?"alert('"+addSpecialChar(remark)+"');":"")+"gameLogin('"+String(sid)+"','"+String(surl)+"');return false;");
			}else{
			}
		}catch(e){}
		if(lli){
			lli.onclick = func;
		}
		PageConfig.newServerList.push(ServerInfo[i]);
		PageConfig.ServerList.push(ServerInfo[i]);
	}
	initRecomServers();
	showLoginNewServer();
	PageConfig.curServerPGNo = 1;
	showLeftServers();
	showNewOpenAreas();
}

//显示最新开区列表
function showNewOpenAreas(){
	var servernewP   = $(PageConfig.pnlUsernewserver);
	servernewP.innerHTML = '';
	//最新开	
	PageConfig.newServerList.sort(sortServerList);
	for(var i=0;(i<PageConfig.newServerList.length && i<8);i++){
		var lli = document.createElement('li');
		var fuc = new Function('return false;');
		if(PageConfig.newServerList[i]['inuse']){
			fuc = new Function("gameLogin('"+String(PageConfig.newServerList[i]['serverid'])+"','"+String(PageConfig.newServerList[i]['serveraddress'])+"');return false;");
		}
		lli.onclick = fuc;
		var a = document.createElement('a');
		a.href = 'javascript:///';
		a.target = '_self';
		a.innerHTML = PageConfig.newServerList[i]['servername'];		
		a.onclick = function(){return false;}
		lli.appendChild(a);
		
		servernewP.appendChild(lli);
	}
}

//显示新开服务器列表
function showLoginNewServer(){
	PageConfig.loginNewSvrs.innerHTML = '';	
	var til = $('loginedServerTil');
	if(PageConfig.loginedSvrs.length>0){
		if(til){
			til.innerHTML = '您目前所在服务器';
		}
		for(var i=0;(i<PageConfig.loginedSvrs.length && i<5);i++){
			if(!PageConfig.loginedSvrs[i]){
				continue;
			}
			var sinfo = getServerInfo(PageConfig.loginedSvrs[i]);
			var sid  = sinfo['serverid'];
			var surl = sinfo['serveraddress'];
			var snam = sinfo['servername'];
			
			var a = document.createElement('a');
			var li = document.createElement('li');
			li.appendChild(a);
			a.href = '#';
			a.innerHTML = snam;
			
			var func = new Function('return false;');
			if(sinfo['inuse']){
				func = new Function('gameLogin("'+sid+'","'+surl+'");return false;');
			}
			//alert(func);
			li.onclick = func;
			PageConfig.loginNewSvrs.appendChild(li);
		}
	}else{
		if(til){
			til.innerHTML = '新开服务器';
		}
		for(var i=0;i<PageConfig.logNewSvrArr.length;i++){
			PageConfig.loginNewSvrs.appendChild(PageConfig.logNewSvrArr[i]);
		}
	}
}

//登陆后初始化用户信息面板
function initUserInfo(f){
	var gid       = PageConfig.gameID;
	var ObjGINFO  = null;
	
	if(PageConfig.isIE){
		$(PageConfig.pnlUsername).innerText=PageConfig.loginUname;
	}else{
		$(PageConfig.pnlUsername).textContent=PageConfig.loginUname;
	}
	
	initLoginedSvr();
	if(!PageConfig.loginType){
		initServerList();
	}
	if (f!==false && !PageConfig.loginType) {
		showServerList();
	}
}


//验证登陆状态前触发事件
function beforeValid(){
	UserLogin.setCookie('_loginStatus_','0');//初始化为未登录状态
	showUserInfoPanel(0,0,1);
}

//验证登陆状态后触发事件
function afterValid(sFlag){
	var  ureged = '';		
	if(typeof(sFlag)!='object'){		
		 ureged = UserLogin.getCookie(PageConfig.cookieLastUN);
		 setUserName();
		 //$(PageConfig.usernameTxt).value = ureged?ureged:PageConfig.USER_NAME;
		showUserInfoPanel(0,1);
		if (_GET['slogin']!=undefined){
			  showLoginPnl(true);
		 }
	}else{
		try{
			var retStr=sFlag.responseText;
			eval('var ret='+retStr);
		}catch(e){
			ret=null;
		}
        if(!ret){
		  showUserInfoPanel(0,1);
		  ureged = UserLogin.getCookie(PageConfig.cookieLastUN);
		  setUserName();
		 // $(PageConfig.usernameTxt).value = ureged?ureged:PageConfig.USER_NAME;
          return false;
        }else if(ret.loginStatus == 0){
		  //验证成功
		  PageConfig.loginUname = UserLogin.getCookie(UserLogin.cookieName);
		  UserLogin.setCookie(PageConfig.cookieLastUN,PageConfig.loginUname,PageConfig.cookieTimeOut);	
		  UserLogin.setCookie('_loginStatus_','1');//记录登录状态
		  if(UserLogin.getCookie('_def_showServer')=='1'){
			  initUserInfo(true);
			  showUserInfoPanel(1);
			  showServerList(true);
			  UserLogin.setCookie('_def_showServer','');
		  }else{			  
			  initUserInfo(false);
			  showUserInfoPanel(1);          
		  }
		  var lkPnl = $('linksarea');
		  if(lkPnl){
				lkPnl.style.display = 'none';
		  }
		}else{
		  showUserInfoPanel(0,1);
		  //ureged = UserLogin.getCookie(PageConfig.cookieLastUN);
		  setUserName();//$(PageConfig.usernameTxt).value = ureged?ureged:PageConfig.USER_NAME;
		  if (_GET['slogin']!=undefined){
			  showLoginPnl(true);
		  }
          return false;
		}
	}
}

// 显示\隐藏用户信息面板
function showUserInfoPanel(){
	var l = arguments.length;
	var panels=[PageConfig.pnlUser,PageConfig.pnlLogin,PageConfig.pnlLoading];

	for(var i=0;i<panels.length;i++){
		if(i<l){
			showPanel(panels[i],(arguments[i]?true:false));		
			if(panels[i]==PageConfig.pnlLogin && arguments[i]){
				$(PageConfig.usernameTxt).focus();
				setUserName();
			}
		}else{
			showPanel(panels[i],false);
		}		
	}
}

//重新载入验证码
function reloadImg(){
	/*
	var vimg  = $(PageConfig.validImg);

	if(!vimg) return;

	var sURL  = PageConfig.validPic;
    vimg.src=sURL+getRandomizChar();
	*/
	loadVCode();
	$(PageConfig.vcodeTxt).value = '';
}

function getRandomizChar(){
	var str='';
	var i=Math.ceil(Math.random()*10);
	for(var j=0;j<i;j++){
	  str+=String.fromCharCode(97+Math.ceil(Math.random()*25));
	}
	return str;
}



function showLoading(flag){
	showPanel(PageConfig.maskDiv,flag);	
	showPanel(PageConfig.loadingBar,flag);

	if(!PageConfig.isIE && flag){
		var mask = $(PageConfig.maskDiv);
		if(mask){
			mask.style.width  = document.body.scrollWidth.toString()+'px';
			mask.style.height = document.body.scrollHeight.toString()+'px';
		}
		var bar  = $(PageConfig.loadingBar);
		if(bar){
			//bar.style.left = '100px';
			//centerPnl(bar);
			bar.style.left = String(Math.floor((document.body.offsetWidth - bar.offsetWidth)/2))+'px';
			bar.style.top  = '200px';
		}
	}else if(flag){
		var bar  = $(PageConfig.loadingBar);
		if(bar){
			//bar.style.left = '100px';
			//centerPnl(bar);
			bar.style.left = String(Math.floor((document.body.offsetWidth - bar.offsetWidth)/2))+'px';
			bar.style.top  = '200px';
		}
	}
}


//PV统计
function PvCount(unid,cflag,uname,gid){
	
	if(gid==undefined || !gid){		
		var PV_URL=PageConfig.pvURL;
		PV_URL+= '?uid='+unid+'&utype='+cflag+'&uname='+uname+'&gameid='+PageConfig.gameID;
	}else{
		var PV_URL=PageConfig.pvURL1;
		PV_URL+= '?uid='+unid+'&utype='+cflag+'&uname='+uname+'&gameid='+gid;
	}
	var pvImg=$(PageConfig.pvImg).src=PV_URL;
}

function pvCount1(un,gid){
	if(gid){
		var pvURL = PageConfig.pvURL2 + "?";
	}else{
		var pvURL = PageConfig.pvURL3 + "?";
	}
	script = document.createElement('script');
	document.getElementsByTagName('head')[0].appendChild(script);

	var advid = _GET['advid'];
	if(advid){
		pvURL +='advid=' + encodeURIComponent(advid)+'&';
	}
	pvURL +='uname=' + encodeURIComponent(un)+'&';

	if(gid){
		pvURL +='gameid=' + encodeURIComponent(gid);
	}

	pvURL += '&'+String(Date.parse(new Date()));
	script.src=pvURL;

}

function setTableInfo(idx){
	//var th = $('phth');
	var td = $('phtd');
	idx = (idx || 0);
	var varIndex = ['rank_roles_level'];
	var hdIdx = ['rank','role_name','skill_class','gradation','level'];

	if(td){
		while(td.rows.length>0){
			td.deleteRow(0);
		}
		if(typeof(heroRanksJsonData)!='undefined'&&heroRanksJsonData[varIndex[idx]]){
			var data = heroRanksJsonData[varIndex[idx]];
			for(var i=0;i<data.length;i++){
				var tr = td.insertRow(-1);

				for(var j=0;j<hdIdx.length;j++){
					var tc = tr.insertCell(-1);
					tc.innerHTML = (data[i][hdIdx[j]] || '');
				}
			}
		}else{
			showMsg('<font color="#ff0000">数据不存在!</font>');
			//$('div_loadingp').style.display = 'block';
			//$('div_loadingp').innerHTML = '<font color="#ff0000">数据不存在!</font>'
			//$('phtd').innerHTML = '<tr><td colspan="5"><font color="#ff0000">数据不存在!</font></td><tr>'
		}
	}
}

function showLoginPnl(flag){	
	flag = (flag===undefined?true:flag);
	showPanel(PageConfig.maskDiv,flag);
	if(PageConfig.floatLoginPnl){
		PageConfig.floatLoginPnl.style.display = flag?'block':'none';		
	}else{
		//alert(PageConfig.floatLoginPnl);
	}
	if(flag){
		centerPnl(PageConfig.floatLoginPnl);
		/*
		$('lgvcode').value = '';
		$('lgpassword').value = '';
		*/
		setVerifyCode($('vcImg'));
		loadVCode('vcImg');
	}else{
		reloadImg();
	}
}

function pnlLogin(){
	
}


function setPH(){		
	var loadingPnl = $('phtd');
	//var contentPnl = $('div_phb');
	var tableC     = $('tb_content');
	if(!loadingPnl||!tableC)return;
	/*if(contentPnl){
		tableC.style.display = contentPnl.style.display = 'none';
	}else{
		alert('noneObje');
	}*/
	if(loadingPnl){
		showMsg('<font color="#ff0000">数据载入中... ...</font>');
		//loadingPnlinnerHTML = '<tr><td colspan="5"><font color="#ff0000">数据载入中... ...</font></td></tr>';
	}

	var scrName = ['rank_roles_level'];

	var sI = (setPH['selIndex'] || 0);
	var sA = $('gserverLists').value;
	if(isNaN(sA)){sA=1;}
	var jsURL = 'http://yingxiongsvr'+sA+'.webgame.xunlei.com/data/' + scrName[sI] + '.js?'+Date.parse(new Date());
	loadJs(jsURL,function(){setTableInfo(sI)});	
}
function setPH_init(){		
	var loadingPnl = $('phtd');
	//var contentPnl = $('div_phb');
	var tableC     = $('tb_content');
	if(!loadingPnl||!tableC)return;
	/*if(contentPnl){
		tableC.style.display = contentPnl.style.display = 'none';
	}else{
		alert('noneObje');
	}*/
	if(loadingPnl){
		showMsg('<font color="#ff0000">数据载入中... ...</font>');
		//loadingPnlinnerHTML = '<tr><td colspan="5"><font color="#ff0000">数据载入中... ...</font></td></tr>';
	}
	
	var scrName = ['rank_roles_level'];
	
	var sI = (setPH['selIndex'] || 0);
	if ($('gserverLists').options.length > 1){
		$('gserverLists').value = $('gserverLists').options[1].value; 
	}
	var sA = $('gserverLists').value;
	if(isNaN(sA)){sA=1;}
	var jsURL = 'http://yingxiongsvr'+sA+'.webgame.xunlei.com/data/' + scrName[sI] + '.js?'+Date.parse(new Date());
	loadJs(jsURL,function(){setTableInfo(sI)});	
}

function showMsg(msg){
	var td = $('phtd');
	while(td.rows.length>0){
		td.deleteRow(0);
	}
	var tr = td.insertRow(-1);
	var tc = tr.insertCell(-1);
	tc.innerHTML = msg;
}
function loadJs(url,fun){
	var randSCID = 'dQFasdfqwe08wfa';
	var jsL;
	var orsc = function(){
		if(this.getAttribute('readyState')=='loaded'){
			//$('div_loadingp').style.display = 'none';
			//$('tb_content').style.display = $('div_phb').style.display = '';
			if(fun){fun();}
		}
	}

	if(!jsL){
		jsL = document.createElement('script');
		jsL.setAttribute('testID',randSCID);
		jsL.setAttribute('charset','utf-8');
		jsL.setAttribute('type','text/javascript');		
	}

	jsL.setAttribute('src',url);
	
	if(PageConfig.isIE){
		jsL.onreadystatechange = function(){orsc.apply(jsL,[])};
	}else{
		jsL.setAttribute('readyState','loaded');
		//jsL.addEventListener('load',function(){orsc.apply(jsL,[])},false);
		//jsL.addEventListener('error',function(){$('div_loadingp').style.display = 'none';$('div_phb').style.display = '';alert('网络链接中断!');},false);
		
		jsL.onload = function(){orsc.apply(jsL,[])};
		jsL.onerror = function(){
		//$('div_loadingp').style.display = '';
		//$('tb_content').style.display = $('div_phb').style.display = 'none';
		//$('div_loadingp').innerHTML = '<font color="#ff0000">网络链接中断!</font>';};
			showMsg('<font color="#ff0000">网络链接中断!</font>');
		//$('phtd').innerHTML = '<tr><td colspan="5"><font color="#ff0000">网络链接中断!</font></td></tr>';};
		}
	}
	document.getElementsByTagName('head')[0].appendChild(jsL);
}

//添加收藏夹
function myAddBookmark(title,url){
	//alert(title+'-'+url);
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)){
		try{
		 window.external.AddFavorite(url,title);
		 }catch(e){}
	}else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')){
		//Gecko
        window.sidebar.addPanel(title,url,"");
    }
}
function setHome(obj,url){
			try{
				obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
			}
			catch(e){
				if(window.netscape) {
					try {
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					}
					catch (e) {
						alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
					}
					try {
						var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
						prefs.setCharPref('browser.startup.homepage',url);
					}catch (e) {}
				 }
			}
}

function initPhb(){
	//var objGLTab = $('gjgl_t1');
	//var objPHTab = $('gjgl_t2');
	var objServers = $('gserverLists');
	if(!objServers)return;
	if(objServers){
		objServers.options.length = 0;
	}

	if(webgameSingleGameServers){
		for(var i=0;i<webgameSingleGameServers.length;i++){
			var od = webgameSingleGameServers[i];
			objServers.options[objServers.options.length] = new Option(od['servername'],od['serverid']);
		}
	}

	objServers.onclick = function(){
		if(this.disabled){
			return false;
		}
	}
	objServers.onchange = function(){
		setPH();
	}

	/*objGLTab.onclick = function(){
		this.blur();
		if(this.className == 'a_gjglup'){return false;}
		this.className = 'a_gjglup';
		var obj1  = $('gjgl_t2');
		var obj1d = $('gjgl_t2_d');
		var obj2d = $('gjgl_t1_d');
		if(obj1){
			obj1.className = 'a_yxphb';
			if(obj1d){
				obj1d.style.display = 'none';
			}
			if(obj2d){
				obj2d.style.display = '';
			}
		}
		return false;
	}*/
	/*objPHTab.onclick = function(){
		this.blur();
		if(this.className == 'a_yxphbup'){return false;}
		this.className = 'a_yxphbup';
		var obj1  = $('gjgl_t1');
		var obj1d = $('gjgl_t1_d');
		var obj2d = $('gjgl_t2_d');
		if(obj1){
			obj1.className = 'a_gjgl';
			if(obj1d){
				obj1d.style.display = 'none';
			}
			if(obj2d){
				obj2d.style.display = '';
			}
		}
		return false;
	}*/
	
	var tagPrefix = 'ptb_';
	for(var i=0;i<1;i++){
		var fStr = 'this.blur();setPH["selIndex"]='+i+';if(this.className=="up"){return false;}for(var i=0;i<3;i++){if(i!='+i+'){$("'+ tagPrefix + '"+i).className=""}this.className="up"} setPH();return false;';
		var f= new Function(fStr);
		var o = $(tagPrefix+''+i);
		if(o){
			o.onclick = f;
		}
	}
}

function pnlLogin(){
  var uname = $('lguname').value;
  var pwd   = $('lgpassword').value;
  var vcode = $('lgvcode').value;
  
  var selT  = 'lguname';
  var vResult='';

  if(uname.isEmpty()){
	  vResult='用户名、密码不能为空!\n';
  }else if(pwd.isEmpty()){
	  selT  = 'lgpassword';
	  vResult='用户名、密码不能为空!\n';
  }else if(vcode.isEmpty()){
	  selT  = 'lgvcode';
      vResult='验证码不得为空!\n';
  }

  if(vResult){
	  alert(vResult);
	  try{
			$(selT).focus();
	  }catch(e){}
	  return;
  }else{
	  UserLogin.loginURL=PageConfig.loginURL;
	  seeds = getRandomizChar();
	  showLoginPnl(false);
	  PageConfig.loginType = 1;                     //设置面板登陆
	  UserLogin.login(uname,pwd,vcode,seeds,PageConfig.gameID);		//加入seeds防止缓存
	  PageConfig.loginUname=uname;
  }
}


function centerPnl(pnl){
	var o = $(pnl);
	if(o){
		o.style.left = String(Math.floor((document.body.offsetWidth - o.offsetWidth)/2))+'px';
		o.style.top  = '100px';
		if(document.documentElement){
			document.documentElement.scrollTop = '0px';
		}else{
			document.body.scrollTop = '0px';
		}
	}
}

function sortServerList(x,y){
	var str = '';
	for(var o in x){
		str += o + '=' + x[o];
	}
	return y['seqid'] - x['seqid'];
}

function initLoginedSvr(){
	//alert(PageConfig.loginedSvrCK+'_'+PageConfig.gameID+'_'+PageConfig.loginUname);
	var str = decodeURIComponent(UserLogin.getCookie(PageConfig.loginedSvrCK+'_'+PageConfig.gameID+'_'+PageConfig.loginUname));	
	//alert(str);
	PageConfig.loginedSvrs = [];
	if(str.indexOf('|')>0 && str.trim()!='|'){
		PageConfig.loginedSvrs = str.split('|');
	}else if(!isNaN(str) && str){
		PageConfig.loginedSvrs = [str];
	}
}

function getServerInfo(sid){	
	var ServerInfo = [];
	try{
		ServerInfo = webgameSingleGameServers;
	}catch(e){
		ServerInfo = [];
	}
	var ret = {};
	for(var i=0;i<ServerInfo.length;i++){
		if(String(ServerInfo[i]['serverid'])==String(sid)){
			ret = ServerInfo[i];			
			break;
		}
	}
	return ret;
}

function loadVCode(id){
	id = (id || PageConfig.validImg);
	var o = $(id);
	if(o){
		o.style.visibility = 'hidden';
		if(PageConfig.isIE){
			o.onreadystatechange = function(){
				if(o.readyState=='complete'){
					o.style.visibility = 'visible';
				}
			}
		}else{
			o.onload = function(){
				o.style.visibility = 'visible';
			}
		}
		var sURL  = PageConfig.validPic + String(Date.parse(new Date()));
		o.setAttribute('src',sURL);
	}
}

function setLoginedSid(sid){
	if(isNaN(sid) || !sid){
		return;
	}
	var str = decodeURIComponent(UserLogin.getCookie(PageConfig.loginedSvrCK+'_'+PageConfig.gameID+'_'+PageConfig.loginUname));
	if(str){
		if(str.indexOf(sid+'|')<0){
			str = sid + '|' + str;
		}
	}else{
		str = sid + '|';
	}
	UserLogin.setCookie(PageConfig.loginedSvrCK+'_'+PageConfig.gameID+'_'+PageConfig.loginUname,str);
}