$(window).addEvent('domready', function() {
  if ($('show')) {
    updateSinceId();
    $('show').addEvent('change', updateSinceId);
    $('show').getParent('form').addEvent('submit', function() {
      var index = $('show').selectedIndex;
      if ($('show').options[index].value == 'since-id') {
        var id = parseInt($('since-id').value);
        if ($('since-id').value == '' ||
            !$type(id) || id < 1) {
          alert('Oops, your record ID is invalid');
          return false;
        }
      } else {
        $('since-id').destroy();
      }
    });
  }
  if ($('form')) {
    $('form').addEvent('submit', function() {
      $('submit').set('disabled', 'disabled');
    });
  }
  if ($('country')) {
    updateCountry();
    $('country').addEvent('change', updateCountry);
  }
});

function updateSinceId() {
  var index = $('show').selectedIndex;
  if ($('show').options[index].value == 'since-id') {
    $('since-id').removeClass('hidden');
  } else {
    $('since-id').addClass('hidden');
  }
}

function updateCountry() {
  var index = $('country').selectedIndex;
  if ($('country').options[index].value == 'Canada') {
    $('state-holder').addClass('hidden');
    $('province-holder').removeClass('hidden');
  } else {
    $('state-holder').removeClass('hidden');
    $('province-holder').addClass('hidden');
  }
}
