// dividendCapitalTable.js

var aColNameDivCap = new Array();
var aIsColVisibleDivCap = new Array();	// non-visible columns are used for filtering purposes
var aFormatFunctionDivCap = new Array();
var aStyleNameDivCap = new Array();

var aTableRowsDivCap = new Array();		// 2D Array of all the rows in the table - aTableRows[Row][Col]

var iRenderedRowsDivCap = 0;
var selFlagDC = false;

function AddColumnDC(sColName, isVisible, sFormatFunction, className) {
	// Creates a new range type
	aColNameDivCap.push(sColName);
	aIsColVisibleDivCap.push(isVisible);
	aFormatFunctionDivCap.push(sFormatFunction);
	aStyleNameDivCap.push(className);
}

function AddRowDC() {
	// Adds each parameter to an object and sets up
	var aTableRow = new Array();
	
	if (aColNameDivCap.length != AddRowDC.arguments.length) {
		alert("Invalid number of params sent to child row.");
	}

	for (i=0; i < AddRowDC.arguments.length; i++) {
		//aTableRow[aAttrName[i]] = AddRow.arguments[i];
		aTableRow.push(AddRowDC.arguments[i]);
	}
	aTableRow["isVisible"] = false;

	aTableRowsDivCap.push(aTableRow);
}

function RenderTableDC() {
	var table = document.getElementById("tblDivCap");
	newRow = table.insertRow(iRenderedRowsDivCap);
	newRow.setAttribute('align','center');
	newRow.setAttribute('valign','top');
	newRow.setAttribute('id','DCrow1');
	for (col=0; col < aColNameDivCap.length; col++) {
		if (aIsColVisibleDivCap[col]) {
			newCol = newRow.insertCell(-1);
			if (col == 1) {
				newCol.setAttribute('align','left');
			}
			newCol.className = aStyleNameDivCap[col];
			newCol.innerHTML = aColNameDivCap[col];
		}
	}
	var tdColor = "Interior";
	var tdSubC = "Interior";
	var tdSwitchC = "Interior";
	
	for (row=0; row < aTableRowsDivCap.length; row++) {
		if (aTableRowsDivCap[row]["isFunction"] == "function") {
			if (aTableRowsDivCap[row]["isVisible"]) {
				eval(aTableRowsDivCap[row][2]);
			}
		 tdColor = "Interior";
		 tdSubC = "Interior";
		 tdSwitchC = "Interior";
			
		} else if (aTableRowsDivCap[row]["isVisible"]) {
			iRenderedRowsDivCap++;
			newRow = table.insertRow(iRenderedRowsDivCap);
			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 < aColNameDivCap.length; col++) {
				if (aIsColVisibleDivCap[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="perfTable" + tdSubC + "Col";
						if (tdSubC == "Column") {
							if (tdSwitchC == "Column") {
								tdSwitchC = "White";
							} else {
								tdSwitchC = "Column";
							}
						}
					} else if (col == 9) {
						newCol.className="bg" + tdColor;						
					} else {
						if (tdSubC == "Column") {
							if (tdSwitchC == "Column") {
								tdSwitchC = "White";
							} else {
								tdSwitchC = "Column";
							}
						} 
						newCol.className=" perfTable" + tdSwitchC;
					}
									
					//alert('b');
					displayVal = aTableRowsDivCap[row][col];
					//alert('c');
					newCol.innerHTML = displayVal;
					//alert('d');
				}
			}			
		}
	}	
	if (!selFlagDC) {
		document.getElementById("DCrow1").style.display = "none";
	}	
}

function AddSubheaderDC(fnName, stCategory, stClass) {
	var aTableRow = new Array();
	aTableRow["isFunction"] = "function";
	aTableRow["isVisible"] = false;
	aTableRow[0]=stCategory;
	aTableRow[1]=stClass;
	aTableRow.push(fnName);
	aTableRowsDivCap.push(aTableRow);
}

function AddSubHeaderingPerfDC(text1) {
	iRenderedRowsDivCap++;
	var headerRow=document.getElementById('tblDivCap').insertRow(iRenderedRowsDivCap);
	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.className="perfTableNameCol";	
	col3.colSpan=2;
	var col4=headerRow.insertCell(3);
	//col4.className="perfTableNameCol";	
	col4.colSpan=4;	
	col1.innerHTML="";
	col2.innerHTML=text1;
	col3.innerHTML="&nbsp;";
	col4.innerHTML="";
	//iRenderedRowsDivCap++;
}

function noInfoDC(text1) {
	var headerRow=document.getElementById('tblDivCap').insertRow(iRenderedRowsDivCap);
	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=7;
	col1.innerHTML="";
	col2.innerHTML=text1;
	iRenderedRowsDivCap++;
}

function filterResultDC(objCat, objClass, strNoSelectionMsg) {
	var flag = false;
	var tmpId = "";
	selFlagDC = false;
	if (typeof objCat != "undefined" && typeof objClass != "undefined") {	
		for (i=0; i < objCat.length; i++) {
			if (objCat[i].checked) {
				for(j=0; j < aTableRowsDivCap.length; j++) {
				//alert(aTableRowsMonMark[j][0]+"-"+j);
					//check categories
					if (objCat[i].value == aTableRowsDivCap[j][0]) {
							if (aTableRowsDivCap[j][1] == "-1") {
								aTableRowsDivCap[j]["isVisible"] = true;
								flag = false;
								tmpId = j;
								continue;
							} else if (aTableRowsDivCap[j][1] == "-2" && flag) {
								aTableRowsDivCap[j]["isVisible"] = true;
								continue;
							} else {
								for (k=0; k < objClass.length; k++) {
									if (objClass[k].checked) {
										if(aTableRowsDivCap[j][1]=="Class R1" || aTableRowsDivCap[j][1]=="Class R2"
									       || aTableRowsDivCap[j][1]=="Class R3"){
										    aTableRowsDivCap[j][1]="Class R";
									    }
										if (objClass[k].value == aTableRowsDivCap[j][1]) {
											aTableRowsDivCap[j]["isVisible"] = true;
											if (!flag) {
												//alert(j);
												aTableRowsDivCap[tmpId]["isVisible"] = true;
												flag = true;
												selFlagDC = true;
											}
										}
									}
								}
								if (!flag) {
									aTableRowsDivCap[tmpId]["isVisible"] = false;
								}
							}
					}
				}
			}
		}
	}
	if (!selFlagDC) {
		noInfoDC(strNoSelectionMsg);
	}	
}

function clearTableDC() {
	var table = document.getElementById("tblDivCap");

	// Clear the table before re-rendering
	for (row=0; row < iRenderedRowsDivCap+1; row++) {
		table.deleteRow(-1);
	}
	iRenderedRowsDivCap=0;
	ClearFiltersDC();
}

function ClearFiltersDC() {
	for (row=0; row < aTableRowsDivCap.length; row++) {
		aTableRowsDivCap[row]["isVisible"] = false;
	}
}

function AddHeaderDC(text1, text2) {
	var headerRow=document.getElementById('tblDivCap').insertRow(iRenderedRowsDivCap);
	headerRow.align="center";
	var col1=headerRow.insertCell(0);
	col1.className="perfTableSub";
	col1.setAttribute("width","4");
	var col2=headerRow.insertCell(1);
	col2.className="perfTableSub";
	col2.setAttribute("width","28%");
	col2.style.borderRight='solid 1px #ffffff';
	var col3=headerRow.insertCell(2);
	col3.className="perfTableSub";
	col3.colSpan=2;
	col3.style.borderRight='solid 1px #ffffff';
	var col4=headerRow.insertCell(3);
	col4.className="perfTableSub";
	col4.colSpan=4;
	col1.innerHTML="";
	col2.innerHTML="";
	col3.innerHTML=text1;
	col4.innerHTML=text2;
	iRenderedRowsDivCap++;
}