function toggleFriendsSearchForm(div, path) {
  if ($(div).style.display == 'none') {
    $(div).innerHTML = "<div class='msearch-loading'><img src='/images/icons/ajax-indicator.gif' alt='loading' class='info-icon' /><span class='info-text'>Loading... Please wait.</span><div class='clear'></div></div>";    
    Element.show(div);
    new Ajax.Updater(div, path, {asynchronous:true, evalScripts:true, method:'get'});
    Element.scrollTo(div);
    return false;
  } else {
    Element.hide(div);
  }
}

function toggleFriendsLoading() {
  if ($('loading-friends1') != null) Element.hide('showing-friends1');
  if ($('showing-friends1') != null) Element.show('loading-friends1');
  if ($('showing-friends2') != null) Element.hide('showing-friends2');
  if ($('loading-friends2') != null) Element.show('loading-friends2');
}

function setFriendAlphaButtonStyles(current) {
  $("alpha-filter1").className = 'alpha-filter';
  $("alpha-filter2").className = 'alpha-filter';
  $("alpha-filter3").className = 'alpha-filter';
  $("alpha-filter4").className = 'alpha-filter';  
  $("alpha-filter" + current).className = 'alpha-filter-active';
}

function refreshFriends(div_check, path, auth_token) {
  if ($(div_check) != null && $("friends-list-container") != null) {
    new Ajax.Updater("friends-list-container", path, { asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(auth_token), method:'get'});
  }
}

function addFriend(uid, path, auth_token) {
  if ($("friend-progress-img-" + uid) != null) Element.show($("friend-progress-img-" + uid));
  new Ajax.Updater("ajax-update-container", path, 
    { 
      asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(auth_token), method:'post',
      onComplete:function(request) { if ($('friend-progress-img-' + uid) != null) Element.hide('friend-progress-img-' + uid); }
    });
  return false;  
}

function removeFriend(uid, path, auth_token) {
  if ($('fbl-' + uid) != null) Element.show('fbl-' + uid);
  new Ajax.Updater("ajax-update-container", path, 
    { 
      asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(auth_token), method:'delete',
      onComplete:function(request) { if ($('fbl-' + uid) != null) Element.hide('fbl-' + uid); }
    });
  return false;
}

function blockFriend(uid, path, auth_token) {
  if ($('fbl-' + uid) != null) Element.show('fbl-' + uid);
  if ($("friend-progress-img-" + uid) != null) Element.show($("friend-progress-img-" + uid));  
  new Ajax.Updater("ajax-update-container", path, 
    { 
      asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(auth_token), method:'delete',
      onComplete:function(request) { 
        if ($('fbl-' + uid) != null) Element.hide('fbl-' + uid); 
        if ($('friend-progress-img-' + uid) != null) Element.hide('friend-progress-img-' + uid);
      }
    });
  return false;
}

function unBlockFriend(uid, path, auth_token) {
  if ($('fbl-' + uid) != null) Element.show('fbl-' + uid);
  new Ajax.Updater("ajax-update-container", path, 
    { 
      asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(auth_token), method:'delete',
      onComplete:function(request) { if ($('fbl-' + uid) != null) Element.hide('fbl-' + uid); }
    });
  return false;
}

function showMessageWindow(path, msg) {
  tb_show('Message Window', path + "?msg=" + encodeURIComponent(msg) + "&KeepThis=true&TB_iframe=true&width=300&height=200", false);  
}

function hideFriendRow(uid) {
  if ($('toggle-stats-' + uid) != null) Element.hide('toggle-stats-' + uid); 
  if ($('friend-row-' + uid) != null) new Effect.Fade('friend-row-' + uid);  
}