function hideform()
{
	//$q('#comment_form').hide('fast');
	$q('form[name="form_x"] textarea[name="t_text"]').val('');
	$q('form[name="form_x"] input[name="i_answer_id"]').val(0);
}

handlers['comment_error']=function(text)
{
	var tmp = $('logjerk2').innerHTML;
	$('logjerk2').innerHTML=text;
	
	showlog('logjerk2');
	setTimeout(function(){$q("#logjerk2").hide("fast");}, 3000);
};

handlers['comment_add']=function(text)
{
	var id = /^(.+?)\|/.exec(text);
	id = parseInt (id[1],10);
	
	text = text.replace(/.+?\|/, "");
	text = $e('span',{innerHTML:text}).getElementsByTagName('div')[0];

	hideform();

	if(id)
	{
		$q('#c_'+id).append(text);
		$q('#' + text.id).show('fast');
	}
	else 
	{
		$q('#comments_data').append(text);
		$q('#' + text.id).show('fast');
	}
};

$q('#comment_new').click(function(){ 
	$q(this).parent().append( $q('#comment_form')); 
	$q('#comment_form').show('slow');
});

$q('a.reply').livequery('click', function(event) { 

	id = $q(this).parent().parent().attr('id').replace(/c_/, '');
	$q(this).parent().append( $q('#comment_form')); 

	t_value = $q(this).parent().parent().find('p.user a:first').text() + ': ' + $q('form[name="form_x"] textarea[name="t_text"]').val();

	$q('#comment_form').css({display: 'block'});
	$q('form[name="form_x"] textarea[name="t_text"]').val(t_value);
	$q('form[name="form_x"] input[name="i_answer_id"]').val(id);

	$q('.reply').removeClass('active');
	$q(this).addClass('active');

});

$q('.buttons a.answers').click(function(){
	hideform();
	if ( $q(this).attr('class') == 'answers')
	{
		var level = parseInt( $q(this).parent().parent().attr('class').replace(/comment l_/, ''), 10) + 1;
		$q(this).addClass('open');
		$q(this).parent().parent().find('.l_' + level).slideDown('fast');
		$q(this).parent().find("a.multiple").css({display: 'block'});
		console.log('q');
	}
	else
	{
		$q(this).removeClass('open');
		$q(this).parent().parent().find('.comment').slideUp('fast');
		$q(this).parent().parent().find("a.multiple").css({display: 'none'});
	}
});

var U_comment=
{
	deletex:function(id)
	{
		AC.simple('?ZRP=comment.delete&args={}','POST',{"i_com_id":id},function(text)
		{
			var txt = json_decode(text);
			if(!txt) alert(text);
			
			if(!txt[1])
			{
				window.location.hash='';
				window.location.href=window.location.href;
				return;
			}
			
			var com=$('c_'+txt[0]);
			
			if(!com) return;
			
			hideform();
			com.parentNode.removeChild(com);
		});
	}
};