function postThreadedGroupComment(url, grpId, replyToThreadCommentId, uniqId){

	tinyMCE.triggerSave(true,true);

	var pingBody;

	if (uniqId == '') {
	   pingBody = $F('pingBody');
	} else {
	   pingBody = $F('addComment-' + uniqId);
	}

	var req = gatherAjax.Request({
		url: url,
		options: {
			method: 'POST',
			parameters: {
				grpId: grpId,
				replyToThreadCommentId: replyToThreadCommentId,
				pingBody: pingBody
			},
			onSuccess: function(transport) {

				if(transport.responseText.isJSON())
				{
				    responseObj = transport.responseText.evalJSON();

				    if(responseObj.success) {
				        window.location.href = responseObj.redirectUrl + '#pings';
				        window.location.reload (true);
				    } else {

				    	//display the appropriate error
				        if(responseObj.message == 'pingLimit') {
				            if (uniqId == '') {
				                $('mainPingTxtArea').hide();
	                            $('pingLimitErrorContent').show();
	                            $('pingBtnPost').hide();
	                        } else {
	                           if ($('pingLimitError-' + uniqId)) {
	                               $('pingLimitError-' + uniqId).show();
	                               $('commentBox-' + uniqId).hide();
	                            } else {
	                               alert(responseObj.message);
	                            }
	                        }
                        } else if(responseObj.message == 'emptyPing') {
                            if (uniqId == '') {
				                $('emptyPingErrorContent').style.display='block';
				            } else {
                               if ($('emptyPingError-' + uniqId)) {
                                   $('emptyPingError-' + uniqId).show();
                                } else {
                                   alert(responseObj.message);
                                }
				            }
				       }

		               if(uniqId == ''){
		                   if($('pingBtnPost')) {
	                            $('pingBtnPost').enable();
	                            removeClass($('pingBtnPost'), 'selected');
	                            $('pingBtnPost').value='Submit';
	                            $('pingBtnPost').style.cursor='default';
	                            document.body.style.cursor='default';
		                   }
		               } else {
		                   if($('commentBtnPost-' + uniqId)) {
			                     $('commentSubmitting-' + uniqId).hide();
			                     $('commentBtnPost-' + uniqId).show();
		                   }
		               }

				       $('pingBody').value = '';
	               }
				}
     		},
     		onError: function(transport){
     		}
     	}
	});

}

function removeGroupCommentThread(form){

	var elId = 'grpPingThread-' + form.grpPingId.value;
	var el = parent.document.getElementById(elId);

	if(typeof parent.Effect != 'undefined') {
		new parent.Effect.DropOut(el);
	} else {
		el.hide();
	}

	gatherAjax.Request({
		url: form.action,
		options: {
    		method: 'POST',
    		parameters: form.serialize(true),
      		onSuccess: function(transport) {

		        if(transport.responseText.isJSON()){

		        	var response = transport.responseText.evalJSON();

		        	if(response.success) {

			        }else{
			        	//error!
			        }

		        } else {

		          parent.myLightWindow.deactivate();

		          if(form.moduleInstanceId.value){
		          	parent.document.getElementById('divModuleInstance_' + moduleInstanceId).innerHTML = transport.responseText;
		          }else{
		          	parent.document.getElementById('groupPings').innerHTML = transport.responseText;
		          }

		        }

      		},
      		onError: function(transport){myLightWindow.deactivate();}
   		}
	});
}

function profilePingPost(form){

	pingPost(form, 'pingSection');
}

function groupPingPost(form){
	pingPost(form);
}

function pingPost(form) {

	if($('emptyPingErrorContent')){
		$('emptyPingErrorContent').style.display='none';
	}

	// Blur both first in case of error states
	if($('pingBtnPost')) {
		$('pingBtnPost').blur();
		addClass($('pingBtnPost'), 'selected');
		$('pingBtnPost').value='Submitting...';
		$('pingBtnPost').style.cursor='wait';
		document.body.style.cursor='wait';
	}

	var req = gatherAjax.Request({
		url: form.url.value,
		options: {
			method: 'POST',
			parameters: form.serialize(true),
			onSuccess: function(transport) {

				if(transport.responseText.isJSON())
				{
				    responseObj = transport.responseText.evalJSON();

				    if(responseObj.success) {
				        window.location.href = responseObj.redirectUrl + '#pings';
				        window.location.reload (true);
				    } else {

				    	//display the appropriate error
				        if(responseObj.message == 'pingLimit') {
                            $('pingBody').style.display = 'none';
                            document.getElementById('pingBtnPost').disabled = true;
                            $('pingLimitErrorContent').style.display='block';
                        } else  if(responseObj.message == 'emptyPing') {
				            $('emptyPingErrorContent').style.display='block';
				       }

				       $('pingBody').value = '';

						if($('pingBtnPost')) {
						    $('pingBtnPost').enable();
						    removeClass($('pingBtnPost'), 'selected');
						    $('pingBtnPost').value='Submit';
						    $('pingBtnPost').style.cursor='default';
						    document.body.style.cursor='default';
						}
	               }
				}
     		},
     		onError: function(transport){
     		}
     	}
	});
};

  function togglePingingFields() {

    if ($('allowPings').checked == true) {

      // if "Allow pings on this article" is checked, then enable all the pinging fields and change the text styles
      $('pingEveryone').disabled = false;
      $('pingConnectionsOnly').disabled = false;
      $('moderatePings').disabled = false;
      $('pingEmail').disabled = false;

      $('pingEveryone').checked = true;

      $('moderatePingsLabelText2').removeClassName('disabledLabel');
      $('pingCriteriaEveryoneLabelText').removeClassName('disabledLabel');
      $('pingCriteriaConnectionsLabelText').removeClassName('disabledLabel');
      $('pingEmailLabel').removeClassName('disabledLabel');
    } else {

      // if it's not checked, then disable the pinging fields and change the text styles
      $('pingEveryone').disabled = true;
      $('pingConnectionsOnly').disabled = true;
      $('moderatePings').disabled = true;
      $('pingEmail').disabled = true;

      $('moderatePingsLabelText2').addClassName('disabledLabel');
      $('pingCriteriaEveryoneLabelText').addClassName('disabledLabel');
      $('pingCriteriaConnectionsLabelText').addClassName('disabledLabel');
      $('pingEmailLabel').addClassName('disabledLabel');
    }
  }

function hidePingLimitErrorAndShowPingBody(uniqId){
	if (uniqId == '') {
		$('mainPingTxtArea').show();
		$('pingLimitErrorContent').hide();
		$('pingBtnPost').show();
    } else {
        $('commentBox-' + uniqId).show();
        $('pingLimitError-' + uniqId).hide();
    }
}

var comMesg = [ 'Ping action failed. Please try again later.' ];

function profilePingStatusHandler(id, act, removeIfModAccepted, url, viewedMemberId){

	var el = $('profileComment-'+id);

	if(act == 'delete' || act == 'remove' || act == 'decline') {
		if(typeof Effect != 'undefined') {
			new Effect.DropOut(el);
		} else {
			$(el).hide();
		}
	} else if(act == 'accept') {

		// Pending Comments page requires both states remove the comment from the list
		if(removeIfModAccepted) {
			if(typeof Effect != 'undefined') {
				new Effect.DropOut(el);
			} else {
				$(el).hide();
			}
		} else {

			var removeLink = "<a href=\"#\" onclick=\"profilePingStatusHandler('"+id+"','"+act+"',"+removeIfModAccepted+",'"+url+"','"+viewedMemberId+"'); return false;\" class=\"med_gray\">remove ping</a>";

			$(el).removeClassName('profileCommentPending');
			$('commentTooltip-'+id).hide();
			$('commentControls-'+id).update(removeLink);
			$(el).style.backgroundColor = 'white';
		}
	} else {
		alert(comMesg[0]);
		return false;
	}

	var ajaxParameters = { profileCommentId: id, action: act, viewedMemberId: viewedMemberId};

	pingStatusHandler(el, act, url, ajaxParameters, 'pingSection');
}

function groupPingStatusHandler(id, act, removeIfModAccepted, url, viewedGroupId, moduleInstanceId, redirectUrl){

	var el = $('grpPing-'+id);
	var childPingEl = $('childPings-'+id);

	if(act == 'delete' || act == 'remove' || act == 'decline') {

		if(typeof Effect != 'undefined') {
			new Effect.DropOut(el);

			if(childPingEl){
				new Effect.DropOut(childPingEl);
			}
		} else {
			$(el).hide();

			if(childPingEl){
				$(childPingEl).hide();
			}
		}

	} else if(act == 'accept') {

		// Pending Comments page requires both states remove the comment from the list
		if(removeIfModAccepted) {
			if(typeof Effect != 'undefined') {
				new Effect.DropOut(el);
			} else {
				$(el).hide();
			}
		} else {

			var removeLink = "<a href=\"#\" class=\"t11\" onclick=\"groupPingStatusHandler('"+id+"','"+act+"',"+removeIfModAccepted+",'"+url+"','"+viewedGroupId+"','"+moduleInstanceId+"'); return false;\">remove group comment</a>";

			$('commentTooltip-'+id).hide();
			$('commentControls-'+id).update(removeLink);
			$(el).style.backgroundColor = 'white';
		}
	} else {
		alert(comMesg[0]);
		return false;
	}

	var replacementDiv = 'divModuleInstance_' + moduleInstanceId;

	if(!moduleInstanceId || moduleInstanceId == '' || moduleInstanceId == -1){
		moduleInstanceId = -1;
		replacementDiv = 'groupPings';
	}

	ajaxParameters = { groupPingId: id,	action: act, grpId: viewedGroupId, moduleInstanceId: moduleInstanceId, redirectUrl: redirectUrl};

	pingStatusHandler(el, act, url, ajaxParameters, replacementDiv);
}

function pingStatusHandler(el, action, url, ajaxParameters, replacementDiv){

	var req = gatherAjax.Request({
		url: url,
		options: {
			method: 'POST',
			parameters: ajaxParameters,
			onSuccess: function(transport) {

				if(action == 'delete' || action == 'remove' || action == 'deny' || action == 'decline') {
					$(el).remove();
				}

				$(replacementDiv).innerHTML = transport.responseText;
				loadTinyMCEforGrpPing();
     		},
     		onError: function(transport){

     			$(el).show();
     			alert(comMesg[0]);
     		}
     	}
	});

}

function submitProfilePingSettingEdits(form){

	var divToUpdate = document.getElementById('pingSection');

	submitPingSettingEdits(form, divToUpdate);

	myLightWindow.deactivate();
}

function submitGroupPingSettingEdits(form, moduleInstanceId){

	var loadingDiv = parent.document.getElementById('divModuleInstanceLoading_' + moduleInstanceId);

	if (loadingDiv) {
		loadingDiv.style.display = "block";
	}

	var divToUpdate = parent.document.getElementById('divModuleInstance_' + moduleInstanceId);

	submitPingSettingEdits(form, divToUpdate);

	parent.myLightWindow.deactivate();
}

function submitPingSettingEdits(form, replacementDiv) {

  clearOldErrors(form);

  gatherAjax.Request({ url: form.action,
  options: { asynchronous: false, method: "post",
  parameters: $(form).serialize(true),
  onSuccess: function(transport) {
    try {

        replacementDiv.innerHTML = transport.responseText;
    } catch (e) {
      var sectionId = "pingSection";
      $(sectionId).innerHTML = transport.responseText;
      myLightWindow.deactivate();
      Nifty("div.roundedCorners","top");
      new Effect.Highlight("profileCommentSettings", { startcolor: "#F3901C" });
    }
  }}});


}


function showAllGroupComments(parentGrpPingId){

	$$('div[id^="childComment-' + parentGrpPingId + '"]').each(function(d) {
        d.style.display='';
    });

}