/*
   JavaSkript Bibliothek
   ------------------------------------------------------------------------------
   Um diese Bibliothek nutzen zu koennen, muessen die Eintraege
   o <script language="JavaScript" SRC="Pfad/CookIslands.js"></script> im Header und
   o <script language="JavaScript"> Befehl() ; </script> an der entsp. Stelle
   eingebunden sein
*/

// -------- Globale Funktionen -----------
// Eigene Fehlerbehandlung aktivieren
window.onerror = Fehler ;


// -------- Unterfunktionen ---------------
// Fehlerausgabe in Statuszeile
function Fehler(meldung, url, zeile)
{
  if (self.location.protocol.toString() != "file:")
  {
    // Fehler in Statuszeile -> kein laestiges Bestaetigen ...
    window.status = "JavaScript-Error URL >"+url+"< Line >"+zeile+"<: "+meldung ;
  }
  else
  {
    // Auf lokalem Rechner -> richtig anzeigen
    alert("JavaScript-Error:\nURL >"+url+"<\nLine >"+zeile+"<\n"+meldung) ;
  }
  // Keine Standard-Behandlung mehr
  return true ;
}

// Document initialisieren
// o Frameset prfen
function DocumentInit(cLocRef)
{
  // Ist die Seite im Frame geladen (sonst keine Navigation moeglich)
  // Dies kann bei Aufruf ueber Link von Suchmaschine passieren
  //
  // Funktioniert teilweise - aufgrund von Sicherheitseinstellungen im Browser -
  // NICHT, wenn jemand anderes eine Seite (nicht Startseite)
  // in einem fremdem Frameset laedt
	//alert(parent.frames.length) ;
	
  //if (parent.frames.length == 0)
	//alert("DocumentInit: " + cLocRef + " - " + top.frames.length.toString() );
	if (top.frames.length != 3)
  {
    // Keine Frames vorhanden
		if (top.location.protocol == "file:")
      top.location.href = "index.html?" + cLocRef ;
		else
		  top.location.href = "Redirect.php?" + cLocRef ;
  }
	else
	{
	  if (cLocRef.length >= 4)
    {
      // Fuehrendes ? entfernen
	    cLocRef = cLocRef.substring(1);
	    nPos    = cLocRef.lastIndexOf('?');

		  if (nPos != -1)
	    {
			  cCont = cLocRef.substring(nPos + 1) ;
				//alert("Replace0: " + cCont) ;
			  frames[0].location.replace(cCont) ;
		  }
		}
	}
}

// Laedt einen bestimmten Frame (Variable nMode hier nicht gebraucht)
function FrameLoad(cQuery)
{
  // Falls Internet-Startseite NICHT in TopFrame laeuft
  // dorthin bringen - Funktionert teilweise wg. Browsersicherheit nicht
  if (top.location.href != this.location.href)
  {
    top.location.href = this.location.href ;
  }

  // DEBUG
  //alert("FrameLoad:" + cQuery) ;

  if (cQuery.length >= 4)
  {
    // Fuehrendes ? entfernen
	  cQuery = cQuery.substring(1);
	  nPos   = cQuery.lastIndexOf('&');

	  if (nPos != -1)
    {
		  cFrame = cQuery.substring(0, nPos) ;
			cPage  = cQuery.substring(nPos + 1) ;
	  }
    else
    {
      cFrame = cQuery ;
			cPage  = "" ;
    }
		
		//alert("FrameLoad: " + cQuery + "\r\n" + cFrame + " - " + cPage + " - " + nPos.toString() ) ;

		//
		if (cPage == "")
			frames[2].location.replace(cFrame) ;
		else
			frames[2].location.replace(cFrame + "?" + cPage) ;
  }
  else
  {
    return true;
  }
}

