document.observe('dom:loaded', function() {
    if ($('d') != null) {
        if ($('d').options.length > 1) {
            $('d').enable();
        }
    }
});

function notesAdd(link, dodane) {
    new Ajax.Updater('notes', link, {
        method: 'get',
        asynchronous: true,
        onComplete: function() {
            new Effect.Highlight('notes', {
                startcolor: "#A30606",
                endcolor: "#212121",
                duration: 3
            });

            if ($(dodane)) {
                $(dodane).setStyle({opacity:1, visibility:'visible'});
                fadeOut.delay(1.5, $(dodane));
            }
        }
    });
}

function setDropDown(dropdown, data) {
    dropdown.options.length = 1;

    $H(data).each(function(dzielnica) {
        var opt = new Option(dzielnica.value, dzielnica.key);
        try {
            dropdown.add(opt, null); // standards compliant; doesn't work in IE
        } catch(ex) {
            dropdown.add(opt); // IE only
        }
    });
}



function czyscDzielnice() {
    $('d').disable();
    setDropDown($('d'), []);
}

function updateDzielnice(response) {
    var json = response.responseText.evalJSON();
    var dropdown = $('d');
    $('d').disable();
    setDropDown(dropdown, json);
    if (dropdown.options.length > 1) {
        dropdown.enable();
    }
}

function fadeOut(obj) {
    new Effect.Opacity(obj, {duration:1, from:1, to:0});
}

function no(strToUrl,name,width,height)
{
    window.open(strToUrl, name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width= ' + (width) + ',height=' + (height) + ',left=' + (screen.width / 2 - width / 2) + ',top=' + (screen.height / 2 - height / 2));
}