<?
error_reporting(0);
session_start();
define("beerman", true);
require('sfb.php');
$user = (isset($_SESSION["username"])) ? strip_tags(stripslashes($_SESSION["username"])) : NULL; 
$ad=intval($_SESSION["ad"]);
$row_pr=mysql_fetch_assoc(mysql_query("SELECT id FROM tb_ads WHERE id='$ad' and play = '1'"));
if($row_pr["id"]!=""){echo "Нет токой ссылки, или просмотр был остановлен рекламодателем"; exit;}
$qwe = (isset($_GET["view"])) ? strip_tags(stripslashes($_GET["view"])) : NULL;
$timer = (isset($_SESSION["timer"])) ? strip_tags(stripslashes($_SESSION["timer"])) : NULL;
if($qwe != "ok"){
$t = time();
$t = $t + $timer;
$_SESSION["endtime"] = intval($t);
}
?>

<script language=javascript>
if(self==parent) self.window.location='sites.php';
</script>
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="./css/style_cap.css" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<style type="text/css">
a, a:link, a:visited { color: #057fac; text-decoration: none; font-family: Verdana; font-size: 13px; }
a:hover {color: #f00; text-decoration: none; font-family: Verdana; font-size: 13px; }
#tbl {
background: none repeat scroll 0 0 #6d74a4;
padding: 5px;
width: 100%;
}
</style>
</head>
<body>

<?

$row=mysql_fetch_assoc(mysql_query("SELECT * FROM tb_ads WHERE id='$ad'"));
if($row["active"]!='1')
{
if($qwe!="ok" and $row["active"]!='1')
{
?>
	<script type="text/javascript">
	setTimeout('location.replace("vls.php?view=ok")', <?=$_SESSION["timer"]*1000 ?>);
	</script>

	<noscript>
	<meta http-equiv="refresh" content="<?=$_SESSION["timer"]?>; url=vls.php?view=ok">
	</noscript>
<?
}
?>

<table id="tbl" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td style="font-family: Verdana;font-size: 13px;" width="390px" rowspan="2">
<script type="text/javascript">
function timer()
{
var obj=document.getElementById('timer_inp');
obj.innerHTML--;
if(obj.innerHTML==0)
{
setTimeout('location.replace("vls.php?view=ok")', 1000);}
else
{setTimeout(timer, 1000);}
}
setTimeout(timer, 1000);
</script>
<?
if($qwe!="ok")
{
	?>
<table>
<tr>
<td><img src="/images/date1.png" style="padding-right: 3px"></td>
<td><span style="color:white; font-size: 9pt;padding: 5px;">Подождите <b><span style="color:white; font-size: 8pt;" id="timer_inp"><?=$_SESSION["timer"] ?></span></b> секунд</span></td>
</tr>
</table>
<?
}else{
  include('success.php');
}
?>
</td>
<td align="right" style="padding:0 30px 17px 0;"><? include('inc/rotator.php'); ?></td>
</tr></table>
<?
}else{
?>
<table id="tbl" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td style="font-family: Verdana;font-size: 13px;" width="390px" rowspan="2">
<? if($qwe!="ok")
{ ?>
<script type="text/javascript">
var b = false;
var last = 0;
function t() {
    var c = document.getElementById('time');
    if (typeof c == "undefined") return;
    var t = parseInt(c.innerHTML);
    last = stime();
    if (t > 0) {
        if (b == true) {
            setTimeout('t()', 1000);
            return
        }--t;
        setTimeout('t()', 1000)
    } else {
        location.replace("vls.php?view=ok")
    }
    c.innerHTML = t
};
function stime() {
    var d = new Date();
    return d.getTime()
};
function w_obj() {
    var wobj, i;
    for (i = 0; i < 10; ++i) {
        wobj = self.parent;
        if ((wobj && !(wobj === self)) && (wobj.frames.length != 0)) {
            wobj = self.parent
        }
    }
    return wobj
}
var w;
if (navigator.appName == "Microsoft Internet Explorer") w = w_obj();
else w = top;
setTimeout('t()', 1000);
w.onblur = function() {
    b = true
};
w.onfocus = function() {
    b = false
};
w.onmousemove = function() {
    b = false;
    if (last > 0 && last < stime() - 1500) setTimeout('t()', 1000)
};
</script>
<table><tr>  
<td><img src="/images/date1.png" style="padding-right: 3px;"></td>
<td><span style="color:white; font-size: 9pt;padding: 5px;">Подождите <b><span style="color:white; font-size: 8pt;" id="time"><?=$_SESSION["timer"] ?></span></b> секунд</span></td>
</tr>
</table><?
}else{ include('success.php'); }

}
?>
</td>
<td align="right" style="padding:0 30px 17px 0;"><? include('inc/rotator.php'); ?></td>
</tr>
</table>

</body>
</html>