// $Id: comments.js 5056 2009-03-12 20:24:31Z sbillman $
var objAjaxRequest = null;

var message_array = new Object;
message_array.en = new Array(
   "Sorry, you've already voted on this comment.",
   "Sorry, an unexpected error has occured.  Please try resubmitting your vote.",
   "Comment Title must be less than 100 characters.",
   "Comment body too long, please shorten and resubmit.",
   "Comment body must be longer than 1 character, please try again.",
   "Loading",
   "This should only be used for offensive comments. If you agree with the comment, click the plus sign. If you disagree, click the minus sign instead."
);
message_array.es = new Array(
   "Lo sentimos, pero usted ya ha votado en este comentario.",
   "Disculpe, ha ocurrido un error inesperado.  Por favor vote otra vez.",
   "El título del comentario debe tener menos de  100 caracteres.",
   "Su comentario es muy largo, por favor córtelo y vuelva a enviarlo.",
   "El cuerpo de comentario debe ser más largo que 1 carácter, por favor vuelva a intentarlo.",
   "Cargando",
   "Esto debe usarse solamente para comentarios ofensivos.  Si está de acuerdo con el comentario haga click en el signo de más.  Si no está de acuerdo con el comentario haga click en el signo de menos."
);

var language_id;
if( 'string' != typeof language_id || 'undefined' == typeof message_array[language_id] ){
   language_id = 'en';
}
var message = message_array[language_id];

// ######################################
// PURPOSE: 	All the below functions simply form the POST URL arguments in preperation to sending 
//   to the backend CGI script, a couple have some simple logic to do some post cgi submission tasks, 
//   however these should be very limited if placed in these functions.
	
	
	// ##################
	// PURPOSE: Displays all comments given an assetType (No regards to Asset ID's)
	function displayAssetTypeComments( assetType ){
		var argumentString = "function=fetchAllAssetTypeComments&assetType=" + assetType;
		runCommentCGI( argumentString );
	}
	// ##################
	
	// ##################
	// PURPOSE: Selects -ALL- comments from the DB with no narrowing criteria at all, results are limited
	//   to the value you set 'numberComments' to.
	function displayComments( startResult, numberComments ){
		var argumentString = "function=fetchComments&startResult=" + startResult + "&numberComments=" + numberComments;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Selects -ALL- assets from the DB with no narrowing criteria at all, results are limited
	//   to the value you set 'numberAssets' to.
	function displayAssets( numberAssets ){
		var argumentString = "function=fetchAssets&numberAssets=" + numberAssets;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Selects -ALL- End Users from the DB with no narrowing criteria at all, results are limited
	//   to the value you set 'numberAssets' to.
	function displayEndUsers( numberUsers ){
		var argumentString = "function=fetchEndUsers&numberUsers=" + numberUsers;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Selects -ALL- Administrators from the DB with no narrowing criteria at all, results are limited
	//   to the value you set 'numberAssets' to.
	function displayAdministrators( numberAdmins ){
		var argumentString = "function=fetchAdministrators&numberAdmins=" + numberAdmins;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Selects -ALL- Words from the wordFilter DB
	function displayWordFilter(){
		var argumentString = "function=fetchWordFilter";
		runCommentCGI( argumentString );
	}
	// ##################


	// ##################
	// PURPOSE: Shows end user stats
	function displayUserStats( limit ){
		var argumentString = "function=fetchUserStats&limit=" + limit;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Shows asset stats
	function displayAssetStats( limit ){
		var argumentString = "function=fetchAssetStats&limit=" + limit;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Shows comment stats (Statistics on actual comments that is)
	function displayCommentStats( limit ){
		var argumentString = "function=fetchCommentStats&limit=" + limit;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Formulates string to call CGI function to display all Flagged Comments
	function displayFlaggedComments( numberComments ){
		var argumentString = "function=fetchFlaggedComments&numberComments=" + numberComments;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Sends a string to get the Welcome Statistics for admin users.
	//   This could include things such as total number of comments, total number 
	//     of comments in the past 24 hours, total unique commenters, etc...
	function fetchWelcomeStats() {
		var argumentString = "/cgi-bin/mi/comments/comments_cgi.pl?function=fetchWelcomeStats";
		$("#welcomeStats").load(argumentString, function() {
			$("#welcomeStats").css({"display" : "block"} );
		});
	}
	// ##################

	// ##################
	// PURPOSE: Formulates the argument string needed to rate a comment with + 1 positive vote
	function rateCommentPlus( commentID, voterName ) {
		var argumentString = "function=rateCommentPlus&commentID=" + commentID + "&voterName=" + voterName;
		// Here we pass the argument string neccessary to rate the comment + 1, if the user has already voted
		//   on this comment then "-1" will be returned.
		$("div#ajaxNotify-" + commentID).html("<img id='ajaxLoadClient' src='/static/images/mi/comments/admin_icons/ajax_load_bar_small.gif' alt='" + message[5] + "' />");	
		$.ajax({
			url: "/cgi-bin/mi/comments/comments_cgi.pl",
			type: "POST",
			dataType: 'html',
			data: argumentString,
			success: function(html){
				$("div#ajaxNotify-" + commentID).html('');
				var tmpReturnValue = html.split("<body>");
				var returnValue = tmpReturnValue[1];
				
				if( returnValue == "-1" ){
					alert( message[0] );
				} else {
					currentRating = $("span.ratingCommentID-" + commentID).html();
					$("span.ratingCommentID-" + commentID).html( ++currentRating );
		
					currentNumberRated = $("span.numberRatedCommentID-" + commentID).html();
					$("span.numberRatedCommentID-" + commentID).html( ++currentNumberRated );
				}
			},
			error: function(msg) { 
				alert( message[1] );
			}
		});
	}
	// ##################

	// ##################
	// PURPOSE: This function will return the number of comments associated with an asset, or '-1' if the asset doesn't exist or 
	//   another error occurs.
	function getNumComments( assetType, assetID ){
		var argumentString = "function=fetchNumComments&assetType=" + assetType + "&assetID=" + assetID;
		var returnValue;
		$.ajax({
			url: "/cgi-bin/mi/comments/comments_cgi.pl",
			type: "POST",
			async: false,
			dataType: 'html',
			data: argumentString,
			success: function(html){
				var tmpReturnValue = html.split("<body>");
				returnValue = tmpReturnValue[1];
			},
			error: function(msg) { 
				returnValue = -1;
			}
		});
		return( returnValue );

	}

	// ##################
	// PURPOSE: Formulates the argument string needed to rate a comment with - 1 negative vote
	function rateCommentMinus( commentID, voterName ) {
		var argumentString = "function=rateCommentMinus&commentID=" + commentID + "&voterName=" + voterName;
		$("div#ajaxNotify-" + commentID).html("<img id='ajaxLoadClient' src='/static/images/mi/comments/admin_icons/ajax_load_bar_small.gif' alt='" + message[5] + "' />");	
		$.ajax({
			url: "/cgi-bin/mi/comments/comments_cgi.pl",
			type: "POST",
			dataType: 'html',
			data: argumentString,
			success: function(html){
				$("div#ajaxNotify-" + commentID).html('');
				var tmpReturnValue = html.split("<body>");
				returnValue = tmpReturnValue[1];
				
				if( returnValue == "-1" ){
					alert( message[0] );
				} else {
					currentRating = $("span.ratingCommentID-" + commentID).html();
					if( (currentRating - 1) == 0 )
						currentRating = "0";
					else
						currentRating--;
					$("span.ratingCommentID-" + commentID).html( currentRating );
		
					currentNumberRated = $("span.numberRatedCommentID-" + commentID).html();
					$("span.numberRatedCommentID-" + commentID).html( ++currentNumberRated );
				}
			},
			error: function(msg) { 
				alert( message[1] );
			}
		});
	}
	// ##################

	// ##################
	// PURPOSE: Formulates string to call CGI function to display all disabled Comments
	function displayDisabledComments( numberComments ){
		var argumentString = "function=fetchDisabledComments&numberComments=" + numberComments;
		runCommentCGI( argumentString );
	}
	// ##################

	// ##################
	// PURPOSE: Passes URL to add a comment to the DB, also, after comment is added will reload the page with 
	//   a new hash, this is needed for omniture tracking. 
	function addAssetComment( assetType, assetID, assetURL, assetTitle, assetGlobalExpireDate, assetSectionName, submitter, commentTitle, commentBody ) {
		// Strip out whitespace and linebreaks to check for empty comment.
		strippedCommentBody = commentBody;
		strippedCommentBody = strippedCommentBody.replace( / /g, '');
		strippedCommentBody = strippedCommentBody.replace( /\n/g, '');

		
		// Here we are going to count the number of line breaks the user is trying to use
		//   if it's less than 5 we'll assume this is a legitimate request and allow the line breaks, greater than 5 and we'll 
		//   strip all breaks and post with out them
		var numOfBreaks = commentBody.split("\n");
		if( numOfBreaks.length <= 5 ) {
  			commentBody = commentBody.replace( /\n/g, '[br]');
		}
	
		if( commentTitle.length > 100 )
			alert( message[2] );
		else if( commentBody.length > 768 )
			alert( message[3] );
		else if( strippedCommentBody.length < 2 )
			alert( message[4] );
		else{
			var argumentString = "function=addAssetComment&assetType=" + assetType + "&assetID=" + assetID + "&assetURL=" + assetURL + "&assetTitle=" + assetTitle + "&assetGlobalExpireDate=" + assetGlobalExpireDate + "&assetSectionName=" + assetSectionName + "&submitter=" + submitter + "&commentTitle=" + commentTitle + "&commentBody=" + encodeURIComponent(commentBody);
			
			$("#commentAdd").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					// We need to check to see if our addComment hash is already in the URL ... if so, just reaload the page
					//   if not then we need to set the hash and then reload.
					var currentURL = window.location.href;
					if( currentURL.search(/addcomment=true/) != -1) {
						window.location.reload();
					} else {
						window.location = assetURL + "?addcomment=true;#recent_comm";
					}
				},
				error: function(msg) { 
					alert( message[1] );
				}
			});
		}
	}
	// ##################
	
	// ##################
	// PURPOSE: Given a comment ID will flag that comment, then swaps out the "!" image to show the comment
	//   has been flagged.
	function flagComment( commentID, userName ) {
		var answer = confirm( message[6] );

		if( answer ) {
			var argumentString = "function=flagComment&commentID=" + commentID + "&reporterName=" + userName;
			var flagImgClass   = "img.commentID-" + commentID;
			$("div#ajaxNotify-" + commentID).html("<img id='ajaxLoadClient' src='/static/images/mi/comments/admin_icons/ajax_load_bar_small.gif' alt='" + message[5] + "' />");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					$("div#ajaxNotify-" + commentID).html('');
					$(flagImgClass).attr({
						src: "/images/mi/comments/exclamation-red.png"
					});	
				},
				error: function(msg) { 
					alert( message[1] );
				}
			});
		} 
	}
	// ##################


	// ##################
	// PURPOSE: This function will show a comment who has been hidden due to a negative rating
	function showHiddenComment( commentID ) {
		var commentLiSelector = "li.liCommentID-" + commentID;
		var commentRatingWarningSelector = commentLiSelector + " div.rateWarningInfo";

		$(commentRatingWarningSelector).slideUp("slow",function() {
			$(commentLiSelector + " div.showRateWarning").slideDown("slow");
		});
		
	}
	// ##################
	
	// ##################
	// PURPOSE: Will display all comments associated with asset in paged view
	function displayCurrentAssetCommentsAll( assetType, assetID, userName, startResult, numResultsPerPage ){
		var argumentString = "function=fetchCurrentAssetCommentsAll&assetType=" + assetType + "&assetID=" + assetID + "&userName=" + userName + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;

		$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
        	objAjaxRequest = $.ajax({
                	url: "/cgi-bin/mi/comments/comments_cgi.pl",
	                type: "POST",
                	dataType: 'html',
	                data: argumentString,
        	        success: function(html){
				var tmpReturnValue = html.split("<body>");
                                var returnValue = tmpReturnValue[1];
				if( returnValue != -1 ){
					$("#commentDisplay").html( html );
					$("#commentContainer").css({"display":"block"});
				}
                        	objAjaxRequest = null;
	                },
        	        error: function(msg) {
                	        //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
	                }
        	 });
	}

	// ##################
	// PURPOSE: Will show all the comments for the unique Asset Type / Asset ID combination
	function displayCurrentAssetComments( assetType, assetID, userName, numberComments ) {
		var argumentString = "function=fetchCurrentAssetComments&assetType=" + assetType + "&assetID=" + assetID + "&userName=" + userName + "&numberComments=" + numberComments;

		$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
        	objAjaxRequest = $.ajax({
                	url: "/cgi-bin/mi/comments/comments_cgi.pl",
	                type: "POST",
                	dataType: 'html',
	                data: argumentString,
        	        success: function(html){
				var tmpReturnValue = html.split("<body>");
                                var returnValue = tmpReturnValue[1];
				if( returnValue != -1 ){
					$("#commentDisplay").html( html );
					$("#commentContainer").css({"display":"block"});
				}
                        	objAjaxRequest = null;
	                },
        	        error: function(msg) {
                	        //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
	                }
        	 });

	}
	// ##################

	// ##################
	// PURPOSE: Will formulate the SQL needed to disable a comment, disabling does not remove a comment, simply will not 
	//   show the comment to end users, but it does stay in the DB
	function disableComments() {
	   	var commentIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to disable comments with ID's: " + commentIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=disableComments&commentIDs=" + commentIDs;
			
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayComments(0, 25);
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################
	// ##################
        // PURPOSE: Will send off list of comment IDs to mark as bozo'd 
        function enableCommentBozo() {
                var commentIDs = $(':checkbox').fieldValue();
                var userConfirmation = confirm("Are you sure you want to bozo comments with ID's: " + commentIDs + "?");
                
                if( userConfirmation ) {
                        var argumentString = "function=enableCommentBozo&commentIDs=" + commentIDs;

                        $("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
                        $.ajax({
                                url: "/cgi-bin/mi/comments/comments_cgi.pl",
                                type: "POST",
                                dataType: 'html',
                                data: argumentString,
                                success: function(html){
                                        displayComments(0, 25);
                                },
                                error: function(msg) { 
                                        //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
                                }
                        });
                }
        }
        // ##################
	 // ##################
        // PURPOSE: Will send off list of comment IDs to mark as not bozo'd 
        function disableCommentBozo() {
                var commentIDs = $(':checkbox').fieldValue();
                var userConfirmation = confirm("Are you sure you want to bozo comments with ID's: " + commentIDs + "?");

                if( userConfirmation ) {
                        var argumentString = "function=disableCommentBozo&commentIDs=" + commentIDs;

                        $("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
                        $.ajax({
                                url: "/cgi-bin/mi/comments/comments_cgi.pl",
                                type: "POST",
                                dataType: 'html',
                                data: argumentString,
                                success: function(html){
                                        displayComments(0, 25);
                                },
                                error: function(msg) {
                                        //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
                                }
                        });
                }
        }
        // ##################


	// ##################
	// PURPOSE: Will formulate the SQL needed to disable a comment, disabling does not remove a comment, simply will not 
	//   show the comment to end users, but it does stay in the DB
	function enableComments() {
	   	var commentIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to enable comments with ID's: " + commentIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=enableComments&commentIDs=" + commentIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayComments(0, 25);
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################

	// ##################
	// PURPOSE: Will formulate the SQL needed to disable a wordFilter, disabling does not remove the word filter, simply will not filter
	//   this entry until enabled again.
	function disableWords() {
	   	var wordIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm( "Are you sure you want to disable the selected words?" );
		
		if( userConfirmation ) {
			var argumentString = "function=disableWordFilter&wordIDs=" + wordIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayWordFilter();
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################

	// ##################
	// PURPOSE: Will formulate the SQL needed to disable a wordFilter, disabling does not remove the word filter, simply will not filter
	//   this entry until enabled again.
	function filterBlockComments() {
	   	var wordIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm( "Are you sure you want to block comments that contain the the selected words?" );
		
		if( userConfirmation ) {
			var argumentString = "function=filterBlockComments&wordIDs=" + wordIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayWordFilter();
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################

	// ##################
	// PURPOSE: Will formulate the SQL needed to disable a wordFilter, disabling does not remove the word filter, simply will not filter
	//   this entry until enabled again.
	function filterUnblockComments() {
	   	var wordIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm( "Are you sure you want to allow comments that contain the the selected words?  These words will still be blanked out, and the rest of the comment will be visible." );
		
		if( userConfirmation ) {
			var argumentString = "function=filterUnblockComments&wordIDs=" + wordIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayWordFilter();
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################




	


	// ##################
	// PURPOSE: Will formulate the SQL needed to enable a wordFilter, filtering will now work on these entries
	function enableWords() {
	   	var wordIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm( "Are you sure you want to enable filtering of selected words?" );
		
		if( userConfirmation ) {
			var argumentString = "function=enableWordFilter&wordIDs=" + wordIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayWordFilter();
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
	}
	// ##################


	// ##################
	// PURPOSE: Will formulate the SQL needed to disable commenting on selected assets, disabling does not remove any existing
	// comments, simply will not show the comment to end users or allow them to post anything new
	function disableAssetComments() {
	   	var assetIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to disable commenting on assets with with ID's/Type: " + assetIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=disableAssetComments&assetIDs=" + assetIDs;

			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayAssets('50');
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
		
	}
	// ##################

	// ##################
	// PURPOSE: Will formulate the SQL needed to enable commenting on selected assets
	function enableAssetComments() {
	   	var assetIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to enable comments with ID's/Type: " + assetIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=enableAssetComments&assetIDs=" + assetIDs;
			
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayAssets('50');
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
		
	}
	// ##################

	// ##################
	// PURPOSE: The function simply returns 1 if comments are enabled and 0 if they are disabled for an asset ID / Type
	//   the result is returned in the middle of the <body></body> tags, thus the split on <body> and substring select
	//   below.
	function isCommentingEnabled( assetType, assetID ) {
		var argumentString = "function=isCommentingEnabled&assetID=" + assetID + "&assetType=" + assetType;
		var returnValue = runCommentPost( argumentString );
		
		var test = returnValue.split("<body>");
		returnValue = test[1].substring(0,1);
		return ( returnValue );
		
	}
	// ##################

	// ##################
	// PURPOSE: Will pass a comma seperated list of comment ID's that should be deleted from the DB
	function removeComments() {
	   	var commentIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to delete comments with ID's: " + commentIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=removeComments&commentIDs=" + commentIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayComments(0, 25);
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
		}
	}
	// ##################

	// ##################
	// PURPOSE: Will pass a comma seperated list of comment ID's that should have flag removed
	function removeFlag() {
	   	var commentIDs = $(':checkbox').fieldValue();
		var userConfirmation = confirm("Are you sure you want to remove flag status for comments with ID's: " + commentIDs + "?");
		
		if( userConfirmation ) {
			var argumentString = "function=removeFlag&commentIDs=" + commentIDs;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayComments(0, 25);
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
		}
	}
	// ##################

	// ##################
	// PURPOSE: Will pass a comma seperated list of end user names that should be enabled for commenting
	function enableEndUser() {
	   	var endUserNames = $(':checkbox').fieldValue();
		
		if( endUserNames != "" ){
			var userConfirmation = confirm("Are you sure you want to enable users: " + endUserNames + "?");
		
			if( userConfirmation ) {
				var argumentString = "function=enableEndUser&endUserNames=" + endUserNames;
				$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayEndUsers(50);
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
			}
			
		} else
			alert( "Please select atleast 1 end user to enable.");
	}
	// ##################

	// ##################
	// PURPOSE: Will pass a comma seperated list of end user names that should be disabled for commenting
	function disableEndUser() {
	   	var endUserNames = $(':checkbox').fieldValue();
		
		if( endUserNames != "" ){
			var userConfirmation = confirm("Are you sure you want to disable users: " + endUserNames + "?");
		
			if( userConfirmation ) {
				var argumentString = "function=disableEndUser&endUserNames=" + endUserNames;
				$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayEndUsers(50);
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
			}
			
		} else
			alert( "Please select atleast 1 end user to disable.");
	}
	// ##################
	// ##################
        // PURPOSE: Will pass a comma seperated list of end user names that should be marked as bozo'd
        function enableEndUserBozo() {
                var endUserNames = $(':checkbox').fieldValue();

                if( endUserNames != "" ){
                        var userConfirmation = confirm("Are you sure you want to bozo users: " + endUserNames + "?");

                        if( userConfirmation ) {
                                var argumentString = "function=enableEndUserBozo&userNames=" + endUserNames;
                                $("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
                                $.ajax({
                                        url: "/cgi-bin/mi/comments/comments_cgi.pl",
                                        type: "POST",
                                        dataType: 'html',
                                        data: argumentString,
                                        success: function(html){
                                                displayEndUsers(50);
                                        },
                                        error: function(msg) {
                                                //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
                                        }
                                });
                        }
          
                } else
                        alert( "Please select atleast 1 end user to bozo.");
        }
        // ##################
	// ##################
        // PURPOSE: Will pass a comma seperated list of end user names that should be marked as not bozo'd
        function disableEndUserBozo() {
                var endUserNames = $(':checkbox').fieldValue();

                if( endUserNames != "" ){
                        var userConfirmation = confirm("Are you sure you want to remove bozo filter from users: " + endUserNames + "?");

                        if( userConfirmation ) {
                                var argumentString = "function=disableEndUserBozo&userNames=" + endUserNames;
                                $("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");
                                $.ajax({
                                        url: "/cgi-bin/mi/comments/comments_cgi.pl",
                                        type: "POST",
                                        dataType: 'html',
                                        data: argumentString,
                                        success: function(html){
                                                displayEndUsers(50);
                                        },
                                        error: function(msg) {
                                                //console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
                                        }
                                });
                        }

                } else
                        alert( "Please select atleast 1 end user to remove bozo filter from.");
        }
        // ##################
	











	// ##################
	// PURPOSE: Will pass a comma seperated list of admin ID's that should be deleted from the DB
	function removeCommentAdmins() {
	   	var adminUserNames = $(':checkbox').fieldValue();
		
		if( adminUserNames != "" ){
			var userConfirmation = confirm("Are you sure you want to remove Admins: " + adminUserNames + "?");
		
			if( userConfirmation ) {
				var argumentString = "function=removeCommentAdmins&adminUserNames=" + adminUserNames;
				$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayAdministrators(25);
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
			}
			
		} else
			alert( "Please select atleast 1 Administrator to remove from the commenting system.");
	}
	// ##################

	// ##################
	// PURPOSE: Will pass a comma seperated list of word ID's that should be deleted from the DB
	function deleteWords() {
	   	var wordIDs = $(':checkbox').fieldValue();
		
		if( wordIDs != "" ){
			var userConfirmation = confirm( "Are you sure you want to Delete the selected words from the filter?" );
		
			if( userConfirmation ) {
				var argumentString = "function=removeWordFilter&wordIDs=" + wordIDs;
				$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
				$.ajax({
					url: "/cgi-bin/mi/comments/comments_cgi.pl",
					type: "POST",
					dataType: 'html',
					data: argumentString,
					success: function(html){
						displayWordFilter();
					},
					error: function(msg) { 
						//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
					}
				});
			}
			
		} else
			alert( "Please select atleast 1 word/phrase to remove from the commenting system.");
	}
	// ##################

	// ##################
	// PURPOSE: This function only toggles display of the form to add an Administrator, then passes form data to another
	//   function to send the data to be commited to the DB.
	function showAddAssetForm() {
		var adminInputContents = $("#adminInput").html();
	
		if( adminInputContents == '' ){
			$("#adminInput").html('\
				<form id="frmAddAsset" name="addAsset" action="" method="POST">\
					<label class="adminLabel">Asset ID:</label>\
						<INPUT ID="inputAssetID" class="txtInput" NAME="assetID" TYPE="text">\
					<br />\
					<label class="adminLabel">Asset Title:</label>\
						<INPUT ID="inputAssetTitle" class="txtInput" NAME="assetTitle" TYPE="text">\
					<br />\
					<label class="adminLabel">Asset Type:</label>\
						<select id="assetSelect" name="assetType" width=15>\
  							<option value="story">Story</option>\
						</select>\
					<br />\
					<label class="adminLabel">Asset Disabled?</label>\
						<input type="CHECKBOX" name="assetDisabled">\
					<br />\
					<INPUT ID="btnAddAsset" class="adminButton" TYPE="submit" VALUE="Add Asset" onClick="addAdminAsset( assetID.value, assetType.value, assetTitle.value,  assetDisabled.checked );return( false );">\
				</form>\
				<br />\
			');
		} else {
			$("#adminInput").html('');
		}
	}

	// ##################
	// PURPOSE: This function only toggles display of the form to add an Administrator, then passes form data to another
	//   function to send the data to be commited to the DB.
	function showAddAdminForm() {
		var adminInputContents = $("#adminInput").html();
	
		if( adminInputContents == '' ){
			$("#adminInput").html('\
				<form id="frmAddAdmin" name="addAdministrator" action="" method="POST">\
					<label class="adminLabel">Insite Username:</label>\
						<INPUT ID="inputAdminUserName" class="txtInput" NAME="adminUserName" TYPE="text">\
					<br />\
					<label class="adminLabel">Email:</label>\
						<INPUT ID="inputAdminEmail" class="txtInput" NAME="adminEmail" TYPE="text">\
					<br />\
					<label class="adminLabel">Alerts Enabled?</label>\
						<input type="CHECKBOX" name="alertsEnabled">\
					<br />\
					<INPUT ID="btnAddAdmin" class="adminButton" TYPE="submit" VALUE="Add Administrator" onClick="addCommentAdmin( adminUserName.value, adminEmail.value, alertsEnabled.checked );return( false );">\
				</form>\
				<br />\
			');
		} else {
			$("#adminInput").html('');
		}
	}
	
	// ##################
	// PURPOSE: This function only toggles display of the form to add an words to filter, then passes form data to another
	//   function to send the data to be commited to the DB.
	function showAddWordFilter() {
		var adminInputContents = $("#adminInput").html();
	
		if( adminInputContents == '' ){
			$("#adminInput").html('\
				<form id="frmAddWord" name="addWord" action="" method="POST">\
					<label class="adminLabel">Word or Phrase</label>\
						<INPUT ID="inputAdminWord" class="txtInput" NAME="adminWord" TYPE="text">\
					<br />\
					<label class="adminLabel">Enable Filter?</label>\
						<input type="CHECKBOX" name="filterEnabled">\
					<br />\
					<label class="adminLabel">Block Comment if Found?</label>\
						<input type="CHECKBOX" name="blockComment">\
					<br />\
					<INPUT ID="btnAddWord" class="adminButton" TYPE="submit" VALUE="Add Word or Phrase" onClick="addWordFilter( adminWord.value, filterEnabled.checked, blockComment.checked );return( false );">\
				</form>\
				<br />\
			');
		} else {
			$("#adminInput").html('');
		}
	}

	// ##################
	// PURPOSE: This function formulates the string neccessary to add a word or phrase to the wordFilter DB
	function addWordFilter( adminWord, adminEnabled, blockComment ) {

		if( (adminWord != "") || (adminEnabled != "") ){
			var argumentString = "function=addWordFilter&word=" + adminWord + "&enabled=" + adminEnabled + "&blockComment=" + blockComment;

			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayWordFilter();
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		} else 
			alert( "Please input both a word/phrase to add." );
	}
	// ##################

	// ##################
	// PURPOSE: This function formulates the string neccessary to add an asset to the database and sends to backend
	function addAdminAsset( assetID, assetType, assetTitle, assetDisabled ) {

		if( (assetID == '') || (assetType == '') ){
			alert( "Please input both an Asset ID and Asset Type to add" );
		} else {
			var argumentString = "function=addAsset&assetID=" + assetID + "&assetType=" + assetType + "&assetTitle=" + assetTitle + "&assetDisabled=" + assetDisabled;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayAssets(50);
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
			
	}

	// ##################
	// PURPOSE: This function formulates the string neccessary to add an admin to the database and sends to backend
	function addCommentAdmin( adminUserName, adminEmail, alertsEnabled) {

		if( (adminUserName == '') || (adminEmail == '') ){
			alert( "Please input both a Username and Email for the admin" );
		} else {
			var argumentString = "function=addCommentAdmin&adminUserName=" + adminUserName + "&adminEmail=" + adminEmail + "&alertsEnabled=" + alertsEnabled;
			$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					displayAdministrators(25);
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
			
	}
	// ##################
		
	// ##################
	// PURPOSE: This function detects what view we are at (Comments, Assets, End Users, Admins, etc...)
	//   then passes the appropriate values as URL arguments to comments_cgi.pl
	function searchSimple( searchTerm, startResult, numResultsPerPage ) {
		if( searchTerm == '' ){
			alert("Please enter a term to search on");
		} else {
			// TODO: SETUP switch statement for comments, assets, end users, comment admins
			var currentView = $("ul#tabs > li.navActive > a > span").html();
			if( currentView == "Comments" ){
				var argumentString = "function=searchSimple&view=comments&searchTerm=" + searchTerm + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;
				runCommentCGI( argumentString );
			} else if( currentView == "Assets" ) {
				var argumentString = "function=searchSimple&view=assets&searchTerm=" + searchTerm + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;
				runCommentCGI( argumentString );
			} else if( currentView == "End Users" ) {
				var argumentString = "function=searchSimple&view=endUsers&searchTerm=" + searchTerm + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;
				runCommentCGI( argumentString );
			} else if( currentView == "Comment Admins" ) {
				var argumentString = "function=searchSimple&view=admins&searchTerm=" + searchTerm + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;
				runCommentCGI( argumentString );
			} else if( currentView == "Word Filter" ) {
				var argumentString = "function=searchSimple&view=wordFilter&searchTerm=" + searchTerm + "&startResult=" + startResult + "&numResultsPerPage=" + numResultsPerPage;
				runCommentCGI( argumentString );
			}
		}
		
	}
	// ##################
// ######################################

// ##################
// PURPOSE: This function fetches our insite cookie and returns the insite userName or "-1" if not logged in
function getInsiteUserName( myInsiteCookieName ) {
	if( document.cookie.length > 0 ) {
		var cookieValue = document.cookie.match( '(^|;)*' + myInsiteCookieName + '=([^;]*)(;|$)' );
		if( cookieValue ) {
			var end = cookieValue[2].indexOf( "%7C" );
			var userName = cookieValue[2].substr(0, end);
			if( userName == '' ){
				return( "-1" );	
			}
			return( userName );
		} else
			return( "-1" );
	} else
		return( "-1" );
}
// ##################

// ##################
// PURPOSE: This function passes the parameters needed to logout an Administrator
function logoutAdministrator(){
	 var argumentString = "function=logoutAdmin";
         $("#loginNotification").html("<center><img id='ajaxLoginLoad' src='/static/images/mi/comments/admin_icons/ajax_load_bar.gif' alt='" + message[5] + "' /></center>");
         $.ajax({
         	url: "/cgi-bin/mi/comments/comments_cgi.pl",
                type: "POST",
                dataType: 'html',
                data: argumentString,
                success: function(html){
                       	alert( "Logout Successful, the admin interface will now be refreshed" );
                        window.location.reload();
                },
                error: function(msg) {
                	//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
                }
     	});
}

// ##################
// PURPOSE: This function will call the backend script neccessary to authenticate the user via insite
function authenticateAdmin( userName, password ) {
	if( (password == '') || (userName == '') ){
		alert( "Please input both a Username and Password for the admin" );
	} else {
			var argumentString = "function=authenticateAdmin&userName=" + userName + "&password=" + password;
			$("#loginNotification").html("<center><img id='ajaxLoginLoad' src='/static/images/mi/comments/admin_icons/ajax_load_bar.gif' alt='" + message[5] + "' /></center>");	
			$.ajax({
				url: "/cgi-bin/mi/comments/comments_cgi.pl",
				type: "POST",
				dataType: 'html',
				data: argumentString,
				success: function(html){
					$("#loginNotification").html('');
					var tmpReturnValue = html.split("<body>");
					var returnValue = tmpReturnValue[1];
					if( returnValue == "1" ){
						//alert( "Login Successful, the admin interface will now be refreshed" );	
						window.location.reload();
					} else if( returnValue == "0" ) {
						alert( "Login Unsuccessful - Username / Password incorrect or you are not a comment administrator." );
					}
				},
				error: function(msg) { 
					//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
				}
			});
		}
			
}
// ##################

// ######################################
// PURPOSE: All the below functions operate the Admin Interface, this may end up being 
//   broken into a seperate 'comments_admin.js' script, but for now keeping here for testing.

	// ##################
	// PURPOSE: Will display the initial 'Comments' view in the admin interface
	function adminShowCommentsView() {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs li#navComments").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}
		
		$("#commentDisplayLabel").html("Most Recent Comments:");
		$("#views").html('\
			<form name="commentAdmin" action="" method="POST">\
				<INPUT ID="btnShowFlaggedComments" class="adminButton" TYPE="button" VALUE="Show All Flagged Comments" onClick="displayFlaggedComments(50);return( false );">\
				<INPUT ID="btnShowDisabledComments" class="adminButton" TYPE="button" VALUE="Show All Disabled Comments" onClick="displayDisabledComments(50);return( false );">\
			</form>\
			');

		$("#controls").html('\
			<a id="commentsEnable" title="Enable selected comments" onClick="enableComments();return( false );">\
				<img src="/images/mi/comments/admin_icons/comment_enable.png" alt="Enable Comments" />\
			</a>\
			<a id="commentsDisable" title="Disable selected comments" onClick="disableComments();return( false );">\
				<img src="/images/mi/comments/admin_icons/comment_disable.png" alt="Disable Comments" />\
			</a>\
			<a id="commentsDelete" title="Delete selected comments" onClick="removeComments();return( false );">\
				<img src="/images/mi/comments/admin_icons/comment_remove.png" alt="Delete Comments" />\
			</a>\
			<a id="commentsRemoveFlag" title="Remove flag from selected comments" onClick="removeFlag();return( false );">\
				<img src="/images/mi/comments/admin_icons/remove_flag.png" alt="Remove Flag on Comments" />\
			</a>\
			<div id="controls-SecondRow">\
				<a id="commentsEnableBozo" title="Bozo the selected comments" onClick="enableCommentBozo();return( false );">\
                                <img src="/images/mi/comments/admin_icons/bozo_add.png" alt="Delete Comments" />\
                        </a>\
                        <a id="commentsDisableBozo" title="Disable Bozo on selected comments" onClick="disableCommentBozo();return( false );">\
                                <img src="/images/mi/comments/admin_icons/bozo_remove.png" alt="Remove Flag on Comments" />\
                        </a>\
			</div>\
			' );
		$("#resultPaging").html("");
		$("#adminInput").html('');

		displayComments(0, 25);
	}
	// ##################
	// PURPOSE: Will display the initial 'Assets' view in the admin interface
	function adminShowAssetsView() {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs li#navAssets").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}

		$("#commentDisplayLabel").html("Most Recently Commented Assets:");

		$("#controls").html('\
			<a id="commentAddAsset" title="Add a Pubsys Asset" onClick="showAddAssetForm();return( false );">\
				<img src="/images/mi/comments/admin_icons/asset_add.png" alt="Add an asset" />\
			</a>\
			<a id="commentEnableAsset" title="Enable commenting on asset" onClick="enableAssetComments();return( false );">\
				<img src="/images/mi/comments/admin_icons/comments.png" alt="Remove Administrator" />\
			</a>\
			<a id="commentDisableAsset" title="Disable commenting on asset" onClick="disableAssetComments();return( false );">\
				<img src="/images/mi/comments/admin_icons/comments_block.png" alt="Remove Administrator" />\
			</a>\
		');
				
		$("#resultPaging").html("");
		$("#views").html('');
		$("#adminInput").html('');
		displayAssets(50);
	}
	
	// ##################
	// PURPOSE: Will display the initial 'End Users' view in the admin interface
	function adminShowEndUsersView() {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs li#navEndUsers").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}

		$("#commentDisplayLabel").html("Most Recent Commenting Users:");
		
		$("#controls").html('\
			<a id="commentEnableEndUser" title="Enable user commenting" onClick="enableEndUser();return( false );">\
				<img src="/images/mi/comments/admin_icons/user_add.png" alt="Enable end user" />\
			</a>\
			<a id="commentDisableEndUser" title="Disable user commenting" onClick="disableEndUser();return( false );">\
				<img src="/images/mi/comments/admin_icons/user_remove.png" alt="Disable end user" />\
			</a>\
			<a id="commentEnableEndUserBozo" title="Bozo selected users" onClick="enableEndUserBozo();return( false );">\
                                <img src="/images/mi/comments/admin_icons/bozo_add.png" alt="Enable end user" />\
                        </a>\
                        <a id="commentDisableEndUserBozo" title="Remove Bozo filter on selected users" onClick="disableEndUserBozo();return( false );">\
                                <img src="/images/mi/comments/admin_icons/bozo_remove.png" alt="Disable end user" />\
                        </a>\
		');		


		$("#resultPaging").html("");
		$("#views").html('');
		$("#adminInput").html('');
		displayEndUsers(50);
	}
	
	// ##################
	// PURPOSE: Will display the initial 'Comment Administrators' view in the admin interface
	function adminShowCommentAdminsView() {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs > li#navAdmins").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}

		$("#commentDisplayLabel").html("Commenting Administrators:");
		
		$("#controls").html('\
			<a id="commentAddAdmin" title="Add a comment Administrator" onClick="showAddAdminForm();return( false );">\
				<img src="/images/mi/comments/admin_icons/user_add.png" alt="Add an Administrator" />\
			</a>\
			<a id="commentsRemoveAdmin" title="Remove selected Administrator" onClick="removeCommentAdmins();return( false );">\
				<img src="/images/mi/comments/admin_icons/user_remove.png" alt="Remove Administrator" />\
			</a>\
		');
		$("#resultPaging").html("");
		$("#views").html('');
		$("#adminInput").html('');
		displayAdministrators(25);
	}

	// ##################
	// PURPOSE: Will display the initial 'Manage Word Filter' view in the admin interface
	function adminShowWordFilter() {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs > li#navWordFilter").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}

		$("#commentDisplayLabel").html("Blacklisted Words:");
		$("#resultPaging").html("");
		$("#views").html('');
		$("#adminInput").html('');
		$("#controls").html('\
			<a id="commentWordNew" title="Add a new word or phrase to filter" onClick="showAddWordFilter();return( false );">\
				<img src="/images/mi/comments/admin_icons/word_new.png" alt="Add a new word" />\
			</a>\
			<a id="commentWordEnable" title="Enable the selected words or phrases" onClick="enableWords();return( false );">\
				<img src="/images/mi/comments/admin_icons/word_enable.png" alt="Enable Words" />\
			</a>\
			<a id="commentWordDisable" title="Disable the selected words or phrases" onClick="disableWords();return( false );">\
				<img src="/images/mi/comments/admin_icons/word_disable.png" alt="Disable Words" />\
			</a>\
			<a id="commentWordDelete" title="Delete the selected words or phrases" onClick="deleteWords();return( false );">\
				<img src="/images/mi/comments/admin_icons/comment_remove.png" alt="Delete Words" />\
			</a>\
			<div id="controls-SecondRow">\
				<a id="commentUnblockComments" title="Do not block comment if found, simply star out phrase" onClick="filterUnblockComments();return( false );">\
					<img src="/images/mi/comments/admin_icons/comments.png" alt="Delete Words" />\
				</a>\
				<a id="commentBlockComments" title="Completely block comment if word/phrase is found" onClick="filterBlockComments();return( false );">\
					<img src="/images/mi/comments/admin_icons/comments_block.png" alt="Bloc comment if phrase is found" />\
				</a>\
			</div>\
		');
		
		displayWordFilter();
	}
	// ##################
	// PURPOSE: Will display the initial 'Statistics' view in the admin interface
	function adminShowStatisticsView( limit ) {
		$("ul#tabs > li").removeClass("navActive");
		$("ul#tabs > li#navStats").addClass("navActive");
		// If there is a current ajax call out, then cancel this and just update the UI.  This is 
		//   needed to prevent situations where UI becomes out of sync with menu's
		if( objAjaxRequest ){
			objAjaxRequest.abort();
		}

		$("#commentDisplayLabel").html("End User Statistics:");

		$("#resultPaging").html("");
		$("#views").html('');
		$("#adminInput").html('');
		$("#controls").html('\
			<a id="commentUserStats" title="View end user statistics" onClick="displayUserStats( 10 );return( false );">\
				<img src="/images/mi/comments/admin_icons/user.png" alt="End user stats" />\
			</a>\
			<a id="commentAssetStats" title="View asset statistics" onClick="displayAssetStats( 10 );return( false );">\
				<img src="/images/mi/comments/admin_icons/asset.png" alt="Asset stats" />\
			</a>\
			<a id="commentCommentsStats" title="View comment statistics" onClick="displayCommentStats( 10 );return( false );">\
				<img src="/images/mi/comments/admin_icons/comments.png" alt="Asset stats" />\
			</a>\
		');
		
		displayUserStats( 10 );
	}

	// ##################
	// PURPOSE: This just checks all visible checkboxes
	function checkAllVisible(){
		$("input[@type=checkbox]").each(function() 
                {
			if( this.checked == true )
				this.checked = false;
			else 
                    		this.checked = true; 
                });
	}

// ######################################



//*****************
// This function calls 'comments_cgi.pl' and injects the returned data into
//   #commentDisplay
function runCommentCGI( myArgumentString ) {
	$("#commentDisplay").html("<center><img id='ajaxLoad' src='/static/images/mi/comments/admin_icons/ajax_load.gif' alt='" + message[5] + "' /></center>");	
	objAjaxRequest = $.ajax({
	 	url: "/cgi-bin/mi/comments/comments_cgi.pl",
		type: "POST",
		//cache: true,
		dataType: 'html',
		data: myArgumentString,
		success: function(html){
			$("#commentDisplay").html( html );
			objAjaxRequest = null;
		},
		error: function(msg) { 
			//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
		}
	 });
}
//*****************

//*****************
// This function calls 'comments_cgi.pl' with the passed argument, but does nothing with returned data
function runCommentPost( myArgumentString ) {
	//console.log(myArgumentString);
	var commentPostReturn = "Initial Value";
	
	$.ajax({
	 	url: "/cgi-bin/mi/comments/comments_cgi.pl",
		async: false,
		type: "POST",
		dataType: 'html',
		data: myArgumentString,
		success: function(html){
			commentPostReturn = html;
		},
		error: function(msg) { 
			//console.log("( Function: runCommentCGI ): (AJAX Call: error): msg = " + msg);
		}
	 });
	 return( commentPostReturn );
}
//*****************
