var pc = new Object();

    // Current Version
    pc.VERSION = "1.0";
     // ----------------------------------------------------------------
    // XMLHttpRequest Manager
    // ----------------------------------------------------------------
    pc.ajax =
    {
        request_counter:0,
        responses:{},
        response_handler:function(xml_http_obj, request_id, responses) {
            return function ()
                {
                    if (xml_http_obj.readyState != 4)
                        return false;

                    if ('undefined' == typeof request_id)
                    {
                        request_id = 0;
                    }

                    responses[request_id] = {
                        text:xml_http_obj.responseText,
                        xml:xml_http_obj.responseXML,
                        status:xml_http_obj.status
                    };

                    delete xml_http_obj;
                    return true;
                };
        },

        get_request_object:function() {
            var A;
            try
            {
                A = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    A = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (oc)
                {
                    A = null;
                }
            }

            if(!A && "undefined" != typeof XMLHttpRequest)
                A = new XMLHttpRequest();

            if (!A)
            {
                return null;
            }
            return A;
        },

        get: function(uri, accept_headers)
        {
            try
            {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
            }
            catch (e)
            {
                // Need to think about it.
            }

            var xml_http_obj;
            xml_http_obj = this.get_request_object();
            if (null == xml_http_obj)
            {
                alert("Temporary connection problem");
                return false;
            }

            xml_http_obj.open("GET", uri, true);
            for (header_name in accept_headers)
            {
                xml_http_obj.setRequestHeader(header_name, accept_headers[header_name]);
            }

            var current_request = this.request_counter;
            xml_http_obj.onreadystatechange = this.response_handler(xml_http_obj, current_request, this.responses);
            xml_http_obj.send(null);
            this.request_counter = this.request_counter + 1;
            return current_request;
        }
    };
    // ----------------------------------------------------------------
    // Lobby Manager
    // ----------------------------------------------------------------
    pc.lobby =
    {
        parent:pc,
        lobby_config:{},
        request_refresh_lobby:function(element_id)
        {
            var _url = this.lobby_config.lobby_url;
            //_url = _url.replace(/#CNT#$/, this.lobby_config.number_of_profiles);
            /* Dumb IE caches everything even though told explictily not to cache contents */
            var current_date = new Date();
            var cache_spoiler_seed = current_date.getTime();
            var request_number = pc.ajax.get(_url + "&random=" + (Math.random() * cache_spoiler_seed), {"User-Agent":"ajax", "Accept":"text/html"});
            window.setTimeout('pc.lobby.refresh_lobby(' + request_number + ', "' + element_id + '")', 1000);
            return;
        },

        refresh_lobby:function(request_number, element_id)
        {
            if (
                'undefined' == typeof pc.ajax.responses[request_number]
            )
            {
                window.setTimeout('pc.lobby.refresh_lobby(' + request_number + ', "' + element_id + '")', 1000);
                return false;
            }

            if (200 != pc.ajax.responses[request_number].status)
            {
                alert("Could not update the lobby due to temporary connection problem");
                return false;
            }

            var element = document.getElementById(element_id);
            if (null == element)
            {
                alert("Lobby could not be refreshed");
                return false;
            }
            text = pc.ajax.responses[request_number].text;
            element.innerHTML = text;
            return true;
        }
    };