/*******************************************************************************
**  Javascript Quelldatei zur Erzeugung des Tarrasch Kopfes
**  und der Menüsteuerung der Webseite des SK Tarrasch-1945 München
**
**  Autor: Frank Dymann, München
**  angepasst: Rainer Hutt
**         Email: spielleiter@tarrasch-muenchen.de
**
**     © 2005 SK Tarrasch-1945 München e.V.
**
*******************************************************************************/


/******************************************************************************/
function  Befehl ( text, href, imag, alt )

{
this.text = text;
this.href = href;
this.imag = imag;
this.alt  = alt;
}

/*******************************************************************************
**  aktuelle Felder in Steuerung
*******************************************************************************/
var acCurItems = new Array
  (
  new Befehl ( "DMM11/12", "/archiv/2011-2012/tarrasch1.htm ", "/admin/images/logos/Tarrasch1DSB.gif", "Logo DSB" ),
  new Befehl ( "BMM11/12", "/archiv/2011-2012/tarrasch2.htm ", "/admin/images/logos/Tarrasch2BSBLl.gif", "Logo BSB" ),
  new Befehl ( "KM2012", "/archiv/2011-2012/km_2011_2012/km_index.htm ", "/admin/images/Logos/kmlogo.gif", "Logo KM" ),
  new Befehl ( "ST2011", "/archiv/2010-2011/st_2011/st_2011_index.htm ", "/admin/images/Logos/st_unzicker_logo.gif", "Logo Sommerturnier" ),
  new Befehl ( "MMM2011", "/archiv/2010-2011/mmm_2011/mmm2011.htm ", "/archiv/2010-2011/mmm_2011/mmm2011.gif", "Logo MMM" )
    );

/*******************************************************************************
**  feste Felder in Steuerung
*******************************************************************************/
var acFixItems = new Array
  (
  new Befehl ( "Jugend",        "/archiv/2010-2011/jugend/tjugend.htm", "/bilder/msiggi.gif", "Jugendsiggi" ),
  new Befehl ( "Weihnachts Schnellturnier",        "/archiv/2011-2012/wt_2011/wt_2011_index.htm", null, null ),
  new Befehl ( "Aktuell",       "/index.htm",         null, null ),
  new Befehl ( "Verein",        "/verein/verein.htm", null, null ),
  new Befehl ( "DWZ &amp; Elo", "http://www.schachbund.de/dwz/db/verein.html?zps=22002",    null, null ),
  new Befehl ( "Termine",       "/archiv/2011-2012/termine2.htm",  null, null ),
  new Befehl ( "Links",         "/links/links.htm",   null, null ),
  new Befehl ( "Archiv",        "/archiv/archiv.htm", null, null )
  );

/*******************************************************************************
**  Druckansicht
*******************************************************************************/


/******************************************************************************/
function  FindElemId ( id )

{
if  ( document.getElementById )
  return  document.getElementById(id);

if  ( document.all )
  return document.all[id];

return  null;
}


/******************************************************************************/
function  FindElemsTag ( tag )

{
if  ( document.getElementsByTagName )
  return  document.getElementsByTagName(tag)

if  ( document.all )
  return document.all.tags(tag);

return  null;
}


/******************************************************************************/
function  FindElemClass ( tag, typ )

{
allElems = FindElemsTag ( tag );
i = 0;
while  ( ( allElems[i].className != typ ) && ( i < 100 ) )  // i<100: Notbremse
  {
  i++;
  }
return  allElems[i];
}


/******************************************************************************/
function  HideElem ( el )

{
if  ( el )
  {
  el.style.visibility = "hidden";
  el.style.overflow   = "hidden";
  el.style.height     = "0";
  el.style.width      = "0";
  }
}


/******************************************************************************/
function  Drucksicht()

{
// Nicht druckbare Elementr verstecken
HideElem ( FindElemId ( "Kopf" ) );
HideElem ( FindElemId ( "Menu" ) );
HideElem ( FindElemId ( "Fuss" ) );
HideElem ( FindElemId ( "drform" ) );
HideElem ( FindElemClass ( "div", "logo" ) );

divBasis   = FindElemClass ( "div", "basis" );
divAusgabe = FindElemClass ( "div", "ausgabe" );

divBasis.style.background = "#FFFFFF";
divBasis.style.top = "0";
divAusgabe.style.background = "#FFFFFF";
divAusgabe.style.marginLeft = "0";
}



/*******************************************************************************
**   Funktion ExprInStyleAllowd:
**        Prüft ob "expression" in Stilen erlaubt ist
**        Das ist nur bei IE ab 5.5 möglich und wird benutzt um
**        "position:fixed" im IE zu realisieren
*******************************************************************************/
function  ExprInStyleAllowd()

{
var  j, sVer;
if  ( window.innerWidth )
  return  false;  // ist gar kein IE, so könne wir nicht reingelegt werden

// Nun noch rauskriegen, ob Vers. >= 5.5
sVer = navigator.appVersion;
j = sVer.search ( /MSIE/ );
if  ( j > 0 )
  {
  // ab V5.5 unterstützt IE expression() in Stilen
  if  ( Number ( sVer.substr ( j+5, 3 ) ) >= 5.5 )
    return true;
  return false; // war nix
  }

return false;
}


/*******************************************************************************
**   Funktion GenInnerWidth: Innere Breite des Fensters unabh. vom Brauser
*******************************************************************************/
function  GenInnerWidth()

{
if ( window.innerWidth ) // all except Explorer
  return  window.innerWidth;
else if ( document.documentElement && document.documentElement.clientWidth )  // Explorer 6 Strict Mode
  return  document.documentElement.clientWidth;
else if  ( document.body ) // other Explorers
  return  document.body.clientWidth;
}


/******************************************************************************/
function  Flipp()

{
window.setTimeout ( "Wecke()", 1000 * ( 30 * Math.random() + 30 ) );
document.getElementById("Kopf").className = "rkopf";
}


/******************************************************************************/
function  Wecke()

{
document.getElementById("Kopf").className = "rkopf-i";
window.setTimeout ( "Flipp()", 400 );
}


/*******************************************************************************
**   Funktion AddMenuItems: Baut kontextabhängig das Steuermenü auf
*******************************************************************************/
function  AddMenuItems()

{
/* aktuelle Items */
for  ( i = 0; i < acCurItems.length; i++ )
  if  ( ( acCurItems[i].imag == null ) || !this.fPicsInMenu )
    document.writeln ( this.sItemProlog + acCurItems[i].href + "\">" + acCurItems[i].text + this.sItemEpilog );
  else
    document.writeln ( this.sItemProlog + acCurItems[i].href + "\"><img src=\"" + acCurItems[i].imag + "\" alt=\"" + acCurItems[i].alt + "\">" + this.sItemEpilog );

/* fixe Items */
for  ( i = 0; i < acFixItems.length; i++ )
  if  ( ( acFixItems[i].imag == null ) || !this.fPicsInMenu )
    document.writeln ( this.sItemProlog + acFixItems[i].href + "\">" + acFixItems[i].text + this.sItemEpilog );
  else
    document.writeln ( this.sItemProlog + acFixItems[i].href + "\"><img src=\"" + acFixItems[i].imag + "\" alt=\"" + acFixItems[i].alt + "\">" + this.sItemEpilog );
}



/*******************************************************************************
**   Funktion FootLine: Ausgabe der Fußzeile
*******************************************************************************/



/*******************************************************************************
** Funktion Design2Frame: Baut das Gerüst für Seiten im Design 2 Stil
*******************************************************************************/
function Design2Frame()

{
// Ausgabe des Standardkopfes für Design 2
document.writeln ( "<div class=\"rkopf\" id=\"Kopf\">" );
document.writeln ( "<div class=\"pos-ur\">" );
document.writeln ( "        Der Verein wird gef&ouml;rdert durch " );
document.writeln ( "        <a href=\"http://www.interface-ag.com\" target=\"_blank\"><img src=\"/admin/images/Logos/InterFace-Logo_neu.jpg\" alt=\"Logo IF neug\"><\/a>" );
document.writeln ( "    <\/div>" );
document.writeln ( "    <div class=\"pos\" style=\"left:40px;width:560px\">" );
document.writeln ( "        <p class=\"linksb\">Willkommen auf den Seiten des Schachklubs<\/p>" );
document.writeln ( "        <p class=\"zentr\"><img src=\"/admin/images/Texte/tarrasch_txt.gif\" alt=\"Tarrasch-1945 München e.V.\"><\/p>" );
document.writeln ( "    <\/div>" );
document.writeln ( "<\/div>" );

// Ausgabe des Steuerfensters für Design 2
document.writeln ( "<div class=\"rmenu\" id=\"Menu\">" );
this.AddMenuItems();
document.writeln ( "    <div style=\"background:#FFFCEF\"><img src=\"/admin/images/Rahmen/graf1.jpg\" alt=\"grafischer Abschluss\" width=\"120px\"><\/div>" );
document.writeln ( "<\/div>" );

// Fusszeile
FootLine();

// Seite druckbar?
var printDefElem = document.getElementsByName("druckbar")[0];  // sollte sein meta
if  ( printDefElem && printDefElem.content && ( printDefElem.content == "ja" ) )
  {
  // Dann den Druckbutton ausgeben
  document.writeln ( "<form id=\"drform\" action=\"/verein/verein.htm\" style=\"position:absolute;right:5px;top:105px;z-index:20\">" );
  document.writeln ( "  <div>" );
  document.writeln ( "    <button id=\"drbutt\" type=\"button\" onclick=\"Drucksicht();\">" );
  document.writeln ( "      <p><img src=\"/admin/images/Grafik/druckansicht.gif\" alt=\"Druckansicht\"></p>" );
  document.writeln ( "    </button>" );
  document.writeln ( "  </div>" );
  document.writeln ( "</form>" );
  }

// Timer starten für Schabernack
window.setTimeout ( "Wecke()", 1000 * ( 30 * Math.random() + 30 ) );
}


/*******************************************************************************
** Funktion ClassicFrame: Baut das Gerüst für Seiten im klassischen Design
*******************************************************************************/
function ClassicFrame()

{
// Ausgabe des Kopfes für klassisches Design
document.writeln ( "<div class=\"rkopf\">" );
document.writeln ( "    <div class=\"bild_rechts\"><img src=\"/bilder/IF1.gif\" alt=\"Logo InterFace AG\"><\/div>" );
document.writeln ( "    <p>Willkommen auf der Webseite des Schachklubs<\/p>" );
document.writeln ( "    <p style=\"text-align:center\"><img src=\"/bilder/tarrasch.gif\" alt=\"Tarrasch-1945 M&uuml;nchen e.V.\"><\/p>" );
document.writeln ( "    <p style=\"text-align:right\">powered by InterFace AG ... the face of informatics.<\/p>" );
document.writeln ( "<\/div>" );

// Ausgabe des Menübalken für klassisches Design
document.writeln ( "<div class=\"rmenu\">" );
this.AddMenuItems();
document.writeln ( "<\/div>" );

// Fusszeile
FootLine();
}


/******************************************************************************/
function TarraschFrame()

{
// Konstruktor: den Designtyp bestimmen und Weichen stellen
var typDefElem = document.getElementsByName("design")[0];  // sollte sein meta
if  ( typDefElem && typDefElem.content && ( typDefElem.content == "typ2" ) )
  {
  // Typ = Design 2
  this.Create = Design2Frame;
  this.sItemProlog = "<p class=\"rmenu\"><a class=\"rmenu\" href=\"";
  this.sItemEpilog = "<\/a><\/p>";
  this.fPicsInMenu = true;
  }
else
  {
  // Typ = Classic Design
  this.Create = ClassicFrame;
  this.sItemProlog = "<a class=\"rmenu\" href=\"";
  this.sItemEpilog = "<\/a>";
  this.fPicsInMenu = false;  // keine Bilder im klassischen Menü
  }

this.AddMenuItems = AddMenuItems;
}


/*******************************************************************************
**   Beginn des Hauptkode
*******************************************************************************/
var curFrame = new TarraschFrame();
curFrame.Create();


/*******************************************************************************
**   Funktionen zur Verschlüsselung von eMail-Adressen
*******************************************************************************/
function UnCryptMailto( s )
{
    var n = 0;
    var r = "";
    for( var i = 0; i < s.length; i++)
    {
        n = s.charCodeAt( i );
        if( n >= 8364 )
        {
            n = 128;
        }
        r += String.fromCharCode( n - 1 );
    }
    return r;
}

function linkTo_UnCryptMailto( s )
{
    location.href=UnCryptMailto( s );
}
