/**
 * 引入base方法
 */
document.write("<script language=javascript src='static/js/common/base.js'></script>");

/**
 *  获取用户信息
 */
var user = null;
function getAccountInfo() {
    $.get('/account', function(data) {
        if (data.content) {
            window.loginInfo = data;
            user = data.content;
            $('#re_email').val(user.email);
            $('#re_tel').val(user.tel);
            $('#re_name').val(user.name);
        } else {
            window.location.href = "/signIn";
        }
    });
}

/**
 * 重置密码
 */
function resetPassWord() {
    if (checkUserInfo()) {
        var userInfo = {password: $('#re_pwd').val()};
        $.ajax('resetPassword/' + user.id, {
            data: userInfo,
            method: 'POST',
            async: false,
            success: function() {
                alert('密码修改成功');
                window.location.href = "/signIn";
            },
            error: function (error) {
                alert(error.responseText);
            }
        });
    }
}
/**
 * 检验信息
 */
function checkUserInfo() {
    var result = true;
    if (isEmpty($('#re_pwd').val())) {
        alert("密码不能为空");
        result = false;
    }
    if (result && isEmpty($('#re_confirmPwd').val())) {
        alert("请确认密码");
        result = false;
    }
    if (result && ($('#re_pwd').val() != $('#re_confirmPwd').val())) {
        alert("两次密码不一致");
        result = false;
    }
    return result;
}


$(function() {
    'use strict';

    // 监听页面滚动
    $(window).scroll(function() {
        if($(window).scrollTop() >= 400) {
            $('#nav').addClass('on');
        } else {
            $('#nav').removeClass('on');
        }
    });

    // 查询登录信息
    getAccountInfo();

    // 重置密码
    $('#link-reset').click(resetPassWord);
});