//$Id$

function moderateAnswer ( id, cqrc_id, filternow, answerindex )
{
	hideme('cqrcselector' + id );
	var ajaxurl = '/ajaxserver/modanswer.php5?id=' + id + '&cqrcid=' + cqrc_id + '&filternow=' + filternow + '&answerindex=' + answerindex;
	loadXMLDoc(ajaxurl);
}

function moderateAnswerDone( input, results, success )
{
	// Grab the results from the Ajax transaction
	var this_id = results[0].getElementsByTagName('answerid')[0].firstChild.data;
	var cqrValueAdded = results[0].getElementsByTagName('cqrvalue')[0].firstChild.data;
	var newContentCQRs = results[0].getElementsByTagName('newcqr')[0].firstChild.data;
	var newCQRC = results[0].getElementsByTagName('newcqrc')[0].firstChild.data;
	var newCQRCType = results[0].getElementsByTagName('newcqrctype')[0].firstChild.data;
	var filterNow = results[0].getElementsByTagName('filternow')[0].firstChild.data;
	var isAnswerIndex = results[0].getElementsByTagName('answerindex')[0].firstChild.data;

	// Grab our elements we are going to be modifying
	var modMsg = document.getElementById( 'answermodmsg' + this_id );
	var modMsgCQRC = document.getElementById( 'answermodmsgcqrc' + this_id );
	var modMsgCQRValue = document.getElementById( 'answermodmsgcqrvalue' + this_id );
	var modMsgPosNeg = document.getElementById( 'answermodmsgposneg' + this_id );
	var modMsgNewCQRs = document.getElementById( 'answermodmsgnewcqrs' + this_id );
	
	// Define our text to be put in
	msgCQRC = document.createTextNode(newCQRC);
	msgCQRValue = document.createTextNode(cqrValueAdded);
	msgNewCQRs = document.createTextNode(newContentCQRs);
	if (newCQRCType == 'N')
	{
		msgPosNeg = document.createTextNode("-");
	}
	else
	{
		msgPosNeg = document.createTextNode("+");
	}

	if (newCQRC == 'Irrelevant' && isAnswerIndex != 1)
	{
		var hideMeNow = true;
	}

	// Check to see if they rated it R or X
	if (newCQRCType == 'R' || newCQRCType == 'X')
	{
		// If they did, we can show them that they did so...
		toggleme('answerreactionratingrx' + this_id);
	
		// ...and check to see whether we need to hide the answer immediately
		var hideMeNow = false;
		if (filterNow != 'N' && isAnswerIndex != 1)
		{
			if (newCQRCType == 'X')
			{
				hideMeNow = true;
			}
			else if (newCQRCType == 'R')
			{
				if (filterNow == 'R')
				{
					hideMeNow = true;
				}
			}
		}
	}
	
	modMsgCQRC.appendChild(msgCQRC);
		
	// If we need to hide the answer, let's do so and replace it with a filter message
	if (hideMeNow)
	{	
		// Get the elements of the answer...
		var imageholder = document.getElementById( 'imagecontainer' + this_id );
		var buttonholder = document.getElementById( 'buttoncontainer' + this_id);
	
		// ...and adjust them as necessary...
		if (imageholder != null)
		{
			imageholder.className = 'answerimage_blocked';
		}

		if (buttonholder != null)
		{
			buttonholder.className = 'addtoballot_blocked';
		}
		hideme('answerimage' + this_id);
		hideme('votebutton' + this_id);
		hideme('answersummary' + this_id);
	
		// ...then show them the new filter message
		if (newCQRC == 'Irrelevant')
		{
			var filterDiv = document.getElementById ( 'filterAnswerMessage' + this_id );
			filterDiv.style.display = '';
			fademein('filterAnswerMessage' + this_id);
		}
		else
		{
			var filterDiv = document.getElementById ( 'answermodmsgadult' + this_id );
			filterDiv.style.display = '';
			fademein('answermodmsgadult' + this_id);
		}
	}
	else
	{
		// They didn't rate it as R or X so we need to show them their rating
		toggleme('answerreactionrating' + this_id);

		// Append our text to our locations on the page...
		modMsgCQRValue.appendChild(msgCQRValue);
		modMsgPosNeg.appendChild(msgPosNeg);
		modMsgNewCQRs.appendChild(msgNewCQRs);
	}
	
	// Now let's show them the results
	modMsg.style.display = '';
	fademein('answermodmsg' + this_id);  
}
    
function moderateComment(id, cqrc_id, filternow)
{
	hideme('commentrating'+id); 
	//set current score to "loading" state
	var comment_cqrscore = "comment_cqrscore_" + id;
	var comment_cqrscore_element = document.getElementById(comment_cqrscore);
	comment_cqrscore_element.className = "cqrscore_loading";
	var ajaxurl = '/ajaxserver/modcomment.php5?id=' + id + '&cqrcid=' + cqrc_id + '&filternow=' + filternow;
	showme('commentrating_off'+id); 
    loadXMLDoc(ajaxurl);
}

function moderateCommentDone( input, results, success )
{
	// Grab the results from the Ajax transaction
	var this_id = results[0].getElementsByTagName('commentid')[0].firstChild.data;
	var cqrValueAdded = results[0].getElementsByTagName('cqrvalue')[0].firstChild.data;
	var newContentCQRs = results[0].getElementsByTagName('newcqr')[0].firstChild.data;
	var newCQRC = results[0].getElementsByTagName('newcqrc')[0].firstChild.data;
	var newCQRCType = results[0].getElementsByTagName('newcqrctype')[0].firstChild.data;
	var filterNow = results[0].getElementsByTagName('filternow')[0].firstChild.data;

	// Grab our elements we are going to be modifying
	var modMsg = document.getElementById( 'commentmodmsg' + this_id );
	var modMsgCQRC = document.getElementById( 'commentmodmsgcqrc' + this_id );
	var modMsgCQRValue = document.getElementById( 'commentmodmsgcqrvalue' + this_id );
	var modMsgPosNeg = document.getElementById( 'commentmodmsgposneg' + this_id );
	var modMsgNewCQRs = document.getElementById( 'commentmodmsgnewcqrs' + this_id );
	
	// Define our text to be put in
	msgCQRValue = document.createTextNode(cqrValueAdded);
	msgNewCQRs = document.createTextNode(newContentCQRs);
	msgCQRC = document.createTextNode(newCQRC);
	if (newCQRCType == 'N')
	{
		msgPosNeg = document.createTextNode("-");
	}
	else
	{
		msgPosNeg = document.createTextNode("+");
	}

	if (newCQRC == 'Irrelevant')
	{
		var hideMeNow = true;
	}
	
	// Check to see if this was their first time rating this comment
	if (newCQRC == 'Good Quality')
	{
		toggleme('commentmodmsgposselect' + this_id);
		toggleme('commentreactionrating' + this_id);
		
		// Append our text to our locations on the page...
		modMsgCQRValue.appendChild(msgCQRValue);
		modMsgPosNeg.appendChild(msgPosNeg);
		modMsgNewCQRs.appendChild(msgNewCQRs);
	}
	else if (newCQRC == 'Poor Quality')
	{
		toggleme('commentmodmsgnegselect' + this_id);
		toggleme('commentreactionrating' + this_id);
		
		// Append our text to our locations on the page...
		modMsgCQRValue.appendChild(msgCQRValue);
		modMsgPosNeg.appendChild(msgPosNeg);
		modMsgNewCQRs.appendChild(msgNewCQRs);
	}
	else
	{
		// They rated it something else so we need to make sure the selection box is hidden...
		toggleme('commentmodmsgselector' + this_id);
		// ...and show them what they rated it as
		toggleme('commentmodmsgdone' + this_id);
		var x = modMsgCQRValue.lastChild;
		modMsgCQRValue.replaceChild(msgCQRValue, x);
		var n = modMsgNewCQRs.lastChild;
		modMsgNewCQRs.replaceChild(msgNewCQRs, n);
	}
	
	if (newCQRC != 'Poor Quality' && newCQRC != 'Good Quality')
	{
		modMsgCQRC.appendChild(msgCQRC);
	}

	// Check to see if they rated it R or X
	if (newCQRCType == 'R' || newCQRCType == 'X')
	{
		// If they did, we can show them that they did so...
		toggleme('commentreactionrating' + this_id);
		toggleme('commentreactionratingrx' + this_id);
		
		// ...and check to see whether we need to hide the comment immediately
		var hideMeNow = false;
		if (filterNow != 'N')
		{
			if (newCQRCType == 'X')
			{
				hideMeNow = true;
			}
			else if (newCQRCType == 'R')
			{
				if (filterNow == 'R')
				{
					hideMeNow = true;
				}
			}
		}
	}

	if (hideMeNow)
	{
		// Get the elements of the comment...
		var imageholder = document.getElementById( 'imagecontainer' + this_id );
		var buttonholder = document.getElementById( 'buttoncontainer' + this_id );
	
		// ...and adjust them as necessary...
		hideme('commentReply' + this_id);
		hideme('commentSummary' + this_id);
		
		// ...then show them the new filter message
		if (newCQRC == 'Irrelevant')
		{
			var filterDiv = el('filterCommentMessage' + this_id);
			filterDiv.style.display = '';
			fademein('filterCommentMessage' + this_id);
		}
		else
		{
			var adultModMsg = document.getElementById ( 'commentmodmsgadult' + this_id );
			adultModMsg.style.display = '';
			fademein('commentmodmsgadult' + this_id);	
		}
	}
	
	// Let's update (or insert) the score shown on the page
	comment_cqrscore = "comment_cqrscore_" + this_id;
	comment_cqrscore_element = document.getElementById(comment_cqrscore);
	var newcqr_print = newContentCQRs;
	if (newContentCQRs > 0)
	{
		newcqr_print = "+" + newContentCQRs;
		comment_cqrscore_element.className = 'cqrscore_plus';
	}
	else
	{
		comment_cqrscore_element.className = 'cqrscore_minus';
	}
	comment_cqrscore_element.lastChild.nodeValue = newcqr_print;
	
	// Now let's show them the results
	modMsg.style.display = '';
	fademein('commentmodmsg' + this_id);  
}

function moderateTopic(id, cqrc_id, filternow)
{
	hideme('topicrating'+id);
	showme('topicrating_off'+id);

	// Set current score to "loading" state
	var topic_cqrscore = "topic_cqrscore_" + id;
	var topic_cqrscore_element = document.getElementById(topic_cqrscore);
	topic_cqrscore_element.className = "cqrscore_loading";
	var ajaxurl = '/ajaxserver/modpoll.php5?id=' + id + '&cqrcid=' + cqrc_id + '&filternow=' + filternow;
    loadXMLDoc(ajaxurl);
}

function moderateTopicDone( input, results, success )
{	   
	// Grab the results from the Ajax transaction
	var this_id = results[0].getElementsByTagName('topicid')[0].firstChild.data;
	var cqrValueAdded = results[0].getElementsByTagName('cqrvalue')[0].firstChild.data;
	var newContentCQRs = results[0].getElementsByTagName('newcqr')[0].firstChild.data;
	var newCQRC = results[0].getElementsByTagName('newcqrc')[0].firstChild.data;
	var newCQRCType = results[0].getElementsByTagName('newcqrctype')[0].firstChild.data;
	var filterNow = results[0].getElementsByTagName('filternow')[0].firstChild.data;

	// Grab our elements we are going to be modifying
	var modMsg = document.getElementById( 'topicmodmsg' + this_id );
	var modMsgCQRC = document.getElementById( 'topicmodmsgcqrc' + this_id );
	var modMsgCQRValue = document.getElementById( 'topicmodmsgcqrvalue' + this_id );
	var modMsgPosNeg = document.getElementById( 'topicmodmsgposneg' + this_id );
	var modMsgNewCQRs = document.getElementById( 'topicmodmsgnewcqrs' + this_id );
	
	// Define our text to be put in
	msgCQRValue = document.createTextNode(cqrValueAdded);
	msgNewCQRs = document.createTextNode(newContentCQRs);
	if (newCQRCType == 'N')
	{
		msgPosNeg = document.createTextNode("-");
	}
	else
	{
		msgPosNeg = document.createTextNode("+");
	}
	
	// Check to see if this was their first time rating this topic
	if (newCQRC == 'Good Quality')
	{
		toggleme('topicmodmsgposselect' + this_id);
		toggleme('topicreactionrating' + this_id);
		
		// Append our text to our locations on the page...
		modMsgCQRValue.appendChild(msgCQRValue);
		modMsgPosNeg.appendChild(msgPosNeg);
		modMsgNewCQRs.appendChild(msgNewCQRs);
	}
	else if (newCQRC == 'Poor Quality')
	{
		toggleme('topicmodmsgnegselect' + this_id);
		toggleme('topicreactionrating' + this_id);
		
		// Append our text to our locations on the page...
		modMsgCQRValue.appendChild(msgCQRValue);
		modMsgPosNeg.appendChild(msgPosNeg);
		modMsgNewCQRs.appendChild(msgNewCQRs);
	}
	else
	{
		// They rated it something else so we need to make sure the selection box is hidden...
		toggleme('topicmodmsgselector' + this_id);
		// ...and show them what they rated it as
		toggleme('topicmodmsgdone' + this_id);
		msgCQRC = document.createTextNode(newCQRC);
		modMsgCQRC.appendChild(msgCQRC);
		var x = modMsgCQRValue.lastChild;
		modMsgCQRValue.replaceChild(msgCQRValue, x);
		var n = modMsgNewCQRs.lastChild;
		modMsgNewCQRs.replaceChild(msgNewCQRs, n);
	}

	// Check to see if they rated it R or X
	if (newCQRCType == 'R' || newCQRCType == 'X')
	{
		// If they did, we can show them that they did so
		toggleme('topicreactionrating' + this_id);
		toggleme('topicreactionratingrx' + this_id);
	}
	
	// Update (or insert) the topic quality score shown on page
	var topic_cqrscore = "topic_cqrscore_" + this_id;
	var topic_cqrscore_element = document.getElementById(topic_cqrscore);
	var newcqr_print = newContentCQRs;
	if(newContentCQRs > 0) 
	{
		newcqr_print = "+" + newContentCQRs;
		topic_cqrscore_element.className = 'cqrscore_plus';
	}
	else
	{
		topic_cqrscore_element.className = 'cqrscore_minus';
	}
	topic_cqrscore_element.lastChild.nodeValue = newcqr_print;
	
	// Now let's show them the results
	modMsg.style.display = '';
	fademein('topicmodmsg' + this_id);  
}

