﻿	/********************************************************************
	* 函数名:
	* getCookie
	*
	* 参数:
	* c_name  - Cookie名称
	*
	* 返回值:
	* Cookie内容
	* 
	* 说明:
	* 该函数获取Cookie用户上次登录方式
	********************************************************************/
	function getCookieVal(offset){
         var endstr = document.cookie.indexOf(";",offset);
         if (endstr == -1)
         {
                 endstr = document.cookie.length;
         }
         return unescape(document.cookie.substring(offset,endstr));
	}

	function getCookie(name){
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i= 0;
         while (i<clen)
         {
                 var j = i+alen;
                         if (document.cookie.substring(i,j) == arg)
                         {
                                 return getCookieVal(j);
                         }
                 i = document.cookie.indexOf(" ",i)+1;
                 if(i==0) break;
         }
         return null;
	}
	
	//function getCookie(c_name)
	//{
	//	if (document.cookie.length > 0)
	//	{
		// c_start = document.cookie.indexOf(c_name + "=")
		//if (c_start != -1)
	//	{ 
	//	c_start = c_start + c_name.length + 1;
	//	c_end   = document.cookie.indexOf(";",c_start);
	//	if (c_end == -1) 
	//	{
	//	 c_end = document.cookie.length;
	//	}
	//	return unescape(document.cookie.substring(c_start,c_end));
	//	} 
	//	}
	//	return null
	//}
	/********************************************************************
	* 函数名:
	* setCookie
	*
	* 参数:
	* c_name  - Cookie名称
	*   value  - Cookie内容
	*	   expiredays - Cookie日期
	*
	* 返回值:
	* 空
	* 
	* 说明:
	* 该函数设置Cookie保留用户上次登录方式
	********************************************************************/
	function setCookie(c_name,value,expiredays)
	{
 	var exdate = new Date();
 	exdate.setDate(exdate.getDate() + expiredays);
 	// 使设置的有效时间正确。增加toGMTString()
 	document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
	}

	function delCookie(name)//删除cookie
	{
		document.cookie="loginusername=";
		
		window.location.href=window.location.href;
		return;
		var exp = new Date();
		exp.setTime(exp.getTime() - 1);
		var cval=getCookie(name);
		//setCookie("loginusername",null);
		var cval=getCookie(name);
		//alert(cval);
		if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
	}
	function checklogin(){
	var objuser = document.getElementById('uid');
	var objpwd	 = document.getElementById('pwd');
	if(objpwd.value == '' ||　objuser.value == ''){
			alert('登陆帐号和密码不能为空');
			
		    return false;
	}else{
		document.form1.action="http://www.u966.com/api/authi/arealogin.php";
    	 document.form1.submit();
	}
	
	}
	
	function loginInput()
	{
		    
			str="<form style='margin:0;padding:0;' name='form1' action='' method='post'  onsubmit='return checklogin();'>";
			str+="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
			str+="<tr>";
			str+="<td width='13%' height='23'>&nbsp;</td>";
			str+="<td width='23%'>&nbsp;</td>";
			str+="<td width='64%'>&nbsp;</td>";
			str+="<input   type='hidden'  name='url' id='url' value='http://wdfs.u966.com/index.html'/>";
			str+="</tr>";
			str+="<tr>";
			str+="<td height='25'>&nbsp;</td>";
			str+="<td class='tiaowenzi' height='25'>用户名</td>";
            str+="<td height='25'><input type='text' class='input1' name='uid' id='uid' /></td>";
            str+="</tr>";
            str+="<tr>";
            str+="<td height='25'>&nbsp;</td>";
            str+="<td class='tiaowenzi' height='25'>密 码</td>";
            str+="<td height='25'><input type='password' class='input1' name='pwd' id='pwd' /></td>";
            str+="</tr>";
		//str+="<tr>";
			//str+="<td>&nbsp;</td>";
			//str+="<td class='tiaowenzi'>验证码</td>";
			//str+="<td height='20'><input type='text' class='input2' /></td>";
			//str+="<td height='20'><img src='code.php' onClick='this.src='code.php?rnd='+Math.random()' id='yan' /> </td>";
			//str+="</tr>";
			str+="<tr>";
			str+="<td height='45'>&nbsp;</td>";
			str+="<td height='48' colspan='2' valign='bottom'>";
			str+="<table width='90%' border='0' cellspacing='0' cellpadding='0'><tr><td width='50%' align='left'>";
			str+="<input type='image' src='http://img.u966.com/wdnew/images/btn1.jpg'  />";
			str+="</td><td width='50%' align='left'>";
			str+="<a href='http://www.u966.com/center/getmypassword'><img src='http://img.u966.com/wdnew/images/btn2.jpg' /></a>";
			str+="</A></td></tr></table>";
			str+="</td>";
			str+="</tr>";
			str+="</table>";
			str+="</form>";
			
		return str;
	}
	function loginMessage(obj)
	{		
			str=" <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
			str+="<tr>";      
			str+="<td width='7%' height='25'>&nbsp;</td>";
			str+="<td width='85%'>&nbsp;</td>";
			str+="<td width='8%'>&nbsp;</td>";
			str+="</tr>";
			str+=obj;
			str+="<tr>";
			str+="<td height='25'>&nbsp;</td>";
			str+="<td height='25' align='center' valign='bottom'><input type='image' src='http://img.u966.com/wdnew/images/login5.jpg'  onclick='linkgame()' />";
			str+="<input type='image' src='http://img.u966.com/wdnew/images/login6.jpg' onclick='avascript:logout()'/></td>";
			str+=" <td height='25' valign='bottom'>&nbsp;</td>";
			str+="</tr>";
			str+="</table>";
		
		return str;
	}
	function logout(){			
		document.cookie="u966_tg_login=;path=/;domain=.u966.com";		
		document.cookie="u966_tg_uid=;path=/;domain=.u966.com";
		window.location.reload();
		
	}
	//判断是否登录
	function isLogin()
	{
		var loginusername=getCookie("u966_tg_uid");
		
		var islogin=getCookie("u966_tg_login");
		
		//alert(loginusername);
		if (islogin != 1 || loginusername==null )
		{
			return false;
		}
		if (islogin != 1 || loginusername=="null")
		{
			return false;
		}	
		if (islogin != 1 || loginusername=="")
		{
			return false;
		}	
		
		return true;
	} 
	/* window.load = function() {
		var loginusername=getCookie("u966_tg_uid");		
		//alert(isLogin());

		if ( isLogin() && loginusername != null  )
		{
			document.getElementById('loginTd').innerHTML=loginMessage("欢迎您登录，<br>"+loginusername);
		}
		else
		{
			var str=loginInput();
			document.getElementById('loginTd').innerHTML = str;
		}
		//ServerRequest();
		
	}*/


	function linkgame(){
		var loginusername=getCookie("u966_tg_uid");	
		//alert(loginusername);
		if(isLogin() && loginusername != null  ){
		//	alert('loginusername');
		Getlist()
		//window.location.href="http://www.u966.com/game/gotogame/enter/27/120";
		}else{
			alert("请您先登录");
			return  false;
		}
	}


	function showLoginArea() {
		var loginusername=getCookie("u966_tg_uid");	
		var logingamearea=unescape(getCookie("u966_tg_areaname"));
		var logingamearea=unescape(getCookie("u966_tg_areaname"));
		var loginareaid=getCookie("u966_tg_areaid");
		var logingameid=getCookie("u966_tg_gameid");
		var logintime=unescape(getCookie("u966_tg_lasttime"));
		
		var login_time=logintime.replace('+','日');
		var login=login_time.slice(6,25)
		var logintimee=login.replace('-','月');
//	alert(logintimee);

		if ( isLogin() && loginusername != null  )
		{
			if(loginareaid=='1' && logingameid=='1'){
				document.getElementById('loginTd').innerHTML=loginMessage("<tr><td height='25'>&nbsp;</td><td height='25' align='center' class='tiaowenzi'>欢迎您,"+loginusername+"</td><td height='25'>&nbsp;</td></tr><tr><td height='25'>&nbsp;</td><td height='25' align='center' class='tiaowenzi'>"+logintime.slice(0,17)+"</td><td height='25'>&nbsp;</td></tr><tr><td height='25'>&nbsp;</td><td height='25' align='center' class='tiaowenzi'>"+logingamearea+"</td><td height='25'>&nbsp;</td></tr>");
			}else{
				document.getElementById('loginTd').innerHTML=loginMessage("<tr><td  height='25'>&nbsp;</td><td align='center' height='25' class='tiaowenzi'>欢迎您,"+loginusername+"</td><td height='25'>&nbsp;</td></tr><tr><td  height='25'>&nbsp;</td><td align='center'  height='25' class='tiaowenzi'>上次登录:"+logintimee+"<br/></td><td height='25'>&nbsp;</td></tr><tr><td>&nbsp;</td><td align='center' class='tiaowenzi'>上次登录服务器:<a class='a5' href='http://www.u966.com/game/gotogame/enter/"+logingameid+"/"+loginareaid+"'>"+logingamearea+"</a></td><td height='20'>&nbsp;</td></tr>");
			}
		}
		else
		{
			var str=loginInput();
			document.getElementById('loginTd').innerHTML = str;
		}
		//ServerRequest();
		
	}
	/******登陆后的游戏列表*******/
//推荐的游戏
function gameRec(){
	var game_id= game_27;
		for (x in game_id){
			for(y in service_state ){
				if(service_state[y][0]==game_id[x][1]){
					if(game_id[x][1]==121){
						scr="<li style='width:100%'>";
						//
						scr+="<img src='http://img.u966.com/new09/wd_fwlb/zc.jpg' align='absbottom' />";
						scr+="<a href='http://www.u966.com/game/gotogame/enter/"+game_id[x][0]+"/"+game_id[x][1]+"' target='_blank'>"+game_id[x][2].slice(0,10)+"</a><span class='fwqjian'>荐</span><span class='fwqlc'>"+service_state[y][1]+"</span>";
						//scr+="<a onclick=\"alert('8月10日13时开服,敬请期待')\">"+game_id[x][2].slice(0,10)+"</a><span class='fwqjian'>荐</span><span class='fwqlc'>"+service_state[y][1]+"</span>";
						scr+="</li>";	
						document.write(scr);
					}	
				}
			}
		} 
}
//全部服务器
function areagame(){
	var areagame_id= game_27;
	for (x in areagame_id){
		for(y in service_state ){
			if(service_state[y][0]==areagame_id[x][1]){
				if(areagame_id[x][5]==0){
					scr="<li style='width:200px;'>";
					scr+="<img src='http://img.u966.com/new09/wd_fwlb/zc.jpg' align='absbottom' />";
					//if(areagame_id[x][1]==121){
					//scr+="<a href='#' target='_blank'>"+areagame_id[x][2].slice(0,4)+"</a><span class='fwqlc'>"+service_state[y][1]+"</span>";
					//}else{
					scr+="<a href='http://www.u966.com/game/gotogame/enter/"+areagame_id[x][0]+"/"+areagame_id[x][1]+"' target='_blank'>"+areagame_id[x][2].slice(0,4)+"</a><span class='fwqlc'>"+service_state[y][1]+"</span>";
					//}
					//scr+="<a onclick=\"alert('8月10日13时开服,敬请期待')\">"+areagame_id[x][2].slice(0,4)+"</a><span class='fwqlc'>"+service_state[y][1]+"</span>";
					scr+="</li>";
					document.write(scr);
				}	
			}
		}
	} 
}
//Div弹出
function Getlist(){

		window.parent.document.getElementById('apDiv1').style.display='';
		window.parent.document.getElementById('apDiv2').style.display='';
	
}
//Div关闭
document.domain = 'u966.com';
function closeserver(){
	window.parent.document.getElementById('apDiv1').style.display='none';
	window.parent.document.getElementById('apDiv2').style.display='none';
}
//收藏本页
function AddFavorite(sURL, sTitle) 
{ 
     try{ 
	     window.external.AddFavorite(sURL, sTitle);
     } catch (e) { 
         try{ 
		//window.sidebar.AddPanel(sTitle, sURL, "");
		window.sidebar.addPanel(sTitle, sURL,""); 
         }catch (e){ 
             alert("请使用Ctrl+D进行添加"); 
         } 
     } 
}		