var _title = window.document.title;
function TwinkleTitle() {
    if (document.title == "　") {
        document.title = _title;
    } else {
        document.title = "　";
    }
}
$(document).ready(function () {
    if (param.twinkle) {
        setInterval("TwinkleTitle()", 700);
    }
    $("#zcxy").attr("href", param.rg);
    var x = new xykj();
    x.box = ".s1";
    x.full = param.full;
    x.width = param.width;
    x.height = param.height;
    for (var index = 1; index <= param.fls.length; index++) {
        if (param.fls[index - 1].indexOf(".swf") != -1) {
            x.flash(param.route + param.fls[index - 1], ".block" + index);
        } else {
            x.img(param.route + param.fls[index - 1], ".block" + index);
        }
    }
    $("#clickdiv").click(function () { x.openbox() });
    $(".cs-close").click(function () { x.closebox() });
    $("#qh1").click(function () {
        $("#qh1").css("color", "Yellow")
        $("#qh2").css("color", "#fff");
        $(".reg").hide();
        $(".login").show();
    });
    $("#qh2").click(function () {
        $("#qh1").css("color", "#fff")
        $("#qh2").css("color", "Yellow");
        $(".reg").show();
        $(".login").hide();
    });

    $("#onreg").click(function () {
        x.user.reg();
    })
    $("#onlogin").click(function () {
        x.user.login();
    })
})

var xykj = function () { }
 
xykj.prototype.flash = function (path, selecter) {
    /*
    selecter = selecter || document.body;
    if (this.full) {
    this.width = $(window).width();
    this.height = $(window).height();
    } else {
    $(this.box).width(this.width);
    $(this.box).css("margin", "0px auto");
    }
    var _div = document.createElement("div");
    _div.setAttribute("class", "block " + selecter.substring(1));
    $(this.box).append(_div);
    var _obj = document.createElement("object");
    _obj.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
    _obj.setAttribute("codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0");
    _obj.setAttribute("width", this.width);
    _obj.setAttribute("height", this.height);
    $(_obj).append('<param name="quality" value="high" />');
    $(_obj).append('<param name="wmode" value="transparent" />');
    $(_obj).append('<param name="movie" value="' + path + '" />');
    $(_obj).append('<param name="menu" value="false" />');
    $(_obj).append('<param name="AllowScriptAccess" value="always" />');
    var _embed = document.createElement("embed");
    _embed.setAttribute("src", path);
    _embed.setAttribute("quality", "high");
    _embed.setAttribute("pluginspage", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
    _embed.setAttribute("type", "application/x-shockwave-flash");
    _embed.setAttribute("wmode", "transparent");
    _embed.setAttribute("width", this.width);
    _embed.setAttribute("height", this.height);
    $(_obj).append(_embed);
    $(_div).append(_obj);
    */
    this.clickdiv("clickdiv");

}
xykj.prototype.img = function (path, selecter) {
    selecter = selecter || document.body;
    if (this.full) {
        this.width = $(window).width();
        this.height = $(window).height();
    } else {
        $(this.box).width(this.width);
        $(this.box).css("margin", "0px auto");
    }
    var _div = document.createElement("div");
    _div.setAttribute("class", "block " + selecter.substring(1));
    $(this.box).append(_div);
    var _img = document.createElement("img");
    _img.setAttribute("width", this.width);
    _img.setAttribute("height", this.height);
    _img.setAttribute("src", path);
    $(_div).append(_img);

    this.clickdiv("clickdiv");
}
xykj.prototype.clickdiv = function (selecter) {
    var has = document.getElementById(selecter);
    if (has == null) {
        var clickdiv = document.createElement("div");
        clickdiv.setAttribute("class", "clickdiv");
        clickdiv.setAttribute("id", selecter);
        $(document.body).append(clickdiv);
        $("#" + selecter).height($(window.document).height());
        $("#" + selecter).width($(window.document).width());
    }
};

xykj.prototype.full = false;
xykj.prototype.box = document.body;
xykj.prototype.width = 1000;
xykj.prototype.height = 700;
xykj.prototype.openbox = function (selecter) {
    $(".shade").show();
    $(".shade").height($(window.document).height());
    $(".shade").width($(window.document).width());
    $(".shade-pop").show();
}
xykj.prototype.closebox = function () {
    $(".shade").hide();
    $(".shade-pop").hide();
}

xykj.prototype.user = {
    reg: function () {
        $("#regallerror").html("");
        $("#regallerror1").html("");
        $("#regallerror2").html("");
        var uid = $("#regname").val();
        var pwd1 = $("#regpwd1").val();
        var pwd2 = $("#regpwd2").val();
        var rg = $("#rg").attr("checked");
        if (!rg) { $("#regallerror").html("您需要同意注册协议才能注册").addClass("e").removeClass("f"); return; }
        if (uid.length < 1) {
            $("#regallerror1").html("用户账号不能为空").addClass("e").removeClass("f"); return;
        }
        if (pwd1.length < 1) {
            $("#regallerror2").html("密码不能为空").addClass("e").removeClass("f"); return;
        }
        if (pwd1 != pwd2) {
            $("#regallerror2").html("两次密码不一致").addClass("e").removeClass("f"); return;
        }
        var u_rg = /^[a-zA-Z]{1}[a-zA-z0-9]{3,13}$/;
        if (!u_rg.test(uid)) {

            $("#regallerror").html("用户名格式错误,请使用字母开头,最大14位").addClass("e").removeClass("f"); return;
        }
        $("#regallerror").html("正在注册请稍后...").addClass("f").removeClass("e");
        var path = param.domain + "api/remote/tg_regusers.ashx";
        var str = location.href;
        var str1 = str.split('?u=');
        $.ajax({
            url: path,
            error: function () { },
            dataType: "jsonp",
            jsonp: "callback",
            data: "uid=" + uid + "&pwd=" + pwd1 + "&muid=" + str1[1] + "&game=" + param.game + "&server=" + param.server + "&zhi=" + param.zhi,
            success: function (sun) {
                if (!isNaN(sun)) {
                    $("#regallerror").html("登录成功,正在进入游戏..").addClass("f").removeClass("e");
                    if (param.game == "-1" || param.game == "") {
                        window.location.href = param.domain + "user.html";
                    } else {
                        window.location.href = param.domain + "play/" + sun + ".html";
                    }
                } else {
                    $("#regallerror").html(sun).addClass("f").removeClass("e");
                }
            }
        });

    },
    login: function () {
        $("#loginallerror").html("");
        $("#loginallerror1").html("");
        $("#loginallerror2").html("");
        var uid = $("#loginname").val();
        var pwd = $("#loginpwd").val();
        if (uid.length < 1) {
            $("#loginallerror1").html("请输入账号.").addClass("e").removeClass("f"); return;
        }
        if (pwd.length < 1) {
            $("#loginallerror2").html("请输入密码.").addClass("e").removeClass("f"); return;
        }
        $("#loginallerror").html("正在尝试登陆请稍后...").addClass("f").removeClass("e");
        var rem = "true";
        var path = param.domain + "api/remote/logins.ashx";
        $.ajax({
            url: path,
            error: function () { },
            dataType: "jsonp",
            jsonp: "callback",
            data: "uid=" + uid + "&pwd=" + pwd + "&game=" + param.game + "&server=" + param.server + "&rem=" + rem,          
            success: function (sun) {
                if (!isNaN(sun)) {
                    $("#loginallerror").html("登录成功,正在进入游戏..").addClass("f").removeClass("e");
                    if (param.game == "-1" || param.game == "") {
                        window.location.href = param.domain + "user.html";
                    } else {
                        window.location.href = param.domain + "play/" + sun + ".html";
                    }
                } else {
                    $("#loginallerror").html(sun).addClass("e").removeClass("f");
                }
            }
        });
    }
}