//*****************************************************************************
// Constructor
//*****************************************************************************

function Browser()
{
  activeLayer = "";
  activeForm  = 0;  // First form (assuming there is one)
  modalWindow = null;
}

//*****************************************************************************
// Common functionality
//*****************************************************************************

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Return the browser overview
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.getOverview = function()
{
  return(this.getName() + " " + this.getVersion());
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Return the browser version
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.getVersion = function()
{
  return(parseInt(navigator.appVersion));
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Return a form object
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.getForm = function(formName)
{
    return(document.forms[formName]);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Return the active form object
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.getActiveForm = function()
{
    return(document.forms[activeForm]);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Return an applet object
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.getApplet = function(appletName)
{
    return(document.applets[appletName]);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Activate a layer
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.setActiveLayer = function(layerName)
{
  if(activeLayer != "")
  {
    this.hideLayer(activeLayer);
  }

  activeLayer = layerName;
  this.showLayer(activeLayer);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Activate a form
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.setActiveForm = function(formName)
{
  activeForm = formName;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Open a modal window
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.openModalWindow = function(url,opts)
{
    this.modalWindow = window.open(url,opts);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Reset a modal window
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.clearModalWindow = function()
{
    this.modalWindow = null;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Refocus to a modal window
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Browser.prototype.refocusModalWindow = function()
{
    if(this.modalWindow != null)
    {
        blur();
        this.modalWindow.focus();
    }
}

//*****************************************************************************
// DOM2 functionality
//*****************************************************************************

if(isDOM2())
{
  Browser.prototype.getName = function() { return("DOM2"); }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Return an element
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.getElement = function(elementId)
  {
    return(document.getElementById(elementId));
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Show a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.showLayer = function(layerName)
  {
    var thisDiv = this.getElement(layerName);
    thisDiv.style.visibility = "visible";
    //thisDiv.style.visibility = ""; // Important, causes subdivisions to borrow from parent

    // Forces a redraw (bug in Navigator 7.02)
    //window.resizeBy(1,1);
    //window.resizeBy(-1,-1);
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Hide a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.hideLayer = function(layerName)
  {
    var thisDiv = this.getElement(layerName);
    thisDiv.style.visibility = "hidden";

    // Forces a redraw (bug in Navigator 7.02)
    //window.resizeBy(1,1);
    //window.resizeBy(-1,-1);

  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Dynamically update a layer body
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.setLayerBody = function(layerName, html)
  {
    var thisElement = this.getElement(layerName);
    thisElement.innerHTML = html;
  }
}

//*****************************************************************************
// Opera functionality
//*****************************************************************************

if(isOpera())
{
  Browser.prototype.getName = function() { return("Opera"); }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Return an element
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.getElement = function(elementId)
  {
    return(document.getElementById(elementId));
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Show a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.showLayer = function(layerName)
  {
    var thisDiv = this.getElement(layerName);
    thisDiv.style.visibility = "visible";
    //thisDiv.style.visibility = ""; // Important, causes subdivisions to borrow from parent
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Hide a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.hideLayer = function(layerName)
  {
    var thisDiv = this.getElement(layerName);
    thisDiv.style.visibility = "hidden";
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Dynamically update a layer body
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.setLayerBody = function(layerName, html)
  {
    var thisElement = this.getElement(layerName);
    thisElement.innerHTML = html;
  }
}

//*****************************************************************************
// IE functionality
//*****************************************************************************

if(isIE())
{
  Browser.prototype.getName = function() { return("IE"); }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Return an element
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.getElement = function(elementId)
  {
    return(document.all[elementId]);
  }
  
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Show a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.showLayer = function(layerName)
  {
    with(document.all[layerName].style)
    {
      visibility = "visible";
      //visibility = ""; // Important, causes subdivisions to borrow from parent
    }
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Hide a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.hideLayer = function(layerName)
  {
    document.all[layerName].style.visibility = "hidden";
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Dynamically update a layer body
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.setLayerBody = function(layerName, html)
  {
    var thisElement = this.getElement(layerName);
    thisElement.innerHTML = html;
  }
}

//*****************************************************************************
// Netscape functionality
//*****************************************************************************

if(isNetscape())
{
  Browser.prototype.getName = function() { return("Netscape"); }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Return an element
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.getElement = function(elementId)
  {
    return(eval("document." + elementId));
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Show a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.showLayer = function(layerName)
  {
    document.layers[layerName].visibility = "show";
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Hide a layer
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.hideLayer = function(layerName)
  {
    document.layers[layerName].visibility = "hide";
  }

  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  // Dynamically update a layer body
  //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  Browser.prototype.setLayerBody = function(layerName, html)
  {
    var thisElement = this.getElement(layerName);
    thisElement.document.writeln(html);
    thisElement.document.close();
  }
}

var browser = new Browser();
