function page_size_changed(id, params) {
  var current_action = $('search_form').action;     
  assign_to_current_window_location( current_action, ( params + "&page_size=" + $F(id)) );    
}

function page_sort_changed(id, params) {
  var current_action = $('search_form').action; 
  assign_to_current_window_location( current_action, ( params + "&sort=" + $F(id)) );
}

function assign_to_current_window_location( path, parameters ) {
  if( path.indexOf("?") > 0 ) {
    window.location = path + "&" + parameters;
  } else if (parameters.length > 0) {
    window.location = path + "?" + parameters;
  } else {
    window.location = path;
  }
}

function text_changed() {
  if (/^\d{5}(-\d{4})?$/.exec($F('text')) != null) {
    $('radius').enable();
  }
  else {
    $('radius').disable();
  }
}

function facebook_popup(url) {
  window.open(url, 'sharer', 'toolbar=0,status=0,width=626,height=436');
  return false;
} 

function storeIdChanged(selectElement) {
  $$('.store').each(function(s, index) {
    s.hide();
  });
  $('store_' + $('store_id').value).show();
  $('advertiser_stores_attributes_' + selectElement.selectedIndex + '_address_line_1').activate();
  return false;
}

/* 
  Scripts that need to wait for the DOM to be loaded.
*/
document.observe("dom:loaded", function() {

  /* 
    Looks for clicks on the advertiser name on the Google Map popup.
    Scrolls the view done to the #directory element. This is handled
    through the event being bubbled up to the body.
  */
  Event.observe(document.body, "click", function(event) {
    var element = event.element();
    if( element && element.hasClassName('advertiser_name_link') ) {
      Effect.ScrollTo('directory');
      Event.stop(event);
    }
  });

});