
function postAddToQueue (checkBox)
	{
	var queue = $('#postQueue');
	var currentQueue = queue.val().split('|');
	var newQueue = '';
	for (var i = 0; i < currentQueue.length; i++)
		{
		if (currentQueue[i] != checkBox.value && currentQueue[i] != '')
			{
			newQueue += currentQueue[i] + "|";
			}
		}
	if (checkBox.checked)
		{
		newQueue += checkBox.value;
		}
	queue.val(newQueue);
	}

// INITIALIZE POST FORM
function postInitForm (postType, ArgItemID, ArgIDType, ArgBoA)
	{
	PFRequest = getXMLHttpRequestObject();
	postGetForm(postType, ArgItemID, ArgIDType, ArgBoA);
	}


// GET POST FORM DATA
function postGetForm (postType, ArgItemID, ArgIDType, ArgBoA) 
	{
	if (PFRequest.readyState == 4 || PFRequest.readyState == 0) 
		{
		// EDITING A POST
		if (ArgIDType == 'pid')
			{
			var commentsField = "comments_"+ArgItemID;
			var urlIDType = 'pid';
			var IsAQuote = "ignore";
			var IsAQuoteURL = '';
			var WhatToChange = 'post-' + ArgItemID;
			}
		// QUOTING A POST
		else if (ArgIDType == 'pidq')
			{
			var commentsField = "comments_quote"+ArgItemID;
			var urlIDType = 'pid';
			var IsAQuoteURL = "&quote=1";
			var IsAQuote = '1';
			var WhatToChange = 'post-' + ArgItemID;
			}
		// ADDING A POST
		else
			{
			var commentsField = "comments_new"+ArgItemID;
			var urlIDType = 'id';
			var IsAQuote = "ignore";
			var IsAQuoteURL = '';
			var WhatToChange = 'Post_Form_Area';
			}
		PFRequest.open("GET", baseURL + '/ajaxdata.php?type=postform&ptype='+postType+'&' + urlIDType + '=' + ArgItemID + IsAQuoteURL, true);
		PFRequest.onreadystatechange = function ()
			{
			postHandleForm(WhatToChange, IsAQuote, 'ignore', ArgBoA, commentsField);
			}
		PFRequest.send(null);
		}			
	}


// HANDLE THE POST FORM DATA
function postHandleForm (DivToChange, IsQuoted, Collapse, BoA, commentsField) 
	{
	if (PFRequest.readyState == 4) 
		{
		var PostFormArea = document.getElementById(DivToChange);
		if (Collapse != 'ignore')
			{
			var PostItem = document.getElementById('PostFormSurround');
			PostItem.innerHTML = '';
			}
		if (IsQuoted != 'ignore')
			{
			if (BoA == '0')
				{
				PostFormArea.innerHTML = PFRequest.responseText + PostFormArea.innerHTML;
				}
			else
				{
				PostFormArea.innerHTML += PFRequest.responseText;
				}
			}
		else
			{
			PostFormArea.innerHTML = PFRequest.responseText;
			}
//alert(commentsField);
		//alert(commentsField);
		if (!core.isMobile)
			{
			if (CKEDITOR.instances[commentsField])
				{
				//alert('exists');
				//CKEDITOR.instances[commentsField].destroy();
				CKEDITOR.remove(CKEDITOR.instances[commentsField]);
				}
			CKEDITOR.replace(commentsField, {customConfig : baseURL+'/'+pubDir['lib']+'/js/wysiwyg-comments.js'});
			}
		//wysiwyg_comments();
		}
	}


function postProcessForm (postType, PassItemID, ArgIDType, IsQuoteProcess)
	{
	if (IsQuoteProcess != '1')
		{
		var IsQuoteProcess = '0';
		}
	if (PFRequest.readyState == 4 || PFRequest.readyState == 0) 
		{
		if (ArgIDType == 'pid')
			{
			var commentsField = "comments_"+PassItemID;
			var urlIDType = 'pid';
			var CollapseID = 'ignore';
			var WhatToChange = 'post-' + PassItemID;
			}
		else if (ArgIDType == 'pidq')
			{
			var commentsField = "comments_quote"+PassItemID;
			var urlIDType = 'id';
			var CollapseID = 'ignore';
			var WhatToChange = 'post-' + PassItemID;
			}
		// USED WHEN HANDLING ADDING A QUOTED POST
		else if (IsQuoteProcess == '1')
			{
			var commentsField = "comments_quote"+PassItemID;
			var urlIDType = 'id';
			var CollapseID = '1';
			var WhatToChange = 'Post_Form_Area';
			}
		else
			{
			var commentsField = "comments_new"+PassItemID;
			var urlIDType = 'id';
			var CollapseID = 'ignore';
			var WhatToChange = 'Post_Form_Area';
			}
		PFRequest.open("POST", baseURL + '/ajaxdata.php?type=postform&ptype='+postType+'&' + urlIDType + '=' + PassItemID, true);
		PFRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var PostForm = document.getElementById('PostForm');
		var PostQuery = MakeQueryString(PostForm);
		if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[commentsField]) != 'undefined')
			{
			var pData = CKEDITOR.instances[commentsField].getData();
			}
		else
			{
			var pData = $('#'+commentsField).val();
			}
		PostQuery += "&comments=" + urlencode(pData);
		PFRequest.send(PostQuery);
		PFRequest.onreadystatechange = function()
			{
			postHandleForm(WhatToChange, 'ignore', CollapseID, 0, commentsField);
			}
		}
	}

