var FOOTER_TEXT = {
    table : {
        liga : {
	    en : "CL = Champions League<br>EL = Europa League",
	    de : "CL = Champions League<br>EL = Europa League - Nachfolgewettbewerb des UEFA-Cups"
	},
        liga2 : {
	    en : "* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    },
    home : {
        liga2 : {
	    en : "* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    },
    away : {
        liga2 : {
	    en : "* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    },
    "1stround" : {
        liga2 : {
	    en : "* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    },
    "2ndround" : {
        liga2 : {
	    en : "* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    },
    form : {
        liga : {
	    en : "The form guide is based on the results of the last five matchdays.",
	    de : "Die Formtabelle basiert auf den Ergebnissen der vergangenen f&uuml;nf Spieltage."
	},
        liga2 : {
	    en : "The form guide is based on the results of the last five matchdays.<br/>* Due to a contract penalty Arminia Bielefeld will be deducted four points at the end of the season.",
	    de : "Die Formtabelle basiert auf den Ergebnissen der vergangenen f&uuml;nf Spieltage.<br/>* Aufgrund einer Vertragsstrafe werden Arminia Bielefeld zum Ende der laufenden Saison vier Gewinnpunkte abgezogen."
	}
    }
}

/* Variablen, die den reinzuladenden Source beeinflussen */
extension = '.html';
extension2 = '.php';
target_window1 = 'sv1';
target_window2 = 'sv2';

spieltag = 'p1/' + (liga_spieltag);
reiter_spieltag = spieltag;
reiter_spieltag_tmp = spieltag.split('/');
reiter_spieltag = reiter_spieltag_tmp[1];

var CBID = 123;
var CB_TABS_CONF = {};
CB_TABS_CONF["id_"+CBID] = {
    "style" : "std"
};

var CB_TABS = {};

/* Form */
if(liga == 'liga'){
    swf_liga = 'mbl';
    liga_long = "bundesliga";
    var matchday = liga_spieltag;
} else {
    swf_liga = 'mbl2';
    liga_long = "zweiteBundesliga";
    var matchday = liga2_spieltag;
}

bl_tab_target_prefix = "/data/fmt/html/v/roundMenu/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/all/";

if(saison == '2005'){
  swf_saison = 6;
}else if(saison == '2006'){
  swf_saison = 7;
}else if(saison == '2007'){
  swf_saison = 8;
}else if(saison == '2008'){
  swf_saison = 9;
}else{
  swf_saison = 0;
}
//swf_saison = 's' + swf_saison;
swf_saison = 's' + saison;


function menuChanged(mytag) {

    spieltag = mytag;
    reiter_spieltag_tmp = spieltag.split('/');
    reiter_spieltag = reiter_spieltag_tmp[1];

    wechselVerein(liga, spieltag);
    fill_kopf('leiste');
}

function wechselVerein(liga, spieltag) {  // changes matchday (puke)

    var offset = reiter_spieltag <= 17 ? reiter_spieltag : 17;

    // remove old cardbox if exists
    var container = document.getElementById("cb_container_"+CBID);
    if (container != null) {
        while (container.firstChild != null) container.removeChild(container.firstChild);
    }

    // prepare hook for cardbox
    var content = document.getElementById("sv2");
    while (content.firstChild != null) content.removeChild(content.firstChild);

    var leiste = document.createElement("div");
    leiste.id = "leiste";
    content.appendChild(leiste);

    var cb_container = document.createElement("div");
    cb_container.id = "cb_container_"+CBID;
    content.parentNode.appendChild(cb_container);

    // set tabs
    CB_TABS["id_"+CBID] = [];

    CB_TABS["id_"+CBID].push({
        name    : "table",
        label   : lang == "de" ? "Tabelle" : "League Table",
        active  : true,
        type    : "url",
        source  : "/data/fmt/html/v/standingsBig/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/all/"+spieltag+".html"
    });

    CB_TABS["id_"+CBID].push({
        name    : "home",
        label   : lang == "de" ? "Heimtabelle" : "Home",
        active  : true,
        type    : "url",
        source  : "/data/fmt/html/v/standingsBig/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/home/"+spieltag+".html"
    });

    CB_TABS["id_"+CBID].push({
        name    : "away",
        label   : lang == "de" ? "Ausw&auml;rtstabelle" : "Away",
        active  : true,
        type    : "url",
        source  : "/data/fmt/html/v/standingsBig/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/guest/"+spieltag+".html"
    });

    CB_TABS["id_"+CBID].push({
        name    : "1stround",
        label   : lang == "de" ? "Hinrundentabelle" : "First leg",
        active  : true,
        type    : "url",
        source  : "/data/fmt/html/v/standingsBig/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/all/p1/"+offset+".html"
    });

    if (matchday > 17) {
        CB_TABS["id_"+CBID].push({
            name    : "2ndround",
            label   : lang == "de" ? "R&uuml;ckrundentabelle" : "Second leg",
            active  : true,
            type    : "url",
            source  : "/data/fmt/html/v/standingsBig/lang/"+lang+"/s/soccer/c/"+liga_long+"/h/rueck/"+spieltag+".html"
        });
    }

    CB_TABS["id_"+CBID].push({
        name    : "form",
        label   : "Form",
        active  : true,
        type    : "url",
        source  : "/data/flash/dynamic/analysis/html_php/formtabelle.php?modul_id=akt_gmd3&language="+lang+"&event_active=1&feed=dynamic&competition="+swf_liga+"&season_id="+swf_saison+"&matchday="+reiter_spieltag
    });

    // display card box
    cb_create(CBID);
}

// implementation of cardbox hook
// called when a content was loaded
// to change content's footer
function cb_contentLoaded(cb) {

    // get name of selected tab
    var i=0;
    var name = null;

    for (key in cb.conf) {
        if (i == cb.selected) {
	    name = cb.conf[key].name;
	    break;
	}
	i++;
    }

    // name not found => do nothing
    if (name == null) {
        return;
    }

    // prepare footer HTML
    var footer = '<div class="font_2">';

    // select text to display
    if (FOOTER_TEXT[name] != null) {
        if (FOOTER_TEXT[name][liga] != null) {
	    if (FOOTER_TEXT[name][liga][lang] != null) {
                footer += FOOTER_TEXT[name][liga][lang];
	    }
	}
    }

    // finish footer HTML
    footer += '</div>';

    // replace footer
    document.getElementById('footer_legende').innerHTML  = footer;
}

function callback(req, my_id, optional_var) {
  if(req.readyState == 4) {
    /* OK response */
    if(req.status == 200) { 
  /* HTML bzw. Text Datei direkt ausgeben */
      document.getElementById(my_id).innerHTML = req.responseText;
      fill_kopf('leiste');
    }
  }
}
function fill_kopf(my_target) {
  /* Kopf generieren */
  document.forms["roundMenu"].elements["roundMenuSelect"].selectedIndex = (reiter_spieltag-1);
  var spieltag_komplett = document.forms["roundMenu"].elements["roundMenuSelect"].options[(reiter_spieltag-1)].text;
  var tmp = document.getElementById(my_target);
  if (lang=="de") {
    tmp.innerHTML = '<div class="headline font_11">' + spieltag_komplett + '<a href="javascript:print();" title="Drucken"><div id="druckenicon">Drucken</div></a></div>\n';
  } else {
    tmp.innerHTML = '<div class="headline font_11">' + spieltag_komplett + '<a href="javascript:print();" title="Print"><div id="druckenicon_en">Print</div></a></div>\n';
  }
  
}

function addAbstand(req, my_id, optional_var){
  myText = optional_var;
  if(req.readyState == 4) {
    /* OK response */
    if(req.status == 200) { 
      /* HTML bzw. Text Datei direkt ausgeben */
      var myInhalt  = '<div class="abstand">&nbsp;</div>';
      myInhalt += req.responseText;
      document.getElementById(my_id).innerHTML = myInhalt;
    }
  }
}
/*
function removeLegende(){
  tmp2 = document.getElementById('footer_legende');
  tmp2.innerHTML  = '&nbsp;';
}
*/


// onload = function(){
function init_tabelle_now(){
  wechselVerein(liga,spieltag);
  retrieveURL(bl_tab_target_prefix + 'p1/1' + extension, 'sv1', 'callback');
}


init_tabelle_now();
