function login() {
    var email_login = document.getElementById("email_login").value;  //text为文本框的id
    var password_login = document.getElementById("password_login").value;
    console.log(email_login)
    send_login(email_login, password_login)

}

function send_login(email_login, password_login) {
    var jq1 = jQuery.noConflict();
    jq1.ajax({
        type: 'GET',
        contentType: 'application/json;charset-utf-08',
        dataType: 'text',
        url: '/login_check',   /* Call python function in this script */
        data: {"email": email_login, "password": password_login},
        success: callback
    });

    function callback(data, status) {
        var res = data;
        if (res == "signup") {
            window.confirm("该邮箱尚未注册！");
        } else if (res == "wrong") {
            window.confirm("密码错误！");
        } else if (res == "ok") {
            localStorage.setItem("email", email_login);
            window.confirm("登录成功！");
            // window.location.href = "/static/user/user_booklist.html";
            window.location.href = "/static/user/qiangwei_index.html";
        } else if (res == "admin") {
            localStorage.setItem("email", email_login);
            window.confirm("登录成功！");
            window.location.href = "/static/user/qiangwei_index_admin.html";
        } else {
            window.confirm("请重试！");
        }
    }
}


function sign_up() {
    //text为文本框的id
    var email_signup = document.getElementById("email_signup").value;  //text为文本框的id
    var password_signup = document.getElementById("password_signup").value;  //text为文本框的id
    var username_signup = document.getElementById("username_signup").value;
    console.log(email_signup)
    send_signup(email_signup, username_signup, password_signup)
}

function send_signup(email_signup, username_signup, password_signup) {
    var jq1 = jQuery.noConflict();
    jq1.ajax({
        type: 'GET',
        contentType: 'application/json;charset-utf-08',
        dataType: 'text',
        url: '/signup_check',   /* Call python function in this script */
        data: {"email": email_signup, "username": username_signup, "password": password_signup},
        success: callback2
    });

    function callback2(data, status) {
        var res = data;
        if (res == "NO") {
            window.confirm("该邮箱尚已注册！");
        } else if (res == "null") {
            window.confirm("邮箱为空值！请重新输入！");
        } else {
            localStorage.setItem("email", email_signup);
            window.confirm("注册成功！");
            window.location.href = "/static/pdfjs/web/calibration.html";
        }
    }
}


function cambiar_login() {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_login";
    document.querySelector('.cont_form_login').style.display = "block";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_login').style.opacity = "1";
    }, 400);

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.display = "none";
    }, 200);
}

function cambiar_sign_up(at) {
    document.querySelector('.cont_forms').className = "cont_forms cont_forms_active_sign_up";
    document.querySelector('.cont_form_sign_up').style.display = "block";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.opacity = "1";
    }, 100);

    setTimeout(function () {
        document.querySelector('.cont_form_login').style.display = "none";
    }, 400);


}


function ocultar_login_sign_up() {

    document.querySelector('.cont_forms').className = "cont_forms";
    document.querySelector('.cont_form_sign_up').style.opacity = "0";
    document.querySelector('.cont_form_login').style.opacity = "0";

    setTimeout(function () {
        document.querySelector('.cont_form_sign_up').style.display = "none";
        document.querySelector('.cont_form_login').style.display = "none";
    }, 500);

}