Type.registerNamespace('SfWeb');

SfWeb.ClickedOutsideElement = function(evt, element)
{
	var theElem = SfWeb.GetEventTarget(evt);

	while (theElem != null)
	{
		if (theElem.id == element.id)
			return false;

		theElem = theElem.parentNode;
	}

	return true;
}

SfWeb.GetEventTarget = function(evt)
{
	var targ = (evt.target) ? evt.target : evt.srcElement;

	if (targ != null)
	{
		if (targ.nodeType == 3)
			targ = targ.parentNode;
	}

	return targ;
}

/* Begin AutoComplete.js */
SfWeb.AutoComplete = function(id, divResultsId, divResultListId, textBoxValueId, hiddenInputId, noResultsText, containerId, itemSelectedClientMethod)
{
	this.id = id;
	this.divResults = $get(divResultsId);
	this.divResultList = $get(divResultListId);
	this.textBoxValue = $get(textBoxValueId);
	this.hiddenInput = $get(hiddenInputId);
	this.noResultsText = noResultsText;
	this.divContainer = $get(containerId);
	this.timer;
	this.itemSelectedClientMethod = itemSelectedClientMethod;
	this.lastSearchText;

	SfWeb.AutoComplete.prototype.Init = function()
	{
		$addHandler(this.textBoxValue, "focus", new Function(this.id + '.OnFocus()'));
		$addHandler(document.body, "click", new Function('evt', this.id + '.OnBodyClick(evt)'));
	}

	this.GetSelectedValue = function()
	{
		return this.hiddenInput.value;
	}

	this.GetSelectedText = function()
	{
		return this.textBoxValue.value;
	}

	this.OnFocus = function()
	{
		this.OnKeyUp();
		//		this.ShowResults();
	}

	this.OnBodyClick = function(evt)
	{
		if (SfWeb.ClickedOutsideElement(evt, this.divContainer))
		{
			this.HideResults();
		}
	}

	this.SearchResults = function(result)
	{
		var results = result.split(";");
		results.pop(); // last result is always empty
		this.ClearResults();

		if (results.length > 0)
		{
			for (var i = 0; i < results.length; i++)
			{
				var keyValue = results[i].split("::");

				if (keyValue.length != 2 || keyValue[0] == null)
				{
					return;
				}

				var divItem = document.createElement('div');
				divItem.innerHTML = keyValue[1];
				divItem.setAttribute('dataId', keyValue[0]);
				divItem.onclick = new Function(this.id + '.SelectValue(this)');
				divItem.onmouseover = new Function(this.id + '.Hilight(this)');
				divItem.onmouseout = new Function(this.id + '.Unhilight(this)');
				divItem.className = 'AutoCompleteResultItem';
				this.divResultList.appendChild(divItem);

				// if they've hit a single result set the id
				if (results.length == 1)
				{
					this.hiddenInput.value = keyValue[0];
				}
			}
		}
		else
		{
			this.AddNoResults();
		}

		this.ShowResults();
	}

	this.AddNoResults = function()
	{
		var divItem = document.createElement('div');
		divItem.innerHTML = this.noResultsText;
		divItem.className = 'AutoCompleteResultItem';
		this.divResultList.appendChild(divItem);
	}

	this.Hilight = function(target)
	{
		target.className = 'AutoCompleteResultItemOver';
	}

	this.Unhilight = function(target)
	{
		target.className = 'AutoCompleteResultItem';
	}

	this.SelectValue = function(target)
	{
		this.textBoxValue.value = target.innerHTML;
		this.hiddenInput.value = target.getAttribute('dataId');
		this.HideResults();

		if (this.itemSelectedClientMethod != null && this.itemSelectedClientMethod.length > 0)
		{
			eval(this.itemSelectedClientMethod + '()');
		}
	}

	this.Focus = function()
	{
		this.textBoxValue.focus();
	}

	this.ShowResults = function()
	{
		this.divResults.style.display = '';
	}

	this.HideResults = function()
	{
		this.divResults.style.display = 'none';
	}

	this.Clear = function()
	{
		//		this.ClearResults();
		this.ClearValue();
		this.ClearText();
	}

	this.ClearResults = function()
	{
		this.divResultList.innerHTML = '';
	}

	this.ClearValue = function()
	{
		this.hiddenInput.value = '';
	}

	this.ClearText = function()
	{
		this.textBoxValue.value = '';
	}

	this.OnKeyPress = function(e)
	{
		e = (e) ? e : event;
		var code = e.charCode || e.keyCode;

		if (code == Sys.UI.Key.enter)
		{
			return false;
		}

		return true;
	}

	this.ShowSearching = function()
	{
		this.ClearResults();

		var divItem = document.createElement('div');
		divItem.innerHTML = "Searching...";
		divItem.className = 'AutoCompleteResultItem';
		this.divResultList.appendChild(divItem);

		this.ShowResults();
	}

	this.OnKeyUp = function(e)
	{
		if (this.textBoxValue.value == this.lastSearchText)
		{
			return;
		}

		clearTimeout(this.timer);
		var cancel = false;

		var code;
		if (!e) var e = window.event;

		if (e == null) code = null;
		else if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;

		if (code == Sys.UI.Key.esc)
		{
			cancel = true;
			this.HideResults();
		}

		this.ClearValue();

		if (this.textBoxValue.value.length == 0)
		{
			this.HideResults();
			return;
		}

		if (!cancel)
		{
			this.lastSearchText = this.textBoxValue.value;
			this.timer = setTimeout(this.id + '.AsyncSearch()', 1000);
		}
	}
}
SfWeb.AutoComplete.registerClass('SfWeb.AutoComplete');

function ProcessSearchResults(result, context)
{
	context.SearchResults(result);
}
/* End AutoComplete.js */

/* Begin ModalDialog.js */
function MediasiteModalDialog(behaviorId, clientId)
{
	this.behaviorId = behaviorId;
	this.clientId = clientId;
}

MediasiteModalDialog.prototype =
{
	Show: function()
	{
		var dialog = $find(this.behaviorId);
		dialog.show();
	},

	Hide: function()
	{
		var dialog = $find(this.behaviorId);
		dialog.hide();
	},

	Load: function()
	{
	}
}
/* End ModalDialog.js */

/* Begin MediasiteTreeView.js */
SfWeb.TreeNodeImageType = function() { };
SfWeb.TreeNodeImageType.prototype =
{
	Blank: 0,
	IBeam: 1,
	LBeam: 2,
	RBeam: 3,
	TBeam: 4,
	Collapse: 5,
	CollapseR: 6,
	CollapseL: 7,
	CollapseT: 8,
	Expand: 9,
	ExpandL: 10,
	ExpandR: 11,
	ExpandT: 12,
	Collapsed: 13,
	Expanded: 14,
	CollapseNL: 15,
	ExpandNL: 16
}
SfWeb.TreeNodeImageType.registerEnum("SfWeb.TreeNodeImageType");

SfWeb.MediasiteTreeViewNode = function(id, text, value, level, index, expanded, parentNode, showCheckBox, checked, collapsedImage, expandedImage)
{
	this.id = id;
	this.nodes = new Array();
	this.text = text;
	this.value = value;
	this.level = level;
	this.expanded = expanded;
	this.parentNode = parentNode;
	this.index = index;
	this.draggable;
	this.treeView;
	this.contextMenuId;
	this.collapsedImage = collapsedImage;
	this.expandedImage = expandedImage;
	this.showCheckBox = showCheckBox;
	this.checked = checked;
	this.checkBox;
	this.childrenRendered = false;
	this.branchContainer;
	this.contentContainer;
}

SfWeb.MediasiteTreeViewNode.prototype =
{
	RemoveNode: function(node)
	{
		for (var i = 0; i < this.nodes.length; i++)
		{
			if (this.nodes[i].id == node.id)
			{
				this.nodes.splice(i, 1);
				break;
			}
		}

		for (var i = 0; i < this.nodes.length; i++)
		{
			this.nodes[i].index = i;
		}
	},

	SetDraggable: function()
	{
		for (var i = 0; i < this.nodes.length; i++)
		{
			this.nodes[i].SetDraggable();
		}

		if (this.parentNode != null)
		{
			this.draggable = new Draggable(this.id, { revert: true });
		}

		Droppables.add(this.id, { accept: this.treeView.nodeHoverCssClass, onDrop: function(element, droppableElement) { eval(droppableElement.id).OnDrop(element); } });
	},

	RemoveDraggable: function()
	{
		for (var i = 0; i < this.nodes.length; i++)
		{
			this.nodes[i].RemoveDraggable();
		}

		Droppables.remove(this.id);

		if (this.draggable != null)
		{
			this.draggable.destroy();
		}
	},

	SetLevel: function(level)
	{
		this.level = level;

		for (var i = 0; i < this.nodes.length; i++)
		{
			this.nodes[i].SetLevel(this.level + 1);
		}
	},

	OnDrop: function(droppedElement)
	{
		var dropped = eval(droppedElement.id);

		if (window.confirm('Are you sure you want to move "' + dropped.text + '" to "' + this.text + '"?'))
		{
			dropped.parentNode.RemoveNode(dropped);
			dropped.parentNode = eval(this.id);
			dropped.SetLevel(this.level + 1);
			dropped.index = this.nodes.length;

			this.nodes.push(dropped);

			if (this.treeView.onDropMethod != null)
			{
				eval(this.treeView.onDropMethod + "(droppedElement.id)");
			}

			this.treeView.Render();
		}
	},

	GetImageUrl: function()
	{
		if (!this.treeView.showLines)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.Blank];
		}

		if (this.parentNode == null)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.RBeam];
		}

		if (this.index == (this.parentNode.nodes.length - 1))
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.LBeam];
		}

		return this.treeView.imageArray[SfWeb.TreeNodeImageType.TBeam];
	},

	GetCollapseImageUrl: function()
	{
		if (!this.treeView.showLines)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.CollapseNL];
		}

		if (this.parentNode == null)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.CollapseR];
		}

		if (this.index == (this.parentNode.nodes.length - 1))
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.CollapseL];
		}

		return this.treeView.imageArray[SfWeb.TreeNodeImageType.CollapseT];
	},

	GetExpandImageUrl: function()
	{
		if (!this.treeView.showLines)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.ExpandNL];
		}

		if (this.parentNode == null)
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.ExpandR];
		}

		if (this.index == (this.parentNode.nodes.length - 1))
		{
			return this.treeView.imageArray[SfWeb.TreeNodeImageType.ExpandL];
		}

		return this.treeView.imageArray[SfWeb.TreeNodeImageType.ExpandT];
	},

	GetParents: function()
	{
		var parents = new Array();
		var parent = this.parentNode;

		while (parent != null)
		{
			parents.push(parent);
			parent = parent.parentNode;
		}

		parents.reverse();
		parents.shift();

		return parents;
	},

	Render: function(treeView, parentContainer)
	{
		this.treeView = treeView;

		var container = document.createElement('div');
		container.className = 'mtvTreeNode';

		// start I-beam filler
		var iBeamContainer = document.createElement('span');
		var parents = this.GetParents();

		for (var i = 0; i < this.level; i++)
		{
			var iBeamImage = document.createElement('img');
			iBeamImage.className = 'mtvNodeImage';
			iBeamImage.src = (treeView.showLines ? (parents[i].index == parents[i].parentNode.nodes.length - 1 ? this.treeView.imageArray[SfWeb.TreeNodeImageType.Blank] : this.treeView.imageArray[SfWeb.TreeNodeImageType.IBeam]) : this.treeView.imageArray[SfWeb.TreeNodeImageType.Blank]);
			iBeamContainer.appendChild(iBeamImage);
		}

		container.appendChild(iBeamContainer);
		// end I-beam filler

		// start expand/collapse
		var expandContainer = document.createElement('span');

		if (this.nodes.length > 0)
		{
			expandContainer.onclick = new Function(treeView.id + ".ExpandCollapse('" + this.id + "');");
		}

		var expandImage = document.createElement('img');
		expandImage.id = (this.id + '_img');

		if (this.nodes.length == 0)
		{
			expandImage.setAttribute('src', this.GetImageUrl());
		}
		else if (this.expanded)
		{
			expandImage.setAttribute('src', this.GetCollapseImageUrl());
		}
		else
		{
			expandImage.setAttribute('src', this.GetExpandImageUrl());
		}

		expandContainer.appendChild(expandImage);
		container.appendChild(expandContainer);
		// end expand/collapse

		// start user-supplied image
		if ((!this.expanded && ((this.treeView.imageArray[SfWeb.TreeNodeImageType.Collapsed] != null) || this.collapsedImage != null)) || (this.expanded && ((this.treeView.imageArray[SfWeb.TreeNodeImageType.Expanded] != null) || this.expandedImage != null)))
		{
			var userImage = document.createElement('img');
			userImage.id = this.id + '_uimg';
			userImage.src =
				(this.expanded && this.nodes.length > 0) ?
					(this.expandedImage != null ? this.expandedImage : this.treeView.imageArray[SfWeb.TreeNodeImageType.Expanded])
					: (this.collapsedImage != null ? this.collapsedImage : this.treeView.imageArray[SfWeb.TreeNodeImageType.Collapsed]);

			if (this.nodes.length > 0)
			{
				userImage.onclick = new Function("", treeView.id + ".ExpandCollapse('" + this.id + "')");
			}

			container.appendChild(userImage);
		}
		// end user-supplied image

		// startcheckbox
		if (this.showCheckBox)
		{
			this.checkBox = document.createElement('input');
			this.checkBox.setAttribute('type', 'checkbox');
			this.checkBox.checked = this.checked;
			this.checkBox.onclick = new Function("", treeView.id + ".CheckClicked('" + this.id + "')");
			this.checkBox.id = this.id + '_checkbox';
			container.appendChild(this.checkBox);
			DataChangeValidator_AddNoDirtyCheckControl(this.checkBox.id);
		}
		// end checkbox

		// start user content
		this.contentContainer = document.createElement('span');

		// context menu
		if (this.contextMenuId != null)
		{
			this.contentContainer.oncontextmenu = new Function('evt', 'var posx = 0;var posy = 0;if (!evt) var evt = window.event;if (evt.pageX || evt.pageY) {posx = evt.pageX;posy = evt.pageY;}else if (evt.clientX || evt.clientY) {posx = evt.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;posy = evt.clientY + document.body.scrollTop+ document.documentElement.scrollTop;};' + this.contextMenuId + '.Show(posx, posy); ' + this.treeView.id + '.SetSelectedNode(\'' + this.id + '\', true); return false;');
		}

		this.contentContainer.className = (this.selected ? treeView.selectedNodeCssClass : treeView.nodeCssClass);
		this.contentContainer.onclick = new Function("", treeView.id + '.OnClick(this.id);');
		this.contentContainer.onmouseover = new Function("", treeView.id + '.OnMouseOver(this.id);');
		this.contentContainer.onmouseout = new Function("", treeView.id + '.OnMouseOut(this.id);');
		this.contentContainer.id = this.id;
		this.contentContainer.setAttribute('value', this.value);
		this.contentContainer.innerHTML = this.text.replace('&', '&amp;');

		container.appendChild(this.contentContainer);
		// end user content

		parentContainer.appendChild(container);

		// start sub-branch
		if (this.nodes.length > 0)
		{
			this.branchContainer = document.createElement('div');
			this.branchContainer.id = this.id + '_branch';
			this.branchContainer.className = (this.expanded ? 'mtvTreeBranchVisible' : 'mtvTreeBranchHidden');

			var branchInnerContainer = document.createElement('div');

			if (this.expanded)
			{
				this.RenderChildren();
			}

			this.branchContainer.appendChild(branchInnerContainer);
			parentContainer.appendChild(this.branchContainer);
		}
		// end sub-branch
	},

	RenderChildren: function()
	{
		if (this.childrenRendered)
		{
			return;
		}

		for (var i = 0; i < this.nodes.length; i++)
		{
			this.nodes[i].Render(this.treeView, this.branchContainer);
		}

		this.childrenRendered = true;
	},

	Focus: function()
	{
		//		this.treeView.SetSelectedNode(this.id);
		this.contentContainer.focus();
	}
}
SfWeb.MediasiteTreeViewNode.registerClass('SfWeb.MediasiteTreeViewNode');

SfWeb.MediasiteTreeView = function()
{
	this.id;
	this.containerId;
	this.selectedNodeId;
	this.focusedNodeId;
	this.nodeCssClass;
	this.selectedNodeCssClass;
	this.nodeHoverCssClass;
	this.selectedNodeHoverCssClass;
	this.onClickMethod;
	this.onDropMethod;
	this.showLines;
	this.autoPostBack;
	this.nodes = new Array();
	this.selectedValueInputId;
	this.expandedInputId;
	this.checkedInputId;
	this.validateUnsavedChanges;
	this.enableDragDrop;
	this.serverId;
	this.onNodeSelectMethod;
	this.lastContextMenuId;
	this.hasFocus = false;

	this.keyDownHandler;
	this.keyPressHandler;

	this.imageArray = new Array();
}

SfWeb.MediasiteTreeView.prototype =
{
	Initialize: function(id, serverId, containerId, nodeCssClass, selectedNodeCssClass, nodeHoverCssClss, selectedNodeHoverCssClass, showLines, autoPostBack, selectedValueInputId, expandedInputId, checkedInputId, validateUnsavedChanges, enableDragDrop)
	{
		this.id = id;
		this.serverId = serverId;
		this.containerId = containerId;
		this.nodeCssClass = nodeCssClass;
		this.selectedNodeCssClass = selectedNodeCssClass;
		this.nodeHoverCssClss = nodeHoverCssClss;
		this.selectedNodeHoverCssClass = selectedNodeHoverCssClass;
		this.showLines = showLines;
		this.autoPostBack = autoPostBack;
		this.selectedValueInputId = selectedValueInputId;
		this.expandedInputId = expandedInputId;
		this.checkedInputId = checkedInputId;
		this.validateUnsavedChanges = validateUnsavedChanges;
		this.enableDragDrop = enableDragDrop;
		this.clickTimeout;

		this.keyDownHandler = new Function('evt', 'return ' + this.id + '._onKeyDown(evt);');
		this.keyPressHandler = new Function('evt', 'return ' + this.id + '._onKeyPress(evt);');

		$addHandler($get(this.containerId), 'focus', new Function(this.id + '._focus();'));
		$addHandler($get(this.containerId), 'blur', new Function(this.id + '._blur();'));
		$addHandler(document, 'keydown', this.keyDownHandler);
		$addHandler(document, 'keypress', this.keyPressHandler);
	},

	dispose: function()
	{
		$clearHandlers($get(this.containerId));
		$removeHandler(document, 'keydown', this.keyDownHandler);
		$removeHandler(document, 'keypress', this.keyPressHandler);
	},

	_onKeyPress: function(evt)
	{
		if (evt.ctrlKey && (evt.charCode == 103 || evt.charCode == 7))
		{
			evt.preventDefault();
			this.SetFocus();
			return false;
		}
	},

	SetFocus: function()
	{
		var container = $get(this.containerId);

		if ((container != null) && (container.getAttribute('TABINDEX') != 0))
		{
			try
			{
				$get(this.containerId).focus();
				this._focus();
			}
			catch (ex)
			{
				// do nothing
			}
		}
	},

	_focus: function()
	{
		this.hasFocus = true;
	},

	_blur: function()
	{
		this.hasFocus = false;
	},

	_selectNextNode: function(node)
	{
		if (node == null || node.parentNode == null)
		{
			return;
		}

		var index = node.index + 1;

		if (node.index < node.parentNode.nodes.length - 1)
		{
			this.OnClick(node.parentNode.nodes[index].id, true);
		}
		else
		{
			this._selectNextNode(node.parentNode);
		}
	},

	ScrollIntoView: function()
	{
		var selectedNode = this.GetSelectedNode();
		var nodeLoc = Sys.UI.DomElement.getBounds(selectedNode);

		var container = $get(this.containerId);
		var containerLoc = Sys.UI.DomElement.getBounds(container);
		var nodeTop = nodeLoc.y - containerLoc.y;
		var containerBottom = containerLoc.y + containerLoc.height;

		if (nodeTop < 0)
			container.scrollTop += nodeTop - 5;

		if ((nodeLoc.y + nodeLoc.height) > (containerBottom - 16))
			container.scrollTop += (nodeLoc.y - containerBottom) + nodeLoc.height + 16;
	},

	_onKeyDown: function(evt)
	{
		var code;
		if (!evt) var evt = window.event;

		if (evt == null) code = null;
		else if (evt.keyCode) code = evt.keyCode;
		else if (evt.which) code = evt.which;

		var selectedNodeId = this.GetSelectedNode().id;
		var selectedNode = this.GetNodeById(selectedNodeId);

		if (this.hasFocus)
		{
			if (code == Sys.UI.Key.up)
			{
				if (selectedNode.index == 0 && selectedNode.parentNode != null)
				{
					this.OnClick(selectedNode.parentNode.id, true);
				}
				else if (selectedNode.parentNode != null && selectedNode.parentNode.nodes.length > 0)
				{
					this.OnClick(selectedNode.parentNode.nodes[selectedNode.index - 1].id, true);
				}

				return false;
			}
			if (code == Sys.UI.Key.down)
			{
				if (selectedNode.expanded && selectedNode.nodes.length > 0)
				{
					this.OnClick(selectedNode.nodes[0].id, true);
				}
				else
				{
					this._selectNextNode(selectedNode);
				}

				return false;
			}
			if (code == Sys.UI.Key.left)
			{
				if (selectedNode.expanded)
				{
					this.ExpandCollapse(selectedNodeId);
				}

//				selectedNode.contentContainer.scrollIntoView();
				return false;
			}
			if (code == Sys.UI.Key.right)
			{
				if (!selectedNode.expanded)
				{
					this.ExpandCollapse(selectedNodeId);
				}

				return false;
			}
		}
	},

	GetSelectedValue: function()
	{
		var node = this.GetSelectedNode();

		if (node != null)
		{
			return node.getAttribute('value');
		}
		else
		{
			return null;
		}
	},

	GetSelectedText: function()
	{
		var node = this.GetSelectedNode();

		if (node != null)
		{
			return node.innerHTML;
		}
		else
		{
			return null;
		}
	},

	GetNodeById: function(nodeId, nodes)
	{
		if (nodes == null)
		{
			return this.GetNodeById(nodeId, this.nodes);
		}

		for (var i = 0; i < nodes.length; i++)
		{
			if (nodes[i].id == nodeId)
			{
				return nodes[i];
			}

			if (nodes[i].nodes.length > 0)
			{
				var result = this.GetNodeById(nodeId, nodes[i].nodes);

				if (result != null)
				{
					return result;
				}
			}
		}

		return null;
	},

	ExpandCollapse: function(nodeId)
	{
		var node = eval(nodeId);
		node.expanded = !node.expanded;
		node.RenderChildren();

		var branch = $get(nodeId + "_branch");
		var image = $get(nodeId + "_img");
		var userImage = $get(nodeId + "_uimg");

		if (branch == null)
			return;

		if (branch.className == 'mtvTreeBranchHidden')
		{
			branch.className = 'mtvTreeBranchVisible';

			if (image != null)
			{
				image.src = node.GetCollapseImageUrl();
			}

			if (userImage != null)
			{
				if (node.expandedImage != null)
				{
					userImage.src = node.expandedImage;
				}
				else
				{
					userImage.src = this.imageArray[SfWeb.TreeNodeImageType.Expanded];
				}
			}

			this.SaveExpandedState(node.id);
		}
		else
		{
			branch.className = 'mtvTreeBranchHidden';

			if (image != null)
			{
				image.src = node.GetExpandImageUrl();
			}

			if (userImage != null)
			{
				if (node.collapsedImage != null)
				{
					userImage.src = node.collapsedImage;
				}
				else
				{
					userImage.src = this.imageArray[SfWeb.TreeNodeImageType.Collapsed];
				}
			}

			this.SaveCollapsedState(node.id);
		}
	},

	SaveExpandedState: function(nodeId)
	{
		var expandedInput = $get(this.expandedInputId);
		var ids = expandedInput.value.split('|');
		ids.push(nodeId);
		expandedInput.value = ids.join('|');
	},

	SaveCollapsedState: function(nodeId)
	{
		var expandedInput = $get(this.expandedInputId);
		var ids = expandedInput.value.split('|');

		for (var i = 0; i < ids.length; i++)
		{
			if (ids[i] == nodeId)
			{
				Array.removeAt(ids, i);
				break;
			}
		}

		expandedInput.value = ids.join('|');
	},

	GetExpandedState: function(nodeId)
	{
		var expandedInput = $get(this.expandedInputId);
		var ids = expandedInput.value.split('|');
		var result = false;

		for (var i = 0; i < ids.length; i++)
		{
			if (ids[i] == nodeId)
			{
				result = true;
				break;
			}
		}

		return result;
	},

	CheckClicked: function(nodeId)
	{
		var checkedInput = $get(this.checkedInputId);
		var ids = checkedInput.value.split('|');
		var isChecked = eval(nodeId).checkBox.checked;

		if (!isChecked)
		{
			for (var i = 0; i < ids.length; i++)
			{
				if (ids[i] == nodeId)
				{
					Array.removeAt(ids, i);
					break;
				}
			}
		}
		else
		{
			ids.push(nodeId);
		}

		checkedInput.value = ids.join('|');
	},

	OnMouseOver: function(nodeId)
	{
		var node = $get(nodeId);

		if (nodeId == this.selectedNodeId)
		{
			node.className = this.selectedNodeHoverCssClass;
		}
		else
		{
			node.className = this.nodeHoverCssClss;
		}
	},

	OnMouseOut: function(nodeId)
	{
		var node = $get(nodeId);

		if (nodeId == this.selectedNodeId)
		{
			node.className = this.selectedNodeCssClass;
		}
		else
		{
			node.className = this.nodeCssClass;
		}
	},

	GetSelectedNode: function()
	{
		if (this.selectedNodeId == null)
		{
			return '';
		}

		return $get(this.selectedNodeId);
	},

	SetSelectedNode: function(nodeId, expand)
	{
		if (this.selectedNodeId != null)
		{
			var currentNode = $get(this.selectedNodeId);
			currentNode.className = this.nodeCssClass;
		}

		this.selectedNodeId = nodeId;
		var selectedNode = $get(nodeId);
		if (selectedNode)
		{
			selectedNode.className = this.selectedNodeCssClass;

			if (expand && !this.GetNodeById(this.selectedNodeId).expanded)
			{
				this.ExpandCollapse(this.selectedNodeId);
			}

			var hiddenInput = $get(this.selectedValueInputId);
			hiddenInput.value = selectedNode.getAttribute('value');
			this.ScrollIntoView();
		}

		if (this.onNodeSelectMethod != null)
		{
			eval(this.onNodeSelectMethod + "()");
		}
	},

	SetSelectedValue: function(value, nodes)
	{
		if (nodes == null)
		{
			this.SetSelectedValue(value, this.nodes);
			return;
		}

		for (var i = 0; i < nodes.length; i++)
		{
			var node = this.GetNodeById(nodes[i].id);

			if (node.value == value)
			{
				this.SetSelectedNode(node.id, true);
				return;
			}

			if (node.nodes != null && node.nodes.length > 0)
			{
				this.SetSelectedValue(value, node.nodes);
			}
		}
	},

	OnClick: function(nodeId, delay)
	{
		if (this.clickTimeout != null)
		{
			clearTimeout(this.clickTimeout);
		}

		if (this.validateUnsavedChanges && !ValidateChanges())
		{
			return;
		}

		this.SetSelectedNode(nodeId, !delay);
		this.SetFocus();

		var node = this.GetNodeById(nodeId);

		if (node.contextMenuId != null)
		{
			eval(node.contextMenuId + '.Hide()');
		}

		if (this.autoPostBack)
		{
			if (delay)
				this.clickTimeout = setTimeout('__doPostBack(\'' + this.serverId.replace(/_/g, '$') + '\', \'' + nodeId + '\');', 1000);
			else
				__doPostBack(this.serverId.replace(/_/g, '$'), nodeId);
		}
		else if (this.onClickMethod != null)
		{
			if (delay)
				this.clickTimeout = setTimeout(Function.createDelegate(this, this.onClickMethod), 1000);
			else
				eval(this.onClickMethod + "()");
		}
	},

	Render: function()
	{
		var treeContainer = $get(this.containerId);

		if (treeContainer)
		{
			while (treeContainer.hasChildNodes())
			{
				treeContainer.removeChild(treeContainer.childNodes[0]);
			}

			for (var i = 0; i < this.nodes.length; i++)
			{
				this.nodes[i].Render(this, treeContainer);
			}

			this.SetFocus();
		}
	}
}
SfWeb.MediasiteTreeView.registerClass('SfWeb.MediasiteTreeView');
/* End MediasiteTreeView.js */

/* Start base menu classes */
SfWeb.GetMousePosition = function(evt)
{
	var posx = 0;
	var posy = 0;
	if (!evt)
		var evt = window.event;
	if (evt.pageX || evt.pageY)
	{
		posx = evt.pageX;
		posy = evt.pageY;
	}
	else if (evt.clientX || evt.clientY)
	{
		posx = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	};

	return new Sys.UI.Point(posx, posy);
}

SfWeb.Menu = function(element)
{
	SfWeb.Menu.initializeBase(this, [element]);

	this.onbodyclick = null;
	this.menuItems = new Array();
	this.OnHideMenu = null;
	this.SeparatorUrl = null;
}

SfWeb.Menu.prototype =
{
	initialize: function()
	{
		this.onbodyclick = new Function('evt', this.get_id() + '._onBodyClick(evt)');
		$addHandler(this.get_element(), 'mouseover', Function.createDelegate(this, this._onMouseOver));
		$addHandler(this.get_element(), 'mouseout', Function.createDelegate(this, this._onMouseOut));
		SfWeb.Menu.callBaseMethod(this, 'initialize');
	},

	Render: function()
	{
		var container = this.get_element();

		while (container.hasChildNodes())
		{
			container.removeChild(container.childNodes[0]);
		}

		var menuContainer = document.createElement('div');
		container.appendChild(menuContainer);

		var itemsAreVisible = false;
		for (var i = 0; i < this.menuItems.length; i++)
		{
			if (this.menuItems[i].visible)
			{
				itemsAreVisible = true;
				this.menuItems[i].Render(menuContainer);
			}
		}

		if (!itemsAreVisible)
		{
			this.Hide();
		}
	},

	_onBodyClick: function(evt)
	{
		if (SfWeb.ClickedOutsideElement(evt, this.get_element()))
		{
			this.Hide();

			if (this.OnHideMenu)
			{
				eval(this.OnHideMenu);
			};
		}
	},

	Show: function(x, y)
	{
		$addHandler(document.body, "click", this.onbodyclick);
		var element = this.get_element();
		Sys.UI.DomElement.setLocation(element, x, y);
		element.style.display = '';
	},

	Hide: function()
	{
		try
		{
			$removeHandler(document.body, "click", this.onbodyclick);
		}
		catch (e)
		{
			// fail silently if it wasn't added for some reason
		}

		this.get_element().style.display = 'none';
	},

	Add_MouseOver: function(handler)
	{
		this.get_events().addHandler('menumouseover', handler);
	},

	Remove_MouseOver: function(handler)
	{
		this.get_events().removeHandler('menumouseover', handler);
	},

	Add_MouseOut: function(handler)
	{
		this.get_events().addHandler('menumouseout', handler);
	},

	Remove_MouseOut: function(handler)
	{
		this.get_events().removeHandler('menumouseout', handler);
	},

	_onMouseOver: function()
	{
		var h = this.get_events().getHandler('menumouseover');
		if (h) h(this, Sys.EventArgs.Empty);
	},

	_onMouseOut: function()
	{
		var h = this.get_events().getHandler('menumouseout');
		if (h) h(this, Sys.EventArgs.Empty);
	}
}
SfWeb.Menu.registerClass('SfWeb.Menu', Sys.UI.Control);

SfWeb.MenuItem = function()
{
	SfWeb.MenuItem.initializeBase(this);

	this.menuItems = new Array();
	this.text = null;
	this.menu = null;
	this.autoPostBack = null;
	this.commandName = null;
	this.enabled = true;
	this.visible = true;
	this.cssClass = null;
	this.cssHoverClass = null;
	this.cssDisabledClass = null;
	this.onClickMethod = null;
	this.element = null;
}

SfWeb.MenuItem.prototype =
{
	get_menu: function()
	{
		return this.menu;
	},

	set_menu: function(value)
	{
		this.menu = value;
	},

	initialize: function()
	{
		var menuItem = document.createElement('div');
		menuItem.id = this.get_id();
		this.element = menuItem;
		SfWeb.MenuItem.callBaseMethod(this, 'initialize');

		$addHandler(this.element, 'mouseout', Function.createDelegate(this, this._onMouseOut));
		$addHandler(this.element, 'mouseover', Function.createDelegate(this, this._onMouseOver));
		$addHandler(this.element, 'click', Function.createDelegate(this, this._onClick));
	},

	dispose: function()
	{
		$clearHandlers(this.element);
	},

	set_enabled: function(value)
	{
		this.enabled = value;
		this.element.className = this.text == '' ? 'sofoContextMenuItemSeparator' : (this.enabled ? this.cssClass : this.cssDisabledClass);
	},

	Render: function(container)
	{
		// create menu
		this.set_enabled(this.enabled);

		if (this.text == '')
		{
			this.element.innerHTML = '&nbsp;';
			this.element.style.backgroundImage = 'url(' + this.menu.SeparatorUrl + ')';
		}
		else
		{
			this.element.innerHTML = this.text;
		}

		container.appendChild(this.element);

		// create submenu
	},

	_onMouseOver: function()
	{
		if (this.text == '' || !this.enabled)
		{
			return;
		}

		var element = $get(this.get_id());
		element.className = this.cssHoverClass;

		if (this.menuItems.length > 0)
		{
			// show submenu
		}
	},

	_onMouseOut: function()
	{
		if (this.text == '' || !this.enabled)
		{
			return;
		}

		var element = $get(this.get_id());
		element.className = this.cssClass;

		if (this.menuItems.length > 0)
		{
			// hide submenu
		}
	},

	_onClick: function()
	{
		if (this.text == '' || !this.enabled)
		{
			return;
		}

		this.menu.Hide();
		var result;

		if (this.onClickMethod != null)
		{
			result = eval(this.onClickMethod + '()');

		}

		if ((result != null) && result && this.autoPostBack)
		{
			if (this.commandName == null || this.commandName == '')
			{
				__doPostBack(this.menu.get_id().replace(/_/g, '$'));
			}
			else
			{
				__doPostBack(this.menu.get_id().replace(/_/g, '$'), this.commandName);
			}
		}
	}
}
SfWeb.MenuItem.registerClass('SfWeb.MenuItem', Sys.Component);
/* End base menu classes */

/* Start MouseOverMenu.js */

SfWeb.MouseOverMenu = function(element)
{
	SfWeb.MouseOverMenu.initializeBase(this, [element]);

	this.containerId = null;
	this.contextMenuId = null;
	this.hideTimer;
}

SfWeb.MouseOverMenu.prototype =
{
	initialize: function()
	{
		$addHandler($get(this.containerId), "mouseover", Function.createDelegate(this, this.OnMouseOver));
		$addHandler($get(this.containerId), "mouseout", Function.createDelegate(this, this.OnMouseOut));

		var contextMenu = eval(this.contextMenuId);
		contextMenu.Add_MouseOver(Function.createDelegate(this, this._clearTimeout));
		contextMenu.Add_MouseOut(Function.createDelegate(this, this.OnMouseOut));

		SfWeb.MouseOverMenu.callBaseMethod(this, 'initialize');
	},

	_clearTimeout: function()
	{
		clearTimeout(this.hideTimer);
	},

	get_menuItems: function()
	{
		var contextMenu = eval(this.contextMenuId);
		return contextMenu.menuItems;
	},

	OnMouseOver: function(evt)
	{
		this._clearTimeout();
		if (!evt) evt = window.event;
		var contextMenu = eval(this.contextMenuId);
		var element = this.get_element();
		var loc = Sys.UI.DomElement.getLocation(element);
		var bounds = Sys.UI.DomElement.getBounds(element);
		contextMenu.Show(loc.x, loc.y + bounds.height);
	},

	OnMouseOut: function()
	{
		this.hideTimer = setTimeout(this.contextMenuId + ".Hide()", 1000);
	}
}
SfWeb.MouseOverMenu.registerClass('SfWeb.MouseOverMenu', Sys.UI.Control);
/* End MouseOverMenu.js */

/* Start ImageWithPopup.js */
SfWeb.ImageWithPopupParameters = function(element)
{
	SfWeb.ImageWithPopupParameters.initializeBase(this, [element]);

	this.PopupId = null;
	this.ButtonId = null;
	this.OffsetX = null;
	this.OffsetY = null;
	this.bodyClickHandler = Function.createDelegate(this, this.ClosePopup);
}

SfWeb.ImageWithPopupParameters.prototype =
{
	initialize: function()
	{
		var button = $get(this.ButtonId);
		if (button)
		{
			$addHandler(button, "click", Function.createDelegate(this, this.TogglePopup));
			$addHandler(document, "click", this.bodyClickHandler);
		}

		SfWeb.ImageWithPopupParameters.callBaseMethod(this, 'initialize');
	},

	dispose: function()
	{
		$clearHandlers($get(this.ButtonId));
		$removeHandler(document, 'click', this.bodyClickHandler);
		SfWeb.ImageWithPopupParameters.callBaseMethod(this, 'dispose');
	},

	TogglePopup: function(evt)
	{
		var popup = $get(this.PopupId);
		var button = $get(this.ButtonId);

		if (popup && button)
		{
			if (popup.style.display == "none" && evt.target == button)
			{
				var buttonBounds = Sys.UI.DomElement.getBounds(button);
				Sys.UI.DomElement.setLocation(popup, this.OffsetX, (buttonBounds.height + this.OffsetY));
				popup.style.display = "block";
			}
			else
			{
				if (SfWeb.ClickedOutsideElement(evt, popup))
				{
					popup.style.display = "none";
				}
			}
		}
	},

	ClosePopup: function(evt)
	{
		var popup = $get(this.PopupId);

		if (popup &&
            evt.target.id != this.ButtonId)
		{
			if (SfWeb.ClickedOutsideElement(evt, popup))
			{
				popup.style.display = "none";
			}
		}
	}
}
SfWeb.ImageWithPopupParameters.registerClass('SfWeb.ImageWithPopupParameters', Sys.UI.Control);
/* End ImageWithPopup.js */