function save_group_comment()
{
  // Set the backend filename to process
  var filename = 'modules/Groups/ajax_save_comment.php';

  // Get the elements from the page
  var fk_GroupID = document.getElementById('GroupID').value;
  var txt_Comment = document.getElementById('txt_Comment').value;

  // Format any ampersands with URL friendly characters
  var txt_Comment = txt_Comment.replace( /&/g, '%26' );

  // Disable the comment field
  document.getElementById("txt_Comment").disabled = true;

  // Create the parameter list
  var params = "fk_GroupID=" + fk_GroupID + "&txt_Comment=" + txt_Comment; 

  // 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 comment layer
      document.getElementById("comments_cell").innerHTML = xmlhttp.responseText;

      // Clear the existing comment out and reactivate the field
      document.getElementById("txt_Comment").value = "";
      document.getElementById("txt_Comment").disabled = false;
    }
  }

}



function group_change_status( GroupID, StatusID )
{
  // Get confirmation of the request
  if( StatusID == 1 )
    var check = confirm( 'Members of a group will be automatically notified of new group messages, members, and comments.\n\nWould you like to join this group?' );
  else
    var check = confirm( 'Are you sure you want to leave this group?\n\nYou will no longer receive group messages and other notifications.' );

  // Only use the AJAX method if the user wants join or leave the group
  if( check )
  {
    // Set the backend filename to process the save
    var filename = 'modules/Groups/ajax_group_status.php';

    // Create the parameter list
    var params = "GroupID=" + GroupID + "&StatusID=" + StatusID;

    // 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 join/leave field
        if( StatusID == 1 )
          document.getElementById( 'GroupStatus' ).innerHTML = '<a href="#NULL" onclick="group_change_status( ' + GroupID + ', 0 );">Leave this Group</a>';
        else
          document.getElementById( 'GroupStatus' ).innerHTML = '<a href="#NULL" onclick="group_change_status( ' + GroupID + ', 1 );">Join this Group</a>';

        // Reload the page so that the user image refreshes
        window.location = 'index.php?module=Groups&op=view&GroupID=' + GroupID;
      }
    }

  } // end if( watch )

} // end function group_change_status()



function group_save_comment( GroupID )
{
  // First inform the user that the message is being saved
  //document.getElementById( 'MessageStatus' ).style.display = 'block';

  // Disable the text field
  document.getElementById( 'txt_Comment' ).readOnly = true;

  // Set the backend filename to process
  var filename = 'modules/Groups/ajax_save_comment.php';

  // Get the new message body
  var txt_Comment = document.getElementById('txt_Comment').value;

  // Format any ampersands with URL friendly characters
  txt_Comment = txt_Comment.replace( /&/g, '%26' );

  // Create the parameter list
  var params = "GroupID=" + GroupID + "&txt_Comment=" + txt_Comment;

  // 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) )
    {
      // Get the row we will insert before
      var Prepend = document.getElementById('GroupComment');

      // Create the new DIV section node
      var GroupComment = document.createElement("DIV");

      // Fix the properties of the new div
      GroupComment.setAttribute( 'id', 'GroupComment' );
      GroupComment.style.paddingBottom = '10px';

      // Assign the contents of the AJAX POST to the DIV
      GroupComment.innerHTML = xmlhttp.responseText;

      // Prepend the new element to the document
      document.getElementById( 'GroupComments' ).insertBefore( GroupComment, Prepend );

      // Clear the contents of the text field and enable it
      document.getElementById( 'txt_Comment' ).value = "";
      document.getElementById( 'txt_Comment' ).readOnly = false;

    }
  }


} // end function group_save_comment()


function group_cancel_creation()
{
  // Get confirmation of the request
  var cancel = confirm( 'Are you sure you want to cancel the creation of this group?\n\nAll changes will be lost.' );

  // Redirect the page if requested
  if( cancel == true )
    window.location = 'index.php?module=Groups';

} // end function group_cancel_creation()


function group_cancel_changes( GroupID )
{
  // Get confirmation of the request
  var cancel = confirm( 'Are you sure you want to cancel the changes to this group?\n\nAny new changes will be lost.' );

  // Redirect the page if requested
  if( cancel == true )
    window.location = 'index.php?module=Groups&op=view&GroupID=' + GroupID;

} // end function group_cancel_changes()

