var j_oper =
{
    doman: "/"
}

function loadfile(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);
    }
}

function CallReg() {
    var reg_box = "";
    reg_box += '<div class="j_register j_reg j_post"><div class="j_register_top j_reg j_h"><div class="j_t_btn j_ft"></div>';
    reg_box += '<div class="j_t_btn j_reg " data="t1">登 录</div>';
    reg_box += '<div class="j_t_btn j_reg j_st" data="t2">注 册</div><span class="j_close"></span><div class="j_cl"></div></div><div class="j_box">';
    reg_box += '<div tab="t1" class="j_tab "><table class="j_table"><tbody>';
    reg_box += '<tr><td class="j_t1">用户账号<i>*</i></td><td class="j_t2"><input id="j_login_uid" class="j_input" type="text"/></td><td class="j_t3"><small></small><span>用户账号</span></td></tr>';
    reg_box += '<tr><td class="j_t1">登录密码<i>*</i></td><td class="j_t2"><input id="j_login_pwd" type="password" class="j_input" /></td><td class="j_t3"><small></small><span>登录密码</span></td></tr></tbody><tfoot>';
    reg_box += '<tr><td class="">&nbsp;</td><td class=""><input id="j_login_app" checked="checked" type="checkbox" /><label for="j_login_app">自动登录</label> <a href="/findpass/fil1.html" target="_blank" style=" margin-left:14px;">忘记密码</a></td><td class="">&nbsp;</td></tr></tfoot></table>';
    reg_box += '<div class="j_control"><input type="button" class="jbtn j_button j_login_submit " /><input type="button" class="jbtn j_button j_reg_btn " /></div></div>';
    reg_box += '<div tab="t2" class="j_tab j_tabf"><table class="j_table"><tbody>';
    reg_box += '<tr><td class="j_t1">用户账号<i>*</i></td><td class="j_t2"><input id="j_register_uid" class="j_input" type="text"/></td><td class="j_t3"><small></small><span id="j_x1">不能适用特殊字符及中文</span></td></tr>';
    reg_box += '<tr><td class="j_t1">用户密码<i>*</i></td><td class="j_t2"><input id="j_register_pwd" class="j_input" type="password"/></td><td class="j_t3"><small></small><span id="j_x2">填写您的密码</span></td></tr>';
    reg_box += '<tr><td class="j_t1">确认密码<i>*</i></td><td class="j_t2"><input id="j_register_pwd2" class="j_input" type="password"/></td><td class="j_t3"><small></small><span id="j_x3">重复填写以上密码</span></td></tr></tbody><tfoot>';
    reg_box += '<tr><td class="">&nbsp;</td><td class=""><input id="j_reg_app" checked="checked" type="checkbox" /><label for="j_reg_app">我已阅读并同意<a href="#" target="_blank">注册协议</a></label></td><td class="">&nbsp;</td></tr></tfoot></table><div class="j_control">';
    reg_box += '<input type="button" class="jbtn j_button j_reg_submit " /></div></div></div><div class="j_register_end j_reg j_h"></div></div><div class="j_cover"></div>';
    var Ovid = document.createElement("div");
    $(Ovid).html(reg_box).appendTo(window.document.body);

    $(".j_register").css("left", $(window).width() / 2 - 280);
    $(".j_cover").height($(window.document).height());
    /// <summary>
    /// 标签切换
    /// </summary>
    $(".j_t_btn").click(function () {
        var self = $(this);
        if (self.attr("data") != undefined) {
            $(".j_t_btn").removeClass("j_st");
            self.addClass("j_st");
            $(".j_box .j_tab").each(function (x, d) { if ($(d).attr("tab") == self.attr("data")) { $(d).show() } else { $(d).hide() } });
        }
    });
    /// <summary>
    /// 注册按钮转向
    /// </summary>
    $(".j_reg_btn").click(function () {
        //window.location.href = "/user/reg.html"; //转向注册
        //return;
        var reg_tab = "t2";
        $(".j_t_btn").each(function (x, d) { if ($(d).attr("data") == reg_tab) { $(d).addClass("j_st"); } else { $(d).removeClass("j_st") } });
        $(".j_box .j_tab").each(function (x, d) { if ($(d).attr("tab") == reg_tab) { $(d).show() } else { $(d).hide() } });
    });
    /// <summary>
    /// 关闭注册框
    /// </summary>
    $(".j_close").click(function () {
        $(".j_cover").remove(); $(".j_register").remove();
    })
    /// <summary>
    /// 用户注册
    /// </summary>
    $(".j_reg_submit").click(function () {
        $("#j_x1").html("不能适用特殊字符及中文").css("color", "#eee");
        $("#j_x2").html("填写您的密码").css("color", "#eee");
        $("#j_x3").html("重复填写以上密码").css("color", "#eee");
        var uid = $("#j_register_uid").val();
        var pwd = $("#j_register_pwd").val();
        var pwd2 = $("#j_register_pwd2").val();
        if (uid == "") {
            $("#j_x1").html("用户名不能为空").css("color", "#f00"); return;
        }
        if (pwd == "") {
            $("#j_x2").html("密码不能为空").css("color", "#f00"); return;
        }
        if (pwd != pwd2) {
            $("#j_x3").html("两次密码不一致").css("color", "#f00"); return;
        }
        alert("未完成")
    })

    /// <summary>
    /// 用户登录
    /// </summary>
    $(".j_login_submit").click(function () {
        jQuery.ajax({ url: j_oper.doman + "api/remote/login.ashx?cid=" + Math.random() + "&uid=" + $("#j_login_uid").val() + "&pwd=" + $("#j_login_pwd").val() + "&rem=" + ($("#j_login_app").attr("checked") == true),
            dataType: "jsonp",
            type: "GET",
            jsonp: 'callback',
            error: function (i, k, l) { },
            success: function (msg) {
                if (msg + "" == "200") {
                    window.location.reload();
                } else {
                    alert(msg);
                }
            }
        });
    })
}
$(document).ready(function () {
    $(".xy_call_reg").click(function () { CallReg(); })
    loadfile("/misc/register/reg.css", "css");
})
/*
<script src="/misc/register/register.js" type="text/javascript"></script>
*/