<?php
session_start();
include "../config.php";
if( ($userid == "") || ($password=="") )
{
include "../header.php";
include "../style.php";
echo '<p>You must be logged in to access this site. Please <a href="../index.php">click here</a> to login.</p>';
include "../footer.php";
mysql_close($dblink);
exit();
}
$surfwaittime = $_SESSION['surftime'];
if ($memtype=="PRO") {
$earn = $prosurfpoint;
}elseif($memtype=="JV Member"){
$earn = $jvsurfpoint;
}else {
$earn = $superjvsurfpoint;
}
if (($_POST[x])&&(substr($_SESSION[igif], 16) === $_SESSION['afloat'])){

// posted
$x = $_POST[x];

// decode, strip string and round numbers
$a = base64_decode($_SESSION['afloat']);
$b = 0 + $a;
$a = explode(" ", $a);
$a = $a[3];
$bb = round($b);
$aa = round($a);

// x coords
$gc = explode(" ", '0 30 58 85 112 139 146 174 199 225 254 285');

// check if correct number has been clicked
$ac = $aa + 6;
$rightclick = false;
if ($bb <= $aa){ $ac = $bb + 1; }
$mess = "You clicked the wrong image.";
// if correct number clicked success
if (($x >= $gc[$ac-1]) && ($x <= $gc[$ac])){
$rightclick = true;
}
?>
<html>
<body>

<div style="text-align: left; padding-top: 120px; float: left;">
<a href="<?php echo $_SESSION['currentsurfpage_url'];?>" target="_top">Remove This Frame</a>
</div>

<div style="text-align: right; padding-top: 120px; float: right;">
<a href="<?php echo $_SESSION['currentsurfpage_url'];?>" target="_top">Remove This Frame</a>
</div>


<center>
<a href="index.php" target="_top">Return to Members Area</a> - <a href="mysurf.php" target="_top">Add Your Site</a> - <a href="support.php" target="_blank">Report This Site</a>

<?php
if(!$rightclick){
echo '<br>'.$mess . ' <a href="surf.php" target="_top">View more sites</a><br>';
}else{
echo "<br>You have earned $earn points.". '<a href="surf.php" target="_top">View more sites</a><br>';	
if($_SESSION['currentsurfpage_status'] == 'pending' && $_SESSION['currentsurfpage_id'] != $surf_last_id){
$_SESSION['currentsurfpage_status'] = 'success';
add_adclick('surfpages');
if ($memtype=="PRO") {
assignpoints($userrecord['referid'], $earn);
}elseif($memtype=="JV Member"){
assignpoints($userrecord['referid'], $earn);
}else {
assignpoints($userrecord['referid'], $earn);
}
/*
if ($ppool=="1") {
pointspool($earn);
}
if ($mpool=="1") {
moneypool($earn);
}
*/
//update member point and last surf id
mysql_query("UPDATE members SET points=points+".$earn.", surf_last_id='".$_SESSION['currentsurfpage_id']."' where userid='".$userid."'");
//remove credit from the surfurl owner
mysql_query("UPDATE surfurls SET surfpoint=surfpoint-$earn, surfclicks=surfclicks+1 WHERE id='".$_SESSION['currentsurfpage_id']."' AND surfpoint>=$earn");
}else{
echo "You are already credited today for this surf page";
}
}
?>

<center><?php include("../banners2.php"); mysql_close($dblink); ?></center>			


</center>

</body>
</html>

<?php
exit;
}else{

// afloat = base64_encoded random string
$afloat = base64_encode(" " . $num1 = rand(0,3) . "." . $num2 = rand(100,999) . " IDEuNzg3IEZsb2F0IDMuODc5IA " . $num3 = rand(1,4) . "." . $num4 = rand(100,999) . " "); 

// rectangle x coord

$aler = "> 78";
if(round($num1 . "." . $num2) <= round($num3 . "." . $num4)) {$aler = "< 105";}

// create random image
$_SESSION[igif] = "surfimage.php?n=" . $afloat . "";
$_SESSION['afloat'] = $afloat;
?>
<html>
<head>
<style type="text/css">

/* click image */
.cd {
width: 285px;
height: 30px;
background-image: url(<?=$_SESSION[igif];?>);
background-repeat: no-repeat;
position: relative;
z-index: 2;
}
</style>
<script language="JavaScript">
function submitform() {

if (document.xcoords.x.value <?=$aler;?>) {
document.xcoords.submit();

} else {
alert("Click number in square identical to number in the rectangle to submit.");
}
}
// image x value
function xcoord(event) {
image = event.offsetX?(event.offsetX):event.pageX-document.getElementById("coord").offsetLeft;
document.xcoords.x.value = image;
}
</script>
</head>

<body>

<center>

<form name="xcoords" style="display: inline;" method="post" target="_self">
<input type="hidden" name="x">
</form>


<a href="index.php" target="_top">Return to Members Area</a> - <a href="mysurf.php" target="_top">Add Your Site</a> - <a href="support.php" target="_blank">Report This Site</a><br>



<span id="plzwait">You Will Earn Credits After <?php echo $surfwaittime;?> seconds</span>
<script type="text/javascript">
counter = <?php echo $surfwaittime;?>;
function countdown() {
if ((0 <= 100) || (0 > 0)) {
counter--;
if(counter > 0) {
document.getElementById("plzwait").innerHTML = 'You Will Earn <?php echo $earn;?>  Credits After <b>'+counter+'<\/b> seconds';
setTimeout('countdown()',1000);

} else if(counter==0) {

document.getElementById("plzwait").innerHTML = '<div id="coord" onclick="submitform(xcoord(event))" class="cd"></div>';


}
}
}
countdown();
</script>
<noscript><h2>You need a javascript enable browser to surf</h2></noscript>
<br>

<center>
<?php include("../banners2.php"); mysql_close($dblink); ?>
</center>
</center>

</body>
</html>
<?php } ?>