// include  <SCRIPT src='/javascript/dynamic_content.js'></SCRIPT> in <head> tag
// Place additional comments here

var dcontent_div;
var updater_function;
var can_change_content = true;
var flag = 0
var done_already = 0


// This is a private function used to make it work across browsers.
function dyn_init() {
  done_already = 1
  var range;
  if ( document.createRange ) {
    range = document.createRange();
  }

  if ( range && range.createContextualFragment ) {
    updater_function = function( new_html ) {
      rng = document.createRange();
      rng.setStartBefore( this );
      html_frag = rng.createContextualFragment( new_html );
      while ( this.hasChildNodes() ) {
        this.removeChild( this.lastChild );
      }
      this.appendChild( html_frag );
    }
  }
  else if ( document.all ) {
    updater_function = function( new_html ) {
      this.innerHTML = new_html;
    }
  }
  else if ( document.layers ) {
    updater_function = function( new_html ) {
      this.document.ns4dcontent.document.write( new_html );
      this.document.ns4dcontent.document.close();
    }
  }

  if ( ! document.getElementById || ! updater_function ) {
    alert( "Error: Browser will not show change in content" );
    can_show_progress = false;
    return;
  }
}

// This takes the name of the element to change and the text to change it to.
function alter_content(name, text) {
  dcontent_div = document.getElementById(name);
  if ( dcontent_div ) {
     dcontent_div.update_content = updater_function;
     dcontent_div.update_content( text );
  }
}

// Takes a name of the element to be used by alter_content() and the initial
// text.  If no text is passed in it will put a space there.
function writer (name, text)
{

  name = name.replace(/&/g,"&amp;");
  name = name.replace(/'/g,"&apos;");
  name = name.replace(/</g,"&lt;");

  if (!text) {
    text = '&nbsp;&nbsp;';
  }

  // flag is used to see if getElementById has already been defined
  if ( document.layers && !document.getElementById || flag == 2 ) {
    document.write ( "<ilayer id='" + name + "' width='100%'>" +
    "<layer id='ns4dcontent' width='100%'>" + text + "</layer></ilayer>" )

    if ( !done_already ) {
      flag = 2
      document.getElementById = function(id) {
        return document.layers[id]
      }
    }
  }
  else {
    document.write ("<span id='" + name + "'>" + text + "</span>\n")

    if ( document.all && !document.getElementById && !done_already ) {
      alert( "document.all, still need to check for functionality" );
      document.getElementById = function(id) {
        return document.all[id]
      }
    }
  }

  if ( !done_already ) {
    dyn_init()
  }
}

