<!--
 var tMenu  = "<Table Align='Left' VAlign='Top' Border='0' Cellspacing='0' Cellpadding='2' Height='100%'>";
     tMenu += "<Td>";
     tMenu += "<Table Align='Center' VAlign='Middle' Border='0' Cellspacing='0' Cellpadding='0'><Tr>";
     tMenu += "<Form Name='command'>";
     tMenu += "<Td Align='Center' Valign='Middle' BgColor='#ffffe5' Width='"+(blockSize*10)+"' Height='"+(blockSize*4-4)+"'>";
     tMenu += "<Table Border='1' CellSpacing='0' CellPadding='0' BgColor='#cccccc' Width='70%' Height='100%'><Tr><Td>";
     tMenu += "<Table Border='0' CellSpacing='0' CellPadding='1' Width='100%'><Tr><Td Align='Center'>";
     tMenu += "<Input Type='button' Name='start' Value='&nbsp;Start&nbsp;' onClick='startClear();'><Input Type='button' Name='menu' Value='Menu' onClick='dspMenu()'>";
     tMenu += "</Td></Tr><Tr><Td Align='Center'>";
     tMenu += "<Input Type='button' Name='highScore' Value='High Score' onClick='showHighScore()'>";
     tMenu += "</Td></Tr></Table></Td></Tr></Table></Td></Form></Tr>";
     tMenu += "<Tr><Td Align='Center' Valign='Middle' Width='"+(blockSize*10)+"' Height='"+(blockSize*20)+"'>";

 var eMenu = "</Td></Tr></Table></Td></Table>";
 var bMenu = "";
 var oMenu = "";
 var bGround;

 var blockImage = new Array()
     blockImage[0] = new Image( blockSize,blockSize );  blockImage[0].src = 'tetris/Grey.gif';
     blockImage[1] = new Image( blockSize,blockSize );  blockImage[1].src = 'tetris/Yellow.gif';
     blockImage[2] = new Image( blockSize,blockSize );  blockImage[2].src = 'tetris/Purple.gif';
     blockImage[3] = new Image( blockSize,blockSize );  blockImage[3].src = 'tetris/Blue.gif';
     blockImage[4] = new Image( blockSize,blockSize );  blockImage[4].src = 'tetris/Green.gif';
     blockImage[5] = new Image( blockSize,blockSize );  blockImage[5].src = 'tetris/Red.gif';
     blockImage[6] = new Image( blockSize,blockSize );  blockImage[6].src = 'tetris/Turquoise.gif';
     blockImage[7] = new Image( blockSize,blockSize );  blockImage[7].src = 'tetris/blank.gif';

 var block = new Array(7);
     block[0] = new Array( '11202122','11202131','20212231','11212231' );
     block[1] = new Array( '11213132','12202122','10112131','20212230' );
     block[2] = new Array( '11213031','20212232','11122131','10202122' );
     block[3] = new Array( '11212232','11122021','11212232','11122021' );
     block[4] = new Array( '11202130','10112122','11202130','10112122' );
     block[5] = new Array( '01112131','20212223','01112131','20212223' );
     block[6] = new Array( '10112021','10112021','10112021','10112021' );

 var introBlock = new Array(7);
     introBlock[0] = new Array( 'W4X3X4X5' );
     introBlock[1] = new Array( 'S0T0U0U1' );
     introBlock[2] = new Array( 'F6F7F8G8' );
     introBlock[3] = new Array( 'W8W9X7X8' );
     introBlock[4] = new Array( 'F2G2G1H1' );
     introBlock[5] = new Array( 'Q9R9S9T9' );
     introBlock[6] = new Array( 'X0X1W0W1' );

 var fallTimer = null;
 var runTetris = false;
 var ended = false;
 var pauseActive = false;
 var pauseUsed = false;
 var inhibit = false;

 var level = 1;
 var roundTime = 500;
 var type = 0;
 var shape = 0;
 var nextType = 0;
 var nextShape = 0;
 var next = '';
 var current = '';
 var occupied = '';
 var dspPts = 0;
 var lines = 0;
 var prevLines = 0;
 var prevPnts = 0;
 var COLOR = 4;

function initTetris()
{
  if ( fallTimer != null ) { clearTimeout( fallTimer ); }
  if ( browser == 'N' ) { document.captureEvents( Event.KEYDOWN ); }
  document.onkeydown = keyBoardEvent;
  RtVal();
  highScore[highScore.length-1][0] = highScore.length-1;
  runTetris = false;
  ended = false;
  pauseActive = false;
  level = 1;
  roundTime = 500;
  type = 0;
  shape = 0;
  nextType = 0;
  nextShape = 0;
  fallTimer = null;
  clearStat();
  introduction();
  if ( dspScore ) { dspScore = false;  showHighScore(); }
}

function introduction()
{
 var i,j,k;
  clearScreen();
  if ( tetris && browser == 'N' ) { document.Back.visibility = "show"; }
  else if ( tetris ) { Back.style.visibility = "visible"; }
  showInfoLayer();
  for ( j = 0; j < introBlock.length; j++ ) {
    for( i = 0; i < introBlock[j][0].length; ) {
      putGameImage( introBlock[j][0].charAt(i++)+introBlock[j][0].charAt(i++), j ); }
    occupied += introBlock[j][0]; }
  displayStatusLine();
  inhibit = false;
  focus();
}

function showHighScore()
{
  if ( bMenu.indexOf( '>Score<' ) == -1 ) {
    inhibit = false;
    bMenu = "<Table Border='1' CellSpacing='2' CellPadding='0' BgColor='#cccccc'><Tr>";
    bMenu += "<Td Align='Center' VAlign='Middle' Width='"+( blockSize*9 )+"' Height='"+( blockSize*14 )+"'>";
    bMenu += "<Table Border='0' CellSpacing='0' CellPadding='0'><Tr><Form><Td>";
    bMenu += "<Pre><Font Class='GMenu' Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+size+"'><B>";
    bMenu += "\n<Font Color='#cccccc'>0</Font>Score<Font Color='#cccccc'>00</Font>Name\n\n";

    if ( highScore[0][1] != '' ) {
      var tmp = new Array(highScore.length-1);
      for ( i = 0; i < tmp.length; i++ ) { tmp[i] = highScore[i][2]; highScore[i][0] = -1; }
      tmp.sort(sortNumbers);
      for ( i = 0; i < tmp.length; i++ ) {
        if ( tmp[i].length < 6 ) {
          bMenu += "<Font Color='#cccccc'>";
          for ( j = tmp[i].length; j < 6; j++ ) { bMenu += '0'; }
          bMenu += "</Font>"; }
        for( j = 0; j < tmp.length; j++ ) {
          if ( tmp[i] != highScore[j][2] || highScore[j][0] != -1 ) { continue; }
          bMenu += "<A Href='javascript:showGameScore("+i+");' onMouseOver='display(\"<Font Color=Black><B>Show the complete statistics of the game "+highScore[j][1]+" played.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>";
          bMenu += tmp[i]+' &#0183; ';
          bMenu += highScore[j][1]+'</A><Br>';
          highScore[j][0] = i;
          break; }
      }
    }
    bMenu += "\n</B></Font>";
    bMenu += "<Center><Input Type='button' Name='back' Value='&nbsp;&nbsp;Cancel&nbsp;&nbsp;' onClick='showHighScore();'></Center>";
    bMenu += "</Pre></Td></Form></Tr>";
    bMenu += "</Table></Td></Tr></Table>"; }
  else {
    bMenu = oMenu;
    if ( oMenu.indexOf('ScoreList') != -1 ) inhibit = true; }
  showInfoLayer();
}

function sortNumbers( a,b )
{
  if ( a-b < 0 ) { return 1; }
  if ( browser != 'N' ) { return -1; }
  return
}

function fill(s,l)
{
  var s1 = '';
  if ( s.length < l ) {
    s1 += "<Font Color='#cccccc'>";
    for ( var i = s.length; i < l; i++ ) { s1 += '0'; }
    s1 += "</Font>"+s; }
  else { s1 = s; }
  return s1;
}

function showGameScore(game)
{
  var sh,sm,ss,eh,em,es;

  bGround = bMenu;
  displayStatusLine();
  for ( var i = 0; i < highScore.length; i++ ) { if ( highScore[i][0] == game ) { break; } }
  bMenu = "<Table Border='1' CellSpacing='2' CellPadding='0' BgColor='#cccccc'><Form><Tr>";
  bMenu += "<Td Align='Center' VAlign='Middle' Width='"+( blockSize*9 )+"' Height='"+( blockSize*19 )+"'>";
  bMenu += "<Table Border='0' CellSpacing='0' CellPadding='0'><Tr><Td>";
  bMenu += "<Pre><Font Class='GMenu' Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+String(parseInt(size))+"'><B>";
  bMenu += "Statistics "+highScore[i][1]+"\n\n";

  bMenu += "Score: "+highScore[i][2]+"\n";
  bMenu += "Levels: "+highScore[i][9]+" -> "+highScore[i][10]+"\n\n";

  bMenu += "Time info:\n"
  bMenu += "Date: "+highScore[i][11]+"\n";
  bMenu += "Started: "+highScore[i][12]+"\n";
  sh = parseInt( highScore[i][12].substring( 0,highScore[i][12].indexOf(':') ) );
  sm = parseInt( highScore[i][12].substring( highScore[i][12].indexOf(':')+1,highScore[i][12].lastIndexOf(':') ) );
  ss = parseInt( highScore[i][12].substring( highScore[i][12].lastIndexOf(':')+1, highScore[i][12].length ) );
  eh = parseInt( highScore[i][13].substring( 0,highScore[i][13].indexOf(':') ) );
  em = parseInt( highScore[i][13].substring( highScore[i][13].indexOf(':')+1,highScore[i][13].lastIndexOf(':') ) );
  es = parseInt( highScore[i][13].substring( highScore[i][13].lastIndexOf(':')+1, highScore[i][13].length ) );
  if ( es < ss ) { es += 60; em--; }
  ss = ( ss = es - ss ) < 10 ? '0'+String(ss) : String(ss);
  if ( em < sm ) { em += 60; eh--; }
  sm = ( sm = em - sm ) < 10 ? '0'+String(sm) : String(sm);
  if ( eh < sh ) { eh += 24; }
  sh = ( sh = eh - sh ) < 10 ? '0'+String(sh) : String(sh);
  bMenu += "Played: "+String(sh)+":"+String(sm)+":"+String(ss)+"\n";
  if ( highScore[i][8] == '' ) highScore[i][8] = '0';
  ss = Math.round( parseInt(highScore[i][8])/1000 );
  sh = ( sh = Math.round( ss/3600 )) < 10 ? '0'+String(sh) : String(sh);
  ss = Math.round( ss%3600 );
  sm = ( sm = Math.round( ss/60 )) < 10 ? '0'+String(sm) : String(sm);
  ss = ( ss = Math.round( ss%60 )) < 10 ? '0'+String(ss) : String(ss);
  bMenu += "Gained: "+sh+":"+sm+":"+ss+"\n\n";

  bMenu += "Lines Deleted:\n";
  bMenu += fill(highScore[i][3],4)+" Singel\n";
  bMenu += fill(highScore[i][4],4)+" Pair\n";
  bMenu += fill(highScore[i][5],4)+" Pair+One\n";
  bMenu += fill(highScore[i][6],4)+" Two Pair\n";
  bMenu += fill(highScore[i][7],4)+" Total\n\n";
  bMenu += "</B></Font>";
  bMenu += "<Center><Input Type='button' Name='ret' Value='&nbsp;&nbsp;Cancel&nbsp;&nbsp;' onClick='showInfoLayer(bGround);'></Center>";

  bMenu += "</Pre></Td></Tr>";
  bMenu += "</Table></Td></Tr></Form></Table>";
  showInfoLayer();
}

function dspMenu()
{
  if ( bMenu.indexOf( 'Command\n\n' ) == -1 ) {
    inhibit = false;
    bMenu = "<Table Border='1' CellSpacing='2' CellPadding='0' BgColor='#cccccc'><Form><Tr>";
    bMenu += "<Td Align='Center' VAlign='Middle' Width='"+( blockSize*9 )+"' Height='"+( blockSize*19 )+"'>";
    bMenu += "<Table Border='0' CellSpacing='0' CellPadding='0'><Tr><Td>";
    bMenu += "<Pre><Font Class='Menu' Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+String(parseInt(size))+"'>";
    bMenu += "<B>\nKey Command\n\n";
    bMenu += "  <Font  Class='GMenu'><A Href='javascript:introduction();' onMouseOver='display(\"<Font Color=Black><B>(9) - Stop running game. - Clear playground.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>9)  Stop/Clear</A></Font>\n";
    bMenu += "  <Font  Class='GMenu'><A Href='javascript:startTetris();' onMouseOver='display(\"<Font Color=Black><B>(8) - Start or Restart game. - Sets score to zero. - Leave Level unchanged.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>8)  Start</A></Font>\n";
    bMenu += "  <Font  Class='GMenu'><A Href='javascript:startClear();' onMouseOver='display(\"<Font Color=Black><B>(7) - Start or Restart game. - Sets score to zero. - Sets Level to 1</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>7)  Start/Clear</A></Font>\n"+(screenWidth > 800 ? '\n' : '');
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(6"+(browser != 'N' ? ' or Cursor Right' : '')+") - Move playing pice to the right.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>6)  Move Right</A>\n";
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(5"+(browser != 'N' ? ' or Cursor Up' : '')+") - Rotate the playing pice.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>5)  Rotate</A>\n";
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(4"+(browser != 'N' ? ' or Cursor Left' : '')+") - Move playing pice to the Left.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>4)  Move Left</A>\n"+(screenWidth > 800 ? '\n' : '');
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(3) - Step the playing pice one step down. - Gain Time.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>3)  Step Down</A>\n";
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(2"+(browser != 'N' ? ' or Cursor Down' : '')+") - Force the playing pice to the lowest possible position. - Gain Time.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>2)  Force Down</A>\n";
    bMenu += "  <Font  Class='GMenu'><A Href='javascript:incLevel();' onMouseOver='display(\"<Font Color=Black><B>(1) - Increment Level.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>1)  Level +1</A></Font>\n"+(screenWidth > 800 ? '\n' : '');
    bMenu += "  <A Href='javascript:dummy();' onMouseOver='display(\"<Font Color=Black><B>(0) - Pause running game. - When this key is used your score will not be valid for the High Score list.</B></Font>\"); window.status=\"\"; return true;' onMouseOut='display(\"\")'>0)  Pause</A>\n\n</B>";
    bMenu += " Usage with the\n numeric keypad.\nKeep NumLock on.</Center></Font>\n";
    bMenu += "<Center><Input Type='button' Name='retMenu' Value='&nbsp;&nbsp;Cancel&nbsp;&nbsp;' onClick='dspMenu();'></Center>";
    bMenu += "</Pre></Td></Tr></Table></Td></Tr></Form></Table>"; }
  else {
    bMenu = oMenu;
    if ( oMenu.indexOf('ScoreList') != -1 ) inhibit = true; }
  showInfoLayer();
}

function dummy() { }

function keyBoardEvent(e)
{
  if ( browser != 'N' ) { c = handleEvent(String.fromCharCode(window.event.keyCode)); }
  else if ( verNo >= '5' ) { handleEvent(''); }
  else { handleEvent(String.fromCharCode(e.which)); }
}

function startClear()
{
  changeLevel(1);
  startTetris();
}

function startTetris()
{
  clearStat();
  m = new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
  var nd = new Date();
  highScore[highScore.length-1][11] = ( (k=nd.getDate()) > 9 ? '':'0' )+k+' ';
  highScore[highScore.length-1][11] += m[nd.getMonth()] + ' ';
  highScore[highScore.length-1][11] += nd.getYear();
  highScore[highScore.length-1][12] = ntwnTime();
  highScore[highScore.length-1][9] = String(level);
  inhibit = false;
  clearScreen();
  pauseUsed = false;
  displayStatusLine();
  play();
}

function incLevel()
{
  changeLevel(0);
  displayStatusLine();
}

function changeLevel(s)
{
   if ( s == 0 && ++level > 10 || s == 1 ) { level = 1; }
   roundTime = 550-level*50;
   return true;
}

function togglePause()
{
  if ( !runTetris || ended ) { return }
  if ( !pauseActive ) {
    if ( fallTimer != null ) { clearTimeout( fallTimer ); }
    pauseUsed = true;
    pauseActive = true; }
   else { pauseActive = false; play(); }
}

function displayStatusLine()
{
  var i,lvl,sFnt,bFnt,nFnt,score,delLines,Level

  sFnt = '<Font Color="#ffffe5">';	// Notown's Creem
  bFnt = '<Font Color="Black">';	// Black is black
  nFnt = '<Font Color="#0000cc">';	// NoTown's Blue

  lvl = String(level);
  for( Level = '', i = 2 - lvl.length; i != 0; i-- ) { Level += '1'; }
  Level = lvl+sFnt+Level+bFnt;

  for( score = '', i = 6 - highScore[highScore.length-1][2].length; i != 0; i-- ) { score += '1'; }
  score = highScore[highScore.length-1][2]+sFnt+score+bFnt;

  highScore[highScore.length-1][7] = String(prevLines+lines);
  for( delLines = '', i = 4 - highScore[highScore.length-1][7].length; i != 0; i-- ) { delLines += '1'; }
  delLines = highScore[highScore.length-1][7]+sFnt+delLines+bFnt;

  display( 'Notown\'s Tetris Game:&nbsp;&nbsp;&nbsp;&nbsp;<B>'+bFnt+'Level: '+Level+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Score: '+score+'Deleted Lines: '+delLines+'</B></Font>',0 );
}

function clearScreen()
{
  if ( fallTimer != null ) { clearTimeout( fallTimer ); }
  runTetris = false;
  pauseActive = false;
  ended = false;
  type = 0;			// Type of block in action
  shape = 0;			// Shape of block in action
  nextType = 0;			// Next block type
  nextShape = 0;		// Shape of next block
  clearArea(occupied);
  occupied = '';		// Occupied positions on the play ground
  clearArea(next);
  next = '';			// Holds next figure
  clearArea(current);
  current = '';			// Holds current figure
  bMenu = '';			// Clear bottom menu
  oMenu = '';			// Clear Game Over menu
}

function clearStat()
{
  lines = 0;				    // Number of lines deleted/level
  prevLines = 0;			    // Lines deleted at previouse levels
  prevPnts = 0;				    // Previous snatch second counter
  highScore[highScore.length-1][2] = '0';   // Displayed points
  highScore[highScore.length-1][3] = '0';   // Number of singel lines deleted
  highScore[highScore.length-1][4] = '0';   // Number of singel par of lines deleted
  highScore[highScore.length-1][5] = '0';   // Number of par + one singel line deleted
  highScore[highScore.length-1][6] = '0';   // Number of two par of lines deleted
  highScore[highScore.length-1][7] = '0';   // Total lines deleted
  highScore[highScore.length-1][8] = '0';   // Number of images generated
}


function buildNextBlock()
{
   with( Math ) {
     nextShape = floor( random()*4 );
     nextType = floor( random()*7 ); }
   var align = 0;
   for ( var i = 1; i < 8; i += 2 ) {
     if ( block[nextType][nextShape].charAt(i-1) > align ) { align = block[nextType][nextShape].charAt(i-1); }
     if ( block[nextType][nextShape].charAt(i) > align ) { align = block[nextType][nextShape].charAt(i); }
   }
   align = Math.floor(Math.random()*(10-align));
   for( i = 0; i < 8; ) {
     next += String.fromCharCode( parseInt( block[nextType][nextShape].charAt(i++) )+65 );
     next += String( parseInt( block[nextType][nextShape].charAt(i++) )+align ); }
   writeBlock(next,nextType);
   if ( current == '' ) { nextToCurrent(); }
}

function play(s)
{
  if ( fallTimer != null ) { clearTimeout( fallTimer ); }
  if ( !runTetris ) {
    if ( browser == 'N' ) {
      document.Back.visibility = "hide";
      document.Info.visibility = "hide"; }
    else {
      Back.style.visibility = "hidden";
      Info.style.visibility = "hidden"; }
    clearStat();
    clearScreen();
    buildNextBlock();
    ended = false;
    runTetris = true;
    fallTimer = setTimeout( "play()", 750 );
    return; }
  if ( s == 'force' ) {
    if ( forceDown() ) { if ( !pauseActive ) { fallTimer = setTimeout( "play()", 50 ); } }
    else { gameOver(); } }
  else {
    if ( fallDown(s) ) { if ( !pauseActive ) { clearTimeout( fallTimer ); fallTimer = setTimeout( "play()", roundTime ); } }
    else { gameOver(); }
  }
}

function gameOver()
{
  runTetris = false;  ended = true;  pauseActive = false;
  highScore[highScore.length-1][10] = String(level);
  highScore[highScore.length-1][13] = ntwnTime();
  oMenu  = "<Table Border='1' CellSpacing='2' CellPadding='0' BgColor='#cccccc'><Form Name='GameOver'><Tr>";
  oMenu += "<Td Align='Center' Width='"+( blockSize*9 )+"' Height='"+( blockSize*17 )+"'>";
  oMenu += "<Table Border='0' CellSpacing='0' CellPadding='0'><Tr><Td Align='Center'>";
  oMenu += "<Font Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+String( size )+"'>";
  oMenu += "<B>Game Over";
  oMenu += "<Br><Img Src='../../global/dot.gif' Border='0' Width='1' Height='8'><Br>";
  oMenu += "Score: "+highScore[highScore.length-1][2]+"<Br>Level: "+String(level);
  oMenu += "</B></Font><P>";
  if ( !pauseUsed && parseInt(highScore[highScore.length-1][2]) >= 20 ) {
    for ( i = 0; i < highScore.length-1; i++ ) {
      if ( highScore.length-1 >= nbrOfHighScore && parseInt(highScore[i][2]) >= parseInt(highScore[highScore.length-1][2]) ) { continue; }
      inhibit = true;
      oMenu += "<Font Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+size+"'>";
      oMenu += "<B>You Have Reached<Br>";
      oMenu += "the High ScoreList<Br>";
      oMenu += "Enter Your Name:</B></Font><P>";
      oMenu += "<Input Type='Text' Name='Name' Size='8' MaxLength='8' Value=''>&nbsp;&nbsp;";
      oMenu += "<Input Type='button' Name='newScore' Value='Save' onClick='send(document.GameOver.Name.value);'>";
      oMenu += "<Br><Img Src='../../global/dot.gif' Border='0' Width='1' Height='8'><Br>";
      oMenu += "<Font Face='Verdana, Arial, Helvetica, sans-serif' Color='Black' Size='"+size+"'>";
      oMenu += "Your IP ADR.<Br>"+ipAdr+"<Br>will be stored!</Font><P>";
      break; }
  }
  oMenu += "<Input Type='button' Name='retGO1' Value='&nbsp;Statistics&nbsp;' onClick='showGameScore(highScore.length-1);'>";
  oMenu += "<Br><Img Src='../../global/dot.gif' Border='0' Width='1' Height='8'><Br>";
  oMenu += "<Input Type='button' Name='retGO2' Value='&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;' onClick='introduction();'>";
  oMenu += "</Td></Tr></Table></Td></Tr></Form></Table>";
  bMenu = oMenu;
  showInfoLayer();
}

function send(s)
{
  var valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ@.,!_-'/";
  if ( s != '' ) {
    for( i = 0; i < s.length; i++ ) {
      if ( valid.indexOf(s.charAt(i).toUpperCase()) != -1 ) { continue; }
      alert( "There are invalid characters in the namefield\nValid cahracters are:\nUpper or Lower case: A-Z ÅÄÖ @ 0-9 .,!/_-'" );
      return;
    }
    highScore[highScore.length-1][1] = s;
    for ( i = 1; i < highScore[highScore.length-1].length; i++ ) {
      if ( i != 1 ) { document.SECRET.score.value += ';'; }
      document.SECRET.score.value += highScore[highScore.length-1][i]; }
    document.SECRET.submit(); }
  else { alert( "You must have a name!?" ); }
}

function moveLeft()
{
   var propose = '';
   if ( !runTetris || ended ) { return }
   if ( current.indexOf('0') != -1 ) { return false; }
   for ( i = 0; i < current.length; ) {
     propose += current.charAt(i++)+String(parseInt(current.charAt(i++))-1); }
   if ( !checkIfValidPosition(propose) ) { return false; }
   eraseBlock(propose);
   current = writeBlock(propose,type);
   return true;
}

function moveRight()
{
   if ( !runTetris || ended ) { return }
   var propose = '';
   if ( current.indexOf('9') != -1 ) { return false; }
   for ( i = 0; i < current.length; ) {
     propose += current.charAt(i++)+String(parseInt(current.charAt(i++))+1); }
   if ( !checkIfValidPosition(propose) ) { return false; }
   eraseBlock(propose);
   current = writeBlock(propose,type);
   return true;
}

function rotate()
{
   if ( !runTetris || ended ) { return }
   var propose = '';
   var xOffset = (current.charCodeAt(0)-65)-parseInt(block[type][shape].charAt(0));
   var yOffset = parseInt(current.charAt(1))-parseInt(block[type][shape].charAt(1));
   var proposedShape = shape >= 3 ? 0 : shape+1;
   for( i = 0; i < 8; ) {
     propose += String.fromCharCode( parseInt( block[type][proposedShape].charAt(i++) )+xOffset+65 );
     propose += String(parseInt(block[type][proposedShape].charAt(i++))+yOffset); }
   if ( next != '' )
     for ( i = 0; i < propose.length; ) {
       if ( next.indexOf( propose.charAt(i++)+propose.charAt(i++) ) != -1 ) return false; }
   if ( propose.indexOf('Y') != -1 ) { return false; }
   if ( propose.indexOf('-1') != -1 ) { return false; }
   if ( propose.indexOf('10') != -1 ) { return false; }
   if ( !checkIfValidPosition(propose) ) { return false; }
   shape = proposedShape;
   eraseBlock(propose);
   current = writeBlock(propose,type);
   return true;
}


function fallDown(s)
{
  if ( !runTetris || ended ) { return false; }
  if ( occupied.indexOf( current ) != -1 ) { return false; }
  if ( next == '' && CheckIfPreviewFieldEmpty() ) { buildNextBlock(); }
  var propose = '';
  for ( i = 0; i < current.length; ) {
    propose += String.fromCharCode(current.charCodeAt(i++)+1)+current.charAt(i++); }
  if ( s =='step' ) {
    highScore[highScore.length-1][8] = String(parseInt(highScore[highScore.length-1][8])+roundTime); }
  if ( !checkIfValidPosition(propose) ) {
    occupied += current;
    while( checkIfEraseLine() );
    if ( CheckIfPreviewFieldEmpty() ) {
      nextToCurrent();
      return true; }
    return false; }
  eraseBlock(propose);
  current = writeBlock(propose,type);
  return true;
}

function forceDown()
{
  if ( !runTetris || ended ) { return false; }
  if ( occupied.indexOf( current ) != -1 ) { return false; }
//  if ( current.indexOf('D') != -1 ) { return true; } // This should be here... But it's boring playing with it.
  var propose = current;
  var okPosition = current;
  while ( checkIfValidPosition(propose) ) {
    okPosition = propose;
    for ( propose = '', i = 0; i < okPosition.length; ) {
      propose += String.fromCharCode(okPosition.charCodeAt(i++)+1)+okPosition.charAt(i++); }
  }
  highScore[highScore.length-1][8] = String(parseInt(highScore[highScore.length-1][8])+((okPosition.charCodeAt(0)-current.charCodeAt(0))*roundTime));
  eraseBlock(okPosition);
  current = writeBlock(okPosition,type);
  occupied += current;
  while( checkIfEraseLine() );
  if ( CheckIfPreviewFieldEmpty() ) {
    if ( next == '' ) { buildNextBlock(); }
    nextToCurrent();
    return true; }
  return false;
}

function eraseBlock(propose)
{
  for( i = 0; i < current.length; i += 2 ) {
    if ( propose.indexOf( current.substring( i,i+2 ) ) != -1 ) { continue; }
    if ( occupied.indexOf( current.substring( i,i+2 ) ) != -1 ) { continue; }
      putGameImage( current.substring( i,i+2 ), 7 ); }
}

function writeBlock(propose,fig)
{
  for( i = 0; i < propose.length; i += 2 ) {
    if ( current.indexOf( propose.substring( i,i+2 ) ) != -1 ) { continue; }
      putGameImage( propose.charAt(i)+propose.charAt(i+1), fig ); }
  return propose;
}

function clearArea(area)
{
  var i,s1,s2;

  for( i = 0; i < area.length; ) {
    putGameImage( area.charAt(i++)+area.charAt(i++), 7 ); }
}

function checkIfEraseLine(src)
{
  var c,i,j,k,at,to,s1,s2,cnt;

  for ( s2 = '', c = 'X', cnt = 5; c != 'D'; c = String.fromCharCode(c.charCodeAt(0)-1) ) {
    for ( s1 = '', i = 0; ( i = occupied.indexOf(c,i) ) != -1; ) { s1 += occupied.charAt(i++); }
    if ( s1.length != 10 ) { continue; }
    if ( s2.length > 9 && s2.charCodeAt( s2.length-1 ) - s1.charCodeAt(0) > 1 ) { break; }
    s2 += s1;
    lines++;
    cnt = cnt*4;
  }
  if ( s2.length < 10 ) { return false; }
  for ( i = 0; i < 10; i++ ) {
    to = String.fromCharCode( s2.charCodeAt(0) );
    at = String.fromCharCode( s2.charCodeAt(s2.length-1)-1 );
    c = String(i);
    for ( j = 0; ; j++ ) {
      if ( occupied.indexOf( String.fromCharCode(69+j)+c ) != -1 ) { break; }
    }
    j = to.charCodeAt(0)-(69+j)+1;  // j = number of blocks to be moved in this column
    while ( j-- != 0 ) {
      moveGameImage( to+c, at+c );
      if ( ( k = occupied.indexOf( to+c ) ) != -1 ) {
        occupied = occupied.substring( 0, k )+occupied.substring( k+2, occupied.length ); }
      if ( ( k = occupied.indexOf( at+c ) ) != -1 ) {
        occupied = occupied.substring( 0,k )+to+occupied.substring( k+1,occupied.length ); }
      to = String.fromCharCode( to.charCodeAt(0)-1 );
      at = String.fromCharCode( at.charCodeAt(0)-1 );
    }
  }
  if ( lines > 25 ) {
    prevLines += lines;
    lines = 0;
    highScore[highScore.length-1][2] = String( parseInt(highScore[highScore.length-1][2])+1 );
    changeLevel(0); }
  highScore[highScore.length-1][14] = highScore[highScore.length-1][8];

  i = parseInt(highScore[highScore.length-1][2]);
  i -= prevPnts;
  prevPnts = Math.round( parseInt(highScore[highScore.length-1][14])/60000 );
  i += prevPnts+cnt;
  highScore[highScore.length-1][2] = String(i);

  switch( cnt ) {
    case   20: highScore[highScore.length-1][3] = String( parseInt(highScore[highScore.length-1][3] )+1 ); break;
    case   80: highScore[highScore.length-1][4] = String( parseInt(highScore[highScore.length-1][4] )+1 ); break;
    case  320: highScore[highScore.length-1][5] = String( parseInt(highScore[highScore.length-1][5] )+1 ); break;
    case 1280: highScore[highScore.length-1][6] = String( parseInt(highScore[highScore.length-1][6] )+1 ); break;
    default  : break;
  }
  displayStatusLine();
  return true;
}

function checkIfValidPosition(propose)
{
  if ( propose.indexOf('Y') != -1 ) { return false; }
  for ( i = 0; i < propose.length; ) {
    if ( occupied.indexOf( propose.charAt(i++)+propose.charAt(i++) ) != -1 ) { return false; }
  }
  return true;
}

function CheckIfPreviewFieldEmpty()
{
   var s = 'ABCD';
   for ( i = 0; i < s.length; i++ )
     if ( current.indexOf( s.charAt(i) ) != -1 ) { return false; }
   return true;
}

function nextToCurrent()
{
  current = next;
  type = nextType;
  shape = nextShape;
  next = '';
}

function RtVal()
{
 if ( !crawler && top.navigate == 'installed' )
   top.RtVal();
}

function ntwnTime()
{
 if ( !crawler && top.navigate == 'installed' ) {
   return top.ntwnTime(); }
 else {
  var nt = new Date();
  var H = nt.getHours();
  var M = nt.getMinutes();
  var S = nt.getSeconds();
  var s1 = ( ( H < 10 ) ? '0' : '' ) + H;
  s1 += ( ( M < 10 ) ? ':0' : ':' ) + M;
  s1 += ( ( S < 10 ) ? ':0' : ':' ) + S;
  return s1; }
}

// -->

