function Status_Hide()
{
  Status_Persist( 0 );

  document.getElementById( 'status_popup' ).style.display = 'none';
  document.getElementById( 'status_arrow' ).innerHTML = '<img src="themes/Default/images/Status/arrow_up.gif" onclick="Status_Show();" />';
}

function Status_Show()
{
  Status_Persist( 1 );

  document.getElementById( 'status_popup' ).style.display = 'block';
  document.getElementById( 'status_arrow' ).innerHTML = '<img src="themes/Default/images/Status/arrow_down.gif" onclick="Status_Hide();" />';
}

function Status_Persist( PersistState )
{
  // Set the backend filename to process
  var filename = 'modules/Account/ajax_status_persist.php';

  // Create the parameter list
  var params = "PersistState=" + PersistState;

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Intentionally left blank
    }
  }

} // end function Status_Persist()


function UpdateStatusOnlineCount()
{
  // Function is used to getting the number of online users
  // and keeping the tab updated with the correct number

  // Set the backend filename to process
  var filename = 'modules/Account/ajax_online_count.php';

  // Create the parameter list
  var params = "";

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Update the status bar tab if the result has changed
      if( document.getElementById("StatusOnlineDisplayCount").innerHTML != xmlhttp.responseText )
      {
        var StatusUpdate = true;
        document.getElementById("StatusOnlineDisplayCount").innerHTML = xmlhttp.responseText;
      }
      else
      {
        var StatusUpdate = false;
      }

      // Set the variable with the new number
      document.getElementById("StatusOnlineCount").value = xmlhttp.responseText;

      // Adjust the status online height to accomodate the users
      if( parseInt( xmlhttp.responseText ) > 6 )
        document.getElementById("status_online").style.height = '330px';
      else
        document.getElementById("status_online").style.height = ( 38 * parseInt( xmlhttp.responseText ) + 21 ) + 'px';

      // Now update the table only if the value has changed
      if( StatusUpdate )
        UpdateStatusOnlineTable();
    }
  }

}

function UpdateStatusOnlineTable()
{

  // Set the next filename to process
  var filename = 'modules/Account/ajax_online_users.php';

  // Create the parameter list
  var params = "";

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Update the online user table if it has changed
      document.getElementById("StatusOnlineDiv").innerHTML = xmlhttp.responseText;
    }
  }

}

function StatusOnline()
{
  // Function is used for toggling the StatusOnline on and off

  // Start by getting the current status
  var StatusOnline = document.getElementById( 'StatusOnline' ).value

  // Either open or close the window
  if( StatusOnline == 0 )
  {
    // First open up the window
    document.getElementById( 'status_online' ).style.display = 'block';

    // Fix the borders and color so it appears active
    document.getElementById( 'status_activity' ).style.backgroundColor = '#ffffff';
    document.getElementById( 'status_activity' ).style.borderLeft = '1px solid #000000';
    document.getElementById( 'status_activity' ).style.borderRight = '1px solid #000000';
    document.getElementById( 'status_notifications' ).style.borderTop = '1px solid #000000';
    document.getElementById( 'status_help' ).style.borderTop = '1px solid #000000';

    // Reset the StatusOnline variable
    document.getElementById( 'StatusOnline' ).value = 1;
  }
  else
  {
    // First close up the window
    document.getElementById( 'status_online' ).style.display = 'none';

    // Fix the borders and color so it appears closed
    document.getElementById( 'status_activity' ).style.backgroundColor = '#e5e5e5';
    document.getElementById( 'status_activity' ).style.borderLeft = '1px solid #b5b5b5';
    document.getElementById( 'status_activity' ).style.borderRight = '1px solid #b5b5b5';
    document.getElementById( 'status_notifications' ).style.borderTop = '1px solid #b5b5b5';
    document.getElementById( 'status_help' ).style.borderTop = '1px solid #b5b5b5';


    // Reset the StatusOnline variable
    document.getElementById( 'StatusOnline' ).value = 0;
  }

}

function StatusLoader()
{
  updateStatus();
  setInterval( "updateStatus()", 20000 );
}

function updateStatus()
{
  // Begin the polling process

  // Set the next filename to process
  var filename = 'modules/Account/ajax_status_update.php';

  // Create the parameter list
  var params = "";

  // Process the AJAX POST request
  AJAX_POST( filename, params );

  // Update the form when the AJAX process finishes
  xmlhttp.onreadystatechange = function()
  {
    if( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) )
    {
      // Try handling the process of updating the status bar
      // If we fail, we will provide the user with an error
      try
      {
        var StatusResponse = eval( xmlhttp.responseText );

        document.getElementById( 'status_popup' ).innerHTML = StatusResponse[0];
        document.getElementById( 'status_text' ).innerHTML = StatusResponse[1];
      }
      catch(err)
      {
        document.getElementById( 'status_text' ).innerHTML = 'There was an error loading the status bar.  Trying again...';
      }

      // Update the online user table if it has changed
     //document.getElementById("status_popup").innerHTML = xmlhttp.responseText;
    }
  }


} // end function StatusLoader()
