function choice_facility_type(val, sel) {
    $.getJSON('/get_facilities_by_type/'+val+'/',
        function(data) {
            sel.attr('options').length = 1;
            for (i in data) {
                if (data[i].text != undefined) {
                    sel.append(jQuery('<option value="'+data[i].value+'">'+data[i].text+'</option>'));
                }
                $('#quickContact').empty();
                $('.step2_2').hide();
                $('.step2_3').hide();
                $('.step1_2').show();
                $('.step1_3').hide();
            }
        }
    );

    return false;
}

function choice_facility(val, sel) {
    $.getJSON('/get_departments_by_facility/'+val+'/',
        function(data) {
            sel.attr('options').length = 1;
            for (i in data['departments']) {
                if (data['departments'][i].text != undefined) {
                sel.append(jQuery('<option value="'+data['departments'][i].value+'">'+data['departments'][i].text+'</option>'));
                }
            }
            $('#quickContact').html(data['contact']);
            $('#quickContact').removeClass('other');
            $('#quickContact').find('.mailto').each(email_it);
            astep = $('.step1_3').find('a');
            hrarr = astep.attr('href').split('?');
            astep.attr('href', hrarr[0]+'?facility_id='+val)
            $('.step2_2').hide();
            $('.step2_3').hide();
            $('.step1_3').show();
            //$('.suggest').AddIncSearch();
        }
    );
    return false;
}

function choice_facility_type_other(val, sel) {
    $.getJSON('/get_facilities_by_type_other/'+val+'/',
        function(data) {
            sel.attr('options').length = 1;
            for (i in data) {
                if (data[i].text != undefined) {
                    sel.append(jQuery('<option value="'+data[i].value+'">'+data[i].text+'</option>'));
                }
                $('#quickContact').empty();
                $('.step1_2').hide();
                $('.step1_3').hide();
                $('.step2_2').show();
                $('.step2_3').hide();
            }
        }
    );

    return false;
}

function choice_facility_other(val, sel) {
    $.getJSON('/get_facility_contact/'+val+'/',
        function(data) {
            $('#quickContact').html(data['contact']);
            $('#quickContact').addClass('other');
            $('#quickContact').find('.mailto').each(email_it);
            astep = $('.step2_3').find('a');
            hrarr = astep.attr('href').split('?');
            astep.attr('href', hrarr[0]+'?facility_id='+val)
            $('.step1_2').hide();
            $('.step1_3').hide();
            $('.step2_3').show();
            //$('.suggest').AddIncSearch();
        }
    );
    return false;
}
