var tr_delete='';
var replyComment=false;
var addToEdit = function()
	{
		comment_id = arguments[0];

		if(arguments[1])
			addCommentsUrl = arguments[1];

		var f = '';

		var frm = eval("document.addEdit_"+comment_id);
		for (var i=0;i<frm.elements.length;i++)
			{
				var e=frm.elements[i];
				if (e.type!='button')
					{
						var ovalue = Trim(e.value);
						if(ovalue)
							{
								ovalue = replace_string(ovalue, '\n', '<br />');
								f += ovalue;
							}
						else
							{
								e.value = '';
								e.focus();
								return false;
							}
					}
			}
		f = encodeURIComponent(f);
		var currpath = addCommentsUrl+'&comment_id='+comment_id+'&type=edit&f='+encodeURIComponent(f);
		callAjaxUpdate(currpath,'selCommentBlock');
		return false;
	}

function callAjaxUpdate(path, block)
	{

		path = path;
		new prototype_ajax(path,'callAjaxUpdateResponse');
		return false;
	}

function callAjaxUpdateResponse(data)
	{
		data = unescape(data.responseText);
		if(data.indexOf(session_check)>=1)
			{
				data=data.split(session_check_replace);
				data=data[1];
			}
		else
			{
				return;
			}
		data = data.split('***--***!!!');
		data[0] = data[0].strip();
		if(obj = document.getElementById('selEditCommentTxt_'+data[0]))
			obj.innerHTML = data[1];

		discardEdit(data[0]);
		return;
	}


function callAjaxEdit(path, comment_id)
	{
		//result_div = div_id;
		path = path+'&type=edit&comment_id='+comment_id;
		new prototype_ajax(path,'ajaxResultEdit');
		return false;
	}

function ajaxResultEdit(data)
	{
		data = unescape(data.responseText);
		if(data.indexOf(session_check)>=1)
			{
				var obj;
				data=data.split(session_check_replace);
				data=data[1].strip();
				data = data.split('***--***!!!');
				var ids=data[0];
				if(obj = document.getElementById('selEditCommentTxt_'+ids))
					obj.style.display = 'none';

				obj = document.getElementById('selEditComments_'+ids);

				obj.style.display = 'block';
				var txt = replace_string(data[1], '<br>', '\n');
				txt = replace_string(txt, '<br />', '\n');
				txt = trim(txt);
				obj.innerHTML = txt;
				obj = document.getElementById('selViewEditComment_'+ids);
				obj.style.display = 'none';
				return true;
			}
		return false;
	}

function discardEdit(comment_id)
	{
		var obj;

		if(obj = document.getElementById('selEditCommentTxt_'+comment_id))
			obj.style.display = '';

		if(obj = document.getElementById('selEditComments_'+comment_id))
			obj.style.display = 'none';

		if(obj = document.getElementById('selViewEditComment_'+comment_id))
			obj.style.display = '';
	}
function callAjaxEdit(path, comment_id)
	{
		//result_div = div_id;
		path = path+'&type=edit&comment_id='+comment_id;
		new prototype_ajax(path,'ajaxResultEdit');
		return false;
	}

function ajaxResultEdit(data)
	{
		data = unescape(data.responseText);
		if(data.indexOf(session_check)>=1)
			{
				var obj;
				data=data.split(session_check_replace);
				data=data[1].strip();
				data = data.split('***--***!!!');
				var ids=data[0];
				if(obj = document.getElementById('selEditCommentTxt_'+ids))
					obj.style.display = 'none';

				obj = document.getElementById('selEditComments_'+ids);

				obj.style.display = 'block';
				var txt = replace_string(data[1], '<br>', '\n');
				txt = replace_string(txt, '<br />', '\n');
				txt = trim(txt);
				obj.innerHTML = txt;
				obj = document.getElementById('selViewEditComment_'+ids);
				obj.style.display = 'none';
				return true;
			}
		return false;
	}

function discardEdit(comment_id)
	{
		var obj;

		if(obj = document.getElementById('selEditCommentTxt_'+comment_id))
			obj.style.display = '';

		if(obj = document.getElementById('selEditComments_'+comment_id))
			obj.style.display = 'none';

		if(obj = document.getElementById('selViewEditComment_'+comment_id))
			obj.style.display = '';
	}


function deleteCommand(path, div_id)
	{
		replyComment=false;
		if(confirm(deleteConfirmation))
			{
				tr_delete = div_id;
				new prototype_ajax(path);
				beforeDeleteResult();
			}
		return false;
	}
function deleteCommandReply(path, div_id)
	{
		replyComment=true;
		if(confirm(deleteConfirmation))
			{
				tr_delete = div_id;
				new prototype_ajax(path);
			}	beforeDeleteResult();
		return false;
}
	function beforeDeleteResult()
	{
		var obj;

		if(obj = document.getElementById('del'+tr_delete))
			obj.style.display = 'none';

		if(obj = document.getElementById(tr_delete))
			obj.style.display = 'none';

		if(obj = document.getElementById(tr_delete+'_1'))
			obj.style.display = 'none';
		if(obj = document.getElementById(tr_delete+'_2'))
			obj.style.display = 'none';
		if(obj = document.getElementById(tr_delete+'_3'))
			obj.style.display = 'none';
		if(replyComment==false)
		{

				if(obj = document.getElementById('total_comments1'))
			{
				total_comments = parseInt(obj.innerHTML)-1;
				obj.innerHTML = total_comments;
			}

			if(obj = document.getElementById('total_comments2'))
			{
				total_comments = parseInt(obj.innerHTML)-1
				obj.innerHTML = total_comments;
			}

			if(total_comments && total_comments<=minimum_counts)
			{
				if(obj = document.getElementById('view_all_comments'))
					obj.style.display = 'none';
			}

		if(obj = document.getElementById('totalComments'))
			obj.innerHTML = parseInt(obj.innerHTML)-1;
		}
	}

