function expand(selection, table){
var ex=ex_= selection[1], ey=ey_=selection[3]; // expansions on the bottom and right to do, _ will be their previous values
do {
ex_ = ex; ey_ = ey;
for (var i=selection[0];i<=selection[1]; i++)
for (var j=selection[2]; j<=selection[3]; j++){
var td=table.rows[i].cells[j];
ex = max(i+td.rowspan-1,ex); //maybe min with table.rows.length)
ey = max(j+td.colspan-1,ey); //maybe min with table.rows[i].cells.length)
}