$(document).ready(function() {
  var tabs = $('#tabs').tabs();
  var form = $('#content-area form');
  $('#content div.messages').find('li:contains("Thank you, your submission has been received.")').remove();
  $('<p>These comments will be filed in the FCC\'s open docket number 09-191.</p>').css('font-size', '.9em').insertAfter('#edit-submit');

  function increment_form_action(current_index) {
    // Don't increment if there aren't any tabs left
    if (current_index <= 1) {
      var action = form.attr('action');
      form.attr('action', action.split('#')[0] + '#tabs-' + (current_index + 2));
    }
  }

  function set_claim_field(index) {
    var claim = $('#tabs-' + (index + 1)).find('p:first').text();
    $('#webform-component-their_claim textarea').text(claim).attr('readonly', 'readonly');
  }

  // Set form action to next tab when the page loads
  var current_tab = tabs.tabs('option', 'selected');
  increment_form_action(current_tab);
  set_claim_field(current_tab);

  tabs.bind('tabsshow', function(event, ui) {
    increment_form_action(ui.index);
    set_claim_field(ui.index);
  });

  form.appendTo('#tab-content');
  $('<div>').css('clear', 'both').appendTo('#tab-content');
  $('#content-area form .resizable-textarea').removeClass('resizable-textarea');
  $('<div>').css('clear','both').appendTo('#tab-content');
});

