<script language="javascript">
function showtree(id){
	var menu = 'table' + id;
	var folder = 'folder' + id;
	var node = 'node' + id;
	if(document.all(menu) != null){
		if(document.all(menu).style.display == 'none'){
			document.all(menu).style.display = '';
			document.images[folder].src = '/open.gif';
			document.images[node].src = '/node_minus.gif';
		}
		else{
			document.all(menu).style.display = 'none';
			document.images[folder].src = '/closed.gif';
			document.images[node].src = '/node_plus.gif';
		}
	}
}
</script>

<?


If ($lst == "") {
 $lst = "1";
}
If ($sort == "") {
 $sort = "date";
}

$fr = file("tx/razdel.txt");

for ($m = 0; $m < count($fr); $m++) {
 $arb = explode("^", trim($fr[$m]));
 If ($arb[0] == $rid) {
  $w = 1;
  while ($arb[$w] <> "") {
   $rzd .= "$arb[$w]";
   If ($arb[$w+1] <> "") {
    $rzd .= " &gt;&gt; ";
   }
   $w++;
  }
 }
}
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%" bgcolor="#F0F0F0"><p><b>&gt;&gt; Купить &gt;&gt; <? echo $rzd ?></b></p></td>
  </tr>
</table>


<table border="0" width="100%" cellspacing="10" cellpadding="0">
  <tr>
    <td width="10%" valign="top">
<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #0000FF" cellspacing="1">
  <tr>
    <td width="100%" valign="top">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
           <td width="100%" bgcolor="#FBC900"><p align="center"><b>разделы</b></p></td>
        </tr>
        <tr>
           <td width="100%" valign="top">
<table border="0" cellspacing="0" cellpadding="0">
<?
 $d3 = dir("goods/");
 while($text = $d3->read()) {
  If ($text <> "." and $text <> ".." and $text <> ".htaccess") {
   $fgo = file("goods/" . $text);
   $asd[] = trim($fgo[2]);
  }
 }
 $d3->close();


//$tmp = "";
//$tmp2 = "";
//$tmp3 = "";
$pos = 0;
for ($i = 0; $i < count($fr); $i++) {
 $pos2 = $pos+1;
 $pos3 = $pos2+1;
 $ifs = false;

 $ar0 = explode("^", trim($fr[$i-1]));
 $ar = explode("^", trim($fr[$i]));
 $ar2 = explode("^", trim($fr[$i+1]));

 $tovc = 0;
 for ($t = 0; $t < count($asd); $t++) {
  If ($asd[$t] == $ar[0]) {
   $tovc = $tovc + 1;
  }
 }

 If (strtolower($ar[1]) == strtolower($txtrazdel)) {
 //первое вложение begin
  If ($ar[2] <> "") {
   If ($ar[2] <> $tmp) {
    If ($ar[3] == "") {

     echo "
<tr><td><img src='/pixel.gif' width=15 height=15></td>
<td nowrap><img src='/doc.gif' width=16 height=16 border=0>&nbsp;<a href='/buy_$txtlink.phtml?rid=$ar[0]' class='cap2'>$ar[2]&nbsp;($tovc)</a>&nbsp;</td></tr>
<td></td><td>";
    }
    Else {
     echo "
<tr><td><img id=node$pos src='/node_plus.gif' width=15 height=15 onClick=\"showtree($pos)\"></td>
<td nowrap><img id=folder$pos src='/closed.gif' width=16 height=14>&nbsp;$ar[2]&nbsp;</td></tr>
<tr><td></td><td>";
    }
    $tmp = $ar[2];
   }
   Else {
    If ($ar2[2] <> $ar[2]) {
     echo "</td></tr>";
    }
   }
  $ifs = true;
  }
 //первое вложение end

 //второе вложение begin
  If ($ar[3] <> "") {
   If ($ar[3] <> $tmp2) {
    If ($ar0[2] <> $ar[2]) { echo "<table border=0 CELLSPACING=0 CELLPADDING=0 style='display: none' id=table$pos>"; $gr1=$pos; }
     If ($ar[4] == "") {

      echo "
<tr><td><img src='/pixel.gif' width=15 height=15></td>
<td nowrap><img src='/doc.gif' width=16 height=16 border=0>&nbsp;<a href='/buy_$txtlink.phtml?rid=$ar[0]&ps=$gr1' class='cap2'>$ar[3]&nbsp;($tovc)</a>&nbsp;</td></tr>
<td></td><td>";
     }
     Else {
      echo "
<tr><td><img id=node$pos2 src='/node_plus.gif' width=15 height=15 onClick=\"showtree($pos2)\"></td>
<td nowrap><img id=folder$pos2 src='/closed.gif' width=16 height=14>&nbsp;$ar[3]&nbsp;</td></tr>
<tr><td></td><td>";
     }
    $tmp2 = $ar[3];
   }
   Else {
    If ($ar2[3] <> $ar[3]) {
     echo "</td></tr>";
    }
   }
   If ($ar2[2] <> $ar[2]) {
    echo "</table>";
   }
  $ifs = true;
  }
 //второе вложение end

 //третее вложение begin
  If ($ar[4] <> "") {
   If ($ar[4] <> $tmp3) {
    If ($ar0[3] <> $ar[3]) { echo "<table border=0 CELLSPACING=0 CELLPADDING=0 style='display: none' id=table$pos2>\n"; $gr2=$pos2;}
     If ($ar[5] == "") {

      echo "
<tr><td><img src='/pixel.gif' width=15 height=15></td>
<td nowrap><img src='/doc.gif' width=16 height=16 border=0>&nbsp;<a href='/buy_$txtlink.phtml?rid=$ar[0]&ps=$gr2' class='cap2'>$ar[4]&nbsp;($tovc)</a>&nbsp;</td></tr>
<td></td><td>\n";
     }
     Else {
      echo "
<tr><td><img id=node$pos3 src='/node_plus.gif' width=15 height=15 onClick=\"showtree($pos3)\"></td>
<td nowrap><img id=folder$pos3 src='/closed.gif' width=16 height=14>&nbsp;$ar[4]&nbsp;</td></tr>
<tr><td></td><td>";
     }
    $tmp3 = $ar[4];
  }
   Else {
    If ($ar2[4] <> $ar[4]) {
     echo "</td></tr>";
    }
   }
   If ($ar2[3] <> $ar[3]) {
    echo "</table>";
   }
  $ifs = true;
  }
 //третее вложение end



  If ($ifs == true) {
   $pos = $pos+2;
  }
 }
}


?>
</td></tr></table>
           </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- ПОИКОВИК -->
 <SCRIPT language=javascript> 
 function frmpost(){
	if(document.all){
		if(frm.name.value.length == 0) {
			alert("Заполните поисковое поле!");
			return;
		}
		frm.submit();
	}
 }
 </SCRIPT>
 <p>&nbsp;</p>

<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #0000FF" cellspacing="1">
  <tr>
    <td width="100%" valign="top">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
           <td width="100%" bgcolor="#FBC900"><p align="center"><b>поиск</b></p></td>
        </tr>
        <tr>
           <td width="100%" valign="top">
       <form method="POST" name="frm" action="/buy_sort.phtml?com=find">
         <p align="left"><input type="text" maxlength="100" name="name" size="24" style="font-family: Verdana, Arial; font-size: 8pt; border: 1 solid #7F9DB9"></p>
         <p align="left"><input type="radio" name="r1" value="1" checked>Искать в названии</p>
         <p align="left"><input type="radio" name="r1" value="2">В описании</p>
         <p align="left"><input type="radio" name="r1" value="3">В доп. информации</p>
         <p align="center"><input type="button" onClick="frmpost();" name="B1" style="font-family: Verdana, Arial; font-size: 8pt" value="Искать"></p>
       </form>
           </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- END ПОИКОВИК -->

    </td>
    <td width="90%" valign="top">

<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #0000FF" cellspacing="1">
  <tr>
    <td width="100%" valign="top">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td width="48%" bgcolor="#FBC900"><p><a href='/buy_<? echo $txtlink ?>.phtml?rid=<? echo $rid ?>&lst=<? echo $lst ?>&sort=name<? If ($sort == "name" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "name") { echo "<b>"; } ?>название<? If ($sort == "name") { echo "</b>"; } ?></a></p></td>
          <td width="10%" bgcolor="#FBC900"><p><a href='/buy_<? echo $txtlink ?>.phtml?rid=<? echo $rid ?>&lst=<? echo $lst ?>&sort=price<? If ($sort == "price" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "price") { echo "<b>"; } ?>цена<? If ($sort == "price") { echo "</b>"; } ?></a></p></td>
          <td width="10%" bgcolor="#FBC900"><p><a href='/buy_<? echo $txtlink ?>.phtml?rid=<? echo $rid ?>&lst=<? echo $lst ?>&sort=date<? If ($sort == "date" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "date") { echo "<b>"; } ?>добавлено<? If ($sort == "date") { echo "</b>"; } ?></a></p></td>
          <td width="22%" bgcolor="#FBC900"><p><a href='/buy_<? echo $txtlink ?>.phtml?rid=<? echo $rid ?>&lst=<? echo $lst ?>&sort=seller<? If ($sort == "seller" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "seller") { echo "<b>"; } ?>продавец<? If ($sort == "seller") { echo "</b>"; } ?></a></p></td>
          <td width="10%" bgcolor="#FBC900"></td>
        </tr>
            
<?
$d = dir("goods/");
while($flg = $d->read()) {
 If ($flg <> "." and $flg <> ".." and $flg <> ".htaccess") {
  $fgoods = file("goods/" . $flg);
  If (trim($fgoods[2]) == $rid) {
   $allgoods[] = $flg;
  }
 }
}
$d->close();


for ($k = 0; $k < count($allgoods); $k++){
 $rf = @file("goods/" . $allgoods[$k]);
 $ru = @file("users/" . trim($rf[0]));

 If ($sort == "name") {
  $srt = trim($rf[3]);
 }
 ElseIf ($sort == "price") {
  $srt = trim($rf[1]);
 }
 ElseIf ($sort == "date") {
  $ar = explode(".", trim($rf[4]));
  $str = (integer) $ar[2] * date("z", mktime($ar[3], $ar[4], $ar[5], $ar[1], $ar[0], $ar[2]));
 }
 ElseIf ($sort == "seller") {
  $srt = trim($ru[1]);
 }

 $srtar[] = array(0 => $srt, 1 => $allgoods[$k]);
}

If (count($allgoods) > 0) {
 If ($rv == "true") {
  If ($sort == "date") {
   sort($srtar);
  }
  Else {
   rsort($srtar);
  }
 }
 Else {
  If ($sort == "date") {
   rsort($srtar);
  }
  Else {
   sort($srtar);
  }
 }
}

for ($y = 0; $y < count($srtar); $y++) {
 $allgoods[$y] = $srtar[$y][1];
}



$lfrom = (integer) $lst * $serv_const_lstcount - $serv_const_lstcount;
$lto = (integer) $lst * $serv_const_lstcount;
If ($lto > count($allgoods)) {
 $lto = count($allgoods);
}

If (count($allgoods) <= 0) {
 echo "<tr><td><p>Товаров в этой категории не найдено.</p></td></tr>";
}

for ($r = $lfrom; $r < $lto; $r++) {

   price_min($allgoods[$r]);
   $fgoods = @file("goods/" . $allgoods[$r]);

   $edatear = explode(".", trim($fgoods[4]));
   $edate = "$edatear[0].$edatear[1].$edatear[2]";
   $fusr = @file("users/" . trim($fgoods[0]));
   $usrname = trim($fgoods[0]);

   $eusr = trim($fusr[1]);

   $ename = trim($fgoods[3]);

   If ($clr == "#F9FBFF") { 
    $clr = "#EAEDFF";
   }
   Else {
    $clr = "#F9FBFF";
   }

   If (trim($fgoods[16]) <> "" and trim($fgoods[16]) <> "0") {
    $esumm = "<font style='text-decoration: line-through'>" . trim($fgoods[16]) . "</font>&nbsp;<font color='#FF0000'>" . trim($fgoods[1]) . "</font>";
   }
   Else {
    $esumm = trim($fgoods[1]);
   }

    

   echo "
	<tr>
	<td width='48%' bgcolor='$clr'><p><a href='/buy.phtml?tovid=$allgoods[$r]' class='cap2'>$ename</a></p></td>
	<td width='10%' bgcolor='$clr'><p>$esumm</p></td>
	<td width='10%' bgcolor='$clr'><p>$edate</p></td>
	<td width='22%' bgcolor='$clr'><p><a href='/seller.phtml?name=$usrname' class='cap0'>$eusr</a></p></td>
	<td width='10%' bgcolor='$clr'><p align='right'><a href='/buy.phtml?tovid=$allgoods[$r]' class='cap2'><img border='0' src='/pic_buy.gif' width='16' height='16' alt='Купить!'></a></p></td>
	</tr>";
}
?>
      </table>
    </td>
  </tr>
</table>
<p>&nbsp;&nbsp;Страницы:
<?
//PAGES
for ($c = 1; $c <= ceil(count($allgoods) / $serv_const_lstcount); $c++) {
 If ($lst == $c) {
  echo "<b><a href='/buy_$txtlink.phtml?rid=$rid&lst=$c&sort=$sort&rv=$rv' class='cap3'>$c</a></b>";
 }
 Else {
  echo "<a href='/buy_$txtlink.phtml?rid=$rid&lst=$c&sort=$sort&rv=$rv' class='cap4'>$c</a>";
 }
 If ($c <> ceil(count($allgoods) / $serv_const_lstcount)) {
  echo " | ";
 }
}

If (count($allgoods) <= 0) {
 echo "<b><font color='#FF0000'>1</font></b>";
}
?>
</p>
    </td>
  </tr>
</table>

<?
If ($ps <> "") {
 echo "
<script language=\"javascript\">
function showmenu(me){
	var str_obj;
	if(me.id.toString().indexOf('table') >= 0){
		showtree(me.id.toString().substr(5))
	}
	if(me.parentElement != null){
		showmenu(me.parentElement);
	}
}
showmenu(document.all.table$ps);
</script>";
}
?>