/*
 * Replaces the innerHTML contents of the named element with the contents
 * retrieved from the given href (url).
 */
function ajaxReplace(elemId, href) {
  var elem = document.getElementById(elemId);
  if (elem == null) {
    alert("Sorry, this web page is broken.\nHTML element with id '"+elem+"' not found.");
    return;
  }
  
  var xmlHttp = getXmlHttpObject();
  if (xmlHttp == null) {
    alert("Sorry, AJAX is not supported in this browser.");
    return;
  }
  xmlHttp.open("GET", href, true); 
  function genericAjaxCallback() {
	    if (xmlHttp.readyState == 4) { 
			try {
				if (xmlHttp.status == 200) { 
					elem.innerHTML = xmlHttp.responseText;
					elem.style.visibility="visible";
		        } else {
		    		elem.innerHTML = "Error encountered. xmlHttp.status =" + xmlHttp.status + "\n" + xmlhttp.responseText;
		  		}
	        } catch (err) {
	        	elem.innerHTML = "Error encountered: "+err+"\nxmlHttp.status =" + xmlHttp.status + "\n" + xmlhttp.responseText;
	        }
		}  
	}
    xmlHttp.onreadystatechange = genericAjaxCallback;
    xmlHttp.send("");
}

function getXmlHttpObject() {
  var xmlHttp;
  try {
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        return null;
      }
    }
  }
  return xmlHttp;  
}
