// moneyMarketTable.js
/******************************************************************************
*
*	Filtering has been turned off for Money Market tab.  To turn filtering on,
*	variable aTableRow["isVisible"] has to be set to false in the following 
*	two methods AddRowMM() and AddSubheaderMM().  Also code in class 
*	TabPerformance.java, method genPerfHTML() has to be turned on (its commented).
*	Also a line moneyMarketYield() has to be uncommented.
*
*******************************************************************************/

var aColNameMonMark = new Array();
var aIsColVisibleMonMark = new Array();	// non-visible columns are used for filtering purposes
var aFormatFunctionMonMark = new Array();
var aStyleNameMonMark = new Array();

var aTableRowsMonMark = new Array();		// 2D Array of all the rows in the table - aTableRows[Row][Col]

var iRenderedRowsMonMark = 0;
var selFlagMM = false;

function AddColumnMM(sColName, isVisible, sFormatFunction, className) {
	// Creates a new range type
	aColNameMonMark.push(sColName);
	aIsColVisibleMonMark.push(isVisible);
	aFormatFunctionMonMark.push(sFormatFunction);
	aStyleNameMonMark.push(className);
}

function AddRowMM() {
	// Adds each parameter to an object and sets up
	var aTableRow = new Array();

	if (aColNameMonMark.length != AddRowMM.arguments.length) {
		alert("Invalid number of params sent to child row.");
	}

	for (i=0; i < AddRowMM.arguments.length; i++) {
		//aTableRow[aAttrName[i]] = AddRow.arguments[i];
		aTableRow.push(AddRowMM.arguments[i]);
	}
	aTableRow["isVisible"] = true;

	aTableRowsMonMark.push(aTableRow);
}

function RenderTableMM() {
	var table = document.getElementById("tblMoneyMarket");
	newRow = table.insertRow(iRenderedRowsMonMark);
	newRow.setAttribute('align','center');
	newRow.setAttribute('valign','top');
	newRow.setAttribute('id','MMrow1');
	for (col=0; col < aColNameMonMark.length; col++) {
		if (aIsColVisibleMonMark[col]) {
			newCol = newRow.insertCell(-1);
			if (col == 1) {
				newCol.setAttribute('align','left');
			}
			newCol.className = aStyleNameMonMark[col];
			newCol.innerHTML = aColNameMonMark[col];
		}
	}
	var tdColor = "Interior";
	var tdSubC = "Interior";
	var tdSwitchC = "Interior";
	
	for (row=0; row < aTableRowsMonMark.length; row++) {
		if (aTableRowsMonMark[row]["isFunction"] == "function") {
		//alert(aTableRowsMonMark[row]["isVisible"]);
			if (aTableRowsMonMark[row]["isVisible"]) {
				eval(aTableRowsMonMark[row][2]);
			}
		 tdColor = "Interior";
		 tdSubC = "Interior";
		 tdSwitchC = "Interior";
			
		} else if (aTableRowsMonMark[row]["isVisible"]) {
			iRenderedRowsMonMark++;
			newRow = table.insertRow(iRenderedRowsMonMark);
			newRow.setAttribute("align","center");
			newRow.setAttribute("valign","top");
			newRow.vAlign="top";
			if (tdColor == "Interior") {
				tdColor = "White";
				tdSubC = "Column";
				tdSwitchC = "White";
			} else {
				tdColor = "Interior";
				tdSubC = "Interior";
				tdSwitchC = "Interior";
			}
			
			for (col=0; col < aColNameMonMark.length; col++) {
				if (aIsColVisibleMonMark[col]) {
					newCol = newRow.insertCell(-1);
					//alert(col);
					if (col == 2) {
						newCol.className="bg" + tdColor;
						newRow.setAttribute("width","4");
					} else if (col == 3) {
						newCol.className="perfTable" + tdColor + "Col";
						newCol.setAttribute("align","left");
					} else if (col == 5) {

						newCol.className="bg" + tdColor;							
					} else {
						if (tdSubC == "Column") {
							if (tdSwitchC == "Column") {
								tdSwitchC = "White";
							} else {
								tdSwitchC = "Column";
							}
						} 
						newCol.className=" perfTable" + tdSwitchC;
					}
									
					//alert('b');
					displayVal = aTableRowsMonMark[row][col];
					//alert('c');
					newCol.innerHTML = displayVal;
					//alert('d');
				}
			}			
		}
	}	
	if (!selFlagMM) {
		document.getElementById("MMrow1").style.display = "none";
	}
}

function AddSubheaderMM(fnName, stCategory, stClass) {
	var aTableRow = new Array();
	aTableRow["isFunction"] = "function";
	aTableRow["isVisible"] = true;
	aTableRow[0]=stCategory;
	aTableRow[1]=stClass;
	aTableRow.push(fnName);
	aTableRowsMonMark.push(aTableRow);
}

function AddSubHeaderingPerfMM(text1) {
	iRenderedRowsMonMark++;
	var headerRow=document.getElementById('tblMoneyMarket').insertRow(iRenderedRowsMonMark);
	headerRow.className="bgName";
	var col1=headerRow.insertCell(0);
	col1.className="bgName";
	col1.setAttribute("width","4");
	var col2=headerRow.insertCell(1);
	col2.className="perfTableNameCol";
	var col3=headerRow.insertCell(2);
	col3.colSpan=3;
	col1.innerHTML="";
	col2.innerHTML=text1;
	col3.innerHTML="";
	//iRenderedRowsMonMark++;
}

function noInfoMM(text1) {
	var headerRow=document.getElementById('tblMoneyMarket').insertRow(iRenderedRowsMonMark);
	headerRow.className="bgWhite";
	var col1=headerRow.insertCell(0);
	col1.className="bgWhite";
	col1.setAttribute("width","4");
	var col2=headerRow.insertCell(1);
	col2.className="bgWhite";
	col2.colSpan=5;
	col1.innerHTML="";
	col2.innerHTML=text1;
	iRenderedRowsMonMark++;
}

function filterResultMM(objCat, objClass, strNoSelectionMsg) {
	var flag = false;
	selFlagMM = false;
	if (typeof objCat != "undefined" && typeof objClass != "undefined") {
		for (i=0; i < objCat.length; i++) {
			if (objCat[i].checked) {
				for(j=0; j < aTableRowsMonMark.length; j++) {
				//alert(aTableRowsMonMark[j][0]+"-"+j);
					//check categories
					if (objCat[i].value == aTableRowsMonMark[j][0]) {
							if (aTableRowsMonMark[j][1] == "-1") {
								aTableRowsMonMark[j]["isVisible"] = true;
								//alert(aTableRowsMonMark[j][0]+"-"+j);
								flag = false;
								continue;
							} else if (aTableRowsMonMark[j][1] == "-2" && flag) {
								aTableRowsMonMark[j]["isVisible"] = true;
								continue;
							} else {
								for (k=0; k < objClass.length; k++) {
									if (objClass[k].checked) {
										if (objClass[k].value == aTableRowsMonMark[j][1]) {
											aTableRowsMonMark[j]["isVisible"] = true;
											if (!flag) {
												//alert(j);
												aTableRowsMonMark[j-k]["isVisible"] = true;
												flag = true;
												selFlagMM = true;
											}
										}
									}
								}
								if (!flag) {
									aTableRowsMonMark[j-1]["isVisible"] = false;
								}
							}
					}
				}
			}
		}
	}
	if (!selFlagMM) {
		noInfoMM(strNoSelectionMsg);
	}
}

function ClearFiltersMM() {
	for (row=0; row < aTableRowsMonMark.length; row++) {
		aTableRowsMonMark[row]["isVisible"] = false;
	}
}

function clearTableMM() {
	var table = document.getElementById("tblMoneyMarket");

	// Clear the table before re-rendering
	for (row=0; row < iRenderedRowsMonMark+1; row++) {
		table.deleteRow(-1);
	}
	iRenderedRowsMonMark=0;
	ClearFiltersMM();
}

function AddHeaderMM(text1, text2, text3) {
	var headerRow=document.getElementById('tblMoneyMarket').insertRow(iRenderedRowsMonMark);
	headerRow.align="center";
	var col1=headerRow.insertCell(0);
	col1.className="perfTableSub";
	col1.setAttribute("width","4");
	var col2=headerRow.insertCell(1);
	col2.className="perfTableSub";
	col2.align="left";
	col2.setAttribute("width","30%");
	col2.style.borderRight='solid 1px #ffffff';
	var col3=headerRow.insertCell(2);
	col3.className="perfTableSub";
	col3.setAttribute("width","34.5%");
	col3.style.borderRight='solid 1px #dfdede';
	var col4=headerRow.insertCell(3);
	col4.className="perfTableSub";
	col4.setAttribute("width","34.5%");
	col1.innerHTML="";
	col2.innerHTML=text1;
	col3.innerHTML=text2;
	col4.innerHTML=text3;
	iRenderedRowsMonMark++;
}