$(document).ready(function()
{
    $('#begin, #start, #end, #finish').change(function()
    {
        var begin  = $('#begin').val().replace(/-/g, '/');
        var end    = $('#end').val().replace(/-/g, '/');
        var start  = $('#start').val();
        var finish = $('#finish').val();
        if(!begin || !end || !start || !finish) return false;

        var url = createLink('attend', 'ajaxGetHours', 'type=overtime&begin=' + begin + '&start=' + start + '&end=' + end + '&finish=' + finish);
        $.getJSON(url, function(data)
        {
            if(data.result == 'success') $('#hours').val(data.hours).change();
        });
    });

    $('#begin').change();
})
