/*
 *  Wszelkie prawa zastrzeżone
 *
*/
var xmlhttp

function GetAjaxObj() {
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return xmlhttp;
}

function GetPage(query_str, id, direct) {
    if (!id)
        id = "content";
    if (direct != "0")
        direct = 1;

    check_js();
    document.getElementById("error").innerHTML = "Wczytywanie... Proszę czekać";

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                if (direct == "1")
                    document.getElementById("directlink").href = "index.php?action=" + query_str;

                document.getElementById(id).innerHTML = xmlhttp.responseText;
            } else {
                document.getElementById(id).innerHTML = "<h1>Pobranie żądanej strony nie powiodło się</h1><br/><h2>Proszę, spróbuj ponownie</h2>";
            }

            document.getElementById("error").innerHTML = "";
        }
    }

    xmlhttp.open("GET", "?ajax=1&action=" + query_str, true);
    xmlhttp.send(null);
}

function check_js() {
    xmlhttp = GetAjaxObj();
    if (xmlhttp == null) {
        document.getElementById("error").innerHTML = "Twoja przeglądarka nie obsługuje XMLHTTP (AJAX)";

        // przypisanie wartości href do linków, żeby strona działała
    }
}

