function newXMLHttpRequest() {
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
    rnd.seed = (rnd.seed*9301+49297) % 233280;
    return rnd.seed/(233280.0);
}

function rand(number) {
    return Math.ceil(rnd()*number);
}

function getHost() {
    s = window.location.href;
    a = s.split("/");
    return a[2];
}

// json_data is use in JsonUtils.
function getServerResponse(url, jsonString, callBack) {
    //alert('getServerResponse() is invoked with data: '+url + ':' + jsonString + ":" + callBack);
    var xmlhttp = newXMLHttpRequest();
    if (xmlhttp) {
        url = "http://" + getHost() + url + "?json_data=" + jsonString + "&rnd=" + rand(10000000) + "";
        //alert(url);
        xmlhttp.open("GET", url, true);
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                if (xmlhttp.status == 404) {
                    // for site do not implement this servlet.
                    // return error page.
                    //alert('404 not found.');
                }
                else {
                    res = xmlhttp.responseText;
                    //alert('response : ' + xmlhttp.responseText);
                    if (res != '') 
                        callBack(eval('(' + res + ')' ));
                    else
                        callBack();  
                }
            }
        }
        xmlhttp.send(null);
        return false;
    }
    return true;
}

