// Fanfarenzug Schwarzenberger Herolde, Waldkirch
// Roland Siehl
// 07/25/04

var at = String.fromCharCode(64);
var domain = "herolde-waldkirch.de";

var uteS = new oPrsItm("a", "46", "", "Siehl-Hildebrandt", "Ute", "Glimpenheimer Str.", "29", "79312", "Emmendingen-Wasser", "Vorstand", "7641", "8468", "HW", "", "");
var stefanM = new oPrsItm("a", "31", "", "Mack", "Stefan", "Langestr.", "63", "79183", "Waldkirch", "Vorstand", "7661", "9666", "HW", "", "");
var danielH = new oPrsItm("a", "25", "", "Hergarten", "Daniel", "Jahnstr.", "2", "79183", "Waldkirch", "Vorstand", "7681", "409943", "HW", "", "");
var wolfgangS = new oPrsItm("a", "40", "", "Scheuch", "Wolfgang", "Siensbacher Str.", "14", "79183", "Waldkirch", "Technischer Leiter", "7681", "494583", "HW", "0171-1225416", "");
var carmenS = new oPrsItm("a", "41", "", "Schmieder", "Carmen", "Schlößlestr.", "22", "79183", "Waldkirch", "Schriftführerin", "7681", "1744", "HW", "", "");
var alexR = new oPrsItm("a", "37", "", "Rösch", "Alexandra", "Gartenstr.", "1", "79183", "Waldkirch", "Kassiererin", "7681", "24596", "HW", "", "");
var thomasW = new oPrsItm("a", "58", "", "Wölfle", "Thomas", "Hermann-Rambach-Weg", "9", "79153", "Waldkirch", "Musikalischer Leiter", "", "", "HW", "0177-8891799", "");
var uteWS = new oPrsItm("a", "57", "", "Wernet-Schonhard", "Ute", "St.-Margarethen-Str.", "17", "79183", "Waldkirch", "Festwirtin", "7681", "25859", "HW", "", "");
var maddalenaB = new oPrsItm("a", "11", "", "Braccio", "Maddalena", "Langefurt", "1", "79183", "Waldkirch", "Jugendleiterin", "7681", "4939666", "HW", "", "");
var danielF = new oPrsItm("a", "21", "", "Fuchs", "Benedikt", "Kiefernweg", "5", "79183", "Waldkirch", "", "7681", "25321", "", "", "");

var lPrsTel = "n";
var lPrsHdy = "n";

var winImg;
var winPrs = null;
var sHint="off";
var iHintScreenSize = 1024;

// generic function for printout of person parameter
function fPrsPar(sCtl)
{
  if (sCtl=="Mail")
  {
    document.write('<a href=\"mailto:' + this.mail + '\">' + this.mail + '</a>');
  }
  if (sCtl=="Addr")
  {
    document.write(this.street + ' ' + this.house + '<br />' + this.zip + ' ' + this.town);
  }
  if (sCtl=="Tel")
  {
    document.write(this.tel);
  }
}


// personal functions for compatibility to previous versions
function fUte(sCtl)
{
  uteS.fPrsPar(sCtl);
}
function fStefan(sCtl)
{
  stefanM.fPrsPar(sCtl);
}
function fDaniel(sCtl)
{
  danielH.fPrsPar(sCtl);
}
function fWolfgang(sCtl)
{
  wolfgangS.fPrsPar(sCtl);
}

// opens new window with image with given size by parameter
function viewImg (file,wid,hgt,tit,tim)
{
  var height = hgt+30;
  var width = wid+5;

  if (winImg) winImg.close();

  winImg = window.open("", "Bildfenster", "width="+width+", height="+height+", menubar=no, toolbar=no, location=no, scrollbars=no, status=no, dependent=yes");
  winImg.document.write('<html><head><title>' + tit + ' Fanfarenzug Schwarzenberger Herolde - Waldkirch</title></head><body style="margin-left:0px;margin-top:0px;">');
  winImg.document.write('<table border=0><tr><td background="../images/' + file + '" style="background-repeat:no-repeat;">');
  winImg.document.write('<img src="../images/overlay.gif" width='+wid+' height='+hgt+' alt="'+tit+'"></td></tr>');
  if (tim>0)
  {
    winImg.document.write('<tr><td align=left>Fenster wird nach '+ tim +' Sekunden geschlossen.</td></tr></table>');
    winImg.document.write('</body></html>');
    winImg.setTimeout('window.close()',tim*1000);
  }
  else
  {
    winImg.document.write('<tr><td align=right><a href="javascript:window.close();">Fenster schliessen</a></td></tr></table>');
    winImg.document.write('</body></html>');
  }
}

function openPrsFrm(iData) {
// opens new window with person data and image
  var sOut = '';

  if (winPrs) winPrs.close();

  winPrs = window.open("", "Personendaten", "width=350, height=320, menubar=no, toolbar=no, location=no, scrollbars=yes, status=no, dependent=yes");

  sOut = sOut + '<html><head><title>Fanfarenzug Schwarzenberger Herolde - Waldkirch</title></head><body background="../images/bgr02b.gif"style="margin-left:0px;margin-top:0px;">';

  sOut = sOut + '<table border=0  style="background-repeat:repeat;left:10px;margin:10px;">';
  sOut = sOut + '<tr><td><b>'+ aoPrs[iData].vname + ' '+ aoPrs[iData].name +'</b>&nbsp&nbsp;'+aoPrs[iData].func +'</td></tr>';
 // sOut = sOut + '<tr><td>&nbsp;</td></tr>';

  sOut = sOut + '<tr><td>'+ aoPrs[iData].street + '   ' + aoPrs[iData].house +'</td></tr>';
  sOut = sOut + '<tr><td>'+ aoPrs[iData].zip + '  ' + aoPrs[iData].town +'</td></tr>';

  sOut = sOut + '<tr><td>'+ aoPrs[iData].tel +'</td></tr>';
  sOut = sOut + '<tr><td>'+ aoPrs[iData].handy +'</td></tr>';
  sOut = sOut + '<tr><td>'+ aoPrs[iData].mail +'</td></tr>';
  sOut = sOut + '<tr><td><img src="../images/'+ aoPrs[iData].img +'"width=80 height=100></td></tr>';

  sOut = sOut + '<tr><td>&nbsp;</td></tr>';

  sOut = sOut + '<tr><td><a href="javascript:window.close();">Fenster schliessen</a></td></tr></table>';
  sOut = sOut + '</body></html>';

  winPrs.document.write(sOut);
}

function fPrs(aoPrs)
// output of person list as table in same window
{
  var sOut = '';
  var ii = 0;

    for (ii=0; ii<aoPrs.length; ii++)
    {
      if (aoPrs[ii].type=="a" || aoPrs[ii].type=="p" || aoPrs[ii].type=="e")
      {
        sOut = '<tr><td class="liste">'+ aoPrs[ii].nr +'</td>';
        sOut = sOut + '<td class="liste">'+ aoPrs[ii].name +'</td>';
        sOut = sOut + '<td class="liste">'+ aoPrs[ii].vname +'</td>';
        sOut = sOut + '<td class="liste">'+ aoPrs[ii].func +'</td>';
        sOut = sOut + '<td class="liste"><a href="javascript:openPrsFrm('+ ii +')"><img src="../images/i.gif" height=16 width=16 border=0 alt="' + aoPrs[ii].name + '"></a></td>';
        sOut = sOut + '<td class="liste">';
        if (aoPrs[ii].mail !="")
        {
          sOut = sOut + '<a href=\"mailto:';
          sOut = sOut + aoPrs[ii].mail + '\">';
          sOut = sOut + aoPrs[ii].mail + '</a>';
        }
        sOut = sOut + '&nbsp;</td>';
        if (lPrsTel=="y")
        {
          sOut = sOut + '<td class="termine">'+ aoPrs[ii].tel +'</td>';
        }
        if (lPrsHdy=="y")
        {
          sOut = sOut + '<td class="termine">'+ aoPrs[ii].handy +'</td></tr>\r';
        }
      }
      if (aoPrs[ii].type=="T")
      {
        sOut = '<tr><td class="htermine">'+ aoPrs[ii].nr +'</td>';
        sOut = sOut + '<td class="htermine">'+ aoPrs[ii].name +'</td>';
        sOut = sOut + '<td class="htermine">'+ aoPrs[ii].vname +'</td>';
        sOut = sOut + '<td class="htermine">'+ aoPrs[ii].func +'</td>';
        sOut = sOut + '<td class="htermine">&nbsp;</td>';
        sOut = sOut + '<td class="htermine">'+ aoPrs[ii].mail +'</td>';
        if (lPrsTel=="y")
        {
          sOut = sOut + '<td class="termine">'+ aoPrs[ii].tel +'</td>';
        }
        if (lPrsHdy=="y")
        {
          sOut = sOut + '<td class="termine">'+ aoPrs[ii].handy +'</td></tr>\r';
        }
      }
      if (aoPrs[ii].type=="S")
      {
        sOut = '<tr><td colspan="8">&nbsp;</td></tr>\r';
      }

      document.write(sOut);
    }
}


// Constructor for list of persons
//
function oPrsItm (type,nr,title,name,vname,street,house,zip,town,func,vw,tel,mail,handy,telgesch,heroldemail)
{
  this.nr = nr;
  this.title = title;
  this.name = name;
  this.vname = vname;
  this.func = func || "&nbsp;";

  // replace german umlauts in name
  sTmp = vname + "." + name;
  sTmp = sTmp.toLowerCase();
  while (sTmp.indexOf("ä")>-1)
  {
    sTmp = sTmp.replace(/ä/, "ae");
  }
  while (sTmp.indexOf("ö")>-1)
  {
    sTmp = sTmp.replace(/ö/, "oe");
  }
  while (sTmp.indexOf("ü")>-1)
  {
    sTmp = sTmp.replace(/ü/, "ue");
  }

  // image name = vname+name.jpg without dots and german umlauts
  this.img = sTmp.replace(/\./, "") + ".jpg";

  // create e-mailaddress for herolde-waldkirch
  if (mail=="HW") {
    this.mail = sTmp + at + domain;
  } else {
    this.mail = mail;
  }
  this.tel = "0" + vw + "-" + tel;
  this.handy = handy || "&nbsp;";
  this.type = type;

  this.street = street;
  this.house = house;
  this.zip = zip;
  this.town = town;

  this.fPrsPar = fPrsPar;
  this.telgesch = telgesch;
  this.heroldemal = heroldemail;
}

// functions to show or hide side menu and side footer
function fSidemenu(sFnc)
{
  var oSMenu;

  if (sFnc=="normal")
  {
    oSMenu = document.getElementById("ssidemenu");
    oSMenu.style.visibility="hidden";
    oSMenu = document.getElementById("sidemenu");
    oSMenu.style.visibility="visible";
    oSMenu = document.getElementById("footer");
    oSMenu.style.visibility="visible";
  }
  if (sFnc=="small")
  {
    oSMenu = document.getElementById("sidemenu");
    oSMenu.style.visibility="hidden";
    oSMenu = document.getElementById("ssidemenu");
    oSMenu.style.visibility="visible";
    oSMenu = document.getElementById("footer");
    oSMenu.style.visibility="hidden";

    fSMHintOff();
  }
}

// functions for hint to button for hiding/showing side menu
function fSMHintOff()
{
  var oSMHint;

  if (sHint=="on")
  {
    oSMHint = document.getElementById("smhint");
    oSMHint.style.visibility="hidden";

    sHint="off";
  }
}

function fSMHint()
{
  var oSMHint;

  if (screen.width<iHintScreenSize )
  {
    if (sHint=="off")
    {
      if(navigator.cookieEnabled == true)
      {
        if (!getCookie("MenuHint"))
        {
          oSMHint = document.getElementById("smhint");
          oSMHint.style.visibility="visible";

          sHint="on";

          window.setTimeout('fSMHintOff()',20000);

          setCookie("MenuHint", "1", 60);
        }
// expires instantly        setCookie("MenuHint", "1", 0);
      }
    }
  }
}

// write hint for menu button
function fSMHintWrite()
{
 var sOut = '';

  if (screen.width<iHintScreenSize )
  {
    sOut = '<div id="smhint" class="smhint" title="Hinweis">';
    sOut = sOut + '<table  border=0 margin=5px>';
    sOut = sOut + '<tr>';
    sOut = sOut + '<td border=0 valign="top"><img src="../images/hint_01.gif"></td>';
    sOut = sOut + '<td width=400  class="smhint" text-align="left">';
    sOut = sOut + '<img src="../images/close.gif" width="16" height="16" align="right"';
    sOut = sOut + ' border="0" onClick="fSMHintOff();">';
    sOut = sOut + 'Hinweis: bei einer Bildschirmauflösung kleiner als 1024x768 ';
    sOut = sOut + 'kann das Menü den Haupttext verdecken.<br />';
    sOut = sOut + 'In diesem Fall können Sie mit dem Knopf<br />';
    sOut = sOut + '<img src="../images/menu_s.jpg" width="20" height="20" align="left" border="0">';
    sOut = sOut + 'das Menü verkleinern.</td>';
    sOut = sOut + '</tr></table>';
    sOut = sOut + '</div>';

    document.write (sOut);
  }
}

// functions for cookie operations
function setCookie(sName, sValue, iExpiresIn) {
  // P1  sName      Name of cookie
  // P2  sValue     Value of cookie
  // P3  iExpiresIn Number of days when cookie expires (0=instantly)

  var expires = new Date();
  var expiresAt = expires.getTime() + (iExpiresIn * 24 * 60 * 60 * 1000);
  expires.setTime(expiresAt);
  document.cookie = sName + '=' + escape(sValue) +
    ((iExpiresIn == null) ? "" : ("; expires=" + expires.toGMTString()));
}

function getCookie(sName) {
  var  sSearchFor = sName + '=';
  if (document.cookie.length > 0) { // are there any cookies?
    iOffset = document.cookie.indexOf(sSearchFor);
    if (iOffset != -1) {
      iOffset += sSearchFor.length;
      iEnd = document.cookie.indexOf(';', iOffset);
      if (iEnd == -1) {
        iEnd = document.cookie.length;
      }
      return unescape(document.cookie.substring(iOffset, iEnd));
    }
  }
}
