// Get the HTTP Object
function getHTTPObject()
{
  if (window.ActiveXObject) 
	return new ActiveXObject("Microsoft.XMLHTTP");
  else if (window.XMLHttpRequest) 
	return new XMLHttpRequest();
  else 
  {
	  alert("Your browser does not support AJAX.");
	  return null;
  }
}
  
/**
* This function executes an action at the server and writes the response
* into the referenced element
* 
* @param action - the action to execute at the server
* @param callback - the callback function to use when a response is received
* @param elementId - the ID to write the returned results to (raw HTML)
* @param paramter - an optional paramter to pass to the server
*
*/
function sndReq(action, callback, elementId, param) 
{
	var http = getHTTPObject();
	http.open('get', './php/server.php?action=' + action + '&param=' + param);
	http.onreadystatechange = function() { handleResponse(callback, http, elementId) };
	http.send(null);
}


function handleResponse(callback, http, elementId)
{
    if( ( http != undefined ) && (http.readyState == 4) )
	{
        var response = http.responseText;
		
        if( (callback != undefined) &&(response.length > 0) )
		{
			callback(response, elementId);
        }
    }
}
