
var menuClub = new Array( "Real Atletico;", "Uutiset;", "Historia;");
var menuTeam = new Array( "Pelaajat;players", "Tilastoja;statistic");
var menuOthers = new Array(  "Forum;link#www.realatletico.net/forum", "Real-mail;link#www.realatletico.net:2095/", "Linkit;");
var menuFinance = new Array(  "Maksut;finance");
var menuGames = new Array( );

var activeMenu = 0;
var imgType = null;

function createMenus()
{
  loadGames();
  
  var table = document.createElement("table");
  table.className = "menuTableClass";
  table.id = "menuTableId";

	imgType = "png)";
	
	if ( currentBrowser == browserIE && browserVersion <= 6 )
	{
		imgType = "jpg)";
	}

  var rowIndex = 0;
  var row = table.insertRow( rowIndex++);  
  row.className = "menuRowClass";
  var cell = row.insertCell(0);
  cell.className = "menuCellClass";
  cell.style.backgroundImage = "url(common/pics/clubmenubox." + imgType;
  cell.onclick = menuCellClick;
  cell.id = "menuBoxClub";
    
  var row = table.insertRow( rowIndex++);  
  var cell = row.insertCell(0);
  cell.className = "menuCellClass";
  cell.style.backgroundImage = "url(common/pics/teammenubox." + imgType;
  cell.onclick = menuCellClick;
  cell.id = "menuBoxTeam";
  
  var row = table.insertRow( rowIndex++);  
  var cell = row.insertCell(0);
  cell.className = "menuCellClass";
  cell.style.backgroundImage = "url(common/pics/gamesmenubox." + imgType;
  cell.onclick = menuCellClick;
  cell.id = "menuBoxGames";

  var row = table.insertRow( rowIndex++);  
  var cell = row.insertCell(0);
  cell.className = "menuCellClass";
  cell.style.backgroundImage = "url(common/pics/othersmenubox." + imgType;
  cell.onclick = menuCellClick;
  cell.id = "menuBoxOthers";
 
  document.getElementById("leftCol").appendChild( table);
}

function openMenu( index)
{
  
}

function checkPrivateMenu()
{
	var table = document.getElementById("menuTableId");

	if ( fid)
	{
	  var row = table.insertRow( table.rows.length);  
	  row.id = "privateRowId";
	  var cell = row.insertCell(0);
	  cell.className = "menuCellClass";
	  cell.style.backgroundImage = "url(common/pics/privatemenubox." + imgType;
	  cell.onclick = menuCellClick;
	  cell.id = "menuBoxInternal";
	}	else
	{
		var row = document.getElementById("privateRowId");
		
		if ( row )
		{
			var index = row.rowIndex;
			
			while ( table.rows.length > index)
			{
				table.deleteRow( index);
			}
		}
	}
}

function menuCellClick( e)
{
	var targ = getTargetFromEvent( e);
  
  if ( targ.id == "menuBoxClub")
  {
    createMenu( 1, menuClub);
    goToMenu( "mainpage");
  }
  
  if ( targ.id == "menuBoxTeam")
  {
    createMenu( 2, menuTeam);
  }

  if ( targ.id == "menuBoxOthers")
  {
    createMenu( 4, menuOthers);
  }  
  
  if ( targ.id == "menuBoxGames")
  {
    createMenu( 3, menuGames);
 		goToMenu( "gamesMain", null, null, null);
  }
  
  if ( targ.id == "menuBoxInternal")
  {
  	createMenu( 5, menuFinance);
  }
  
}

function createMenu( index, content)
{
  var table = document.getElementById('menuTableId');
  
  for ( var i = table.rows.length - 1; i >= 0; i--)
  {
    if ( table.rows[i].cells[0].id.substr( 0, 7) != "menuBox") 
    {
      table.deleteRow( i);
    }
  }
  
  if ( index > 0)
  {
     for ( var i = 0; i < content.length; i++)
     {
        var row = table.insertRow( index + i);
        var cell = row.insertCell(0);
        
        result = content[i].split( /;/);
        cell.innerHTML = "<a class=\"subMenuLink\" onclick=\"goToMenu('"+ result[1] +"')\">" + result[0] + "</a>";
     } 
  }
}

function loadGames()
{
  xmlHttpRequest( "common/server/games.php", "rid=getLeagues&onlyvisible=true", 0);
  var xml = xmlParser( xmlHttp.responseText);//xmlHttp.responseXML;
  var leagues = xml.getElementsByTagName("league");
  
  for ( var i = 0; i < leagues.length; i++)
  {
      var value = leagues[i].attributes.getNamedItem("name").nodeValue;
      value += ";league#";
      value += leagues[i].attributes.getNamedItem("id").nodeValue;
      value += "#" + leagues[i].attributes.getNamedItem("defdiv").nodeValue;
      
      menuGames.push( value);
  } 
}

function createRightCol()
{
	
}
