﻿function popLogin() {
    showPOP("登录", 400, 200, "/User/Pop.Login.htm");
}
function checkLogin() {
    if (!isEmail($("#tbUName").val())) { alert("未填写帐号。\n\n友情提示：登录帐号为注册时填写的邮箱地址。"); return; }
    if ($.trim($("#tbUPwd").val()) == "") { alert("未填写登录密码。"); return; }
    var re = /^[\da-z]{4,5}$/gi;
    if (!re.test($("#tbUCode").val())) { alert("验证码不正确。"); return; }

    $.ajax({
        type: "POST",
        url: "/User/Login.aspx?do=login&rnd=" + Math.random(),
        dataType: "text",
        data: "UName=" + $("#tbUName").val() + "&UPwd=" + $("#tbUPwd").val() + "&UCode=" + $("#tbUCode").val() + "&from=" + $("#tbFrom").val() + "&url=" + $("#tbUrl").val(),
        success: function (data) {
            $("#imgUCode").attr("src", "/VerifyCode.aspx?type=login&rnd=" + Math.random());
            switch (data) {
                case "-1":
                    alert("验证码不正确。");
                    break;
                case "-2":
                    alert("帐号格式不正确。");
                    break;
                case "-3":
                    alert("登录帐号或密码不正确。");
                    break;
                case "-4":
                    alert("当前帐号不可用，请与客服联系。");
                    break;
                case "1":
                    window.location.reload(true);
                    break;
                default:
                    top.window.location.replace(data);
                    break;
            }
        }
    });
}


//加载pop窗口
function showPOP(title, width, height, url) {
    showBlock();

    var top = Math.floor(($(window).height() - height - 10) / 2);
    var left = Math.floor(($(window).width() - width - 10) / 2);

    if ($("#__POP").length < 1) {
        var oPOP = $("<div id='__POP' />")
                       .width(width + 10)
                       .height(height + 10)
                       .css({ "left": left + "px", "top": top + "px" });

        if ($("form").length > 0) {
            oPOP.appendTo($("form:eq(0)"));
        } else {
            oPOP.appendTo($(document.body));
        }
    }

    $("#__POP").html("<div id='__POPTitle'><span>" + title + "</span><a onclick='hidePOP();' title='关闭'></a></div><div id='__POPBody'></div>");

    url += (url.indexOf("?") == -1) ? "?" : "&";
    url += "rnd=" + Math.random();
    $("#__POPBody").load(url);

    $("#__POP").show();
}

//隐藏pop窗口
function hidePOP() {
    hideBlock();
    $("#__POP").hide();
}
