/**
 * @Copyright (C) 1999-2006, Game-Cade, Inc.
 * http://www.game-cade.com
 * All Rights Reserved
 * See the product License for more information
 * 
 * @author Seth Morecraft (morecraf@game-cade.com)
 * @date November, 2006
 * Ajax Methods to handle Comment requests and items
 */

var comment_http = new sack();
var target;

function comment_sndReq(url, action, f, art) {
  target = action;

  // Submit a Comment Via Ajax
  if(action == 'submit') {
    // Post this form via http
    comment_http.method = 'POST';
    comment_http.URLString = getFormValues(f);
    comment_http.requestFile = url;
    comment_http.onCompletion = comm_handleResponse;
    comment_http.runAJAX();
    document.getElementById('cognitiveSOULCommentFormC').innerHTML = '<center><img src="media/blueorb.gif"> Posting Comment...</center>';
  }

  // Post the 'Article Form'
  if(action == 'add_new') {
    comment_http.method = 'GET';
    comment_http.URLString = 'action=add_new&selected=' + f + '&article=' + art;
    comment_http.requestFile = url;
    comment_http.onCompletion = comm_handleResponse;
    comment_http.runAJAX();
    document.getElementById('AddCommentDiv').innerHTML = '<center><img src="media/blueorb.gif"> Loading...</center>';
  }

  // Delete the selected entry
  if(action == 'delete') {
    comment_http.method = 'GET';
    comment_http.URLString = 'action=delete&selected=' + f + '&article=' + art;
    comment_http.requestFile = url;
    comment_http.onCompletion = comm_handleResponse;
    comment_http.runAJAX();
    document.getElementById('cognitiveSOUL_comment_' + f).innerHTML = '<center><img src="media/blueorb.gif"> Removing Comment...</center>';
  }

  // Close the 'Comment Form'
 	if(action == 'dispose') {
  		document.getElementById('AddCommentDiv').innerHTML = '';
 	}
}

function comm_handleResponse() {
  result = comment_http.response;
  if(target == 'add_new') {
    document.getElementById('AddCommentDiv').innerHTML = result;
  }
  else {
    // A comment has been submitted - Refresh the entire div
    document.getElementById('ShowCommentsDiv').innerHTML = result;
 	  document.getElementById('AddCommentDiv').innerHTML = '';
  }
}
