var GenericUtil = new Object();

Object.extend(GenericUtil, {
    filledArray: function(size, filler) {
        var array = new Array(size);
        for (var i = 0; i < size; i++) {        
            array[i] = filler;
        }
        return array;
    },
    objRef: function(ref) {
        if (typeof ref == 'string') {
            return eval(ref);
        }
        else {
            return ref;
        }
    },
    // Convert an array into a multidemtional array of the given width and height.  The grid is filled Left to Right, Top to Bottom.  If a dimension is not given, then that dimension is unlimited.  If neither is given, then it will try and make a square.
    arrayToGrid: function(data, width, height) {
        var grid = new Array();
        
        if (!width && !height) { width = Math.ceil(Math.sqrt(data.length)); }
        if (!width) { width = Math.ceil(data.length / height); }
        if (!height) { height = Math.ceil(data.length / width); }
        
        var i = 0;
        var end = width*height;
        var row = 0;
        while (i < end) {
            if (i >= data.length) { break; }
            grid[row] = new Array();
            for (col = 0; col < width; col++) {
                if (i >= data.length) { break; }
                grid[row][col] = data[i];
                i++;
            }
            row++;
        }
        return grid;
    }
});


