function storeMyTeam(myTeam,roundid)
{
	var expires = new Date();
	var onyear = expires.getTime() + 31536000000;
	expires.setTime(onyear);
	setCookie('CmyTeam'+roundid,myTeam,expires,'/');								
}

function storeGalleryCookie()
{
	setCookie('CBktoGalURL',document.URL,'','/');		
}

function loadGalleryCookie()
{
	if(document.cookie)
	{     
		if(getCookie('CBktoGalURL'))
		{
			return getCookie('CBktoGalURL');
     	}
		else return 'javascript:history.back();'

	}		
	else return 'javascript:history.back();'
}

function storeNewsCookie()
{
	setCookie('CBktoNewsListURL',document.URL,'','/');		
}

function loadNewsCookie()
{
	if(document.cookie)
	{     
		if(getCookie('CBktoNewsListURL'))
		{
			return getCookie('CBktoNewsListURL');
     	}
		else return 'javascript:history.back();'

	}		
	else return 'javascript:history.back();'
}

function loadNewsLetterCookie()
{
	if(document.cookie)
	{     
		if(getCookie('CBkNL'))
		{
			return getCookie('CBkNL');
     	}
		else return 'javascript:history.back();'

	}		
	else return 'javascript:history.back();'
}

function getMyPlayersProfile(url,divID,playernumber,imagepos)
{
	var str = 'myPlayImg_'+String(imagepos);
	
	new Ajax.Request	(
							url,
							{
								method		: 'get',
								onSuccess	: function(transport)
								{
									document.getElementById(divID).innerHTML=transport.responseText;
									document.getElementById(str).src=document.getElementById('mpImage'+String(playernumber)).innerHTML;
									document.getElementById(str).title=document.getElementById('mpName'+String(playernumber)).innerHTML;
									document.getElementById(str).alt=document.getElementById('mpName'+String(playernumber)).innerHTML;		
									document.getElementById(str).className='player';
									evalJsNodes(document.getElementById(divID));
									this.ready = true;
								}
							}
						);
}

function getPlayByPlay(url,divID)
{

	new Ajax.Request	(
							url,
							{
								method		: 'get',
								onSuccess	: function(transport)
								{
									document.getElementById(divID).innerHTML=transport.responseText;
									evalJsNodes(document.getElementById(divID));
									this.ready = true;
								}
							}
						);
}

function getSelectValuesMYP(url,roundid)
{
	roundid = roundid || '0';
	new Ajax.Request	(
							url,
							{
								method		: 'get',
								onSuccess	: function(transport)
								{
									MyPlayListArray = transport.responseText.evalJSON(true);
									document.getElementById('waitforload').style.display='';
									if (roundid > 0)
										checkPlayerExists(roundid,true);
									this.ready = true;
								}
							}
						);
}

function getscheduleTVChannels(url)
{
	var TVChannelsListArray = new Array();
	new Ajax.Request	(
							url,
							{
								method		: 'get',
								onSuccess	: function(transport)
								{
									TVChannelsListArray = transport.responseText.evalJSON(true);
									for(var TVi = 0; TVi < TVChannelsListArray.TV_Channels.length;TVi++)
									{
										if(document.getElementById('_'+TVChannelsListArray.TV_Channels[TVi].roundid+TVChannelsListArray.TV_Channels[TVi].gamename+TVChannelsListArray.TV_Channels[TVi].groupname))
										{
											if(TVChannelsListArray.TV_Channels[TVi].ChannelLink == 'NA')
												document.getElementById('_'+TVChannelsListArray.TV_Channels[TVi].roundid+TVChannelsListArray.TV_Channels[TVi].gamename+TVChannelsListArray.TV_Channels[TVi].groupname).innerHTML=TVChannelsListArray.TV_Channels[TVi].ChannelShortName;
											else
												document.getElementById('_'+TVChannelsListArray.TV_Channels[TVi].roundid+TVChannelsListArray.TV_Channels[TVi].gamename+TVChannelsListArray.TV_Channels[TVi].groupname).innerHTML='<a href="'+ TVChannelsListArray.TV_Channels[TVi].ChannelLink+'" onclick="window.open(this.href); return false;">'+TVChannelsListArray.TV_Channels[TVi].ChannelShortName+'</a>';
										}
									}
									this.ready = true;
								}
							}
						);
}

function fillTeamSelectMYP(teamboxid,StrNoTea,StrSelTea)
{
	document.getElementById(teamboxid).options.length=0;
	if(MyPlayListArray.team_List.length == 0)
	{
		var option = document.createElement("OPTION");
		option.appendChild(document.createTextNode(StrNoTea));
		option.setAttribute('value', 0);
		document.getElementById(teamboxid).appendChild(option);
	}
	else
	{	
		var opttext = document.createElement("OPTION");
			opttext.appendChild(document.createTextNode(StrSelTea));
			opttext.setAttribute('value', 0);
			document.getElementById(teamboxid).appendChild(opttext);
			opttext = document.createElement("OPTION");
			opttext.appendChild(document.createTextNode('------------'));
			opttext.setAttribute('value', 'nojump');
			document.getElementById(teamboxid).appendChild(opttext);
			
		for (var teami = 0; teami < MyPlayListArray.team_List.length; teami++)
		{
			var option = document.createElement("OPTION");
			option.appendChild(document.createTextNode(MyPlayListArray.team_List[teami].name));
			option.setAttribute('value', MyPlayListArray.team_List[teami].tID);
			document.getElementById(teamboxid).appendChild(option);
		}
	}
	
}

function fillPlayersSelectMYP(value,playerboxid,StrNoPly,StrSelTea,StrSelPly)
{
	document.getElementById(playerboxid).options.length=0;
	if(MyPlayListArray.player_List.length == 0 || value==0)
	{
		if(MyPlayListArray.player_List.length == 0)
		{
			var option = document.createElement("OPTION");
			option.appendChild(document.createTextNode(StrNoPly));
			document.getElementById(playerboxid).appendChild(option);
		}
		if( value==0)
		{
			var option = document.createElement("OPTION");
			option.appendChild(document.createTextNode(StrSelTea));
			document.getElementById(playerboxid).appendChild(option);
		}		
	}
	else
	{	
		var opttext = document.createElement("OPTION");
			opttext.appendChild(document.createTextNode(StrSelPly));
			opttext.setAttribute('value', 0);
			document.getElementById(playerboxid).appendChild(opttext);
			opttext = document.createElement("OPTION");
			opttext.appendChild(document.createTextNode('------------'));
			opttext.setAttribute('value', 'nojump');
			document.getElementById(playerboxid).appendChild(opttext);
			
		for (var playeri = 0; playeri < MyPlayListArray.player_List.length; playeri++)
		{
			if(MyPlayListArray.player_List[playeri].tID==value && MyPlayListArray.player_List[playeri].pID != myp1 &&  MyPlayListArray.player_List[playeri].pID != myp2 &&  MyPlayListArray.player_List[playeri].pID != myp3 && MyPlayListArray.player_List[playeri].pID != myp4 && MyPlayListArray.player_List[playeri].pID != myp5)
			{
				var option = document.createElement("OPTION");
				var str = document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
				option.appendChild(str);
				option.setAttribute('value', MyPlayListArray.player_List[playeri].pID);
				document.getElementById(playerboxid).appendChild(option);
			}
		}
	}
	resetMYPErrorMessages();
}

function fillSelectedPlayers(selplayboxid)
{
	document.getElementById(selplayboxid).options.length=0;
	var pn1,pn2,pn3,pn4,pn5;
	var pid1 = 0,pid2=0,pid3=0,pid4=0,pid5=0;
	for (var playeri = 0; playeri < MyPlayListArray.player_List.length; playeri++)
	{
		if(MyPlayListArray.player_List[playeri].pID == myp1)
		{
			pn1= document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
			pid1= MyPlayListArray.player_List[playeri].pID;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp2)
		{
			pn2= document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
			pid2= MyPlayListArray.player_List[playeri].pID;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp3)
		{
			pn3= document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
			pid3= MyPlayListArray.player_List[playeri].pID;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp4)
		{
			pn4= document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
			pid4= MyPlayListArray.player_List[playeri].pID;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp5)
		{
			pn5= document.createTextNode(MyPlayListArray.player_List[playeri].firstname+' '+MyPlayListArray.player_List[playeri].lastname);
			pid5= MyPlayListArray.player_List[playeri].pID;
		}
	}
	if(pid1>0)
	{
				var option = document.createElement("OPTION");
				option.appendChild(pn1);
				option.setAttribute('value', pid1);
				document.getElementById(selplayboxid).appendChild(option);
	}
	if(pid2>0)
	{
				var option = document.createElement("OPTION");
				option.appendChild(pn2);
				option.setAttribute('value', pid2);
				document.getElementById(selplayboxid).appendChild(option);
	}
	if(pid3>0)
	{
				var option = document.createElement("OPTION");
				option.appendChild(pn3);
				option.setAttribute('value', pid3);
				document.getElementById(selplayboxid).appendChild(option);
	}
	if(pid4>0)
	{
				var option = document.createElement("OPTION");
				option.appendChild(pn4);
				option.setAttribute('value', pid4);
				document.getElementById(selplayboxid).appendChild(option);
	}
	if(pid5>0)
	{
				var option = document.createElement("OPTION");
				option.appendChild(pn5);
				option.setAttribute('value', pid5);
				document.getElementById(selplayboxid).appendChild(option);
	}	
	
}

function addMyPlayer(boxidPL,boxidSP,roundid,StrNoPly,StrSelTea,StrSelPly)
{
	resetMYPErrorMessages();
	if(document.getElementById(boxidSP).options.length==5)
	{
		document.getElementById('Error5p').style.display='';
		return;
	}
	if(document.getElementById(boxidPL).selectedIndex < 2)
	{
		document.getElementById('ENPS').style.display='';
		return;
	}
	
	var addPL=document.getElementById(boxidPL)[document.getElementById(boxidPL).selectedIndex].value;
	var expires = new Date();
	var onyear = expires.getTime() + 31536000000;
	expires.setTime(onyear);
	if(myp1==0)
	{
		setCookie('CMP1'+roundid,addPL,expires,'/');			
	}
	else if(myp2==0)
	{
		setCookie('CMP2'+roundid,addPL,expires,'/');			
	}
	else if(myp3==0)
	{
		setCookie('CMP3'+roundid,addPL,expires,'/');					
	}
	else if(myp4==0)
	{
		setCookie('CMP4'+roundid,addPL,expires,'/');					
	}
	else if(myp5==0)
	{
		setCookie('CMP5'+roundid,addPL,expires,'/');					
	}

	loadPlayerCookie();
	fillPlayersSelectMYP(document.getElementById('selectTeams')[document.getElementById('selectTeams').selectedIndex].value,'selectPlayers',StrNoPly,StrSelTea,StrSelPly);
	fillSelectedPlayers('playerChange');
}

function removeMYPlayer(boxid,roundid,StrNoTea,StrSelTea)
{
	resetMYPErrorMessages();	
	if(document.getElementById(boxid).selectedIndex == -1)
	{
		document.getElementById('ENPS').style.display='';
		return;
	}
	var remPL=document.getElementById(boxid)[document.getElementById(boxid).selectedIndex].value;
	var expires = new Date();
	var onyear = expires.getTime() + 31536000000;
	expires.setTime(onyear);
	var replacePlayer = false;
	if(myp1==remPL)
	{
		setCookie('CMP1'+roundid,myp2,expires,'/');
		replacePlayer=true;
	}
	if(myp2==remPL || replacePlayer)
	{
		setCookie('CMP2'+roundid,myp3,expires,'/');		
		replacePlayer=true;
	}
	if(myp3==remPL || replacePlayer)
	{
		setCookie('CMP3'+roundid,myp4,expires,'/');					
		replacePlayer=true;
	}
	if(myp4==remPL || replacePlayer)
	{
		setCookie('CMP4'+roundid,myp5,expires,'/');					
		replacePlayer=true;		
	}
	if(myp5==remPL || replacePlayer)
	{
		setCookie('CMP5'+roundid,0,expires,'/');					
	}
	
	loadPlayerCookie();
	fillTeamSelectMYP('selectTeams',StrNoTea,StrSelTea);
	fillSelectedPlayers('playerChange');
	
}
/*****************************************************
* Resets (=hides) the errormessages in Myplayermodule*
*****************************************************/
function resetMYPErrorMessages()
{
	document.getElementById('Error5p').style.display='none';
	document.getElementById('ENPS').style.display='none';
}

function checkPlayerExists(roundid,first)
{
	var expires = new Date();
	var onyear = expires.getTime() + 31536000000;
	expires.setTime(onyear);
	var exists1 = false;
	if (myp1 == 0)
	exists1 = true;
	var exists2 = false;
	if (myp2 == 0)
	exists2 = true;	
	var exists3 = false;
	if (myp3 == 0)
	exists3 = true;	
	var exists4 = false;
	if (myp4 == 0)
	exists4 = true;	
	var exists5 = false;	
	if (myp5 == 0)
	exists5 = true;	
	for (var playeri = 0; playeri < MyPlayListArray.player_List.length; playeri++)
	{
		if(MyPlayListArray.player_List[playeri].pID == myp1)
		{
			exists1= true;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp2)
		{
			exists2= true;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp3)
		{
			exists3= true;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp4)
		{
			exists4= true;
		}
		if(MyPlayListArray.player_List[playeri].pID == myp5)
		{
			exists5= true;
		}
	}

		if(exists1==false)
		{
			setCookie('CMP1'+roundid,myp2,expires,'/');
			setCookie('CMP2'+roundid,myp3,expires,'/');	
			setCookie('CMP3'+roundid,myp4,expires,'/');	
			setCookie('CMP4'+roundid,myp5,expires,'/');			
			setCookie('CMP5'+roundid,0,expires,'/');
			myp1=myp2;
			myp2=myp3;
			myp3=myp4;
			myp4=myp5;
			myp5=0;			
			checkPlayerExists(roundid,false);
		}
		if(exists2==false && exists1)
		{
			setCookie('CMP2'+roundid,myp3,expires,'/');	
			setCookie('CMP3'+roundid,myp4,expires,'/');	
			setCookie('CMP4'+roundid,myp5,expires,'/');			
			setCookie('CMP5'+roundid,0,expires,'/');
			myp2=myp3;
			myp3=myp4;
			myp4=myp5;
			myp5=0;			
			checkPlayerExists(roundid,false);

		}
		if(exists3==false && exists1 && exists2)
		{
			setCookie('CMP3'+roundid,myp4,expires,'/');	
			setCookie('CMP4'+roundid,myp5,expires,'/');			
			setCookie('CMP5'+roundid,0,expires,'/');
			myp3=myp4;
			myp4=myp5;
			myp5=0;			
			checkPlayerExists(roundid,false);
		}
		if(exists4==false && exists1 && exists2 && exists3)
		{
			setCookie('CMP4'+roundid,myp5,expires,'/');			
			setCookie('CMP5'+roundid,0,expires,'/');
			myp4=myp5;
			myp5=0;			
			checkPlayerExists(roundid,false);
		}
		if(exists5==false && exists1 && exists2 && exists3 && exists4)
		{
			setCookie('CMP5'+roundid,0,expires,'/');		
			myp5=0;
		}
		if(first && (exists5==false || exists1 ==false || exists2 ==false || exists3 ==false || exists4 ==false))
		{
			loadPlayerCookie();
		}
}

function show_hide_PlayerCharts_SubElements(Name)
{
	 $$('tr.'+Name).each(
		function(item)
		{
			item.toggle();
		}
	);
}

function ie6TransparancyWorkAround(Name)
{
		$$('img.'+Name).each(
		function(item)
		{
			item.src = item.name;
		}
	);
}

/*
function convertHeight_PlayerCharts()
{
		 $$('td.PLHeight').each(
		function(item)
		{
			item.innerHTML = convertHeight(item.innerHTML);
		}
	);
}

function convertHeight(height)
{
	if(height != '')
	{
		 if (parseFloat(height) < 3)
		 	height =parseFloat(height)*100;
		else 
			if(height.search('\'')!=-1)
			 {
				 height = height.replace(',','.');
				 height = Math.floor(parseFloat(height)) * 2.54 * 12 + parseFloat(height)-Math.floor(parseFloat(height))*2.54;
			 }
		height=parseInt(height);
	}
	return height;
}*/
