function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}
function joins(A)
{
	return openWindow("competitions.php?"+SESSIONURL+"do=viewteamjoins&id="+A,230,300)
}
function wins(A)
{
	return openWindow("competitions.php?"+SESSIONURL+"do=viewteamwins&id="+A,230,300)
}
function deletetmnt(id, title) 
{
	if (confirm("Are you sure you want to delete '" + title + "'")) {
		window.location.href = 'tournaments.php?do=kill&id=' + id;
	}
}
function deleteteam(id) 
{
	if (confirm("Are you sure you want to delete this team?")) {
		window.location.href = 'competitions.php?do=killteam&id=' + id;
	}
}
function deleteann(id) 
{
	if (confirm("Are you sure you want to delete this announcement?")) {
		window.location.href = 'competitions.php?do=killann&id=' + id;
	}
}
function deletecat(id) 
{
	if (confirm("Are you sure you want to delete this category?")) {
		window.location.href = 'competitions.php?do=killcategory&catid=' + id;
	}
}
function jointeam(id) 
{
	if (confirm("Are you sure you want to join this team?")) {
		window.location.href = 'competitions.php?do=reqjointeam&id=' + id;
	}
}
function rejectrecruit(id) 
{
	if (confirm("Are you sure you want to reject this recruit?")) {
		window.location.href = 'competitions.php?do=rejectrecruit&id=' + id;
	}
}
function confirmrecruit(id) 
{
	if (confirm("Are you sure you want to confirm this recruit?")) {
		window.location.href = 'competitions.php?do=confirmrecruit&id=' + id;
	}
}
function deleteplayer(id, tid, userid) 
{
	if (confirm("Are you sure you remove this player from this tournament?")) {
		window.location.href = 'tournaments.php?do=killplayer&id=' + id + '&tid=' + tid + '&userid=' + userid;
	}
}
function deleteteamplayer(id) 
{
	if (confirm("Are you sure you want to remove this player from your team?")) {
		window.location.href = 'competitions.php?do=killteamplayer&id=' + id;
	}
}
function makeleader(id) 
{
	if (confirm("Are you sure you want to make this team member a leader?")) {
		window.location.href = 'competitions.php?do=makeleader&id=' + id;
	}
}
function leaveteam(id) 
{
	if (confirm("Are you sure you want to leave this team?")) {
		window.location.href = 'competitions.php?do=leaveteam&teamid=' + id;
	}
}
function makecoleader(id) 
{
	if (confirm("Are you sure you want to make this team player a co-leader?")) {
		window.location.href = 'competitions.php?do=makecoleader&id=' + id;
	}
}
function deletecomment(id, tid, userid) 
{
	if (confirm("Are you sure you want to delete this comment?")) {
		window.location.href = 'tournaments.php?do=killcomment&id=' + id + '&tid=' + tid +'&userid=' + userid;
	}
}
function finishtmnt(id, title, topscore) 
{
	if (confirm("Are you sure you want to finish '" + title + "'")) {
		window.location.href = 'tournaments.php?do=finish&id=' + id + '&topscore=' + topscore;
	}
}
function progress(id, userid, username, round, slot) 
{
	if (confirm("Are you sure you want to progress '" + username + "' to next round?")) {
		window.location.href = 'tournaments.php?do=progress&id=' + id + '&userid=' + userid + '&round=' + round + '&slot=' + slot;
	}
}
function regress(id, userid, username, round) 
{
	if (confirm("Are you sure you want to regress '" + username + "' to previous round?")) {
		window.location.href = 'tournaments.php?do=progress&id=' + id + '&userid=' + userid + '&round=' + round + '&slot=0';
	}
}
function progressfinish(id, userid, username, round, slot) 
{
	if (confirm("Are you sure you want to progress '" + username + "' to next round?")) {
		window.location.href = 'tournaments.php?do=progressfinish&id=' + id + '&userid=' + userid + '&round=' + round + '&slot=' + slot;
	}
}
function showhide(value, divid)
{
	if (value=="1") {
		document.getElementById(divid).style.display=""
	}
	if (value=="0")
	{
		document.getElementById(divid).style.display="none"
	}
}

function editscore(id, tid)
{ 
 var score=document.getElementById("cmpt_"+id).innerHTML;
 score=parseInt(score);
if (score=="")
 {
 score="0";
 }
 document.getElementById("cmpt_"+id).innerHTML='<input type="text" value="'+score+'" id="score_'+id+'" onblur="savescore('+id+', '+tid+')" />';
}

function getelo()
{
	var rank_u = document.getElementById('rank_u').value;
	rank_u = parseInt(rank_u);
	var k = document.getElementById('kvalue').value;
	k = parseInt(k);
	var rank_ub = document.getElementById('rank_ub').value;
	rank_ub = parseInt(rank_ub);
	var score_u = document.getElementById('score_u').value;
	score_u = parseInt(score_u);
	var score_ub = document.getElementById('score_ub').value;
	score_ub = parseInt(score_ub);
	var dr = parseInt(rank_u - rank_ub);
	var power = - dr / 400;
	if (rank_u > rank_ub)
	{
		var we_u = 1/(Math.pow(10,power)+1); 
		var we_ub = 1-(1/(Math.pow(10,power)+1));
	}
	else
	{
		var we_u = 1-(1/(Math.pow(10,(-dr/400))+1)); 
		var we_ub = 1/(Math.pow(10,(-dr/400))+1);
	}
	if (score_u > score_ub)
	{
		 if (rank_u > rank_ub) 
		 {
		 	var w_u = 0.5; 
		 	var w_ub = -0.5; 
		 }
		 else if (rank_u == rank_ub) 
		 {
		 	var w_u = 0.5; 
		 	var w_ub = -0.5; 
		 } 
		 else 
		 {
		 	var w_u = 1; 
		 	var w_ub = -0.5; 
		 }
	}
	else if (score_u == score_ub)
	{
		if (rank_u > rank_ub)
		{
		 	var w_u = -0.5; 
		 	var w_ub = 0.5; 
		 }
		 else if (rank_u == rank_ub) 
		 {
		 	var w_u = 0.5; 
		 	var w_ub = 0.5; 
		 }
		 else 
		 {
		 	var w_u = 0.5; 
		 	var w_ub = -0.5; 
		 }
	}
	else if (score_u < score_ub)
	{
		if (rank_u > rank_ub)
		{
		 	var w_u = -0.5; 
		 	var w_ub = 1; 
		 }
		 else if (rank_u == rank_ub)
		 {
		 	var w_u = -0.5; 
		 	var w_ub = 0.5; 
		 }
		 else
		 {
		 	var w_u = -0.5; 
		 	var w_ub = 0.5; 
		 }
	}
	var newrank_u  = rank_u + k * (w_u * we_u);
	var newrank_ub = rank_ub + k * (w_ub * we_ub);
	document.getElementById('newrank_u').value = newrank_u;
	document.getElementById('newrank_ub').value = newrank_ub;
}