﻿// If customMoreLinkUrl is not null, then a 'More...' link will be rendered with it's
// href set to the passed custom url. Otherwise, the 'More...' link behaves in its usual
// manner.
function hideAll(ctrl, maxItems, moreText, customMoreLinkUrl)
{
	try {
		var menu;
		var temp;
		var items;
		var numChildren;

		menu = document.getElementById(ctrl);

		if (menu != null) temp = getFirstChild(menu);
		if (temp != null) items = getFirstChild(temp);
		if (items != null) numChildren = items.childNodes.length;
		var count;
		var numItems = 0;

		if (items != null) {
			if (customMoreLinkUrl != null) {
				// Always display a 'More...' link that points to customMoreLinkUrl.
				var footer = document.getElementById(ctrl.replace(/slwp_/, "") + "_footer");
				footer.className = "item";
				footer.innerHTML = "<div style=\"padding-top:5px;\" class=\"link-item more-link\"><a href='" + customMoreLinkUrl + "'>" + moreText + "</a></div>";
			}
			else {
				for (count = 0; count < numChildren; count++) {
					if (items.childNodes[count].nodeType == 1) {
						if (items.childNodes[count].id.indexOf("_footer") == -1) {
							numItems++;

							if (numItems > maxItems) {
								items.childNodes[count].style.display = "none";
							}
						}
					}
				}

				if (numItems > maxItems) {
					var footer = document.getElementById(ctrl.replace(/slwp_/, "") + "_footer");
					footer.className = "item";
					footer.innerHTML = "<div style=\"padding-top:5px;\" class=\"link-item more-link\"><a href='#' onclick='javascript:revealAll(\"" + ctrl + "\");return false;' onkeypress='javascript:revealAll(\"" + ctrl + "\");return false;'>" + moreText + "</a></div>";
				}
			} // if( customMoreLinkUrl != null )
		}
	}
	catch (err) {
		alert('Error ' + err.description + ' in Overflow.js:hideAll');
	}
}

function revealAll(ctrl) {

	try {
		var menu;
		var items;
		var numChildren;
		var temp;

		menu = document.getElementById(ctrl);
		if (menu != null) temp = getFirstChild(menu);
		if (temp != null) items = getFirstChild(temp);
		if (items != null) numChildren = items.childNodes.length;
		var count;
		var numItems = 0;

		if (items != null) {
			for (count = 0; count < numChildren; count++) {
				if (items.childNodes[count].nodeType == 1) {
					if (items.childNodes[count].id.indexOf("_footer") == -1) {
						numItems++;
						items.childNodes[count].style.display = "block";
					}
				}
			}

			var footer = document.getElementById(ctrl.replace(/slwp_/, "") + "_footer");
			footer.innerHTML = "";
		}
	}
	catch (err) {
		alert('Error ' + err.description + ' in Overflow.js:revealAll');
	}
}

function getFirstChild(node) {

	try {
		var child = node.firstChild;

		while (child.nodeType != 1) {
			child = child.nextSibling;
		}

		return child;
	}
	catch (err) {
		alert('Error ' + err.description + ' in Overflow.js:getFirstChild');
	}
}

function RedirectToUrl(url)
{
	window.location = url;
}