var playerList=new Array();

function checkVote(thisinput, totCount) {
  var count=0;
  for (var j=0;j<thisinput.length; j++) {
    if (thisinput[j].checked) {count++;}
  }
  if (count<=totCount) {return true;}
  alert('Your '+count+' votes exceed the maximum of '+totCount+' votes allowed.');
  return false;
}

function updBallot(fromElem,toElem) {
  var x,count=0,txt="",pid;

  var toElemObj=document.getElementById(toElem);

  x=document.getElementsByName(fromElem);

  if (x.length>0) {
	  for (var i=0;i<x.length;i++) {
		  if (x[i].checked==1)
		  {
			  if (txt!="") {txt+="<br/>";}
			  pid=x[i].value;
			  txt+="<a href='#pid"+pid+"'>"+playerList[pid]+"</a>";
			  txt+=" (<a onclick=\"remVote("+pid+",'"+fromElem+"');updBallot('"+fromElem+"','"+toElem+"');\" href='javascript:void(0);' title='Remove from ballot'>remove</a>)";
			  count++;
		  }
	  }
  }

  if (count==0) {txt="0 players";}
  else {
	  txt+="<br/><br/>"+count+" player";
	  if (count>1) {txt+="s";}
  }

  toElemObj.innerHTML=txt;
}

function remVote(pid,toElem) {
  x=document.getElementsByName(toElem);

  if (x.length>0) {
	  for (var i=0;i<x.length;i++) {
		  if (x[i].value==pid) {x[i].checked=0;}
	  }
  }

}
