/*Generic pop up code - please use this only unless you really need something different*/
function popUpPage(url, parameters, name)
{
	var day = new Date();
	var pageName = name ? name : day.getTime()

	eval("bbc"+pageName+" = window.open('"+url+"','"+pageName+"','"+parameters+"')");

	if (eval("bbc"+pageName) && window.focus) eval("bbc"+pageName).focus();
}

/* launch code for avconsole */
function NO_launch_main_player(site)
{
	
	if (site == null) //no site name passed in - have to leave this check in
	{
		clickmain=window.open("/narrowband/static/audio_video/avconsole/ukfs/f_sport_console.stm","clickmain","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top=100,left=100,width=671,height=373");
	}
	else
	{
		if (site == 'UKFS Sport')
		{
			clickmain=window.open("/narrowband/static/audio_video/avconsole/ukfs/f_sport_console.stm","clickmain","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top=100,left=100,width=671,height=373");

		}
		else if (site == 'IFS Sport')
		{
			clickmain=window.open("/narrowband/static/audio_video/avconsole/ifs/f_sport_console.stm","clickmain","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,top=100,left=100,width=671,height=373");
		}
	}
}

function NOlaunchAVConsoleStory(storyid,isBB)
{
	if(bbcV2Tst())
	{
	consoleurl = "http://www.bbc.co.uk/mediaselector/check/sol/ukfs_sport/hi/av?redirect=fs.stm&news=1&bbram=1&bbwm=1";
		if(!isBB)
		{
		consoleurl = consoleurl + "&nbram=1&nbwm=1";
		}
	consoleurl = consoleurl + "&nol_storyid=" + storyid;
		clickmain=window.open(consoleurl,"console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width=681,height=487");
	}
	else
	{
		self.location.href="http://news.bbc.co.uk/sport2/hi/3791877.stm";
	}
}

function NO_launchAVConsoleV3(section,isBB)
{
	if(bbcV2Tst())
	{
	
	if (section)
	{
		//var url = "http://www.bbc.co.uk/mediaselector/check/sol/ukfs_sport/hi/av?redirect=fs_fp.stm&bbram=1&bbwm=1&news=1";
		var url = "http://www.bbc.co.uk/go/sport/int/av1/-/http://www.bbc.co.uk/mediaselector/check/sol/ukfs_sport/hi/av?redirect=fs_fp.stm&bbram=1&bbwm=1&news=1";
	}
	else
	{
		//var url = "http://www.bbc.co.uk/mediaselector/check/sol/ukfs_sport/hi/av?redirect=fs_fp.stm&bbram=1&bbwm=1&news=1";
		var url = "http://www.bbc.co.uk/go/sport/int/av1/-/http://www.bbc.co.uk/mediaselector/check/sol/ukfs_sport/hi/av?redirect=fs_fp.stm&bbram=1&bbwm=1&news=1";
	}
	
	if(!isBB)
	{
	url = url + "&nbram=1&nbwm=1";
	}
	
	if (section)
	{
		url = url + "&nol_index=" + section;
	}
		clickmain=window.open(url,"console","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,width=681,height=487");
}
	else
	{
		self.location.href="http://news.bbc.co.uk/sport2/hi/3791877.stm";
	}
}

function bbcV2Tst(){

	var type = getBrowserType();
	
	return (type  != "other" &&(type == "ie5" || type == "nav6" || type == "domCompliant"));
}

function getPlatform()
{
	var myUserAgent;
	myUserAgent = navigator.userAgent.toLowerCase();

	if ((myUserAgent.indexOf("win") != -1) ||  (myUserAgent.indexOf("16bit") != -1))
	{
		return "win";
	}
	
	if (myUserAgent.indexOf("mac") != -1)
	{
		return "mac";
	}  
	
	if (myUserAgent.indexOf("x11") != -1)
	{
		return "unx";
	}  
	
	return "other";
}

function getBrowserType()
{
	var myUserAgent;

	var myMajor;
	myUserAgent= navigator.userAgent.toLowerCase();
	myMajor= parseInt(navigator.appVersion);
	if( (myUserAgent.indexOf('mozilla')!= -1) &&(myUserAgent.indexOf('spoofer')== -1) &&(myUserAgent.indexOf('compatible') == -1) &&(myUserAgent.indexOf('opera') == -1) &&(myUserAgent.indexOf('webtv')  == -1) )
	{  
		if (myMajor > 4 )
			{
				return "nav6";
			} 
			else if ((myMajor == 4 ) || (myMajor == 5 ))
			{
				return "nav4";
			}
	}
	
	if (myUserAgent.indexOf("msie") == 4)
		{
			return "ie4";
			
	}
	else if (myUserAgent.indexOf("msie") == 5)
		{
			return "ie5";
		}	
// dom compliant browsers are allowed
	if(document.body.firstChild) 
	return "domCompliant";
	return "other";
}

function NO_request_launch(site)
{
	if (getPlatform() != "other" &&(getBrowserType() == "ie4" || getBrowserType() == "nav4" || getBrowserType() == "domCompliant"))
	{
		launch_main_player(site);
	} 
	else 
	{
		self.location.href="/hi/english/static/audio_video/avconsole/old_browser.stm";
	}
	
	return;
}
//used for weather pop-up
function popUp(pageurl,width,height,scroll)
{
	day = new Date();
	id = day.getTime();
  	
	if (window.screen)
	{
		lpos = (screen.width/2)-(width/2);
  		hpos = (screen.height/2)-(height/2);
	}
	else
	{
		lpos = 1;
	hpos = 1;
	} 
	
	eval("bbcnews"+id+" = 	window.open('"+pageurl+"','"+id+"','toolbar=0,scrollbars="+scroll+",location=0,status=0,menubar=0,resizable=0,width="+width+",height="+height+",left="+lpos+",top="+hpos+"')");
}

/* 
pop-up code used by desktop scoreboard and ultra items 
function popup(url)
{
	day = new Date();
	id = day.getTime();

	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=370,height=220');");
}


*/

/* temporary js for on-demand radio player - remove after Wimbledon */
function aodpopup(URL){
//add 70px to height if mac
var high=355;
ismac=false;
if(navigator.userAgent.indexOf("Mac")!=-1){
	high=435;
}

window.open(URL,'aod','width=662,height='+high+',top=0,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=no,left=60,screenX=60,top=100,screenY=100');

window.name="main";

if(location.search.substring(1)=="focuswin"){
	window.focus();

}
}

function sv() 
{ 
	var tag = document.getElementById('lowSwitch');
	if (tag)
	{ 
		window.location = tag.getAttribute('content');				
		return false;
	} 
	else
	{ 
		window.location = "http://news.bbc.co.uk/sport/text_only.stm";
		return true;
	} 
} 

//RSS
function getArgs() { 
	var Args = new Object(); 
	var query = location.search.substring(1); 
	var pairs = query.split("&"); 
	for (var i = 0; i < pairs.length; i++) 
	{ 
		var pos = pairs[i].indexOf('='); 
		if (pos == -1) continue; 
		var argname = pairs[i].substring(0,pos); 
		var value = pairs[i].substring(pos+1); 
		Args[argname] = unescape(value); 
	} 
	return Args;
}

function getRssUrl() { 
if (document.getElementsByTagName)
{
	var url = "http://news.bbc.co.uk/go/sport1/int/footer/-/sport1/hi/help/rss/default.stm";
	var linkTags = document.getElementsByTagName("link");
	var rssURI;
	for (var i = 0; i < linkTags.length; i++) {if (linkTags[i].getAttribute('type') == "application/rss+xml") {rssURI = linkTags[i].getAttribute('href');}}
	if (rssURI){document.write('<div class="rsslink" style="padding:0 16px 8px 0;margin:4px 0 0px 6px;"><a href="'+rssURI+'"><img height="16" hspace="0" vspace="0" border="0" width="16" alt="Sport feeds" src="http://newsimg.bbc.co.uk/shared/img/v3/feed.gif" title="Sport feeds" align="right" /></a><a href="'+url+'" title="Sport feeds help">Sport feeds</a><span class="feedbar">&nbsp;|&nbsp;</span></div>')}
}
}

function getRssUrlStory(rssURI) { 
if (document.getElementsByTagName)
{
	var url = "http://news.bbc.co.uk/go/sport1/int/footer/-/sport1/hi/help/rss/default.stm";

	if (rssURI){document.write('<span class="feedslink"><a href="'+rssURI+'"><img height="16" hspace="7" vspace="2" border="0" width="16" alt="Sport feeds" src="http://newsimg.bbc.co.uk/shared/img/v3/feed.gif" title="Sport feeds" align="right" /></a><a href="'+url+'" title="Sport feeds help">Sport feeds</a><span class="feedbar">&nbsp;|&nbsp;</span><br clear="all"/>')}
}
}


// pic Gallery colours
var currentPicColor = '#900';
var unselectedColor = '#039';
var deadLinkColor = '#ccc';

//   ---------------------------------
function Navselect(navtype){/* navtype defines which nav this refers to */

	this.navtype=navtype;

	this.highlightCurrentTab();	

	this.findTabOnPage();

	this.makeChangesToTab();

}



Navselect.prototype.highlightCurrentTab = function() {

	this.ULs=document.getElementsByTagName("ul");

	this.pageurl = document.location.href.split("?")[0]; /* remove any query string or # on url */

	if(this.pageurl.charAt(this.pageurl.length-1)=="#")this.pageurl = document.location.href.split("#")[0];

}



Navselect.prototype.findTabOnPage = function() {

	var UL, LIs, LI, i=j= -1;

	this.linksInList=[];

	while( UL=this.ULs[++i] ){/* Loop stops when ULs[n]--> null */

		if(UL.id==this.navtype){

			this.navUL=UL;

			j = -1;

			LIs=UL.getElementsByTagName("li");

			while( LI=LIs[++j] ){/* loop through hrefs in li to see which tab matches this url */

				this.linksInList[j]=LI.childNodes.item(0);/* make array of all the links on the list */

				if(LI.childNodes.item(0)==this.pageurl){

					this.tabToHighlight=LI;/* selected LI that matches page location */

					this.onThisPage=j;/* numerical value for this list item */

				}

			}

			this.totalNumberOfLinks=j;

		}

	} 

}



Navselect.prototype.makeChangesToTab=function(){/*  Defferent changes to LI depending on navtype */ 

	if(this.navtype=="tabnav"){// TABNAV

		this.tabToHighlight.style.background="url(/sol/shared/img/v3/tabs/tab_bg104o.gif) #eee";

		var thisTagTxt=this.tabToHighlight.firstChild.firstChild.data;/* Remove Link and replace with text */

		var myTextNode=document.createTextNode(thisTagTxt);

		this.tabToHighlight.removeChild(this.tabToHighlight.firstChild);

		this.tabToHighlight.appendChild(myTextNode);

	}else if(this.navtype=="galnav"){// GALNAV

		this.tabToHighlight.style.background="#990000";

		var thisTagTxt=this.tabToHighlight.firstChild.firstChild.data;/* Remove Link and replace with text */

		var myTextNode=document.createTextNode(thisTagTxt);

		this.tabToHighlight.removeChild(this.tabToHighlight.firstChild);

		this.tabToHighlight.appendChild(myTextNode);

		this.reSizeGalNav();

		this.backNext();

	}

}

			

Navselect.prototype.reSizeGalNav = function(){

	if(this.totalNumberOfLinks<18) {

		var numsWidth=(this.totalNumberOfLinks*24);

		this.navUL.style.width=numsWidth;

	}

}



Navselect.prototype.backNext = function(){

	//alert(this.onThisPage+" :::::::::::: "+this.totalNumberOfLinks);//

	if(this.onThisPage==0){

		var bakString="<b>Back</b>";

	}else{

		var bakString='<a href="'+this.linksInList[(this.onThisPage-1)]+'">Back</a>';

	}

	if(this.onThisPage==(this.totalNumberOfLinks-1)){

		var nxtString="<b>Next</b>";

	}else{

		var nxtString='<a href="'+this.linksInList[(this.onThisPage+1)]+'">Next</a>';

	}

	var bakTD=document.getElementById("bak");

	var nxtTD=document.getElementById("nxt");	

	

	bakTD.innerHTML=bakString;

	nxtTD.innerHTML=nxtString;

}



Navselect.prototype.ColorOver=function(o) {

    o.parentNode.style.backgroundColor="#cc0000";

}



Navselect.prototype.ColorOut=function(o) {

    o.parentNode.style.backgroundColor="#0000cc";

}
function whichTab() {
        var ULs, UL, LIs, LI, i=j= -1, pageurl = document.location.href.split("?")[0];
        ULs = document.getElementsByTagName("ul"); 
        while( UL=ULs[++i] ){/* Loop stops when ULs[n]--> null */
                if(UL.id=="tabnav"){
                j = -1;
                LIs=UL.getElementsByTagName("li");
                while( LI=LIs[++j] ){//loop through hrefs in li to see which tab matches this url
                        if(LI.childNodes.item(0)==pageurl){// Change <li> background
                                LI.style.background="url(http://newsimg.bbc.co.uk/sol/shared/img/v3/tabs/tab_bg104o.gif) #eee";
                                // Remove Link and replace with text
                                var thisTagTxt=LI.firstChild.firstChild.data;
                                var myTextNode=document.createTextNode(thisTagTxt);
                                LI.removeChild(LI.firstChild);
                                LI.appendChild(myTextNode);
                        }
                }
                }
        } 
}

