/*
 postReply
 
 This function will post a reply through Ajax 
*/

function postReply(articleID,objectForm,userOrCrew,listToRefresh,textAreaToBlock,buttonToBlock,replyIDField,parentID)
{
	passThroughValue = new Array();
	passThroughValue[0] = userOrCrew;
	passThroughValue[1] = listToRefresh;
	passThroughValue[2] = textAreaToBlock;
	passThroughValue[3] = buttonToBlock;
	passThroughValue[4] = replyIDField;
	passThroughValue[5] = parentID;
	
	document.getElementById(""+buttonToBlock).disabled = true;
	ajaxSubmitFormPOST('ajaxArticleReply.php',objectForm,'procesReply',passThroughValue);

	document.getElementById('parentIDuser').value = 0;
	document.getElementById('parentIDcrew').value = 0;
}

function procesReply(ajaxStatus,ajaxResponse,passThroughValue)
{
	if(ajaxStatus == 202)
	{
		eval(''+ajaxResponse);
	}
	else
	{
		ajaxInnerXHTML(passThroughValue[1],ajaxResponse);
		document.getElementById(""+passThroughValue[2]).value = "";
		
	}
	document.getElementById(""+passThroughValue[3]).disabled = false;
	document.getElementById(""+passThroughValue[4]).value = "0";
}

function getQuoteArticleReply(replyID, formToReply)
{
	document.getElementById(formToReply).value = replyID;
	document.getElementById('editReplyIDUser').value = 0;
	document.getElementById('editReplyIDCrew').value = 0;
	document.getElementById('postTextUser').value = "";
	document.getElementById('postTextCrew').value = "";
}

function getEditArticleReply(replyID,textAreaToEdit,editReplyIDCrew)
{
	var http = ajaxRequestObject();
	var returnElements;
	var stringText;
	
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
		{
			if(http.status == 200)
			{
				document.getElementById(""+textAreaToEdit).value = http.responseText;
				document.getElementById(""+editReplyIDCrew).value = replyID;
			}
		}
	}
	http.open('get','ajaxArticleReply.php?edit=1&replyID='+replyID,true);
	http.send(null);

	document.getElementById('parentIDuser').value = 0;
	document.getElementById('parentIDcrew').value = 0;
}

function deleteArticleReply(articleID,replyID,userOrCrew,listToRefresh,replyIDField)
{
	var http = ajaxRequestObject();
	var returnElements;
	var stringText;
	
	http.onreadystatechange = function()
	{
		if(http.readyState == 4)
		{
			if(http.status == 200)
			{
				ajaxInnerXHTML(listToRefresh,http.responseText);
			}
		}
	}
	
	var goAhead = confirm('Weet je zeker dat je reactie wilt verwijderen?');
	
	if(goAhead == true)
	{
		if(document.getElementById(""+replyIDField).value == replyID)
		{
			document.getElementById(""+replyIDField).value = "0";
		}
			
		http.open('get','ajaxArticleReply.php?articleID='+articleID+'&userOrCrew='+userOrCrew+'&delete=1&replyID='+replyID,true);
		http.send(null);
	}

	document.getElementById('parentIDuser').value = 0;
	document.getElementById('parentIDcrew').value = 0;
}
