/*
 * Author: Herbert Baier - baier@itbaier.de
 * 
 * Set font size with cookie.
 *
 * Date: Tue Nov 18 16:56:30 CET 2008
 */
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("ffwinterhausenstyle");
  var emStep = cookie ? parseInt(cookie) : 0;

  fontSizer(0, false);
}

window.onunload = function(e) {
  createCookie("ffwinterhausenstyle", emStep, 365);
}

var cookie = readCookie("ffwinterhausenstyle");

var emStepWidth = 0.125;				// increase/decrease font every step by emStepWidth
var emBasis 	= 0.85;					// font size of body at startup
var emStep 	= cookie ? parseInt(cookie) : 0;	// counter for current step (leave as 0)
var emMaxSteps 	= 2;					// maximum steps alowed
/**
* fontSizer increase/decrease font size inside "emStep"
*
* use: fontSizer(1, false), fontSizer(-1, false) or fontSizer(0, true)
* @param inc set to 1 or -1
* @param reset set to true to get initial font size
*/
function fontSizer(inc, reset) {
  // reset font size
  if (reset)
      emStep = 0;
  // inside allowed steps?
  if (Math.abs(emStep + inc) <= emMaxSteps) {
     // increase/decrease emStep
     emStep += inc;

     // set new font size for every tag inside "emStep"
     emFontSize = emStep * emStepWidth + emBasis;

     //get content
     emBody = document.getElementById('contents');
     // set new fot size
     emBody.style.fontSize = emFontSize + "em";

  }
  if (emStep == -emMaxSteps) {
      document.getElementById("fontsizeMinus").src = "images/fontsizeMinus_lo.jpg";
  }
  else if (emStep == emMaxSteps) {
      document.getElementById("fontsizePlus").src = "images/fontsizePlus_lo.jpg";
  }
  else {
      document.getElementById("fontsizePlus").src = "images/fontsizePlus.jpg";
      document.getElementById("fontsizeMinus").src = "images/fontsizeMinus.jpg";
  }
} 

/*
 * Write font size script.
 */

function writeFontSize(prefix){
	document.write(prefix);
	document.write("<a href=\"javascript:void(0)\" onmousedown=\"fontSizer(-1, false)\" onfocus=\"blur()\"><img src=\"images/fontsizeMinus.jpg\" id=\"fontsizeMinus\" align=\"absmiddle\"></a><a href=\"javascript:void(0)\" onmousedown=\"fontSizer(1, false)\" onfocus=\"blur()\"><img src=\"images/fontsizePlus.jpg\" id=\"fontsizePlus\" align=\"absmiddle\"></a>");
}

/*
 * Write Bookmark script. If it is supported. i.e. Firefox, opera or IE, it will be added.
 */

function writeBookmark(url, title, message){
    if (window.sidebar || (window.opera && window.print) || document.all) {
	document.write("&ensp;<a href=\"javascript:bookmark('" + url + "','" + title + "');\" title='" + message + "' onfocus=\"blur()\"><img src=\"images/bookmark.gif\" alt=\"Bookmark this page\" name=\"bookmark\" align=\"absmiddle\" border=\"0\"></a>");
    }
}

function bookmark(url, title){
    if(window.sidebar) { // Firefox
	window.sidebar.addPanel(title, url,'');
    } else  if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
    } else if(document.all) { // IE
	window.external.AddFavorite(url, title);
    }
}

/*
 * Head.
 */

function writeHead(){
    document.write("<div id=\"header\"><div class=\"left\"></div> <div id=\"siteTitle\"><h1>Freiwillige Feuerwehr Winterhausen</h1><h2>Leben retten, Br&auml;nde l&ouml;schen, G&uuml;ter bergen, Umwelt sch&uuml;tzen</h2></div><div class=\"right\"></div><div class=\"wap\"></div></div>");
}

/*
 * Footnote.
 */

function writeFootnote(){
    document.write("<div id=\"footer\"><p>&copy; 2008 - 2011 Freiwillige Feuerwehr Winterhausen</p><p><img src=\"http://www.ff-winterhausen.de/cgi-std/count.pl?c=1&d=tube\" height=12 border=\"0\" align=\"absmiddle\" > Besucher seit Juli 2008</p><p>Entwickelt von <a href=\"http://www.itbaier.de/de/\" target=\"_blank\" onfocus=\"blur()\">itbaier</a></p></div>");
}

/*
 * Information about the visitor's browser.
 */
function detectBrowser_de() {
    detectBrowser("Diese Seite wird nicht korrekt angezeigt, da Ihre Version von Microsofts Internet Explorer unterst&uuml;tzt nicht alle Seitenlayout-Eigenschaften. Der Internet Explorer 7.0 (oder neuere Version) ist erforderlich.");
}

function detectBrowser(messageIE6) {
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName  = navigator.appName;
    var fullVersion  = ''+parseFloat(navigator.appVersion); 
    var majorVersion = parseInt(navigator.appVersion,10);
    var nameOffset,verOffset,ix;

    // In MSIE, the true version is after "MSIE" in userAgent
    if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
	browserName = "Microsoft Internet Explorer";
	fullVersion = nAgt.substring(verOffset+5);
    }
    // In Opera, the true version is after "Opera" 
    else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
	browserName = "Opera";
	fullVersion = nAgt.substring(verOffset+6);
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
	browserName = "Chrome";
	fullVersion = nAgt.substring(verOffset+7);
    }
    // In Safari, the true version is after "Safari" 
    else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
	browserName = "Safari";
	fullVersion = nAgt.substring(verOffset+7);
    }
    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
	browserName = "Firefox";
	fullVersion = nAgt.substring(verOffset+8);
    }
    // In most other browsers, "name/version" is at the end of userAgent 
    else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
	browserName = nAgt.substring(nameOffset,verOffset);
	fullVersion = nAgt.substring(verOffset+1);
	if (browserName.toLowerCase()==browserName.toUpperCase()) {
	    browserName = navigator.appName;
	}
    }

    // trim the fullVersion string at semicolon/space if present
    if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
    if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

    majorVersion = parseInt(''+fullVersion,10);
    if (isNaN(majorVersion)) {
	fullVersion  = ''+parseFloat(navigator.appVersion); 
	majorVersion = parseInt(navigator.appVersion,10);
    }

    // writeBrowserName(browserName,fullVersion,majorVersion);

    if (browserName=="Microsoft Internet Explorer" && parseFloat(fullVersion) < 7) {
	document.write("<p class=\"error\">" + messageIE6 + "</p><br/>");
    }
}

/*
 * Main menus.
 */

function writeMainMenu(option) {
    writeMainMenuLang("Willkommen", "Fahrzeuge", "Unsere Mannschaft", "HvO - Helfer vor Ort", "Jugendfeuerwehr", "Einsatz&uuml;bersicht", "Termine", "Bilder", "Kontakt", option);
}

function writeMainMenuLang(welcome, autos, team, firstResponder, young, firefighting, appointment, pictures, contact, option) {
    document.write("<div id=\"mainNavigation\"><div class=\"left\"></div><ul>");

    if (option=="welcome") {
	document.write("<li class=\"activeLeft\">" + welcome + "</li>");
    } else {
 	document.write("<li class=\"inactiveLeft\"><a href=\"index.html\">" + welcome + "</a></li>");
    }
   
    if (option=="autos") {
	document.write("<li class=\"active\">" + autos + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"fahrzeuge.html\">" + autos + "</a></li>");
    }
   
    if (option=="team") {
	document.write("<li class=\"active\">" + team  + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"mannschaft.html\">" + team + "</a></li>");
    }
   
     if (option=="firstResponder") {
	document.write("<li class=\"active\">" + firstResponder + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"hvo.html\">" + firstResponder + "</a></li>");
    }
   
   if (option=="young") {
	document.write("<li class=\"active\">" + young + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"jugend.html\">" + young + "</a></li>");
    }
   
    if (option=="firefighting") {
	document.write("<li class=\"active\">" + firefighting + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"e-2012.html\">" + firefighting + "</a></li>");
    }
   
    if (option=="appointment") {
	document.write("<li class=\"active\">" + appointment + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"termine.html\">" + appointment + "</a></li>");
    }
   
    if (option=="pictures") {
	document.write("<li class=\"active\">" + pictures + "</li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"bilder-2011.html\">" + pictures + "</a></li>");
    }
   
    if (option=="contact") {
	document.write("<li class=\"active\">" + contact + "</li><li class=\"lastActive\"></li>");
    } else {
 	document.write("<li class=\"inactive\"><a href=\"kontakt.html\">" +contact + "</a></li><li class=\"lastInactive\"></li>");
    }
   
   document.write("</ul><div class=\"right\">");
   document.write("<a href=\"http://www.draeger.com/fww\" target=\"_blank\"><img src=\"images/draeger-3helme-2011.png\"/></a>");
   document.write("</div></div>");
}

/*
 * Sub menus.
 */

function writeSubMenuWelcome(option) {
    writeSubMenuWelcomeLang("Home", "Begr&uuml;&szlig;ung", "Links", "G&auml;stebuch", "Impressum", option);
}

function writeSubMenuWelcomeLang(home, greeting, links, guestbook, imprint, option) {
    writeSubMenuPrefix();

    if (option=="home") {
	document.write("<span class=\"selected\">" + home + "</span>");
    } else {
 	document.write("<a href=\"index.html\">" + home + "</a>");
    }
   
    document.write(" | ");

    if (option=="greeting") {
	document.write("<span class=\"selected\">" + greeting + "</span>");
    } else {
 	document.write("<a href=\"begruessung.html\">" + greeting + "</a>");
    }
   
    document.write(" | ");

    if (option=="links") {
	document.write("<span class=\"selected\">" + links + "</span>");
    } else {
 	document.write("<a href=\"links.html\">" + links + "</a>");
    }
   
    document.write(" | ");

    if (option=="guestbook") {
	document.write("<span class=\"selected\">" + guestbook + "</span>");
    } else {
 	document.write("<a href=\"gaestebuch.html\">" + guestbook + "</a>");
    }
   
    document.write(" | ");

    if (option=="imprint") {
	document.write("<span class=\"selected\">" + imprint + "</span>");
    } else {
 	document.write("<a href=\"impressum.html\">" + imprint + "</a>");
    }

    writeSubMenuSuffix();
}

function writeSubMenuAutos(option) {
    writeSubMenuAutosLang("&Uuml;berblick", "TLF 16/25", "LF 8", "MZF", "MZB", option);
}

function writeSubMenuAutosLang(overview, tlf_16_25, lf_8, mzf, mzb, option) {
    writeSubMenuPrefix();

    if (option=="overview") {
	document.write("<span class=\"selected\">" + overview + "</span>");
    } else {
 	document.write("<a href=\"fahrzeuge.html\">" + overview + "</a>");
    }
   
    document.write(" | ");

    if (option=="tlf_16_25") {
	document.write("<span class=\"selected\">" + tlf_16_25 + "</span>");
    } else {
 	document.write("<a href=\"tlf16-25.html\">" + tlf_16_25 + "</a>");
    }

    document.write(" | ");

    if (option=="lf_8") {
	document.write("<span class=\"selected\">" + lf_8 + "</span>");
    } else {
 	document.write("<a href=\"lf8.html\">" + lf_8 + "</a>");
    }

    document.write(" | ");

    if (option=="mzf") {
	document.write("<span class=\"selected\">" + mzf + "</span>");
    } else {
 	document.write("<a href=\"mzf.html\">" + mzf + "</a>");
    }

    document.write(" | ");

    if (option=="mzb") {
	document.write("<span class=\"selected\">" + mzb + "</span>");
    } else {
 	document.write("<a href=\"mzb.html\">" + mzb + "</a>");
    }

    writeSubMenuSuffix();
}

function writeSubMenuTeam(option) {
    writeSubMenuTeamLang("Vorstandschaft", "Aktive Mitglieder", option);
}

function writeSubMenuTeamLang(executiveCommittee, members, option) {
    writeSubMenuPrefix();

    if (option=="executiveCommittee") {
	document.write("<span class=\"selected\">" + executiveCommittee + "</span>");
    } else {
 	document.write("<a href=\"mannschaft.html\">" + executiveCommittee + "</a>");
    }
   
    document.write(" | ");

    if (option=="members") {
	document.write("<span class=\"selected\">" + members + "</span>");
    } else {
 	document.write("<a href=\"aktive.html\">" + members + "</a>");
    }
   
    writeSubMenuSuffix();
}

function writeSubMenuYoung(option) {
    writeSubMenuYoungLang("&Uuml;berblick", "Mitglieder", "Bilder 2011", "Bilder 2010", "Bilder 2009", "Bilder 2008", "Termine", option);
}

function writeSubMenuYoungLang(overview, team, pictures2011, pictures2010, pictures2009, pictures2008, appointment, option) {
    writeSubMenuPrefix();

    if (option=="overview") {
	document.write("<span class=\"selected\">" + overview + "</span>");
    } else {
 	document.write("<a href=\"jugend.html\">" + overview + "</a>");
    }
   
    document.write(" | ");

    if (option=="team") {
	document.write("<span class=\"selected\">" + team + "</span>");
    } else {
 	document.write("<a href=\"j_mitglieder.html\">" + team + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2011") {
	document.write("<span class=\"selected\">" + pictures2011 + "</span>");
    } else {
 	document.write("<a href=\"j_bilder2011.html\">" + pictures2011 + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2010") {
	document.write("<span class=\"selected\">" + pictures2010 + "</span>");
    } else {
 	document.write("<a href=\"j_bilder2010.html\">" + pictures2010 + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2009") {
	document.write("<span class=\"selected\">" + pictures2009 + "</span>");
    } else {
 	document.write("<a href=\"j_bilder2009.html\">" + pictures2009 + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2008") {
	document.write("<span class=\"selected\">" + pictures2008 + "</span>");
    } else {
 	document.write("<a href=\"j_bilder2008.html\">" + pictures2008 + "</a>");
    }
   
    document.write(" | ");

    if (option=="appointment") {
	document.write("<span class=\"selected\">" + appointment + "</span>");
    } else {
 	document.write("<a href=\"j_termine.html\">" + appointment + "</a>");
    }
    
    writeSubMenuSuffix();
}

function writeSubMenuFirefighting(option) {
    writeSubMenuFirefightingLang("2012", "2011", "2010", "2009", "2008", "&Uuml;berblick", option);
}

function writeSubMenuFirefightingLang(e2012, e2011, e2010, e2009, e2008, overview, option) {
    writeSubMenuPrefix();

    if (option=="e2012") {
	document.write("<span class=\"selected\">" + e2012 + "</span>");
    } else {
 	document.write("<a href=\"e-2012.html\">" + e2012 + "</a>");
    }
   
    document.write(" | ");

    if (option=="e2011") {
	document.write("<span class=\"selected\">" + e2011 + "</span>");
    } else {
 	document.write("<a href=\"e-2011.html\">" + e2011 + "</a>");
    }
   
    document.write(" | ");

    if (option=="e2010") {
	document.write("<span class=\"selected\">" + e2010 + "</span>");
    } else {
 	document.write("<a href=\"e-2010.html\">" + e2010 + "</a>");
    }

    document.write(" | ");

    if (option=="e2009") {
	document.write("<span class=\"selected\">" + e2009 + "</span>");
    } else {
 	document.write("<a href=\"e-2009.html\">" + e2009 + "</a>");
    }

    document.write(" | ");

    if (option=="e2008") {
	document.write("<span class=\"selected\">" + e2008 + "</span>");
    } else {
 	document.write("<a href=\"e-2008.html\">" + e2008 + "</a>");
    }

    document.write(" | ");

    if (option=="overview") {
	document.write("<span class=\"selected\">" + overview + "</span>");
    } else {
 	document.write("<a href=\"einsatz.html\">" + overview + "</a>");
    }

   
    writeSubMenuSuffix();
}

function writeSubMenuPictures(option) {
    writeSubMenuPicturesLang("2011", "2010", "2009", "2008", option);
}

function writeSubMenuPicturesLang(b2011, b2010, b2009, b2008, option) {
    writeSubMenuPrefix();

    if (option=="b2011") {
	document.write("<span class=\"selected\">" + b2011 + "</span>");
    } else {
 	document.write("<a href=\"bilder-2011.html\">" + b2011 + "</a>");
    }
   
    document.write(" | ");

    if (option=="b2010") {
	document.write("<span class=\"selected\">" + b2010 + "</span>");
    } else {
 	document.write("<a href=\"bilder-2010.html\">" + b2010 + "</a>");
    }
   
    document.write(" | ");

    if (option=="b2009") {
	document.write("<span class=\"selected\">" +  b2009+ "</span>");
    } else {
 	document.write("<a href=\"bilder-2009.html\">" + b2009 + "</a>");
    }
   
    document.write(" | ");

    if (option=="b2008") {
	document.write("<span class=\"selected\">" + b2008 + "</span>");
    } else {
 	document.write("<a href=\"bilder-2008.html\">" + b2008 + "</a>");
    }
   
    writeSubMenuSuffix();
}

function writeSubMenuAppointment(option) {
    writeSubMenuAppointmentLang("&Uuml;bungen / Veranstaltungen", "Lehrgänge", "Ausbildungen", option);
}

function writeSubMenuAppointmentLang(overview, course, training, option) {
    writeSubMenuPrefix();

    if (option=="overview") {
	document.write("<span class=\"selected\">" + overview + "</span>");
    } else {
 	document.write("<a href=\"termine.html\">" +overview  + "</a>");
    }
   
    document.write(" | ");

    if (option=="course") {
	document.write("<span class=\"selected\">" + course + "</span>");
    } else {
 	document.write("<a href=\"lehrgang.html\">" + course + "</a>");
    }

    document.write(" | ");

    if (option=="training") {
	document.write("<span class=\"selected\">" + training + "</span>");
    } else {
 	document.write("<a href=\"ausbildung.html\">" + training + "</a>");
    }

    writeSubMenuSuffix();
}

function writeSubMenuContact(option) {
    writeSubMenuContactLang("Adresse", "Wegbeschreibung", "Formular", option);
}

function writeSubMenuContactLang(address, locationPlan, form, option) {
    writeSubMenuPrefix();

    if (option=="address") {
	document.write("<span class=\"selected\">" + address + "</span>");
    } else {
 	document.write("<a href=\"kontakt.html\">" + address + "</a>");
    }
   
    document.write(" | ");

     if (option=="locationPlan") {
	document.write("<span class=\"selected\">" + locationPlan + "</span>");
    } else {
 	document.write("<a href=\"wegbeschreibung.html\">" + locationPlan + "</a>");
    }
  
    document.write(" | ");

     if (option=="form") {
	document.write("<span class=\"selected\">" + form + "</span>");
    } else {
 	document.write("<a href=\"formular.html\">" + form + "</a>");
    }

    writeSubMenuSuffix();
}



function writeSubMenuFirstResponder(option) {
    writeSubMenuFirstResponderLang("&Uuml;berblick", "Mitglieder", "Bilder 2011", "Bilder 2010", "Termine", "Kontakt", option);
}

function writeSubMenuFirstResponderLang(overview, team, pictures2011, pictures2010, appointment, contact, option) {
    writeSubMenuPrefix();

    if (option=="overview") {
	document.write("<span class=\"selected\">" + overview + "</span>");
    } else {
 	document.write("<a href=\"hvo.html\">" + overview + "</a>");
    }
   
    document.write(" | ");

    if (option=="team") {
	document.write("<span class=\"selected\">" + team + "</span>");
    } else {
 	document.write("<a href=\"hvo-mitglieder.html\">" + team + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2011") {
	document.write("<span class=\"selected\">" + pictures2011 + "</span>");
    } else {
 	document.write("<a href=\"hvo-bilder-2011.html\">" + pictures2011 + "</a>");
    }
   
    document.write(" | ");

    if (option=="pictures2010") {
	document.write("<span class=\"selected\">" + pictures2010 + "</span>");
    } else {
 	document.write("<a href=\"hvo-bilder-2010.html\">" + pictures2010 + "</a>");
    }
   
    document.write(" | ");

    if (option=="appointment") {
	document.write("<span class=\"selected\">" + appointment + "</span>");
    } else {
 	document.write("<a href=\"hvo-termine.html\">" + appointment + "</a>");
    }
    
    document.write(" | ");

    if (option=="contact") {
	document.write("<span class=\"selected\">" + contact + "</span>");
    } else {
 	document.write("<a href=\"hvo-kontakt.html\">" + contact + "</a>");
    }
    
    writeSubMenuSuffix();
}

/////////////////////////

function writeSubMenuPrefix() {
    document.write("<div id=\"subNavigation\"><div class=\"left\"></div><div class=\"options\">");
}

function writeSubMenuSuffix() {
    document.write("</div><div class=\"right\"></div>");

    writeSubNavigationExtras();

    document.write("</div>");
}

function writeSubNavigationExtras() {
    writeSubNavigationExtrasLang("Schrift","Diese Seite zu den Favoriten hinzuf&uuml;gen");
}

function writeSubNavigationExtrasLang(font,bookmark) {
    document.write("<div class=\"extras\">");
    writeFontSize(font + ":");
    writeBookmark(window.document.location,window.document.title,bookmark);
    document.write("</div>");
}

