$(document).ready(function()
{
    $(document).on('click', '#overtimeTable td:not(.idTD,.actionTD)', function()
    {
        $.zui.modalTrigger.show({name : 'ajaxModal', url : $(this).parent().attr('url'), backdrop : 'static'});
        return false;
    });

    $(document).on('click', '.deleteOvertime', function()
    {
        if(confirm(v.lang.confirmDelete))
        {
            $(this).text(v.lang.deleting);
            $.getJSON($(this).attr('href'), function(data)
            {
                if(data.result == 'success')
                {
                    if(data.locate) return location.href = data.locate;
                    return location.reload();
                }
                else
                {
                    alert(data.message);
                    if(selecter.parents('#ajaxModal').size()) return $.reloadAjaxModal(1200);
                    return location.reload();
                }
            });
        }
        return false;
    });

    $(document).on('click', '.reviewPass', function()
    {
        if(confirm(v.confirmReview.pass))
        {
            var selecter = $(this);

            $.getJSON(selecter.attr('href'), function(data)
            {
                if(data.result == 'success')
                {
                    if(data.locate) return location.href = data.locate;
                    return location.reload();
                }
                else
                {
                    alert(data.message);
                    return location.reload();
                }
            });
        }
        return false;
    });

    $('.batchPass').on('click', function()
    {
        $.setAjaxForm('#batchReviewForm');
        $('#batchReviewForm').submit();
    });

    /* expand active tree. */
    $('.tree').tree('expandSelect', '.active');
});
