var lastRoundJeugd     = 19;
var lastRoundSenioren  = 21;
var lastPeriodSenioren = 3;

function logVisitor() {
  if (document.images) {
	img1 = new Image();
	img1.src = 'http://www.amstelschaak.nl/php/logvisitor.php?wdt=' + screen.width + '&hgt=' + screen.height;
  } 
  document.location.href = 'home.html';
}

function start() {
  if (document.images) {
	img1 = new Image();
	img1.src = 'http://www.amstelschaak.nl/php/logvisitor.php?wdt=' + screen.width + '&hgt=' + screen.height;
  } 
}

function init(title) {
  if (document.images) {
	img1 = new Image();
	img1.src = "http://www.amstelschaak.nl/php/asp.php?" + document.URL;
  } 

  if (top.location.href == self.location.href) {
	top.location.href = '/index.html';
  } else {
	parent.frames['title'].document.getElementById('title').innerHTML = title;
  }
}

function setLastRoundJeugd() {
  if (lastRoundJeugd<10) {
	document.location.href = 'competitie_ronde0' + lastRoundJeugd + '.html';
  } else {
	document.location.href = 'competitie_ronde' + lastRoundJeugd + '.html';
  }
}

function setLastRoundSenioren() {
  if (lastRoundSenioren<10) {
	document.location.href = 'competitie_ronde0' + lastRoundSenioren + '.html';
  } else {
	document.location.href = 'competitie_ronde' + lastRoundSenioren + '.html';
  }
}

function setNavJeugd(current,total) {
  var html = '<table class="border" cellspacing="0"><tr>';
  for (var i=1; i<=total; i++) {
	if (i == current) {
	  html += '<td class="curnav">' + i + '</td>';
	} else if (i <= lastRoundJeugd) {
	  html += '<td class="nav"><a href="competitie_ronde';
	  if (i<10) {
		html += '0';
	  }
	  html += i + '.html">' + i + '</a></td>';
	} else {
	  html += '<td class="disnav">' + i + '</td>';
	}
  }
  html += '</tr></table>';
  document.getElementById('navbar').innerHTML = html;
}

function setNavSenioren(current,total) {
  var html = '<table class="border" cellspacing="0"><tr>';
  if (current == -1) {
	html += '<td class="curnav" rowspan="2">Statistieken</td>';
  } else { 
	html += '<td class="prompt" rowspan="2"><a href="statistieken.html">Statistieken</a></td>';
  }
  for (var i=1; i<=total; i++) {
	if (i == current) {
	  html += '<td class="curnav">' + i + '</td>';
	} else if (i <= lastRoundSenioren) {
	  html += '<td class="nav"><a href="competitie_ronde';
	  if (i<10) {
		html += '0';
	  }
	  html += i + '.html">' + i + '</a></td>';
	} else {
	  html += '<td class="disnav">' + i + '</td>';
	}
  }
  if (current == 0) {
	html += '<td class="curnav" rowspan="2">Historie</td>';
  } else { 
	html += '<td class="prompt" rowspan="2"><a href="historie.html">Historie</a></td>';
  }
  html += '</tr></table>';
  document.getElementById('navbar').innerHTML = html;
}

function setNavArchiefJeugd(min,current,max) {
  var html = '<table class="border" cellspacing="0"><tr>';
  for (var i=min; i<=max; i++) {
	if (i == current) {
	  html += '<td class="curnav">' + i + '</td>';
	} else {
	  html += '<td class="nav"><a href="competitie_ronde';
	  if (i<10) {
		html += '0';
	  }
	  html += i + '.html">' + i + '</a></td>';
	}
  }
  html += '</tr></table>';
  document.getElementById('navbar').innerHTML = html;
}

function setNavArchiefSenioren(min,current,max) {
  var html = '<table class="border" cellspacing="0"><tr>';
  if (current == -1) {
	html += '<td class="curnav" rowspan="2">Statistieken</td>';
  } else { 
	html += '<td class="prompt" rowspan="2"><a href="statistieken.html">Statistieken</a></td>';
  }
  for (var i=min; i<=max; i++) {
	if (i == current) {
	  html += '<td class="curnav">' + i + '</td>';
	} else {
	  html += '<td class="nav"><a href="competitie_ronde';
	  if (i<10) {
		html += '0';
	  }
	  html += i + '.html">' + i + '</a></td>';
	}
  }
  if (current == 0) {
	html += '<td class="curnav" rowspan="2">Historie</td>';
  } else { 
	html += '<td class="prompt" rowspan="2"><a href="historie_periode1.html">Historie</a></td>';
  }
  html += '</tr></table>';
  document.getElementById('navbar').innerHTML = html;
}

function createCenteredWindow(url,width,height)
{
  var xOffset,yOffset;
  var xMax,yMax;
  var popupWindow;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = 
	'width=' + width + ',height=' + height + 
	',left=' + left + ',top=' + top + 
	',screenX=' + left + ',screenY=' + top + 
	',scrollbars=yes,resizable';

  if (popupWindow != null) {
	popupWindow.close();
  }
  popupWindow = window.open(url, 'PopupWindow', windowFeatures);
  popupWindow.focus();
  return false;
}

function createCenteredImageWindow(text,url,width,height)
{
  var xOffset,yOffset;
  var xMax,yMax;
  var popupWindow;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = 
	'width=' + width + ',height=' + height + 
	',left=' + left + ',top=' + top + 
	',screenX=' + left + ',screenY=' + top;

  if (popupWindow != null) {
	  popupWindow.close();
  }
  popupWindow = window.open('', 'PopupWindow', windowFeatures);
  var page='<html><head><title>'+text+'</title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><img src="'+url+'"></body></html>';
  popupWindow.document.open();
  popupWindow.document.write(page);
  popupWindow.document.close();
  popupWindow.focus();
  return false;
}

function playMedia(url)
{
  var xOffset,yOffset;
  var xMax,yMax;
  var popupWindow;
  var width=200;
  var height=40;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = 
	'width=' + width + ',height=' + height + 
	',left=' + left + ',top=' + top + 
	',screenX=' + left + ',screenY=' + top + 
	',status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=0,resizable=0';

  if (popupWindow != null) {
	popupWindow.close();
  }
  popupWindow = window.open(url, 'PopupWindow', windowFeatures);
  popupWindow.focus();
  return false;
}

function setOpacity(objectId, opacity)
{
  var object = document.getElementById(objectId);
  if (!object) {
	object = top.document.getElementById(objectId);
  }
  if (object && object.style) {
	if (navigator.userAgent.indexOf("Firefox") != -1) {
	  if (opacity == 100) { opacity = 99.9999; }
	}
	object.style.opacity = (opacity / 100);
	object.style.MozOpacity = (opacity / 100);
	object.style.KhtmlOpacity = (opacity / 100);
	object.style.filter = 'alpha(opacity=' + opacity + ')';
  }
}

function changeOpacity(objectId, startValue, endValue, milliSec)
{
  var speed = Math.round(milliSec / 100);
  var timer = 0;

  if (startValue > endValue) {
	for (var i = startValue; i >= endValue; i--) {
	  setTimeout("setOpacity('" + objectId + "'," + i + ")",(timer * speed));
	  timer++;
	}
  } else if (startValue < endValue) {
	for (var i = startValue; i <= endValue; i++) {
	  setTimeout("setOpacity('" + objectId + "'," + i + ")",(timer * speed));
	  timer++;
	}
  }
}

function fadeIn(objectId, milliSec)
{
  changeOpacity(objectId, 0, 100, milliSec);
}

function fadeOut(objectId, milliSec)
{
  changeOpacity(objectId, 100, 0, milliSec);
}

function generateUniqueId()
{
  var newDate = new Date();
  return newDate.getTime();
}

function showHistorieLid(id, containerid)
{
  var container = document.getElementById(containerid);
  if (!container) { return; }

  Utils.removeChildrenFromNode(container);
  var table = Utils.addTableToNode(container);

  var uitslagen = res[id];

  for (var i=1; i<uitslagen.length; i++) {
	if (uitslagen[i][0] == 'BYE') {
	  var cells = Utils.addCellsToTable(table, 3);
	  cells[0].innerHTML = i;
	  cells[1].innerHTML = rnd[i];
	  cells[2].innerHTML = '<b>-- oneven --</b>';
	  cells[2].colSpan = '4';
	} else if (uitslagen[i][0] == 'EXT') {
	  var cells = Utils.addCellsToTable(table, 3);
	  cells[0].innerHTML = i;
	  cells[1].innerHTML = rnd[i];
	  cells[2].innerHTML = '<b>-- extern --</b>';
	  cells[2].colSpan = '4';
	} else if (uitslagen[i][0] == 'AFW') {
	  var cells = Utils.addCellsToTable(table, 3);
	  cells[0].innerHTML = i;
	  cells[1].innerHTML = rnd[i];
	  cells[2].innerHTML = '<b>-- afwezig --</b>';
	  cells[2].colSpan = '4';
	} else if (uitslagen[i][0] == 'NBS') {
	  var cells = Utils.addCellsToTable(table, 3);
	  cells[0].innerHTML = i;
	  cells[1].innerHTML = rnd[i];
	  cells[2].innerHTML = '<b>-- niet gespeeld buiten schuld --</b>';
	  cells[2].colSpan = '4';
	} else  {
	  var cells = Utils.addCellsToTable(table, 6);
	  cells[0].innerHTML = i;
	  cells[1].innerHTML = rnd[i];
	  cells[3].innerHTML = ' - ';
	  if (uitslagen[i][1] == 'W') {
		cells[2].innerHTML = '<i>' + lid[id] + '</i>';
		cells[4].innerHTML = lid[uitslagen[i][0]];
		if (uitslagen[i][2] == '1') {
		  cells[5].innerHTML = '1 - 0';
		} else if (uitslagen[i][2] == '2') {
		  cells[5].innerHTML = '0 - 1';
		} else if (uitslagen[i][2] == '3') {
		  cells[5].innerHTML = '&frac12; - &frac12;';
		}
	  } else {
		cells[2].innerHTML = lid[uitslagen[i][0]];
		cells[4].innerHTML = '<i>' + lid[id] + '</i>';
		if (uitslagen[i][2] == '1') {
		  cells[5].innerHTML = '0 - 1';
		} else if (uitslagen[i][2] == '2') {
		  cells[5].innerHTML = '1 - 0';
		} else if (uitslagen[i][2] == '3') {
		  cells[5].innerHTML = '&frac12; - &frac12;';
		}
	  }
	  cells[3].align = 'center';
	  cells[5].align = 'center';
	}
	cells[0].width = '20';
	cells[0].align = 'right';
	cells[1].width = '100';
	cells[1].align = 'center';

	if ((i % 2) == 0) {
	  cells[0].parentNode.className = 'even';
	} else {
	  cells[0].parentNode.className = 'odd';
	}
  }
}

