﻿var gamecode = get_game_name();
$(document).ready(function () {
    getserver("serv", gamecode, "serverlisttop","  class=\"s_list\"");
 getserver("allserver", gamecode, "serverlist","  class=\"s_list\"");
});

function getserver(aid, agamecode, method,csss) {
    $("#" + aid).html("");
    var serverstat = '';
    var url = "//www.266wan.com/api/GetServer.ashx?gamecode=" + agamecode + "&method=" + method + "&jsoncallback=?";
    $.getJSON(url, function (data) {
        var i = 0;
        $.each(data, function (k, v) {
            $.each(v, function (kk, vv) {

                var areastate = vv.Areastate;
                var start_datexx = vv.Starttime;
                var start_date = new Date(Date.parse(start_datexx.replace(/-/ig, "/")));

                if (areastate == "维护中") {
                    serverstat = "维护";
                } else if (areastate == "正常" && start_date > (new Date())) {
                    serverstat = "暂未开启";
                } else {
                    serverstat = "火爆开启";
                }
                var Gamename = vv.Gamename;
                var gamecode = vv.Gamecode;
                var gameareaname = "[" + vv.Gameareaname + "] " + vv.Xh + "区 " + start_date.getHours() + "点开启";              
                var id = vv.Id;
                var entergame = "";
                var logareaurl = "http://game.266wan.com/LoginGame.aspx?id=" + id;
               var isnew=vv.Isnew;
		if(isnew=='1'){isnew="<img src=\"/skin/new.gif\">"}else{isnew='';}
               entergame = "<a href=\"" + logareaurl + "\" class=\"server_btn\" target='_blank'>";               
               entergame ="<li>" + entergame +"<i class=\"s_green\"></i> " + Gamename  + vv.Gamefu +"服 " + serverstat +"</a> </li>";

                $("#" + aid).append(entergame);
i++;
if(i>=4 && method=="serverlisttop") return false;
               
            });
        });

    });
}


Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
        RegExp.$1.length == 1 ? o[k] :
        ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

function Request(argname) {
    var url = document.location.href;
    var arrStr = url.substring(url.indexOf("?") + 1).split("&");
    //return arrStr; 
    for (var i = 0; i < arrStr.length; i++) {
        var loc = arrStr[i].indexOf(argname + "=");

        if (loc != -1) {
            return arrStr[i].replace(argname + "=", "").replace("?", "");
            break;
        }

    }
    return "";
}
function get_game_name() {
    var url = window.location.href;
    url_part = url.split('/');
    if (url_part[2] == 'www.266wan.com') 
    {
        game = url_part[3];
    } else {
        temp = url_part[2].split('.');
        game = temp[0];
    }
    return game;
}