var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}}}


function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}}}
var newwindow = '';

function popitup(url,w,h)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
		//newwindow.width = w;
		//newwindow.height= h;
	} else {
		LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';

		newwindow=window.open(url,'pop',settings);
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

//ADD BOOKMARK
function addbookmark()
{
	if (window.sidebar) 
	{
		window.sidebar.addPanel(Config.defaultName, Config.defaultURL,"");
	} 
	else if( window.external ) 
	{
		window.external.AddFavorite( Config.defaultURL, Config.defaultName);
	} 
	else if(window.opera && window.print) 
	{
		return true;
	}
}

//REDIRECT
function Redirect(url)
{
	var url = Config.defaultURL + url;
	popitup(url,935,500);
}

//SET AS HOMEPAGE 
//CHECK FOR NULL - AND POPULATE THE LINK
if(Config.setAsHomepageImage=='null')
{
	//NO IMAGE
	var ie="<a href=/# style='cursor:hand' onclick=this.style.behavior='url(#default#homepage)';this.setHomePage(Config.defaultURL);>" + Config.setAsHomepageText + "</a>";

}
else
{
	if(document.all)
	{

	var ie="<a href=\# onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + Config.defaultURL + "');\" style='cursor:hand' ><img src=" + Config.setAsHomepageImage + " border=0>&nbsp;<span style=\"display: none;\" class=\"swHiddenSpaceHack\">&nbsp;</span>" + Config.setAsHomepageText + "</a>";
	}
	else
	{
	var ie="<a href=\# onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + Config.defaultURL + "');\" style='cursor:hand' ><img src=" + Config.setAsHomepageImage + " border=0>&nbsp;<span style=\"display: none;\" class=\"swHiddenSpaceHack\">&nbsp;</span>" + Config.setAsHomepageText + "</a>";
	}
}
//FUNCTION ONCE CALLED
function SetAsHomePage(page,title)
{

	if (document.all)
	{
		this.style.behavior='url(#default#homepage)';
		this.setHomePage('http://bbc.co.uk')
	}
	else if (window.sidebar)
	{
		window.sidebar.addPanel(title, page, "");
	}
	else if (window.sidebar&&window.sidebar.addPanel)
	{
		window.sidebar.addPanel(title,page,"");
	}
}



function PrintMe(w) {
var o='toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,width='+w+',height=600,left=100,top=25';
var pHTML=document.getElementById('prt').innerHTML;
var wp=window.open('','',o);
wp.document.open();
wp.document.write('<html><LINK href=http://www.silentworld.tv/css/smCommon1540.css rel=Stylesheet><LINK href=/css1540/print.css rel=Stylesheet>');
var browser = "";
	
	//detecting older Netscapes
	if (!document.all)
	{
		browser = "Old Netscape";
		wp.document.write('<link rel=stylesheet href=css1540/layout-ns.css>');
	}
	
	//detecting Opera
	if (navigator.userAgent.indexOf("Opera") > 0)
	{
		browser = "Opera";
		wp.document.write('<link rel=stylesheet href=css1540/layout-op.css>');
	}

	//detecting IE
	if (navigator.userAgent.indexOf("MSIE") > 0 && navigator.userAgent.indexOf("Opera") < 0)
	{
		browser = "IE";
		wp.document.write('<link rel=stylesheet href=css1540/layout-ie.css>');
	}

wp.document.write('<body leftmargin=0 rightmargin=0 topmargin=0><div class=extPopUp>');
wp.document.write(pHTML);
wp.document.write('</div></body></html>');
wp.document.close();
wp.focus();
}
function GetDiv(sDiv)
{
 var div;
 if (document.getElementById)
  div = document.getElementById(sDiv);
 else if (document.all)
  div = eval("window." + sDiv);
 else if (document.layers)
  div = document.layers[sDiv];
 else
  div = null;
 
 return div;
}
 
function HideDiv(sDiv)
{
 d = GetDiv(sDiv);
 if (d)
 {
  if (document.layers) d.visibility = "hide";
  else d.style.visibility = "hidden";
 }
}
 
function PleaseWait(sDivButton, sDivMessage, sInnerHtml)
{
 HideDiv(sDivButton);
 var d = GetDiv(sDivMessage);
 if (d) d.innerHTML = sInnerHtml;
}

function QuickGuide()
{
 	CreateWindow(Config.QuickGuideURL);
}

function RulesQuickGuide()
{
	CreateWindow(Config.RulesQuickGuide);
}

//CREATES A NEW WINDOW FROM URL
function CreateWindow(url)
{
	try
	{
		var newwindow = window.open(url,'name','height=' + Config.GuideHeight + ',width=' + Config.GuideWidth + ',scrollbars=yes');
		if (window.focus) {newwindow.focus()}
	}
	catch(error)
	{
		alert('An error has occured while creating new window \r\n\r\n Error :\r\n' + error.description);
	}
}

function ShowHide(pass)
{
var t = document.getElementById(pass);
var d = t.style.display;

if ("block"==d ) 
{
	Hide(pass); 
}
else
{
	Show(pass);
}
}

function ShowHide(divId,textDivId)
{
	//IS OVERLOADED METHOD OF ABOVE, THIS ONE CHANGES TEXT OF ANOTHER DIV
	var t = document.getElementById(divId);
	var l = document.getElementById(textDivId);
	var d = t.style.display;

	if ("block"==d ) 
	{
		Hide(divId);
		try
		{
			l.innerHTML = "<a class=\"playerStatAdvancedLink\" href=\"javascript:ShowHide('" + divId + "','" + textDivId + "');\"  >" + more + "&nbsp;<img src='/image/ajax/panels/arrowdown.gif' style='vertical-align:middle;' /></a>";
		}
		catch(e){}
	}
	else
	{
		Show(divId);
		try
		{
			l.innerHTML = "<a class=\"playerStatAdvancedLink\" href=\"javascript:ShowHide('" + divId + "','" + textDivId + "');\" >" + less + "&nbsp;<img src='/image/ajax/panels/arrowup.gif' style='vertical-align:middle;'/></a>";
		}
		catch(e){}
	}

}

function Hide(pass)
{
	document.getElementById(pass).style.display='none'; 
}

function Show(pass)
{
	document.getElementById(pass).style.display='block';
}

//LOOPS ROUND ALL DIVS AND MAKES THEM DISSAPEAR, AKA NONE
function CloseDivs()
{
    var collection = document.getElementsByTagName("div")
    
    var x = collection.length;
    for(i=0;i<(x);i++)
    {
        var a = collection[i].id;
        
        if (a.match(/^w\d{1,}$/)) { 
            collection[i].style.display='none';
        }
    }
}

//LOOPS ROUND ALL DIVS AND MAKES THEM DISSAPEAR, updated version for VirginMedia
function CloseDivsVirgin()
{
    var collection = document.getElementsByTagName('div');
    
    var x = collection.length;
    for(i=0;i<(x);i++)
    {
        var a = collection[i].id;
        
        if (a.match(/^w\d{1,}$/)) { 
            collection[i].style.display='none';
        }
    }
}


function ClipBoard(control,type) 
{

//
// type will be either asp or text, asp needs to be ported to copyTemp first
//

	if(type=='asp')
	{
		//MOVE TO TEMP CONTROL - THE TEXT IS COMING FROM A <ASP:TextBox />
		document.getElementById('copyTemp').value = document.getElementById(control).value;
		Copied = document.getElementById('copyTemp').createTextRange();
		Copied.execCommand("Copy");
	
	}
	else
	{
		//THE DATA IS COMING FROM A TEXTAREA WHICH SUPPORTS createTextRange();
		Copied = document.getElementById(control).createTextRange();
		Copied.execCommand("Copy");
		alert('The code has been copied to the clipboard.');
	}
}

function SelectAll(control)
{
//SELECT ALL TEXT, EASIER FOR COPYING TEXT
document.getElementById(control).select();
}


//
// MARCH 2008 CH AJAX Extensions 1.0 FOR .NET 2.0
//

function HoverDiv(id,color)
{
	var item = id.substring(3,4);
	if(document.getElementById('tab' + item).style.display == 'none')
	{
		document.getElementById(id).style.background = color;
	}
	else
	{
		//BOX0 is on tab0 so let is colour
		//document.getElementById(id).style.background = color;
	}	

}


function HoverDivCeleb(id,color,bkColor)
{
	var item = id.substring(3,4);
	if(document.getElementById('tab' + item + 'CelebList').style.display == 'none')
	{
		document.getElementById(id).style.background = color;
		document.getElementById(id).style.color = bkColor;
	}
	else
	{
		//BOX0 is on tab0 so let is colour
		//document.getElementById(id).style.background = color;
	}	

}

function EnableTabIncollection(item,totalTabs)
{
	//LOOPS ROUND THE TOTALTABS UNTIL FINDS item, sets item as visible all other invisible
	var i=0
	for (i=0;i<=totalTabs;i++)
	{	
		if(i==item)
		{
			if (document.getElementById('homeHighlightLeaguesAlt') == null)
			{
				// This means we are using the original look / feel 
				// SET TO BLOCK AND WHITESMOKE
				document.getElementById('tab' + item).style.display = 'BLOCK';
				document.getElementById('tab' + item + 'head').style.background = 'ivory';
				document.getElementById('tab' + item + 'head').style.borderBottom = '0px solid ivory';
			}
			else 
			{
				// This means we are using the alternate look / feel 
				document.getElementById('tab' + item + 'head').parentNode.id='current'
			}
		}
		else
		{
			if (document.getElementById('homeHighlightLeaguesAlt') == null)
			{
				// This means we are using the original look / feel 
				//THIS ISNT THE ACTIVE ITEM SO DISABLE
				document.getElementById('tab' + i).style.display = 'NONE';
				document.getElementById('tab' + i + 'head').style.background = 'white';
				document.getElementById('tab' + i + 'head').style.borderBottom = '1px solid black';
			}
			else 
			{
				// This means we are using the alternate look / feel 
				document.getElementById('tab' + i + 'head').parentNode.id=''
			}
		}
	}
}

function EnableTabIncollectionCeleb(item,totalTabs)
{
	//LOOPS ROUND THE TOTALTABS UNTIL FINDS item, sets item as visible all other invisible
	var i=0
	for (i=0;i<=totalTabs;i++)
	{	
		if(i==item)
		{
			//FOUND ITEM SET TO BLOCK AND WHITESMOKE
			document.getElementById('tab' + item + 'Celeb').style.display = 'BLOCK';
		}
		else
		{
			//THIS ISNT THE ACTIVE ITEM SO DISABLE
			document.getElementById('tab' + i + 'Celeb').style.display = 'NONE';
		}
	}
}

function EnableTabIncollectionCelebList(item,totalTabs)
{
   	var i=0
	for (i=0;i<=totalTabs;i++)
	{	
	    //SET THEM ALL AS HIDDEN
		document.getElementById('tab' + i + 'CelebList').style.display = 'NONE';
		document.getElementById('tab' + i + 'headCelebList').style.background = '#FFFFFF';
		document.getElementById('tab' + i + 'headCelebList').style.color = '#FF2C55';
	}
	//MAKE SHOW CURRENT
	document.getElementById('tab' + item + 'CelebList').style.display = 'BLOCK';
	document.getElementById('tab' + item + 'headCelebList').style.background = '#FF2C55';
	document.getElementById('tab' + item + 'headCelebList').style.color = '#FFFFFF';
}
///
/// JUNE 08 CH PREM ENHANCMENTS
///

function ShowPopPlayer(top,left,position)
{
	//WE NEED TO CHECK IF USER IS LOGGED IN, IF NOT DONT SHOW POPUP
	if(loggedIn=="True")
	{
		var  item = document.getElementById('teamPopUpPlayer');
		item.style.top = top + 70;
		item.style.left  = left + 20;
		item.style.display = "block";
		item.tag = position;
	
	}
}

function ShowPopPlayerT()
{
	var  item = document.getElementById('teamPopUpPlayer');
	item.style.display = "block";
	
}
function HidePopPlayer()
{
	var  item = document.getElementById('teamPopUpPlayer');
	item.style.display = "none";
}

function RedirectTransfer()
{
	//var length = document.getElementById('teamPopUpPlayer').tag.length;
	//.substring(1,(length-1));
	var posId = document.getElementById('teamPopUpPlayer').tag;

	var url = "/team.aspx?page=myPlayer&p=" + posId;
	window.location = url;
}

var direction;
var size = 75;
var newLeft = 0;
var newRight = 0;
var itemCountOn = 0;
var totalItems = 4;
var tempTitle= "";
var tempDescription= "";
function ScrollRight()
{
	//HIDE CONFIRMATION
	document.getElementById('scrollConfirmation').style.display = 'NONE';
	direction = "right";
	Scroll();
}
function ScrollLeft()
{
	//HIDE CONFIRMATION
	document.getElementById('scrollConfirmation').style.display = 'NONE';
	direction = "left";
	Scroll();
}
function Scroll()
{
	//HANDLES THE ACTUAL SCROLL
	if(direction=="right")
	{
		//SCROLL RIGHT
		document.getElementById('scrollLeftImg').src = "image/avatar/btnLeft.gif";
		//CHECK IF ITS ALL THE WAY OVER SO DONT LET IT GO TO THE RIGHT ANY FURTHER
		if(itemCountOn==(totalItems-3))
		{
			//DONT ALOW TO SCROL FURTHER
			document.getElementById('scrollRightImg').src="image/avatar/blank1.gif";
			return;
		}
		else
		{
			//SHOW IMAGE
			document.getElementById('scrollRightImg').src="image/avatar/btnRight.gif";
		}
		//SET DISTANCE TO GO RIGHT ONCE
		if(newLeft==0)
		{
			newLeft = parseInt(scrollDiv.style.left) - size;
		}
		
		if(parseInt(scrollDiv.style.left) <= newLeft)
		{
			//SET THE LEFT SPACE BACK TO 0 SO IT CAN MOVE AGAIN
			newLeft=0;
			itemCountOn++;
			return;
		}
		else
		{
			//SCROLL RIGHT
			scrollDiv.style.left =  parseInt(scrollDiv.style.left) - 10;
			setTimeout("Scroll()",0);
		}
	}
	else
	{
		//SCROLL LEFT
		document.getElementById('scrollRightImg').src="image/avatar/btnRight.gif";
		//CHECK IF ITS ALL THE WAY OVER SO DONT LET IT GO TO THE LEFT ANY FURTHER
		if(itemCountOn==0)
		{
			//DONT ALOW TO SCROL FURTHER
			document.getElementById('scrollLeftImg').src="image/avatar/blank1.gif";
			return;
		}
		//SET DISTANCE TO GO LEFT ONCE
		if(newLeft==0)
		{
			newLeft = parseInt(scrollDiv.style.left) + size;
		}
		
		if(parseInt(scrollDiv.style.left) >= newLeft)
		{
			//SET THE LEFT SPACE BACK TO 0 SO IT CAN MOVE AGAIN
			newLeft=0;
			itemCountOn--;
			return;
		}
		else
		{
			//SCROLL RIGHT
			scrollDiv.style.left =  parseInt(scrollDiv.style.left) + 10;
			setTimeout("Scroll()",0);
		}
	}
}
function PopulateAvatarItem(name,description)
{
	//GET ITEM TO POPULATES
	document.getElementById('scrollDescription').innerHTML = name + "<br/><br/>" + description;
}
function RestAvatarItem()
{
	document.getElementById('scrollDescription').innerHTML = "Hover over an image above.";
}

function PopulateAvatarItem(name,description)
{
	//GET ITEM TO POPULATES
	document.getElementById('scrollDescription').innerHTML = name + "<br/><br/>" + description;
}
function RestAvatarItem()
{
	document.getElementById('scrollDescription').innerHTML = tempTitle + "<br/><br/>" + tempDescription;
}
function RePositionPop(id,width)
{
	//RELOCATE POPUP IN TEAMS VIEW
	document.getElementById(id).style.top = (GetY()+25) + "px";
	document.getElementById(id).style.left = (GetX() - (width/2)) + "px";
}
function RePositionPopPREP(id,width)
{
	//RELOCATE POPUP IN TEAMS VIEW
	document.getElementById(id).style.top = (GetY()+25) + "px";
	document.getElementById(id).style.left = "15px";
}
function RePositionPopWithId(id,idTarget)
{
	//RELOCATE POPUP IN TEAMS VIEW
	var left = (screen.width / 2) - 250;
	var top = 0;
	var vLeft = document.getElementById(idTarget).style.left.replace("px","");
	var vTop = document.getElementById(idTarget).style.top.replace("px","");
	left = parseInt(left) + parseInt(vLeft);
	top = parseInt(vTop) + parseInt(400);

	//CHECK IF NEW LEFT IS GRATER THAN HALF WAY ACROSS - IF ALIGN TO THE RIGHT OF THE SHIRT
	if(left > ((screen.width / 2)-50))
	{
		left = left - 405;
		document.getElementById('arrowBottomImg').src="image/Controls/TeamHover/arrowBRight.gif";
		document.getElementById('arrowBottom').style.left = 330;
	}
	else
	{
		document.getElementById('arrowBottomImg').src="image/Controls/TeamHover/arrowBLeft.gif";
		document.getElementById('arrowBottom').style.left = -20;
	}
	document.getElementById(id).style.top = top;
	document.getElementById(id).style.left = left;
}
function RePositionPopWithIdTwoCol(id,idTarget)
{
	//RELOCATE POPUP IN TEAMS VIEW
	var left = (screen.width / 2) - 395;
	var top = 0;
	var vLeft = document.getElementById(idTarget).style.left.replace("px","");
	var vTop = document.getElementById(idTarget).style.top.replace("px","");
	left = parseInt(left) + parseInt(vLeft);
	top = parseInt(vTop) + parseInt(400);

	//CHECK IF NEW LEFT IS GRATER THAN HALF WAY ACROSS - IF ALIGN TO THE RIGHT OF THE SHIRT
	if(left > ((screen.width / 2)-50))
	{
		left = left - 425;
		document.getElementById('arrowBottomImg').src="image/Controls/TeamHover/arrowBRight.gif";
		document.getElementById('arrowBottom').style.left = 330;
	}
	else
	{
		document.getElementById('arrowBottomImg').src="image/Controls/TeamHover/arrowBLeft.gif";
		document.getElementById('arrowBottom').style.left = -20;
	}
	document.getElementById(id).style.top = top;
	document.getElementById(id).style.left = left;
}
function GetY()
{
	var y = window.pageYOffset;
	if(y==null)
	{
		y = document.body.scrollTop;
	}
	return y;

}
function GetX()
{
	var x = (screen.width / 2);
	if(x==null)
	{
		x = 50;
	}
	return x;
}

function ShowHideTSearch(idShow)
{
	//HIDE ALL FIRST
	Hide('TS0');
	Hide('TS1');
	Hide('TS2');
	Hide('TS3');
	Show('TS' + idShow);
}
