var pagearray=new Array();
var timerout1 ;
    var timerout;
	var timerout2;
	var timerout3;
var pageno =0 ;
//postadd
pagearray[0]="http://lankaworldtv.net/tv/ads/google1.html";

//midadd
pagearray[1]="http://lankahq.net/advertise/livestream/lankahq.html";
pagearray[2]="http://lankahq.net/advertise/livestream/lankahq2.html";
pagearray[3]="http://lankaworldtv.net/tv/ads/google2.html";

function getFlashMovie(movieName)
{
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function showmidadd()
{

X= findPosX(document.getElementById('mediaspace'));
    Y= findPosY(document.getElementById('mediaspace'));
    w=parseInt(document.getElementById('mediaspace').style.width);
    // document.getElementById('light').style.left=X+((w-300)/2);
    h=parseInt(document.getElementById('mediaspace').style.height);
	if(w==100)
	{
		if (self.innerWidth) {
      w = self.innerWidth;
      h = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			  w= document.documentElement.clientWidth;
			  h = document.documentElement.clientHeight;
		}
		else if (document.body) {
			  w = document.body.clientWidth;
			  h = document.body.clientHeight;
		}
             
	}
    document.getElementById('midadd').style.top=Y+((h-420))+"px";
    document.getElementById('midadd').style.left=X+((w-310)/2)+"px";
document.getElementById('midadd').style.display="block";
	
	for(var i=0;i<20;i++)
    setTimeout("showtimer('"+i+"')",(20-i)*1000);
    window.setTimeout("showbut()", 10000);
	
}
function showtimer(n)
{
	document.getElementById('lbltime').value=n+'s';
if(n==0){
document.getElementById('midadd').style.display="none";
}
}
function showbut()
{
	document.getElementById('buttondiv').style.display="block";
}
function closemidadd()
{
	document.getElementById('midadd').style.display="none";
}
function googleclose()
{
	document.getElementById('framediv').innerHTML="";
	document.getElementById('lightm').style.display="none";
	document.getElementById('closeimgm').style.display="none";
	clearTimeout();
	
	 window.setTimeout("showadd('1')", 50000);
}
function onplayerloaded()
{
        
	showadd('0');
       showmidadd();
    getFlashMovie('player').playmovie();
}

function showadd(id)
{
	X= findPosX(document.getElementById('mediaspace'));
    Y= findPosY(document.getElementById('mediaspace'));
    w=parseInt(document.getElementById('mediaspace').style.width);
    // document.getElementById('light').style.left=X+((w-300)/2);
    h=parseInt(document.getElementById('mediaspace').style.height);
	if(w==100)
	{
		if (self.innerWidth) {
      w = self.innerWidth;
      h = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			  w= document.documentElement.clientWidth;
			  h = document.documentElement.clientHeight;
		}
		else if (document.body) {
			  w = document.body.clientWidth;
			  h = document.body.clientHeight;
		}
             
	}

    document.getElementById('lightm').style.top=Y+((h-90))+"px";
    document.getElementById('lightm').style.left=X+((w-470)/2)+"px";
	
	if(id ==0)
	{
	 timerout1 = window.setTimeout('bindpage(0)', 20000);
	 timerout2 = window.setTimeout("bindpage(1)", 60000);
	 timerout3 = window.setTimeout("bindpage(2)", 120000);
	}
	else if(pageno==1)
	{
	 timerout1 = window.setTimeout('bindpage(2)', 60000);
	}
	else if(pageno==0)
	{
	 timerout1 = window.setTimeout('bindpage(1)', 60000);
	 timerout = window.setTimeout("bindpage(2)", 60000);
	}
	else if(pageno==2 )
	{
	 timerout1 =window.setTimeout('bindpage(2)', 200000);
	}
}


function postadd()
{
 document.getElementById('lightm').style.display="block";
		prerequest4(pagearray[0]);
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
            break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            if(!obj.offsetParent)
            break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}
  
function bindpage(pageno1)
{
	pageno=pageno1;
	document.getElementById('lightm').style.display="none";
	 document.getElementById('closeimgm').style.display="none";
		prerequest4(pagearray[pageno]);
	//setInterval('bindpage()', 10000);
}

function onEndVideo()
{
    postadd();
}
 function handleHttpResponse()
	   {
        if (http.readyState == 4)
		{
              if(http.status==200)
			  {
                  var results=http.responseText;
				
				  document.getElementById('framediv').innerHTML = results;
				 
    document.getElementById('closeimgm').style.display="block";
	document.getElementById('lightm').style.display="block";
              }
          }
        }
function prerequest4(pageurl)
{
		  
		    url="framepage.php?page="+pageurl;
			http.open("GET", url , true);
            http.onreadystatechange = handleHttpResponse;
            http.send(null);
            return true;
        }
function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp)
    {
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }

}
  return xmlhttp;
}
var http = getHTTPObject(); 