var shareClassListArray = new Array();
var shareClassList = new Array("A", "B", "C", "C2");
var productTypeList = new Array("all", "A", "S", "M", "L", "V");

function showDiv ( id ) {
	var div = document.getElementById( id );
	if ( div ) if ( div.style ) div.style.display = "block";
}
function hideDiv ( id ) {
	var div = document.getElementById( id );
	if ( div ) if ( div.style ) div.style.display = "none";
}

var currentShareClass = '';
var currentProductType = '';

function toggleProductType(type) {

	var productTypeSelectedIndex = 0;

	for (t = 0; t < productTypeList.length; t++) {
		var tProdType = document.getElementById('product_type_list_' + productTypeList[t]);
		if ( tProdType ) {
			removeClass(tProdType, 'on');
			if (productTypeList[t] == type) {
				addClass(tProdType, 'on');
				productTypeSelectedIndex = t;
			}
		}
	}

	switch (productTypeSelectedIndex) {
		case 0:
			for (t = 1; t < productTypeList.length; t++) {
				showDiv( 'portfolio_type_div_' + productTypeList[t] );
				showDiv( 'footnotes_portfolio_type_div_' + productTypeList[t] );
			}
			break;
			
		default:
			for (t = 1; t < productTypeList.length; t++) {
				if (productTypeList[t] == type) {
					showDiv( 'portfolio_type_div_' + productTypeList[t] );
					showDiv( 'footnotes_portfolio_type_div_' + productTypeList[t] );					
				} else {
					hideDiv( 'portfolio_type_div_' + productTypeList[t] );
					hideDiv( 'footnotes_portfolio_type_div_' + productTypeList[t] );					
				}
			}	
	}


	if ( type == 'M' ) {
		
		showShareClassFootnotes( '' );
	} else {
		if ( currentProductType == 'M' ) {
			
			showShareClassFootnotes( currentShareClass );
		}
	}
	
	currentProductType = type;
		
	return;
}



function toggleShareClass(share, portType) {

	for (c = 0; c < shareClassList.length; c++) {
		for (t = 1; t < productTypeList.length; t++) {
			var cShareClass = document.getElementById('share_class_list_' + shareClassList[c] + '_' + productTypeList[t]);
			if ( cShareClass ) {
				removeClass(cShareClass, 'on');
				if (shareClassList[c] == share) {
					addClass(cShareClass, 'on');
				}
			}
		}
	}
	
	for (s = 0; s < shareClassListArray.length; s++) {
		var trShareClass = document.getElementById(shareClassListArray[s]);
		if ( trShareClass ) {
			if ( (shareClassListArray[s].substring(shareClassListArray[s].length - share.length)) == share) {
				trShareClass.style.display = '';
			} else {
				if (shareClassListArray[s].substring(0, 1) != 'M')
					trShareClass.style.display = 'none';
			}
		}
	}


	showShareClassFootnotes( share );

	currentShareClass = share;
	
	return;
}


function showShareClassFootnotes( share ) {

	for (f = 0; f < shareClassList.length; f++) {
		if (shareClassList[f] == share) {
			showDiv( 'footnotes_class_' + shareClassList[f] );
		} else {
			hideDiv( 'footnotes_class_' + shareClassList[f] );
		}
	}
}

function hiLiteRow(rowElem) {
	addClass(rowElem, 'mouseover');
}

function loLiteRow(rowElem) {
	removeClass(rowElem, 'mouseover');
}

function removeClass(element, className) {
	var regexp = new RegExp(" " + className);    
	element.className = element.className.replace(regexp, "");
}

function addClass(element, className) {
	element.className += " " + className;
}


function gvRE () { window.status=''; }
function gvRI ( id ) { window.status='/public/site/factsheet/0,,@@ID@@,00.shtm'.replace( /@@ID@@/g, id ); } 
function gvRC ( id ) { window.location='/public/site/factsheet/0,,@@ID@@,00.shtm'.replace( /@@ID@@/g, id ); } 

/// 
// Handler for the onMouseOut event for a CrosshairGridView Cell
// It reverts highlighted cells back to their normal color
function cgvME(cell, rowColor, alternatingRowColor) {
	var columnIndex = cgvGetColumnIndex(cell);
	
	var row = cell.parentNode;
	var table = row.parentNode;
	var rows = table.childNodes;
	
	// Iterate over all the rows.  For most rows, we just have to switch the color
	// of the cell in the highlighted column.  But for the row containing the current
	// cell, we have to switch the color of all the cells in the row
	var rowNum = 0;
	for(var i = 0; i < rows.length; i++)  {
		var row2 = rows[i];
		
		// Skip any pager header row(s)
		if (row2.className == null || (row2.className.indexOf("pager_row") < 0)) {
		
			if ( row2.style && row2.style.display != 'none' ) {
			
			     // Choose the normal color (regular or alternating)
			     var color = (rowNum%2 == 0) ? alternatingRowColor : rowColor;
			     
			     // Is this the highlighted row?
			     if(row2 == row) {
			        var cells = row.childNodes;
			        
			        //  For the highlighted row, switch every cell back
			        for(var j = 0; j < cells.length; j++) {
			           if(cells[j] && (cells[j].nodeName == 'TD')) {
			              cells[j].style.backgroundColor = color;
			           }
			        }
			     } else {
			        // For the non-highlighted row, we only have to switch the cell in highlighted column
			        var highlightCell = row2.childNodes[columnIndex];
			        if(highlightCell && (highlightCell.nodeName == 'TD')) {
			           highlightCell.style.backgroundColor = color;
			        }
			     }
				rowNum++;
			}	
		}
	}
}

// Handler for the onMouseOver event for a CrosshairGridView Cell
// It highlights the row and column of the current cell.  The cell itself
// gets the bullseye color
function cgvMI(cell, crosshairColor, bullseyeColor) {
	var columnIndex = cgvGetColumnIndex(cell);
	
	var row = cell.parentNode;
	var table = row.parentNode;
	var rows = table.childNodes;
	
	// Iterate over all the rows.  For most rows, we just have to switch the color
	// of the cell in the highlighted column.  But for the row containing the current
	// cell, we have to switch the color of all the cells in the row
	for(var i = 0; i < rows.length; i++) {
		var row2 = rows[i];  
		if ( row2.style && row2.style.display != 'none' ) {
			// Is this the highlighted row?
			if(row2 == row) {
				//  For the highlighted row, highlight every cell
				var cells = row.childNodes;
				for(var j = 0; j < cells.length; j++) {
					if(cells[j] && (cells[j].nodeName == 'TD')) {
					   cells[j].style.backgroundColor = crosshairColor;
					}
				}
			} else {
				// For the non-highlighted row, only highlight the cell in highlighted column
				var highlightCell = row2.childNodes[columnIndex];
				if(highlightCell && (highlightCell.nodeName == 'TD')) {
					highlightCell.style.backgroundColor = crosshairColor;
				}
			}
		}
	}
	cell.style.backgroundColor = bullseyeColor;
}

// handler to change the color of a row containing the passed in cell
function cgvHR(cell, rowColor)
{
   var row = cell.parentNode;
   var table = row.parentNode;
   var rows = table.childNodes;

   //  For the highlighted row, restore every cell
   var cells = row.childNodes;
   for(var j = 0; j < cells.length; j++)
   {
      if(cells[j] && (cells[j].nodeName == 'TD'))
      {
         cells[j].style.backgroundColor = rowColor;
      }
   }
}


// Utility function to find the column index of a cell
function cgvGetColumnIndex(cell)
{
   var row = cell.parentNode;
   var cellsInRow = row.childNodes
   for(var i = 0; i < cellsInRow.length; i++)
   {
      if(cellsInRow[i] == cell)
      {
         return i;
      }
   }
}




///