function tickreelRequest(url, content, loadFunction, argObj){
    this.url = url == null ? "" : url;
    this.content = content;
    this.loadFunction = loadFunction;
    this.argObj = argObj;
}

var requestHandler = {};
requestHandler.handleRequest = function(req){
    try {
        if (_Debug) 
            netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    } 
    catch (ex) {
    }
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest()
    }
    else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP")
    }
    var url = req.url;
    if (req.content) {
        url += "?";
        var b = true;
        for (var key in req.content) {
            var obj = req.content[key];
            if (obj) {
                if (obj.type == 'Array') 
                    obj = obj.join(";");
                if (b) {
                    url += key + "=" + obj;
                    b = false;
                }
                else 
                    url += "&" + key + "=" + obj;
            }
        }
    }
    url += "&ms=" + new Date().getTime();
    xhttp.open(_Method, url, true);
    if (isIE()) {
        xhttp.onreadystatechange = function(){
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                responseCmd(xhttp.responseText, req.loadFunction, req.argObj);
            }
        }
    }
    else {
        xhttp.onreadystatechange = function(){
            if (xhttp.readyState == 3) {
                responseCmd(xhttp.responseText, req.loadFunction, req.argObj);
            }
        }
    }
    xhttp.send(null);
}

function responseCmd(str, loadFun, argObj){
    try {
        var obj = json_parse(str);
        if (obj.stat != "0") {
            alert(obj.errmsg);
        }
        else 
            if (loadFun) 
                loadFun(obj, argObj);
    } 
    catch (ex) {
        alert(ex);
    }
}


/* this function is for suggested tickers at search box ticker. */
function getSuggestions(txtValue){
    var url = getServerUrl(SUGGESTION_PATH);
    var usr = getUserId();
    var input = txtValue;
    var req = new tickreelRequest(url, {
        usr: usr,
        input: input
    }, populateSuggestionArray, {
        targetPane: 'targetDiv',
        txtValue: txtValue
    });
    requestHandler.handleRequest(req);
}

