/* Blue River Digital API - Data Table **********************************
 *	
 *	This API contains all the data table Javascript functions
 *	
 *********************************************************************/
 
 	
/* Check Line Data **********************************************************
*
*	TAKES:		dataValueId, dataType
*	RETURNS:	NOTHING
*	NOTES:		On FALSE, sets the tableColLeft and tableColRight to the Error
*				class tableColError.
*
**************************************************************************/

	function checkLineData(dataValueId, dataType, required)
	{
		var dataElement = getElement("tableInput" + dataValueId)
		var dataValue = dataElement.value
		
		dataValue = dataValue.replace(/\n/g, "");
		
		var checkResult = dataIsValid(dataValue, dataType);
		
		if (!(checkResult == true))
		{
			dataElement.className = "tableColError";	
			getElement("tableRowErrorMessage" + dataValueId).innerHTML = "Error: " + checkResult; // Error Message
			showElement("tableRowErrorMessage" + dataValueId);
		}
		else
		{
			dataElement.className = "";	
			hideElement("tableRowErrorMessage" + dataValueId);
		}
		
	}
	
/* Paint Rows **********************************************************
*
*	TAKES:		Element List, Row Class Name, Row Alt. Class
*	RETURNS:	NOTHING
*	NOTES:		Paints the rows in alternating class styles
*
**************************************************************************/

	function paintRowElements(elementList, rowClass, rowAltClass)
	{
		if (elementList.length > 0)
		{
			var currentClass = rowClass;
			
			var iterateAction = function(element, index)
			{
				element.className = currentClass;
				
				if (currentClass == rowClass)
				{
					currentClass = rowAltClass;
				}
				else
				{
					currentClass = rowClass;
				}
			}
			
			iterateElementList(elementList, iterateAction);
		}
	}
	
/* Repaint Rows **********************************************************
*
*	TAKES:		HTML Tag Type, Row Color, Row Color Alt 
*	RETURNS:	NOTHING
*	NOTES:		Repaints the data rows
*
**************************************************************************/

	function repaintRows(tagType, rowColor, rowAltColor)
	{
		var spanArray = document.getElementsByTagName(tagType);
		var regExp		= /^row/; 			// Checks for Integers
		var currentRowColor = rowColor;
		var temp = "";
		
		for(ctr=0; ctr < spanArray.length; ctr++)
		{
			
			//temp = temp + spanArray[ctr].id + ": " + (spanArray[ctr].id).search(regExp) + ", display: " + spanArray[ctr].style.display + "\n";
			
			if (((spanArray[ctr].id).search(regExp) != -1) & (spanArray[ctr].style.display != "none"))
			{
				getElement(spanArray[ctr].id).style.backgroundColor = currentRowColor;
				
				if (currentRowColor == rowColor)
				{
					currentRowColor = rowAltColor;
				}
				else
				{
					currentRowColor = rowColor;
				}
			}
		}
		
		//alert(temp);
		
	}
