

  function addChildAges(children, child_ages)
  {
    var child_age_selects = '';

    if(children > 0)
    {
      child_age_selects = '<label>Et&agrave;</label>';
      for (var c=1; c<=children; c++)
      {
        child_age_selects =  child_age_selects + '<select name="eta_bambini[' + c + ']"' +
          '<option value="0">&lsaquo; 1</option>';
          for(var a=1; a<=18; a++)
          {
            var selected = '';
            if(a == child_ages[c])
              selected = ' selected';
            child_age_selects =  child_age_selects + "\n" + '<option value="'+ a +'"'+selected+'>'+ a +'</option>';
          }
          child_age_selects =  child_age_selects + '</select>';
      }
    }

    $('#child_ages').html(child_age_selects);
  }
    
  $(document).ready(function(){ 
    $('#checkin').datepicker({
      dateFormat: 'dd/mm/yy',
      autoSize: true,
      selectOtherMonths: true,
      numberOfMonths: 2,
      showOn: 'both',
      buttonImage: 'img/datepicker/calendar_icon.png',
      buttonImageOnly: true,
      minDate: '+0d',
      maxDate: '+1y',
      altField: '#checkin_hidden',
      altFormat: 'yy-mm-dd',
      onSelect: function(selectedDate, inst) {
        var checkin_date = $(this).datepicker('getDate');
        $('#checkin_fulldate').html($.datepicker.formatDate('DD, d MM, yy', checkin_date));
        checkin_date.setDate(checkin_date.getDate() + 1);
        $('#checkout').datepicker('option', 'minDate', checkin_date);
        var checkout_date = $('#checkout').datepicker('getDate');
        $('#checkout_fulldate').html($.datepicker.formatDate('DD, d MM, yy', checkout_date));
      }
    });

    $('#checkout').datepicker({
      dateFormat: 'dd/mm/yy',
      autoSize: true,
      selectOtherMonths: true,
      numberOfMonths: 2,
      showOn: 'both',
      buttonImage: 'img/datepicker/calendar_icon.png',
      buttonImageOnly: true,
      minDate: '+1d',
      maxDate: '+1y',
      altField: '#checkout_hidden',
      altFormat: 'yy-mm-dd',
      onSelect: function(selectedDate, inst) {
        var checkout_date = $(this).datepicker('getDate');
        $('#checkout_fulldate').html($.datepicker.formatDate('DD, d MM, yy', checkout_date));
      }
    });

    $('#checkin_hidden').val($.datepicker.formatDate($('#checkin').data('datepicker').settings.altFormat, $('#checkin').datepicker('getDate')));
    $('#checkin_fulldate').html($.datepicker.formatDate('DD, d MM, yy', $('#checkin').datepicker('getDate')));
    $('#checkout_hidden').val($.datepicker.formatDate($('#checkout').data('datepicker').settings.altFormat, $('#checkout').datepicker('getDate')));
    $('#checkout_fulldate').html($.datepicker.formatDate('DD, d MM, yy', $('#checkout').datepicker('getDate')));

    $('#children').change(function() {
      addChildAges(this.value, 0);
    });

    $('#booking_form_submit').click(function() {
      $('#booking_form').submit();
    });
    
  });
