var g_comparer;

function onLoad(language, prefix, context, refresh) {
    g_comparer = new Comparer(language, document.getElementById("id_comparer"), prefix + "../comparer.php.htm");
    if (refresh) {
        g_comparer.refresh();
    }
}

function Comparer(language, container, url) {
    this.container = container;
    this.language = language;
    this.url = url;
}

Comparer.prototype.add = function(id) {
    var _this = this;
    Ajax.post(this.url, "action=add&id=" + id + "&l=" + this.language, function(html) {_this.setContent(html);});
}

Comparer.prototype.remove = function(id) {
    var _this = this;
    Ajax.post(this.url, "action=remove&id=" + id + "&l=" + this.language, function(html) {_this.setContent(html);});
}

Comparer.prototype.reset = function() {
    var _this = this;
    Ajax.post(this.url, "action=reset&l=" + this.language, function(html) {_this.setContent(html);});
}

Comparer.prototype.refresh = function() {
    var _this = this;
    Ajax.post(this.url, "action=refresh&l=" + this.language, function(html) {_this.setContent(html);});
}

Comparer.prototype.setContent = function(html) {
    this.container.innerHTML = (html && html != "0") ? html : "";
}


function Ajax() {
}

Ajax.post = function(url, query, func) {
    var request = Ajax.createRequest();
    request.open("POST", url, true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if (typeof func == "function") {
        request.onreadystatechange = function() {
            if (request.readyState == 4 && request.status == 200) {
                func(request.responseText);
            }
        }
    }
    request.send(query);
}

Ajax.createRequest = function() {
    return (window.XMLHttpRequest) ? new XMLHttpRequest() : (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : null;
}
