var id;
function fctShowBlock(intBlockID, maxid) {
    if(id == intBlockID) {
        Effect.BlindUp('block' + intBlockID, {});
        id=-1;
        return false;
    }

    id = intBlockID;
    for(i=0; i<maxid; i++) {
        if(intBlockID != i) {
            Effect.BlindUp('block' + i, {});
        }
    }
    Effect.BlindDown('block' + intBlockID, {});
    return false;
}

function showBlock(vid) {
    var b = document.getElementById("block_" + vid);
    hideBlock(b);
    if (b) {
        b.style.display = "block";
    }
    return false;
}
function hideBlock(block) {
    var blocks = block.parentNode.getElementsByTagName("div");
    if (blocks.length > 0) {
        for (i = 0; i < blocks.length; i++) {
            blocks[i].style.display = "none";
        }
    }
}



// Auf  der Detailseite vom Kader den Spieler wechseln
function changePlayer(sid) {
    var url = window.location.href;
    url = url.substr(5, url.indexOf("show")) + sid;
    window.location.href = url;
}

/***************************************************************
 * Cookie
 ***************************************************************/
function schreibCookie(name) {
    var jetzt = new Date();
    var ende = jetzt.getTime() + (1000 * 24 * 60 * 60 * 1000);
    jetzt.setTime(ende);
    ende = jetzt.toGMTString();
    document.cookie = name + '=1;' + 'expires=' + ende + ';';
}

function liesCookie(name) {
    var keks = document.cookie;
    
    // Anfangsposition des Name=Wert-Paars suchen
    var posName = keks.indexOf("; " + name + "=");
    if (posName == -1) {
        // vielleicht war's der erste Name in der Liste?
        if (keks.indexOf(name + "=") == 0) posName = 0;
        // nein? dann abbrechen mit Rückgabewert null
        else return null;
    }
    
    // Anfangs- und Endposition des Krümelwerts suchen
    var wertAnfang = keks.indexOf("=", posName)+1;
    var wertEnde = keks.indexOf(";", posName+1);
    if (wertEnde == -1) wertEnde = keks.length;

    // Krümelwert auslesen und zurückgeben
    var wert = keks.substring(wertAnfang, wertEnde);
    return unescape(wert);
}


/***************************************************************
 *   Funktionen im CMS
 ***************************************************************/
// Im CMS den Spieler wechseln
function change(sid) {
    var url = window.location.href;
    if(url.indexOf("sid") > 0) {
        url = url.substr(0, url.indexOf("sid")) + "sid=" + sid;
    } else {
        url = url + "?sid=" + sid;
    }
    window.location.href = url;
}


/***************************************************************
 *   Aufklappen der Tickermeldung im Tickerarchiv ANFANG
 ***************************************************************/
var t = null;
function showDetailTicker(self, docid) {
 // Alle offenen News schließen
    if (a != self) {
        if (a != null) {
            new Effect.BlindUp(
                $(a).nextSibling.getElementsByTagName('div')[0], {
                    afterFinish:function () {
                        $(a).parentNode.removeChild($(a).nextSibling);
                        requestTicker(self, docid);
                    }
                }
            );
        } else {
            requestTicker(self, docid);
        }
    }
    return false;
}

function requestTicker(link, docid) {
    var self = link.parentNode.parentNode.parentNode;
    a = self;
    var subDiv = document.createElement('div');
    subDiv.setAttribute('class', 'spieler_details_0');
    subDiv.setAttribute('className', 'spieler_details_0');
    subDiv.style.marginTop = "0px";
    subDiv.style.marginBottom = "0px";
    subDiv.style.paddingTop = "0px";
    subDiv.style.paddingBottom = "0px";
    subDiv.style.width = "410px";
    new Insertion.After(self, subDiv);

    var URI = window.location.href;
    if (URI.indexOf("#") > 0) {
        URI = URI.substr(0, URI.indexOf("#"));
    }
    new Ajax.Request(URI, {
        method:'post',
        parameters: {tickerid: docid},
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            subDiv.style.display = 'none';
            subDiv.innerHTML = response;
            Effect.BlindDown(subDiv, {});
        }
    });
    return false;
}
/***************************************************************
 *   Aufklappen der Tickermeldung im Tickerarchiv ENDE
 ***************************************************************/


/***************************************************************
 *   Aufklappen der Umfrageergebnisse im Umfragearchiv ANFANG
 ***************************************************************/
var t = null;
function showDetailUmfrage(self, docid) {
  // Alle offenen Umfrageergebnisse schließen
    if (a != self) {
        if (a != null) {
            new Effect.BlindUp(
                $(a).nextSibling.getElementsByTagName('div')[0], {
                    afterFinish:function () {
                        $(a).parentNode.removeChild($(a).nextSibling);
                        requestUmfrage(self, docid);
                    }
                }
            );
        } else {
            requestUmfrage(self, docid);
        }
    }
    return false;
}

function requestUmfrage(link, docid) {
    var self = link.parentNode.parentNode.parentNode;
    a = self;
    var subDiv = document.createElement('div');
    subDiv.setAttribute('class', 'spieler_details_0');
    subDiv.setAttribute('className', 'spieler_details_0');
    subDiv.style.marginTop = "0px";
    subDiv.style.marginBottom = "0px";
    subDiv.style.paddingTop = "0px";
    subDiv.style.paddingBottom = "0px";
    subDiv.style.width = "410px";
    new Insertion.After(self, subDiv);

    var URI = window.location.href;
    if (URI.indexOf("#") > 0) {
        URI = URI.substr(0, URI.indexOf("#"));
    }
    new Ajax.Request(URI, {
        method:'post',
        parameters: {uid: docid},
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            subDiv.style.display = 'none';
            subDiv.innerHTML = response;
            Effect.BlindDown(subDiv, {});
        }
    });
    return false;
}
/***************************************************************
 *   Aufklappen der Umfrageergebnisse im Umfragearchiv ENDE
 ***************************************************************/


/***************************************************************
 *   Aufklappen der ChartVotingergebnisse ANFANG
 ***************************************************************/
var t = null;
function showDetailVote(self, docid) {
  // Alle offenen Votingergebnisse schließen
    if (a != self) {
        if (a != null) {
            new Effect.BlindUp(
                $(a).nextSibling.getElementsByTagName('div')[0], {
                    afterFinish:function () {
                        $(a).parentNode.removeChild($(a).nextSibling);
                        requestVote(self, docid);
                    }
                }
            );
        } else {
            requestVote(self, docid);
        }
    }
    return false;
}

function requestVote(link, docid) {
    var self = link.parentNode.parentNode.parentNode;
    a = self;
    var subDiv = document.createElement('div');
    subDiv.setAttribute('class', 'spieler_details_0');
    subDiv.setAttribute('className', 'spieler_details_0');
    subDiv.style.marginTop = "0px";
    subDiv.style.marginBottom = "0px";
    subDiv.style.paddingTop = "0px";
    subDiv.style.paddingBottom = "0px";
    subDiv.style.width = "410px";
    new Insertion.After(self, subDiv);

    var URI = window.location.href;
    if (URI.indexOf("#") > 0) {
        URI = URI.substr(0, URI.indexOf("#"));
    }
    new Ajax.Request(URI, {
        method:'post',
        parameters: {voteid: docid},
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            subDiv.style.display = 'none';
            subDiv.innerHTML = response;
            Effect.BlindDown(subDiv, {});
        }
    });
    return false;
}
/***************************************************************
 *   Aufklappen der ChartVotingergebnisse ENDE
 ***************************************************************/


/***************************************************************
 *   Aufklappen der Kurznews auf Aktuelles ANFANG
 ***************************************************************/
var a = null;
function showDetailNews(self, docid, tabelle) {
 // Alle offenen News schließen
    if (a != self) {
        if (a != null) {
            new Effect.BlindUp(
                $(a).nextSibling.getElementsByTagName('div')[0], {
                    afterFinish:function () {
                        $(a).parentNode.removeChild($(a).nextSibling);
                        requestNews(self, docid, tabelle);
                    }
                }
            );
        } else {
            requestNews(self, docid, tabelle);
        }
    }
    return false;
}

function requestNews(link, docid, tabelle) {
    var self = link.parentNode.parentNode;
    a = self;
    var subDiv = document.createElement('div');
    subDiv.setAttribute('class', 'inhalt2');
    subDiv.setAttribute('className', 'inhalt2');
    subDiv.setAttribute('id', 'shortnews');
    subDiv.style.marginTop = "0px";
    subDiv.style.marginBottom = "0px";
    subDiv.style.paddingTop = "0px";
    subDiv.style.paddingBottom = "0px";
    new Insertion.After(self, subDiv);

    var URI = window.location.href;
    if (URI.indexOf("#") > 0) {
        URI = URI.substr(0, URI.indexOf("#"));
    }
    new Ajax.Request(URI, {
        method:'post',
        parameters: {id: docid, dbtabelle: tabelle},
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            subDiv.style.display = 'none';
            subDiv.innerHTML = response;
            Effect.BlindDown(subDiv, {});
        }
    });
    return false;
}
/***************************************************************
 *   Aufklappen der Kurznews auf Aktuelles ENDE
 ***************************************************************/


/***************************************************************
 *   Auflistung der Spieler ANFANG
 ***************************************************************/
var act = null;

function showSpielerDetails(self, sid, kader, jugend) {
    // Alle offenen Details schließen
    if (act != self) {
        if (act != null) {
            $(act).parentNode.setAttribute('class', 'spieler');
            $(act).parentNode.setAttribute('className', 'spieler');
            new Effect.BlindUp(
                $(act).parentNode.getElementsByTagName('div')[0], {
                    afterFinish:function () {
                        $(act).parentNode.removeChild($(act).nextSibling);
                        requestDetails(self, sid, kader, jugend);
                    }
                }
            );
        } else {
            requestDetails(self, sid, kader, jugend);
        }
    }
    return false;
}

function requestDetails(link, sid, kader, jugend) {
    var self = link.parentNode.parentNode.parentNode.parentNode.parentNode;

    act = self;
    var subDiv = document.createElement('div');
    subDiv.setAttribute('class', 'spielerdetails');
    subDiv.setAttribute('className', 'spielerdetails');
    
    new Insertion.After(self, subDiv);
    $(self).parentNode.setAttribute('class', 'spieleraktiv');
    $(self).parentNode.setAttribute('className', 'spieleraktiv');

    var URI = window.location.href;
    if (URI.indexOf("#") > 0) {
        URI = URI.substr(0, URI.indexOf("#"));
    }

    new Ajax.Request(URI, {
        method:'post',
        parameters: {details: sid, mannschaft: kader, jugend: jugend},
        onSuccess: function(transport) {
            var response = transport.responseText || "no response text";
            subDiv.style.display = 'none';
            subDiv.innerHTML = response;
            Effect.BlindDown(subDiv, {});
        }
    });

    return false;
}
/***************************************************************
 *   Auflistung der Spieler ENDE
 ***************************************************************/


/***************************************************************
 *   Suche
 ***************************************************************/
var sI=null;
var ss;
var la;
var pa;
var bl;
function suche(begriff, lang, page, block) {
    if(begriff.length>2) {
     if(block >= 0) {
      bl=block;
     } else {
      bl = -1;
     }
        ss=escape(begriff);
        la=lang;
        pa=page;
        if(sI) window.clearInterval(sI);
        sI=window.setInterval("requestSuche();window.clearInterval(sI);", 300);
    }
}

function requestSuche() {
    var URI = "/scripte/suche.php";
    var pars = "search=" + ss + "&lang=" + la + "&page=" + pa + "&block=" + bl;
    new Ajax.Request(URI, {method:"post", postBody:pars, onComplete:showSearchResult});
}

function showSearchResult(request) {
    $('searchcontent').innerHTML=request.responseText;
    new Effect.Fade($('maincontent'), {afterFinish: function() {new Effect.Appear($('searchcontent'))}});
}

function createPageNav(s,e,m) {
    var pages = Math.ceil(m/10);
    var akt = Math.ceil(s/10);
    var d = document.createElement('div');
    d.style.marginTop="10px";
    d.style.marginBottom="10px";
    if(akt>0) {
        var l = document.createElement('a');
        l.href="javascript:;";
        l.onclick=showPage;
        l.title=akt;
        var l_t = document.createTextNode("<<");
        l.appendChild(l_t);
        d.appendChild(l);
    }
    for(var i=1; i<=pages; i++) {
        if(i != (akt+1)) {
            var l = document.createElement('a');
            l.href="javascript:;";
            l.onclick=showPage;
            l.title=i;
            var l_t = document.createTextNode(i);
        } else {
            var l = document.createElement('a');
            l.href="javascript:;";
            l.onclick=showPage;
            l.title=i;
            var l_t = document.createTextNode("["+i+"]");
        }
        l.appendChild(l_t);
        l.style.marginLeft="5px";
        d.appendChild(l);
    }
    if(akt+1<pages) {
        var l = document.createElement('a');
        l.href="javascript:;";
        l.onclick=showPage;
        l.title=akt+2;
        var l_t = document.createTextNode(">>");
        l.appendChild(l_t);
        l.style.marginLeft="5px";
        d.appendChild(l);
    }
    return d;
}
function showPage() {
    p=parseInt(this.title);
    cs.setOpts('p', p);
    cs.sendRequest();
    return false;
}
/***************************************************************
 *   Suche Ende
 ***************************************************************/



function MM_findObj(n, d) { //v4.0
 var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
 if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
    obj.display=v; }
}         
