<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}
?>
  <div align="right" style="padding-right:10px;">
    <?php if($topbanner[0]->simage!='' and file_exists('./static/uploadfiles/banners/'.$topbanner[0]->simage)){?><img class="img-responsive" name="topbannerimg" src="./utility/processImage.php?imageName=<?php echo urlencode($topbanner[0]->simage); ?>&w=430&h=80&mod=2&type=2&<?php echo date("HisdmY");?>" <?php if($topbanner[0]->surl!=''){?> style="cursor:pointer" onclick="saveClick_top()"<?php }?> /><?php }?>
    </div>
   
<form name="frm_banner" action="" method="post">
<input type="hidden" name="topbanner_u" id="topbanner_u" value="">
<input type="hidden" name="topbanner_type" id="topbanner_type" value="">
<input type="hidden" name="topbanner_id" id="topbanner_id" value="">

<input type="hidden" name="leftbanner_u" id="leftbanner_u" value="">
<input type="hidden" name="leftbanner_type" id="leftbanner_type" value="">
<input type="hidden" name="leftbanner_id" id="leftbanner_id" value="">

<input type="hidden" name="rightbanner_u" id="rightbanner_u" value="">
<input type="hidden" name="rightbanner_type" id="rightbanner_type" value="">
<input type="hidden" name="rightbanner_id" id="rightbanner_id" value="">

<input type="hidden" name="bottombanner_u" id="bottombanner_u" value="">
<input type="hidden" name="bottombanner_type" id="bottombanner_type" value="">
<input type="hidden" name="bottombanner_id" id="bottombanner_id" value="">
</form>
<?php
//'<?php echo str_replace('http://','',$topbanner[0]->surl)? >','top','<?php echo $topbanner[0]->id? >','<?php echo $ip? >'
?>
<script language="javascript">

/*
Random image slideshow- By Tyler Clarke (tyler@ihatecoffee.com)
For this script and more, visit http://www.javascriptkit.com
*/

var delay=6000 //set delay in miliseconds
var curindex=0

var randomimages=new Array()
var randomurl=new Array()
var randomtype=new Array()
var randomid=new Array()
<?php 
$i=0;
foreach($topbanner as $tb){
	if($tb->simage !='' and file_exists('./static/uploadfiles/banners/'.$tb->simage)){
	?>
		randomimages[<?php echo $i?>]="<?php echo "./utility/processImage.php?imageName=".urlencode($tb->simage)."&w=430&h=80&mod=2&type=2&".date("HisdmY");?>";
		randomurl[<?php echo $i?>]='<?php echo str_replace('http://','',$tb->surl)?>';
		randomtype[<?php echo $i?>]='top';
		randomid[<?php echo $i?>]='<?php echo $tb->id?>'
	<?php
	}
	$i++;
}
?>

function rotateimage(){

if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){
curindex=curindex==0? 1 : curindex-1
}
else
curindex=tempindex

	document.images.topbannerimg.src=randomimages[curindex];
		document.getElementById("topbanner_u").value = randomurl[curindex];
		document.getElementById("topbanner_type").value = randomtype[curindex];
		document.getElementById("topbanner_id").value = randomid[curindex];
}

setInterval("rotateimage()",delay)

</script>
<script>
function saveClick_top(){
var Type = document.getElementById("topbanner_type").value;
var bannerid = document.getElementById("topbanner_id").value;
var u = document.getElementById("topbanner_u").value;

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if(xmlhttp.responseText==1){
    		window.open("http://"+u,'_blank');
		}else{
			alert('error');
		}
    }
  }
var url="clickcount";
url=url+"?ttype="+Type;
url=url+"&bannerid="+bannerid;
url=url+"&ipaddr="+"<?php echo $ip?>";
url=url+"&WebUrl="+u;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function saveClick_bottom(){
var Type = document.getElementById("bottombanner_type").value;
var bannerid = document.getElementById("bottombanner_id").value;
var u = document.getElementById("bottombanner_u").value;

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if(xmlhttp.responseText==1){
    		window.open("http://"+u,'_blank');
		}else{
			alert('error');
		}
    }
  }
var url="clickcount";
url=url+"?ttype="+Type;
url=url+"&bannerid="+bannerid;
url=url+"&ipaddr="+"<?php echo $ip?>";
url=url+"&WebUrl="+u;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function saveClick_left(){
var Type = document.getElementById("leftbanner_type").value;
var bannerid = document.getElementById("leftbanner_id").value;
var u = document.getElementById("leftbanner_u").value;

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if(xmlhttp.responseText==1){
    		window.open("http://"+u,'_blank');
		}else{
			alert('error');
		}
    }
  }
var url="clickcount";
url=url+"?ttype="+Type;
url=url+"&bannerid="+bannerid;
url=url+"&ipaddr="+"<?php echo $ip?>";
url=url+"&WebUrl="+u;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function saveClick_right(){
var Type = document.getElementById("rightbanner_type").value;
var bannerid = document.getElementById("rightbanner_id").value;
var u = document.getElementById("rightbanner_u").value;

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if(xmlhttp.responseText==1){
    		window.open("http://"+u,'_blank');
		}else{
			alert('error');
		}
    }
  }
var url="clickcount";
url=url+"?ttype="+Type;
url=url+"&bannerid="+bannerid;
url=url+"&ipaddr="+"<?php echo $ip?>";
url=url+"&WebUrl="+u;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>