var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
        var xmlHttp;

                try
                {
                        xmlHttp = new XMLHttpRequest();
                }
                catch(e)
                {
                        try
                        {
                                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(e){}
                }
                if(!xmlHttp)
                        alert("Niestety w tym momencie serwis jest nie osiągalny");
                else
                        return xmlHttp;
}
function dorequest(method,file,method_answer,fun,params)
{
        method.toUpperCase();
        method_answer.toLowerCase();
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
        {
                if(method == 'GET')
                {
                        xmlHttp.open('GET',file+'?'+params,true);
                }
                else
                {
                        xmlHttp.open('POST',file,true);
                        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                }
                        xmlHttp.onreadystatechange = function()
                        {
                                answer(method_answer,fun);
                        }
                if(method == 'GET')
                {
                        xmlHttp.send(null);
                }
                else
                {
                        xmlHttp.send(params);
                }
        }
        else
        setTimeout('dorequest("'+method+'","'+file+'","'+method_answer+'","'+fun+'","'+params+'")',1500);
}

function answer(method_answer,fun)
{
if(xmlHttp.readyState == 4)
{
        if(xmlHttp.status == 200)
        {
                if(method_answer == "tekst")
                {
                        xmlResponse = xmlHttp.responseText;
                }
                else
                {
                        xmlResponse = xmlHttp.responseXML;
                }
                fun=fun+'(xmlResponse);';
                eval(fun);
        }
        else
        {
                alert("Niestety w tym momencie serwis jest nie osiągalny");
        }
}

}
