/*extern  ts_makeSortable, ts_resortTable */

// -----------------------------------------------------------------------------------
function form_and_attach(my_record_table, headers, trow, table_place, sortmefirst, numrows, high) {

// Append the headers to tHead:
var i;
for (i=0; i<headers.length; i++) {
    my_record_table.tHead.appendChild(headers[i]);
}

/***
my_record_table.tHead.appendChild(header1);
my_record_table.tHead.appendChild(header2);
***/

//  Append the rows to tBodies[0]:

for (i=0; i<numrows; i++) { 
    my_record_table.tBodies[0].appendChild(trow[i]);
}


// Find the place in the document where the table should be placed
// We assume that the html has a line something like this:  <div id="district_standings_table_here" ></div>
var t_here = document.getElementById(table_place + "_here");
var appendplace;
if ( (t_here === undefined) || (t_here === null)) {appendplace = document.body;}
else {appendplace = t_here;}



// Append the table to the document:
var my_app_table = appendplace.appendChild(my_record_table);


// Make the table sortable:
ts_makeSortable(my_record_table);


// Find the "sortmefirst" cell for this table:
var sortcell = document.getElementById(sortmefirst);

if ( (sortcell === undefined) || (sortcell === null ) )
    {
    // alert("Did not find sortcell!");
    return;
    }


// Sort the chosen column:
ts_resortTable(sortcell.parentNode);  // Low to high
if (high==1) {ts_resortTable(sortcell.parentNode);}  // High to low


}  // End of function form_and_attach(my_record_table, headers, trow, table_place, sortmefirst, numrows, high) {