

function HO_ApplyOverlay(url)
{
  var p;
  try {
    p = new XMLHttpRequest();
  } catch (e) {
    p = new ActiveXObject("Msxml2.XMLHTTP");
  }

  try {
   
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
  } catch (e) {
   
  }

  
  p.open("GET", url, false);
  p.send(null);

  
  var doc = p.responseXML;

  
  if (doc)
  {
   
    if (doc.documentElement &&
        doc.documentElement.nodeName == "XMLoverlay")
    {
     
      var child = doc.documentElement.firstChild;
      while (child)
      {
        if (child.nodeType == 1 &&
            child.getAttribute("id"))
        {
          
          var a = child.attributes;
          var t = document.getElementById(child.getAttribute("id"));
          if (t)
          {
            
            HO_cloneNodeDeep(child.firstChild, t);
          }
         
          for (var i=0; i<a.length; i++)
          {
            var sourceAtt = a[i];
            try{
            t.setAttribute(sourceAtt.nodeName, sourceAtt.nodeValue);
            }
            catch(e){}
          }
        }
        child = child.nextSibling;
      }
    }
  }
}

function HO_cloneNodeDeep(source, target)
{
  
  while (source)
  {
    switch (source.nodeType)
    {
      case 1:
       
        var clone = document.createElement(source.nodeName);
      
        var refElt = null;
        var insertbefore = source.getAttribute("insertbefore");
        if (insertbefore)
          refElt = document.getElementById(insertbefore);
        if (insertafter && !refElt)
        {
          var insertafter  = source.getAttribute("insertafter");
          if (insertafter)
            refElt = document.getElementById(insertafter);
          if (refElt)
            refElt = refElt.nextSibling;
          else
          {
            var position = source.getAttribute("position");
            if (position)
            {
              
              var index = 0;
              refElt = target.firstChild;
              while (refElt)
              {
                if (refElt.nodeType == 1)
                  index++;
                if (index == position)
                  break;
                refElt = refElt.nextSibling;
              }              
            }
          }
        }
        
        
        target.insertBefore(clone, refElt);
        var a = source.attributes;
        for (var i=0; i<a.length; i++)
        {
         
          var sourceAtt = a[i];
          switch (sourceAtt.nodeName.toLowerCase())
          {
            case "class":
             
              clone.className = sourceAtt.nodeValue;
              break;
            case "insertbefore":
            case "insertafter":
            case "position":
             
              break;
            default:
              clone.setAttribute(sourceAtt.nodeName, sourceAtt.nodeValue);
              break;
          }
        }
      
        if (source.firstChild)
          HO_cloneNodeDeep(source.firstChild, clone);
        break;

      case 3:
      
        clone = document.createTextNode(source.data);
        target.appendChild(clone);
        break;

      default:
       
        break;
    }
   
    source = source.nextSibling;
  }
}

function HO_ApplyOverlays()
{
  var d = document;
  var linkCollection = d.getElementsByTagName("link");
  var linkCollectionLength = linkCollection.length;
  for (var i=0; i<linkCollectionLength; i++)
  {
    var theLink = linkCollection[i];
    if (theLink.parentNode &&
        theLink.parentNode.nodeName.toLowerCase() == "head")
    {
      if (theLink.getAttribute("rel").toLowerCase() == "overlay")
        HO_ApplyOverlay(theLink.getAttribute("href"));
    }
  }
}

function HO_addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


HO_addLoadEvent(HO_ApplyOverlays);

