var host = "";
$(document).ready(function () {

    $("a.home").click(function () {
        window.location.href = '/Play/home.html';
    })

    $("a.exit").click(function () {
        ajax_post(host + '/Handler/Users.ashx?Action=Logout', '', function (res) {
            if (res.state === '1') {
                window.location.href = '/Play/login.html';
            }
        });

    })

    $("a.refresh").click(function () {
        window.location.reload(true);
    })

    $(".confirmUpdate").click(function () {
        var email = $('input[name=email]').val();
        var oldPwd = $('input[name=oldPwd]').val();
        var newPwd = $('input[name=newPwd]').val();
        var reNewPwd = $('input[name=reNewPwd]').val();

        if (oldPwd === '') {
            $('#d_oldPwd').addClass('has-error');
        } else {
            $('#d_oldPwd').removeClass('has-error');
        }

        if (newPwd != '') {
            if (newPwd != reNewPwd) {
                $('#d_reNewPwd').addClass('has-error');
            }
        }

        if (newPwd === '' || reNewPwd === '') {
            $('#d_newPwd').addClass('has-error');
            $('#d_reNewPwd').addClass('has-error');
        } else {
            $('#d_newPwd').removeClass('has-error');
            $('#d_reNewPwd').removeClass('has-error');
        }

        ajax_post(host + '/Handler/Users.ashx?Action=UpdatePwd', { Email: email, OldPwd: oldPwd, NewPwd: newPwd }, function (res) {
            if (res.state === '1') {
                $('#updatePwd').modal('hide');
                alert(res.info);
            }
        });
    })
})

var Sessioninfo = [];

function getSession(successcallback) {
    ajax_post("/handler/Users.ashx?action=Session", this.login, function (res) {
        if (res.state === "1") {
            localStorage.EmpId = res.data[0].Id;
            localStorage.EmpName = res.data[0].EmpName;
            localStorage.IsAdmin = res.data[0].IsAdmin;
            Sessioninfo.upd(res.data);

            if (typeof successcallback == 'function')
                successcallback(Sessioninfo);
        }
        else {
            alert(res.data);
        }
    },
        function (res, err, e) {
            console.error(err);
        },
        function (res) {
            console.info(res);
        });
}

var headerVue = new Vue({
    el: "#body",
    data: {
        Sessioninfo: Sessioninfo
    },
    methods:{
        backHome: function () {
            window.location.href = '/Play/home.html';
        }
    }
});