﻿function selectGrid_gridHighlight(row, id)
{
 	try
	{
	    if (row.className == "RowDetail")
	    {
	        row.className = "RowHighlighted";
	    }
    }
    catch (err)
	{
		alert(err.description);
	}
}

function selectGrid_gridUnHighlight(row, id)
{
	try
	{
	    if (row.className == "RowHighlighted")
	    {
	        row.className = "RowDetail";
	    }
    }
    catch (err)
    {
		alert(err.description);
	}
}

function selectGrid_gridItemClick(multiSelect, row, id, attributes, rowIDElementID, rowAttributesElementID)
{
	try
	{
		// Just set the attribute value in the hidden input
		var elRowAttributes = window.document.forms[0].elements[rowAttributesElementID];
		elRowAttributes.value = attributes;

		// Setup the variables
		var elRowID = window.document.forms[0].elements[rowIDElementID];
		var pattern1 = new RegExp("^" + id + "\,");
		var pattern2 = new RegExp("\," + id + "\,");

		// If the grid doesn't support multiple selection,
		// deselect the previously selected row
		if (!multiSelect)
		{
			var selectedRows = row.parentNode.getElementsByTagName("tr");
			for (var i = 0; i < selectedRows.length; i++)
			{
				if (selectedRows[i].className == "RowSelected")
				{
					selectedRows[i].className = "RowDetail";
				}
				
				if (selectedRows[i].className == "RowAltSelected")
				{
					selectedRows[i].className = "RowAlternate";
				}
			}
		}

		// Change the row's style to reflect the user's click
		switch (row.className)
		{
			case "RowSelected":
			{
				row.className = "RowDetail";

				// Remove the selected row ID from the hidden input, so that
				// the server can determine which rows have been selected
				elRowID.value = elRowID.value.replace(pattern1, "");
				if (multiSelect)
				{
					elRowID.value = elRowID.value.replace(pattern2, ",");
				}
				
				break;
			}
			case "RowHighlighted":
			{
				row.className = "RowSelected";
				
				// Add the selected row ID to the hidden input, so that
				// the server can determine which rows have been selected
				if (elRowID.value.search(pattern1) == -1 &&
					elRowID.value.search(pattern2) == -1)
				{
					if (multiSelect)
					{
						elRowID.value = elRowID.value + id + ",";
					}
					else
					{
						elRowID.value = id;
					}
				}
				
				break;
			}
		}
	}
	catch (err)
	{
		alert(err.description);
	}
}
