function changeCities_1( form_name, lang ){
    var frm         = eval('document.' + form_name);
    var city_select = frm.city_id;

    // Изчистваме селекта
    city_select.options.length = 1;
    city_select.selectedIndex  = 0;

    // ако сме избрали стойността по подразбиране просто изчистваме селекта
    var country_select  = frm.country_id;
    var country_id      = country_select.options[country_select.selectedIndex].value;
    if (country_id != '' && country_id != 0){
        //MAKE REQUEST
        $.getJSON("batch/city.html?language="+ lang +"&country_id=" + country_id,
            function(city_data){
                $.each(city_data, function(i,item){
                    $("<option/>").attr("value", item.id).text(item.name).appendTo("#city_id");
                });

                setTimeout(function (){ city_select.selectedIndex = 0; },1);
            }
        );
    }

    changeRegions_1( form_name, lang );
}

function changeRegions_1( form_name, lang ){
    var frm             = eval('document.' + form_name);
    var regions_select  = frm.region_id;

    // epmty selects
    regions_select.options.length = 0;
    regions_select.selectedIndex  = -1;

    // just clear selects if we choose default value
    var city_select  = frm.city_id;
    var city_id      = city_select.options[city_select.selectedIndex].value;
    if (city_id != '' && city_id != 0){
        //MAKE REQUEST
        $.getJSON("batch/region.html?language="+ lang +"&city_id=" + city_id,
            function(region_data){
                $.each(region_data, function(i,item){
                    $("<option/>").attr("value", item.id).text(item.name).appendTo("#region_id");
                });

                setTimeout(function (){ regions_select.selectedIndex = 0; },1);
                setTimeout(function (){ regions_select.selectedIndex = -1; },1);
            }
        );
    }

    clearSelectedRegions( form_name );
}

function clearSelectedRegions( form_name ){
    var frm                     = eval('document.' + form_name);
    var selected_regions_select = frm.selected_region_id;

    // epmty selects
    selected_regions_select.options.length = 0;
    selected_regions_select.selectedIndex  = -1;

    $("<option/>").attr({   "value": "",
                            "default_option": "1"
                            }).text( $(selected_regions_select).attr('default_text') ).appendTo("#selected_region_id");

}

function moveSelectedRegion( form_name, from_select_selector, to_select_selector ){

    var from_select = $(from_select_selector).get(0);

    if (from_select.selectedIndex > -1){
        if ( ! $(from_select.options[from_select.selectedIndex]).attr('default_option') ){
            if ( $($(to_select_selector).get(0).options[0]).attr('default_option') ){
                $($(to_select_selector).get(0).options[0]).remove();
            }

            var previous_element_index = from_select.selectedIndex - 1;

            var selected_option = from_select.options[from_select.selectedIndex];
            from_select.selectedIndex = previous_element_index;
            $(selected_option).appendTo( to_select_selector );
            $(selected_option).attr('selected', false);
            
            setTimeout(function (){ from_select.selectedIndex = -1; },1);
        }
    }

    if (from_select.id == 'selected_region_id' && from_select.options.length == 0){
        clearSelectedRegions( form_name );
    }

}
