

var lastSelectedRow = null;
var lastBackgroundColor = "";
var clickableGridPageLoaded = false;
var clickableGridCallbackFunction = onRowClick;


function clickableGridPageOnLoad()
{
	clickableGridPageLoaded = true;
	onResize();	
}

function onResize()
{
	var offset = 0; // 17, 34;
	var docHeight = getDocumentHeight();
	var el = document.getElementById("sizedDiv");
	
	var newHeight = docHeight - offset;
	if (newHeight > 0) 
		el.style.height = newHeight;
}
			
function onRowClick(el)
{
}
			
function clickableGridRowClicked(el)
{
	if (lastSelectedRow != null)
		lastSelectedRow.style.backgroundColor = lastBackgroundColor;
	lastSelectedRow = el;
	
	lastBackgroundColor = el.style.backgroundColor;
	el.style.backgroundColor = selectedRowBackgroundColor;

	if (clickableGridCallbackFunction)
		clickableGridCallbackFunction(el);
}

function clickableGridOnClick(ev)
{
	if (!clickableGridPageLoaded)
		return;
		
	var se = getEventSrc(ev);
		
	while(se) 
	{
		if (se.tagName && se.tagName.toUpperCase() == "TR")
	 	{
	 		if (se.id.indexOf('click') != - 1)
	  		{
		 		if (lastSelectedRow != se)
		 		{
		 			clickableGridRowClicked(se);
		 			ev.cancelBubble = true;
				}
			}
			return true;
		}
		se = se.parentNode;
	}
	return true;
}

addEvent(document, "mouseup", clickableGridOnClick);
addEvent(window, "load", clickableGridPageOnLoad);

