<center>
<table style="width:100%;" cellpadding="0" cellspacing="0"><tr><td style="width:64%;background-color : #FFF9F0;">
<?php
if (!empty($_POST['comment_is']) and ($_POST['comment_is']<>'Комментарий')){
	if ($_POST['code_comment']<>$_SESSION['code']){
		echo '<center><p><span class="div_bbig">Введенный вами код неверен</span></p></center>';
	}else{
		if ($_SESSION['IsEnter'] == 1){
			$_POST['comment_login'] = $_SESSION['IsMyLogin'];
		}else{
			if ($_POST['comment_login']=='' or $_POST['comment_login']=='Ваш ник'){$_POST['comment_login'] = 'Гость';}else{
				$_POST['comment_login'] = addslashes(htmlspecialchars($_POST['comment_login']));
				$_SESSION['cmt_login'] = $_POST['comment_login'];
			}
		}
		$_POST['comment_is'] = addslashes(htmlspecialchars($_POST['comment_is']));
		$_POST['comment_is'] = str_replace("\r\n", "<br />", $_POST['comment_is']);
		
		mysql_select_db('onestyle_w');
		$query = "insert into octblTag_" . $_GET['p'] . " (c_word_id, c_nick, c_comment, c_date, c_reg) values (" . $_GET['u'] . ", '" . $_POST['comment_login'] . "', '" . $_POST['comment_is'] . "', '" . date('j.m.Y, H:i:s') . "', ";
		if ($_SESSION['IsEnter'] == 1){$query .= "1)";}else{$query .= "0)";}
		$result = mysql_query($query) or print("облом, но все-таки: <br />");
		mysql_select_db('onestyle_testmy');
		echo '<center><p><span class="div_bbig">Ваш комментарий добавлен</span></p></center>';
	}
}
?>
</td><td rowspan="2"><FORM style="position:relative;top:-1px;" class="sm" METHOD="POST" id="add_comment" action="<?php echo $_SERVER['REQUEST_URI'] . "#add_comment";?>">
<center><textarea class="cwidth" style="background-color : #FFF9F0;border: 0px none transparent;border-bottom: 1px solid #FCCE92;" rows="7" name="comment_is">Комментарий</textarea>
<div class="p_block rgt">
<?php
if ($_SESSION['IsEnter'] == 1){
	echo "Ник: " . "<pre style='display:inline;'>" . $_SESSION['IsMyLogin'] . "</pre>";
}else{
?>
<input class="cinline input_or" size="40" maxlength="40" type="text" name="comment_login" value="<?php if (isset($_SESSION['cmt_login'])){echo $_SESSION['cmt_login'];}else{ echo "Ваш ник";} ?>" />
<?php } ?>
</div></center>
<table><tr><td class="pg10"><img src="code.php"></td>
<td class="sm"><p>Введите цифры, изображенные<br />на картинке слева:</p><input class="cinline" type="text" size="4" maxlength="4" name="code_comment">
<input class="cinline" type="Submit" name="comment_Send" value="Добавить">
</td></tr></table>
</FORM>
<div class="pg10 sm">
<?php
	if ($i > 5){
		include "../ggl_ref_txt.php";
	}
?>
</div></td></tr><tr><td style="border-right: 3px solid #FFF9F0;border-bottom: 3px solid #FFF9F0;border-left: 3px solid #FFF9F0;">
<div class="black_block cntr" style="color:#FCCE92;"><span class="div_bbig">Комментарии</span> <a class="a_tags" title="Отобразить все комментарии к записи" href="comment.php?d=<?php echo $_GET['p'];?>&u=<?php echo $_GET['u'];?>">[ все ]</a>&nbsp;<a class="a_tags" title="Комментарии к другим записям" href="forcomment.php?d=<?php echo $_GET['p'];?>&u=<?php echo $_GET['u']?>">[ другие ]</a></div>
<?php
mysql_select_db('onestyle_w');
$query = "select * from octblTag_" . $_GET['p'] . " where c_word_id= " . $_GET['u'] .  " ORDER BY commentid asc";

//проверка лимита
$result = mysql_query($query);
$z = mysql_num_rows($result);
if (isset($_GET['l'])){$query .= " limit " .$_GET['l'] . "," . $cur_list_numb;}else{$query = $query . " limit 0," . $cur_list_numb;}
$result = mysql_query($query);
$num_result = mysql_num_rows($result);

$i = 0;
if ($num_result){
	if (isset($_GET['l'])){echo '<div class="black_block_c" id="cmt_show">';}else{
	echo "<p class='cntr' id='cmt_ashow'><a class='sm' href='javascript:void(0)' onclick='document.getElementById(";
	echo '"cmt_show").style.display = "block";document.getElementById("cmt_ashow").style.display = "none";';
	echo "'>Отобразить ";
	if (isset($_GET['l']) and $_GET['l'] > 0){echo "следующие ";}else{echo "первые ";}
	echo $_SESSION['listnumb'] . " комментариев(я)</a></p>";
	echo '<div class="black_block_c" id="cmt_show" style="display:none;">';
	}
	for ($i=0; $i<$num_result; $i++){
		$row = mysql_fetch_array($result);?>
<div class="bl_w sm">
<?php
if (isset($_GET['l'])){
	echo $i + 1 + $_GET['l'];}
else{
	echo $i + 1;
}
?>
:
<span class="div_bbig">
[<?php echo $row['c_date']; ?>]&nbsp;&nbsp;</span><?php 
if ($row['c_reg'] == 1){echo "<span class='sm' style='color:navy;'>[ reg ]</span> ";}
echo "<pre style='display:inline;'>" . $row['c_nick'] . "</pre>";
?></div>
<div class="sm" style="padding:7px;border-right: 3px solid #FFF9F0;border-left: 3px solid #FFF9F0;border-bottom: 3px solid #FFF9F0;"><span><?php
echo $row['c_comment'] . '</span></div>'; 
	}
	if (isset($_GET['l'])){ }else{echo '</div>';}
}else{
	echo '<p class="cntr sm">Комментариев нет</p>';
}
mysql_select_db('onestyle_testmy');
?>
<div class="black_block">
<FORM METHOD="POST" class="cinline" id="list_reload" action="<?php echo $_SERVER['REQUEST_URI'];?>">
<select class="cinline" name="list_numb" onchange="javascript:list_reload.submit();">
<?php
for($k=3;$k<10;$k++){
	echo "<option";
	if ($k == $cur_list_numb) {echo " selected";}
	echo ">" . $k . "</option>";
}
?>
</select>
</form>
<span id="result_bar">Всего: <?php echo $z; ?>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<?php 
$_GET['l'] = intval($_GET['l']);
$window_cur = 0;
if (isset($_GET['u'])){}else{$_GET['u'] = 1;}

if (isset($_GET['l'])){
	$zz = intval(($_GET['l'])/($cur_list_numb*6))*$cur_list_numb*6 + 1;
}else{
	$zz=1;
}
if ($_GET['l'] >= $cur_list_numb){
	echo "<a class='a_black2' href='" . $site_pages[$_GET['p']][1] . "?u=" . $_GET['u'] . "&l=" . ($_GET['l']-$cur_list_numb) . "#add_comment'>пред</a> ";
}

if (intval(($_GET['l'])/($cur_list_numb*6))>0){echo "<a class='a_black2' href='" . $site_pages[$_GET['p']][1] . "?u=" . $_GET['u'] . "&l=" . (($_GET['l']/($cur_list_numb*6) - 1)*$cur_list_numb*6) . "#add_comment'>&lt;&lt;</a>";}

for($ztmp = $z - intval(($_GET['l'])/($cur_list_numb*6))*$cur_list_numb*6; $ztmp>$cur_list_numb; $ztmp-=$cur_list_numb){
if ($zz==($_GET['l']+1)){
echo "[" . $zz . "-" . ($zz + $cur_list_numb - 1) . "]&nbsp;";
}else{
	echo "<a class='a_black2' href='" . $site_pages[$_GET['p']][1] . "?u=" . $_GET['u'] . "&l=" . ($zz - 1) . "#add_comment'>[" . $zz . "-" . ($zz + $cur_list_numb - 1) . "]</a>&nbsp;";
}
$zz+=$cur_list_numb;
++$window_cur;
if ($window_cur>5){break;}
}
if ($zz==($_GET['l']+1)){
echo "[" . $zz . "-" . ($zz + $cur_list_numb - 1) . "]&nbsp;";
}else{
	echo "<a class='a_black2' href='" . $site_pages[$_GET['p']][1] . "?u=" . $_GET['u'] . "&l=" . ($zz - 1) . "#add_comment'>[" . $zz . "-" . ($zz + $cur_list_numb - 1) . "]";
	if ($window_cur>5){echo "&gt;&gt;";}
	echo "</a>&nbsp;";
}
if ($_GET['l'] + $cur_list_numb <= $z){
	echo "<a class='a_black2' href='" . $site_pages[$_GET['p']][1] . "?u=" . $_GET['u'] . "&l=" . ($_GET['l']+$cur_list_numb) . "#add_comment'>след</a> ";
}

?>
</div>
</td></tr></table></center>
