//<script>

/*
 * Sets the focus on the first element that should "reasonably" receive it
 */
function Fev_FocusOnFirstFocusableFormElement()
{
	for (i = 0; i < document.forms.length; i++)
	{
		if (Fev_FocusOnDefaultElement(document.forms[i])) return;
		//if (Fev_FocusOnFirstFocusableElement(document.forms[i])) return;
	}
}

/*
 * Sets the focus on the first element that is able to receive it
 */
function Fev_FocusOnFirstFocusableElement(objForm)
{
	if (objForm && (objForm != null))
	{
		for (i = 0; i < objForm.length; i++)
		{
			var objElement = objForm.elements[i];
			if (Fev_IsFocusableElement(objElement))
			{
				objElement.focus();
				return true;
			}
		}
	}
	return false;
}

/*
 * Sets the focus on the first element that should "reasonably" receive it
 */
function Fev_FocusOnDefaultElement(objForm)
{
	if (objForm && (objForm != null))
	{
		for (i = 0; i < objForm.length; i++)
		{
			var objElement = objForm.elements[i];
			if (Fev_IsFocusableElement(objElement))
			{
				var strType = Fev_GetElementType(objElement);
				//we know (strType != null) because it was checked within Fev_IsFocusableElement().
				if (strType.toLowerCase().indexOf("select") == 0)
				{
					//NOTE: SELECT tags are ignored (they interfere with mousewheel scrolling when they have focus)
				}
				else
				{
					objElement.focus();
					return true;
				}
			}
		}
	}
	return false;
}

/*
 * returns true if the element can receive focus
 */
function Fev_IsFocusableElement(objElement)
{
	if (objElement && 
		(objElement != null) && 
		Fev_IsElementEnabled(objElement) && 
		Fev_IsElementVisible(objElement) && 
		Fev_IsElementEditable(objElement) )
	{
		var strType = Fev_GetElementType(objElement);
		if (strType != null)
		{
			if ((strType == "text") || (strType == "textarea") || (strType.toString().charAt(0) == "s"))
			{
				return true;
			}
		}
	}
	return false;
}

/*
 * returns true if the element is enabled
 */
function Fev_IsElementEnabled(objElement)
{
	if (objElement && (objElement != null))
	{
		if (!(objElement.disabled == false))
		{
			return false;
		}
		return true;
	}
	return false;
}

/*
 * returns true if the element's content is editable by the user
 */
function Fev_IsElementEditable(objElement)
{
	if (objElement && (objElement != null))
	{
		if (objElement.readOnly)
		{
			return false;
		}
		if ((!objElement.isContentEditable) && (typeof(objElement.isContentEditable) != 'undefined'))
		{
			return false;
		}
		return true;
	}
	return false;
}

/*
 * returns true if the element is visible to the user
 */
function Fev_IsElementVisible(objElement)
{
	if (objElement && (objElement != null))
	{
		if (objElement.style && (objElement.style != null))
		{
			if (objElement.style.display && (objElement.style.display.toLowerCase() == 'none'))
			{
				return false;
			}
			if (objElement.style.visibility && (objElement.style.visibility.toLowerCase() == 'hidden'))
			{
				return false;
			}
			if (objElement.style.visibility && (objElement.style.visibility.toLowerCase() == 'inherit'))
			{
				var objParentElement = Fev_GetParentElement(objElement);
				if (objParentElement && (objParentElement != null) && (!Fev_IsElementVisible(objParentElement)))
				{
					return false;
				}
			}
		}
		return true;
	}
	return false;
}

/*
 * returns true if the element responds directly to Enter key presses
 * return true for:
 *     Textarea, Select/Dropdown, Input Buttons (Submit/Button/Image/Reset),
 *     A tags
 * return false for everything else, including:
 *     Input type=[Radio/Checkbox/Text/Password/File]
 *     IMG tags
 */
function Fev_IsElementUsesEnterKey(objElement)
{
	if (objElement && (objElement != null))
	{
		var strType = Fev_GetElementType(objElement);
		if (strType != null) strType = strType.toLowerCase();
        switch (strType)
        {
            case "textarea":
            case "select":
            case "submit":
            case "button":
            case "image":
            case "reset":
                return true;
                break;
            case "radio":
            case "checkbox":
            case "text":
            case "password":
            case "file":
                return false;
                break;
            default: 
                break;
        }

		var strTagName = Fev_GetElementTagName(objElement);
		if (strTagName != null) strTagName = strTagName.toLowerCase();
		switch (strTagName)
		{
			case "textarea":
			case "select":
			case "a":
				return true;
				break;
			case "img":
			case "input":
			default:
				break;
		}
	}
	return false;
}

function Fev_GetParentElement(objElement)
{
	if (objElement && (objElement != null))
	{
		if (objElement.parentNode && (objElement.parentNode != null))
		{
			return objElement.parentNode;
		}
		if (objElement.parentElement && (objElement.parentElement != null))
		{
			return objElement.parentElement;
		}
	}
	return null;
}

function Fev_GetElementType(objElement)
{
	if (objElement && (objElement != null))
	{
		if (objElement.type)
		{
			return objElement.type;
		}
	}
	return null;
}

function Fev_GetElementTagName(objElement)
{
	if (objElement && (objElement != null))
	{
		if (objElement.tagName)
		{
			return objElement.tagName;
		}
	}
	return null;
}

function Fev_GetEventSourceElement(objEvent)
{
	if (objEvent && (objEvent != null))
	{
		if (objEvent.srcElement)
		{
			return objEvent.srcElement;
		}
	}
	return null;
}

function Fev_IsEnterKeyPressed(bIgnoreTextAreaEvents)
{
	if (window.event)
	{
		var e = window.event;
		var bIsEnterKeyPress = ((e.keyCode == 13) && (e.type == 'keypress'));
		if (bIsEnterKeyPress)
		{
			if (bIgnoreTextAreaEvents && (bIgnoreTextAreaEvents == true))
			{
				var strType = Fev_GetElementType(Fev_GetEventSourceElement(e));
				if (strType != null) strType = strType.toLowerCase();
				if (strType == "textarea")
				{
					return false;
				}
			}
			return true;
		}
	}
	return false;
}

function Fev_IsFormSubmitKeyPress()
{
	if (window.event)
	{
		var e = window.event;
		var bIsEnterKeyPress = ((e.keyCode == 13) && (e.type == 'keypress'));
		if (bIsEnterKeyPress)
		{
			var eventSrc = Fev_GetEventSourceElement(e);
			if (!Fev_IsElementUsesEnterKey(eventSrc))
			{
				return true;
			}
		}
	}
	return false;
}

function Fev_ClickButton(buttonId)
{
	var button = document.all(buttonId);
	if (button == null) button = document.all(buttonId + '_Button');
	if (button == null) button = document.all(buttonId + '__Button');
	if (button && (typeof(button.click) == 'object'))
	{
		button.click();
		return true;
	}
	return false;
}

//Sets the value or selection of the form element, independent of the element's type.
function Fev_SetFormControlValue(objElement, strValue)
{
	var strTagName = Fev_GetElementTagName(objElement);
	if (strTagName != null) strTagName = strTagName.toLowerCase();
	switch (strTagName)
	{
		case "textarea":
			objElement.value = strValue;
			return true;
			break;
		case "select":
			var currentIndex = objElement.selectedIndex;
			objElement.value = strValue;
			if (objElement.selectedIndex < 0)
			{
				objElement.selectedIndex = currentIndex;
				return false;
			}
			return true;
			break;
		case "input":
			switch (objElement.type.toLowerCase())
			{
				case "text":
				case "password":
				case "hidden":
					objElement.value = strValue;
					return true;
					break;
				case "file":
					//can't programatically set the value of file controls
					return false;
				case "checkbox":
					if ((strValue == null) || (strValue == ''))
					{
						objElement.checked = false;
						return true;
						break;
					}
					else if (strValue == objElement.value)
					{
						objElement.checked = true;
						return true;
						break;
					}
					else
					{
						//the specified value matches niether the checked nor unchecked state
						//objElement.checked = true;
						//objElement.value = strValue;
						//return true;
						break;
					}
				case "radio":
					if (strValue == null)
					{
						//uncheck all radio buttons in the group
						objElement.checked = true;
						objElement.checked = false;
						return true;
						break;
					}
					else if (strValue == objElement.value)
					{
						objElement.checked = true;
						return true;
						break;
					}
					else
					{
						var f = objElement.form;
						var allRadioButtonsInGroup = f.elements(objElement.name)
						for (i = 0; i < allRadioButtonsInGroup.length; i++)
						{
							var rb = allRadioButtonsInGroup[i];
							if (strValue == rb.value)
							{
								rb.checked = true;
								return true;
							}
						}
						//the specified value matches the checked state of none of the radio buttons
						//objElement.checked = true;
						//objElement.checked = false;
						//return true;
						break;
					}
				default:
					break;
			}
		default:
			break;
	}
	return false;
}

//Inserts the value into a list element, independent of the element's type.
function Fev_ReplaceLastListControlOption(objListElement, strValue, strText)
{
	var strTagName = Fev_GetElementTagName(objListElement);
	if (strTagName != null) strTagName = strTagName.toLowerCase();
	switch (strTagName)
	{
		case "select":
			var objOption = objListElement.options[objListElement.options.length-1];
			objOption.value = strValue;
			objOption.text = strText;
			//objOption.innerText = strText;
			return true;
			break;
		default:
			break;
	}
	return false;
}

function Fev_HandleFormSubmitKeyPress(buttonId)
{
	//if (window.event && (window.event.returnValue == false))
	//	return false;

	if (Fev_IsFormSubmitKeyPress()) //if (Fev_IsEnterKeyPressed(true))
	{
		if (Fev_ClickButton(buttonId))
		{
			if (window.event)
			{
				//window.event.returnValue = false;
				window.event.cancelBubble = true;
			}
			return true;
		}
	}
	return false;
}


/**************************************************************************************
 *  Function    : toggleExpandCollapse()                                              *
 *  Description : Toggles the expanding and collapsing of the content region of       *
 *                    record and table panels; also swaps the "expand/collapse" icon, *
 *                    and "total records" count based upon the current                *
 *                    expand/collapse state.                                          *
 *  Parameters  : anchorNode, <a> tag node which is clicked upon to initiate toggling *
 *                    of expand/collapse                                              *
 *  Assumptions : The region which is expanded/collapsed is the table (with HTML      *
 *                    id, "CollapsibleRegion") within the sibling (row) of the table  *
 *                    row which contains the anchorNode.                              *
 *  Author      : Samson Wong                                                         *
 **************************************************************************************/
function toggleExpandCollapse(anchorNode)
{
	var collapsibleNode;
			
	// find the node to be expanded/collapsed based on browser type
	if (navigator.appName == "Netscape")
	{
		collapsibleNode = anchorNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes.item(2).childNodes.item(1).childNodes.item(1);
	}
	else // navigator.appName == "Microsoft Internet Explorer"
	{
		collapsibleNode = anchorNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes.item(1).childNodes.item(0).childNodes.item(0);
	}
	
	
    // make sure this node is a collapsible region before collapsing
    if ((collapsibleNode.id == "CollapsibleRegion") && (collapsibleNode.tagName == "TABLE"))
    {
		collapsibleNode.style.display = (collapsibleNode.style.display == "block") ? "none" : "block";
	}
	
	// traverse to image node (note that for both Netscape and IE, this is the first child of anchor tag)
	var imageNode = anchorNode.childNodes.item(0);

	// make sure this node contains the expand/collapse image before swapping icon
	if ((imageNode.id == "ExpandCollapseIcon") && (imageNode.tagName == "IMG"))
	{
		// show appropriate icon for current expand/collapse state
		imageNode.src = (collapsibleNode.style.display == "block") ? "../Images/DialogHeaderIconCollapse.gif" : "../Images/DialogHeaderIconExpand.gif";
		
		// show appropriate tool tip for current expand/collapse state (for section 508 compliance)
		imageNode.alt = (collapsibleNode.style.display == "block") ? "Collapse panel" : "Expand panel";
		imageNode.title = (collapsibleNode.style.display == "block") ? "Collapse panel" : "Expand panel";
	}
	
	
	var totalRecordsNode;
	
	// traverse to the total records node
	if (navigator.appName == "Netscape")
	{
		totalRecordsNode = anchorNode.parentNode.parentNode.childNodes.item(9).childNodes.item(1);
	}
	else // navigator.appName == "Microsoft Internet Explorer"
	{
		totalRecordsNode = anchorNode.parentNode.parentNode.childNodes.item(4).childNodes.item(0);
	}
	
	// make sure this node contains the total records count before toggling
    if ((totalRecordsNode.id == "CollapsibleRegionTotalRecords") && (totalRecordsNode.tagName == "TABLE"))
    {
    	// show total records count if panel in collapsed state
		totalRecordsNode.style.display = (totalRecordsNode.style.display == "block") ? "none" : "block";
	}	
	
	return false;
}


/**************************************************************************************
 *  Description : Global variables used by the following functions:                   * 
 *                    moveToNextTableRow()                                            *
 *                    moveToPreviousTableRow()                                        *
 *                    moveToThisTableRow()                                            *
 *                    updateCurrentTableAndIndex()                                    *
 *                    highlightTableRow()                                             *
 *                    clickEditButtonOfTableRowInFocus()                              *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
var justDoIt = true;
var currentTable = null;
var currentRowIndex = 0;

/**************************************************************************************
 *  Function    : captureUpDownKey()                                                  *
 *  Description : Captures an "up/down arrow" and "enter" keyboard event, and calls   *
 *                    the respective function to process the event.                   *
 *  Parameters  : pTableInFocus, html table receiving the keyboard event              *
 *                event, browser-generated event object                               *
 *  Assumptions : Only table panels will call this function.                          *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function captureUpDownKey(pTableInFocus, event) {

	// capture current scroll position for "maintain position in tables" feature 
	setCurrentBrowserCoordinates();
	
	if (justDoIt == true) {
	
		// for IE...
		if (event.keyCode) {
			// if key down...
			if (event.keyCode == 40) {
				event.returnValue = false;
				event.cancel = true;
				moveToNextTableRow(pTableInFocus);
			}
			// if key up...
			else if (event.keyCode == 38) {
				event.returnValue = false;
				event.cancel = true;
				moveToPreviousTableRow(pTableInFocus);
			}
			// if enter key...
			else if (event.keyCode == 13) {
			    if (clickEditButtonOfTableRowInFocus() == true) {
					event.returnValue = false;
					event.cancel = true;
			    }
			    /* else let event bubble up to "enter key capture" code for the above column filter button */
			}
			
		}
		// if Netscape/Firefox...
		else if (event.which) {
			// if key down...
			if (event.which == 40) {
				event.returnValue = false;
				event.cancel = true;
				moveToNextTableRow(pTableInFocus);
			}
			// if key up...
			else if (event.which == 38) {
				event.returnValue = false;
				event.cancel = true;
				moveToPreviousTableRow(pTableInFocus);
			}  
			// if enter key...
			else if (event.which == 13) {
			    if (clickEditButtonOfTableRowInFocus() == true) {
					event.returnValue = false;
					event.cancel = true;
			    }
			    /* else let event bubble up to "enter key capture" code for the above column filter button */
			}
		}
	}
}

/**************************************************************************************
 *  Function    : captureEnterKeyInScrollingTable()                                   *
 *  Description : Captures an "enter" keyboard event, and calls the respective        *
 *                    function to process the event.                                  *
 *  Parameters  : pTableInFocus, html table receiving the keyboard event              *
 *                event, browser-generated event object                               *
 *  Assumptions : Only scrolling table panels will call this function.                *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function captureEnterKeyInScrollingTable(pTableInFocus, event) {

	// capture current scroll position for "maintain position in tables" feature 
	setCurrentBrowserCoordinates();
	
	if (justDoIt == true) {
			
		// for IE...
		if (event.keyCode) {
			// if enter key...
			if (event.keyCode == 13) {
			    if (clickEditButtonOfTableRowInFocus() == true) {
					event.returnValue = false;
					event.cancel = true;
			    }
			    /* else let event bubble up to "enter key capture" code for the above column filter button */
			}
			// if key down...
			else if (event.keyCode == 40) {
				event.returnValue = false;
				event.cancel = true;
				// ignore because up/down keypress functionality is not supported in scrolling tables
			}
			// if key up...
			else if (event.keyCode == 38) {
				event.returnValue = false;
				event.cancel = true;
				// ignore because up/down keypress functionality is not supported in scrolling tables
			}
		}
		// if Netscape/Firefox...
		else if (event.which) {
			// if enter key...
			if (event.which == 13) {
			    if (clickEditButtonOfTableRowInFocus() == true) {
					event.returnValue = false;
					event.cancel = true;
			    }
			    /* else let event bubble up to "enter key capture" code for the above column filter button */
			}
			// if key down...
			else if (event.which == 40) {
				event.returnValue = false;
				event.cancel = true;
				// ignore because up/down keypress functionality is not supported in scrolling tables
			}
			// if key up...
			else if (event.which == 38) {
				event.returnValue = false;
				event.cancel = true;
				// ignore because up/down keypress functionality is not supported in scrolling tables
			}
		}
	}
}

/**************************************************************************************
 *  Function    : moveToNextTableRow()                                                *
 *  Description : Upon "down arrow" keypress, unhighlights the current table row, and *
 *                    highlights the next table row.                                  *
 *  Parameters  : pTableInFocus, html table receiving the "down arrow" keyboard event *
 *  Assumptions : None.                                                               *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function moveToNextTableRow(pTableInFocus) {
    var tableInFocus;
    var tableRows;
    var maxRowIndex;
    var tableCells;
 
	if (justDoIt == true) {  
	 
		if (pTableInFocus != null) {
		
			// if focus is still within same table...
			if (currentTable == pTableInFocus) {
					
				// retrieve all rows of the current table
				tableRows = currentTable.getElementsByTagName("tr");
				
				if (tableRows != null) {
				    
				    // determine the number of rows (including "header row") in this table
				    maxRowIndex = tableRows.length;
				
					// if current row is not the last row of this table...
				    if ((currentRowIndex >= 0) && (currentRowIndex < maxRowIndex-1)) {
				    
				    	if (tableRowHighlightable(tableRows.item(currentRowIndex+1)) == true) {
	
					    	// unhighlight the current row
							unhighlightTableRow(tableRows.item(currentRowIndex));
						
							// make previous row of this table the current row
							currentRowIndex++;
		
							// highlight the (new) current row
							highlightTableRow(tableRows.item(currentRowIndex));
						}       
				    }
				}
			}
			else {
				
				// retrieve all rows of the new table in focus
				tableRows = pTableInFocus.getElementsByTagName("tr");
				
				// determine the number of rows (including "header row") in this new table in focus
				maxRowIndex = tableRows.length;
				
				// make this new table in focus the current table
				currentTable = pTableInFocus;

				moveToNextTableRow(currentTable);
			}
		}
	}
}

/**************************************************************************************
 *  Function    : moveToPreviousTableRow()                                            *
 *  Description : Upon "up arrow" keypress, unhighlights the current table row, and   *
 *                    highlights the previous table row.                              *
 *  Parameters  : pTableInFocus, html table receiving the "down arrow" keyboard event *
 *  Assumptions : None.                                                               *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function moveToPreviousTableRow(pTableInFocus) {
    var tableInFocus;
    var tableRows;
    var maxRowIndex;
    var tableCells;

	if (justDoIt == true) {
    
		if (pTableInFocus != null) {
		
			// if focus is still within same table...
			if (currentTable == pTableInFocus) {
			
				// retrieve all rows of the current table
				tableRows = currentTable.getElementsByTagName("tr");
				
				if (tableRows != null) {
				    
				    // determine the number of rows (including "header row") in this table
				    maxRowIndex = tableRows.length;
				     	
					// if current row is not the first row of this table...
				    if ((currentRowIndex > 1) && (currentRowIndex < maxRowIndex)) {
				    
				    	if (tableRowHighlightable(tableRows.item(currentRowIndex-1)) == true) {
	
					    	// unhighlight the current row
							unhighlightTableRow(tableRows.item(currentRowIndex));
						
							// make previous row of this table the current row
							currentRowIndex--;
		
							// highlight the (new) current row
							highlightTableRow(tableRows.item(currentRowIndex));
						}       
				    }
				}
			}
			else {
				
				// retrieve all rows of the new table in focus
				tableRows = pTableInFocus.getElementsByTagName("tr");
				
				// determine the number of rows (including "header row") in this new table in focus
				maxRowIndex = tableRows.length;
				
				// make this new table in focus the current table
				currentTable = pTableInFocus;
				
				moveToPreviousTableRow(currentTable);
			}
		}
	}
}

/**************************************************************************************
 *  Function    : moveToThisTableRow()                                                *
 *  Description : Upon "radio button select", unhighlights the current table row, and *
 *                    highlights the newly selected table row.                        *
 *  Parameters  : pTableCell, "radio button" table cell selected                      *
 *  Assumptions : Only "radio button" table cells will call this function.            *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function moveToThisTableRow(pTableCell) {
	var tableRow;

	// capture current scroll position for "maintain position in tables" feature 
	setCurrentBrowserCoordinates();
	
	if (justDoIt == true) {

		if (pTableCell != null) {

			tableRow = pTableCell.parentNode;
			
			if (tableRowHighlightable(tableRow) == true) {
			
				tableRow.getElementsByTagName("input").item(2).focus();
				tableRow.parentNode.getElementsByTagName("input").item(2).checked = true;
		
				// if current row highlighted...
				if (currentTable != null) {
				
					// retrieve all rows of the current table
					tableRows = currentTable.getElementsByTagName("tr");
					
					unhighlightTableRow(tableRows.item(currentRowIndex));
				}
		
				// determine current table and index resulting from focus change
				updateCurrentTableAndIndex(tableRow);
				
				// highlight (new) current table row
				highlightTableRow(tableRow);
			}
		}
	}
}

/**************************************************************************************
 *  Function    : updateCurrentTableAndIndex()                                        *
 *  Description : Updates the global variables, currentTable and currentRowIndex,     *
 *                    indicating the new table and row in focus.                      *
 *  Parameters  : pTableRow, new table row in focus                                   *
 *  Assumptions : None.                                                               *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function updateCurrentTableAndIndex(pTableRow) {
	var tableRows;
	var maxTableIndex;

	if (justDoIt == true) {
	
		currentTable = pTableRow.parentNode;
		currentRowIndex = 0;

		tableRows = currentTable.getElementsByTagName("tr");
		
		if (tableRows != null) {
			maxTableIndex = tableRows.length;
			
			for (var i=1; i<maxTableIndex; i++) {
				if (tableRows.item(i) == pTableRow) {
					currentRowIndex = i;
					break;
				}
			}
		}
		
		// alert("updateCurrentTableAndIndex(currentRowIndex=" + currentRowIndex + ")"); 
	}
}

/**************************************************************************************
 *  Function    : unhighlightTableRow()                                               *
 *  Description : For the specified table row, deselects the "radio button", and      *
 *                    unhighlights its table cells.                                   *
 *  Parameters  : pTableRow, table row to be unhighlighted                            *
 *  Assumptions : The second table cell in row contains "radio button"; all           *
 *                    subsequent cells are data cells.                                *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function unhighlightTableRow(pTableRow) {

	var iconCellContents = null;

	if (justDoIt == true) {

		if (pTableRow != null) {

			iconCellContents = pTableRow.getElementsByTagName("input");
			
			if ((iconCellContents != null) && (iconCellContents.length >= 3) && (iconCellContents.item(2) != null)) {
				
			    iconCellContents.item(2).checked = false;
			        
				// unhighlight row
				tableCells = pTableRow.getElementsByTagName("td");
				for (var i=0; i<tableCells.length; i++) {
					if (i<=2) {
					 	tableCells.item(i).className = "icon_cell";
				 	}
				 	else {
					 	tableCells.item(i).className = "table_cell";
				 	}
				}
				// alert("unhighlightTableRow(currentRowIndex=" + currentRowIndex + ")");
			}
		}
	}
}

/**************************************************************************************
 *  Function    : highlightTableRow()                                                 *
 *  Description : For the specified table row, selects the "radio button", and        *
 *                    highlights its table cells.                                     *
 *  Parameters  : pTableRow, table row to be highlighted                              *
 *  Assumptions : The second table cell in row contains "radio button"; all           *
 *                    subsequent cells are data cells.                                *
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function highlightTableRow(pTableRow) {

	var iconCellContents = null;
	
	if (justDoIt == true) {

		if (pTableRow != null) {

			iconCellContents = pTableRow.getElementsByTagName("input");
			
			if ((iconCellContents != null) && (iconCellContents.length >= 3) && (iconCellContents.item(2) != null)) {
				
				iconCellContents.item(2).focus();
			    iconCellContents.item(2).checked = true;
			            
				// highlight row
				tableCells = pTableRow.getElementsByTagName("td");
				for (var i=0; i<tableCells.length; i++) {
					if (i<=2) {
					 	tableCells.item(i).className = "icon_cell_highlighted";
				 	}
				 	else {
					 	tableCells.item(i).className = "table_cell_highlighted";
				 	}
				}
				// alert("highlightTableRow(currentRowIndex=" + currentRowIndex + ")");
			}
		}
	}
}

/**************************************************************************************
 *  Function    : tableRowHighlightable()                                             *
 *  Description : Returns whether the table row contains icon cells.                  *
 *  Parameters  : None.                                                               *
 *  Assumptions : None.                                                               *                 
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function tableRowHighlightable(pTableRow) {

	var rTableRowHighlightable = false;
	var iconCellContents = null;
	var headerCellContents = null;
	var tableRows = null;
	
	// select table row's radio button
	iconCellContents = pTableRow.getElementsByTagName("input");
	if ((iconCellContents != null) && (iconCellContents.length >= 3) && (iconCellContents.item(2) != null)) {

		// make sure there is an icon cell in this row
		if (iconCellContents.item(2).parentNode.className == "icon_cell") {
		
			rTableRowHighlightable = true;
		}
	}
	/*
	else {
		
		headerCellContents = pTableRow.getElementsByTagname("th");
		if (headerCellContents != null) {

			// if current row highlighted...
			if (currentTable != null) {
			
				// retrieve all rows of the current table
				tableRows = currentTable.getElementsByTagName("tr");
				
				unhighlightTableRow(tableRows.item(currentRowIndex));
			}
	
			// determine current table and index resulting from focus change
			updateCurrentTableAndIndex(pTableRow);
		}
	}
	*/
				
	return(rTableRowHighlightable);
}

/**************************************************************************************
 *  Function    : clickEditButtonOfTableRowInFocus()                                  *
 *  Description : Invokes the edit record page of the selected record (in focus table *
 *                    row) by programmatically clicking the record's edit button.     *
 *  Parameters  : None.                                                               *
 *  Assumptions : The edit button is contained in the first cell of the table row in  *
 *                    focus.                                                          *                 
 *  ISD Feature : "Table row selection via up/down arrow keypress"                    *
 *  Authors     : Samson Wong & Cocosoft B.V.                                         *
 **************************************************************************************/
function clickEditButtonOfTableRowInFocus() {
	var tableRows = null;
	var tableRowInFocus = null;
	var iconCellContents = null;
	var rTableRowClickable = false;

	if (justDoIt == true) {
	
		if (currentTable != null) {
		
			tableRows = currentTable.getElementsByTagName("tr");
			if (tableRows != null) {
			
				tableRowInFocus = tableRows.item(currentRowIndex); 
				if (tableRowInFocus != null) {
				
					iconCellContents = tableRowInFocus.getElementsByTagName("input");
					if (iconCellContents != null) {
						iconCellContents.item(0).click();
						
						rTableRowClickable = true;
					}	
				}	
			}
		}
	}
	
	return(rTableRowClickable);
}

/**************************************************************************************
 *  Function    : setCurrentBrowserCoordinates()                                      *
 *  Description : Records current browser focus location based upon user input        *
 *                    (scroll, click, or keypress).                                   *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
 function setCurrentBrowserCoordinates() {
    var scrollX, scrollY;
    
    if (justDoIt == true) {
		var pageLeftCoordinate = document.getElementById("pageLeftCoordinate");
		var pageTopCoordinate = document.getElementById("pageTopCoordinate");

		// do not scroll in pre-v3.2.1 apps (which do not contain the hidden scroll coordinates fields)			
		if (!pageLeftCoordinate || !pageTopCoordinate) return;
    
		if (document.all)
		{
			if (!document.documentElement.scrollLeft)
				scrollX = document.body.scrollLeft;
			else
				scrollX = document.documentElement.scrollLeft;
		 
			if (!document.documentElement.scrollTop)
				scrollY = document.body.scrollTop;
			else
				scrollY = document.documentElement.scrollTop;
		}
		else
		{
			scrollX = window.pageXOffset;
			scrollY = window.pageYOffset;
		}
	    	
	    // alert("setCurrentBrowserCoordinates(x=" + scrollX + ",y=" + scrollY + ")");
		pageLeftCoordinate.value = scrollX;
		pageTopCoordinate.value = scrollY;
    }
}
  
/**************************************************************************************
 *  Function    : goToCurrentBrowserCoordinates()                                     *
 *  Description : Moves to the browser coordinates previously saved by                *
 *                    setCurrentBrowserCoordinates().                                 *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
 function goToCurrentBrowserCoordinates() {
	if (justDoIt == true) {
		var pageLeftCoordinate = document.getElementById("pageLeftCoordinate");
		var pageTopCoordinate = document.getElementById("pageTopCoordinate");

		// do not scroll in pre-v3.2.1 apps (which do not contain the hidden scroll coordinates fields)	
		if (!pageLeftCoordinate || !pageTopCoordinate) return;
		
		// do not scroll if not a doPostBack() reload of page
		if ((pageLeftCoordinate.value == "") && (pageTopCoordinate.value == "")) return;

		var scrollX = pageLeftCoordinate.value;
		var scrollY = pageTopCoordinate.value;
		// alert("goToCurrentBrowserCoordinates(x=" + scrollX + ",y=" + scrollY + ")");
		window.scrollTo(scrollX, scrollY);
	}
 }

/**************************************************************************************
 *  Description : Event handlers (scroll, click, and keypress) active for all pages.  *
 *  Parameters  : None.                                                               *
 *  ISD Feature : "Maintain position in tables"                                       *
 *  Authors     : Akesh Gupta, Light Speed Solutions                                  *
 **************************************************************************************/
  window.onload = goToCurrentBrowserCoordinates;
  window.onscroll = setCurrentBrowserCoordinates;
  window.onclick = setCurrentBrowserCoordinates;
  window.onkeypress = setCurrentBrowserCoordinates;

