/* Java-Scripts fuer die Baumbestimmung 
*
*	Name: baumbest.js
*	Autor: Loescher Robert	am: 06.07.1999
*
*	History:
*
*/

/* Object Attribut */
function Attribut(typ, beschreibung, bild)
{
   	this.typ = typ;
   	this.beschreibung = beschreibung;
   	this.bild = bild;
}

/* Object Baum */
function Baum(attribute)
{
    this.attribute = new Array();
}
    

BaumObjectArray = new Array();


Unbekannt = new Array("unbekannt#unbekannt#unbekannt#unbekannt#0#false#");

var arrayzaehler = 0;

var sprache = 0; /* 0 - Deutsch, 1 - Englisch */
var Verfallszeit = 1000*60*60*24*365;

function setDeutsch()
{
   sprache = 0;
   var jetzt= new Date();
   var Auszeit = new Date(jetzt.getTime() + Verfallszeit);  
   document.cookie="Sprache="+sprache+"; expires="+Auszeit.toGMTString()+";";
}

function setEnglisch()
{
   sprache = 1;
   var jetzt= new Date();
   var Auszeit = new Date(jetzt.getTime() + Verfallszeit);  
   document.cookie="Sprache="+sprache+"; expires="+Auszeit.toGMTString()+";";
}

function getSprache()
{
   sprache = 0;
   if(document.cookie) 
   {
      Wertstart = document.cookie.indexOf("=") + 1;
      Wertende = document.cookie.indexOf(";");
      if(Wertende == -1) Wertende = document.cookie.length;
      sprache = document.cookie.substring(Wertstart,Wertende);
   }
   return sprache;
}


function MakeBaumObjectArray()
{
    for (i=0; i < BaumArray.length; ++i) {
	    BaumObjectArray = BaumObjectArray.concat(new Baum());
        cnt = BaumObjectArray.length - 1;
                
        attributinfo = BaumArray[i].split("#");
        for (j=0; j < attributinfo.length; ++j) {
    	    attributdetail = attributinfo[j].split("^");
            BaumObjectArray[cnt].attribute = BaumObjectArray[cnt].attribute.concat(new Attribut(attributdetail[0], attributdetail[1], attributdetail[2]));
        }
    }
    arrayzaehler = 0;
}


function ResetBaumArray()
{
   arrayzaehler = 0;
}

/*****************************************************************************************************************************************
function GetSumBilder()
Gibt die Summe der Abbildungen zurueck
*****************************************************************************************************************************************/
function GetSumBilder()
{
   bildersumme = 0;

   ResetBaumArray();
   hkurz = GetNext("anzbild");
   do
   {
      bildersumme = eval(bildersumme + "+" + hkurz);
      hkurz = GetNext("anzbild");
   } while (hkurz != false);

   return bildersumme;
}

/*****************************************************************************************************************************************
function GetVollInfo(Name)

Gibt fuer den Namen die Volle Info aus, die hier eingetragen ist.
Dieser String ist folgendermassen aufgebaut:

Name;Blatttyp;Pflanzentyp;AnzBilder;HtmExist

Dabei ist folgendes einzutragen:
	Name: 		Frei waehlbar
            Kurzname:	Frei waehlber
	Blatttyp:	gelappt, ganzrand, gezahnt, gefiedert, gefing, einznad, nadbusch, schuppen
            Pflanzentyp: 	Baum, Strauch
	AnzBilder: 	Zahl
	HtmExist:	true od. false

Nicht vergessen: anzahl anpassen!!
*****************************************************************************************************************************************/
/*
function GetVollInfo(Name)
{
   var i;
   gefunden = new Boolean(false);

   if (Name == "anzahl") return BaumArray.length;
   else
   {
      for (i = 0; i < BaumArray.length; ++i)
      {
         BaumInfo = BaumArray[i].split("#");

         if (Name == BaumInfo[1])
         {
            gefunden = true;
            break;
         }
      }
      if (gefunden == true) return BaumArray[i];
      else return Unbekannt;
   }
}
*/

function getAttributeArray(kurz) {
   var i;

    if (BaumObjectArray.length == 0) {
    	MakeBaumObjectArray();
    }
    
    gefunden = 0;
    
	for (i=0; i<BaumObjectArray.length; ++i) {
    	for (j=0; j < BaumObjectArray[i].attribute.length; ++j) {
      		with(BaumObjectArray[i]) {
      			if ((attribute[j].typ == "kurz") && (attribute[j].beschreibung == kurz)) {
      				gefunden = 1;
      				break;
      			}
			}
		}
		if (gefunden == 1) {
			break;
		}
	}
	if (gefunden == 1) {
		return BaumObjectArray[i].attribute;
	}
	else {
		alert("Baum mit \"kurz\" = \"" + kurz + "\" nicht gefunden!");
		return false;
	}
}
	
function GetAttribute(baum, attribtyp)
{
	for (i=0; i<baum.attribute.length; ++i) {
		if (baum.attribute[i].typ == attribtyp) {
			return baum.attribute[i];
		}
	}
/* LoRo 25.11.00	
	alert("Attribut \"" + attribtyp + "\" nicht gefunden!");
*/	
	return false;
}


/*****************************************************************************************************************************************
function GetDetInfo(Name, Tag)

Gibt fuer einen bestimmten Namen den Tag aus, der in GetVillInfo() eingetragen ist.

Folgende Moeglichkeiten fuer Tag (Gross- Kleinschreibung egal):
        kurzname
	name
	blatt
	pflanze
	anzbild
	htmexist
*****************************************************************************************************************************************/
function GetDetInfo(Name, Tag)
{
   var BaumVollInfo;
   var BaumInfo;
   var hattribute;
   var i;

    if (BaumObjectArray.length == 0) {
    	MakeBaumObjectArray();
    }
    
    gefunden = 0;
    
	for (i=0; i<BaumObjectArray.length; ++i) {
    	for (j=0; j < BaumObjectArray[i].attribute.length; ++j) {
      		with(BaumObjectArray[i]) {
      			if ((attribute[j].typ == "kurz") && (attribute[j].beschreibung == Name)) {
      				gefunden = 1;
      				break;
      			}
			}
		}
		if (gefunden == 1) {
			break;
		}
	}
	if (gefunden == 1) {
		hattribute = GetAttribute(BaumObjectArray[i], Tag);
		return hattribute.beschreibung;
	}
	else {
/* LoRo 25.11.00		
		alert("Element mit \"" + Tag + " = " + Name + "\" nicht gefunden!");
*/		
		return false;
	}
}

function GetNext(Tag)
{
	var hattribute = new Array();
    if (BaumObjectArray.length == 0) {
    	MakeBaumObjectArray();
    }
    	
	if (arrayzaehler < BaumArray.length) {
		hattribute = GetAttribute(BaumObjectArray[arrayzaehler++], Tag);
		
		return hattribute.beschreibung;
	}
	else return false;
}

  function NeuFenster(fenstername,Name,groesse)
  {
   MeinFenster =
   window.open(fenstername,Name,groesse);
   MeinFenster.focus();
  }

  function LadeMitNamen(fenstername,Name)
  {
    window.parent.location.href=fenstername;
    window.parent.name=Name;
  }

  function FotoAnzeigen(nummer)
  {
     NeuFenster("image/"+GetDetInfo(parent.name, "kurz")+nummer+".jpg","","height=500,width=700");
  }


  function FotosFuerListe(nummer)
  {
    document.write("<a href='javascript:FotoAnzeigen("+nummer+")'>");
    kurzname = GetDetInfo(parent.name, "kurz");
    fototext="<img src='image/"+kurzname+nummer+"v.jpg' height=150 width=100 border=0>";
    document.write(fototext);
    document.write("</a>");
  }

  function fotoFenster(bildkurz)
  {
     NeuFenster("image/"+bildkurz+".jpg","","height=600,width=800,resizable=yes");
  }
  
  function fotoLink(bildkurz, align)
  {
    document.write("<a href='javascript:fotoFenster(\""+bildkurz+"\")'>");
    fototext="<img src='image/"+bildkurz+"v.jpg' height=150 width=100 border=2 align='" + align + "' hspace=15>";
    document.write(fototext);
    document.write("</a>");
  }

   function Lade(Name)
   {
      LadeMitNamen("baumdetail.htm", Name);
   }


   function LadeBlattform(Name)
   {
      LadeMitNamen("spezblattform.htm", Name);
   }


   function BaumHeader(Name)
   {
      document.write("<TABLE BORDER CELLSPACING=3 CELLPADDING=5 WIDTH=100%>");

      blatttyp = GetDetInfo(Name.toLowerCase(), "blattyp");

      switch(blatttyp)
      {
         case "ganzrand":
         case "gelappt":
         case "gefiedert":
         case "gefing":
         case "gezahnt":
            document.write("<TR><TD VALIGN='MIDDLE' BGCOLOR='#008000' HEIGHT=44 BACKGROUND='image/17.jpg'>");
            break;
         default:
            document.write("<TR><TD VALIGN='MIDDLE' BGCOLOR='#B22222' HEIGHT=44 BACKGROUND='image/red3.gif'>");
            break;
      }

      document.write("<P ALIGN='CENTER'><B><FONT FACE='Arial' COLOR='white' SIZE='5'>");
      document.write(GetDetInfo(Name.toLowerCase(), "name"));
      document.write("</B></FONT></TD></TR>");
      document.write("</TABLE>");

      latinname = GetDetInfo(Name.toLowerCase(), "latinname");

      if (latinname != "") {
         document.write("<div class='ueberschr'>Lateinischer Name</div>");
         document.write("<div class ='allgem'><i>"+latinname+"</i></div>");
      }
   }

function MkKopf(Typ)
{
   switch(Typ) {
      case "gelappt":
      case "gezahnt":
      case "ganzrand":
      case "gefing":
      case "gefiedert": 
         document.write("<TD VALIGN='MIDDLE' COLSPAN=5 BGCOLOR='#008000' HEIGHT=44 BACKGROUND='image/17.jpg'>");
         break;
      default:
         document.write("<TD VALIGN='MIDDLE' COLSPAN=5 BGCOLOR='#B22222' HEIGHT=44 BACKGROUND='image/red3.gif'>");
   }

   document.write("<P ALIGN='CENTER'><FONT FACE='Arial' SIZE=4 COLOR='#FFFFFF'>");
   document.write(ExpandName(Typ));
   document.write("</FONT><BR>");
   document.write("<A HREF='blattform.htm' target='_top'><B><FONT FACE='Arial' SIZE=2 COLOR='#FFFFFF'>Blattformauswahl</B></FONT></A>");
   document.write("<img src='image/pixel.gif' height=1 width=20>");
   document.write("<A HREF='baumindex.htm' target='_top'><B><FONT FACE='Arial' SIZE=2 COLOR='#FFFFFF'>Baumverzeichnis</B></FONT></A>");
   document.write("<img src='image/pixel.gif' height=1 width=20>");
   document.write("<A HREF='index.htm' target='_top'><B><FONT FACE='Arial' SIZE=2 COLOR='#FFFFFF'>Homepage</B></FONT></A>");
   document.write("<img src='image/pixel.gif' height=1 width=20>");
      vorname="robert";
      nachname="loescher";
      punkt=".";
      klammeraffe="@";
      domaene="gmx";
      land="net";
      document.write("<a href='");
      document.write("mailto:" + nachname + punkt + vorname + klammeraffe + domaene + punkt + land);
      document.write("'><B><FONT FACE='Arial' SIZE=2 COLOR='#FFFFFF'>Mail</B></FONT></a>");
   document.write("</TD>");
}

function spezBlaetterAnz(Typ)
{
   ResetBaumArray();
   BaumArray.sort();

   var j = 0;
   for (zaehl = 0; zaehl < BaumArray.length; ++zaehl) {
      hkurzname = GetNext("kurz");
      if (GetDetInfo(hkurzname, "blattyp") == Typ) {
         hname = GetDetInfo(hkurzname, "name");
         hnamearray = hname.split("|");

         if (j == 0) document.write("<TR>");

         document.write("<TD VALIGN='TOP' ALIGN='CENTER' HEIGHT=115><FONT face='Arial' size='2' >");
         document.write("<A HREF='javascript:Lade(\""+String(hkurzname)+"\")'><img src=\"image/"+hkurzname+"0v.jpg\" alt=\""+hname+"\"  BORDER=0 WIDTH=100 HEIGHT=150></A><BR>");
         document.write("<strong>"+hnamearray[0]+"</strong>");
         document.write("</FONT></TD>");

         if (++j >= 5) {
            j = 0;
           document.write("</TR>");
         }
      }
   }
}


function ExpandName(Name)
{
   switch(Name) {
      case "ganzrand": return  "Ganzrandige Laubbl&auml;tter"; break;
      case "gelappt": return  "Gelappte Laubbl&auml;tter"; break;
      case "gezahnt": return  "Gez&auml;hnte Laubbl&auml;tter"; break;
      case "gefing": return  "Gefingerte Laubbl&auml;tter"; break;
      case "gefiedert": return  "Gefiederte Laubbl&auml;tter"; break;
      case "einznad": return  "Einzelne Nadeln"; break;
      case "nadbusch": return  "Nadelb&uuml;schel"; break;
      case "schuppen": return  "Schuppenbl&auml;tter"; break;
      default: return  "false"; break;
   }
   return "false";
}

