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+'&page=comment_edit&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+'&page=comment_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;	
		pars = '';
		if(confirm(deleteConfirmation))
			{
				tr_delete = div_id;
				var myAjax = new Ajax.Request(
					path,
					{
						method: 'post',
						parameters: pars,
						onComplete: beforeDeleteResult
					});
			}
		return false;
	}
function deleteCommandReply(path, div_id)
	{
			replyComment=true;
			pars = '';
			if(confirm(deleteConfirmation))
				{
					tr_delete = div_id;
					var myAjax = new Ajax.Request(
								path,
								{
									method: 'get',
									parameters: pars,
									onComplete: beforeDeleteResult
								});
					return false;
				}
			return false;
	}
	function beforeDeleteResult(data)
		{
			var obj;
			//ERROR MESSAGES
			$('selCommentBlock').show();
			$('selMsgSuccess').show();	
			$('kindaSelMsgSuccess').innerHTML = comment_success_deleted_msg;
			$('selMsgSuccess').fade({ duration: 3.0, from: 1, to: 0 });
			//CONTENT
			data = unescape(data.responseText);
			if(data.indexOf(session_check)>=1)
				data = data.replace(session_check_replace,'');
			else
				return;
			$('selCommentBlock').innerHTML = data;	
			return false;
		}
