function round(num,places) {
  var decPoint = ".";
  if (places > 0)  {
    if ((num.toString().length - num.toString().lastIndexOf(".")) > (places + 1)) {
      var rounder = Math.pow(10, places);
      num = Math.round(num * rounder) / rounder;
    }
    num = num.toString();
    if (num.indexOf(".") == -1) {
      num = num + decPoint;
    }
    if ((num.length - num.lastIndexOf('.')) < (places + 1)) {
      for (var i=num.length-num.lastIndexOf('.');i<(places+1);i++) {
        num = num + zero;
      }
    }
    return num;
  }
  else return Math.round(num);
}

function calcPoints(grade,opp,res) {
  var x=eval(grade);
  var y=eval(opp);
  if ( y > ( x + 40 )) y = x + 40;
  else if ( y < ( x - 40 )) y = x - 40;
  return ( y + (( 1 - res ) * 50 ));
}

function displayHalves(num) {
  var numHalf=0;
  var numScore=0;
  numHalf = (( num * 2 ) % 2 );
  numScore = ((( num * 2 ) - numHalf) / 2 );
  if (numHalf > 0) {
    if (numScore == 0 ) numScore="";
    numScore = numScore + half;
  }
  return numScore;
}

function show_game(season,gameNo,colours) {
  var pgnFile="000";
  pgnFile=pgnFile+gameNo;
  pgnFile=pgnFile.substring(pgnFile.length-4,pgnFile.length)+".pgn";
  var winopts = "height=560, width=630, toolbar=no, location=no, directories=no,status=no, menubar=no, resizable=no, left=5, top=5";
  okno=window.open("", "okno", winopts);
  okno.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html lang="en">');
  okno.document.write('<title>'+season+' | Game No.'+gameNo+'</title>');
  okno.document.write('</head><body leftmargin=0 topmargin=0 rightmargin=0 marginheight=0 marginwidth=0>');
  okno.document.write('<APPLET code=ChessBoard.class codebase="previous/viewer/" align=baseline width=730 height=560>');
  okno.document.write('<PARAM name=pgngamefile value=../viewer/'+season+'/'+pgnFile+'>');
  /*default or 0        Green */
  if (colours == 1)  /* OlimpBase */ {okno.document.write('<PARAM name=lightSquares value=FDEB94>');
                                      okno.document.write('<PARAM name=darkSquares value=D48C1A>');
                                      okno.document.write('<PARAM name=background value=7D380C>'); }
  if (colours == 2)  /* Grey  */     {okno.document.write('<PARAM name=lightSquares value=ffffff>');
                                      okno.document.write('<PARAM name=darkSquares value=666666>');
                                      okno.document.write('<PARAM name=background value=999999>'); }
  if (colours == 3)  /* Brown */     {okno.document.write('<PARAM name=lightSquares value=ffff99>');
                                      okno.document.write('<PARAM name=darkSquares value=cc6600>');
                                      okno.document.write('<PARAM name=background value=cc9966>'); }
  if (colours == 4)  /* Blue  */     {okno.document.write('<PARAM name=lightSquares value=9EC2EF>');
                                      okno.document.write('<PARAM name=darkSquares value=1474A3>');
                                      okno.document.write('<PARAM name=background value=0E5172>'); }
  if (colours == 5)  /* Orange */    {okno.document.write('<PARAM name=lightSquares value=9EC2EF>');
                                      okno.document.write('<PARAM name=darkSquares value=1474A3>');
                                      okno.document.write('<PARAM name=background value=0E5172>'); }
  okno.document.write('</APPLET></body></html>');
}

