﻿////////////////////////////////////////////////////////////////////////////
// Global support objects
////////////////////////////////////////////////////////////////////////////
var _rowComment = "";
var _gridContainer = null;
var _tempSelectedRow = null;
var _Y = 0;
 
////////////////////////////////////////////////////////////////////////////
// Application scripting methods
////////////////////////////////////////////////////////////////////////////

/* Sets the data change status of the current screen */
function setPageDirty()
{
	document.getElementById("ctl00__isDirty").value = "true";
}

/* Gets the current data change status of the current screen */
function getDirtyStatus()
{
	if (document.getElementById("ctl00__isDirty").value == "true")
	{
		if (confirm("The contents of the page have changed. Continue without saving?") == true)
		{
			document.getElementById("ctl00__isDirty").value == "false"
			return true;
		}
		else
		{
			document.getElementById("ctl00__isDirty").value == "true"
			return false;
		}
	}
}

/* Handles grid row styling */
function setSelectedRow(rowControl)
{
	// Allocate objects
	var rowContainer = document.getElementById(rowControl.id).parentNode;
	var childCount = rowContainer.childNodes.length;
	
	// Set global grid container
	_gridContainer = rowContainer;
	
	// Implement row styling
	for (var i = 0; i < childCount; i++)
	{
		// Set row style
		rowContainer.childNodes[i].className = "gridRow";		
	}
	
	for (var i = 0; i < childCount; i++)
	{
		if (rowContainer.childNodes[i].id == rowControl.id)
		{
			// Set row style
			rowContainer.childNodes[i].className = "selectedGridRow";
			document.getElementById("ctl00__selectedGridRowID").value = rowControl.id;
		}
	}
	if (rowContainer.id != null)
	{
	   setTimeout("setScroll(" + rowContainer.id + ")",800);
	}
	rowContainer.focus();
}

function setScroll(divTag)
{
  var id = divTag.id;
  document.getElementById(id).scrollTop = _Y;
}
/* Handles row selection by arrow keys */
function setArrowSelectedRow()
{
	// Allocate objects
	var childCount = _gridContainer.childNodes.length;
	
	// Implement row styling
	for (var i = 0; i < childCount; i++)
	{
		if (_gridContainer.childNodes[i].className == "selectedGridRow")
		{
			if (event.keyCode == 40)
			{
				if (!(_gridContainer.childNodes[i + 1] == null))
				{
					_gridContainer.childNodes[i + 1].click();
					break;
				}
			}
			
			if (event.keyCode == 38)
			{
				if (!(_gridContainer.childNodes[i - 1] == null))
				{
					_gridContainer.childNodes[i - 1].click();
					break;
				}
			}
		}
	}
}

/* Handles the display of row descriptions */
function setComment()
{
	var infoElement = document.getElementById("_additionalInfo");

	if( infoElement.innerText != null )
		infoElement.innerText = _rowComment;    // Works on IE 6 and IE 7
	else
		infoElement.textContent = _rowComment;  // Works on Firefox

	_rowComment = "";
}

/* Handles site menu display options */
function ToggleMenuVisibility()
{
	if (document.getElementById('_menuState').value == 'none')
	{
		document.getElementById('_menuState').value = '';
	}
	else if (document.getElementById('_menuState').value == '')
	{
		document.getElementById('_menuState').value = 'none';
	}
	
	// Set display style
//	document.getElementById('_siteMenu').style.left = document.getElementById('_toggleMenu').style.left;
//	document.getElementById('_siteMenu').style.top = document.getElementById('_toggleMenu').style.top + 122;
	//document.getElementById('_siteMenu').style.display = document.getElementById('_menuState').value;
}

function SetMenuState()
{
	if (document.getElementById('_siteMenu').style.display=='')
	{
		document.getElementById('_menuState').value='none'; 
		document.getElementById('_toggleImage').src='Content/Graphics/ToggleShow.gif';
		document.getElementById('_toggleImage').alt='Expand Menu';
	}
	else
	{
		document.getElementById('_menuState').value=''; 
		document.getElementById('_toggleImage').src='Content/Graphics/ToggleHide.gif'
		document.getElementById('_toggleImage').alt='Collapse Menu';
	}
	
	document.getElementById('_siteMenu').style.display=document.getElementById('_menuState').value;
}

/* Handles control auto focus */
function SetNextControlFocus(sourceControlID, destinationControlID, charCount)
{
	var sourceControl = document.getElementById(sourceControlID);
	var destinationControl = document.getElementById(destinationControlID);
	
	if (sourceControl.value.length == charCount)
	{
		destinationControl.focus();
	}
}


/* Tooltip Related Functions */
// Shows tooltips
function ShowToolTip(current,e,text)
{
   if (document.all)
   {
      thetitle=text.split('<br>')
      if (thetitle.length > 1)
      {
        thetitles=""
        for (i=0; i<thetitle.length-1; i++)
           thetitles += thetitle[i] + "\r\n"
        current.title = thetitles
      }
      else current.title = text
   }

   else if (document.layers)
   {
       document.tooltip.document.write( 
           '<layer bgColor="#FFFFE7" style="border:1px ' +
           'solid black; font-size:12px;color:#000000;">' + text + '</layer>')
       document.tooltip.document.close()
       document.tooltip.left=e.pageX+5
       document.tooltip.top=e.pageY+5
       document.tooltip.visibility="show"
   }
}

// Hides tooltips
function HideToolTip()
{
    if (document.layers)
        document.tooltip.visibility="hidden"
}