<?
session_start();
require('config.php');
$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=$_GET["view"];
if($qwe!="ok")
{
	$t=time();
	$t=$t+$_SESSION["timer"];
	$_SESSION["endtime"]=$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: green; text-decoration: none; font-family: Verdana; font-size: 13px; }
	a:hover {color: red; text-decoration: none; font-family: Verdana; font-size: 13px; }
input.serfnum {
    font: 12px Tahoma, Arial, sans-serif;
    text-shadow: 1px 1px 1px #304f12;
    text-align: center;
    color: #ffffff;
    background: url('../images/bg_capcha_b.png') no-repeat left top;
    height: 20px;
    width: 22px;
    vertical-align: middle;
    display: block;
    display: inline-block; /*ie*/
    text-decoration: none;
    outline: none;
    border: none;
    margin: 0 -2px 1px 0;
    padding: 0 1px 2px 0;
    cursor: pointer;
}
input.serfnum:hover {
    background-position: left bottom;
}
td.h2 {
	font:18px/14px Arial, sans-serif;
	color:#7e7e7e;
        text-shadow: 1px 1px 1px #dbf0fc;
        padding:8px;
}
</style>
</head>
<body>

<?

$row=mysql_fetch_assoc(mysql_query("SELECT * FROM tb_ads WHERE id='$ad'"));
if($row["act"]!='1')
{
if($qwe!="ok" and $row["act"]!='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="30%" rowspan=2 valign=center>
<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:green; font-size: 9pt;">Подождите, пожалуйста, <span style="color:red" id="timer_inp"><?=$_SESSION["timer"] ?></span> секунд...</span>
<br />
<span style="color:#818181; font-size: 7pt;">Дождитесь окончания таймера</span>
</td>


</tr>
</table><?
}else{
  include('success.php');
}

}else{
?>
<table id="tbl" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="font-family: Verdana; font-size: 13px;" width="30%" rowspan=2 valign=center>
<? 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:green; font-size: 9pt;padding: 5px;">Подождите, пожалуйста, <span style="style="color:red; font-size: 8pt;" id="time"><?=$_SESSION["timer"] ?></span> секунд...</span>
<br />
<span style="color:#818181; font-size: 7pt;padding: 5px;">При остановке таймера нажмите <font color='Red'>ЗДЕСЬ</font></span>
</td></tr></table><?
}else{ include('success.php'); }

}
?>
</td>
<td class='h2' style="font-family: Verdana; font-size: 13px;">
Описание: <?=$_SESSION["desc"] ?>
<br>
Ссылка на сайт: <a href="<?=$_SESSION["urlsite"] ?>" target="_blank"><?=$_SESSION["urlsite"] ?></a>
</td>
</tr>
</table>

</body>
</html>