// Popup function, taken from http://www.htmlcodetutorial.com/linking/linking_famsupp_72.html
function popup(mylink, windowname)
{
  if (! window.focus)return true;
  var href;
  if (typeof(mylink) == 'string')
     href=mylink;
  else
     href=mylink.href;
  // Append the referer in the qs, as IE doesn't include it in the HTTP request for a
  // window.open
  if (/\?/.exec(href)) {
    href = href + '&referer=' + window.location.href
  } else {
    href = href + '?referer=' + window.location.href
  }
  window.open(href, windowname, 'width=700,height=500,scrollbars=yes,resizable=yes');
  return false;
}

// Hides a sidebar_block if necessary.
function hide_sidebar_block(element) {
  parent_id = jQuery(element).attr('id');
  if (sidebar_prefs.data[parent_id] == null)
  {
    jQuery('#' + parent_id + ' .sidebarcontent').hide();
    jQuery('#' + parent_id + ' .sidebarheader').toggleClass('sidebarheaderclosed');
  }
}

// Removes default text, if present, and un-greys the search box
function defaultable_field_on_click(input, default_text)
{
  input = jQuery(input); // Possibly redundant, but does no harm
  if (input.val() == default_text)
  {
    input.val('');
    input.removeClass('default');
  }
}

// Puts in default text, if currently blank, and re-greys the search box
function defaultable_field_on_blur(input, default_text)
{
  input = jQuery(input); // Possibly redundant, but does no harm
  if (jQuery.trim(input.val()) == '')
  {
    input.val(default_text);
    input.addClass('default');
  }
}
