function ButtonOut(cellId, level)
{
	var tableCell = document.getElementById(cellId);
	if (tableCell != null)
		tableCell.className = "buttonTyp" + level + "CellInact";
}

function ButtonOver(cellId, level)
{
	var tableCell = document.getElementById(cellId);
	if (tableCell != null)
		tableCell.className = "buttonTyp" + level + "CellAct";
}


function CheckFormEnter(submitId)
{
	if (window.event.keyCode == 13)
	{
		var control = document.getElementById(submitId);
		control.click();
	}
}

function cleanPrintNodes(parentNode, hideFormElements)
{
	if (!parentNode.hasChildNodes())
		return;

	if (hideFormElements == null)
		hideFormElements = false;

	for (var index = parentNode.childNodes.length - 1; index >= 0; index--)
	{
		var node = parentNode.childNodes[index];
		var tagName = node.tagName;

		if (tagName != undefined)
		{
			switch (tagName.toLowerCase())
			{
				case "a":
					// Do not allow navigation in the print page
					node.href = "javascript:return false;";
					break;

				case "div":
					// Remove the button div
					var className = node.className;

					if ((className != null) && (className == "rightButton"))
						parentNode.removeChild(node);
					else
						cleanPrintNodes(node, hideFormElements);
					break;

				case "button":
				case "input":
				case "select":
				case "textarea":
					if (hideFormElements)
						parentNode.removeChild(node);
					break;

				case "script":
					// Remove any source attribute and inner script code
					if (node.getAttribute("src") != null)
						node.attributes.removeNamedItem("src");
					node.text = "";
					break;

				default:
					cleanPrintNodes(node, hideFormElements);
					break;
			}

		}
	}
}

function PrintContent(controlId, cssHref, hideFormElements)
{
	var element = document.getElementById(controlId);
	if (element != null)
	{
		var winPrint = window.open("", "winPrint");
		var docPrint = winPrint.document.open("text/html", "replace");

		docPrint.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
		docPrint.writeln('<html><head>');
		docPrint.write('<title>');
		docPrint.write(document.title);
		docPrint.writeln('</title>');

		if (cssHref == null)
			docPrint.writeln('<link href="/Common/Css/Styles.css" type="text/css" rel="stylesheet" />');
		else
			docPrint.writeln('<link href="' + cssHref + '" type="text/css" rel="stylesheet" />');

		docPrint.writeln('</head><body>');
		docPrint.writeln('<div id="supermain">');
		docPrint.writeln('<div id="main">');

		docPrint.write('<');
		docPrint.write(element.tagName);

		var attributes = element.attributes
		for (var index = 0; index < attributes.length; index++)
		{
			var attribute = attributes[index];

			if ((attribute.nodeValue != null) && (attribute.nodeValue != ""))
			{
				docPrint.write(' ');
				docPrint.write(attribute.nodeName);
				docPrint.write('="');
				docPrint.write(attribute.nodeValue);
				docPrint.write('"');
			}
		}

		docPrint.writeln('>');

		// Clone the node, otherwise all the cleaning is done to the original also!
		var elementClone = element.cloneNode(true);
		cleanPrintNodes(elementClone, hideFormElements);

		docPrint.writeln(elementClone.innerHTML);

		docPrint.write('</');
		docPrint.write(element.tagName);
		docPrint.writeln('>');

		docPrint.writeln('<script language="JavaScript" type="text/javascript">');
		docPrint.writeln('window.print();');
		docPrint.writeln('</script>');
		docPrint.writeln('</div>');
		docPrint.writeln('</div>');
		docPrint.writeln('</body></html>');

		docPrint.close();
		winPrint.focus();
	}
}

function TextCounter(textControlId, countControlId, maximumCount)
{
	var textControl = document.getElementById(textControlId);
	var countControl = document.getElementById(countControlId);
	var textLength = textControl.value.length;

	// If too long, trim it; otherwise, update the 'characters left' counter
	if (textLength > maximumCount)
		textControl.value = textControl.value.substring(0, maximumCount);
	else
		countControl.innerText = maximumCount - textLength;
}
