/*extern make, form_and_attach */




// -----------------------------------------------------------------------------------
function display_matrix_as_table(
                        mrow,           // the matrix to display
                        attribm,        // matrix of attributes for the display table cells, to control color, e.g.
                        caption,        // caption for the matrix
                        rowlabels,      // labels for the rows
                        columnlabels,   // labels for the columns (includes a label for the column of rowlabels)
                        tablewidth,     // string (e.g., "600") representing width in pixels of the table
                        high,           // whether to sort low-to-high (0) or high-to-low (1) in the initial sort
                        table_place )    // name of the table in the htm file
                        {
 
var td = maker("td"); 
var trow = [];
var Modern = false;
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {Modern = true;}
if (navigator.userAgent.toLowerCase().indexOf("chrome") != -1) {Modern = true;}
if (navigator.userAgent.toLowerCase().indexOf("msie 8.0") != -1) {Modern = true;}
if (navigator.userAgent.toLowerCase().indexOf("msie 7.0") != -1) {Modern = true;}

// Maybe we can now (in late 2009) assume that all browsers are modern:
Modern = true;

// Form the table rows:
var attr = "";
for (var i=0; i<mrow.length; i++) {
    var dataline = [];
    dataline[0] = make("TD", rowlabels[i]);
    for (var j=0; j<mrow[i].length; j++) {
		attr = "" + attribm[i][j];
        dataline[j+1] =  td( { "class":attr }, ["" + mrow[i][j]] )  ;		
    }  

    trow[i] = make("TR", {align:"center"}, dataline );
}    


        
var headers = [];
var dcol = [];
for (i=0;i<mrow[0].length+1; i++) {dcol.push( make("TH", [columnlabels[i]]) ); }
headers[0] = make( "TR", dcol );

var sortmefirst = "sortmefirst_" + table_place;
// Build the CAPTION:
var captionh = make( "CAPTION", [caption] );
var mythead = make( "THEAD" );
var mytbody = make( "TBODY" );

// Form the table and attach the column groups, caption, and empty thead and tbody:

var my_record_table = make( "TABLE", {align:"center", className:"sortable", 
                                      id:table_place, border:"3", width:tablewidth,  
                                      cellpadding:"2", cellspacing:"2"}, 
                                [captionh, mythead, mytbody ] );
                                
var numrows = trow.length; // Number of rows of trow to insert into the table


// Form the table, with its headers and its rows, with the chosen column sorted,
//   and insert it into the proper place in the document:
form_and_attach(my_record_table, headers, trow, table_place, sortmefirst, numrows, high);
   
}  // End of function display_matrix_as_table(mrow,table_place)