function createXMLHttpRequest() {

var XHR = null,
 
 browserUtente = navigator.userAgent.toUpperCase();

 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();
                                       
 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {
    
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
}


function requestPage(page, method, pars, ok_func, err_func, cal){
    //TODO make pars to be an array
    var ajax = createXMLHttpRequest();
    if(!ajax) {
        alert("AJAX Error!");
        return false;
    } else {
        ajax.onreadystatechange = function() {
            if(ajax.readyState === 4) {
              if(ajax.status == 200) {
                ok_func(ajax.responseText, cal);
              } else {
                err_func();
              }
            }
        }
        ajax.open(method, page);
        if(method == 'post') {
        	ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        }
        ajax.setRequestHeader("connection", "close");
        ajax.send(pars);
    }
}   