﻿function resizeGridFilters(grid_name, date_filter_control, columns_ignore) {
    var i, j, k;
    var skip;
    var width_filter_icons_common = 45;
    var width_filter_icons_date = 28;
    var width_filter_min = 10;

    var grid = $find(grid_name);

    if (grid == null) return;

    var tblMasterTable = document.getElementById(grid.get_masterTableView().get_id());
    var tableRows = tblMasterTable.getElementsByTagName('tr');
    var columns = grid.get_masterTableView().get_columns();
    if (tableRows != null) {
        for (i = 0; i < tableRows.length; i++) {
            if (tableRows[i].className == 'rgFilterRow') {
                var filterRow = tableRows[i];
                var count = filterRow.children.length;
                for (j = 0; j < count; j++) {
                    var columnName = columns[j].get_uniqueName();

                    if (columns_ignore != null) {
                        skip = false;
                        for (k = 0; k < columns_ignore.length; k++) {
                            if (columnName == columns_ignore[k]) {
                                skip = true;
                                break;
                            }
                        }

                        if (skip == true)
                            continue;
                    }

                    var filterCell = filterRow.children[j];
                    filterCell.style.whiteSpace = 'normal';
                    var width = filterCell.offsetWidth;

                    if (filterCell.children.length > 1) {
                        var firstControl = filterCell.children[0];
                        var lastControl = filterCell.children[filterCell.children.length - 1];
                        var dataType = columns[j].get_dataType();
                        if (lastControl.offsetWidth != 0) {
                            width -= width_filter_icons_common;

                            if (dataType == "System.DateTime") {
                                if (width < width_filter_min + width_filter_icons_date)
                                    width = width_filter_min + width_filter_icons_date;

                                firstControl.style.width = width + 'px';

                                //  Get internal textbox                                            
                                var textbox = document.getElementById(grid_name + date_filter_control + columnName + '_dateInput_text');
                                if (textbox != null) {
                                    textbox.style.width = '100%';
                                }
                            }
                            else {
                                if (width < width_filter_min)
                                    width = width_filter_min;

                                firstControl.style.width = width + 'px';

                            }
                        }
                    }
                }
                break;
            }
        }
    }
}
