
var http = getHTTPObject();
//-------------------------------------------------------------------------------------
  function getHTTPObject()
  {
    var xmlhttp;
    try{xmlhttp = new XMLHttpRequest(); /* e.g. Firefox */}
    catch(e)
    {
      try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */}
      catch (e)
      {
        try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */}
        catch (e)
        {
          xmlhttp = false;
        }
      }
    }
    return xmlhttp;
  }

function getPlayer(vars){
    var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url="getPlayer.php" + "?rand=" + myRandom + vars;
    http.open("GET", url, true);
    http.onreadystatechange = showPlayer;
    http.send(null);
  }
  
 function showPlayer()
 {
 	if (http.readyState == 4){
	  top.document.getElementById("thePlayer").innerHTML = http.responseText;
    }
 }

var playstatetimer = true;
 
var psto=setTimeout('setplaystate()',30000); 
 
function setplaystate()
{
 playstatetimer = false;
 clearTimeout(psto);
}


var xmlHttp;
var myRandomNo;

function genRandomNo(){
myRandomNo = parseInt(Math.random()*99999999999);
}

function updateStats(str1,str2,str3)
{
	genRandomNo();
	xmlHttp=getHTTPObject()
	var url="../includes/updateDb.php?rand="+myRandomNo+"&s="+str1+"&p="+str2+"&c="+str3;
	xmlHttp.onreadystatechange=statsUpdated;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function statsUpdated() 
{ 
if (xmlHttp.readyState==4)
{ 
//do nothing
}
}

function updateSched(str)
{
	genRandomNo();
	xmlHttp=getHTTPObject()
	var url="f.channel.php?rand="+myRandomNo+"&id="+str;
	xmlHttp.onreadystatechange=schedUpdated;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function returnToListing()
{
	var nameCheck = parent.document.getElementById('clientSchedListId').value;
	if (nameCheck!=""){	
		schedAddCheck = "";
		updateSched(nameCheck);
	}
}

var clientUrl;
var returnTime=7000;

function schedUpdated() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var framediv = parent.document.getElementById('schedList1');
		framediv.innerHTML=xmlHttp.responseText;
		if (schedAddCheck == "")
		{
			framediv = document.getElementById('translucentbkg');
			framediv.innerHTML=xmlHttp.responseText;
		}
	}
}

function jsGET(variable){
var $_GET = new Object();
var $qry_str = location.search.substring(1);
var $k = 0;
//check there is a '=' in the string, if not exit.
if($qry_str.indexOf('=') < 1){
return false;
}
	do {
		$_GET[$qry_str.split("=")[0].replace(/&/, "")] = $qry_str.split("=")[1].split(/&|$/)[0];
		$qry_str = $qry_str.split($qry_str.split("=")[1].split(/&|$/)[0])[1];
		$k ++;
	} while($k < (location.search.split("=").length - 1));
	
	for(key in $_GET){
	if (key==variable){
	   return $_GET[key];
		} else {
	   	return false;
	   }
	}
}

var progMemory=0;

function doPlayState(oldState,newState,clientSchedId,thisclientid)
{
 if (!playstatetimer)

 {
  var outResp = "";
  switch (oldState) 
  {
    case 10 : outResp="Player Ready"; break;
    case 9 : outResp="Transitioning..."; break;
    case 8 : outResp="Media Ended"; break;
    case 7 : outResp="Waiting..."; break;
    case 6 : outResp="Buffering..."; break;
    case 5 : outResp="Rewind..."; break;
    case 4 : outResp="Fast Forward..."; break;
    case 3 : outResp="Playing..."; break;
    case 2 : outResp="Paused"; break;
    case 1 : outResp="Stopped"; break;
  }
  if (oldState == 9)
  {
	if (jsGET('s')){ //its a schedule.
		var framediv;
		framediv = parent.document.getElementById('theprogramme');
		if((progMemory!=framediv.value)||(progMemory==0))
		{
			progMemory=framediv.value;
			updateStats(jsGET('s'),framediv.value,thisclientid);
		}
		updateSched(jsGET('s'));
	}
	if (jsGET('h')){ //its a PPV
		updateStats(clientSchedId,channelPlaying,thisclientid);
		getNextProg();
	}
  }else if (oldState == 8)
  {
	if (jsGET('h')){
		updateStats(clientSchedId,channelPlaying,thisclientid);
		//getNextProg();
		document.location.href = "player.php";
	}
	if (jsGET('s')){
		document.location.href = "player.php?s=" + jsGET('s');
	}
  }
 }
}

var channelPlaying;
setTimeout('getFirstProgId()', 20000);

function getNextProg()
{
 setTimeout('getFirstProgId()', 20000);
}

function getFirstProgId()
{
 if (jsGET('h'))
 {
	 try{channelPlaying = document.getElementById('mediaplayer1').className;}
	 catch(e){/* do nothing */}
 }
 if (jsGET('s'))
 {
	 try{parent.document.getElementById('theprogramme').value = window.frames['contentframe'].document.getElementById('theprogramme').value;}
	 catch(e){/*do nothing*/}
 }
}

function getLargeAds(){
	var randAdVal = new Array(
	'<a href="http://www.tripleplay-events.com/" target="_blank"><img src="images/adverts/btps_banner468x60.gif" style="border:0px;" /></a>',
	'<a href="http://www.tlcsigns.co.uk/" target="_blank"><img src="images/adverts/banner_ad_ad.gif" style="border:0px;" /></a>',
	'<a href="http://www.ukbanners.94mb.com" target="_blank"><img src="images/adverts/banners.gif" style="border:0px;" /></a>',
	'<img src="images/adverts/BoySolider2.gif" />',
	'<a href="http://www.formulasystems.com/" target="_blank"><img src="images/adverts/formula_sys_v1.gif" style="border:0px;" /></a>',
	'<a href="http://www.w2forum.com/i/Benefits/" target="_blank"><img src="images/adverts/iptv_mea_banner_468x60.gif" style="border:0px;" /></a>',
	'<a href="http://www.iptv-forum.com/" target="_blank"><img src="images/adverts/iptvla08_banner_468x60.gif" style="border:0px;" /></a>',
	'<a href="http://www.menkind.co.uk/" target="_blank"><img src="images/adverts/menkind468x60.gif" style="border:0px;" /></a>',
	'<a href="http://www.midnightracer.co.uk" target="_blank"><img src="images/adverts/midnightracer.gif" style="border:0px;" /></a>',
	'<a href="http://www.pacer.co.uk/jkcm/" target="_blank"><img src="images/adverts/pacer.gif" style="border:0px;" /></a>',
	'<a href="http://www.rittal.com/" target="_blank"><img src="images/adverts/rittal.gif" style="border:0px;" /></a>',
	'<a href="http://dell.com" target="_blank"><img src="images/adverts/untitled.bmp" style="border:0px;" /></a>',
	'<a href="http://www.mayowynnebaxter.co.uk" target="_blank"><img src="images/adverts/mayoWynneBaxter_468x60.GIF" style="border:0px;" /></a>');
	var max = randAdVal.length;
	var pointNum = Math.floor((Math.random() * max));
	document.writeln(randAdVal[pointNum]);	
}

function getThreeAds() {
	var randAdVal = new Array(
	'<a href="http://store.alloy.com/frontpage.do" target="_blank"><img src="images/adverts/120x60.gif" style="border:0px;margin-left:-6px;" /></a>',
	'<a href="http://www.ringingphone.com/" target="_blank"><img src="images/adverts/120x60-a.gif" style="border:0px;margin-left:-6px;" /></a>',
	'<a href="http://www.britishcornershop.co.uk/" target="_blank"><img src="images/adverts/bcs_banner_120_60.jpg" style="border:0px;margin-left:-6px;" /></a>');
	var max = randAdVal.length;
	var pointNum1 = Math.floor((Math.random() * max));	//initialise all three random points
	var pointNum2 = Math.floor((Math.random() * max));	//..
	var pointNum3 = Math.floor((Math.random() * max));	//..
	for(;pointNum1==pointNum2 || pointNum3==pointNum2;)	//checks that pointers are all different
	{
		pointNum2 = Math.floor((Math.random() * max));	//..
	}
	for(;pointNum1==pointNum3 || pointNum2==pointNum3;)	//..
	{
		pointNum3 = Math.floor((Math.random() * max));	//..
	}
	document.writeln(randAdVal[pointNum1]);			//display first ad
	
	//array is updated with different styling
	randAdVal = new Array(											
	'<a href="http://store.alloy.com/frontpage.do" target="_blank"><img src="images/adverts/120x60.gif" style="border:0px;" /></a>',
	'<a href="http://www.ringingphone.com/" target="_blank"><img src="images/adverts/120x60-a.gif" style="border:0px;" /></a>',
	'<a href="http://www.britishcornershop.co.uk/" target="_blank"><img src="images/adverts/bcs_banner_120_60.jpg" style="border:0px;" /></a>');
	document.writeln(randAdVal[pointNum2]);			//second ad displayed
	
	//array updated again with new styling
	randAdVal = new Array(
	'<a href="http://store.alloy.com/frontpage.do" target="_blank"><img src="images/adverts/120x60.gif" style="border:0px;margin-right:-6px;" /></a>',
	'<a href="http://www.ringingphone.com/" target="_blank"><img src="images/adverts/120x60-a.gif" style="border:0px;margin-right:-6px;" /></a>',
	'<a href="http://www.britishcornershop.co.uk/" target="_blank"><img src="images/adverts/bcs_banner_120_60.jpg" style="border:0px;margin-right:-6px;" /></a>');
	document.writeln(randAdVal[pointNum3]);			//display last ad
}

//---------TAKEN FROM BUTTONS . JS-----------------------------//////////////

// JavaScript Document
var tabs = new Array("channels", "schedule", "features","search");
channelstab = 1;
featurestab = 0;
searchtab = 0;
myaccounttab = 0;
viewontvtab = 0;
abouttab = 0;
contributetab = 0;
advertisetab = 0;
newstab = 0;
contacttab = 0;
poweredtab = 0;
scheduletab = 0;

function setZero(){//set all tabs to 'off'
channelstab = 0;
featurestab = 0;
searchtab = 0;
myaccounttab = 0;
viewontvtab = 0;
abouttab = 0;
contributetab = 0;
advertisetab = 0;
newstab = 0;
contacttab = 0;
poweredtab = 0;
scheduletab = 0;
}


function schedulepage() {
	window.frames[0].location.href="f.schedule.php";
	setZero();
	scheduletab = 1;
}
function channelpage() {
	window.frames[0].location.href="f.channels.php";
	setZero();
	channelstab=1;
}
function dosearch() {
	window.frames[0].location.href="f.search.php";
	setZero();
	searchtab = 1;
}
function featurespage() {
	window.frames[0].location.href="f.features.php";
	setZero();
	featurestab = 1;
}
function myaccountpage() {
	window.frames[0].location.href="http://secure2.globaldigitalbroadcast.com/tvscuba/f.myaccount.php";
	setZero();
	myaccounttab=1;
}
function viewontvpage() {
	window.open('http://www.globaldigitalbroadcast.com','_blank','menubar=yes,scrollbars=yes,resizable=yes');	
	//window.frames[0].location.href="f.viewontv.php";
	setZero();
	viewontvtab=1;
}
function aboutpage() {
	window.frames[0].location.href="f.about.php";
	setZero();
	abouttab=1;
}
function contributepage() {
	window.frames[0].location.href="f.contribute.php";
	setZero();
	contributetab = 1;
}
function advertisepage() {
	window.frames[0].location.href="f.advertise.php";
	setZero();
	advertisetab = 1;
}
function newspage() {
	window.frames[0].location.href="f.news.php";
	setZero();
	newstab = 1;
}
function contactpage() {
	window.frames[0].location.href="f.contact.php";
	setZero();
	contacttab = 1;
}
function poweredpage() {
	window.open('http://www.globaldigitalbroadcast.com','_blank','menubar=yes,scrollbars=yes,resizable=yes');
//	window.frames[0].location.href="f.holding.php";
//	window.frames[0].location.href="f.powered.php";

	setZero();
	poweredtab = 1;
}

function imgOn(imgName,ext) {
	//ext = (ext == "") ? ext = "gif" : ext;	
	if (document.images) {
		document[imgName].src = "images/buttons/" + imgName + "_on." + ext;
	}
}

function imgOff(imgName,ext) {
	//ext = (ext == "") ? ext = "gif" : ext;	
	if (document.images) {
		document[imgName].src = "images/buttons/" + imgName + "_off." + ext;
		for(var i=0; i<tabs.length;i++) {
		if(eval(tabs[i] + "tab")==1) {
			document[tabs[i]].src = "images/buttons/" + tabs[i] + "_on." + ext;
		} else {
			document[tabs[i]].src = "images/buttons/" + tabs[i] + "_off." + ext;		
		}
		}
	}
}




// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

function ffwd() {
	document.mediaplayer1.controls.fastForward(); 
}

function rwd() {
	document.mediaplayer1.controls.fastReverse(); 
}

function doBuffering(end) {
	document.getElementById("buffer").style.visibility = hidden;
	document.getElementById("buffer").style.zIndex = 500;	
}

function doBuffering(start) {
	document.getElementById("buffer").style.visibility = "visible";
	document.getElementById("buffer").style.zIndex = 0;		
}

function stop() {
	document.mediaplayer1.controls.stop();
} 

function play() {	
	document.mediaplayer1.controls.play();
}

var theevent;
function fullScreen() {
	window.name='player';
	var k = window.open("timer.php","timer","width=250, height=100, scrolling=0, scrollbars=0, status=0, location=0");
	k.moveTo((screen.availWidth/2)-125,(screen.availHeight/2)-50);
	k.focus();
}

function goFullScreen() {
	var player = document.getElementById("mediaplayer1");
	if (player.playState == 3) { // check wmplayer status
		player.fullScreen = true;
	}
}

function closeAlert() {
	theevent.close();
}

function channelpagelist(thechannel,isSubs,isSched) {
	isSubs = (isSubs!=null)? isSubs : 0;
	isSched = (isSched!=null)? isSched : 0;
	if (isSubs==0){
		document.location.href="f.channel.php?id=" + thechannel;
		//alert("normal");
	}else{
		if (isSched==0){
			document.location.href="f.subscriptions.php?channel=" + thechannel;
		//alert("subscriptions");
		}else{
			document.location.href="f.subscriptions.php?channel=" + thechannel + "&is=" + isSched;
		}
	}
}

function subchannellist(thechannel) {
	document.location.href="f.channels.php?parentId=" + thechannel;
}

function register() {
	window.frames[0].location.href="register1.php";
}

function checkRegister1(f) {
	if(!f.email.value) {
		alert("Please enter an email address.");
		return false;
	}
	if((!f.pin.value)) {
		alert("Please enter a four digit PIN number.");
		return false;
	}
	return true;
}

function checkRegister2(f) {
	if(!f.firstname.value) {
		alert("Please enter your first name.");
		return false;
	}
	if(!f.lastname.value) {
		alert("Please enter your last name.");
		return false;
	}
	if(!f.address1.value) {
		alert("Please enter your address.");
		return false;
	}
	if(!f.town.value) {
		alert("Please enter your town.");
		return false;
	}
	if(!f.zip.value) {
		alert("Please enter your postcode.");
		return false;
	}	
	return true;
}

function checkRegister3(f) {
	if(!f.cardname.value) {
		alert("Please enter the name as it appears on your card.");
		return false;
	}
	if(!f.cardno.value) {
		alert("Please enter your card number.");
		return false;
	}
	if(!f.cv2.value) {
		alert("Please enter your CV2 number (the last three digits on the signature strip of your card).");
		return false;
	}
	return true;
}

function checkWatch(ppvHash,channelId,ppvid,ppvamt,mob,subs,login,portal,url)
{
	document.location.href = "http://secure2.globaldigitalbroadcast.com/" + url + "/checkLogin.php?h=" + ppvHash + "&channelId=" + channelId + "&ppvId=" + ppvid + "&ppvamt=" + ppvamt + "&mob=" + mob + "&s=" + subs + "&por=" + portal;
}

function checkpayment(f) {
	var theamount;
	for(var i=0;i<f.amount.length;i++) {
		if(f.amount[i].checked==true) theamount = f.amount[i].value;
	}
	if(confirm("You will be billed " + theamount + " which will be credited to your account.\n\n Click 'OK' to continue or 'Cancel' to go back.")) return true;
	return false;
}

function refreshto(theurl) {
	document.location.href = theurl;
}

function highlight(theel) {
	theel.style.backgroundColor='#fff';
}

function unhighlight(theel) {
	theel.style.backgroundColor='';
}

function startSchedule(src) {
	parent.document.location.href = "player.php?s=" + src;	
	
}

function schedulepagelist(thechannel) {
	document.location.href="f.schedule.php?schId=" + thechannel;
}

var curDateTime = new Date();
var curOffset = -(curDateTime.getTimezoneOffset()/60);

function localiseIt(inputTime){
	var now = new Date();
	now.setHours(inputTime.substr(0,inputTime.indexOf(":")));
	now.setMinutes(inputTime.substr(inputTime.indexOf(":")+1));
	now.setSeconds(0);
	var newHour = (now.getHours()+curOffset);
	var newMins = "";
	if(now.getMinutes()>59){
		newMins += (now.getMinutes()-59);
		newHour = (now.getHours()+(curOffset+1));
	}else{
		if(now.getMinutes()<10){
			newMins += "0"+now.getMinutes();
		}else{
			newMins += now.getMinutes();
		}
	}
	if(newHour>23){
		newHour -= 24;
	}
	var newTime = newHour+":"+newMins;
	document.write(newTime);
}

























