// Global variables
var active_div_replace=false;

// Include the content of a given URL in a div
function replace_content(pURL, pNodeId) {

  if (!active_div_replace){
    active_div_replace=true;
    var url=pURL;
    if (arguments.length>=2) {
      rfNodeId=pNodeId;
    }
  
    // empty the div
    // document.getElementById(rfNodeId).innerHTML='';
    // alert(pURL);
    
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=replace_div_HTML;
      xmlhttp.open("GET", pURL, true); // leave true for Gecko
      xmlhttp.send(null);
    } else if (window.ActiveXObject) { //IE 
      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
      if (xmlhttp) {
        xmlhttp.onreadystatechange=replace_div_HTML;
        xmlhttp.open('GET', pURL, false);
        
        xmlhttp.send();
      }
    } else {
      alert('Your browser does not appear to support remote scripting.');
      xmlhttp=false;
      active_div_replace=false;
    }
    
    if ((typeof(xmlhttp))!='object') {
      document.write('You need to upgrade your browser to use this page.\r\nAs of March 2006 more than 98% of the web browsers in use support the remote scripting object. Either your browser does not support remote scripting or the support has been disabled.');
      active_div_replace=false;
    }
  }else{
    window.setTimeout("replace_content('"+pURL+"','"+pNodeId+"');",1);
  }
}

// function to replace the HTML of a div produced by the replace_content function
function replace_div_HTML(){
  if (xmlhttp.readyState==4) {
    if (xmlhttp.status==200) {
      if (rfNodeId=='') {
        document.write(xmlhttp.responseText);
        active_div_replace=false;
      }else{
        document.getElementById(rfNodeId).innerHTML=xmlhttp.responseText;
	active_div_replace=false;
      }
    }
  }
}