/* ************************************************************************** */
/* Datei JavaScript-Funktionen.js                                             */
/*                                                                            */
/* JavaScript-Funktionen                           Status: 10.11.2004         */
/*                                                                            */
/* Author: Gerhard Mueller, GmuSoft, www.gmusoft.de                           */
/* Copyright: Entsprechend der GNU General Public License (GPL),              */
/*   siehe http://www.gnu.org/licenses/gpl.html                               */
/*   oder  http://www.gnu.de/gpl-ger.html,                                    */
/*   siehe auch GNU Free Documentation License (GFDL),                        */
/*         http://www.gnu.org/copyleft/fdl.html oder                          */
/*         http://www.giese-online.de/gnufdl-de.html                          */
/* Bestimmte Personen sind jedoch von der freien Nutzung ausgeschlossen,      */
/*   siehe http://www.mueller-herrenberg\license.htm                          */
/* ************************************************************************** */

   function analyze_parameters ()
      // Die dem Aufruf mitgegebenen Parameter analysieren
      {
      if(window.location.search != "")
        alert(window.location.search);
      }


   function zoom (bild, zoomfaktor)
      // Ein Bild einschliesslich image map vergroessern oder verkleinern
      {
      // bild = charstring
      // zoomfaktor = charstring
      // alert("zoom:  " + bild + "  " + zoomfaktor );
      if (typeof(bildbreite_orig) == "undefined")   // ist "undefinded" oder "number"
         {                                                        // speichere urspruengliche Werte von Breite und Hoehe:
         bildbreite_orig = document.getElementById(bild).width;   // ergibt eine Character-Variable
         bildhoehe_orig  = document.getElementById(bild).height;  // ergibt eine Character-Variable
         }
      var altebreite = document.getElementById(bild).width;
      var altehoehe  = document.getElementById(bild).height;
      var neuebreite = Math.ceil(eval(altebreite * zoomfaktor));
      var neuehoehe  = Math.ceil(eval(altehoehe  * zoomfaktor));
      document.getElementById(bild).width  = neuebreite;
      document.getElementById(bild).height = neuehoehe;
      usemap = document.getElementById(bild).useMap; // ergibt eine Character-Variable mit # vorweg
      // alert (usemap);  not necessary:  zoom is not called without a usemap
      usemap = usemap.substr(1,usemap.length);
      var i = 0;
      var altekoordinaten, neuekoordinaten;
      for ( i=0; i<document.getElementById(usemap).areas.length; i=i+1 )
        {
        altekoordinaten = document.getElementById(usemap).areas[i].coords;
        neuekoordinaten = zoom_coords(altekoordinaten, zoomfaktor);
        document.getElementById(usemap).areas[i].coords = neuekoordinaten;
        }
      }


   function zoom_coords (coords, zoomfaktor)
      // Umrechnung der Koordinaten in einer image map
      {
      // bild = charstring
      // coords ist Aufzaehlung von Charstrings, getrennt durch Kommata
      // zoomfaktor = charstring
      var coords1 = coords;
      var newcoords = "";
      var i = 0;
      var kommapos, coord, newcoord, newcoords;
      for (i=1; i<1000; i++)
        {
        kommapos = coords1.search(/,/);  // search for (next) comma
        if (kommapos == -1)
           {break;}
        coord   = coords1.substring(0,kommapos);
        coords1 = coords1.substring(kommapos+1, coords1.length);
        newcoord = Math.ceil(eval(coord  * zoomfaktor));
        newcoords = newcoords + String(newcoord) + ",";
        }
      coord = coords1.substring(0,coords1.length);
      newcoord = Math.ceil(eval(coord  * zoomfaktor));
      newcoords = newcoords + String(newcoord);
      return newcoords;
      }


   function zoom_map (bild)
      // Aufbau eines Zoom-Streifens am unteren Rand eines Bildes
      {
      // bild = charstring
      // alert("zoom_map:  " + bild + " " + typeof(bild) );
      if (! document.getElementById(bild))
         {
         alert( "Image " + bild + " not found");
         return;
         }
      bildbreite_orig = document.getElementById(bild).width;
      bildhoehe_orig  = document.getElementById(bild).height;
      var start = 0;
      var ende  = 0;
      var koordinaten = "";
      var zoomstufe   = 0;
      var skalenlaenge = "0";  // Wenn vorher definiert, muss es eine Character-Variable sein
      var bildhoehe    = "0";
      var skalenhoehe  = 0;
      var skalenlage   = 0;
      var skalenende   = "0";
      skalenlaenge = document.getElementById(bild).width;  // ergibt eine Character-Variable
      bildhoehe    = document.getElementById(bild).height; // ergibt eine Character-Variable
      // document.write(skalenlaenge + " " + bildhoehe + "  -  ");
      skalenhoehe  = Math.ceil( Math.min(6, Math.max(20, eval(bildhoehe / 50) ) ) );  //  Skalenhoehe zwischen 6 und 20
      skalenlage   = eval(bildhoehe - skalenhoehe - 1);
      skalenende   = eval(skalenlaenge);
      koordinaten  =       String(start) + "," + String(skalenlage)  /* oben links (x,y)   */
                   + "," + skalenlaenge  + "," + bildhoehe           /* unten rechts (x,y) */ ;
      // document.writeln(koordinaten);
      // document.writeln("<area shape='rect' coords='" + koordinaten + "' alt='Vergr&ouml;&szlig;ern/Verkleinern' />" );
      var teile            = Math.min ( 100, Math.floor(eval(skalenlaenge/6)) );  // i.a. 100 Teile, aber maximal 1/6 der Zahl der vorhandenen Pixel
      var skalenteillaenge = eval(skalenlaenge / teile);  // i.a. 100 Teile fuer Vergroesserung 0,02 .. 1,00 .. 2,00
                                                          // keine ganze Zahl
      // Koordinaten: Die Ecke oben links hat die Koordinaten 0,0 - die Ecke unten rechts hat (width-1), (height-1)  ??
      var i = 0;
      start = 0;
      for ( i=0; i<teile; i=i+1 )
          {
          ende  = Math.floor((i+1)*skalenteillaenge) - 1;
          koordinaten =       String(start) + "," + String(skalenlage) /* oben links (x,y)   */
                      + "," + String(ende)  + "," + bildhoehe          /* unten rechts (x,y) */ ;
          zoomstufe   = Math.ceil( (i+1) * (2/teile) * 100 ) / 100;  // Vergroesserung i.a. 0,02 .. 1,00 .. 2,00
                                                                       // bei weniger Stufen groeberes Raster, aber bis Faktor 2
          // alert('<area shape="rect" coords="' + koordinaten +
          //                  '" alt="Vergr&ouml;&szlig;ern/Verkleinern Faktor ' + (String(zoomstufe)).substring(0,4) +
          //                  '" onclick="javascript:zoom(\'' + bild + '\', \'' + (String(zoomstufe)).substring(0,4) + '\')" />' );
          document.writeln('<area shape="rect" coords="' + koordinaten +
                           '" alt="Vergr&ouml;&szlig;ern/Verkleinern Faktor ' + (String(zoomstufe)).substring(0,4) +
                           '" onclick="javascript:zoom(\'' + bild + '\', \'' + (String(zoomstufe)).substring(0,4) + '\')" />' );
          start = ende + 1;
          }
      // alert( "end of zoom_map" );
      }



   function show_coordinates (bild)
      // image map erstellen, um danach
      // die Koordinaten von Punkten im Bild anzeigen
      // zum Aufbau einer image map fuer den Bildinhalt
      {
      // bild = charstring
      // alert("show_coordinates: " + bild);
      var bildbreite = document.getElementById(bild).width;
      var bildhoehe  = document.getElementById(bild).height;
      var koordinaten = "";
      var koordoben   = "";
      var koordunten  = "";
      // Koordinaten: Die Ecke oben links hat die Koordinaten 0,0 - die Ecke unten rechts hat (width-1), (height-1)  ??
      var genauigkeit = 1;  //  Raster der Angaben - jedes Pxel einzeln ergibt eine zu grosse Zahl von areas
      if ( (bildbreite * bildhoehe) >    400 )  { genauigkeit =  5; }
      if ( (bildbreite * bildhoehe) >  10000 )  { genauigkeit = 10; }
      if ( (bildbreite * bildhoehe) >  90000 )  { genauigkeit = 20; }
      if ( (bildbreite * bildhoehe) > 250000 )  { genauigkeit = 50; }
      genauigkeit = 10;
      var i = 0;
      for ( i=0; i<bildbreite; i=i+genauigkeit )
          {
          var j = 0;
          for ( j=0; j<bildhoehe; j=j+genauigkeit )
              {
              koordoben   = String(i)                + "," + String(j)                /* oben links (x,y)   */ ;
              koordunten  = String(i+genauigkeit-1)  + "," + String(j+genauigkeit-1)  /* unten rechts (x,y) */ ;
              koordinaten = koordunten + "," + koordoben;
              document.writeln('<area shape="rect" coords="' + koordinaten +
                               '" alt="' + koordoben +
                               '" onmouseover="javascript:show_coord(\'' + bild + '\', \'' + koordoben + '\')"' +
                               ' onclick="javascript:write_coord(\'' + bild + '\', \'' + koordoben + '\')" />' );
              }
          }
      }


   function show_coord (bild, koordinaten)
      // Die Koordinaten von Punkten im Bild anzeigen
      // zum Aufbau einer image map fuer den Bildinhalt
      {
      // bild = charstring
      // koordinaten = charstring (mit enthaltenem Komma)
      // alert("show_coord: " + bild + ", " + koordinaten);
      window.status = koordinaten;
      return true;
      }


   function write_coord (bild, koordinaten)
      // Die Koordinaten von Punkten im Bild in eine Datei schreiben
      // zum Aufbau einer image map fuer den Bildinhalt
      {
      // bild = charstring
      // koordinaten = charstring (mit enthaltenem Komma)
      // alert("write_coord: " + bild + ", " + koordinaten);
      // document.writeln(koordinaten);
      // write into cookie:
      var gespeichert = "";
      if (document.cookie)
         {
         gespeichert = document.cookie + " - ";
         var dataend = document.cookie.indexOf(";");
         if (dataend != -1)
            { gespeichert = document.cookie.substring( 0, dataend ); }
         }
      var ablauf = new Date();
      var in2Tagen = ablauf.getTime() + (2 * 24 * 60 * 60 * 1000);
      ablauf.setTime(in2Tagen);
      document.cookie = gespeichert + koordinaten;  + "; expires=" + ablauf.toGMTString();
      alert(document.cookie) ;
      }


   function markieren (searchstrings)
      // Im Dokument Suchbegriffe hervorheben
      // Unfertig
      {
      // searchstrings = charstring (mit evtl. enthaltenen Kommata)
      var text = "";
      var newtext = '<B style="color:black;background-color:#ffff66">' + text + '</B>';
      }


   function checkframes (checkwindow)
      // Von Object-Datei aus auf einschliessendes Fenster entsprechend zugreifen
      // Unfertig, im Test
      {
      // checkwindow = charstring
      alert("frames.length = " + frames.length);  // ist in beiden Faellen 0
      if (frames.length > 0)
         {
         alert("parent.frames[0].document.lastModified = " + parent.frames[0].document.lastModified);
         alert("parent.frames[1].document.lastModified = " + parent.frames[1].document.lastModified);
         }
      alert("top.frames.length = " + top.frames.length);  // als ganze Seite 0, als eingefuegte 1
      if (top.frames.length > 0)
         {
         alert("top.frames[0].document.lastModified = " + top.frames[0].document.lastModified);
         alert("top.frames[0].document.title = " + top.frames[0].document.title);  // Volkstanzgruppe Herrenberg
         // alert("top.document.title = " + top.document.title);  // Fehler: Zugriff verweigert
         // alert("top.frames[1].document.lastModified = " + top.frames[1].document.lastModified);
         }
      alert("document.lastModified = " + document.lastModified);
      alert("window.document.lastModified = " + window.document.lastModified);
      // alert("parent.document.lastModified = " + parent.document.lastModified);
         // als ganze Seite ok, als eingefuegte Seite (als Object) Fehler "Zugriff verweigert"
      alert("window.document.location.href = " + window.document.location.href);
      // alert("top.document.location.href = " + top.document.location.href);
         // als ganze Seite ok, als eingefuegte Seite (als Object) Fehler "Zugriff verweigert"
      // top.document.writeln("Zusatz-Text");
         // als ganze Seite ok, gibt Text (am Anfang der Seite) aus, als eingefuegte Seite (als Object) Fehler "Zugriff verweigert"
      alert("end of function checkframes");
      }


