function formInput() {
  // empty object
}

  var group = '', year = '',tbl = 1;
  var _place='', _date='';	
  var valueOf = new formInput();

  var pairs = document.location.search.substring(1).split("&");
  for (var i=0; i < pairs.length; i++) {
    var values = pairs[i].split("=");
    valueOf[values[0]] = unescape(values[1]);
  }

 for (var x in valueOf) {
     if(x == 'group')
        group = valueOf[x];
     else if(x == 'year')
        year = valueOf[x];
     else if(x == 'place')
        _place = valueOf[x];
     else if(x == 'date')
        _date = valueOf[x];

 }
if(year == '')
  document.write("<script type='text/javascript' src='data/var.js'></script>")
else
  document.write("<script type='text/javascript' src='data/" + year + "/var.js'></script>")

function getAllTeams(){
var newht, newat;
 for(i=0; i < match.length; i++){
  if(match[i][gr].indexOf('semi') != -1 ||
     match[i][gr].indexOf('Semi') != -1 ||
     match[i][gr].indexOf('Final') != -1 ||
     match[i][gr].indexOf('3:e pris') != -1)
    continue;
  newht = true; newat = true;
  for(j=0; j < allteams.length; j++){
   if((match[i][ht]+'_&_'+match[i][gr])  == allteams[j]){
     newht = false;
     if(!newat)
       break;
   }
   if((match[i][at]+'_&_'+match[i][gr])  == allteams[j]){
     newat = false;
     if(!newht)
       break;
   }
  }
  if(newht)
   allteams[j++] = match[i][ht]+'_&_'+match[i][gr];
   
  if(newat)
   allteams[j] = match[i][at]+'_&_'+match[i][gr];
 }
allteams = allteams.sort();
return;
}



function getTeam_id(strTeam){
 for(j=0; j < teams.length; j++){
  if(strTeam == teams[j])
	return j;
 }
 team[j] = [0, 0, 0, 0, 0, 0, 0, 0]
 teams[j] = strTeam
 resTable[j]= new Array()
 return j;
}


function parseRes(ht_id, at_id, h_g, a_g){

    team[ht_id][p]+=h_g
    team[ht_id][m]+=a_g
    team[at_id][p]+=a_g
    team[at_id][m]+=h_g

    if(h_g > a_g){
      team[ht_id][w]+=1
      team[at_id][l]+=1
      resTable[ht_id][at_id] =1
      resTable[at_id][ht_id] =3
    }else if(h_g < a_g){
      team[ht_id][l]+=1
      team[at_id][w]+=1
      resTable[ht_id][at_id] =3
      resTable[at_id][ht_id] =1
    }else{
      team[ht_id][a]+=1
      team[at_id][a]+=1
      resTable[ht_id][at_id] =2
      resTable[at_id][ht_id] =2
    }
}

function getH_Goals(idx){
  return parseInt(match[idx][res].substring(0,match[idx][res].indexOf('-')))
}

function getA_Goals(idx){
  return parseInt(match[idx][res].substring(match[idx][res].indexOf('-')+1))
}

//Sort teams
function compare(t1, t2){
  if((t1[w]*wp+t1[a]*ap+t1[l]*lp+t1[pp]) > (t2[w]*wp+t2[a]*ap+t2[l]*lp+t2[pp]))
       return -1;
  if((t1[w]*wp+t1[a]*ap+t1[l]*lp+t1[pp]) < (t2[w]*wp+t2[a]*ap+t2[l]*lp+t2[pp]))
       return 1;
  if(resTable[t1[tid]][t2[tid]] != null)
     if(resTable[t1[tid]][t2[tid]] == 1)
        return -1
     else if(resTable[t1[tid]][t2[tid]] == 3)
        return 1
  if(t1[p]-t1[m] > t2[p]-t2[m])
       return -1
  if(t1[p]-t1[m] < t2[p]-t2[m])
       return 1
  if(t1[p] > t2[p])
       return -1
  if(t1[p] < t2[p])
       return 1

  if((teams.length-1) == (t1[w]+t1[a]+t1[l]) && (teams.length-1) == (t2[w]+t2[a]+t2[l])){
    t1[draw] = -1
    t2[draw] = -1
  }
  if(teams[t1[tid]] > teams[t2[tid]])
    return 1
  if(teams[t1[tid]] < teams[t2[tid]])
    return -1
 return 0
}

//Sort games
function compare2(t1, t2){
  if(match[t1][date] > match[t2][date])
     return 1;

  if(match[t1][date] < match[t2][date])
     return -1;
  
  if(match[t1][time] > match[t2][time])
     return 1;

  if(match[t1][time] < match[t2][time])
     return -1;

 return 0
}

//Sort games
function compare2(t1, t2){
  if(t1[date] > t2[date])
     return 1;

  if(t1[date] < t2[date])
     return -1;
  
  if(t1[time] > t2[time])
     return 1;

  if(t1[time] < t2[time])
     return -1;

 return 0
}


function getRes(){
  match = match.sort(compare2);
 for(i=0; i<match.length; i++){
  if(match[i][gr] == group){
    matchid[matchid.length]=i 
    h_id = getTeam_id(match[i][ht])
     team[h_id][tid]=h_id

     a_id = getTeam_id(match[i][at])
     team[a_id][tid]=a_id

     if(match[i][res].length > 1 && match[i][res].indexOf('-') != -1){
       parseRes(h_id, a_id, getH_Goals(i), getA_Goals(i));
       if(match[i][bp] == 1)
        team[h_id][pp]+=1;
       else if(match[i][bp] == 2)
        team[a_id][pp]+=1;
    }
  }
}
 team = team.sort(compare);
}
