/*do not use word pad to edit this file, screws up mysteriously*/
/***********************************************************************************
 * @Name	legend.js
 * @author 	Kris Kline
 * 
 * @Purpose	This script handles putting the legend on the page
 * 
 * Date Created:	19 DEC 2002
 * Date Modified:	17 JUN 2003
 **********************************************************************************/

var STR_LEGEND_TITLE="Explanation";
var STR_LEGEND_TITLE_CLASS="legendTitle";
var STR_LEGEND_TABLE_OUTER="legendTable";
var STR_LEGEND_TABLE_INNER="legendInternalTable";
var STR_LEGEND_PIC_CELL_CLASS="legendCellPic";
var STR_LEGEND_NAME_CELL_CLASS="legendCellName";
var STR_LEGEND_ITEM_FONT="legendItem";

var N_LEGEND_NUM_TESTS=3;
var N_LEGEND_ARR_NUM_COLS=0;
var N_LEGEND_ARR_NAME=1;

var arrLegendNames = new Array(N_LEGEND_NUM_TESTS);
		// At [N_LEGEND_ARR_NUM_COLS] of each internal array is the number of clumns to store the data in
		// At [N_LEGEND_ARR_NAME] of each internal array is the test name

var N_LEGEND_ARR_M204BT=0;
var N_LEGEND_ELEMENTS_M204BT=7;
arrLegendNames[N_LEGEND_ARR_M204BT] = new Array(N_LEGEND_ELEMENTS_M204BT + 2);
arrLegendNames[N_LEGEND_ARR_M204BT][N_LEGEND_ARR_NUM_COLS]=2;
arrLegendNames[N_LEGEND_ARR_M204BT][N_LEGEND_ARR_NAME]="sb204";
arrLegendNames[N_LEGEND_ARR_M204BT][2]="Median flow < 1 ft<sup>3</sup>/s";
arrLegendNames[N_LEGEND_ARR_M204BT][3]="Median flow >= 1 ft<sup>3</sup>/s";
arrLegendNames[N_LEGEND_ARR_M204BT][4]="Major Road";
arrLegendNames[N_LEGEND_ARR_M204BT][5]="Federal reservoir controlled stream";
arrLegendNames[N_LEGEND_ARR_M204BT][6]="Lake or Reservoir";
arrLegendNames[N_LEGEND_ARR_M204BT][7]="Site <br>(downstream end of CUSEGA stream segment)";
arrLegendNames[N_LEGEND_ARR_M204BT][8]="Gage";

var N_LEGEND_ARR_FDUR=1;
var N_LEGEND_ELEMENTS_FDUR=6;
arrLegendNames[N_LEGEND_ARR_FDUR] = new Array(N_LEGEND_ELEMENTS_FDUR + 2);
arrLegendNames[N_LEGEND_ARR_FDUR][N_LEGEND_ARR_NUM_COLS]=2;
arrLegendNames[N_LEGEND_ARR_FDUR][N_LEGEND_ARR_NAME]="flowdur";
arrLegendNames[N_LEGEND_ARR_FDUR][2]="Stream Segment";
arrLegendNames[N_LEGEND_ARR_FDUR][3]="Major Road";
arrLegendNames[N_LEGEND_ARR_FDUR][4]="Reservoir controlled stream";
arrLegendNames[N_LEGEND_ARR_FDUR][5]="Lake or Reservoir";
arrLegendNames[N_LEGEND_ARR_FDUR][6]="Site <br>(downstream end of CUSEGA stream segment)";
arrLegendNames[N_LEGEND_ARR_FDUR][7]="Gage";

var N_LEGEND_ARR_FFREQ=2;
var N_LEGEND_ELEMENTS_FFREQ=6;
arrLegendNames[N_LEGEND_ARR_FFREQ] = new Array(N_LEGEND_ELEMENTS_FFREQ + 2);
arrLegendNames[N_LEGEND_ARR_FFREQ][N_LEGEND_ARR_NUM_COLS]=2;
arrLegendNames[N_LEGEND_ARR_FFREQ][N_LEGEND_ARR_NAME]="ffreq";
arrLegendNames[N_LEGEND_ARR_FFREQ][2]="Stream Segment";
arrLegendNames[N_LEGEND_ARR_FFREQ][3]="Major Road";
arrLegendNames[N_LEGEND_ARR_FFREQ][4]="Reservoir controlled stream";
arrLegendNames[N_LEGEND_ARR_FFREQ][5]="Lake or Reservoir";
arrLegendNames[N_LEGEND_ARR_FFREQ][6]="Site <br>(downstream end of CUSEGA stream segment)";
arrLegendNames[N_LEGEND_ARR_FFREQ][7]="Gage";

var N_LEGEND_ARR_BASIN=3;
var N_LEGEND_ELEMENTS_BASIN=6;
arrLegendNames[N_LEGEND_ARR_BASIN] = new Array(N_LEGEND_ELEMENTS_BASIN + 2);
arrLegendNames[N_LEGEND_ARR_BASIN][N_LEGEND_ARR_NUM_COLS]=2;
arrLegendNames[N_LEGEND_ARR_BASIN][N_LEGEND_ARR_NAME]="basin";
arrLegendNames[N_LEGEND_ARR_BASIN][2]="Stream Segment";
arrLegendNames[N_LEGEND_ARR_BASIN][3]="Major Road";
arrLegendNames[N_LEGEND_ARR_BASIN][4]="Reservoir controlled stream";
arrLegendNames[N_LEGEND_ARR_BASIN][5]="Lake or Reservoir";
arrLegendNames[N_LEGEND_ARR_BASIN][6]="Site <br>(downstream end of CUSEGA stream segment)";
arrLegendNames[N_LEGEND_ARR_BASIN][7]="Gage";

var STR_LEGEND_PIC_ROOT="studies/strmstats/images/legendPics/";
var STR_LEGEND_PIC_EXT="gif";


/*********************************************************************
 * @Function	putLegendTitle
 * @Script	legend.js
 * @author 	Kris Kline
 *
 * This method puts the legend title cell onto the page
 *
 * @param nCols		The number of columns in the legend
 ********************************************************************/
function putLegendTitle(nCols)
{
	document.writeln("<TR>");
	document.writeln("	<TD COLSPAN=" + (nCols * 2) + " " +
			 	"CLASS=" + STR_LEGEND_TITLE_CLASS + ">");
	document.writeln("	<CENTER>");
	document.writeln("	<FONT CLASS=" + STR_LEGEND_TITLE_CLASS + ">" +
			 	STR_LEGEND_TITLE + 
			 	"</FONT>");
	document.writeln("	</CENTER>");
	document.writeln("	</TD>");
	document.writeln("</TR>");
} // putLegendTitle


/*********************************************************************
 * @Function	putLegendNames
 * @Script	legend.js
 * @author 	Kris Kline
 *
 * This function puts in all the legend names
 *
 * @param arrNames	The array of all the names
 * @param strPicRoot	The root of all the legend pictures
 * @param strPicExt	The extenstion of all the legend pictures
 ********************************************************************/
function putLegendNames(arrNames, strPicRoot, strPicExt)
{
	var nCols=arrNames[N_LEGEND_ARR_NUM_COLS];
	var strTest=arrNames[N_LEGEND_ARR_NAME];
	var nOff=2;
	var nNum=arrNames.length;
	
	for(var x=nOff; x<nNum; x+=nCols)
	{
		document.writeln("<TR>");
		for(var y=0;y<nCols && x+y<nNum;y++)
		{
			document.writeln("<TD CLASS=" + 
					 STR_LEGEND_PIC_CELL_CLASS + ">");
			document.writeln("<IMG" +
						" SRC=\"" + strPicRoot + strTest + "/" + (x+y+1-nOff) + "." + strPicExt + "\"" +
					 " BORDER=0" +
					 ">");
			document.writeln("</TD>");
			document.writeln("<TD CLASS=" + 
					 STR_LEGEND_NAME_CELL_CLASS + ">");
			document.writeln("<FONT CLASS=" +
					 STR_LEGEND_ITEM_FONT + ">" +
					 arrNames[x+y] + "</FONT>");
			document.writeln("</TD>");
		} // for(var y=0;y<nCols && x+y<nNum;y++)
		document.writeln("</TR>");
	} // for(var x=0; x<nNum; x+=nCols)
} // putLegendNames


/*********************************************************************
 * @Function	putInternalTable
 * @Script	legend.js
 * @author 	Kris Kline
 *
 * This function puts in all the legend names
 *
 * @param nTest		The location of the test in the array
 ********************************************************************/
function putInternalTable(nTest,strLevel)
{
	document.writeln("<TABLE BORDER=1 "+
			 	"CELLPADDING=2 CELLSPACING=2 " + 
				"CLASS=" + STR_LEGEND_TABLE_INNER + ">");

	putLegendTitle(arrLegendNames[nTest][N_LEGEND_ARR_NUM_COLS]);
	
	putLegendNames(arrLegendNames[nTest],
			strLevel+STR_LEGEND_PIC_ROOT,
			STR_LEGEND_PIC_EXT);
	
	document.writeln("</TABLE>");
} // putInternalTable


/*********************************************************************
 * @Function	putLegend
 * @Script	legend.js
 * @author 	Kris Kline
 *
 * This method puts the entire legend onto the page
 *
 * @param strTest	The test
 ********************************************************************/
function putLegend(strTest,strLevel)
{
	var nTestNum=0;
	switch(strTest.toLowerCase( ))
	{	case arrLegendNames[N_LEGEND_ARR_M204BT][1]:
		nTestNum=N_LEGEND_ARR_M204BT;
		break;
	case arrLegendNames[N_LEGEND_ARR_FDUR][1]:
		nTestNum=N_LEGEND_ARR_FDUR;
		break;
	case arrLegendNames[N_LEGEND_ARR_FFREQ][1]:
		nTestNum=N_LEGEND_ARR_FFREQ;
		break;
        case arrLegendNames[N_LEGEND_ARR_BASIN][1]:
		nTestNum=N_LEGEND_ARR_BASIN;
		break;
	default:
		return;
	} // switch(strTest.toLowerCase( ))
	document.writeln("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0" +
			 	" CLASS=" + STR_LEGEND_TABLE_OUTER + ">\n" +
			 "	<TR>\n" +
			 "		<TD>");
	putInternalTable(nTestNum,strLevel);
	document.writeln("		</TD>\n" +
			 "	</TR>\n" +
			 "</TABLE>");

} // putLegend

