//http_request is global handle to XMLHTTP instance
//TODO: rewrite to use an array of handles
var http_request;

function makeRequest(url,action,additionalParam) {

   //send a request to the server (GET url) an set action as trigger for the response
   //function can receive a single additional parameter
   //TODO: rewrite to accept multiple params

   http_request=false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
       }   catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
           }
   }

    if (!http_request) {
        alert('Cannot create an XMLHTTP instance');
        return false;
    } else {
        //set as trigger a new function which pass to 'action' function the index of the http_request object
        if(!additionalParam) additionalParam='';
        else additionalParam="'"+additionalParam+"'";

        http_request.onreadystatechange =
                new Function(action+'('+additionalParam+');');
        http_request.open('GET',url, true);
        http_request.send(null);
    }

}

function getResponse(type) {

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
           if (type=='xml') {
              return http_request.responseXML;
           } else {
              return http_request.responseText;
           }
        } else {
            alert('getResponse:: There was a problem with the request. Status:'+ http_request.status);
            return false;
        }
    } else {
        return false;
    }
}



