var gameID;
var vitoftoday = 0;
var maxpage;
var minpage = 0;
var question = "";
var fenPosition = "";
var solution = "";
var oplossing = "";
var witspeler = "";
var zwartspeler = "";
var place = "";
var date = "";
var wieaanzet;
var huidgeZet = "";
var days = new Array(31,59,90,120,151,181,212,243,273,304,334,365);
var gameloaded = 0;
var flitsisloaded = false;
var oldMove = null;
var oldClassname = "";
var bord;

function Board_DoFSCommand(command, args)
{
	switch (command)
	{
		case "Load":
			this.Board_Load();
			break;
		case "COMMAND_PLAYMOVE":
			this.byFlash(args);
			break;
	}
}
	
function Board_Load()
{
	this.bord = MOZILLA ? document.Board : this.GetElementByID("Board");
	this.Board_SetCommandParameter("EscapeQuotes", MOZILLA ? "True" : "False");
}
function Board_ExecuteCommand(command)
{
	this.bord.SetVariable("Command", command);
}
function Board_SetCommandParameter(paramName, paramValue)
{
	this.bord.SetVariable(paramName, paramValue);
}

// Look for Internet Explorer.
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
//
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1)
{
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub Board_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call Board_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</script\> \n');
}
function show(a,b)
{
	if(this.bord == null)
	{
		this.Board_Load();
		return;
	}
	if(oldMove != null)
	{
		oldMove.className = oldClassname;
		
	}
	else
	{
		oldMove = GetElementByID("move1");
		//location.href = "?#" + "move1"; 
	}
	this.Board_SetCommandParameter("FenPosition", b);
	this.Board_ExecuteCommand("ViewPosition");
	oldMove = a;
	oldClassname = a.className;
	//location.href = "?#" + a.id;
	a.className = "e0Selected";
}

function InitTable()
{
	oldMove = GetElementByID("move0");
	//location.href = "?#" + "move0";
}	
function byFlash(keyCode)
{
	if(this.bord == null)
	{
		this.Board_Load();
		return;
	}
	if(keyCode == "0") keyCode = -5555;
	if(oldMove != null)
	{
		oldMove.className = oldClassname;
	}
	else
	{
		oldMove = GetElementByID("move1");
		
	}
	if(oldMove != null)	b = oldMove.id.substring(4);
	else b = "0";
	showPostition(checKeystroke(keyCode,b))
}
function showKey()
{
	if(oldMove != null)
	{
		oldMove.className = oldClassname;
	}
	a = 0;
	switch(event.keyCode)
	{
		case 35 : a = 5555;
			break;
		case 36: a = -5555;
			break;
		case 37: a = -1;
			break;
		case 33:
		case 38: a = -5;
			break;
		case 39: a = 1;
			break;
		case 34:
		case 40: a = 5;
			break;

	}
    
	if(a == 0) return;
	if(oldMove != null)	b = oldMove.id.substring(4);
	else b = "0";
	showPostition(checKeystroke(a,b))
}
function checKeystroke(a,b)
{
	f = Math.floor(a) + Math.floor(b);
	if(f<1) 
	{
		show(this,'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0 ');
		return 0;
	}
	for(i=2;i<=f;i++)
	{
		c = "move"+i;
		if(GetElementByID(c) == null)
		{
			if(i==2) return f-1;
			return i-1;
		}
	}
	return f; 
}
function showPostition(a)
{
	if(oldMove != null)
	{
		oldMove.className = oldClassname;
	}
	f = Math.floor(a);
	c = "move"+f;
	if(GetElementByID(c) != null)
	{
		d = GetElementByID(c);
		e = this.GetElementByID("m"+f);
		if(f>0)
		{
		this.Board_SetCommandParameter("FenPosition", e.value);
		this.Board_ExecuteCommand("ViewPosition");
		}
		oldMove = d;
		oldClassname = d.className;
		d.className = "e0Selected";
		d.focus();
		//location.href = "?#" + c;
		var f = this.GetElementByID("gameContainer");
		f.scrollTop = d.offsetTop;
	}
}
var lastGame = "Game1"

function selektGame()
{
	var gamemenu = this.GetElementByID("selektID");
	var value = gamemenu.options[gamemenu.selectedIndex].value;
	var gameindex = this.GetElementByID(lastGame);
	gameindex.style.display = "none";
	var nextgame = this.GetElementByID(value);
	nextgame.style.display = "";
	lastGame = value;
	show(this,'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0 ');
}

