﻿// ====================================================================================================
//
//          Page: AJAX WEB COMMENT FUNCTIONS
//        Author: Michael Marzilli   ( http://www.linkedin.com/in/michaelmarzilli )
//       Created: Aug 11, 2011
//
//	Minify with: http://sundgaard.dk/javascript-minify.aspx
//
// VERS 1.0.000 : Aug 11, 2011 : Original File Created, split off from JSLibrary.js.
//
// ====================================================================================================



// WEB COMMENT FUNCTIONS
// ----------------------------------------------------------------------------------------------------	
var strWebCommentID   = 'Comments';
var intCommentUID     = 0;
var intCommentType    = 0;
var intCommentRefresh = 120;
var intCommentID      = 0;
var intArticleID      = 0;
var intReplyToID      = 0;
var intCommentPrivate = 0;
var intCommentLimit   = 0;
var intCommentPlace   = 0;
var intCommentDir     = 1;
var commentAJAX;


function CommentToggle()
{
	var nodeDiv = getObjectElementByID('cmntGlobal', 'divCommentWrapper');
	if (nodeDiv == null)
		return;

	if (nodeDiv.style.visibility == 'visible')
	{
		nodeDiv.style.visibility = 'hidden';
		nodeDiv.style.display = 'none';
	}
	else
	{
		nodeDiv.style.visibility = 'visible';
		nodeDiv.style.display = 'block';
	}
}

function GetCommentTextBox()
{
	return getObjectElementByID(strWebCommentID, 'txtCommentEntry');
}
function GetCommentTextBoxText()
{

	var strTemp;
	var intReturn;
	var intSpace;
	var intEnd;
	var strURL;
	var strReturn = GetCommentTextBox().value;

	trim(strReturn);
	strReturn = strReturn.replace(/</g, "[");
	strReturn = strReturn.replace(/>/g, "]");
	strReturn = strReturn.replace(/&/g, "and");
	strReturn = chat_string_create_urls(strReturn);

	return strReturn;
}
function MyCommentSend(strButton)
{
	var strMsg = GetCommentTextBoxText()
	strMsg = trim(strMsg);
	if (strMsg == '')
	{
		GetCommentTextBox().value = '';
		GetCommentTextBox().focus();
		return;
	}

	AJAX_COMMENT_SEND();
	GetCommentTextBox().disabled = true;
	GetCommentTextBox().value    = 'Thank you for your comment.';

	var obj = getObjectElementByID(strWebCommentID, strButton);
	if (obj != null)
	{
		obj.disabled = true;
		setTimeout("GetCommentTextBox().value = '';GetCommentTextBox().disabled = false; getObjectElementByID('" + strWebCommentID + "', '" + strButton + "').disabled = false; GetCommentTextBox().focus();", 5000);
	} else
		setTimeout("GetCommentTextBox().value = '';GetCommentTextBox().disabled = false; GetCommentTextBox().focus();", 5000);
}
function StartWebComment()
{
	setTimeout('AJAX_COMMENT_START()', 250);
}


function AJAX_COMMENT_START()
{
	commentAJAX = new AJAX();
	commentAJAX.SetID('commentAJAX');
	commentAJAX.SetAJAXpoll(intCommentRefresh);
	commentAJAX.SetAJAXscrolling(false);
	commentAJAX.SetAJAXgetFunction('AJAX_COMMENT_GET');
	commentAJAX.SetAJAXtarget('AJAX_Comment.aspx');
	commentAJAX.SetAJAXwaitObject(strWebCommentID, 'commentwait');
	commentAJAX.SetTargetDiv(strWebCommentID, 'divCtrlCommentList');
	commentAJAX.SetTargetTempDiv('div_comment_temp');
	commentAJAX.SetAJAXbeepPlay(0);
	commentAJAX.SetAJAXbeep(0);
	commentAJAX.SetAJAXbeepOverride(0);
	window.setTimeout('AJAX_COMMENT_GET()', 300);
}
function AJAX_COMMENT_GET()
{
	commentAJAX.ClearParams();
	commentAJAX.AddParam('app',    'comment');
	commentAJAX.AddParam('action', 'request');
	commentAJAX.AddParam('uid',   intCommentUID);
	commentAJAX.AddParam('type',  intCommentType);
	commentAJAX.AddParam('artid', intArticleID);
	commentAJAX.AddParam('limit', intCommentLimit);
	commentAJAX.AddParam('place', intCommentPlace);
	commentAJAX.AddParam('dir',   intCommentDir);
	commentAJAX.AddParam('priv',  intCommentPrivate);
	commentAJAX.GetAJAX();
}
function AJAX_COMMENT_SEND()
{
	var strMsg = GetCommentTextBoxText();
	commentAJAX.SetAJAXWaitVisible();
	commentAJAX.SetAJAXbeepOverride(1);
	commentAJAX.SetAJAXbeep(0);
	commentAJAX.ClearParams();
	commentAJAX.AddParam('app',    'comment');
	commentAJAX.AddParam('action', 'send');
	commentAJAX.AddParam('type',  intCommentType);
	commentAJAX.AddParam('cmtid', 0);
	commentAJAX.AddParam('artid', intArticleID);
	commentAJAX.AddParam('uid',   intCommentUID);
	commentAJAX.AddParam('repid', intReplyToID);
	commentAJAX.AddParam('limit', intCommentLimit);
	commentAJAX.AddParam('place', intCommentPlace);
	commentAJAX.AddParam('dir',   intCommentDir);
	commentAJAX.AddParam('priv',  intCommentPrivate);
	commentAJAX.AddParam('msg',   strMsg);
	commentAJAX.SendAJAXtext();
	GetCommentTextBox().value = '';
	GetCommentTextBox().focus();
}
function AJAX_COMMENT_MODIFY(intCommentID, intUserID, intTypeID)
{
	var strTemp = '';
	switch (intTypeID)
	{
		case 1:
			strTemp = 'like';
			break;
		case 2:
			strTemp = 'dislike';
			break;
		case 3:
			strTemp = 'abuse';
			break;
	}
	commentAJAX.SetAJAXWaitVisible();
	commentAJAX.SetAJAXbeepOverride(1);
	commentAJAX.SetAJAXbeep(0);
	commentAJAX.ClearParams();
	commentAJAX.AddParam('app',   'comment');
	commentAJAX.AddParam('action', strTemp);
	commentAJAX.AddParam('cmtid',  intCommentID);
	commentAJAX.AddParam('uid',    intCommentUID);
	commentAJAX.AddParam('priv',   intCommentPrivate);
	commentAJAX.AddParam('msg', '');
	commentAJAX.SendAJAXtext();
}
function AJAX_COMMENT_RESET()
{
	commentAJAX.SetAJAXWaitVisible();
	commentAJAX.ClearDiv();
	commentAJAX.ClearParams();
	commentAJAX.AddParam('app',    'comment');
	commentAJAX.AddParam('action', 'request');
	commentAJAX.AddParam('uid',   intCommentUID);
	commentAJAX.AddParam('type',  intCommentType);
	commentAJAX.AddParam('artid', intArticleID);
	commentAJAX.AddParam('limit', intCommentLimit);
	commentAJAX.AddParam('place', intCommentPlace);
	commentAJAX.AddParam('dir',   intCommentDir);
	commentAJAX.AddParam('priv',  intCommentPrivate);
	commentAJAX.SendAJAXtext();
	GetCommentTextBox().value = '';
	GetCommentTextBox().focus();
}
function SetCommentModifier(intCommentID, intUserID, intTypeID)
{
	AJAX_COMMENT_MODIFY(intCommentID, intUserID, intTypeID);
	return false;
}


