Autor: DDtank | Publicado: 2011-07-14T18:48:00-07:00


function keyDown()
{
 $(elem).keydown(function(event){ &nbsp;
   &nbsp;if(event.keyCode==13){ &nbsp;
    if(document.getElementById("user").value != "") {
     checkLogin();
    }
 
   if(document.getElementById("username").value != "") {
    checkReg();
   } &nbsp;
   &nbsp;}
  });
}

function changetab(id)
{
 switch(id)
 {
  case "tab_1":
    document.getElementById("tab_1").style.display="block";
    document.getElementById("tab_2").style.display="none";
    document.getElementById("tab_card_1").style.display="block";
    document.getElementById("tab_card_2").style.display="none";
    break;
  case "tab_2":
    document.getElementById("tab_1").style.display="none";
    document.getElementById("tab_2").style.display="block";
    document.getElementById("tab_card_2").style.display="block";
    document.getElementById("tab_card_1").style.display="none";
    break;
 }
}
function tabnews(id)
{
 switch(id)
 {
  case "list_1":
    document.getElementById("list_1").style.display="block";
    document.getElementById("list_2").style.display="none";
    document.getElementById("list_3").style.display="none";
    document.getElementById("list_4").style.display="none";
    break;
  case "list_2":
    document.getElementById("list_1").style.display="none";
    document.getElementById("list_2").style.display="block";
    document.getElementById("list_3").style.display="none";
    document.getElementById("list_4").style.display="none";
    break;
  case "list_3":
    document.getElementById("list_1").style.display="none";
    document.getElementById("list_2").style.display="none";
    document.getElementById("list_3").style.display="block";
    document.getElementById("list_4").style.display="none";
    break;
  case "list_4":
    document.getElementById("list_1").style.display="none";
    document.getElementById("list_2").style.display="none";
    document.getElementById("list_3").style.display="none";
    document.getElementById("list_4").style.display="block";
    break;
 }
}

function tabliansai(id)
{
 switch(id)
 {
  case "liansai_1":
    document.getElementById("liansai_1").style.display="block";
    document.getElementById("liansai_2").style.display="none";
    document.getElementById("liansai_3").style.display="none";
    break;
  case "liansai_2":
    document.getElementById("liansai_1").style.display="none";
    document.getElementById("liansai_2").style.display="block";
    document.getElementById("liansai_3").style.display="none";
    break;
  case "liansai_3":
    document.getElementById("liansai_1").style.display="none";
    document.getElementById("liansai_2").style.display="none";
    document.getElementById("liansai_3").style.display="block";
    break;
 }
}
function addFavorite(url,title)
{
 var fav_url = url;
 var fav_title = title;
 if (document.all &amp;&amp; window.external){
 window.external.AddFavorite(fav_url,fav_title);
 }else if (window.sidebar){
 window.sidebar.addPanel(fav_title,fav_url,"");
 }else{
 alert("浏览器不支持，请手动加入收藏夹");
 }
}
function isNumberOrLetter(s){
 var regu = "^[0-9a-zA-Z\_]+$";
 var re = new RegExp(regu);
 if (re.test(s)) {
  return true;
 }else{
  return false;
 }
}
//登录
function checkReg()
{
 var msg = new Array(
  "请输入用户名",
  "请输入密码",
  "两次输入密码不一致",
  "账号已存在",
  "请输入4-32位字符，不允许空格",
  "请输入4-20位字母数字下划线的组合",
  "密码不能与用户名相同",
  "密码过于简单",
  "用户名输入正确，可以注册",
  "用户名已存在或者禁止注册",
  "用户名已存在或者禁止注册",
  "用户名错误",
  "密码错误"
 )
 var chk = true;
 if($("#username").val() == ""){
  chk = false;
  alert(msg[0]);
  return false;
 }
 else if($("#username").val().length &lt; 4 || $("#username").val().length&gt;20){
  chk = false;
  alert(msg[4]);
  return false;
 }
 else if(!isNumberOrLetter($("#username").val())){
  chk = false;
  alert(msg[5]);
  return false;
 }
 if(chk){
  &nbsp; &nbsp;//Ajax验证
&nbsp; &nbsp; &nbsp; &nbsp; $.get("/source/Post.php", {checkuser:"checkusername", username:$("#username").val(),ran: Math.random()},
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(data){
    if(data == -3)
    {
     chk = false;
     alert(msg[9]);
     return false;
    }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
 }
 if(chk){
  if($("#password").val()==""){
   chk = false;
   alert(msg[1]);
   return false;
  }
  else if($("#password").val().length &lt;4 || $("#password").val().length&gt;32){
   chk = false; 
   alert(msg[5]);
   return false;
  }
  else if($("#password").val() == $("#username").val()){
   chk = false;
   alert(msg[6]);
   return false;
  }
  else if($("#password").val()=="123456"){
   chk = false;
   alert(msg[7]);
   return false;
  }
 }
 if(chk){
  if($("#password").val() != $("#confirmpassword").val()){
   chk = false;
   alert(msg[2]);
   return false;
  }
 }
 if(chk){
  $("#loginbtn").attr("disabled","true");
   $.post("/source/Post.php", {password:$("#password").val(), username:$("#username").val(),confirmpassword:$("#confirmpassword").val(),action:$("#action").val(),from:$("#refer").val(),ran: Math.random()},
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(data){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //成功
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#loginbtn").removeAttr("disabled");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(data &gt; 1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  //$("#logintip").html("&lt;div class='serverstatus'&gt;&lt;a href='http://web.7k7k.com/index.php?controller=user&amp;action=game&amp;sid=8'&gt;弹弹堂 [电信1区](&lt;font color='#ff0000'&gt;爆满&lt;/font&gt;)&lt;/a&gt;&lt;br /&gt;&lt;a href='http://web.7k7k.com/index.php?controller=user&amp;action=game&amp;sid=9'&gt;弹弹堂 [电信2区](&lt;font color='#ff0000'&gt;今日新开&lt;/font&gt;)&lt;/a&gt;&lt;/div&gt;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  //alert('恭喜你，注册成功，点击确定进入游戏...');
     //top.location.href='http://web.7k7k.com/index.php?controller=user&amp;action=game&amp;sid=9';
     alert('恭喜你，注册成功');
     top.location.href='http://web.7k7k.com/games/ddt/index.html?ran='+Math.random();
     //top.location.href='http://web.7k7k.com/games/ddt/server_list.htm';
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
    else if(result == -3)
    {
     alert("用户名已经存在");
     return false;
    }
    else if(result == -1)
    {
     alert("用户名不合法,请重新输入");
     return false;
    }
    else if(result == -2)
    {
     alert("包含要不允许注册的词语");
     return false;
    }
    else if(result == -4)
    {
     alert("密码不能为空");
     return false;
    }
    else if(result == -5)
    {
     alert("两次密码不一致");
     return false;
    }
    else if(result == 0)
    {
     alert("注册失败未知错误");
     return false;
    }
    else
    {
     alert("注册失败，请稍后再试");
     return false;
    }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
 }
}
function checkLogin(){
 var msg = new Array(
  "用户名不能为空",
  "密码不能为空",
  "请输入4-32位字符，不允许空格",
  "请输入4-20位字母数字下划线的组合",
  "提交失败",
  "用户名不存在",
  "密码错误",
  "登陆失败，请稍后再试"
 )
 var chk = true;
 if($("#user").val() == ""){
  chk = false;
  alert(msg[0]);
  return false;
 }
 else if($("#user").val().length &lt;4 || $("#user").val().length&gt;32){
  chk = false; 
  alert(msg[2]);
  return false;
 }
 if($("#pass").val()==""){
  chk = false;
  alert(msg[1]);
  return false;
 }
 else if($("#pass").val().length &lt;4 || $("#pass").val().length&gt;32){
  chk = false; 
  alert(msg[3]);
  return false;
 }
 if($("#action2").val() != "login"){
  chk = false;
  alert(msg[4]);
  return false;
 }
 if(chk){
  $("#loginbtn2").attr("disabled","true");
   $.post("/source/Post.php", {password:$("#pass").val(), username:$("#user").val(),action:$("#action2").val(),ran: Math.random()},
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(data){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $("#loginbtn2").removeAttr("disabled");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(data == 1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  $("#loginbtn2").removeAttr("disabled");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  //$("#logintip").html("&lt;div class='serverstatus'&gt;&lt;a href='http://web.7k7k.com/index.php?controller=user&amp;action=game&amp;sid=8'&gt;弹弹堂 [电信1区](&lt;font color='#ff0000'&gt;爆满&lt;/font&gt;)&lt;/a&gt;&lt;br /&gt;&lt;a href='http://web.7k7k.com/index.php?controller=user&amp;action=game&amp;sid=9'&gt;弹弹堂 [电信2区](&lt;font color='#ff0000'&gt;今日新开&lt;/font&gt;)&lt;/a&gt;&lt;/div&gt;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  alert('恭喜你，登陆成功');
     top.location.href='http://web.7k7k.com/games/ddt/index.html?ran='+Math.random();
     //top.location.href='http://web.7k7k.com/games/ddt/server_list.htm';
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
    else if(data == -1)
    {
     alert("用户名不存在，请您重新输入");
     return false;
    }
    else if(data == -2)
    {
     alert("密码错误，请您重新输入");
     return false;
    }
    else if(data == -3)
    {
     alert("用户名不能为空");
     return false;
    }
    else if(data == -4)
    {
     alert("密码不能为空");
     return false;
    }
    else if(data == 0)
    {
     alert("登陆失败，请稍后再试");
     return false;
    }
   });
 }
}

function readCookie(name) {
var cookieValue = "";
var search = name + "=";
if (document.cookie.length &gt; 0)
{
 offset = document.cookie.indexOf(search);
 if (offset != -1)
 {
  offset += search.length;
  end = document.cookie.indexOf("&amp;", offset);
  if (end == -1) end = document.cookie.length;
  cookieValue = unescape(document.cookie.substring(offset, end));
  var cookiearr = cookieValue.split(';');
  if(cookiearr.length &gt; 0)
  {
   cookieValue = cookiearr[0];
  }
 }
}
return cookieValue;
}

function getNew(){
 var serv = &nbsp;document.getElementById("newsv").innerHTML;
  return serv;
}


//专区状态
function loginDdtStatus()
{
 $(function(){
   &nbsp;document.onkeydown = function(e){ 
   &nbsp; &nbsp;var ev = document.all ? window.event : e;
   &nbsp; &nbsp;if(ev.keyCode==13) {
     if(document.getElementById("user").value != "") {
      checkLogin();
     }
  
     if(document.getElementById("username").value != "") {
      checkReg();
     } &nbsp;
    &nbsp;}
   &nbsp; &nbsp;}
  }); &nbsp;
 var url = window.location.href;
 if(url.indexOf("web.7k7k.com") &lt; 0)
 {
  url ="http://web.7k7k.com";
 }
 var s = '';
 if(decodeURI(readCookie("k7_username")) != "" &amp;&amp; readCookie("userpermission") != "")
 {
  s += '&lt;div class="dtl"&gt;&lt;/div&gt;';
  s += ' &lt;div class="ddt_login" id="tab_card_1"&gt;';
  s += ' &lt;ul&gt;';
  s += ' &lt;li class="dt_li"&gt;您好：&lt;font color="red"&gt;&lt;b&gt;'+decodeURI(readCookie("k7_username"))+'&lt;/b&gt;&lt;/font&gt;(&lt;a href="/user/logout.php?refer='+url+'"&gt;退出&lt;/a&gt;)&lt;/li&gt;';
  s += ' &lt;li class="dt_li"&gt;上次登录：'+readCookie("k7_lastlogin").replace("+"," ")+'&lt;/li&gt;';
  //s += ' &lt;li class="dt_li"&gt;本次登录IP：'+readCookie("k7_ip")+'&lt;/li&gt;';
  s += ' &lt;li class="dt_li" &gt;最新开服：&lt;b&gt;&lt;font color="red" &nbsp;id="dsv"&gt;'+getNew()+'&lt;/font&gt;&lt;/b&gt;&lt;/li&gt;';
  s += ' &lt;li class="dt_li"&gt;上次玩过的游戏：&lt;/li&gt;';
  if(readCookie("k7_gamelist") != "")
  {
   var gamelist = decodeURI(readCookie("k7_gamelist"));
   if(gamelist) {
    var data = eval("("+gamelist+")");
    for(var i=0;i&lt;1;i++) {
     s += "&lt;li class=\"dt_st\"&gt;&lt;font color=\"red\"&gt;&lt;b&gt;&lt;a href=\"/games/togame.php?target="+data[i]['key']+"_"+data[i]['gid']+"&amp;server_id="+data[i]['server_id']+"\" target=\"_blank\" style=\"color:#707070;font-size:14px;\"&gt;"+data[i]['sname']+"&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;";
    }
   } else {
    s += '&lt;li class="dt_st"&gt;&lt;font color="red"&gt;&lt;b&gt;您暂时没有玩过游戏！&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;';
   }  
  }
  else
  {
   s += '&lt;li class="dt_st"&gt;&lt;font color="red"&gt;&lt;b&gt;您暂时没有玩过游戏！&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;';
  }
  s += '&lt;/ul&gt;&lt;/div&gt;';
 }
 else
 {
  &nbsp; &nbsp;//注册
&nbsp; &nbsp;  s +='&lt;ul id="menu0"&gt;&lt;li &nbsp;onclick="setTab(0,0)"&gt;用户注册&lt;/li&gt;&lt;li class="hover" onclick="setTab(0,1)"&gt;用户登录&lt;/li&gt;&lt;/ul&gt;&lt;div class="loginInner"&gt; &lt;div class="right2"&gt; &lt;div class="right23" id="main0"&gt;';
&nbsp; &nbsp; &nbsp; &nbsp; s +='&lt;span class="disnone" id="disblock" &gt;&lt;ul&gt;&lt;li&gt;用&amp;nbsp;户&amp;nbsp;名：&lt;input type="text" name="username" class="input" id="username" value=""/&gt;&lt;/li&gt;';
  s +='&lt;li&gt;密&amp;nbsp;&amp;nbsp;&amp;nbsp; 码：&lt;input type="password" name="password" class="input" &nbsp;id="password" value=""/&gt;&lt;/li&gt;';
  s +='&lt;li&gt;确认密码：&lt;input type="password" name="confirmpassword" id="confirmpassword" class="input" &nbsp;value=""/&gt;&lt;/li&gt;';
&nbsp; &nbsp; &nbsp; &nbsp; s +='&lt;li&gt;&lt;input name="refer" type="hidden" id="refer" value="" /&gt;&lt;input name="action" type="hidden" id="action" value="register" /&gt;&lt;input type="button" id="loginbtn" onclick="checkReg();" name="loginbtn" class="submit" value="确认"/&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;';
&nbsp; &nbsp; &nbsp; &nbsp; //登录
&nbsp; &nbsp; &nbsp; &nbsp; s +='&lt;span class="disblock" id="disnone" &gt;&lt;ul&gt;&lt;li&gt;用&amp;nbsp;户&amp;nbsp;名：&lt;input type="text" id="user" name="user" class="input" value=""/&gt;&lt;/li&gt;'; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; s +='&lt;li&gt;密 &amp;nbsp;&amp;nbsp;&amp;nbsp;码：&lt;input type="password" name="pass" id="pass" class="input" value=""/&gt;&lt;/li&gt;';
&nbsp; &nbsp; &nbsp; &nbsp; s +='&lt;li&gt; &lt;input name="action2" type="hidden" id="action2" value="login" /&gt;&lt;input type="button" id="loginbtn2" name="loginbtn2" onclick="checkLogin();" class="submit" value="确认" /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;&lt;/div&gt;';
 }
 return s;
}

function getGamesStatus()
{
 var s = '';
 if(decodeURI(readCookie("k7_username")) != "" &amp;&amp; readCookie("userpermission") != "")
 {
  if(readCookie("k7_gamelist") != "")
  {
   var gamelist = decodeURI(readCookie("k7_gamelist"));
   if(gamelist) {
    var data = eval("("+gamelist+")");
    for(var i=0;i&lt;1;i++) {
   &nbsp; &nbsp; &nbsp; &nbsp;s += "&lt;a href=\"/games/togame.php?target="+data[i]['key']+"_"+data[i]['gid']+"&amp;server_id="+data[i]['server_id']+"\" target=\"_blank\" style=\"color:#663300;font-size:14px;width:200px;\"&gt;"+data[i]['sname']+"&lt;/a&gt;&lt;/font&gt;";
    }
   }else
   {
    s += '您还没有玩过游戏！';
   }
  }
  else
  {
   s += '您还没有玩过游戏！';
  }
 }
 else
 {
  s += '您还没有登陆，请您登陆！';
 }
 return s;
}