// Call of remote data via xmlHttpRequest

function dataServent()
{};

dataServent.prototype.initialize = function()
{
    try {
        // Mozilla / Safari
        this._xh = new XMLHttpRequest();
    } catch (e) {
        // Explorer
        var _ieModel = new Array(
        'MSXML2.XMLHTTP.5.0',
        'MSXML2.XMLHTTP.4.0',
        'MSXML2.XMLHTTP.3.0',
        'MSXML2.XMLHTTP',
        'Microsoft.XMLHTTP'
        );
        var success = false;
        for (var i=0;i < _ieModel.length && !success; i++)
        {
            try {
                this._xh = new ActiveXObject(_ieModel[i]);
                success = true;
            } catch (e) {
                // Manage the exceptions
            }
        }
        if ( !success )
        {
            // Manage the exceptions, while alert
            return false;
        }
        return true;
    }
}

dataServent.prototype.occupy = function()
{
    beenActual = this._xh.readyState;
    return (beenActual && (beenActual < 4));
}

dataServent.prototype.process = function()
{
    if (this._xh.readyState == 4 && this._xh.status == 200)
    {
        this.processdo = true;
    }
}

dataServent.prototype.sending = function(urlget,data)
{
    if (!this._xh)
    {
        this.initialize();
    }
    if (!this.occupy())
    {
        this._xh.open("GET",urlget,false);
        this._xh.send(data);
        if (this._xh.readyState == 4 && this._xh.status == 200)
        {
            return this._xh.responseText;
        }
    }
    return false;
}

// Rapid access for making changes
function _gr(reqseccion,divcont)
{
    remote = new dataServent;
    nt = remote.sending(reqseccion,"");
    document.getElementById(divcont).innerHTML = nt;
}

function rateTopic(rating,forum_id)
{
        remote = new dataServent;
        nt = remote.sending('ajax-rating.php?rating='+rating+'&forum_id='+forum_id);
        rating = rating * 25;
        document.getElementById('current-rating').style.width = rating+'px';
        document.getElementById('ratelinks').style.display = 'none';
        document.getElementById('ratingtext').innerHTML = 'Thank you for your vote!';
}

function rateAdminTopic(rating,forum_id)
{
        remote = new dataServent;
        nt = remote.sending('forum/ajax-rating.php?rating='+rating+'&forum_id='+forum_id);
        rating = rating * 25;
        document.getElementById('current-rating').style.width = rating+'px';
        document.getElementById('ratelinks').style.display = 'none';
        document.getElementById('ratingtext').innerHTML = 'Thank you for your vote!';
}    
