//  ACHTUNG:   ../BI/javascript.js IDENTISCH mit ../DFLD/javascript.js !!!
//  Original:  ../DFLD/javascript.js

var ZusFensterHandle = null;  // Handle vom Zusatzfenster

//  Funktionen zur Unterscheidung BI bzw. DFLD ===============================
//  Liefert Heimatverzeichnis (BI oder DFLD)
function GetHome()
{  if ( window.location.hostname=='www.eans.info' ) return 'EANS';
   if ( window.location.hostname=='www.eans.biz'  ) return 'EANS';
   if ( window.location.hostname=='www.eans.at'   ) return 'EANS';
   if ( window.location.hostname=='www.eans.co.uk') return 'EANS';
   if ( window.location.hostname=='www.eans.de'   ) return 'EANS';
   if ( window.location.hostname=='www.efld.de'   ) return 'EANS';
   if ( window.location.hostname=='www.fluglaerm-eppstein.de' ) return 'BI';
   return 'DFLD';
}

//  Laeuft Programm unter Kontrolle www.fluglaerm-eppstein.de
//                             oder www.dfld.de
//                             oder www.EANS.net
function IsHomeBI()
{  if ( GetHome()=='BI' ) return true;
   return false;
}
function IsHomeDFLD()
{  if ( window.location.hostname=='www.dfld.de' ) return true;
   if ( window.location.hostname=='dfld.de'     ) return true;
   return false;
}
function IsHomeEANS()
{  if ( GetHome()=='EANS' ) return true;
   return false;
}

//  Einbau von Link auf aktuelles StyleSheet
function StyleSheet()
{  if ( IsHomeBI() )
        { document.write('<link rel="STYLESHEET" href="../BI/Stylesheet.css">'     ); }
   else { document.write('<link rel="STYLESHEET" href="../DFLD/Stylesheet.css">'   ); }
}
function StyleSheet1()
{  if ( IsHomeBI() )
        { document.write('<link rel="STYLESHEET" href="../BI/Stylesheet.css">'     ); }
   else { document.write('<link rel="STYLESHEET" href="../DFLD/Stylesheet.css">'   ); }
}
function StyleSheet2()
{  if ( IsHomeBI() )
        { document.write('<link rel="STYLESHEET" href="../../BI/Stylesheet.css">'  ); }
   else { document.write('<link rel="STYLESHEET" href="../../DFLD/Stylesheet.css">'); }
}
function StyleSheet3()
{  if ( IsHomeBI() )
        { document.write('<link rel="STYLESHEET" href="../../../BI/Stylesheet.css">'  ); }
   else { document.write('<link rel="STYLESHEET" href="../../../DFLD/Stylesheet.css">'); }
}

//  Einbau von Link auf Leserbrief-eMail-Adresse
function BriefMail()
{  if ( IsHomeBI() )
        { document.write('<a href="mailto:Leserbrief@Fluglaerm-Eppstein.de">Leserbrief@Fluglaerm-Eppstein.de</a>'); }
   else { document.write('<a href="mailto:Leserbrief@DFLD.de"              >Leserbrief@DFLD.de</a>'              ); }
}

//  Einbau von aktuellem Logo
function GetBriefLogo()
{  if ( IsHomeBI() || true )
        { document.write('<img alt="Logo" src="LogoBriefBI.gif"   border="0">'  ); }
   else { document.write('<img alt="Logo" src="LogoBriefDFLD.gif" border="0">'  ); }
}

//  Schreibt Datum der letzten Veraenderung raus =============================
function WriteFileDate()
{  var fd      = new Date(document.lastModified);
   var fdYear  = fd.getYear(); if (fdYear < 1000) fdYear += 1900;
   var fdDay   = fd.getDate();
   var fdMonth = fd.getMonth()+1;

   document.write('<small>Letzte Aktualisierung: ');
   document.write(fdDay   + '.' +
                  fdMonth + '.' +
                  fdYear);
   document.write('</small>');
}

//  Liefert Anzahl Tage von HEUTE bis zu eingegebenem Datum ==================
function NochXTage(BisTag,BisMon,BisJah)
{  var Diff, AktTagImJahr, i;
   var AktDat = new Date();
   var AktTag = AktDat.getDate();
   var AktMon = AktDat.getMonth()+1;
   var AktJah = AktDat.getYear(); if (AktJah<1000) AktJah += 1900;

   AktTagImJahr = GetDayOfYear(AktTag,AktMon,AktJah);
   Diff = 0;
   if ( BisJah >AktJah ) { // Rest in aktuellem Jahr
                           Diff += (GetDayOfYear(31,12,AktJah)-AktTagImJahr);
                           // Ganze Jahre dazwischen
                           for ( i=AktJah+1 ; i<BisJah ; i++ )
                            Diff+=  GetDayOfYear(31,12,i);
                           // Rest im letzten Jahr
                           Diff +=  GetDayOfYear(BisTag,BisMon,BisJah);
                         }
   if ( BisJah==AktJah ) Diff = GetDayOfYear(BisTag,BisMon,BisJah)-AktTagImJahr;
   if ( Diff<0 ) Diff = 0;
   return Diff;
}

//  Liefert Laufende Nummer vom Tag im Jahr zu angegebenem Datum
function GetDayOfYear(Tag,Monat,Jahr)
{  var DayOfYear = 0;
   var i;

   for ( i=1 ; i<Monat ; i++ )
   {  switch ( i )
      { case  1:
        case  3:
        case  5:
        case  7:
        case  8:
        case 10:
        case 12:                      DayOfYear += 31;   break;
        case  4:
        case  6:
        case  9:
        case 11:                      DayOfYear += 30;   break;
        case  2: if ( (Jahr%4)!=0 ) { DayOfYear += 28; }
                             else   { DayOfYear += 29; } break;
      }
   }
   DayOfYear += Tag;
   return DayOfYear;
}

//  Liefert Monat der letzten Aenderung als String
function GetMonat(Datei)
{  var fd      = new Date(document.lastModified);
   var fdMonth = fd.getMonth()+1;
   switch ( fdMonth )
   { case  1: return "Januar";
     case  2: return "Februar";
     case  3: return "M&auml;rz";
     case  4: return "April";
     case  5: return "Mai";
     case  6: return "Juni";
     case  7: return "Juli";
     case  8: return "August";
     case  9: return "September";
     case 10: return "Oktober";
     case 11: return "November";
     case 12: return "Dezember";
   }
   return "";
}

//  Funktionen zum Sammel-Beschwerdehandling =================================
var BeschAnz = 0;
var TwoHours = new Array ( 0,0,0,0,0,0,0,0,0,0, // 00:00 - 00:09
                           0,0,0,0,0,0,0,0,0,0, // 00:10 - 00:19
                           0,0,0,0,0,0,0,0,0,0, // 00:20 - 00:29
                           0,0,0,0,0,0,0,0,0,0, // 00:30 - 00:39
                           0,0,0,0,0,0,0,0,0,0, // 00:40 - 00:49
                           0,0,0,0,0,0,0,0,0,0, // 00:50 - 00:59
                           0,0,0,0,0,0,0,0,0,0, // 01:00 - 01:09
                           0,0,0,0,0,0,0,0,0,0, // 01:10 - 01:19
                           0,0,0,0,0,0,0,0,0,0, // 01:20 - 01:29
                           0,0,0,0,0,0,0,0,0,0, // 01:30 - 01:39
                           0,0,0,0,0,0,0,0,0,0, // 01:40 - 01:49
                           0,0,0,0,0,0,0,0,0,0, // 01:50 - 01:59
                           0                    // 02:00
                         );
                                   
var InfoHandle = null;
function ShowInfoWnd(BaseZeit,Maske,RegNr,StatNr,Zoom,Datum) // Zeigt kuzzeitig ein Bestaetigungsfenster
{  var PhpAufruf   = 'ShowInfoWnd.php?Zeit=' + BaseZeit + '&Maske=' + Maske + '&RegNr=' + RegNr + '&StatNr=' + StatNr + '&Zoom=' + Zoom + '&Datum=' + Datum;
   var Breite      = 800; // Variante Waag: 800 x 190  /  Variante Senk: 710 x 250
   var BreiteInnen = Breite - 20;
   var Hoehe       = 190; // 190 = Direkt ueber BeschwerdeLink  /  710 = 60 + BeschAnz * 16;
   var HoeheInnen  = Hoehe  - 30;
   var Options     = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',innerHeight=' + HoeheInnen + ',innerWidth=' + BreiteInnen + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=no,location=no';

   CloseInfoWnd();
   InfoHandle =  window.open( PhpAufruf,"Bestaetigung",Options );
// var cValue = new Array();
// cValue=showModalDialog(PhpAufruf,0,"dialogWidth:230px;dialogHeight:700px");

   //window.setTimeout("CloseInfoWnd();",30500);

   //InfoHandle.blur();
}
function CloseInfoWnd()              // Schliesst Bestaetigungsfenster
{  if ( InfoHandle ) InfoHandle.close();
   InfoHandle = null;
}
function InitBeschwerde()            // Initialisiert alle Beschwerde-Variablen
{  var i;
   CloseInfoWnd();
   for ( i=0 ; i<=120 ; i++ ) TwoHours[i] = 0;
   BeschAnz   =    0;
}
function SetBeschwerde(i,BaseZeit,RegNr,StatNr,Zoom,Datum)   // Registriert eine Einzelbeschwerde
{  if ( i>=0 && i<120 )
   {  var RetVal = "";
      if ( TwoHours[i]==0 )
           { TwoHours[i] = 1; BeschAnz++; }
      else { TwoHours[i] = 0; BeschAnz--; }
      if ( BeschAnz>0 ) RetVal = GetMaske();
      ShowInfoWnd(BaseZeit,RetVal,RegNr,StatNr,Zoom,Datum);
   }
}
function MakeBeschwerde(RegNr,Datum,StatNr,Zoom,BGrnd,Maske) // Aufruf der eigentlichen Bearbeitungsfunktion
{  if ( BeschAnz<=0 )
   {  var Hoehe     = 670;
      var Breite    = 800;
      var Options   = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=yes,location=no';
Options   = '';
      window.open( 'BeschHelp.html','Beschwerde',Options );
   } else
   {  var PhpAufruf = 'Beschwerde.php?Typ=0&RegNr='+RegNr+'&Datum='+Datum+'&StatNr='+StatNr+'&Zoom='+Zoom+'&Zeit='+GetMaske();
      //if ( BGrnd!='' ) 
      PhpAufruf += '&BckGrnd=' + BGrnd;
      CloseInfoWnd();
      if ( top.Main )   top.Main.location.href                 = PhpAufruf;
      //else            parent.location.href                   = PhpAufruf;
      else            { // PhpAufruf = 'http://www.dfld.de/Mess/' + PhpAufruf;
                        // top.Frame[0].location.href             = PhpAufruf;
                        location.href             = PhpAufruf;
                        //document.write(PhpAufruf);
                        //alert (PhpAufruf);
                      }
      // var Hoehe     = 510;
      // var Breite    = 650;
      // var Options   = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=no,location=no';
      // window.resizeTo(Breite,Hoehe);
      // wndInfo = window.open( PhpAufruf,'Beschwerde',Options );
   }
}
function ShowInfoWndNeu(Lan,BaseZeit,Maske,RegNr,StatNr,Zoom,Datum) // Zeigt kuzzeitig ein Bestaetigungsfenster
{  var PhpAufruf   = 'ShowInfoWnd.php?Lan='+Lan+'&Zeit=' + BaseZeit + '&Maske=' + Maske + '&RegNr=' + RegNr + '&StatNr=' + StatNr + '&Zoom=' + Zoom + '&Datum=' + Datum;
   var Breite      = 800; // Variante Waag: 800 x 190  /  Variante Senk: 710 x 250
   var BreiteInnen = Breite - 20;
   var Hoehe       = 200; // 190 = Direkt ueber BeschwerdeLink  /  710 = 60 + BeschAnz * 16;
   var HoeheInnen  = Hoehe  - 30;
   var Options     = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',innerHeight=' + HoeheInnen + ',innerWidth=' + BreiteInnen + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=no,location=no';

   CloseInfoWnd();
   InfoHandle =  window.open( PhpAufruf,"Bestaetigung",Options );
// var cValue = new Array();
// cValue=showModalDialog(PhpAufruf,0,"dialogWidth:230px;dialogHeight:700px");

   //window.setTimeout("CloseInfoWnd();",30500);

   //InfoHandle.blur();
}
function SetBeschwerdeNeu(i,Lan,BaseZeit,RegNr,StatNr,Zoom,Datum)   // Registriert eine Einzelbeschwerde
{  if ( i>=0 && i<120 )
   {  var RetVal = "";
      if ( TwoHours[i]==0 )
           { TwoHours[i] = 1; BeschAnz++; }
      else { TwoHours[i] = 0; BeschAnz--; }
      if ( BeschAnz>0 ) RetVal = GetMaske();
      ShowInfoWndNeu(Lan,BaseZeit,RetVal,RegNr,StatNr,Zoom,Datum);
   }
}
function MakeBeschwerdeNeu(Lan,RegNr,Datum,StatNr,Zoom,BGrnd,Maske) // Aufruf der eigentlichen Bearbeitungsfunktion
{  if ( BeschAnz<=0 )
   {  var Hoehe     = 670;
      var Breite    = 800;
      var Options   = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=yes,location=no';
Options   = '';
      window.open( 'Language/BeschHelp'+Lan+'.html','Beschwerde',Options );
   } else
   {  var PhpAufruf = 'Beschwerde.php?Lan='+Lan+'&Typ=0&RegNr='+RegNr+'&Datum='+Datum+'&StatNr='+StatNr+'&Zoom='+Zoom+'&Zeit='+GetMaske();
      //if ( BGrnd!='' ) 
      PhpAufruf += '&BckGrnd=' + BGrnd;
      CloseInfoWnd();
      if ( top.Main )   top.Main.location.href                 = PhpAufruf;
      //else            parent.location.href                   = PhpAufruf;
      else            { // PhpAufruf = 'http://www.dfld.de/Mess/' + PhpAufruf;
                        // top.Frame[0].location.href             = PhpAufruf;
                        location.href             = PhpAufruf;
                        //document.write(PhpAufruf);
                        //alert (PhpAufruf);
                      }
      // var Hoehe     = 510;
      // var Breite    = 650;
      // var Options   = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=no,location=no';
      // window.resizeTo(Breite,Hoehe);
      // wndInfo = window.open( PhpAufruf,'Beschwerde',Options );
   }
}
function GetMaske()
{  var RetVal = "";
   var i;
   for ( i=0 ; i<=120 ; i++ )
      RetVal += ( TwoHours[i] ? "1" : "0" );
   return RetVal;
}

//  Funktionen zum manuellen aendern von Peaks =================================
var PeakAnz   = 0;
var PeakHours = new Array ( 0,0,0,0,0,0,0,0,0,0, // 00:00 - 00:09
                            0,0,0,0,0,0,0,0,0,0, // 00:10 - 00:19
                            0,0,0,0,0,0,0,0,0,0, // 00:20 - 00:29
                            0,0,0,0,0,0,0,0,0,0, // 00:30 - 00:39
                            0,0,0,0,0,0,0,0,0,0, // 00:40 - 00:49
                            0,0,0,0,0,0,0,0,0,0, // 00:50 - 00:59
                            0,0,0,0,0,0,0,0,0,0, // 01:00 - 01:09
                            0,0,0,0,0,0,0,0,0,0, // 01:10 - 01:19
                            0,0,0,0,0,0,0,0,0,0, // 01:20 - 01:29
                            0,0,0,0,0,0,0,0,0,0, // 01:30 - 01:39
                            0,0,0,0,0,0,0,0,0,0, // 01:40 - 01:49
                            0,0,0,0,0,0,0,0,0,0, // 01:50 - 01:59
                            0                    // 02:00
                          );

function ChgPeak(i,Lan,BaseZeit,RegNr,StatNr,Zoom,Datum)   // Registriert eine Einzelbeschwerde
{    if ( i>=0 && i<120 )
     {  var RetVal = "";
        if ( PeakHours[i]==0 )
             { PeakHours[i] = 1; PeakAnz++; }
        else { PeakHours[i] = 0; PeakAnz--; }
        if ( PeakAnz>0 ) RetVal = GetPeakMaske();
        ShowInfoWndNeu(Lan,BaseZeit,RetVal,RegNr,StatNr,Zoom,Datum);
     }
}
function SetPeak(Parameter) // Aufruf der eigentlichen Bearbeitungsfunktion
{  if ( PeakAnz<=0 )
   {  // Keine Aenderungen angefordert => Nix
      var Hoehe     = 670;
      var Breite    = 800;
      var Options   = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=yes,location=no';
      Options   = '';
      // window.open( 'Language/BeschHelp'+Lan+'.html','Beschwerde',Options );
   } else
   {  var PhpAufruf = 'PeakChg.php?'+Parameter+'&M='+GetPeakMaske();
      CloseInfoWnd();
      if ( top.IntMessMain ) top.IntMessMain.location.href = PhpAufruf;
      else                   location.href                 = PhpAufruf;
   }
}
function GetPeakMaske()
{  var RetVal = "";
   var i;
   for ( i=0 ; i<120 ; i++ )
      RetVal += ( PeakHours[i] ? "1" : "0" );
   return RetVal;
}

//  Aubau eines autonomen Zusatzfensters
//  Url    = Url des Fensterinhalts
//  Breite = Fensterbreite
//  Hoehe  = Fensterhoehe
//  Datum  = Abschaltdatum im Format jjjjmmdd
//  Zeit   = Abschaltzeit
//  Wenn das Verfallsdatum/zeit erreicht ist, wird das Fenster automatisch abgestellt
function ShowInfoWindow(Url,Breite,Hoehe,Datum,Zeit)
{  var AktDat = new Date();
   var AktJah = AktDat.getYear   (); if (AktJah < 1000) AktJah += 1900;
   var AktMon = AktDat.getMonth  ()+1;
   var AktTag = AktDat.getDate   ();
   var AktStu = AktDat.getHours  ();
   var AktMin = AktDat.getMinutes();

   if ( (AktJah*100000000 + AktMon*1000000 + AktTag*10000 + AktStu*100 + AktMin ) <=
                                             Datum *10000 + Zeit                   )
      wndInfo=window.open(Url,'Info','scrollbars=no,width='+Breite+',height='+Hoehe+',left=0,top=0');
}

function ShowRchtg()
{  var url;
   url = "http://www.DFLD.de/Mess/BetriebsRchtg.php?ShowErg=1";
   CloseZusFenster();
   ZusFensterHandle = window.open(url,'Betriebsrichtung','width=600,height=150,left=0,top=0,scrollbars=no,resizable=no,toolbars=no,status=no,directories=no,location=no');
}

function ShowRchtg2(Url,Airport,Breite,Hoehe)
{  CloseZusFenster();
   ZusFensterHandle = window.open(Url,Airport,'width=='+Breite+',height='+Hoehe+',left=0,top=0,scrollbars=no,resizable=no,toolbars=no,status=no,directories=no,location=no');
}

//  Anzeige Kommentar zu Messwert
function ShowComment(url)
{  CloseZusFenster();
   ZusFensterHandle = window.open(url,'MessKommentar','width=390,height=250,left=0,top=0,scrollbars=yes,resizable=no,toolbars=no,status=no,directories=no,location=no');
}

function ShowZusFenster(url,Breite,Hoehe)
{  CloseZusFenster();
   ZusFensterHandle = window.open(url,'Zusatz','width='+Breite+',height='+Hoehe+',left=0,top=0,scrollbars=yes,resizable=yes,toolbars=no,status=no,directories=no,location=no');
}

function CloseZusFenster()              // Schliesst Zusatzfenster
{  if ( ZusFensterHandle ) ZusFensterHandle.close();
   ZusFensterHandle = null;
}

function TrackInfo(Lan,Pos,Id,Zeit,Hoehe,RegNr,AbAn,StatNr,Aircraft,NoOpt,NoDataCorrection,Debug)   // Zeigt Flugspurinfo-Fenster
{  var LanAndEans  = Lan + '  ';
   var NoOptStr    = ( NoOpt<=0 ? '' : '&NoOpt='+NoOpt );
   var DebugStr    = ( Debug<=0 ? '' : '&Debug='+Debug );
   var PhpAufruf   = '../Mess/TrackInfo.php?L=' + LanAndEans.substring(0,1) + '&E='+LanAndEans.substring(1,2) + '&P='+Pos + '&I='+Id + '&Z='+Zeit + '&H='+Hoehe + '&R='+RegNr + '&AD='+AbAn + '&S='+StatNr + '&A='+Aircraft + '&NC='+NoDataCorrection + NoOptStr+DebugStr;
   var Breite      = 520;
   var BreiteInnen = Breite - 20;
   var Hoehe       = 740;
   var HoeheInnen  = Hoehe  - 30;
   var Options     = 'top=0,left=0,height=' + Hoehe + ',width=' + Breite + ',innerHeight=' + HoeheInnen + ',innerWidth=' + BreiteInnen + ',dependent=yes,menubar=no,resizable=yes,status=no,scrollbar=no,location=no';

   CloseInfoWnd();
   InfoHandle =  window.open( PhpAufruf,'TrackInfo',Options );
}

//  Siehe j:\WWW\...\Examples\GetPar.htm
function GetPar(ParNumm)
{  var RetVal = '';
   var ParIx  = 1;
   var ParStr = location.search;
   var NxtIx;
   while ( ParStr.length>0 )
   {  if ( ParStr.substring(0,1)!='?' &&
           ParStr.substring(0,1)!='&'  ) return('');
      RetVal = ParStr.substring(0+1);
      NxtIx  = RetVal.indexOf('&');

      if ( NxtIx>0 )
      {  RetVal = RetVal.substring(0,NxtIx);
         ParStr = ParStr.substring(1+NxtIx);
      } else
      if ( RetVal.substring(0,1)=='&' )
      {  ParStr = RetVal;
         RetVal = '';
      }
      else
         ParStr = '';
      if ( ParNumm==ParIx ) return(RetVal);
      ParIx++;
   }
   return('');
}
function GetParNam(Par)
{  var RetVal = Par;
   var NxtIx  = Par.indexOf('=');
   if ( NxtIx>0 ) RetVal = RetVal.substring(0,NxtIx);
   return ( RetVal );
}
function GetParVal(Par)
{  var RetVal = Par;
   var NxtIx  = Par.indexOf('=');
   if ( NxtIx>0 ) RetVal = RetVal.substring(1+NxtIx);
           else   RetVal = '';
   return ( RetVal );
}

//
function click(e)
{
//   var m = "(c) Eppsteiner gegen Fluglärm";
//   if ( top.Menu.BlockRight()!=0 )
//   {  if ( document.all )
//      {  if ( event.button==2 )
//         {  alert(m);
//            return false
//         }
//      }
//      if ( document.layers )
//      {  if ( e.which==3 )
//         {  alert(m);
//            return false
//         }
//      }
//   }
}

// if ( document.layers ) { document.captureEvents(Event.MOUSEDOWN) }
// document.onmousedown = click;
