<script language="JavaScript">
    var stop_time = 100;

    function load_page() {
        setTimeout('update_timeout()', 100);
    }

    var max_stop_time = stop_time;

    function update_timeout() {
        stop_time--;
        if (stop_time >= 0) {
            var o = document.getElementById("move");
            if (o) {
                var width = ((max_stop_time - stop_time) / max_stop_time) * 110;
                if (width > 110) {
                    width = 110
                }
                o.style.width = width + 'px';
            }
        }
        setTimeout('update_timeout()', 100);
    }

    function check_time() {
        if (stop_time < 1) return true;
        else {
            document.getElementById("mess").innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b style='font-size:12px'>Ждите</b>.";
            return false;
        }
    }

</script>


<?php
print'<table width="100%" border="0">';
print'<tr align=left valign=top border="0">
<td>
<table width="100%" border="0">
  <tr>';
print'<td width="48%" align="left" valign="top">';

print'<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="18">';
print "&nbsp;<span style='font-size:12px; color:red;'>";
if ($_GET['warning'] == '1') {
    print "Вы получили 'Гайка'";
}
if ($_GET['warning'] == '3') {
    print "Вы получили 'Вентиль'";
}
if ($_GET['warning'] == '2') {
    print "Кто-то оказался быстрее!";
}
if ($_GET['warning'] == '4') {
    print "Вы подняли ключ №'" . $_GET['key'];
}
if ($_GET['warning'] == '5') {
    print "У вас уже есть ключ №'" . $_GET['key'];
}
if ($_GET['warning'] == '6') {
    print "Вы вытащили 'Гайку'";
}
if ($_GET['warning'] == '8') {
    print "Вы вытащили 'Болт'";
}
if ($_GET['warning'] == '7') {
    print "Сундук пуст";
}
if ($_GET['warning'] == '9') {
    print "Вы получили 'Ключиик'";
}
if ($_GET['warning'] == '10') {
    print "Вы получили 'Зелье жизни'";
}
if ($_GET['warning'] == '11') {
    print "Вы уже брали зелье!";
}
if ($_GET['warning'] == '12') {
    print "Невозможно! Вы далеко!";
}
print'</span><br></td>
</tr>
</table>';
$sided = mysql_query("select * from `labirint` where `glav_id`='$glav_id'");
while ($didd = mysql_fetch_array($sided)) {

    $Loca = $Location ?? 0;
    if ($Location < 0) {
        $Loca = 0;
    }
    if ($Location == '01') {
        $Loca = 1;
    }
    if ($Location == '02') {
        $Loca = 2;
    }
    if ($Location == '03') {
        $Loca = 3;
    }
    if ($Location == '04') {
        $Loca = 4;
    }
    if ($Location == '05') {
        $Loca = 5;
    }
    if ($Location == '06') {
        $Loca = 6;
    }
    if ($Location == '07') {
        $Loca = 7;
    }
    if ($Location == '08') {
        $Loca = 8;
    }
    if ($Location == '09') {
        $Loca = 9;
    }

    if (in_array($_GET['sun'], ['se_gaika'])) {
        $ferrr = mysql_query("SELECT n$Loca FROM `podzem3` WHERE glava='$glava'");
        $retr = mysql_fetch_array($ferrr);
        $stloc = $retr["n$Loca"];
        if ($stloc == '503' or $stloc == '502' or $stloc == '501') {
            if ($stloc == '503') {
                mysql_query("UPDATE `podzem3` SET n$Loca='502' WHERE glava='$glava'");
            }
            if ($stloc == '502') {
                mysql_query("UPDATE `podzem3` SET n$Loca='501' WHERE glava='$glava'");
            }
            if ($stloc == '501') {
                mysql_query("UPDATE `podzem3` SET n$Loca='' WHERE glava='$glava'");
            }
            if ($stloc == '') {
                print "<script>location.href='?warning=2'</script>";
                exit;
            }
            $f = mysql_query("SELECT `maxdur` FROM `inventory` WHERE `owner`='" . $user['id'] . "' and `type`='200' and `name`='Гайка' and maxdur<'30'");
            if ($g = mysql_fetch_array($f)) {
                $koll = $g["maxdur"];
                mysql_query("UPDATE `inventory` SET maxdur=maxdur+1,massa=massa+1,cost=cost+1 WHERE owner='" . $user['id'] . "' and `type`='200' and `name`='Гайка' and maxdur<'30'");
            } else {
                $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,podzem) VALUES('Гайка','0','1','1','g.gif','" . $user['id'] . "','200','1','0','1')");
            }
            print "<script>location.href='?warning=1'</script>";
            exit;
        }
    }

//////////////////////////////////////////

    if (in_array($_GET['sun'], ['se_vintel'])) {
        $ferrr = mysql_query("SELECT n$Loca FROM podzem3 WHERE glava='$glava'");
        $retr = mysql_fetch_array($ferrr);
        $stloc = $retr["n$Loca"];
        if ($stloc == '504') {
            if ($stloc == '504') {
                mysql_query("UPDATE podzem3 SET n$Loca='' WHERE glava='$glava'");
            }
            if ($stloc == '') {
                print "<script>location.href='?warning=2'</script>";
                exit;
            }
            $f = mysql_query("SELECT maxdur FROM `inventory` WHERE `owner`='" . $user['id'] . "' and `type`='200' and `name`='Вентиль' and maxdur<'30'");
            if ($g = mysql_fetch_array($f)) {
                $koll = $g["maxdur"];
                mysql_query("UPDATE `inventory` SET maxdur=maxdur+1,massa=massa+1,cost=cost+1 WHERE owner='" . $user['id'] . "' and `type`='200' and `name`='Вентиль' and maxdur<'30'");
            } else {
                $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,podzem) VALUES('Вентиль','0','1','1','v.gif','" . $user['id'] . "','200','1','0','1')");
            }
            print "<script>location.href='?warning=3'</script>";
            exit;
        }
    }

    if (in_array($_GET['sun'], ['se_kluchiik'])) {
        $ferrr = mysql_query("SELECT n$Loca FROM podzem3 WHERE glava='$glava'");
        $retr = mysql_fetch_array($ferrr);
        $stloc = $retr["n$Loca"];
        if ($stloc == '505') {
            if ($stloc == '505') {
                mysql_query("UPDATE podzem3 SET n$Loca='' WHERE glava='$glava'");
            }
            if ($stloc == '') {
                print "<script>location.href='?warning=2'</script>";
                exit;
            }
            $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,podzem) VALUES('Ключиик','0','1','1','kluchik.gif','" . $user['id'] . "','200','3','0','1')");
            print "<script>location.href='?warning=9'</script>";
            exit;
        }
    }

    if (in_array($_GET['sun'], ['el'])) {
        if ($el != '1' and $Location == $el) {
            $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,magic,podzem) VALUES('Зелье жизни','0','15','15','food_l8.gif','" . $user['id'] . "','50','1','0','8','1')");
            mysql_query("UPDATE `labirint` SET el='1' WHERE `glav_id`='$glav_id' and `login`='$login'");
            print "<script>location.href='?warning=10'</script>";
            exit;
        } else {
            if ($el == '1') {
                print "<script>location.href='?warning=11'</script>";
                exit;
            } else {
                print "<script>location.href='?warning=12'</script>";
                exit;
            }
        }
    }

    if (in_array($_GET['sun'], ['sunduk'])) {
        $ferrr = mysql_query("SELECT sunduk" . $_GET['sn'] . " FROM `podzem3` WHERE `glava`='$glava'");
        $retr = mysql_fetch_array($ferrr);
        $stloc = $retr["sunduk" . $_GET['sn'] . ""];
        if ($stloc != '' and $Location == $stloc) {
            mysql_query("UPDATE `podzem3` SET sunduk" . $_GET['sn'] . "='' WHERE `glava`='$glava'");
        } else {
            if ($stloc == '') {
                print "<script>location.href='?warning=2'</script>";
                exit;
            } else {
                print "<script>location.href='?warning=12'</script>";
                exit;
            }
        }

        $f = mysql_query("SELECT `maxdur` FROM `inventory` WHERE `owner`='" . $user['id'] . "' and `type`='200' and `name`='Гайка' and maxdur<'30'");
        if ($g = mysql_fetch_array($f)) {
            $koll = $g["maxdur"];
            mysql_query("UPDATE `inventory` SET maxdur=maxdur+1,massa=massa+1,cost=cost+1 WHERE owner='" . $user['id'] . "' and `type`='200' and `name`='Гайка' and maxdur<'30'");
        } else {
            $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,podzem) VALUES('Гайка','0','1','1','g.gif','" . $user['id'] . "','200','1','0','1')");
        }
        print "<script>location.href='?warning=6'</script>";
        exit;
    }

    if (in_array($_GET['sun'], ['key'])) {
        $keys = "key" . $_GET['sn'] . "";
        $keyd = $r["key" . $_GET['sn'] . ""];
        if ($keyd != 1) {
            if ($keyd == $Location) {
                mysql_query("UPDATE labirint SET $keys='1' WHERE glav_id='$glav_id'");
                print "<script>location.href='?warning=4&key=" . $_GET['sn'] . "'</script>";
                exit;
            } else {
                print "<script>location.href='?warning=12'</script>";
                exit;
            }
        } else {
            print "<script>location.href='?warning=5&key=" . $_GET['sn'] . "'</script>";
            exit;
        }
    }

    if (in_array($_GET['sun'], ['sunduk_b'])) {
        $ferrr = mysql_query("SELECT sunduk" . $_GET['sn'] . " FROM podzem3 WHERE glava='$glava'");
        $retr = mysql_fetch_array($ferrr);
        $stloc = $retr["sunduk" . $_GET['sn'] . ""];
        if ($stloc != '' and $Location == $stloc) {
            mysql_query("UPDATE podzem3 SET sunduk" . $_GET['sn'] . "='' WHERE glava='$glava'");
        } else {
            if ($stloc == '') {
                print "<script>location.href='?warning=2'</script>";
                exit;
            } else {
                print "<script>location.href='?warning=12'</script>";
                exit;
            }
        }


        $f = mysql_query("SELECT maxdur FROM `inventory` WHERE `owner`='" . $user['id'] . "' and `type`='200' and `name`='Болт' and maxdur<'30'");
        if ($g = mysql_fetch_array($f)) {
            $koll = $g["maxdur"];
            mysql_query("UPDATE `inventory` SET maxdur=maxdur+1,massa=massa+1,cost=cost+1 WHERE owner='" . $user['id'] . "' and `type`='200' and `name`='Болт' and maxdur<'30'");
        } else {
            $fo = mysql_query("INSERT INTO `inventory`(name,duration,maxdur,cost,img,owner,type,massa,isrep,podzem) VALUES('Болт','0','1','1','bolt.gif','" . $user['id'] . "','200','1','0','1')");
        }
        print "<script>location.href='?warning=8'</script>";
        exit;
    }
}
print"<br>";
print"<table width=\"440\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td>";

$gags = mysql_query("SELECT * FROM `labirint` WHERE `glav_id`='$glav_id'");
while ($ghhg = mysql_fetch_array($gags)) {
    $sax = mysql_query("SELECT login,level,hp,maxhp,id FROM `users` WHERE login='" . $ghhg['login'] . "'");
    $ber = mysql_fetch_array($sax);
    print"<table width=\"440\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr>
    <td align=\"left\"><b style='font-size:12px;'>" . $ber['login'] . "[" . $ber["level"] . "]</b><IMG alt=\"Инфо\" src=\"i/inf.gif\" width=12 height=12></td>
<td align=\"left\">";
    echo showProgressBar($ber['hp'], $ber['maxhp']);
    print"</td>";
    if ($ber['id'] == $glav_id) {
        print"<td align=\"left\" ><IMG alt=\"Лидер группы\" src=\"http://img.combats.com/i/misc/lead1.gif\" width=24 height=15>";
        print"<IMG alt=\"Выгнать супостата\" src=\"http://img.combats.com/i/misc/ico_kill_member1.gif\" WIDTH=\"16\" HEIGHT=\"19\">";
        print"&nbsp;<IMG alt=\"Новый царь\" src=\"http://img.combats.com/i/misc/ico_change_leader1.gif\" WIDTH=\"16\" HEIGHT=\"19\">";
    }
    print"</td>
  </tr>
</table>";
}

print"</td>
  </tr>
</table>";


print"<br>";
$gag = mysql_query("SELECT * FROM qwest WHERE login='" . $user["login"] . "' and status!='ok'");
while ($qw = mysql_fetch_array($gag)) {
    $name_qwest = $qw["name_items"];
    $zadanie = $qw["zadanie"];
    $qwesta = mysql_fetch_array(mysql_query("SELECT id FROM `inventory` WHERE `owner`='" . $user['id'] . "' and `type`='200' and `name`='$name_qwest'"));
    if ($qwesta) {
        $ok_qwest = "1";
    } else {
        $ok_qwest = "0";
    }
    print"&nbsp;&nbsp;<font style='font-size:13px; color:#000'>Задание:</font> <font style='font-size:11px; color:#000'>$zadanie ($ok_qwest/1)</font><br><br>";
}
if ($kill > '0') {
    print"<font style='font-size:15px; color:#600'> <b>&nbsp;&nbsp;Кол-во смертей:</font></b> <b style='font-size:14px; color:#000'>$kill</b><br><br>";
}
include "podzem_res.php";

print'</td>';

print'<td width="52%" align=right valign=top border="0">';


print' <table><tr>
<td width="530" height="285" align="right">';


print"<font style='font-size:18px; color:#400000'><b>Этаж 1 - Канализация</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='?act=cexit' title='Вернуться'>&nbsp;<b style='font-size:18px; color:#000000;'>выйти</b></a>";
print'<div style="position:relative;  id="ione"><div align="left"><img src="labirint3/podzem.jpg" width=530 height=260 border=1 galleryimg="no" /></div>';
echo "<div style='position:absolute; left:375px; top:123px;'><img src='labirint3/" . $styles . "/yo.gif' border='0' width='150' height='130'></div>";


$fer = mysql_query("select * from `labirint` where `glav_id`='$glav_id'");
$s = 0;
while ($ler = mysql_fetch_array($fer)) {
    $s++;
    $n_log = $ler["login"];
    $n_locat = $ler["location"];
    $n_left = $ler["l"];
    $n_top = $ler["t"];
    echo "<div style='position:absolute; left:$n_left px; top:$n_top px;'><img src='labirint3/$s.gif' border='0' width='10' height='10'  alt='$n_log'></div>";
}

?>