/// <summary>
/// 延时读取数据
/// </summary>
$(document).ready(function () {

    /* 调用示例
    var selet =
    {
    pro: "#LoginBts",                       //点击事件
    username: "input[name='Username']",     //用户名
    password: "input[name='Password']",     //密码
    remember: "#reme",                      //记住账号
    doman: "/"                              //域名
    }
    */
    /// <summary>
    /// 用户登录
    /// </summary>
    jQuery(selet.pro).click(function () {


       /* jQuery.ajax({ url: selet.doman + "api/remote/login.ashx?cid=" + Math.random() + "&uid=" + $(selet.username).val() + "&pwd=" + $(selet.password).val() + "&rem=" + ($(selet.remember).attr("checked") == true),
            dataType: "jsonp",
            type: "GET",
            jsonp: 'callback',
            error: function (i, k, l) { alert(l) },
            success: function (msg) {
                if (msg + "" == "200") {
                    window.location.reload();
                } else {
                    alert(msg);
                }
            }
        });*/
        /*登录开始*/
        jQuery.ajax({
            url: selet.doman + "api/remote/login.ashx?cid=" + Math.random(),
            dataType: "jsonp",
            jsonp: 'callback',
            type: "POST",
            data: "uid=" + $(selet.username).val() + "&pwd=" + $(selet.password).val() + "&rem=" + ($(selet.remember).attr("checked") == true),
            error: function (i, k, l) { alert(l) },
            success: function (msg) {
                if (msg + "" == "200") {
                    window.location.reload();
                } else {
                    alert(msg);
                }
            }
          
        });
        /*登录结束*/




    });
    /// <summary>
    /// 获取服务器
    /// </summary>
    $.getJSON(selet.doman + "api/getServer/Server.ashx?gid=" + selet.gid, function (data) {
        var _html = "";
        $(data).each(function (i, d) {
            if (selet.serverCount > i) {
                _html += selet.sample.replace("{ID}", d.ID)
                                 .replace("{Name}", d.Name)
                                 .replace("{Circuit}", d.Circuit)
                                 .replace("{State}", serverState(d.State))
                                 .replace("{StartDate}", d.StartDate)
                                 .replace("{GameId}", d.GameId);
            }
        });
        _html += selet.than;
        $(selet.container).html(_html);
    });




    /// <summary>
    /// 最后登录服务器
    /// </summary>
    if (selet.uid > 0) {
        jQuery.ajax({ url: selet.doman + "api/remote/lastServer.ashx?cid=" + Math.random() + "&uid=" + selet.uid + "&gid=" + selet.gid,
            type: "GET",
            dataType: "jsonp",
            jsonp: 'callback',
            error: function (i, k, l) { },
            success: function (d) {
                if (d != null) {
                    $(selet.mygame).html(selet.mygame_sample.replace("{ID}", d.ID)
                                 .replace("{Name}", d.Name)
                                 .replace("{sid}", d.ServerId)
                                 .replace("{Circuit}", d.Circuit)
                                 .replace("{State}", serverState(d.State))
                                 .replace("{StartDate}", d.StartDate)
                                 .replace("{Img1}", d.Img1)
                                 .replace("{GameName}", d.GameName)
                                 .replace("{GameId}", d.GameId));
                }
            }
        });
    }
});

function serverState(s) {
    switch (s) {
        case "WILLSTART": return "即将开启";
        case "NEW": return "新服推荐";
        case "NORMAL": return "正常开启";
        case "MERGER": return "即将和服";
        case "MAINTENANCE": return "维护";
        case "OFF": return "关闭";
        case "FULL": return "爆满";
        case "FLUENT": return "流畅";
        case "DELFILE": return "删档内侧";
    }
}

function loadjscssfile(filename, filetype) {

    if (filetype == "js") {
        var fileref = document.createElement('script');
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", filename);
    } else if (filetype == "css") {

        var fileref = document.createElement('link');
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", filename);
    }
    if (typeof fileref != "undefined") {
        document.getElementsByTagName("head")[0].appendChild(fileref);
    }
}