// Get the CGI parameters.

function getArgs()
{
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split(",");
  for( var i=0; i < pairs.length; i++)
  {
    var pos = pairs[i].indexOf('=');
    if (pos == -1) continue;
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    args[argname] = unescape(value);
  }
  return args;
}

function showMatch(selector,org) {
  selected = selector.selectedIndex;
  fixture = selector.value;
//alert("Show match:"+fixture);
  var args = getArgs();
  url = document.location.protocol+"//"+document.location.hostname+document.location.pathname;
//alert("url "+url);
//document.location = "index.php?fixture="+fixture+"&org="+org;
  document.location = url+"?fixture="+fixture+"&org="+org;
}

function totalScore() {
//alert("totalScore: ");
  homeScore = 0;
  awayScore = 0;
//form = document.forms[0];
  form = document.match;
  if( form!=null && form.elements !=null )
  {
  for(i=0; i<form.elements.length; i++)
  {
//  element = document.forms[0].elements[i];
    element = document.match.elements[i];
    if( element.type == "select-one" )
    {
      if( element.name.substr(0,6) == "result" )
      {
        score = element.value;
        if( score == "W" )
        {
          homeScore+=2;
        }
        if( score == "D" )
        {
          homeScore+=1;
          awayScore+=1;
        }
        if( score == "L" )
        {
          awayScore+=2;
        }
      }
    }
  }
  }
  homeTotal = homeScore / 2.0;
  awayTotal = awayScore / 2.0;
  finalScore = homeTotal + " - " + awayTotal;
//alert("finalScore: "+finalScore);
//document.forms[0].total.value = finalScore;
  if( document.match!=null )
  {
  document.match.total.value = finalScore;
  }
//alert("Selected:"+option);
}
function showTables(org) {
//alert("totalScore: ");
  url = document.location.protocol+"//"+document.location.hostname+document.location.pathname;
//document.location = "index.php?org="+org+"&fixture=0";
  document.location = url + "?org="+org+"&fixture=0";
}
function showEventPage(page,org,event) {
  newLocation = page+"?org="+org+"&event="+event;
  document.location = newLocation;
}
function logoutPage(page,org) {
  newLocation = page+"?org="+org+"&action=logout";
  document.location = newLocation;
}


