﻿/// <reference path="../../../Script/jquery-1.4.1.js" />
$(document).ready(function () {

    ///////Kiểm tra đăng nhập///////////
    $('#btnLogin').click(function () {
        if ($('#txtUsername').val() == '' || $('#txtUsername').val() == 'Tên đăng nhập') {
            alert('Chưa có tên đăng nhập!');
            return false;
        }
        else if ($('#txtPassword').val() == '' || $('#txtPassword').val() == 'Mật khẩu') {
            alert('Chưa nhập mật khẩu!');
            return false;
        }
        else {
            $.ajax({
                type: "POST",
                url: "Component/User/Security/Login.aspx?action=loginmodule",
                data: "action=loginmodule&username=" + encodeURIComponent($("#txtUsername").val()) + "&password=" + encodeURIComponent($("#txtPassword").val()),
                success: function (string) {
                    if (string[0] == "1") {
                        location.reload(true);
                    }
                    else {
                        alert("Tên đăng nhập hoặc mật khẩu sai!");
                    }
                }
            });
        }
    });
    ///////Sự kiện thoát/////////
    $('#btnLogout').click(function () {
        $.ajax({
            type: "POST",
            url: "Component/User/Security/Login.aspx?action=logoutmodule",
            data: "action=logoutmodule",
            success: function (string) {
                if (string[0] == "1") {
                    location.reload(true);
                }                
            }
        });
    });

    ////////Các sự kiện thêm dữ liệu/////////
    //Tên đăng nhập
    $('#txtUsername').focus(function () {
        if ($(this).val() == 'Tên đăng nhập')
            $(this).val('');
    });
    $('#txtUsername').blur(function () {
        if ($(this).val() == '')
            $(this).val('Tên đăng nhập');
    });
    //Mật khẩu
    $('#txtPassword').focus(function () {
        if ($(this).val() == 'Mật khẩu')
            $(this).val('');
    });
    $('#txtPassword').blur(function () {
        if ($(this).val() == '')
            $(this).val('Mật khẩu');
    });
});
