﻿//动态帮定展开关闭面板的数据

var userNameText = ""

$('.btm_HH_Login').livequery(function() {

    $('.btm_HH_Login').click(function() {

        user = iniUser();

        var sel = "[gt=" + $(this).attr("gt") + "]";
        var gt = $(this).attr("gt");

        if (user.isLogin) {
            GetHongHuangAccountInfo(gt);
            userNameText = user.username;
        }

        $('.hh_LoginBg' + sel).slideDown(200);
        $('.HH_NewsBox' + sel).hide();
        $("input[txtLogin='userName']").focus();
    });
})

//关闭按钮
$('.btm_hh_close').livequery(function() {
    $('.btm_hh_close').click(function() {
        var sel = "[gt=" + $(this).attr("gt") + "]";
        $('.hh_LoginBg' + sel).slideUp(200);
        $('.HH_NewsBox' + sel).show();
    });
})

$("input[txtLogin='pwd']").livequery(function() {
    $("input[txtLogin='pwd']").keydown(function(event) {
        if (event.keyCode == 13) { $("[submitBtn='login']").click(); }
    });
})

$("input[registe='pwd2']").livequery(function() {
    $("input[registe='pwd2']").keydown(function(event) {
        if (event.keyCode == 13) { $("[submitbtn='registe']").click(); }
    });
})

/**********登陆游戏开始************/
$("[submitBtn='login']").livequery(function() {

    $("[submitBtn='login']").click(function() {
        var $LoginName = $("input[txtLogin='userName']");
        var $LoginPwd = $("input[txtLogin='pwd']");

        var un = $LoginName.eq($LoginName.length - 3).val();
        var pwd = $LoginPwd.eq($LoginPwd.length - 3).val();

        if (un == "") { $(".HH_Login_sms").html("请输入账号."); return; };
        if (pwd == "") { $(".HH_Login_sms").html("请输入密码."); return; };

        var sel = "[gt=" + $(this).attr("gt") + "]";
        var gt = $(this).attr("gt");

        $("[submitBtn='login']" + sel).hide();
        $(".Login_Loading" + sel).show();

        var ajaxUrl = window.location.href.toLowerCase();
        if (ajaxUrl.indexOf("freedom-game.com") > -1) {
            ajaxUrl = "http://www.freedom-game.com/api/Internal/Base/Login.ashx?callback=?";
        }
        else if (ajaxUrl.indexOf("ziyoudalu.com") > -1) {
            ajaxUrl = "http://www.ziyoudalu.com/api/Internal/Base/Login.ashx?callback=?";
        }
        $.ajax({
            type: "get",
            url: ajaxUrl,
            dataType: "json",
            data: "un=" + un + "&pwd=" + pwd + "&j=" + Math.random(),
            success: function(objJson) {
                if (objJson.result != 1) {
                    // alert(objJson.message);
                    $(".HH_Login_sms").html(objJson.message);
                }
                else {
                    $(".HH_Login_sms").html("");
                    loadUserInfo();
                    GetHongHuangAccountInfo(gt);
                    if (objJson.isMobile == 0)
                        updateMobile();
                }
                $("[submitBtn='login']" + sel).show();
                $(".Login_Loading" + sel).hide();
            }
        });
    });
});

function GetHongHuangAccountInfo(gt) {
    var sel = "[gt=" + gt + "]";
    var ajaxUrl = window.location.href.toLowerCase();
    if (ajaxUrl.indexOf("freedom-game.com") > -1) {
        ajaxUrl = "freedom-game.com";
    }
    else if (ajaxUrl.indexOf("ziyoudalu.com") > -1) {
        ajaxUrl = "ziyoudalu.com";
    }
    if (gt == 1) {

        $.ajax({
            type: "get",
            url: "http://www." + ajaxUrl + "/api/Internal/T6/GetLoginInfo.ashx?callback=?",
            dataType: "json",
            data: "j=" + Math.random(),
            success: function(objJson) {
                if (objJson.status == 1) {
                    $("a[serverID='1']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_This6_StartGame.aspx?GAID=" + objJson.gaid1);
                    $("a[serverID='3']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_This6_StartGame.aspx?GAID=" + objJson.gaid3);

                    $(".HHSelectServer" + sel).show();
                    $(".HH_loginBoxDiv" + sel).hide();
                    $(".hh_LoginBg" + sel).addClass("hh_LoginBg2");
                    $(".hh_Login2_DIV" + sel).hide();

                    user = iniUser();
                    if (user.isLogin) { $(".welName").html("欢迎您:" + user.username); }
                }
                else { alert(objJson.message); }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.statusText); }
        });
    }
    else if (gt == 2) {
        $.ajax({
            type: "get",
            url: "http://www." + ajaxUrl + "/api/Internal/BT/GetLoginInfo.ashx?callback=?",
            dataType: "json",
            data: "j=" + Math.random(),
            success: function(objJson) {
                if (objJson.status == 1) {
                    $("a[serverID='1']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Game_Shangzhou_StartGame.aspx?GAID=" + objJson.gaid1);

                    $(".HHSelectServer" + sel).show();
                    $(".HH_loginBoxDiv" + sel).hide();
                    $(".hh_LoginBg" + sel).addClass("hh_LoginBg2");
                    $(".hh_Login2_DIV" + sel).hide();

                    user = iniUser();
                    if (user.isLogin) { $(".welName").html("欢迎您:" + user.username); }
                }
                else { alert(objJson.message); }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.statusText); }
        });
    }
    else if (gt == 3) {
        $.ajax({
            type: "get",
            url: "http://www." + ajaxUrl + "/api/Internal/HH/GetLoginInfo.ashx?callback=?",
            dataType: "json",
            data: "j=" + Math.random(),
            success: function(objJson) {
                if (objJson.status == 1) {
                    $("a[serverID='1']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid1);
                    $("a[serverID='2']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid2);
                    $("a[serverID='3']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid3);
                    $("a[serverID='4']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid4);
                    $("a[serverID='5']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid5);
                    $("a[serverID='6']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid6);
                    $("a[serverID='7']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid7);
                    $("a[serverID='8']" + sel).attr("href", "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + objJson.gaid8);

                    $(".HHSelectServer" + sel).show();
                    $(".HH_loginBoxDiv" + sel).hide();
                    $(".hh_LoginBg" + sel).addClass("hh_LoginBg2");
                    $(".hh_Login2_DIV" + sel).hide();

                    user = iniUser();
                    if (user.isLogin) { $(".welName").html("欢迎您:" + user.username); }
                }
                else { alert(objJson.message); }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.statusText); }
        });
    }
}
/**********登陆游戏结束************/


/**********注册开始************/
$("[submitbtn='registe']").livequery(function() {

    $("[submitbtn='registe']").click(function() {
        var ajaxUrl = window.location.href.toLowerCase();
        if (ajaxUrl.indexOf("freedom-game.com") > -1) {
            ajaxUrl = "freedom-game.com";
        }
        else if (ajaxUrl.indexOf("ziyoudalu.com") > -1) {
            ajaxUrl = "ziyoudalu.com";
        }

        var gt = $(this).attr("gt");

        var $RegisteName = $("input[registe='userName']");
        var $RegistePwd = $("input[registe='pwd']");
        var $RegistePwd2 = $("input[registe='pwd2']");

        var un = $RegisteName.eq($RegisteName.length - 3).val();
        var pwd = $RegistePwd.eq($RegistePwd.length - 3).val();
        var pwd2 = $RegistePwd2.eq($RegistePwd2.length - 3).val();

        var patrn = /^[a-zA-Z]{1}([a-zA-Z0-9]){3,19}$/;
        if (!patrn.exec(un)) { $(".HH_Reg_sms").html("请输入通行证账号，通行证账号只能是以英文字母开头长度4-20个的字母数字组合"); return; };
        if (pwd == "") { $(".HH_Reg_sms").html("请输入密码"); return; };
        if (pwd != pwd2) { $(".HH_Reg_sms").html("您两次输入的密码不相同，请重新输入"); return; };

        var sel = "[gt=" + gt + "]";
        $("[submitBtn='registe']" + sel).hide();
        $(".Registe_Loading" + sel).show();
        if (gt == 1) {
            $.getJSON("http://www." + ajaxUrl + ".com/CPSAD/newT6Register.aspx?jsoncallback=?", {
                act: "REGISTER",
                txtUserName: un,
                txtPwd: pwd,
                txtPwd2: pwd2,
                service: 3
            },
        function(data) {
            var TM = data.ak;
            var r = TM.split(":");
            $("[submitBtn='registe']" + sel).show();
            $(".Registe_Loading" + sel).hide();
            if (r[0] == "1") { alert(r[1]); return false; }
            else {
                var GAID = r[0];
                if ((GAID != "") && (GAID != "0")) { loadUserInfo(); GetHongHuangAccountInfo(gt); }
                else { location.href = "http://www." + ajaxUrl + "/uc/Games_This6_StartGame.aspx?ServerID=1"; }
            }
        });
        }
        else if (gt == 2) {
            $.getJSON("http://www.freedom-game.com/CPSAD/BaTianRegister.aspx?jsoncallback=?", {
                act: "REGISTER",
                txtUserName: un,
                txtPwd: pwd,
                txtPwd2: pwd2,
                service: 1
            },
        function(data) {
            var TM = data.ak;
            var r = TM.split(":");
            $("[submitBtn='registe']" + sel).show();
            $(".Registe_Loading" + sel).hide();
            if (r[0] == "1") { alert(r[1]); return false; }
            else {
                var GAID = r[0];
                if ((GAID != "") && (GAID != "0")) { loadUserInfo(); GetHongHuangAccountInfo(gt); }
                else { location.href = "http://www.freedom-game.com/uc/Games_HongHuang_StartGame.aspx?ServerID=1"; }
            }
        });
        }
        else if (gt == 3) {
            $.getJSON("http://www." + ajaxUrl + "/CPSAD/HongHuangRegister.aspx?jsoncallback=?", {
                act: "REGISTER",
                txtUserName: un,
                txtPwd: pwd,
                txtPwd2: pwd2,
                service: 8
            },
        function(data) {
            //            var TM = data.ak;
            //            var r = TM.split(":");
            //            $("[submitBtn='registe']" + sel).show();
            //            $(".Registe_Loading" + sel).hide();
            //            if (r[0] == "1") { alert(r[1]); return false; }
            //            else {
            //                var GAID = r[0];
            //                if ((GAID != "") && (GAID != "0")) { loadUserInfo(); GetHongHuangAccountInfo(gt); }
            //                else { location.href = "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?ServerID=1"; }
            //            }

            var TM = data.ak;
            var r = TM.split(":");
            $("[submitBtn='registe']" + sel).show();
            $(".Registe_Loading" + sel).hide();
            if (r[0] == "1") { alert(r[1]); return false; }
            else {
                var GAID = r[0];
                if ((GAID != "") && (GAID != "0"))
                { location.href = "http://www." + ajaxUrl + "/uc/Games_HongHuang_StartGame.aspx?GAID=" + GAID; }
            }
        });
        }
    });
});
/**********注册结束************/

/**********登陆后若手机为空则提示用户填写************/

function updateMobile() {
    var ajaxUrl = window.location.href.toLowerCase();
    if (ajaxUrl.indexOf("freedom-game.com") > -1) {
        ajaxUrl = "http://www.freedom-game.com";
    }
    else if (ajaxUrl.indexOf("ziyoudalu.com") > -1) {
        ajaxUrl = "http://www.ziyoudalu.com";
    }
    if (confirm('您还没有进行手机绑定，是否去个人中心绑定手机号码？')) {
        window.location.href = ajaxUrl + "/uc2/UserInfoEdit.html";
    }

    //    var mobile = prompt("您还没有填写过手机号码，请填写手机号码，进一步完善资料。", "");

    //    if (mobile != null) {
    //        if (mobile == "") {
    //            alert("手机号码不能为空。");
    //            updateMobile();
    //            return;
    //        }
    //        var reg = /^((\(\d{3}\))|(\d{3}\-))?(13\d{1}|15[0-9]{1}|18[0-9]{1}|147)\d{8}$/;
    //        if (!reg.test(mobile)) {
    //            alert("手机号码格式不符合要求。");
    //            updateMobile();
    //            return;
    //        }

    //        var ajaxUrl = window.location.href.toLowerCase();
    //        if (ajaxUrl.indexOf("freedom-game.com") > -1) {
    //            ajaxUrl = "freedom-game.com";
    //        }
    //        else if (ajaxUrl.indexOf("ziyoudalu.com") > -1) {
    //            ajaxUrl = "ziyoudalu.com";
    //        }
    //        $.ajax({
    //            type: "get",
    //            url: "http://www." + ajaxUrl + "/api/Internal/Base/UpdateMobile.ashx?callback=?",
    //            dataType: "jsonp",
    //            data: "mobile=" + mobile + "&j=" + Math.random(),
    //            success: function(objJson) {
    //                alert(objJson.message);
    //                if (objJson.status == 2) {
    //                    updateMobile(ajaxUrl);
    //                }

    //            }
    //        });
    //    }
}
/**********修改手机结束************/
