/*extern make, maker, display_matrix_as_table */
 

// -----------------------------------------------------------------------------------
// Display the strengths
function display_strengths(os, ds, rowlabels, table_place) {

var smatrix = [];   // The matrix of strengths that we'll compute and display
var sortmefirst = "sortmefirst_" + table_place;
var columnlabels = ["Team", "Offensive", "Defensive", "Overall<span id=" + sortmefirst + "></span>"];
// var columnlabels = ["Team", "Offensive", "Defensive", "Overall"];
var attribm = [];
var i, j;

for (i=0;i<os.length; i++) {
     attribm[i] = [];
     for (j=0; j<4; j++) {
         attribm[i][j] = " ";
     }  
}
    

// Form the table rows for all of the teams:
for (i=0; i<os.length; i++) {
    var overall = ((os[i] - 0) + (ds[i] - 0)).toFixed(1);
    smatrix[i] = [];
    smatrix[i][0] = os[i];
    smatrix[i][1] = ds[i];
    smatrix[i][2] = overall;
}    



var high = 1;  //  Sort the chosen column high-to-low

// Display the strengths:  
display_matrix_as_table(smatrix, attribm, "5A Region III District 23 - Team Strengths", 
                rowlabels, columnlabels, "400", high, table_place);


}  //  End of function display_strengths(os, ds, teamnames, table_place)



// -----------------------------------------------------------------------------------
// Display the predicted scores
function display_predictions(ostrengths, dstrengths, rowlabels, table_place, scores, full_future_past) {

var attrib = "";    // An individual attribute
var score;          // An individual score
var psm = [];       // The matrix of predicted scores to display
var attribm = [];   // The matrix of attributes to control the colors of the display
   
// Form the table rows for all of the teams:
// The predicted score when team i plays team j is that team i scores o[i]-d[j] points
//    and that team j scores o[j]-d[i]

for (var i=0; i<ostrengths.length; i++) {
    
    psm[i] = [];
    attribm[i] = [];
    
    for (var j=0; j<ostrengths.length; j++) {
    
        var iscore = (ostrengths[i] - dstrengths[j]).toFixed(0);
        var jscore = (ostrengths[j] - dstrengths[i]).toFixed(0);
        
        if(iscore-jscore > 0) {attrib="win";}
        else if (iscore-jscore < 0) {attrib="loss";}
        else {attrib="tie";}
        
        score = iscore + "-" + jscore;     // This is the score to display, if we're going to display this game
        
        if (i==j) {score = ""; attrib="notplayed";}  // Never show a team playing itself
        
        if (full_future_past==2) {          // full_future_past==2  ====> Show only future games:
            if ( !isNaN(scores[i][j]) ) {score = ""; attrib="";}   // I.e., hide past games
        }
        else if (full_future_past==3) {     // full_future_past==3  ====> Show only past games:
                                            // And color-code them to show whether the predicted winner is correct
            if ( isNaN(scores[i][j]) ) 
                {score = ""; attrib="";}   // I.e., hide future games
            else 
                {
                var sij = scores[i][j];
                var sji = scores[j][i];
                var winlosetie = sij - sji;
                var win = winlosetie > 0;
                var tie = winlosetie === 0;
            
                if( ((attrib=="win") && win) || ( (attrib=="loss") && !win && !tie ) || ( (attrib=="tie") && tie) ) 
                    {attrib = "right";}
                else
                    {attrib = "wrong";}
            }
        }  

        psm[i][j]     = score;
        attribm[i][j] = attrib; 

    }  // end j

}    // end i


var sortmefirst = "sortmefirst_" + table_place;

var columnlabels = ["Team", "Austin", "Bush", "Clements", "Dulles", "Elkins", "High", "Kemp.", "Marsh.", "Willow."];


var title = "5A Region III District 23 Predicted Scores";
if (full_future_past==1) {title += " (Past and Future)";}
else if (full_future_past==2) {title += " (Future Games)";}
else {title += " (Past Games)";}

var high = 0;  //  Sort the chosen column low-to-high

// Display the strengths:  
display_matrix_as_table(psm, attribm, title, 
                rowlabels, columnlabels, "600", high, table_place);


}  // End of function display_predictions(ostrengths, dstrengths, teamnames, table_place) 
