// Skryti veci, ktere vidi jen users bez JS ;-)
// #34552 - zmena head -> html, not clean solution, ale diky bugu v IE je nutne :-\
$('html').prepend('<style>.custom-price, .hidden-js { display: none; } .specify { display: block; }</'+'style>');

SearchForm =
{
    defaultOption: '-1',
    lng: {},

    /**
    * Inicializuje vyhledávací formulář
    * Nutno volat při $(document).ready()
    *	
    */
    init: function () {
        if ($('#search').size() == 0) return;

        this.optionPlus = '<a href="#" class="btn-add-option" title="' + this.lng.plus + '"><img src="/design/ico-more.png" class="plain" /></a>';
        this.optionMinus = '<a href="#" class="btn-remove-option" title="' + this.lng.minus + '"><img src="/design/ico-less.png" class="plain" /></a>';

        //bind odkazů pro pridani kriterii ve vyhledavani (vsechny elementy s id="#add-*"
        $('.specify li[id*=add-]').bind('click', this.addSingleField);

        //live bind prepinani lokalit
        //msie je v lostu z 'change' eventu
        if ($.browser.msie) {
            $('select[id*=-nl_country_id]').bind('change', this.bindSwitchLocalities);
        }
        else {
            $('select[id*=-nl_country_id]').live('change', this.bindSwitchLocalities);
        }

        //boxik vlasni ceny
        $('#c_price_int').live('change customLoad', function () {
            if ($(this).val() == '-2') {
                $('#price-box .custom-price').show().find('input').removeAttr('disabled');
            }
            else {
                $('#price-box .custom-price').hide().find('input').attr('disabled', 'disabled');
            }
        });

        //bind switchnuti dopravy
        $('#nl_transportation_id').live('change customLoad', function () {
            if ($(this).val() == "3") {
                $('#transfer-airport-row').show().find('select').removeAttr('disabled');
            }
            else {
                $('#transfer-airport-row').hide().find('select').attr('disabled', 'disabled');
            }
        });

        //taby v horni casti vyhledavatka - trochu hardcode :-\
        $('#search .tabs ul li a').bind('click', function () {
            $('#search .tabs ul li').removeClass('active');
            $(this).parent().addClass('active');
            //$('#frmMain').get(0).action = this.href;
            $('#nl_type_id').val(this.rel);
            return false;
        });

        //taby v horni casti vyhledavatka - trochu hardcode :-\
        $('#guidepost .tabs ul li a').bind('click', function () {
            $('#guidepost .tabs ul li').removeClass('active');
            $(this).parent().addClass('active');
            $('#guidepost .in').removeClass('active');
            $('#guidepost #' + $(this).attr('rel')).addClass('active');
            return false;
        });

        //bind skryti kriteria ve vyhledavani
        $('a.btn-remove-option').live('click', function (e) {
            field_name = $(this).parent().attr('id').replace('-row', '');
            field_box = $('#' + field_name + '-box');

            $('#add-' + field_name).fadeIn('def');
            $('input', field_box).attr('disabled', 'disabled');
            $('select', field_box).attr('disabled', 'disabled');
            field_box.hide();
            SearchForm.checkHideSpecify();

            $(document).trigger("refreshTripsCount");

            return false;
        });

        //posovani a skryvani pluska u zemi
        $('#search .k2form-element-array-adder').live('click', function () {
            setTimeout("SearchForm.initAddDel()", 1);
        });

        //Skryva / zobrazuje textovy popisek "Upřesnit"
        this.checkHideSpecify();

        //Zobrazi vyplnene elementy
        this.showElements();

        //Zobrazuje/skryva [+] a [-]
        this.initAddDel();

        //Plusko u zeme
        this.countryPlus();

        //Disabluje neinicializovane polozky vyhledavani (zkracuje url)
        this.disableHiddenElements();

        //zavola bind na custom event
        $('#c_price_int, #nl_transportation_id').trigger('customLoad');

        //bind ajaxTripsCount
        $(document).trigger('ajaxTripsCount');
    },

    ShowSearchCount: function (data) {
        $("#search-loader").html("");
        $("#trips-count").html(data.count);
    },

    /**
    * Zobrazuje/skryva [+] a [-]
    *
    */
    initAddDel: function () {
        $('#search .k2form-element-array').each(function () {
            if ($(this).find('.k2form-element-array-remover').size() > 1) {
                $(this).find('.k2form-element-array-remover').show();
            }
        });

        if ($('.k2form-element-array-remover-c').size() > 1) $('.k2form-element-array-remover-c').show();
    },

    /**
    *	Zobrazi vyplnene elementy
    */
    showElements: function () {
        $('.specify ul li:visible').each(function () {
            id = $(this).attr('id');
            field_box = '#' + id.replace('add-', '') + '-box';

            $(field_box + ' input, ' + field_box + ' select').each(function () {
                if ($(this).attr('type') != 'checkbox') {
                    val = $(this).val();
                }
                else {
                    val = $(this).attr('checked') ? 1 : -1;
                }

                if (val != SearchForm.defaultOption && val != '') {
                    $('#' + id).trigger('click');
                    return;
                }
            });
        });
    },

    /**
    * Disabluje neinicializovane polozky vyhledavani (zkracuje url)
    * 
    */
    disableHiddenElements: function () {
        $('#search').find('input:hidden, select:hidden').each(function () {
            $(this).attr('disabled', 'disabled');
        });
    },

    /**
    * Skryva / zobrazuje textovy popisek "Upřesnit"
    *
    */
    checkHideSpecify: function (event) {
        //jquery 1.3.2 needed
        $('.specify').show();

        if ($('.specify ul li:visible').length == 0) {
            $('.specify').hide();

        }
        else {
            $('.specify').show();
        }
    },

    /**
    * Zobrazi zakliknuty element ve vyhledávátku
    *
    */
    addSingleField: function (event) {
        var id = $(event.target).attr('id') == '' ? $(event.target).parent().attr('id') : $(event.target).attr('id');
        var field_name = id.replace('add-', '');
        var field_box = $('#' + field_name + '-box');

        // pokud NENI definovane <minus> u elementu, tak se zadefinuje:
        if ($('#' + field_name + '-row a').length == 0) {
            var minus = $(SearchForm.optionMinus);
            $('#' + field_name + '-row').append(minus);
        }

        //skryje popisek v sekci "Upresnit"
        $('#add-' + field_name).hide();

        //prida vyhledavaci kriterium do searchformu
        field_box.remove().appendTo($('#enhoptions .fm-spc')).fadeIn('def');

        //enable input prvku:
        field_box.find('input, select').each(function () { $(this).removeAttr('disabled'); });

        field_box.find('input, select').bind('change', function () {
            if (!field_box.hasClass("changed")) field_box.addClass("changed");
        });

        SearchForm.checkHideSpecify();

        return false;
    },

    /**
    * Přidá options do nově vzniklého selectu zemí
    * Zabinduje akci change
    *
    */
    addCountry: function (id, cnt) {
        sel = '#' + id + '-' + cnt + '-nl_country_id';
        val = $('.country-box:first select').html();

        //opera sux code
        //od opera 10.10 uz to konecne funguje, jeste to tady nejakej cas ale nechame, lidi neumi updatovat software
        if (jQuery.browser.opera) {
            val = val.replace(/<optgroup label="([^"]+)">/ig, '<option disabled="disabled">$1</option>')
				.replace(/<\/optgroup>/ig, '');
        }

        $(sel).append(val).children('option:first').attr('selected', 'selected');
        if ($.browser.msie) {
            $(sel).bind('change', this.bindSwitchLocalities);
        }

        this.countryPlus();
    },

    countryPlus: function () {
        sel = '#countries-box .country-row:last-child select[id*=nl_country_id]';
        $('#k2form-element-array-adder-c').remove();
        $(sel + ' + span').after('<span id="k2form-element-array-adder-c" class="input-text k2form-element-array-adder"><img alt="" src="/design/ico-more.png"/></span>')
    },

    /**
    * Přidá options do nově vznikého selectu lokalit
    *
    */
    addLocality: function (id, cnt) {
        sel = '#' + id + '-' + cnt;
        val = $('#k2form-element-array-' + id + ' select:first').html();

        $(sel).html(val).children('option:first').attr('selected', 'selected');
    },

    /**
    * Odstraní mínusko
    *
    */
    removeMinus: function (id, row) {
        if (k2.formElementArray[id].real_count <= 2) $('#k2form-element-array-' + id + ' .k2form-element-array-remover-' + id).hide();

        //když je v selectu vybráno nerozhoduje a umažeme jej, nevoláme přenačítání počtu zájezdů
        //nefunguje na 100%, protože do proměnné row se dosazuje kokotina
        if ($('select[id*=' + id + '-' + row + ']').val() != -1) {
            setTimeout("$(document).trigger('refreshTripsCount');", 10);
        }

        return true;
    },

    /**
    * Smaže a switchne lokality podle právě vybrané země
    *
    */
    bindSwitchLocalities: function (event) {
        var regiondb = new Object()

regiondb["5"] = [{ value: "96", text: "Les Trois Valées" },{ value: "97", text: "Les Deux Alpes" },{ value: "98", text: "Les Arcs" },{ value: "99", text: "La Plagne" },{ value: "111", text: "Risoul" },{ value: "113", text: "Alpe d´Huez" },{ value: "114", text: "Valmenier" },{ value: "115", text: "Val D´Isere" },{ value: "116", text: "Tignes" },{ value: "117", text: "Val Thorens" },{ value: "118", text: "Les Menuires" },{ value: "119", text: "La Rosiere" },{ value: "139", text: "Le Grande Serre Chevalier" },{ value: "140", text: "Puy Saint Vincent" },{ value: "141", text: "Les Orres" },{ value: "147", text: "Flaine" },{ value: "171", text: "Azúrové pobrežie" },{ value: "172", text: "Francúzska riviéra" },{ value: "174", text: "Camarque" },{ value: "175", text: "Languedoc - Roussillon" },{ value: "176", text: "Korzika" },{ value: "177", text: "Francúzske Alpy" },{ value: "252", text: "La Norma" },{ value: "289", text: "Bordeaux" },{ value: "442", text: "Paríž" },{ value: "463", text: "Nice" },{ value: "480", text: "Valloire" },{ value: "482", text: "Orcieres Merlette" },{ value: "483", text: "Praloup" },{ value: "484", text: "Val Frejus" },{ value: "485", text: "Superdevoluy" },{ value: "541", text: "Bretónsko" },{ value: "735", text: "L´Espace Killy" },{ value: "766", text: "Lyon" },{ value: "774", text: "Alsasko" },{ value: "775", text: "Normandia" },{ value: "776", text: "Burgundsko" },{ value: "777", text: "Provencia" },{ value: "781", text: "Chamonix Mont-Blanc" },{ value: "813", text: "Pyreneje" },{ value: "814", text: "Akvitánie" }]
regiondb["6"] = [{ value: "100", text: "Lungau" },{ value: "124", text: "Schladming" },{ value: "125", text: "Dachstein" },{ value: "126", text: "Salcbursko" },{ value: "127", text: "Badgastein" },{ value: "128", text: "Kaprun" },{ value: "129", text: "Mittersill" },{ value: "131", text: "Brixental" },{ value: "132", text: "Tyrolské Alpy" },{ value: "133", text: "Vysoké Taury" },{ value: "134", text: "Nízke Taury" },{ value: "135", text: "Glocknerské Dolomity" },{ value: "189", text: "Rakúske Alpy" },{ value: "241", text: "Stubaital" },{ value: "248", text: "Korutansko" },{ value: "253", text: "Hochkar" },{ value: "499", text: "Pitztal" },{ value: "751", text: "Viedeň" },{ value: "770", text: "Vorarlbersko" },{ value: "792", text: "Štajersko" },{ value: "803", text: "Dolné Rakúsko" },{ value: "817", text: "Horní Rakousko" },{ value: "819", text: "Burgenland" }]
regiondb["9"] = [{ value: "190", text: "Tenerife" },{ value: "191", text: "Fuerteventura" },{ value: "196", text: "Lanzarote" },{ value: "197", text: "Gran Canaria" },{ value: "204", text: "La Palma" },{ value: "381", text: "El Hierro" },{ value: "382", text: "La Gomera" }]
regiondb["10"] = [{ value: "41", text: "Mahdia" },{ value: "42", text: "Djerba" },{ value: "70", text: "Tunis" },{ value: "150", text: "Tabarka" },{ value: "237", text: "Port El Kantaoui" },{ value: "280", text: "Nabeul" },{ value: "281", text: "Sousse" },{ value: "298", text: "Monastir" },{ value: "299", text: "Hammamet" },{ value: "327", text: "Skanes" },{ value: "622", text: "Yasmine Hammamet" },{ value: "709", text: "Borj Cedria" }]
regiondb["11"] = [{ value: "32", text: "Sharm El Sheikh" },{ value: "33", text: "Hurghada" },{ value: "290", text: "Taba" },{ value: "320", text: "Ain Soukhna" },{ value: "626", text: "Marsa Alam" },{ value: "653", text: "Dahab" },{ value: "804", text: "Sahl Hasheesh" },{ value: "816", text: "Safaga" }]
regiondb["12"] = [{ value: "50", text: "Pattaya" },{ value: "56", text: "Koh Chang" },{ value: "59", text: "Koh Lanta" },{ value: "60", text: "Krabi" },{ value: "61", text: "Bangkok" },{ value: "77", text: "Koh Samui" },{ value: "78", text: "Phuket" },{ value: "217", text: "Phi Phi" },{ value: "438", text: "Koh Samet" },{ value: "487", text: "Koh Tao" },{ value: "506", text: "Khao Lak" }]
regiondb["13"] = [{ value: "62", text: "Dubaj" },{ value: "108", text: "Ajman" },{ value: "121", text: "Abu Dhabi" },{ value: "215", text: "Sharjah" },{ value: "216", text: "Ras Al Khaimah" },{ value: "679", text: "Umm Al Quwain" },{ value: "680", text: "Fujairah" }]
regiondb["14"] = [{ value: "66", text: "Juan Dolio" },{ value: "210", text: "Bayahibe" },{ value: "218", text: "Punta Cana" },{ value: "219", text: "Boca Chica" },{ value: "809", text: "poloostrov Samaná" }]
regiondb["15"] = [{ value: "71", text: "Cancún" },{ value: "72", text: "Playa del Carmen" },{ value: "509", text: "Ciudad de México" },{ value: "713", text: "Acapulco" },{ value: "714", text: "Yucatan" },{ value: "715", text: "Riviera Maya" }]
regiondb["16"] = [{ value: "75", text: "Le Morne" },{ value: "76", text: "Trou aux Biches" },{ value: "632", text: "Grand Baie" },{ value: "633", text: "Flic en Flac" },{ value: "634", text: "Belle Mare" },{ value: "635", text: "Grand Gaube" },{ value: "636", text: "Grand Riviere" },{ value: "796", text: "Blue Bay" }]
regiondb["17"] = [{ value: "397", text: "Varadero" },{ value: "492", text: "La Habana (Havana)" },{ value: "673", text: "Cayo Coco" },{ value: "674", text: "Cayo Largo" },{ value: "716", text: "Cayo Guillermo" },{ value: "791", text: "Cayo Santa Maria" }]
regiondb["18"] = [{ value: "412", text: "Negril" },{ value: "591", text: "Ocho Rios" },{ value: "637", text: "Montego Bay" }]
regiondb["21"] = [{ value: "606", text: "Malindi" },{ value: "677", text: "Mombasa" },{ value: "704", text: "Diani Beach" }]
regiondb["22"] = [{ value: "79", text: "Val di Fiemme/Obereggen" },{ value: "80", text: "Arabba/Marmolada" },{ value: "82", text: "Bormio" },{ value: "83", text: "Val di Fassa e Carezza" },{ value: "84", text: "Tonale/Ponte di Legno" },{ value: "87", text: "Santa Caterina" },{ value: "89", text: "Val Gardena" },{ value: "90", text: "Cortina d´Ampezzo" },{ value: "91", text: "Alta Badia" },{ value: "93", text: "Madonna di Campiglio" },{ value: "94", text: "Cervinia/Zermatt" },{ value: "95", text: "Livigno" },{ value: "120", text: "Paganella" },{ value: "123", text: "Alta Valtellina" },{ value: "143", text: "Sestriere" },{ value: "145", text: "Marilleva/Folgarida" },{ value: "151", text: "Sardínia / Sardegna" },{ value: "153", text: "Sicílie" },{ value: "155", text: "Elba" },{ value: "156", text: "Kalábria" },{ value: "157", text: "Lombardie" },{ value: "158", text: "Veneto" },{ value: "159", text: "Trentino" },{ value: "160", text: "Palmová Riviéra" },{ value: "161", text: "Kampánia" },{ value: "162", text: "Capri" },{ value: "163", text: "Ischia" },{ value: "164", text: "Apulská oblasť (Puglia)/Gargano" },{ value: "167", text: "Dolomiti Brenta" },{ value: "168", text: "Gargano" },{ value: "170", text: "Ligúrska riviéra" },{ value: "186", text: "Adriatická riviéra" },{ value: "187", text: "Lago di Garda" },{ value: "195", text: "Řím" },{ value: "198", text: "Talianske Alpy" },{ value: "242", text: "Passo Tonale" },{ value: "244", text: "Aprica" },{ value: "245", text: "Ponte di Legno" },{ value: "246", text: "Lido di Jesolo" },{ value: "249", text: "Dolomiti Superski" },{ value: "250", text: "Florencia" },{ value: "254", text: "Val di Sole" },{ value: "257", text: "Tre Valli" },{ value: "260", text: "San Martino" },{ value: "282", text: "Lignano" },{ value: "317", text: "Benátská riviéra" },{ value: "319", text: "Rimini" },{ value: "368", text: "Lido Degli Scacchi" },{ value: "369", text: "Toskánsko" },{ value: "372", text: "Lido Adriano" },{ value: "374", text: "Eraclea Mare" },{ value: "395", text: "Jadranská riviéra" },{ value: "404", text: "Bibione" },{ value: "478", text: "Valtellina" },{ value: "479", text: "Valle d`Aosta" },{ value: "496", text: "Skiaréna Ortlerské Alpy" },{ value: "510", text: "Folgaria" },{ value: "511", text: "Civetta" },{ value: "512", text: "Marche/Abruzzo" },{ value: "513", text: "Sappada" },{ value: "514", text: "Lazio" },{ value: "664", text: "Piancavallo" },{ value: "668", text: "Emilia Romagna" },{ value: "736", text: "Benátky" },{ value: "737", text: "Neapol" },{ value: "743", text: "Salento" },{ value: "755", text: "Miláno" },{ value: "783", text: "Alta Pusteria – Hochpustertal" },{ value: "784", text: "Madesimo" },{ value: "785", text: "Kronplatz – Plan de Corones" }]
regiondb["26"] = [{ value: "199", text: "Švajčiarske Alpy" },{ value: "517", text: "St. Moritz" },{ value: "620", text: "Ženeva" },{ value: "787", text: "Bern" }]
regiondb["28"] = [{ value: "9", text: "Peloponéz" },{ value: "10", text: "Chalkidiki" },{ value: "11", text: "Zakynthos" },{ value: "13", text: "Rhodos" },{ value: "14", text: "Thassos" },{ value: "19", text: "Kréta" },{ value: "21", text: "Korfu" },{ value: "22", text: "Lefkada" },{ value: "23", text: "Kefalónia" },{ value: "30", text: "Andros" },{ value: "148", text: "Kos" },{ value: "149", text: "Skiathos" },{ value: "193", text: "Samos" },{ value: "269", text: "Epirus" },{ value: "271", text: "Olympská riviéra" },{ value: "274", text: "Parga" },{ value: "291", text: "Santorini" },{ value: "292", text: "Kalymnos" },{ value: "477", text: "Skopelos" },{ value: "522", text: "Karpathos" },{ value: "523", text: "Mykonos" },{ value: "534", text: "Attika a ostrov Evia" },{ value: "562", text: "Ostrov Meganissi" },{ value: "627", text: "Lesbos" },{ value: "629", text: "Naxos" },{ value: "712", text: "Athény" },{ value: "732", text: "Solún" },{ value: "744", text: "Chios" },{ value: "769", text: "Limnos" },{ value: "779", text: "Leptokaria" },{ value: "780", text: "Nei Pori" }]
regiondb["29"] = [{ value: "194", text: "Larnaca" },{ value: "228", text: "Limassol" },{ value: "229", text: "Protaras" },{ value: "272", text: "Paphos (tiež Pafos)" },{ value: "322", text: "Coral Bay" },{ value: "323", text: "Kissonerga" },{ value: "731", text: "Ayia Napa" }]
regiondb["30"] = [{ value: "24", text: "Andalúzia" },{ value: "25", text: "Mallorca" },{ value: "26", text: "Menorca" },{ value: "27", text: "Costa Blanca" },{ value: "28", text: "Costa Brava" },{ value: "29", text: "Ibiza" },{ value: "152", text: "Valencia" },{ value: "279", text: "Costa Del Sol" },{ value: "316", text: "Costa del Maresme" },{ value: "325", text: "Madrid" },{ value: "402", text: "Costa Del Azahar" },{ value: "436", text: "Costa Dorada" },{ value: "472", text: "Tossa de Mar" },{ value: "473", text: "Lloret de Mar" },{ value: "669", text: "Formentera" },{ value: "717", text: "Barcelona" },{ value: "718", text: "Biskajský záliv" },{ value: "815", text: "Costa de Amleria" }]
regiondb["31"] = [{ value: "192", text: "Turecká Riviéra" },{ value: "223", text: "Side" },{ value: "224", text: "Alanya" },{ value: "225", text: "Marmaris" },{ value: "226", text: "Antalya" },{ value: "278", text: "Egejská Riviéra" },{ value: "283", text: "Bodrum" },{ value: "284", text: "Kemer" },{ value: "296", text: "Fethiye" },{ value: "387", text: "Belek" },{ value: "623", text: "Istanbul" }]
regiondb["32"] = [{ value: "43", text: "Zlaté Piesky" },{ value: "44", text: "Slnečné Pobrežie" },{ value: "45", text: "Primorsko" },{ value: "46", text: "Burgas" },{ value: "47", text: "Sozopol" },{ value: "231", text: "Obzor" },{ value: "232", text: "Albena" },{ value: "233", text: "Sveti Vlas" },{ value: "251", text: "Pomorie" },{ value: "255", text: "Nesebar" },{ value: "366", text: "Kiten" },{ value: "391", text: "Lozenec" },{ value: "393", text: "Ravda" },{ value: "445", text: "Kranevo" },{ value: "467", text: "Balčik" },{ value: "469", text: "Elenite" },{ value: "475", text: "Čiernomorec" },{ value: "476", text: "Achtopol" },{ value: "526", text: "Sv. Konštantín" },{ value: "527", text: "Varna" },{ value: "528", text: "Djuni" },{ value: "543", text: "Carevo" }]
regiondb["33"] = [{ value: "12", text: "Makarska" },{ value: "34", text: "Istria" },{ value: "35", text: "Kvarner" },{ value: "36", text: "Severná Dalmácia" },{ value: "37", text: "Stredná Dalmácia" },{ value: "38", text: "Južná Dalmácia" },{ value: "300", text: "Krk" },{ value: "301", text: "Orebič" },{ value: "305", text: "Komarna" },{ value: "307", text: "Gradac" },{ value: "308", text: "Tučepi" },{ value: "309", text: "Primošten" },{ value: "310", text: "Šibeník" },{ value: "311", text: "Vodice" },{ value: "312", text: "Murter" },{ value: "314", text: "Novigrad" },{ value: "315", text: "Petrčane" },{ value: "331", text: "Brač" },{ value: "377", text: "Pula" },{ value: "378", text: "Zadar" },{ value: "379", text: "Split" },{ value: "380", text: "Dubrovník" },{ value: "394", text: "Poreč" },{ value: "396", text: "Rabac" },{ value: "401", text: "Hvar" },{ value: "405", text: "Baška Voda" },{ value: "406", text: "Umag" },{ value: "407", text: "Rovinj" },{ value: "409", text: "Biograd Na Moru" },{ value: "410", text: "Crikvenica" },{ value: "411", text: "Podgora" },{ value: "420", text: "Lanterna" },{ value: "423", text: "Trogir" },{ value: "433", text: "Korčuľa" },{ value: "446", text: "Rab" },{ value: "447", text: "Lošinj" },{ value: "448", text: "Ostrov Pag" },{ value: "471", text: "Drašnice" },{ value: "778", text: "Makarská riviéra" },{ value: "800", text: "Omiš" },{ value: "805", text: "Plitvická jezera" },{ value: "806", text: "Pelješac" }]
regiondb["34"] = [{ value: "398", text: "Bečiči" },{ value: "413", text: "Budva" },{ value: "574", text: "Sutomore" },{ value: "575", text: "Ulcinj" },{ value: "576", text: "Bar" },{ value: "577", text: "Petrovac" }]
regiondb["35"] = [{ value: "551", text: "Sliema" },{ value: "552", text: "St. Julian" },{ value: "553", text: "Cirkewwa" },{ value: "554", text: "Mellieha" },{ value: "555", text: "Bugibba a Qawra" },{ value: "628", text: "Marfa" },{ value: "666", text: "Valletta" },{ value: "711", text: "ostrov Gozo" }]
regiondb["36"] = [{ value: "178", text: "Moravskoslezské Beskydy" },{ value: "180", text: "Jizerské hory" },{ value: "181", text: "Krkonoše" },{ value: "182", text: "Pošumaví - Lipno" },{ value: "183", text: "Šumava" },{ value: "184", text: "Severné Čechy" },{ value: "185", text: "Južné Čechy" },{ value: "200", text: "Orlické hory" },{ value: "201", text: "Jeseníky" },{ value: "202", text: "Beskydy" },{ value: "203", text: "Českomoravská Vrchovina" },{ value: "205", text: "Český Raj" },{ value: "375", text: "Západní Čechy" },{ value: "389", text: "Broumovsko" },{ value: "424", text: "Krušné Hory" },{ value: "449", text: "Stredné Čechy" },{ value: "450", text: "Lipno" },{ value: "451", text: "Východné Čechy" },{ value: "453", text: "Južná Morava" },{ value: "454", text: "Drahanská vrchovina" },{ value: "455", text: "Moravský kras" },{ value: "456", text: "Valašsko" },{ value: "515", text: "Severná Morava" },{ value: "726", text: "Střední Morava" },{ value: "742", text: "Praha a okolie" }]
regiondb["37"] = [{ value: "263", text: "Algarve" },{ value: "264", text: "Azorské ostrovy" },{ value: "265", text: "Estoril" },{ value: "722", text: "Lisabon" },{ value: "767", text: "Porto" }]
regiondb["40"] = [{ value: "57", text: "Kuta Beach" },{ value: "58", text: "Sanur" },{ value: "63", text: "Nusa Dua Beach" },{ value: "488", text: "Seminyak" }]
regiondb["45"] = [{ value: "580", text: "Peking" },{ value: "581", text: "Šanghaj" }]
regiondb["46"] = [{ value: "390", text: "Natal" },{ value: "440", text: "Rio De Janeiro" },{ value: "500", text: "Buzios" },{ value: "693", text: "Amazonie" }]
regiondb["55"] = [{ value: "39", text: "Dillí" },{ value: "589", text: "Kerala" },{ value: "590", text: "Goa" }]
regiondb["65"] = [{ value: "295", text: "Auckland" }]
regiondb["68"] = [{ value: "507", text: "Hanoi" },{ value: "701", text: "Phan Thiet" },{ value: "702", text: "Nha Trang" }]
regiondb["70"] = [{ value: "495", text: "Isla Margarita" },{ value: "597", text: "Isla Coche" }]
regiondb["71"] = [{ value: "601", text: "New York" },{ value: "602", text: "Florida" },{ value: "681", text: "Californie" },{ value: "682", text: "Nevada" },{ value: "703", text: "Havajské ostrovy" },{ value: "756", text: "Miami" }]
regiondb["73"] = [{ value: "356", text: "Kalutara" },{ value: "357", text: "Beruwela" },{ value: "358", text: "Bentota" },{ value: "383", text: "Koggala" },{ value: "384", text: "Negombo" },{ value: "426", text: "Induruwa" },{ value: "427", text: "Unawatuna" },{ value: "431", text: "Waduwa" },{ value: "432", text: "Marawila" },{ value: "434", text: "Hikkaduwa" },{ value: "435", text: "Colombo" },{ value: "503", text: "Tangalla" },{ value: "707", text: "Trincomalee" }]
regiondb["77"] = [{ value: "355", text: "Muscat" },{ value: "613", text: "Salalah" }]
regiondb["79"] = [{ value: "363", text: "Lhaviyani Atol" },{ value: "400", text: "Atol Ari" },{ value: "421", text: "Severný Atol Male" },{ value: "425", text: "Južný Atol Male" },{ value: "504", text: "Kaafu Atol" }]
regiondb["84"] = [{ value: "505", text: "Eilat" }]
regiondb["85"] = [{ value: "136", text: "Nízke Tatry" },{ value: "137", text: "Vysoké Tatry" },{ value: "276", text: "Poprad" },{ value: "277", text: "Liptovský Mikuláš" },{ value: "285", text: "Malá Fatra" },{ value: "286", text: "Slovenský Raj" },{ value: "287", text: "Trenčianske Teplice" },{ value: "288", text: "Bratislava" },{ value: "332", text: "Štrbské pleso" },{ value: "333", text: "Ľubovnianske Kúpele" },{ value: "334", text: "Piešťany" },{ value: "335", text: "Vyšné Ružbachy" },{ value: "336", text: "Rajecké Teplice" },{ value: "337", text: "Bardejovské Kúpele" },{ value: "338", text: "Dudince" },{ value: "340", text: "Turčianske Teplice" },{ value: "341", text: "Strážovské Vrchy" },{ value: "344", text: "Oravské Beskydy" },{ value: "346", text: "Žilina" },{ value: "347", text: "Dunajská Streda" },{ value: "350", text: "Slnečné Jazerá" },{ value: "352", text: "Senecké Jazerá" },{ value: "408", text: "Veľká Fatra" },{ value: "415", text: "Západné Slovensko" },{ value: "416", text: "Stredné Slovensko" },{ value: "418", text: "Východné Slovensko" },{ value: "419", text: "Južné Slovensko" },{ value: "457", text: "Liptov" },{ value: "458", text: "Pieniny" },{ value: "459", text: "Zemplínska Šírava" },{ value: "460", text: "Kremnické vrchy" },{ value: "564", text: "Banská Bystrica" },{ value: "565", text: "Nitra" },{ value: "566", text: "Trenčín" },{ value: "567", text: "Trnava" },{ value: "730", text: "Západní Tatry" },{ value: "801", text: "Podhájska" }]
regiondb["86"] = [{ value: "610", text: "poloostrov Caravelle" },{ value: "705", text: "Les Trois Ilets" },{ value: "706", text: "Ste. Luce" }]
regiondb["87"] = [{ value: "587", text: "Grande Terre" },{ value: "588", text: "Basse Terre" },{ value: "675", text: "Gosier" }]
regiondb["91"] = [{ value: "615", text: "La Saline les Bains" }]
regiondb["94"] = [{ value: "364", text: "Portorož" },{ value: "516", text: "Kranjska Gora" },{ value: "676", text: "Julské Alpy" },{ value: "683", text: "Slovinské kúpele" },{ value: "684", text: "Bohinj" },{ value: "685", text: "Bled" }]
regiondb["95"] = [{ value: "570", text: "Palm Beach" },{ value: "571", text: "Eagle Beach" }]
regiondb["98"] = [{ value: "243", text: "Funchal" },{ value: "258", text: "Caniço" },{ value: "609", text: "Calheta" },{ value: "686", text: "Santana" },{ value: "723", text: "Paul do Mar" },{ value: "727", text: "Machico" }]
regiondb["100"] = [{ value: "599", text: "Birmingham" },{ value: "600", text: "Londýn" },{ value: "728", text: "Edinburgh" },{ value: "760", text: "Brighton" },{ value: "761", text: "Manchester" },{ value: "802", text: "Škótsko" },{ value: "831", text: "Liverpool" }]
regiondb["102"] = [{ value: "188", text: "Balaton" },{ value: "417", text: "Termálne Kúpele" },{ value: "525", text: "Zalakaros" },{ value: "687", text: "Budapešť" },{ value: "821", text: "Západ od Dunaje" },{ value: "822", text: "Střed okolí Dunaje" },{ value: "823", text: "Jih od Dunaje" },{ value: "824", text: "Sever Maďarska" }]
regiondb["104"] = [{ value: "275", text: "Agadir" },{ value: "537", text: "Marrákeš" },{ value: "818", text: "Saidia" }]
regiondb["108"] = [{ value: "812", text: "Krakov" }]
regiondb["110"] = [{ value: "568", text: "Dublin" }]
regiondb["113"] = [{ value: "670", text: "Hamburk" },{ value: "671", text: "Bavorské Alpy" },{ value: "672", text: "Berlín" },{ value: "794", text: "Drážďany" },{ value: "795", text: "Norimberg" },{ value: "799", text: "Německé termální lázně" }]
regiondb["123"] = [{ value: "593", text: "Ostrov Sal" },{ value: "594", text: "Ostrov Boavista" },{ value: "595", text: "Ostrov Santiago" }]
regiondb["125"] = [{ value: "546", text: "Akaba" },{ value: "549", text: "Mŕtve more" },{ value: "550", text: "Ammán" }]
regiondb["127"] = [{ value: "386", text: "La Digue" },{ value: "422", text: "Mahé" },{ value: "464", text: "mikroostrovy v Seychelách" },{ value: "519", text: "Praslin" }]
regiondb["149"] = [{ value: "700", text: "Doha" }]

        locality_array_id = $(event.target).attr('id').replace('country', 'locality');
        real_count = k2.formElementArray[locality_array_id].real_count - 1;

        // Step 1: delete more than 1 locality selects:
        for (x = 0; x < real_count; x++) { k2.formElementArrayDel(locality_array_id, real_count - x); }

        locality_element = $('#k2form-element-array-' + locality_array_id).find('select[id*=nl_locality_id]');

        var db = regiondb[$(event.target).val()];
        var newOptions = '<option id=\'-1\'>(Nerozhoduje)</option>';
        if (typeof db != 'undefined') {
            locality_element.html(newOptions);

            for (var i = 0; i < db.length; i++) {
                newOptions = newOptions + '<option value="' + db[i].value + '">' + db[i].text + '</option>';
            }
        }

        locality_element.html(newOptions);
    }
};

