$(document).ready(function()
{
    $('#begin').change(function()
    {
        var begin = $('#begin').val().replace(/-/g, '/');

        if(begin)
        {
            var url = createLink('lieu', 'ajaxGetBalance', 'date=' + begin);
            $.getJSON(url, function(data)
            {
                if(data.result == 'success') $('.balanceTip').html(data.balanceTip);
            });
        }
    });

    $('#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=lieu&begin=' + begin + '&start=' + start + '&end=' + end + '&finish=' + finish);
        $.getJSON(url, function(data)
        {
            if(data.result == 'success') $('#hours').val(data.hours).change();
        });
    });

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