
function xulHost(hostElementID, id, width, height, sourceuri, source) {
  var hostElement = document.getElementById(hostElementID);
  var innerHTML;

  if (navigator.appVersion.indexOf("MSIE") != -1) {   
    // IE detection

    innerHTML = "<object id=\"" + id + "\" width=\"" + width + "\" height=\"" + height + "\" classid=\"clsid:1339B54C-3453-11D2-93B9-000000000000\"></object>";

    var delayedUri = "";
    if (sourceuri != null) {
      if (sourceuri.indexOf("://") == -1) {
        var baseUri = location.href;
        if (sourceuri.indexOf("?") == -1) {
          baseUri = baseUri.substring(0, baseUri.lastIndexOf("?"));
        }
        baseUri = baseUri.substring(0, baseUri.lastIndexOf("/")) + "/";
        delayedUri = baseUri;
      }

      delayedUri += sourceuri;
    }
    else if (source != null) {
      delayedUri += "data:application/vnd.mozilla.xul+xml," + encodeURIComponent(source);
    }

    var delayedJS = id + ".Navigate(\"" + delayedUri + "\")";
    setTimeout(delayedJS, 1000);
  }
  else if (navigator.userAgent.indexOf("Gecko") != -1) {   
    // XUL enabled detection

    innerHTML = "<iframe id=\"" + id + "\" width=\"" + width + "\" height=\"" + height;

    if (sourceuri != null) {
      innerHTML += "\" src=\"" + sourceuri + "\"";
    }
    else if (source != null) {
      var dataURI = "data:application/vnd.mozilla.xul+xml," + encodeURIComponent(source);
      innerHTML += "\" src=\"" + dataURI + "\"";
    }
    
    innerHTML += "/>";
  }
  else {     
    innerHTML =  "<div width=\""+ width + "\" height=\"" + height + "\" >"; 
    innerHTML += "You must be running Firefox or IE to view 'XUL/E' content on this page.";
    innerHTML += "</div>"
  }        

  hostElement.innerHTML = innerHTML;
}
