﻿var allDivs = document.getElementsByTagName('div');


function displayNav(tableId){
	for (var i=0;i<allDivs.length;i++) {
		if (allDivs[i].className == 'fund_table') {
			if ((allDivs[i].id == 'funds_' + tableId) || (tableId == 'all')) {
				allDivs[i].style.display = 'block';
			}
			else allDivs[i].style.display = 'none';
		}
	}
}

var colorOffLight = '#FFFFFF';
var colorOffDark = '#fafbf5';
var colorOver = '#edece8';
var colorCurrent = '#FFFFFF';
var theTables = new Array;
var cellCollection = new Array;
var c = 0;

function setAllRowColors(){
	var j = 0;
	var allTables = document.getElementsByTagName('tbody');
	for (var i=0;i<allTables.length;i++) {
		if (allTables[i].className.indexOf('altrows') != -1) {
			theTables[j] = allTables[i];
			setTheRowColors(theTables[j]);
			j++;
		}
	}
	cellEvents();
}

function setTheRowColors(theTable){
	theRows = theTable.getElementsByTagName('tr');
	
    var ii=-1;
	for (var i=0;i<theRows.length;i++) {
	  if (theRows[i].childNodes.length==1) 
	   {
	      if (theRows[i].childNodes[0].innerText.indexOf("Note regarding the Money Market Trust:")>-1)
	       {
	         theRows[i].childNodes[0].style.backgroundColor= ii%2 ? colorOffLight : colorOffDark;
	       }
	       else
	       {
	          theRows[i].style.backgroundColor='#8d8778';
	       }
	   }	  
	  else
      {	
         ii++;
		for (var j=0;j<theRows[i].childNodes.length;j++) {
			if (theRows[i].childNodes[j].nodeName == 'TD') {
				theRows[i].childNodes[j].style.backgroundColor = ii%2 ? colorOffLight : colorOffDark;
			}
		}
	  }
    }
}

function getLink(currentCell,action) {
	var siblingCells = currentCell.parentNode.childNodes;
	if (action == 'over') currentCell.style.cursor = 'pointer';
	for (var i=0;i<siblingCells.length;i++) {
		if (siblingCells[i].className == 'col_name') {
			var nameCell = siblingCells[i];
			for (var j=0;j<nameCell.childNodes.length;j++){
				if (nameCell.childNodes[j].nodeName == 'A') {
					switch(action){
						case 'click': return nameCell.childNodes[j].href; break;
						case 'over': nameCell.childNodes[j].style.color = '#000'; break;
						case 'out': nameCell.childNodes[j].style.color = '#234F70'; break;
					}
				}
			}
		}
	}
}

function cellEvents(){
	var parentRow;
	for (var i=0;i<theTables.length;i++) {
		if (theTables[i].className.indexOf('hiliterow') != -1) {
			theCells = theTables[i].getElementsByTagName('td');
				if (theCells.length>0) {
					for (var j=0;j<theCells.length;j++) {
						theCells[j].onmouseover = function() {
							parentRow = this.parentNode;
							collectCells(parentRow,this,'on');
							getLink(this,'over');
							this.style.cursor = 'pointer';
						}
						theCells[j].onmouseout = function() {
							parentRow = this.parentNode;
							collectCells(parentRow,this,'off');
							setTheRowColors(parentRow.parentNode);
							getLink(this,'out');
						}

					}
// Nov08 - Web 2008 - this is caused error page if the theCells[0] withour navigate url				
//					theCells[0].onclick = function(){
//						if (this.parentNode.childNodes.length==1) return;
//						window.location.href = getLink(this,'click');				
//					}
				}
			}
		}
	
	}

function collectCells(theRow,theCell,state) {
    if (theRow.childNodes.length==1) return;
	var theTable;
	var theRows;
	var siblingCells = new Array;
	siblingCells = theRow.childNodes;
	for (var i=0;i<siblingCells.length;i++) {
		if (siblingCells[i].nodeName == 'TD') {
			cellCollection[c] = siblingCells[i];
			theTable = theRow.parentNode;
			if (theTable.className.indexOf('hilitecol') != -1) {
				if (cellCollection[c] == theCell) {
					c++;
					theRows = theTable.getElementsByTagName('tr');
					for (var j=0;j<theRows.length;j++) {
						if ((theCell.className.indexOf('col_name') == -1) && (theCell.className.indexOf('col_symbol') == -1)) {
							cellCollection[c] = theRows[j].childNodes[i];
							c++;
						}
					}
				}
				else c++;
			}
			else c++;
		}
	}

	for ( var k=0 ; k<cellCollection.length ; k++ ) {
		if (cellCollection[k]) cellCollection[k].style.backgroundColor = (state == 'on' ? colorOver : colorOffLight);
	}
	if ((state == 'on') && (theCell.className.indexOf('col_name') == -1) && (theCell.className.indexOf('col_symbol') == -1) && (theTable.className.indexOf('hilitecol') != -1)) {
		theCell.style.backgroundColor = colorCurrent;
	}	
	cellCollection.length = 0;
	c = 0;
}


window.onload=function(){
	setAllRowColors();
}