$(function() {
  $('#addanothergliderlink').click(function () {
    elTableRow = $('table#register-gliders tbody tr').clone().get(0);
    $('input[type="text"]', $(elTableRow)).each(function () {
      $(this).val('');
    });

    $('input[type="checkbox"]', $(elTableRow)).each(function () {
      $(this).removeAttr('checked');
    });

    intNoRows = $('table#register-gliders tbody tr').size();

    $('input', $(elTableRow)).each(function () {
      $(this).attr('name', $(this).attr('name').replace(/(.*-)(\d+)$/, '$1' + (intNoRows + 1)));
    });

    elImg = document.createElement('img');
    $(elImg).attr('src', 'images/icons/remove.png').attr('alt', 'Remove');

    elRemoveLink = document.createElement('a');
    $(elRemoveLink).attr('href', '#').attr('title', 'Remove').append($(elImg)).click(function () {
      return removeRow(this);
    });

    $('td.remove', elTableRow).append($(elRemoveLink));

    $(elTableRow).insertAfter('table#register-gliders tbody tr.gliderrow:last');

    return false;
  });

  $('td.remove a').click(function () {
    return removeRow(this);
  });

  $('#input-your-dateofbirth').datepicker({
    changeMonth: true,
    changeYear: true,
    constrainInput: true,
    dateFormat: 'dd/mm/yy',
    duration: 100,
    firstDay: 1,
    showAnim: 'slideDown',
    yearRange: '-70:-15'
  });
});

function removeRow (link) {
  $(link).parents('tr.gliderrow').remove();
  return false;
}//function
