<!--

var games_col = new Array ();
games_col[0] = new Array ();
games_col[1] = new Array ();
games_col[2] = new Array ();

function game(game_id,value,bool) {
    this.game_id = game_id;
    this.value = value;
    this.bool = bool;
}

function rules()
{
  var rules = new Array();
  var comb = new Array();
  comb[2]=0;
  comb[3]=0;

  for(var i=0;i<games_col.length;i++)
  {
    for(var j=0;j<games_col[i].length;j++)
    {
      if (games_col[i][j] && games_col[i][j].bool==1) 
      {
	if (! rules[j]) { rules[j]=0; }
	rules[j]++;
      }
    }
  }

  for(var i=0;i<rules.length;i++)
  {
    if (rules[i]) 
    {
      if (rules[i]==2) { comb[2]++; }
      if (rules[i]==3) { comb[3]++; }
    }
  }

  if (comb[2]>4 || comb[3]>3) { alert('בטופס זה אתה רשאי לשים 4 כפולים ו-3 משולשים בלבד.'); return false; }

  document.frontpage.double.value=comb[2];
  document.frontpage.triple.value=comb[3];
  return true;
}

function win_select(button,game_id)
{
   var type;

   if (/home/.test(button.name)) { type=0; }
   if (/draw/.test(button.name)) { type=1; }
   if (/away/.test(button.name)) { type=2; }

   if (! games_col[type][game_id])
   {
      games_col[type][game_id] = new game(game_id,button.value,1);
      button.style.color='red';
      games_col[type][game_id].bool=1;
   }

   else if (games_col[type][game_id].bool==1)
   {
      button.style.color='black';
      games_col[type][game_id].bool=0;
   }
   else if (games_col[type][game_id].bool==0)
   {
      button.style.color='red';
      games_col[type][game_id].bool=1;
   }

/**
   if (type==0)
   {
       var win_draw = document.getElementsByName('win_draw_' + game_id)[0];
       win_draw.style.color='black';
       if (games_col[1][game_id]) {games_col[1][game_id].bool=0; } ;

       var win_away = document.getElementsByName('win_away_' + game_id)[0];
       win_away.style.color='black';
       if (games_col[2][game_id]) {games_col[2][game_id].bool=0; } ;
   }
   if (type==1)
   {
       var win_home = document.getElementsByName('win_home_' + game_id)[0];
       win_home.style.color='black';
       if (games_col[0][game_id]) {games_col[0][game_id].bool=0; } ;

       var win_away = document.getElementsByName('win_away_' + game_id)[0];
       win_away.style.color='black';
       if (games_col[2][game_id]) {games_col[2][game_id].bool=0; } ;
   }
   if (type==2)
   {
       var win_home = document.getElementsByName('win_home_' + game_id)[0];
       win_home.style.color='black';
       if (games_col[0][game_id]) {games_col[0][game_id].bool=0; } ;

       var win_draw = document.getElementsByName('win_draw_' + game_id)[0];
       win_draw.style.color='black';
       if (games_col[1][game_id]) {games_col[1][game_id].bool=0; } ;
   }
**/

  if (! rules())
  {
    button.style.color='black';
    games_col[type][game_id].bool=0;
  }

  return true;
}

function tofes_send_enable()
{
  var tofes_send = document.getElementById('tofes_send');
  tofes_send.disabled=false;
}

function tofes_send_disable()
{
  var tofes_send = document.getElementById('tofes_send');
  tofes_send.disabled=true;
}

function tofes_select(tofes_serial)
{
  var form = document.getElementsByName('frontpage')[0];
  var input,name;
  var tofes;
  var exists=0;
  var found=0;
  var count=0;
  var counted = new Array();

  var tofes_send = document.getElementById('tofes_send');
  tofes_send.disabled=true;

  for(var i=0;i<form.elements.length;i++)
  {
    if (form.elements[i] && form.elements[i].type=='hidden')
    {
        form.removeChild(form.elements[i]);
    }
  }

  for (var j=0;j<=2;j++)
  {
    for(var i=0;i<=games_col[j].length;i++)
    {
      if ((games_col[j][i]) && (games_col[j][i].bool==1))
      {
	if (! counted[i])
	{
	  count++;
	  counted[i]=1;
	}

        exists=0;
        found=1;
        tofes = games_col[j][i].tofes_id;

        input = document.createElement('input');
        input.setAttribute('name','games_col' + j + '-' + i);
        input.setAttribute('type','hidden');

        for(var k=0;k<form.elements.length;k++)
        {
          if (input.name == form.elements[k].name)
          {
            exists=1;
            continue;
          } 
        }

        if (exists==0){ form.appendChild(input); }
      }
    }
  }

  if (count % 16 != 0)
  {
    alert('אתה חייב להמר על כל 16 המשחקים בכל טור שאתה שולח.');
    return false;
  }

  if (found==1)
  {
    delete games_col;
    input = document.createElement('input');
    input.setAttribute('name','tofes');
    input.setAttribute('value','');
    input.setAttribute('value',tofes_serial);
    input.setAttribute('type','hidden');
    form.appendChild(input);
    return true; 
  }
  else {
    alert('לא בחרת אף משחק עדיין!');
    return false;
  }
}

function open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}

-->
