<fieldset>
	<legend>Комментарии пользователей</legend>
		<div id="comm_id" style="padding-top:10px" >
		<? 
		if(!$_SESSION['ID_P']) 
		echo '<font color=green>Комментарии могут оставлять только зарегистрированные пользователи</font><br>';
		elseif ($_SESSION['ID_P'][1] != $rr['id_akk'])
			{
			?>
			<form id="form_comment" method="post" >
			<textarea name="comment" rows="4" cols="70"></textarea>
			<input name="com_a" type="hidden" value="1">
			<input name="submit" class="submit" type="submit" onclick="comment_add(<?=$id?>); return false" value="Оставить комментарий">
			</form>
			<?
			}

		$com=mysql_query("SELECT * FROM comment WHERE id='".$id."' ORDER BY parent_id, id_comment");
		while($r_com=mysql_fetch_array($com))
			{
			if(!$r_com['moder'])
				{
				echo '<p>';
				if($r_com['contakt']) 
					{
					echo '<b>'.$r_com['contakt'].'</b> ('.date("d-m-Y H:i", strtotime($r_com['data'])).')';
					if(($_SESSION['ID_P'][1] == $rr['id_akk'] || $_SESSION['ID_Glob']) && !$r_com['typ_comment']) 
					echo ' ['.$r_com['id_akk'].']';
					echo '<br>';
					}
				
				if(!$r_com['typ_comment'])
				echo $r_com['comment'];
				else
				echo '<span style="color:#003366">'.$r_com['comment'].'</span>';

				if($_SESSION['ID_P'][1] == $rr['id_akk'] || $_SESSION['ID_P'][1] == $r_com['id_akk'])
					{
					echo '<br>';
					if($_SESSION['ID_P'][1] == $rr['id_akk'] && !$r_com['typ_comment'])
					echo ' <span id="otvet_'.$r_com['id_comment'].'"><font color=blue><b>&#8764;</b></font><a href="javascript:otvet('.$id.','.$r_com['id_comment'].')">Ответить на комментарий</a></span>';
					echo ' <font color=red><b>&#215;</b></font><a href="javascript:send_opt('.$id.', '.$r_com['id_comment'].', 2)">Удалить</a>';
					}
				}
			elseif($r_com['moder'] && ($_SESSION['ID_P'][1] == $rr['id_akk'] || $_SESSION['ID_P'][1] == $r_com['id_akk'] || $_SESSION['ID_Glob']))
				{
				echo '<p><span style="color:#CC9999">';
				if($r_com['contakt']) 
					{
					echo '<b>'.$r_com['contakt'].'</b> ('.date("d-m-Y H:i", strtotime($r_com['data'])).')';
					if($_SESSION['ID_P'][1] == $rr['id_akk'] || $_SESSION['ID_Glob'])
					echo ' ['.$r_com['id_akk'].'] ';
					echo '<br>';
					}
					
				if($_SESSION['ID_P'][1] == $rr['id_akk'])
				echo ' - <span style="color:#FF0000">Комментарий ожидает Вашего одобрения</span><br>';
				else
				echo ' - <span style="color:#FF0000">Комментарий ожидает одобрения владельца объявления</span><br>';
			
				echo $r_com['comment'];
				echo '<span>';
				
				if($_SESSION['ID_P'][1] == $rr['id_akk'] || $_SESSION['ID_P'][1] == $r_com['id_akk'])
					{
					echo '<br>';
					if($_SESSION['ID_P'][1] == $rr['id_akk'])
					echo ' <font color=green><b>&#8744;</b></font><a href="javascript:send_opt('.$id.', '.$r_com['id_comment'].', 1)">Одобрить</a>';
					echo ' <font color=red><b>&#215;</b></font><a href="javascript:send_opt('.$id.', '.$r_com['id_comment'].', 2)">Удалить</a>';
					}
				}
			}
		
		?>
					
		</div>
</fieldset>

<br>
<script>
function otvet(id, id_comment)
	{
	var a = '<form id="form_otv" method="post"><textarea name="comment" rows="4" cols="70"></textarea><input name="com_b" type="hidden" value="1"><input type="hidden" name="parent_id" value="'+id_comment+'"><input name="submit" class="submit" type="submit" onclick="comment_otv('+id+'); return false" value="Ответить на комментарий"></form>';
	document.getElementById('otvet_'+id_comment).innerHTML = a; 
	}
	
function send_opt(id, id_comment, opt)
			{
			$.ajax({
					type: "GET",
					url: "<?=$bp.'comment/'?>c_ajax.php?id="+id+"&id_comment="+id_comment+"&opt="+opt,
					success: function(html) {
						$("#comm_id").empty();
						$("#comm_id").append(html);
                	}
        		});
			}
	
function comment_add(id) {
      		var str = $("#form_comment").serialize();
			$.ajax({
					type: "POST",
					url: "<?=$bp.'comment/'?>c_ajax.php?id="+id,
					data: str,
					success: function(html) {
						$("#comm_id").empty();
						$("#comm_id").append(html);
                	}
        		});
				scrollTo("#comm_id");
    		}
			
function comment_otv(id) {
      		var str = $("#form_otv").serialize();
			$.ajax({
					type: "POST",
					url: "<?=$bp.'comment/'?>c_ajax.php?id="+id,
					data: str,
					success: function(html) {
						$("#comm_id").empty();
						$("#comm_id").append(html);
                	}
        		});
				scrollTo("#comm_id");
    		}

</script>