workSearch = function(blockId, url) {
    
    this.blockId = blockId;
    this.url = url;
}

workSearch.prototype = {

    blockId: null,
    url: null,

    init: function(county,city) {

        if(!county) {
            $($('#wrksearch [name=city]')).attr('disabled','disabled');
        }
        this.city=city;
        $('#cities').hide();
        $('#county').bind('change', {blockId: this.blockId, url: this.url, city:this.city}, this.fillCities);
        if (county) $('#county').trigger('change');
        
    },

    fillCities: function(ev) {
        var obj=this;
        if ($('#county').val()>0) {$('#cities').show(); } else {$('#cities').hide();$('#city').val('')};
          
        $.getJSON("?", {
            block_id: ev.data.blockId,
            fillCities: true,
            county_id: $('#county').val()
        }, function(e) {
            $('#city').attr('disabled',null);
            var html = "<option value=''>&nbsp</option>";
            $.each(e,function(index,item) {
                html += "<option value='" + item.id + "'>" + item.name + "</option>";
            });
            $('#city').html(html);
            
            $('#city').val(ev.data.city);
            ev.data.city=0;
        })
    }
}



