﻿function login() {
    loginuser = $("#user").val();
    loginpass = $("#pass").val();
    var url = "ashx/login.ashx?user=" + encodeURI(encodeURI(loginuser)) + "&pass=" + encodeURI(encodeURI(loginpass)) + "&t=" + new Date().getTime();
    $.get(url, function (data) {
        if (data == "usererr") {
            alert("用户与密码不符合！");
        }
        else {
            $(".login_div").html(data);
        }
    })
}
function logineixt() {
    var url = "ashx/session.ashx?exit=yes" + "&t=" + new Date().getTime();
    $.get(url, function (data) {
        if (data == "yes") {
            top.location = "/cn";
        }
    })
}
function showreg() {
    var url = "ashx/showreg.ashx?t=" + new Date().getTime();
    $.get(url, function (data) {
        $(".regdiv").html(data);
    })
    showdiv();
}
function register() {
    ruser = $("#reguser").val();
    rpass = $("#regpass").val();
    rchpass = $("#regchpass").val();
    rmail = $("#regmail").val();
    if (ruser == "") {
        alert("用户名不能为空！");
        return;
    }
    if (rpass != rchpass) {
        alert("两次密码不匹配！");
        return;
    }
    if (checkmail(rmail) == false) {
        alert("电子邮件不正确！");
        return;
    }
    if (ruser != "" && rchpass != "" && rmail != "") {
        var url = "ashx/register.ashx?user=" + encodeURI(encodeURI(ruser)) + "&pass=" + encodeURI(encodeURI(rchpass)) + "&mail=" + encodeURI(encodeURI(rmail)) + "&t=" + new Date().getTime();
        $.get(url, function (data) {
            if (data == "yes") {
                var url = "ashx/login.ashx?user=" + encodeURI(encodeURI(ruser)) + "&pass=" + encodeURI(encodeURI(rchpass)) + "&t=" + new Date().getTime();
                $.get(url, function (data) {
                    $(".login_div").html(data);
                })
            }
            else {
                alert(data);
            }
        })
    }
}
function showdiv() {
    $(".regdiv").toggle("600");
}
function checkmail(obj) {
    if (obj.length > 0 && !obj.match(/^.+@.+$/)) {
        return false;
    }
    if (obj.length == 0) {
        return false;
    }
    else {
        return true;
    }
}
