function getHTTPObject() {
  var xhr = false; // Pre-defining the xhr variable
  if (window.XMLHttpRequest) { // Firefox, Safari, Opera and Netscape and IE7 all use this
    xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // Below IE7 uses this
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP"); // IE 6
    } catch(e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP"); // IE 5
      } catch(e) {
        xhr = false; // Browser seemingly does not support XHR
      };
    };
  };
  return xhr;
};

function fillElementId(url,elementId,parameters) {
	if(!document.getElementById(elementId)) { // Make sure the element exists
		return; // If it doesn't, no need to run this script
	};
	parameters = encodeURI(parameters); // Encode the parameters (changes " " to "%20", etc.)
	var xmlHttp = getHTTPObject(); // Calling the XHR (XMLHttpRequest)
	xmlHttp.onreadystatechange=function(){ // Fires every time the readyState changes
		if(xmlHttp.readyState==4){
		/* 
		readyState can be any of the following:
		0 = uninitialized
		1 = connection open
		2 = data sent
		3 = receiving data
		4 = transaction complete
		*/
			if(xmlHttp.status==200){
			/*
			status is the HTML status received, these are the most commonly received:
			200 = OK
			301 = Redirected
			400 = Bad Request
			401 = Unauthorized
			403 = Forbidden
			404 = Not Found
			408 = Request Timeout
			500 = Internal Server Error
			503 = Service Unavailable
			*/
				document.getElementById(elementId).innerHTML = xmlHttp.responseText; // For XML, you can use responseXML
				/*
				This simply replaces everything in the container with the ID we specified
				with whatever is in the variable 'xmlHttp.responseText'
				*/
				xmlHttp=null; // This removes the reference to the object
			} else { // "Not Found"
				alert("Error: "+xmlHttp.statusText); //Will output what the server returns, such as "Not Found" or "Forbidden"
			};
		};
	};
	xmlHttp.open('POST',url,true);  //request method (GET/POST), page url, asynchronous(true/false)
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Send a urlencoded form
	xmlHttp.setRequestHeader("Content-Length", parameters.length); // Declare the length of the parameters
	xmlHttp.setRequestHeader("Connection", "close"); // Close the connection
	xmlHttp.send(parameters); //send the request with parameters
};