// dom constants
var w3cDom = 1;
var ieDom = 2;
var ns4Dom = 3;
var lvl0Dom = 4;

// domType constants
var lvl1Html = 1;
var lvl1Xml = 2;

var dom; // DOM to use
var domType; // DOM level and type (W3C only)
var advancedDom; // Advanced DOM (W3C only, can create/delete elements)

function isOpera6()
{
  
  return window.opera && window.print && !window.document.childNodes;
  
}

function canDoDhtml()
{
  
  return dom == ieDom || dom == ns4Dom || domType == lvl1Html;
  
}

function detectDom()
{
  
  if (window.document.getElementById) dom = w3cDom;
  else if (window.document.all) dom = ieDom;
  else if (window.document.layers) dom = ns4Dom;
  else if (window.document.forms) dom = lvl0Dom;
  
}

function detectDomType()
{
  
  if (dom == w3cDom && document.forms) domType = lvl1Html;
  else if (dom == w3cDom && !document.forms) domType = lvl1Xml;
  
}

function detectAdvancedDom()
{
  
  if (dom == w3cDom && window.document.createElement && !isOpera6())
    advancedDom = true;
  else advancedDom = false;
  
}

/*
  Retrieves element 'id'. Returns an object with the following members:
  object | The element itself
  style  | The element's style object
*/
function getElement(id)
{
  
  switch (dom)
  {
    case w3cDom:
      
      this.object = window.document.getElementById(id);
      
      if (this.object) this.style = this.object.style;
      break;
      
    case ieDom:
      
      this.object = window.document.all(id);
      if (this.object) this.style = this.object.style;
      
      break;
      
    case ns4Dom:
      
      this.object = eval("window.document." + id);
      if (this.object) this.style = this.object;
      
      /* break; */
      
  }
  
}

/* TEMPORARY! */
function getAttribute(element, attribute)
{
  
  if (dom == w3cDom)
  {
    if (domType == lvl1Html)
    {
      return eval("element." + attribute);
    }
    else
    {
      return element.getAttribute(attribute);
    }
  }
  else if (dom == ieDom || dom == nn4Dom)
  {
    return eval("element." + attribute);
  }
  
}

detectDom();
detectDomType();
detectAdvancedDom();
