// browsers.js
// -----------
// cross browser compatibility for context information
// - has to be included as first javascript file as far as context is checked
// - self-initializes browser context information
//----------------------------------------------------------------------------

//
// GLOBALS
//
var myCtx;   // global object holding browser information


//
// FUNCTIONS
//

// sniffContext:
// -------------
// - set global browser and behavior switches,
// - set browser type and version info
// - alert unknown browsers
// - redirect to sorry.html if DYN is not supported
// - returns a context object with all switches set
function sniffContext()
{
    // Init browser context
    this.DYN = 0;   // check for dynamic html, if 0 -> old browser (< V4)
    this.DOM = 0;   // check for support of the DOM, if 0 NET or MI4 V4

    this.OPE = 0;   // Switch for Opera
    this.GEC = 0;   // Switch for Netscape 6 (Gecko) and new Mozilla
    this.NET = 0;   // Switch for Netscape 4
    this.MI4 = 0;   // Switch for Microsoft IE V4
    this.MIC = 0;   // Switch for Microsoft IE V5,6

    this.brType    = "unknown";   // Browser type: Net (Netscape 4), Gec (Netscape 5+), Mic or Ope
    this.brName    = "unknown";   // Browser type, full string
    this.brVersion = "unknown";   // Browser version


    // Recognize Opera
    if (window.opera)   this.OPE = 1;


    // if document.getElementById is supported, the browser supports DYN and DOM,
    // probably new browser, like Gecko, Opera 6 or IE 5,6
    if (document.getElementById)
    {
        this.DYN = 1;
        this.DOM = 1;
    }


    // if document.all is supported, the browser supports DYN, but not DOM
    // probably IE 4 (Opera supports them all)
    if (document.all && !DOM && !OPE)
    {
        this.DYN = 1;
        this.MI4 = 1;
    }


    // if document.layers is supported, the browser supports DYN, but not DOM
    // probably Netscape 4 (Opera supports them all)
    if (document.layers && !OPE)
    {
        this.DYN = 1;
        this.NET = 1;
    }


    // redirect if not dynamic (old browsers < V4)
    if (!this.DYN)   location.replace("sorry.html");


    // set browser name and version information
    this.brType    = navigator.appName.substring(0,3);
    this.brName    = navigator.appName;
    this.brVersion = parseInt(navigator.appVersion.substring(0,3));

    // Set Browser switches and distinguish between Netscape 4 and Gecko
    // and between IE 4 and other IE
    if ((this.brType == "Net") && (this.DOM))    this.GEC = 1;
    if ((this.brType == "Mic") && (this.DOM))    this.MIC = 1;

    // check browser type an alert if unknown
    if (!this.GEC && !this.NET && !this.MIC && !this.MI4 && !this.OPE)
    {
      // alert a warning message
      alert("Diese Seiten wurden nicht fuer Ihren Browser: \n" +
            this.brName + " Version " + this.brVersion + "\ngetestet und werden " +
            "daher u.U. nicht korrekt dargestellt !\n\n" +
            "These pages were not tested for your browser: \n" +
            this.brName + " Version " + this.brVersion + "\nand may not display correctly !");

      // treat them depending on DOM as IE6 or IE4
      if   (this.DOM)
           this.MIC = 1;
      else this.MI4 = 1;
    }

    return this;
}

// From here on, the browser context is available
myCtx = sniffContext();


// testContext
// - requires myCtx to be set
function testContext()
{
    alert("DOM:" + myCtx.DOM + " DYN:" + myCtx.DYN);
    alert("Name: " + myCtx.brName + " Typ: " + myCtx.brType + " Version: " + myCtx.brVersion);
    alert("GEC:" + myCtx.GEC + " NET:" + myCtx.NET + " MIC:" + myCtx.MIC + " MI4:" + myCtx.MI4 + " OPE:" + myCtx.OPE);
}

// Uncomment to test browser context
// testContext();


// Netscape 4 resize problem
function neuladen()
{
  top.window.location.reload()
}

function setResize()
{
  setTimeout("top.window.onresize=neuladen",500);
}

if (myCtx.NET)  top.window.onload = setResize;
