var TableText;  //Used to save the HTML for the table layout

function ShowGameDiagram(board,spanid){
	var s;
	s=document.getElementById(spanid);
	s.innerHTML=ShowSmallBoard(board);
}

function ShowFollowedGamesAsTable(){
	var span=document.getElementById('FollowedGames');
	span.innerHTML=TableText;
	span=document.getElementById("FollowedGamesSelector");
	span.innerHTML="<a href='javascript:ShowFollowedGamesAsDiagrams()'>Diagram</a>";
}

function LoadGame(id){
	document.location='viewgame.cgi?p1='+id;
}

function ShowFollowedGamesAsDiagrams(){
	var i,game,text,data;
	var MaxColumns=4;
	var span=document.getElementById('FollowedGames');
	TableText=span.innerHTML;

	text="<table border=0 cellspacing=0 cellpadding=0><tr>";

   i=1;
   game=document.getElementById('FollowedGame'+i);
	while(game!=null){
		data=game.value.split("|");
		text+="<td><span onClick='javascript:LoadGame(\""+data[4]+"\");' style='cursor:pointer'>";
		text+="<table border=1 bgcolor='#990000'><tr><td><table border=0 cellspacing=0 cellpadding=0 bgcolor='#ddddbb'><tr><td align=center>";
		if(data[2]=='black'){
			text+="<b>"+data[1]+"</b>";
		} else {
			text+=data[1];
		}
		text+="</td><tr><td>"+ShowSmallBoard(data[3])+"</td></tr><tr><td align=center>";
		if(data[2]=='white'){
			text+="<b>"+data[0]+"</b>";
		} else {
			text+=data[0];
		}
		text+="</td></tr></table></td></tr></table>\n";
		i++;
		game=document.getElementById('FollowedGame'+i);
		if(i%(MaxColumns+1)==0){
			text+="</tr><tr>";
		}
	}
	text+="</tr></table>";
	span.innerHTML=text;
	span=document.getElementById("FollowedGamesSelector");
	span.innerHTML="<a href='javascript:ShowFollowedGamesAsTable()'>Table</a>";
}

