$(function () {
    $('#rentPrevzatieMiesto').change(function () {
        var placeId = $(this.options[this.selectedIndex]).attr('rel');
        changeCars(placeId);
    });
    changeCars($($('#rentPrevzatieMiesto')[0].options[$('#rentPrevzatieMiesto')[0].selectedIndex]).attr('rel'));
});

function changeCars(placeId) {
    if (placeId && TempusRentCars[placeId]) {
        $('#rentAuto')[0].selectedIndex = 0;
        //vsetky presuniem do pomocneho selectu
        $('#rentAuto option').each(function (idx, opt) {
            if (idx) {
                $(opt).appendTo($('#rentAuto2'));
            }
        });
        $.each(TempusRentCars[placeId], function (idx, pos) {
            $('#'+pos).appendTo($('#rentAuto'));
        });
    } else {
        //vsetko z pomocneho selectu presuniem nazad
        $('#rentAuto2 option').each(function (idx, opt) {
            $(opt).appendTo($('#rentAuto'));
        });
    }
}