HttpCall = {};
HttpCall.http = false;
if (navigator.appName == "Microsoft Internet Explorer") {
    HttpCall.http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
    HttpCall.http = new XMLHttpRequest();
}

HttpCall.animation = "HttpCallAnimation";

/**
 Just supply a url and an elementId and it set the inner html of the element to be the result of the call to the url
 **/
HttpCall.replaceElement = function(urlOrForm, elmId) {
    HttpCall.call(urlOrForm, function() {
        document.getElementById(elmId).innerHTML = HttpCall.http.responseText;
    });
}

HttpCall.buildURL = function(form) {
    var url = form.action + "?";
    var allElms = form.elements;
    var elm;
    for (var i = 0; i < allElms.length; i++) {
        elm = allElms[i];
        if (elm.name == '' || elm.tagName == 'FIELDSET') {
            continue;
        }
        if (elm.type.toLowerCase() == 'checkbox' && !elm.checked) {
            continue;
        }
        if (elm.type.toLowerCase() == 'select-multiple') {
            for (var x=0; elm.options[x]; x++) {
                if (elm.options[x].selected) {
                    url += elm.name + '=' + elm.options[x].value + '&';
                }
            }            
        } else {
            url += elm.name + '=' + elm.value + '&';
        }
    }
    return url;
}

HttpCall.call = function(urlOrForm, onready) {
    if (document.getElementById(HttpCall.animation)) {
        document.getElementById(HttpCall.animation).style.display = 'block';
    }
    var url = (typeof urlOrForm == 'string') ? urlOrForm : HttpCall.buildURL(urlOrForm);
    var connectorString = "?";
    if (url.indexOf("?",0)>-1) {
        connectorString = "&";
    }
    HttpCall.http.open("GET", url + connectorString + "rnd=" + (new Date()).getTime(), true);
    if (onready) {
        HttpCall.http.onreadystatechange = function() {
            if (HttpCall.http.readyState == 4) {
                onready();
                if (document.getElementById(HttpCall.animation)) {
                    document.getElementById(HttpCall.animation).style.display = 'none';
                }
            }
        }
    }

    HttpCall.http.send(null);
}

