function pollMiniForm(id) {
    $("#"+id).find("form").unbind("submit").submit(function() {
        $(this).ajaxSubmit({ cache: false, target:"#"+id });
        $("#"+id).preloader();
        return false;
    });
}

$.fn.pollmini = function(category,zone) {
    category=category.toUpperCase();
    if (typeof (zone)=="undefined") {
        zone=false;
    }
    if (zone)
        zone=zone.toUpperCase();

    // pokaz div z sonda (domyslnie jest niewidoczny)
    $(this).show();
    // sprawdz czy zmienna pollExists została ustalona
    if (typeof (pollExists)=="undefined") {
        pollExists=false;
    }
    // jesli nie ma sondy dla biezacej kategorii
    if (!pollExists) {
        // ustalenie domyslnej kategorii w zaleznosci od regionu
        if (category.indexOf("PILKA")!=-1) {
            switch (zone) {
                case "SWI": pollCategory="PILKA01"; break;
                case "RAD": pollCategory="PILKA02"; break;
                case "POD": pollCategory="PILKA03"; break;
                default: pollCategory="PILKA01"; break;
            }
        } else {
            switch (zone) {
                case "SWI": pollCategory="POWIAT0114"; break;
                case "RAD": pollCategory="POWIAT0209"; break;
                case "POD": pollCategory="POWIAT0305"; break;
                default: pollCategory="POWIAT0114"; break;
            }
            // ustalenie kategorii innej niż domyslna dla okreslonych grup kategorii
            if (category=="SWIETOKRZYSKIE" || category.indexOf("POWIAT01")!=-1) {
                pollCategory="POWIAT0114";
            }
            else if (category=="RADOMSKIE" || category.indexOf("POWIAT02")!=-1) {
                pollCategory="POWIAT0209";
            }
            else if (category=="PODKARPACKIE" || category.indexOf("POWIAT03")!=-1) {
                pollCategory="POWIAT0305";
            }
            else if (category.indexOf("SPORT08")!=-1) {
                pollCategory="SPORT08";
            }
            else if (category.indexOf("SPORT09")!=-1) {
                pollCategory="SPORT09";
            }
            else if (category.indexOf("SPORT11")!=-1) {
                pollCategory="SPORT11";
            }
        }
     // aktualizacja sondy
        $(this).load("/apps/pbcs.dll/miniquery?NoStat=1&W=280&H=120&Labels=trailing&Kategori=" + pollCategory + "&ObjectClass=-1&GraphColors=10D1FF,10D1FF,10D1FF", function() { pollMiniForm("pollMini") });
    }
    else {
        pollMiniForm("pollMini");
    }
    return true;
};

$.fn.pollmulti = function(query) {
    var identifier = $(this).attr("id");
    $(this).show();
    $(this).load(query, function() { pollMiniForm(identifier) });
};
