var currentCell = "";
var selectedCell = "";

var currentSideCell = "";
var selectedSideCell = "";

var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 

var colorHighlight 	= 'yellow';
var colorNormal 	= 'white';
var colorSelected 	= 'orange';

var colorSideHighlight 	= '#666666';
var colorSideNormal 	= '#B6B6B6';
var colorSideSelected 	= '#B6B6B6';

var ndash = "-";

function getDash ()
{
	if (ie4 || ns6)
	{
		ndash="&ndash;";
	}
	return ndash;
}

function setHighlightColor (color)		{	colorHighlight = color;	}
function setNormalColor (color)			{	colorNormal = color;	}
function setSelectedColor (color)		{	colorSelected = color;	}
function highlightCell (cellId)			{	setCellColor (cellId, colorHighlight);	}
function unhighlightCell (cellId)		{ 	setCellColor (cellId, colorNormal);		}

function setSideHighlightColor (color)	{	colorSideHighlight = color;	}
function setSideNormalColor (color)		{	colorSideNormal = color;	}
function setSideSelectedColor (color)	{	colorSideSelected = color;	}
function highlightSideCell (cellId)		{	setCellColor (cellId, colorSideHighlight);	}
function unhighlightSideCell (cellId, isSelected)	{ if(isSelected) { setCellColor(cellId, colorSelected); } else {setCellColor (cellId, colorSideNormal); }		}

function setSelectedSideCell(cellId)
{
	if (cellId != selectedSideCell)
	{
		var oldSelectedSideCell = selectedSideCell;
		selectedSideCell = -1;
		unhighlightCell (oldSelectedSideCell);
		setCellColor (cellId, colorSideSelected);
		selectedSideCell = cellId;
	}
	
}

function selectSideCell(cellId, url)
{
	if (cellId != selectedSideCell)
	{
		setSelectedSideCell(cellId);
		window.location.href = url;
	}
}

function setSelectedCell(cellId)
{
	if (cellId != selectedCell)
	{
		var oldSelectedCell = selectedCell;
		selectedCell = -1;
		unhighlightCell (oldSelectedCell);		
		setCellColor (cellId, colorSelected);
		selectedCell = cellId;
	}
}

function selectCell(cellId, url)
{
	if (cellId != selectedCell)
	{
		setSelectedCell(cellId);
		window.location.href = url;
	}
}

function setCellColor (cellId, color)
{
	var cellColorCommand = "";		
	if ( (currentCell != cellId) && (selectedCell != cellId) && (currentSideCell != cellId) && (selectedSideCell != cellId))
	{
		if (ns4) // browser is NN
		{ 
			cellColorCommand = "window.document."+ cellId;
		}
		else //assume IE
		{
			var x = null;
			if (document.getElementById)
			{
				x = eval("document.getElementById('"+ cellId + "')");
			}
			if (x!=null)
			{
				cellColorCommand = "document.getElementById('"+ cellId + "')";
			}
			else
			{
				cellColorCommand = "";
			}
		}
		var x = eval(cellColorCommand);
		if (x != null)
		{
			eval(cellColorCommand + ".bgColor='" + color + "';");
		}		
	}
}

function openNASAWindow(url)
{
  if (url != "#")
  {
   var positionX = screen.width;
   var positionY = ((screen.height)/2);

    var sizeX = 720;
    var sizeY = 640;
    
    var strWindowFeatures = "";
    strWindowFeatures += 'menubar=yes,location=yes,toolbar=yes,directories=yes,scrollbars=yes,status=yes,resizable=yes,outerWidth='+720+',outerHeight='+640+',width='+720+'height='+640+',left='+80+',top='+60+'screenX='+80+',screenY='+60;
    winPopupWindow = window.open(url, "nasawindow", strWindowFeatures);
    winPopupWindow.focus();
  }
}


function toggleDisplay(elementId) 
{
	var isDisplayed = eval(document.getElementById(elementId).style.display == 'none');
	setDisplayed(elementId, isDisplayed);
}

function setDisplayed (elementId, isDisplayed)
{
	var styleVarId = elementId + 'DisplayStyle'
	var displayVar = document.getElementById(styleVarId);		
	var displayStyle = 'none';	
	if (isDisplayed) 
	{
		displayStyle= 'inline';
	}
	
	document.getElementById(elementId).style.display = displayStyle;
	if (displayVar) 
	{
		displayVar.value = displayStyle;
	}
}

function checkboxControlledToggleDisplay(elementId) 
{
	var box = document.getElementById(elementId)
	var isDisplayed = box.checked;
	setDisplay(elementId, isDisplayed);
}

function checkboxControlledToggleDisplay(elementId, styleVarId) 
{
	var styleVarId = elementId + 'DisplayStyle'
	var displayVar = document.getElementById(styleVarId);	
	
	box = document.getElementById(elementId);
	if (box.checked)
	{
		document.getElementById(elementId + 'Fields').style.display = 'inline';
		if (displayVar) 
		{
			displayVar.value = 'inline';
		}
	}	
	else 
	{
		document.getElementById(elementId + 'Fields').style.display = 'none';          
		if (displayVar) 
		{
			displayVar.value = 'none';
		}
	}
}

function stopRKey(evt) 
{
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}


function toggleField (field, isOn)
{
	field.disabled = !isOn;
	return true;
}


setHighlightColor ("#006699");
setNormalColor ("#666666");
setSelectedColor ("#006699");

setSideHighlightColor ("#666666");
setSideNormalColor ("#B7B6B6");
setSideSelectedColor ("#006699");

function showComments(btn, parameters, groupId)
{
	openWindow('showComments.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}
function showFoundProjects(btn)
{
	openWindow('showFoundProjects.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}
function showApplication(btn, parameters, groupId)
{
	openWindow('showApplication.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}
function showMissing(btn, parameters,groupId)
{
	openWindow('showMissing.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}
function showAward(btn, parameters, groupId)
{
	openWindow('showAwards.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}	
function showFunding(btn, parameters, groupId)
{
	openWindow('../showFunding.jsp?' + parameters + '&groupId=' + groupId + '&applicantId=' + btn.name);
}	
function showPosition(id) 
{
	openWindow ('../showPosition.jsp?positionId=' + id);
}
function showProject(id) 
{
	openWindow ('../showProject.jsp?id=' + id);
}
function showProgram(id) 
{
	openWindow('../showProgram.jsp?groupId=' + id);
}
function showGroupEndorsements(id) 
{
	openWindow('showGroupEndorsements.jsp?groupId=' + id);
}


function openWindow(url) 
{
	popupWin = window.open(url,'mywindow',
	'width=780,height=1000,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes'
	);
}


