// Thank you: http://www.thefutureoftheweb.com/blog/2006/5/using-ajax-without-server-side-scripting
// Author: Jesse Skinner 2006-05-23
function httpRequest(url, callback) {
    var httpObj = false;
    if (typeof XMLHttpRequest != 'undefined') {
        httpObj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try{
            httpObj = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e) {
            try{
                httpObj = new ActiveXObject('iMicrosoft.XMLHTTP');
            } catch(e) {}
        }
    }
    if (!httpObj) return;

    httpObj.onreadystatechange = function() {
        if (httpObj.readyState == 4) { // when request is complete
            callback(httpObj.responseText);
        }
    };
    httpObj.open('GET', url, true);
    httpObj.send(null);
}

// Author: mark byram 2007-04-10
function ajax_replace(id, url) {
  var myHandler = function(msg) {
    var myElement = document.getElementById(id);
    if (myElement) {
      // MS IE broken when replacing the innerHTML of a select element!
      // see also http://www.sitecrafting.com/blog/ltselectgt-tag-innerhtml/
      if (myElement.outerHTML && myElement.nodeName.toUpperCase() == "SELECT") {
        myElement.outerHTML = myElement.outerHTML.replace(/(<SELECT[^>]*>).*?(<\/SELECT>)/i, '$1'+msg+'$2');
      }
      else {
        myElement.innerHTML = msg;
      }
    }
    else {
      alert("Error: unable to locate element with id '"+id+"' within document!");
    }
  } // myHandler
  httpRequest(url, myHandler);
} // ajax_replace
