var net;	

var DNN_HIGHLIGHT_COLOR = '#9999FF';
var COL_DELIMITER = String.fromCharCode(18);
var ROW_DELIMITER = String.fromCharCode(17);

if (typeof(__net_m_aNamespaces) == 'undefined')	//include in each NET ClientAPI namespace file for dependency loading
	var __net_m_aNamespaces = new Array();

//NameSpace NET
	function __net()
	{
		this.apiversion = .1;
		this.pns = '';
		this.ns = 'net';
		this.diagnostics = null;
		this.vars = null;
		this.dependencies = new Array();
		this.isLoaded = false;
	}

	__net.prototype.getVars = function()
	{
		if (this.vars == null)
		{
			this.vars = new Array();
			var oCtl = net.dom.getById('__netVariable');
			if (oCtl != null)
			{
				var aryItems = oCtl.value.split(ROW_DELIMITER);
				for (var i=0; i<aryItems.length; i++)
				{
					var aryItem = aryItems[i].split(COL_DELIMITER);
					
					if (aryItem.length == 2)
						this.vars[aryItem[0]] = aryItem[1];
				}
			}
		}
		return this.vars;	
	}

	__net.prototype.getVar = function(sKey)
	{
		return this.getVars()[sKey];
	}

	__net.prototype.setVar = function(sKey, sVal)
	{			
		if (this.vars == null)
			this.getVars();			
		this.vars[sKey] = sVal;
		var oCtl = net.dom.getById('__netVariable');
		if (oCtl == null)
		{
			oCtl = net.dom.createElement('INPUT');
			oCtl.type = 'hidden';
			oCtl.id = '__netVariable';
			net.dom.appendChild(net.dom.getByTagName("body")[0], oCtl);		
		}
		var sVals = '';
		var sKey
		for (sKey in this.vars)
		{
			sVals += ROW_DELIMITER + sKey + COL_DELIMITER + this.vars[sKey];
		}
		oCtl.value = sVals;
		return true;
	}

	__net.prototype.callPostBack = function(sAction)
	{
		var sPostBack = net.getVar('__net_postBack');
		var sData = '';
		if (sPostBack.length > 0)
		{
			sData += sAction;
			for (var i=1; i<arguments.length; i++)
			{
				var aryParam = arguments[i].split('=');
				sData += COL_DELIMITER + aryParam[0] + COL_DELIMITER + aryParam[1];
			}
			eval(sPostBack.replace('[DATA]', sData));
		}
	}

	__net.prototype.dependenciesLoaded = function()
	{
		return true;
	}

	__net.prototype.loadNamespace = function ()
	{
		if (this.isLoaded == false)
		{
			if (this.dependenciesLoaded())
			{
				net = this; 
				this.isLoaded = true;
				this.loadDependencies(this.pns, this.ns);
			}
		}	
	}

	__net.prototype.loadDependencies = function (sPNS, sNS)
	{
		for (var i=0; i<__net_m_aNamespaces.length; i++)
		{
			for (var iDep=0; i<__net_m_aNamespaces[i].dependencies.length; i++)
			{
				if (__net_m_aNamespaces[i].dependencies[iDep] == sPNS + (sPNS.length>0 ? '.': '') + sNS)
					__net_m_aNamespaces[i].loadNamespace();
			}
		}
	}


	//--- net.dom
		function dnn_dom()
		{
			this.pns = 'net';
			this.ns = 'dom';
			this.dependencies = 'net'.split(',');
			this.isLoaded = false;
		}

		dnn_dom.prototype.getById = function (sID, oCtl)
		{
			if (oCtl == null)
				oCtl = document;
			if (oCtl.getElementById) //(net.dom.browser.isType(net.dom.browser.InternetExplorer) == false)
				return oCtl.getElementById(sID);
			else
				return oCtl.all(sID);
		}

		dnn_dom.prototype.getByTagName = function (sTag, oCtl)
		{
			if (oCtl == null)
				oCtl = document;
			if (oCtl.getElementsByTagName) //(net.dom.browser.type == net.dom.browser.InternetExplorer)
				return oCtl.getElementsByTagName(sTag);
			else if (oCtl.all.tags)
				return oCtl.all.tags(sTag);
			else
				return null;
		}

		dnn_dom.prototype.createElement = function (sTagName) 
		{
			if (document.createElement) 
				return document.createElement(sTagName);
			else 
				return null;
		}
		
		dnn_dom.prototype.isNonTextNode = function (oNode)
		{
			return (oNode.nodeType != 3 && oNode.nodeType != 8); //exclude nodeType of Text (Netscape/Mozilla) issue!
		}
		
		dnn_dom.prototype.getNonTextNode = function (oNode)
		{
			if (this.isNonTextNode(oNode))	
				return oNode;
			
			while (oNode != null && this.isNonTextNode(oNode))
			{
				oNode = this.getSibling(oNode, 1);
			}
			return oNode;
		}

		dnn_dom.prototype.getSibling = function (oCtl, iOffset)
		{
			if (oCtl != null && oCtl.parentNode != null)
			{
				for (var i=0; i<oCtl.parentNode.childNodes.length; i++)
				{
					if (oCtl.parentNode.childNodes[i].id == oCtl.id)
					{
						if (oCtl.parentNode.childNodes[i + iOffset] != null)
							return oCtl.parentNode.childNodes[i + iOffset];
					}
				}
			}
		}

		dnn_dom.prototype.appendChild = function (oParent, oChild) 
		{
			if (oParent.appendChild) 
				return oParent.appendChild(oChild);
			else 
				return null;
		}

		dnn_dom.prototype.removeChild = function (oChild) 
		{
			if (oChild.parentNode.removeChild) 
				return oChild.parentNode.removeChild(oChild);
			else 
				return null;
		}


		dnn_dom.prototype.setCookie = function (sName, sVal, iDays, sPath, sDomain, bSecure) 
		{
			var sExpires;
			if (iDays)
			{
				sExpires = new Date();
				sExpires.setTime(sExpires.getTime()+(iDays*24*60*60*1000));
			}
			document.cookie = sName + "=" + escape(sVal) + ((sExpires) ? "; expires=" + sExpires : "") + 
				((sPath) ? "; path=" + sPath : "") + ((sDomain) ? "; domain=" + sDomain : "") + ((bSecure) ? "; secure" : "");
			
			if (document.cookie.length > 0)
				return true;
				
		}
		dnn_dom.prototype.getCookie = function (sName) 
		{
			var sCookie = " " + document.cookie;
			var sSearch = " " + sName + "=";
			var sStr = null;
			var iOffset = 0;
			var iEnd = 0;
			if (sCookie.length > 0) 
			{
				iOffset = sCookie.indexOf(sSearch);
				if (iOffset != -1) 
				{
					iOffset += sSearch.length;
					iEnd = sCookie.indexOf(";", iOffset)
					if (iEnd == -1) 
						iEnd = sCookie.length;
					sStr = unescape(sCookie.substring(iOffset, iEnd));
				}
			}
			return(sStr);
		}

		dnn_dom.prototype.deleteCookie = function (sName, sPath, sDomain) 
		{
			if (this.getCookie(sName)) 
			{
				this.setCookie(sName, '', -1, sPath, sDomain);
				return true;
			}
			return false;
		}

		dnn_dom.prototype.dependenciesLoaded = function()
		{
			return (typeof(net) != 'undefined');
		}

		dnn_dom.prototype.loadNamespace = function ()
		{
			if (this.isLoaded == false)
			{
				if (this.dependenciesLoaded())
				{
					net.dom = this; 
					this.isLoaded = true;
					net.loadDependencies(this.pns, this.ns);
				}
			}	
		}


			//--- net.dom.browser
			function dnn_dom_browser()
			{
				this.pns = 'net.dom';
				this.ns = 'browser';
				this.dependencies = 'net,net.dom'.split(',');
				this.isLoaded = false;
				this.InternetExplorer = 'ie';
				this.Netscape = 'ns';
				this.Mozilla = 'mo';
				this.Opera = 'op';
				this.Safari = 'safari';
				this.Konqueror = 'kq';
				
				//Please offer a better solution if you have one!
				var sType;
				var agt=navigator.userAgent.toLowerCase();

				if (agt.toLowerCase().indexOf('konqueror') != -1) 
					sType = this.Konqueror;
				else if (agt.toLowerCase().indexOf('opera') != -1) 
					sType = this.Opera;
				else if (agt.toLowerCase().indexOf('netscape') != -1) 
					sType = this.Netscape;
				else if (agt.toLowerCase().indexOf('msie') != -1)
					sType = this.InternetExplorer;
				else if (agt.toLowerCase().indexOf('safari') != -1)
					sType = 'safari';
				
				if (sType == null)
					sType = this.Mozilla;  
				
				this.type = sType;
				this.version = parseFloat(navigator.appVersion);
				
				var sAgent = navigator.userAgent.toLowerCase();
				if (this.type == this.InternetExplorer)
				{
					var temp=navigator.appVersion.split("MSIE");
					this.version=parseFloat(temp[1]);
				}
				if (this.type == this.Netscape)
				{
					var temp=sAgent.split("netscape");
					this.version=parseFloat(temp[1].split("/")[1]);	
				}

				//this.majorVersion = null;
				//this.minorVersion = null;
			}
			
			dnn_dom_browser.prototype.toString = function ()
			{
				return this.type + ' ' + this.version;
			}
			
			dnn_dom_browser.prototype.isType = function ()
			{
				for (var i=0; i<arguments.length; i++)
				{
					if (net.dom.browser.type == arguments[i])
						return true;
				}
				return false;
			}

			dnn_dom_browser.prototype.dependenciesLoaded = function()
			{
				return (typeof(net) != 'undefined' && typeof(net.dom) != 'undefined');
			}

			dnn_dom_browser.prototype.loadNamespace = function ()
			{
				if (this.isLoaded == false)
				{
					if (this.dependenciesLoaded())
					{
						net.dom.browser = this; 
						this.isLoaded = true;
						net.loadDependencies(this.pns, this.ns);
					}
				}	
			}
			
			//--- End net.dom.browser
			

	dnn_dom.prototype.attachEvent = function (oCtl, sType, fHandler) 
	{
		if (net.dom.browser.isType(net.dom.browser.InternetExplorer) == false)
		{
			var sName = sType.substring(2);
			oCtl.addEventListener(sName, function (evt) {net.dom.event = new dnn_dom_event(evt, evt.target); return fHandler();}, false);
		}
		else
			oCtl.attachEvent(sType, function () {net.dom.event = new dnn_dom_event(window.event, window.event.srcElement); return fHandler();});
		return true;
	}
	
	function dnn_dom_event(e, srcElement)
	{
		this.object = e;
		this.srcElement = srcElement;
	}
			
	//--- End net.dom


//--- End net

//load namespaces
__net_m_aNamespaces[__net_m_aNamespaces.length] = new dnn_dom_browser();
__net_m_aNamespaces[__net_m_aNamespaces.length] = new dnn_dom();
__net_m_aNamespaces[__net_m_aNamespaces.length] = new __net();
for (var i=__net_m_aNamespaces.length-1; i>=0; i--)
	__net_m_aNamespaces[i].loadNamespace();


var NET_COL_DELIMITER = String.fromCharCode(16);
var NET_ROW_DELIMITER = String.fromCharCode(15);
var __net_m_bPageLoaded = false;

window.onload = __net_Page_OnLoad;

function __net_ClientAPIEnabled()
{
	return typeof(net) != 'undefined';
}


function __net_Page_OnLoad()
{
	if (__net_ClientAPIEnabled())
	{
		var sLoadHandlers = net.getVar('__net_pageload');
		if (sLoadHandlers != null)
			eval(sLoadHandlers);
	}
	__net_m_bPageLoaded = true;
}

function __net_KeyDown(iKeyCode, sFunc, e)
{
	if (e == null)
		e = window.event;

	if (e.keyCode == iKeyCode)
	{
		eval(unescape(sFunc));
		return false;
	}
}

function __net_bodyscroll() 
{
	var oF=document.forms[0];	
	if (__net_ClientAPIEnabled() && __net_m_bPageLoaded)
		oF.ScrollTop.value=net.dom.getByTagName("body")[0].scrollTop;
}

function __net_setScrollTop(iTop)
{
	if (__net_ClientAPIEnabled())
	{
		if (iTop == null)
			iTop = document.forms[0].ScrollTop.value;
	
		var sID = net.getVar('ScrollToControl');
		if (sID != null && sID.length > 0)
		{
			var oCtl = net.dom.getById(sID);
			if (oCtl != null)
			{
				iTop = net.dom.positioning.elementTop(oCtl);
				net.setVar('ScrollToControl', '');
			}
		}
		net.dom.getByTagName("body")[0].scrollTop = iTop;
	}
}

//Focus logic
function __net_SetInitialFocus(sID)
{
	var oCtl = net.dom.getById(sID);	
	if (oCtl != null && __net_CanReceiveFocus(oCtl))
		oCtl.focus();
}	

function __net_CanReceiveFocus(e)
{
	//probably should call getComputedStyle for classes that cause item to be hidden
	if (e.style.display != 'none' && e.tabIndex > -1 && e.disabled == false && e.style.visible != 'hidden')
	{
		var eParent = e.parentElement;
		while (eParent != null && eParent.tagName != 'BODY')
		{
			if (eParent.style.display == 'none' || eParent.disabled || eParent.style.visible == 'hidden')
				return false;
			eParent = eParent.parentElement;
		}
		return true;
	}
	else
		return false;
}

//Max/Min Script
function __net_ContainerMaxMin_OnClick(oLnk, sContentID)
{
	var oContent = net.dom.getById(sContentID);
	if (oContent != null)
	{
		var oBtn = oLnk.childNodes[0];
		var sContainerID = oLnk.getAttribute('containerid');
		var sCookieID = oLnk.getAttribute('cookieid');
		var sCurrentFile = oBtn.src.toLowerCase().substr(oBtn.src.lastIndexOf('/'));
		var sMaxFile;
		var sMaxIcon;
		var sMinIcon;

		if (net.getVar('min_icon_' + sContainerID))
			sMinIcon = net.getVar('min_icon_' + sContainerID);
		else
			sMinIcon = net.getVar('min_icon');

		if (net.getVar('max_icon_' + sContainerID))
			sMaxIcon = net.getVar('max_icon_' + sContainerID);
		else
			sMaxIcon = net.getVar('max_icon');

		sMaxFile = sMaxIcon.toLowerCase().substr(sMaxIcon.lastIndexOf('/'));

		if (sCurrentFile == sMaxFile)
		{
			oBtn.src = sMinIcon;				
			oContent.style.display = '';
			oBtn.title = net.getVar('min_text');
			if (sCookieID != null)
			{
				if (net.getVar('__net_' + sContainerID + ':defminimized') == 'true')
					net.dom.setCookie(sCookieID, 'true', 365);
				else
					net.dom.deleteCookie(sCookieID);
			}
			else
				net.setVar('__net_' + sContainerID + '_Visible', 'true');
		}
		else
		{
			oBtn.src = sMaxIcon;				
			oContent.style.display = 'none';
			oBtn.title = net.getVar('max_text');
			if (sCookieID != null)
			{
				if (net.getVar('__net_' + sContainerID + ':defminimized') == 'true')
					net.dom.deleteCookie(sCookieID);
				else
					net.dom.setCookie(sCookieID, 'false', 365);				
			}
			else
				net.setVar('__net_' + sContainerID + '_Visible', 'false');			
		}
		
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

function __net_Help_OnClick(sHelpID)
{
	var oHelp = net.dom.getById(sHelpID);
	if (oHelp != null)
	{
		if (oHelp.style.display == 'none')
			oHelp.style.display = '';
		else
			oHelp.style.display = 'none';

		return true;	//cancel postback
	}
	return false;	//failed so do postback
}

function __net_SectionMaxMin(oBtn, sContentID)
{
	var oContent = net.dom.getById(sContentID);
	if (oContent != null)
	{
		var sMaxIcon = oBtn.getAttribute('max_icon');
		var sMinIcon = oBtn.getAttribute('min_icon');
		if (oContent.style.display == 'none')
		{
			oBtn.src = sMinIcon;				
			oContent.style.display = '';
			net.setVar(oBtn.id + ':exp', 1);
		}
		else
		{
			oBtn.src = sMaxIcon;				
			oContent.style.display = 'none';
			net.setVar(oBtn.id + ':exp', 0);
		}
		return true;	//cancel postback
	}
	return false;	//failed so do postback
}