var http = getHTTPObject();
var http2 = getHTTPObject();
var http3 = getHTTPObject();
var httpViewers = getHTTPObject();//used in script
//-------------------------------------------------------------------------------------
  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;
  }
//------------------------------//
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);
}
//------------------------------//
var carry_clientId;
function playStreamClient(clientId,ppvId,directory){
	if(clientId>0){
		carry_clientId = clientId;
		var myRandom=parseInt(Math.random()*99999999);  // cache buster
		var url="includes/playStreamClient.php?clientId=" + clientId + "&ppvId=" + ppvId + "&dir=" + directory + "&rand=" + myRandom;
		http.open("GET", url, true);
		http.onreadystatechange = returnStreamClient;
		http.send(null);
	}
}
function returnStreamClient(){
	if(http.readyState == 4){
		top.document.getElementById('theContentDetails').innerHTML = http.responseText;
//		if(top.document.getElementById('limelightActive').value == 1){
//			changePlayerUrl(top.document.getElementById('limelightUrl').value);
//		}else{
			changePlayerUrl(top.document.getElementById('contentUrl').value);
//		}
	}
}
function changePlayerUrl(url){
	if(top.ply.controller.state != 'Closed')
	{
		top.ply.sendEvent('stop');
	}
	top.ply.configuration.file = url;
	setTimeout("updateAndPlay();",1000);
}
function updateAndPlay(){
	top.ply.sendEvent('play');
	document.location = 'f.metadata.php?clientid=' + carry_clientId + '&streamId=' + top.document.getElementById('theContentStreamId').value;
}
//------------------------------//
function refreshNowPlaying(ends){
	document.location = 'f.metadata.php?' + ends;
}
//------------------------------//
var mediaRequest;
function getGeoBlock(clientId,vars){
	mediaRequest = vars + clientId;
	var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url="includes/geoservice.php?clientId="+clientId+ "&rand=" + myRandom;
    http.open("GET", url, true);
    http.onreadystatechange = returnPermission;
    http.send(null);	
}

function returnPermission(){
	if (http.readyState == 4){
		if(http.responseText == "1"){
			getPlayer(mediaRequest);
		}else{
			window.document.location.href = "http://admin.gdbtv.com/blocked.php";
		}
	}
}
//------------------------------//


//---------JAVASCRIPT FOR----viewers-script--->>>
//moved var httpViewers = getHTTPObject();
var viewer = null;
var deadCount = 0;
function doMove() {
	if(parseInt(viewer.style.marginLeft)>0){
		viewer.style.marginLeft = parseInt(viewer.style.marginLeft)-10+"px";
  		setTimeout(doMove,20);
	}
}

function init() {
	var elements = getElementsByName_iefix("div","viewer");
	var oldView = "";
	try{if(elements[elements.length-1].id!="undefined"){
			oldView = elements[elements.length-1].id;
	}}catch(e){}
	viewer = top.document.getElementById(oldView);
	if(!parseInt(viewer.style.marginLeft)){
		viewer.style.marginLeft = "750px";
		doMove();
	}	
}

function getElementsByName_iefix(tag, name){
     var elem = top.document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function getViewers(){
	var elements = getElementsByName_iefix("div","viewer");
	var oldView = "&nothing";
	try{if((elements[elements.length-1].id!="undefined")&&(deadCount<(elements.length))){
		oldView = "&viewer="+elements[elements.length-1].getElementsByTagName("input")[0].value;
	}else{oldView = "&nothing";}}catch(e){oldView = "&nothing";}
    var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url="getViewer.php" + "?rand=" + myRandom + oldView;
	httpViewers.open("GET", url, true);
    httpViewers.onreadystatechange = showViewer;
    try{httpViewers.send(null);}
	catch(e){}
  }
  
 function showViewer()
 {
 	if (httpViewers.readyState == 4){
	  if(httpViewers.responseText!=""){
	  	top.document.getElementById("mask").innerHTML += httpViewers.responseText;
		setTimeout('init()',2000);
		}
    }
 }

function clearUp(){
	var elements = getElementsByName_iefix("div","viewer");
	var oldView = "";
	try{if((elements[elements.length-1].id!="undefined")&&(deadCount<(elements.length))){
			viewer = top.document.getElementById(elements[deadCount].id);
			doReMove();
	}}catch(e){}	
}

function doReMove() {
	if(parseInt(viewer.style.marginLeft)>(-219)){
		viewer.style.marginLeft = parseInt(viewer.style.marginLeft)-20+"px";
  		setTimeout(doReMove,20);
	}else{
		var d = top.document.getElementById("mask");
		var olddiv = viewer;
		try{d.removeChild(olddiv);}
		catch(e){}
		deadCount++;
		deadCount--;
	}
}

//---------END-OF-SCRIPT---------------------->>>

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){
	  //alert("show player  " + http.responseText);
	  top.document.getElementById("thePlayer").innerHTML = http.responseText;
silverLightPlayer(document.getElementById('sl_file').value,document.getElementById('sl_preview').value,document.getElementById('sl_height').value,document.getElementById('sl_width').value);
    }
 }
 
 // JAY //
var ply;
function silverLightPlayer(file,image,h,w){	
	var cnt = document.getElementById("mediaspace");
	var src = 'wmp/wmvplayer.xaml';
	var cfg = {
		file:file,
		image:image,
		height:h,
		width:w,
		autostart:"true",
		backcolor:"000000", 
    frontcolor:"FFFFFF", 
    lightcolor:"ED1C24"
	};
	ply = new jeroenwijering.Player(cnt,src,cfg);
}
// JAY //
 var targetDiv = "";
 function getPage(page,vars,target){
    targetDiv = target;
	var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url= page + ".php?rand=" + myRandom + vars;
	try{http2.open("GET", url, true);}
	catch(e){}
    http2.onreadystatechange = sendToPage;
    http2.send(null);
  }
  
 function sendToPage()
 {
 	if (http2.readyState == 4){
	  //window.alert("show player  " + targetDiv + http.responseText);
	  top.document.getElementById(targetDiv).innerHTML = http2.responseText;
    }
 }
 
 function getAccountPage(page,vars,target){
    targetDiv = target;
	var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url= "https://secure2.gdbtv.com/gouktv/" + page + ".php?rand=" + myRandom + vars;
	http3.open("GET", url, true);
    http3.onreadystatechange = sendAccountToPage;
    http3.send(null);
  }
  
 function sendAccountToPage()
 {
 	if (http3.readyState == 4){
	  //window.alert("show player  " + targetDiv + http.responseText);
	  top.document.getElementById(targetDiv).innerHTML = http3.responseText;
    }
 }
 
 //JAY//
 function getPlayerTrailer(vars){
    var myRandom=parseInt(Math.random()*99999999);  // cache buster
	var url="getPlayer.php" + "?rand=" + myRandom + vars;
    http.open("GET", url, true);
    http.onreadystatechange = showPlayerTrailer;
    http.send(null);
  }
  
 function showPlayerTrailer()
 {
 	if (http.readyState == 4){
	  //alert("show player  " + http.responseText);
	  if(top.document.getElementById("h").value == "" && top.document.getElementById("clientSchedListId").value == ""){
	  	top.document.getElementById("thePlayer").innerHTML = http.responseText;
	  }
    }
 }
 //JAY//

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;
	//alert(url);
	//url=url+"?q="+str;
	//url=url+"&sid="+Math.random();
	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);
		//schedAddCheck = clientUrl;
	}
}

var clientUrl;
var returnTime=7000;

function schedUpdated() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var framediv = parent.document.getElementById('schedList1');
		framediv.innerHTML=xmlHttp.responseText;
		if (schedAddCheck == "")
		{
			schedAddCheck = clientUrl;
			framediv = document.getElementById('translucentbkg');
			//framediv = window.frames[0].document.getElementById('translucentbkg');
			framediv.innerHTML=xmlHttp.responseText;
			//schedAddCheck = clientUrl + "/f.channel.php?id=" + parent.document.getElementById('clientSchedListId').value + "&play=1";
			//schedAddCheck = "off";
			//alert(schedAddCheck);
		}/*else
		{
			//if ((schedAddCheck == clientUrl + "/f.channel.php?id=" + jsGET('s') + "&play=1")
			//if ((window.frames['contentframe'].document.location.href != "https://secure2.gdbtv.com/gouktv/f.mylogin.php") && (window.frames['contentframe'].document.location.href != "https://secure2.gdbtv.com/gouktv/f.myaccount.php"))
			//{
				//alert(schedAddCheck);
				//framediv = window.frames['contentframe'].document.getElementById('translucentbkg');
				//framediv.innerHTML=xmlHttp.responseText;
				
			//}else{alert(schedAddCheck);}
		}*/
		//schedAddCheck = clientUrl + "/f.channel.php?id=" + jsGET('s') + "&play=1";
	}
}

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;
}
	try{
		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));
	}
	catch(e){/*continue*/}
	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');
		//window.frames['contentframe'].document.getElementById('theprogramme');
		/*find value from within player.php */ //alert(parent.document.getElementById('schedList1').value);
		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');
	}
  }
 }
}

/*function goToTrailer()
{
	document.location.href = "player.php";
}*/

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", "features", "myaccount", "search");
channelstab = 1;
featurestab = 0;
searchtab = 0;
myaccounttab = 0;
viewontvtab = 0;
abouttab = 0;
contributetab = 0;
advertisetab = 0;
newstab = 0;
contacttab = 0;
poweredtab = 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;
}
function channelpage() {
	window.frames[0].location.href="f.clients.php";
	setZero();
	channelstab=1;
}
function categoriespage() {
	window.frames[0].location.href="f.categories.php";
	//window.frames[0].location.href="f.clients.php";
	setZero();
	channelstab=1;
}
function packagespage() {
	top.window.frames[0].location.href="f.packages.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="https://secure2.gdbtv.com/gouktv/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) {
	if (document.images) {
		document[imgName].src = "images/buttons/" + imgName + "Off.gif";
	}
}
function imgOff(imgName) {
	if (document.images) {
		document[imgName].src = "images/buttons/" + imgName + "On.gif";
		for(var i=0; i<tabs.length;i++) {
		if(eval(tabs[i] + "tab")==1) {
			document[tabs[i]].src = "images/buttons/" + tabs[i] + "Off.gif";
		} else {
			document[tabs[i]].src = "images/buttons/" + tabs[i] + "On.gif";		
			}
		}
	}
}




// 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();

//alert(browser.isGecko);

//var controller = document.mediaplayer1;

function opentelly() {
	var w = window.open("telly.php","tv_brighton","location=0, scrolling=0, status=0, width=1005, height=715, statusbar=0");
	w.focus(); 
}

function opentelly2() {
	var w = window.open("player.php","tv_brighton","location=0, scrolling=0, status=1, statusbar=1, width=852, height=382, statusbar=0");
	w.focus(); 
}


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() {
//	var player = document.getElementById("mediaplayer1");
//	player.stop();
//  playerStatus = document.getElementById("mediaplayer1").playState;
//  playerStatus = document.mediaplayer1.playState;
//  document.mediaplayer1.controls.pause();
	document.mediaplayer1.controls.stop();
  /**
  if (playerStatus == 6) {
    player.play();
//    document.playerCtrl.playOrPause.value = " Pause ";
  } 
  else if (playerStatus == 1) {
    player.play();
//    document.playerCtrl.playOrPause.value = " Pause ";
  } 
  else if (playerStatus == 2) {
    player.pause(); 
//    document.playerCtrl.playOrPause.value = " Play  ";
  } else if (playerStatus == 3) {
    player.play();
//    document.playerCtrl.playOrPause.value = " Pause ";
  } 
**/
} 

function play() {
//	  document.mediaplayer1.controls.play();	
	document.mediaplayer1.controls.play();
//	var player = document.getElementById("mediaplayer1");
//	player.play();
}

/**
nn=(document.layers)?true:false;
ie=(document.all)?true:false;
function keyDown(e) {
	var evt=(e)?e:(window.event)?window.event:null;
	if(evt){
		var
key=(evt.charCode)?evt.charCode:((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
		if(key=="70") fullScreen();
	}
}
 
document.onkeydown=keyDown;

if(nn) document.captureEvents(Event.KEYDOWN);
**/
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() {
//	alert("To exit full screen mode, press the <Esc> key once.");
	var player = document.getElementById("mediaplayer1");
	if (player.playState == 3) { // check wmplayer status
		player.fullScreen = true;
	}
//	return false;
}

function closeAlert() {
	theevent.close();
}
/*
var tabs = new Array("channels","schedule","features","search","myaccount");

var channelstab = 0;
var scheduletab = 0;
var featurestab = 0;
var searchtab = 0;
var myaccounttab = 0;

function channels() {
	window.frames[0].location.href="frame.channels.php";
}

function channelpage() {
	window.frames[0].location.href="f.channels.php";
	channelstab = 1;
	scheduletab = 0;
	featurestab = 0;
	searchtab = 0;
	myaccounttab = 0;
}


function myaccount() {
	window.frames[0].location.href="https://secure2.gdbtv.com/account/myaccount.php";
}

function myaccountpage() {
	window.frames[0].location.href="https://secure2.gdbtv.com/tvbrighton/f.myaccount.php";
	myaccounttab = 1;
	scheduletab = 0;
	featurestab = 0;
	searchtab = 0;
	channelstab = 0; 
}

function schedule() {
	window.frames[0].location.href="frame.schedule.php";
}

function schedulepage() {
	window.frames[0].location.href="f.schedule.php";
	scheduletab = 1;
	channelstab = 0;
	featurestab = 0;
	searchtab = 0;
	myaccounttab = 0;
}


function dosearch() {
	window.frames[0].location.href="f.search.php";
	searchtab = 1;
	channelstab = 0;
	featurestab = 0;
	scheduletab = 0;
	myaccounttab = 0;

}

function features() {
	window.frames[0].location.href="frame.features.php";
}

function featurespage() {
	window.frames[0].location.href="f.features.php";
	featurestab = 1;
	scheduletab = 0;
	channelstab = 0;
	searchtab = 0;
	myaccounttab = 0;
}


function aboutus() {
	window.frames[0].location.href="aboutus.php";
}

function advertise() {
	window.frames[0].location.href="advertise.php";
}

function contribute() {
	window.frames[0].location.href="contribute.php";
}

function contact() {
	window.frames[0].location.href="contact.php";
}

function channel(thechannel) {
	document.location.href="frame.channel.php?id=" + thechannel;
}
*/
function channelpagelist(thechannel,isSubs,isSched,thisclient) {
	isSubs = (isSubs!=null)? isSubs : 0;
	isSched = (isSched!=null)? isSched : 0;
	if (isSubs==0){
		document.location.href="f.channel.php?clientid=" + thisclient + "&id=" + thechannel + "&trailer=1";
		//alert("normal");
	}else{
		if (isSched==0){
			document.location.href="f.subscriptions.php?clientid=" + thisclient + "&channel=" + thechannel;
		//alert("subscriptions");
		}else{
			document.location.href="f.subscriptions.php?clientid=" + thisclient + "&channel=" + thechannel + "&is=" + isSched;
		}
	}
}

function subchannellist(thechannel,thisclient) {
	document.location.href="f.channels.php?clientid=" + thisclient + "&parentId=" + thechannel + "&trailer=1";
}

function openchannel(thechannel,thisclient) {
	top.window.frames[0].location.href="f.channels.php?clientid=" + thisclient + "&parentId=" + thechannel + "&trailer=1";
}
function listprogrammes(thechannel,isSubs,isSched,thisclient) {
	isSubs = (isSubs!=null)? isSubs : 0;
	isSched = (isSched!=null)? isSched : 0;
	if (isSubs==0){
		window.frames[0].location.href="f.channel.php?clientid=" + thisclient + "&id=" + thechannel + "&trailer=1";
		//alert("normal");
	}else{
		if (isSched==0){
			window.frames[0].location.href="f.subscriptions.php?clientid=" + thisclient + "&channel=" + thechannel;
		//alert("subscriptions");
		}else{
			window.frames[0].location.href="f.subscriptions.php?clientid=" + thisclient + "&channel=" + thechannel + "&is=" + isSched;
		}
	}
}
function packageDetails(thisclient,subsId){
	top.window.frames[0].location.href="f.subscriptionsDetail.php?clientid="+thisclient+"&id="+subsId;	
}

function subclientlist(thisclient) {
	document.location.href="f.channels.php?clientid=" + thisclient + "&trailer=1";
}

function register() {
	window.frames[0].location.href="register1.php";
}

/**
function watch(programmeId,url) { 
	if(parseFloat(cost)==0) {
		parent.getElementById("mediaplayer1").URL = "thisone";
		parent.document.mediaplayer1.URL = "thisone";
	}
}
**/

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 showreel() {
	parent.document.location.href = "telly.php?showreel=1";
}

function checkWatch(ppvHash,channelId,ppvid,ppvamt,mob,subs,login,portal,url,thisclientid)
{
	//if ((login==1) || (ppvamt > 0) || (subs > 0))
	//{
		document.location.href = "https://secure2.gdbtv.com/" + url + "/checkLogin.php?h=" + ppvHash + "&channelId=" + channelId + "&ppvId=" + ppvid + "&ppvamt=" + ppvamt + "&mob=" + mob + "&s=" + subs + "&por=" + portal + "&clientid=" + thisclientid;
	//} else {
		//just play it
		//document.location.href = "f.ppvconfirm.php?h=" + ppvHash;
	//}
}
function programmeConfirm(ppvHash,channelId,ppvid,ppvamt,mob,subs,login,portal,url,thisclientid)
{
	//alert(ppvHash+" @ "+channelId+" @ "+ppvid+" @ "+ppvamt+" @ "+mob+" @ "+subs+" @ "+login+" @ "+portal+" @ "+url+" @ "+thisclientid);
	window.frames[2].location.href = "https://secure2.gdbtv.com/gouktv/checkLogin.php?h=" + ppvHash + "&channelId=" + channelId + "&ppvId=" + ppvid + "&ppvamt=" + ppvamt + "&mob=" + mob + "&s=" + subs + "&por=" + portal + "&clientid=" + thisclientid;
}
function searchFor(vars)
{//catId = the category
	window.frames[0].location.href = "http://admin.gdbtv.com/gouktv1/search.for.php?"+vars;	
}


function dowatch2(ppvHash) {
	parent.document.location.href = "telly.php?h=" + ppvHash;
}

function dowatch(ppvHash, channelId) {
	document.location.href="frame.channel.php?h=" + ppvHash + "&id=" + channelId;
}

function dowatch3(ppvHash, channelId, issearch) {
	document.location.href="f.channel.php?h=" + ppvHash + "&id=" + channelId + "&search=" + issearch;
}

function dowatch5(ppvHash, channelId, issearch) {
	document.location.href="f.ppvconfirm.php?h=" + ppvHash + "&id=" + channelId + "&search=" + issearch;
}

function dowatch4(ppvHash) {
	parent.document.location.href = "player.php?h=" + ppvHash;
}

function dowatch4Mob(ppvHash) {
	document.location.href = "m.player.php?h=" + ppvHash;
	//alert("dw4 " + ppvHash);
}

function dowatch5Mob(ppvHash) {
	//alert(ppvHash);
	document.location.href = "m.ppvconfirm.php?h=" + ppvHash;
	//alert("dw5 " + ppvHash);
}

function dowatch3Mob(ppvHash)
{
	document.location.href = "m.login.php?h=" + ppvHash;
}
function dowatch6(ppvHash, channelId, issearch) {
	//document.location.href="f.channel.php?h=" + ppvHash + "&id=" + channelId + "&search=" + issearch;
	window.frames[0].location.href="f.ppvdetail.php?h=" + ppvHash + "&id=" + channelId + "&search=" + issearch;
	//alert("dw6 " + ppvHash);
}

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 playppv(thehash) {
	parent.document.location.href='player.php?h=' + thehash;
}
/*
function imgOn(imgName) {
	if (document.images) {
		document[imgName].src = "images/new/" + imgName + "_on.gif";
	}
}

function imgOff(imgName) {
	if (document.images) {
		document[imgName].src = "images/new/" + imgName + "_off.gif";
		for(var i=0; i<tabs.length;i++) {
		if(eval(tabs[i] + "tab")==1) {
			document[tabs[i]].src = "images/new/" + tabs[i] + "_on.gif";
		} else {
			document[tabs[i]].src = "images/new/" + tabs[i] + "_off.gif";		
		}
		}
	}
}
*/
/**
function highlight(theel) {
	theel.style.backgroundColor='#fff';
}
**/

function highlight(theel) {
	theel.style.backgroundColor='#999';
//	theel.style.filter = "Alpha(Opacity=100)";
//	theel.style.MozOpacity = "1";
}

/**
function unhighlight(theel) {
	theel.style.backgroundColor='transparent';
}**/

function unhighlight(theel) {
	theel.style.backgroundColor='';
//	theel.style.filter = "Alpha(Opacity=60)";
//	theel.style.MozOpacity = "0.6";	
}

function startSchedule(src,thisclientid) {
	top.document.location.href = "player.php?s=" + src + "&x=" + thisclientid;
	//alert(top.document.location.href);	
}

function startSchedule1(src)
{
parent.document.location.href = "player.php?s=" + src;	
//getPlayer(src);
}


function schedulepagelist(thechannel) {
	document.location.href="f.schedule.php?schId=" + thechannel;
}

//make PNGs transparent in IE5.5+
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}
//end of make PNGs transparent

function goToTop(topOffSet) {
	//var topOffSet = top.window.pageYOffset;
	setTimeout('top.window.scrollTo(0,'+topOffSet+')',200);//scroll(0,0);
}