var dnn;	//should really make this m_dnn... but want to treat like namespace

var DNN_HIGHLIGHT_COLOR = '#9999FF';
var COL_DELIMITER = String.fromCharCode(18);
var ROW_DELIMITER = String.fromCharCode(17);
var QUOTE_REPLACEMENT = String.fromCharCode(19);
var KEY_LEFT_ARROW = 37;
var KEY_UP_ARROW = 38;
var KEY_RIGHT_ARROW = 39;
var KEY_DOWN_ARROW = 40;
var KEY_RETURN = 13;
var KEY_ESCAPE = 27;

if (typeof(__dnn_m_aNamespaces) == 'undefined')	//include in each DNN ClientAPI namespace file for dependency loading
	var __dnn_m_aNamespaces = new Array();

//NameSpace DNN
	function __dnn()
	{
		this.apiversion = .4;
		this.pns = '';
		this.ns = 'dnn';
		this.diagnostics = null;
		this.vars = null;
		this.dependencies = new Array();
		this.isLoaded = false;
		this.delay = new Array();
	}
	
__dnn.prototype = 
{
	getVars: function()
	{
		if (this.vars == null)
		{
			this.vars = new Array();
			var oCtl = dnn.dom.getById('__dnnVariable');
			if (oCtl != null)
			{
				if (oCtl.value.indexOf('__scdoff') != -1)
				{
					//browsers like MacIE don't support char(18) very well... need to use multichars
					COL_DELIMITER = '~|~';
					ROW_DELIMITER = '~`~';
					QUOTE_REPLACEMENT = '~!~';
				}
			
				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;	
	},

	getVar: function(sKey)
	{
		if (this.getVars()[sKey] != null)
		{
			var re = eval('/' + QUOTE_REPLACEMENT + '/g');
			return this.getVars()[sKey].replace(re, '"');
		}
	},

	setVar: function(sKey, sVal)
	{			
		if (this.vars == null)
			this.getVars();			
		this.vars[sKey] = sVal;
		var oCtl = dnn.dom.getById('__dnnVariable');
		if (oCtl == null)
		{
			oCtl = dnn.dom.createElement('INPUT');
			oCtl.type = 'hidden';
			oCtl.id = '__dnnVariable';
			dnn.dom.appendChild(dnn.dom.getByTagName("body")[0], oCtl);		
		}
		var sVals = '';
		var s;
		var re = eval('/"/g');
		for (s in this.vars)
			sVals += ROW_DELIMITER + s + COL_DELIMITER + this.vars[s].toString().replace(re, QUOTE_REPLACEMENT);

		oCtl.value = sVals;
		return true;
	},

	callPostBack: function(sAction)
	{
		var sPostBack = dnn.getVar('__dnn_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));
			return true;
		}
		return false;
	},

    createDelegate: function(oThis, pFunc) 
    {
        return function() {pFunc.apply(oThis, arguments);};
    },

	doDelay: function(sType, iTime, pFunc, oContext) 
	{
		if (this.delay[sType] == null)
		{
			this.delay[sType] = new dnn.delayObject(pFunc, oContext, sType);
			//this.delay[sType].num = window.setTimeout(dnn.dom.getObjMethRef(this.delay[sType], 'complete'), iTime);
			this.delay[sType].num = window.setTimeout(dnn.createDelegate(this.delay[sType], this.delay[sType].complete), iTime);
		}
	},

	cancelDelay: function(sType) 
	{
		if (this.delay[sType] != null)
		{
			window.clearTimeout(this.delay[sType].num);
			this.delay[sType] = null;
		}
	},

	decodeHTML: function(s)	
	{
		return s.toString().replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"');
	},

	encode: function(sArg)
	{
		if (encodeURIComponent)
			return encodeURIComponent(sArg);
		else
			return escape(sArg);
	},

	encodeHTML: function(s)	
	{
		return s.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/\"/g, "&quot;");
	},

	evalJSON: function(s)
	{
		return eval("("+s+")");
	},

	escapeForEval: function(s)	//needs work...
	{
		return s.replace(/\\/g, '\\\\').replace(/\'/g, "\\'").replace(/\r/g, '').replace(/\n/g, '\\n').replace(/\./, '\\.');
	},

	extend: function(dest, src) 
	{
		for (s in src)
			dest[s] = src[s];
		return dest;
	},

	dependenciesLoaded: function()
	{
		return true;
	},


	loadNamespace: function()
	{
		if (this.isLoaded == false)
		{
			if (this.dependenciesLoaded())
			{
				dnn = this; 
				this.isLoaded = true;
				this.loadDependencies(this.pns, this.ns);
			}
		}	
	},

	loadDependencies: function(sPNS, sNS)
	{
		for (var i=0; i<__dnn_m_aNamespaces.length; i++)
		{
			for (var iDep=0; iDep<__dnn_m_aNamespaces[i].dependencies.length; iDep++)
			{
				if (__dnn_m_aNamespaces[i].dependencies[iDep] == sPNS + (sPNS.length>0 ? '.': '') + sNS)
					__dnn_m_aNamespaces[i].loadNamespace();
			}
		}
	}
}	

	__dnn.prototype.delayObject = function(pFunc, oContext, sType)
	{
		this.num = null;
		this.pfunc = pFunc;
		this.context = oContext;
		this.type = sType;
	}

	__dnn.prototype.delayObject.prototype =
	{
		complete: function()
		{
			dnn.delay[this.type] = null;
			this.pfunc(this.context);
		}
	}

	__dnn.prototype.ScriptRequest = function(sSrc, sText, fCallBack)
	{
		this.ctl = null;
		this.xmlhttp = null;
		this.src = null;
		this.text = null;
		if (sSrc != null && sSrc.length > 0)
			this.src = sSrc;
		if (sText != null && sText.length > 0)
			this.text = sText;
		this.callBack = fCallBack;
		this.status = 'init';
		this.timeOut = 5000;
		//this.alreadyLoaded = false;
	}
	__dnn.prototype.ScriptRequest.prototype = 
	{
		load: function()
		{
			this.status = 'loading';
			this.ctl = document.createElement('script');
			this.ctl.type = 'text/javascript';
			if (this.src != null)
			{
				if (dnn.dom.browser.isType(dnn.dom.browser.Safari))
				{
					this.xmlhttp=new XMLHttpRequest();
					this.xmlhttp.open('GET',this.src,true);
					this.xmlhttp.onreadystatechange=dnn.createDelegate(this, this.xmlhttpStatusChange);
					this.xmlhttp.send(null);
					return;
				}
				else
				{
					if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer))
						this.ctl.onreadystatechange = dnn.createDelegate(this, this.statusChange);
					else if (dnn.dom.browser.isType(dnn.dom.browser.Opera) == false)	//opera loads synchronously
						this.ctl.onload = dnn.createDelegate(this, this.complete);
					
					this.ctl.src = this.src;
				}
			}
			else
			{
				if (dnn.dom.browser.isType(dnn.dom.browser.Safari))
					this.ctl.innerHTML = dnn.encodeHTML(this.text);			
				else
					this.ctl.text = this.text;			
			}
						
			var oHeads = dnn.dom.getByTagName('HEAD');
			if (oHeads)
			{
				//opera will load script twice if inline and appended to page 
				if (dnn.dom.browser.isType(dnn.dom.browser.Opera) == false || this.src != null)
					oHeads[0].appendChild(this.ctl);
			}
			else
				alert('Cannot load dynamic script, no HEAD tag present.');
			
			if (this.src == null || dnn.dom.browser.isType(dnn.dom.browser.Opera))	//opera loads script synchronously
				this.complete();
			else if (this.timeOut)
				dnn.doDelay('loadScript_' + this.src, this.timeOut, dnn.createDelegate(this, this.reload), null);
		},

		xmlhttpStatusChange: function()
		{
			if(this.xmlhttp.readyState != 4)
				return;
			
			this.src = null;
			this.text = this.xmlhttp.responseText;
			this.load();	//load as inline script
		},

		statusChange: function()
		{
			if ((this.ctl.readyState == 'loaded' || this.ctl.readyState == 'complete') && this.status != 'complete')
				this.complete();
		},
		
		reload: function()
		{
			//if (dnn.dom.getScript(this.src))
			if (dnn.dom.scriptStatus(this.src) == 'complete')
			{	
				//alert('timeout:  event didnt fire\n' + this.src);
				this.complete();
			}
			else
			{
				//alert('timeout: attempting load\n' + this.src);
				this.load();
			}
		},
				
		complete: function()
		{
			dnn.cancelDelay('loadScript_' + this.src);
			this.status = 'complete';
			//this.ctl.readyState = 'loaded';
			if (typeof(this.callBack) != 'undefined')
				this.callBack(this);
		    this.dispose();			
		},
		
		dispose: function()
		{
			this.callBack = null;
			if (this.ctl)
			{
				if (this.ctl.onreadystatechange)
					this.ctl.onreadystatechange = new function() {};//stop IE memory leak.  Not sure why can't set to null;
				else if (this.ctl.onload)
					this.ctl.onload = null;
				this.ctl = null;
			}
			this.xmlhttp = null;
		}
	}

	//--- dnn.dom
		function dnn_dom()
		{
			this.pns = 'dnn';
			this.ns = 'dom';
			this.dependencies = 'dnn'.split(',');
			this.isLoaded = false;
			this.browser = new this.browserObject();
			this.__leakEvts = new Array();			
			this.scripts = [];
			this.scriptElements = [];
		}

dnn_dom.prototype =
{
		appendChild: function(oParent, oChild) 
		{
			if (oParent.appendChild) 
				return oParent.appendChild(oChild);
			else 
				return null;
		},

		attachEvent: function(oCtl, sType, fHandler) 
		{
			if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer) == false)
			{
				var sName = sType.substring(2);
				oCtl.addEventListener(sName, function(evt) {dnn.dom.event = new dnn.dom.eventObject(evt, evt.target); return fHandler();}, false);
			}
			else
				oCtl.attachEvent(sType, function() {dnn.dom.event = new dnn.dom.eventObject(window.event, window.event.srcElement); return fHandler();});
			return true;
		},		

		createElement: function(sTagName) 
		{
			if (document.createElement) 
				return document.createElement(sTagName.toLowerCase());
			else 
				return null;
		},

		cursorPos: function(oCtl)
		{			
			// empty control means the cursor is at 0
			if (oCtl.value.length == 0)
				return 0;
			
			// -1 for unknown
			var iPos = -1;

			if (oCtl.selectionStart)	// Moz - Opera
				iPos = oCtl.selectionStart;
			else if ( oCtl.createTextRange )// IE
			{
				var oSel = window.document.selection.createRange();
				var oRange = oCtl.createTextRange();
				
				// if the current selection is within the edit control			
				if (oRange == null || oSel == null || (( oSel.text != "" ) && oRange.inRange(oSel) == false))
					return -1;
				
				if (oSel.text == "")
				{
					if (oRange.boundingLeft == oSel.boundingLeft)
						iPos = 0;
					else
					{
						var sTagName = oCtl.tagName.toLowerCase();
						// Handle inputs.
						if (sTagName == "input")
						{
							var sText = oRange.text;
							var i = 1;
							while (i < sText.length)
							{
								oRange.findText(sText.substring(i));
								if (oRange.boundingLeft == oSel.boundingLeft)
									break;
								
								i++;
							}
						}
						// Handle text areas.
						else if (sTagName == "textarea")
						{
							var i = oCtl.value.length + 1;
							var oCaret = document.selection.createRange().duplicate();
							while (oCaret.parentElement() == oCtl && oCaret.move("character",1) == 1)
								--i;
							
							if (i == oCtl.value.length + 1)
								i = -1;
						}
						iPos = i;
					}
				}
				else
					iPos = oRange.text.indexOf(oSel.text);
			}
			return iPos;
		},

		cancelCollapseElement: function(oCtl)
		{
			dnn.cancelDelay(oCtl.id + 'col');
			oCtl.style.display = 'none';
		},
		
		collapseElement: function(oCtl, iNum, pCallBack) 
		{
			if (iNum == null)
				iNum = 10;
			oCtl.style.overflow = 'hidden';
			var oContext = new Object();
			oContext.num = iNum;
			oContext.ctl = oCtl;
			oContext.pfunc = pCallBack;
			oCtl.origHeight = oCtl.offsetHeight;
			dnn.dom.__collapseElement(oContext);
		},
		
		__collapseElement: function(oContext) 
		{
			var iNum = oContext.num;
			var oCtl = oContext.ctl;
			
			var iStep = oCtl.origHeight / iNum;
			if (oCtl.offsetHeight - (iStep*2) > 0)
			{
				oCtl.style.height = (oCtl.offsetHeight - iStep).toString() + 'px';
				dnn.doDelay(oCtl.id + 'col', 10, dnn.dom.__collapseElement, oContext);
			}
			else
			{
				oCtl.style.display = 'none';
				if (oContext.pfunc != null)
					oContext.pfunc();
			}
		},

		cancelExpandElement: function(oCtl)
		{
			dnn.cancelDelay(oCtl.id + 'exp');
			oCtl.style.overflow = '';
			oCtl.style.height = '';			
		},
		
		expandElement: function(oCtl, iNum, pCallBack) 
		{
			if (iNum == null)
				iNum = 10;
			
			if (oCtl.style.display == 'none' && oCtl.origHeight == null)
			{
				oCtl.style.display = '';
				oCtl.style.overflow = '';
				oCtl.origHeight = oCtl.offsetHeight;
				oCtl.style.overflow = 'hidden';
				oCtl.style.height = '1px';
			}
			oCtl.style.display = '';

			var oContext = new Object();
			oContext.num = iNum;
			oContext.ctl = oCtl;
			oContext.pfunc = pCallBack;
			dnn.dom.__expandElement(oContext);
		},

		__expandElement: function(oContext) 
		{
			var iNum = oContext.num;
			var oCtl = oContext.ctl;
			var iStep = oCtl.origHeight / iNum;
			if (oCtl.offsetHeight + iStep < oCtl.origHeight)
			{
				oCtl.style.height = (oCtl.offsetHeight + iStep).toString() + 'px';
				dnn.doDelay(oCtl.id + 'exp', 10, dnn.dom.__expandElement, oContext);
			}
			else
			{
				oCtl.style.overflow = '';
				oCtl.style.height = '';
				if (oContext.pfunc != null)
					oContext.pfunc();
			}				
		},
		
		deleteCookie: function(sName, sPath, sDomain) 
		{
			if (this.getCookie(sName)) 
			{
				this.setCookie(sName, '', -1, sPath, sDomain);
				return true;
			}
			return false;
		},

		getAttr: function(oNode, sAttr, sDef)
		{
			if (oNode.getAttribute == null)
				return sDef;
			var sVal = oNode.getAttribute(sAttr);
			
			if (sVal == null || sVal == '')
				return sDef;
			else
				return sVal;
		},

		getById: function(sID, oCtl)
		{
			if (oCtl == null)
				oCtl = document;
			if (oCtl.getElementById) //(dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer) == false)
				return oCtl.getElementById(sID);
			else if (oCtl.all)
				return oCtl.all(sID);
			else
				return null;
		},

		getByTagName: function(sTag, oCtl)
		{
			if (oCtl == null)
				oCtl = document;
			if (oCtl.getElementsByTagName) //(dnn.dom.browser.type == dnn.dom.browser.InternetExplorer)
				return oCtl.getElementsByTagName(sTag);
			else if (oCtl.all && oCtl.all.tags)
				return oCtl.all.tags(sTag);
			else
				return null;
		},

		getParentByTagName: function(oCtl, sTag)
		{
			var oP = oCtl.parentNode;
			sTag = sTag.toLowerCase();
			while (oP!= null)
			{
				if  (oP.tagName && oP.tagName.toLowerCase() == sTag)
					return oP;
				oP = oP.parentNode;
			}
			return null;
		},

		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);
		},

		getNonTextNode: function(oNode)
		{
			if (this.isNonTextNode(oNode))	
				return oNode;
			
			while (oNode != null && this.isNonTextNode(oNode))
			{
				oNode = this.getSibling(oNode, 1);
			}
			return oNode;
		},

		__leakEvt: function(sName, oCtl, oPtr)
		{
			this.name = sName;
			this.ctl = oCtl;
			this.ptr = oPtr;
		},
		
		addSafeHandler: function(oDOM, sEvent, oObj, sMethod)
		{
			oDOM[sEvent] = this.getObjMethRef(oObj, sMethod);			

			if (dnn.dom.browser.isType(dnn.dom.browser.InternetExplorer))	//handle IE memory leaks with closures
			{
				if (this.__leakEvts.length == 0)
					dnn.dom.attachEvent(window, 'onunload', dnn.dom.destroyHandlers);

				this.__leakEvts[this.__leakEvts.length] = new dnn.dom.__leakEvt(sEvent, oDOM, oDOM[sEvent]);
			}
		},
		
		destroyHandlers: function()	//handle IE memory leaks with closures
		{
			var iCount = dnn.dom.__leakEvts.length-1;
			for (var i=iCount; i>=0; i--)
			{
				var oEvt = dnn.dom.__leakEvts[i];
				oEvt.ctl.detachEvent(oEvt.name, oEvt.ptr);
				oEvt.ctl[oEvt.name] = null;
				dnn.dom.__leakEvts.length = dnn.dom.__leakEvts.length - 1;
			}
		},
		
		//http://jibbering.com/faq/faq_notes/closures.html (associateObjWithEvent)
		getObjMethRef: function(obj, methodName)
		{
			return (function(e)	{e = e||window.event; return obj[methodName](e, this); } );
		},

		getScript: function(sSrc)
		{
			if (this.scriptElements[sSrc]) //perf
				return this.scriptElements[sSrc];
				
			//var oScripts = (document.scripts != null ? document.scripts : dnn.dom.getByTagName('SCRIPT'));
			var oScripts = dnn.dom.getByTagName('SCRIPT');	//safari has document.scripts
			//for (var s in oScripts)
			for (var s=0; s<oScripts.length; s++) //safari
			{
				if (oScripts[s].src != null && oScripts[s].src.indexOf(sSrc) > -1)
				{
					this.scriptElements[sSrc] = oScripts[s];	//cache for perf
					return oScripts[s]; 
				}
			}
		},
		
		getScriptPath: function()
		{
			var oThisScript = dnn.dom.getScript('dnn.js');
			if (oThisScript)
				return oThisScript.src.replace('dnn.js', '');
			return '';
		},

		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];
					}
				}
			}
			return null;
		},
	
		isNonTextNode: function(oNode)
		{
			return (oNode.nodeType != 3 && oNode.nodeType != 8); //exclude nodeType of Text (Netscape/Mozilla) issue!
		},

		scriptFile: function(sSrc)	//trims off path
		{
			var ary = sSrc.split('/');
			return ary[ary.length-1];
		},
	
		loadScript: function(sSrc, sText, callBack)
		{
			var sFile;
			if (sSrc != null && sSrc.length > 0)
			{
				sFile = this.scriptFile(sSrc); 
				if (this.scripts[sFile] != null)	//already loaded
					return;
			}
			var oSR = new dnn.ScriptRequest(sSrc, sText, callBack);
			if (sFile)
				this.scripts[sFile] = oSR;
			oSR.load();
			return oSR;		
		},
		
		loadScripts: function(aSrc, aText, callBack)
		{
			if (dnn.scripts == null)
			{
				var oRef = function(aSrc, aText, callBack) //closure to invoke self with same params when done
							{return (function() {dnn.dom.loadScripts(aSrc, aText, callBack);});};
				dnn.dom.loadScript(dnn.dom.getScriptPath() + 'dnn.scripts.js', null, oRef(aSrc, aText, callBack));
				//dnn.dom.loadScript(dnn.dom.getScriptPath() + 'dnn.scripts.js', null);
				return;
			}
			var oBatch = new dnn.scripts.ScriptBatchRequest(aSrc, aText, callBack);
			oBatch.load();
		},
		
		scriptStatus: function(sSrc)
		{
			var sFile = this.scriptFile(sSrc);
			if (this.scripts[sFile])
				return this.scripts[sFile].status;	//dynamic load
			
			var oScript = this.getScript(sSrc);
			if (oScript != null)	//not a dynamic load, must be complete if found
				return 'complete';
			else
				return '';
		},	
		
		setScriptLoaded: function(sSrc)	//called by pages js that is dynamically loaded.  Needed since Safari doesn't support onload for script elements
		{
			var sFile = this.scriptFile(sSrc);
			if (this.scripts[sFile] && dnn.dom.scripts[sFile].status != 'complete')
				dnn.dom.scripts[sFile].complete();		
		},
				
		navigate: function(sURL, sTarget)
		{
			if (sTarget != null && sTarget.length > 0)
			{
				if (sTarget == '_blank')	//todo: handle more
					window.open(sURL);
				else
					document.frames[sTarget].location.href = sURL;
			}
			else
				window.location.href = sURL;
			return false;
		},
		
		removeChild: function(oChild) 
		{
			if (oChild.parentNode.removeChild) 
				return oChild.parentNode.removeChild(oChild);
			else 
				return null;
		},

		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.toGMTString() : "") + 
				((sPath) ? "; path=" + sPath : "") + ((sDomain) ? "; domain=" + sDomain : "") + ((bSecure) ? "; secure" : "");
			
			if (document.cookie.length > 0)
				return true;
		},

		getCurrentStyle: function(oNode, prop) 
		{
			if (document.defaultView) 
			{
				if (oNode.nodeType != oNode.ELEMENT_NODE) return null;
				return document.defaultView.getComputedStyle(oNode,'').getPropertyValue(prop.split('-').join(''));
			}
			if (oNode.currentStyle) 
				return oNode.currentStyle[prop.split('-').join('')];
			if (oNode.style) 
				return oNode.style.getAttribute(prop.split('-').join(''));  // We need to get rid of slashes
			return null;
		},

		dependenciesLoaded: function()
		{
			return (typeof(dnn) != 'undefined');
		},

		loadNamespace: function()
		{
			if (this.isLoaded == false)
			{
				if (this.dependenciesLoaded())
				{
					dnn.dom = this; 
					this.isLoaded = true;
					dnn.loadDependencies(this.pns, this.ns);
				}
			}	
		},

		getFormPostString: function(oCtl)
		{
			var sRet = '';
			if (oCtl != null)
			{
				if (oCtl.tagName && oCtl.tagName.toLowerCase() == 'form')	//if form, faster to loop elements collection
				{
					for (var i=0; i<oCtl.elements.length; i++)
						sRet += this.getElementPostString(oCtl.elements[i]);					
				}
				else
				{
					sRet = this.getElementPostString(oCtl);
					for (var i=0; i<oCtl.childNodes.length; i++)
						sRet += this.getFormPostString(oCtl.childNodes[i]);	//1.3 fix (calling self recursive insead of elementpoststring)
				}
			}
			return sRet;		
		},
		
		getElementPostString: function(oCtl)
		{
			var sTagName;
			if (oCtl.tagName)
				sTagName = oCtl.tagName.toLowerCase();
				
			if (sTagName == 'input') 
			{
				var sType = oCtl.type.toLowerCase();
				if (sType == 'text' || sType == 'password' || sType == 'hidden' || ((sType == 'checkbox' || sType == 'radio') && oCtl.checked)) 
					return oCtl.name + '=' + dnn.encode(oCtl.value) + '&';
			}
			else if (sTagName == 'select') 
			{
				for (var i=0; i<oCtl.options.length; i++) 
				{
					if (oCtl.options[i].selected) 
						return oCtl.name + '=' + dnn.encode(oCtl.options[i].value) + '&';
				}
			}
			else if (sTagName == 'textarea') 
					return oCtl.name + '=' + dnn.encode(oCtl.value) + '&';
			return '';
		}
}

		dnn_dom.prototype.eventObject = function(e, srcElement)
		{
			this.object = e;
			this.srcElement = srcElement;
		}
		
		//--- dnn.dom.browser
		dnn_dom.prototype.browserObject = function()
		{
			this.InternetExplorer = 'ie';
			this.Netscape = 'ns';
			this.Mozilla = 'mo';
			this.Opera = 'op';
			this.Safari = 'safari';
			this.Konqueror = 'kq';
			this.MacIE = 'macie';
			
			//Please offer a better solution if you have one!
			var sType;
			var agt=navigator.userAgent.toLowerCase();

			if (agt.indexOf('konqueror') != -1) 
				sType = this.Konqueror;
			else if (agt.indexOf('opera') != -1) 
				sType = this.Opera;
			else if (agt.indexOf('netscape') != -1) 
				sType = this.Netscape;
			else if (agt.indexOf('msie') != -1)
			{
				if (agt.indexOf('mac') != -1)
					sType = this.MacIE;
				else
					sType = this.InternetExplorer;
			}
			else if (agt.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]);	
			}
		}
		
dnn_dom.prototype.browserObject.prototype =
{
		toString: function()
		{
			return this.type + ' ' + this.version;
		},
		
		isType: function()
		{
			for (var i=0; i<arguments.length; i++)
			{
				if (dnn.dom.browser.type == arguments[i])
					return true;
			}
			return false;
		}
}	
		//--- End dnn.dom.browser
						
	//--- End dnn.dom

	//--- dnn.controls - not enough here to justify separate js file	
	function dnn_controls()
	{
		this.pns = 'dnn';
		this.ns = 'controls';
		this.dependencies = 'dnn,dnn.dom'.split(',');	//,dnn.xml - removed 10/17/06
		this.isLoaded = false;
		this.controls = new Array();
		this.toolbars = [];	//stores JSON toolbar objects
		
		this.orient = new Object();
		this.orient.horizontal = 0;
		this.orient.vertical = 1;
		
		this.action = new Object();
		this.action.postback = 0;
		this.action.expand = 1;
		this.action.none = 2;
		this.action.nav = 3;
	}

dnn_controls.prototype = 
{
	dependenciesLoaded: function()
	{
		return (typeof(dnn) != 'undefined' && typeof(dnn.dom) != 'undefined');	//removed && typeof(dnn.xml) != 'undefined' - 10/17/06
	},

	loadNamespace: function()
	{
		if (this.isLoaded == false)
		{
			if (this.dependenciesLoaded())
			{				
				if (typeof(dnn_control) != 'undefined')
					dnn.extend(dnn_controls.prototype, new dnn_control);

				dnn.controls = new dnn_controls(); 	
				this.isLoaded = true;
				dnn.loadDependencies(this.pns, this.ns);
			}
		}	
	}
}
	dnn_controls.prototype.DNNNode = function(oNode)
	{
		if (oNode != null)
		{
			this.node = oNode; 
			this.id = oNode.getAttribute('id', '');
			this.key = oNode.getAttribute('key', '');
			this.text = oNode.getAttribute('txt', '');
			this.url = oNode.getAttribute('url', '');
			this.js = oNode.getAttribute('js', '');
			this.target = oNode.getAttribute('tar', '');
			this.toolTip = oNode.getAttribute('tTip', '');
			this.enabled = oNode.getAttribute('enabled', '1') != '0';
			this.css = oNode.getAttribute('css', '');
			this.cssSel = oNode.getAttribute('cssSel', '');
			this.cssHover = oNode.getAttribute('cssHover', '');
			this.cssIcon = oNode.getAttribute('cssIcon', '');
			this.hasNodes = oNode.childNodeCount() > 0;	
			this.hasPendingNodes = (oNode.getAttribute('hasNodes', '0') == '1' && this.hasNodes == false);	
			this.imageIndex = new Number(oNode.getAttribute('imgIdx', '-1')); 
			this.image = oNode.getAttribute('img', '');
			this.level = this.getNodeLevel();	//cache
		}
	}
dnn_controls.prototype.DNNNode.prototype = 
{
	childNodeCount: function()
	{
		return this.node.childNodes.length;
	},
	getNodeLevel: function()
	{
		var i=0;
		var oNode = this.node;
		while (oNode != null)
		{
			oNode = oNode.parentNode();
			if (oNode == null || oNode.nodeName() == 'root')
				break;
			i++;
		}	
		return i;
	},
	update: function(sProp)
	{
		if (sProp != null)
		{
			var sType = typeof(this[sProp]);
			
			if (sType == 'string' || sType == 'number' || this[sProp] == null)
				this.node.setAttribute(sProp, this[sProp]);
			else if (sType == 'boolean')
				this.node.setAttribute(sProp, new Number(this[sProp]));
		}
		else
		{
			for (sProp in this)
				this.update(sProp);
		}
	}
}//END DNNNode Methods
	
//--- End dnn.controls

	//--- dnn.utilities
	function dnn_util()
	{
		this.pns = 'dnn';
		this.ns = 'utilities';
		this.dependencies = 'dnn,dnn.dom'.split(',');
		this.isLoaded = false;
	}

	dnn_util.prototype.dependenciesLoaded = function()
	{
		return (typeof(dnn) != 'undefined' && typeof(dnn.dom) != 'undefined');
	}

	dnn_util.prototype.loadNamespace = function()
	{
		if (this.isLoaded == false)
		{
			if (this.dependenciesLoaded())
			{				
				if (typeof(dnn_utility) != 'undefined')
					dnn.extend(dnn_util.prototype, new dnn_utility);

				dnn.util = new dnn_util(); 	
				this.isLoaded = true;
				dnn.loadDependencies(this.pns, this.ns);
			}
		}	
	}
	//--- End dnn.utilities
	
//--- End dnn

//-- prototype/atlas shorthand functions
function $() 
{
  var ary = new Array();
  for (var i=0; i<arguments.length; i++) 
  {
    var arg = arguments[i];
    var ctl;
    if (typeof arg == 'string')
      ctl = dnn.dom.getById(arg);
    else
      ctl = arg;

    if (ctl != null && typeof(Element) != 'undefined' && typeof(Element.extend) != 'undefined')   //if prototype loaded, we must extend the object
        Element.extend(ctl);
        
    if (arguments.length == 1)
      return ctl;

    ary[ary.length] = ctl;
  }
  return ary;
}

//load namespaces
__dnn_m_aNamespaces[__dnn_m_aNamespaces.length] = new dnn_util();
__dnn_m_aNamespaces[__dnn_m_aNamespaces.length] = new dnn_controls();
__dnn_m_aNamespaces[__dnn_m_aNamespaces.length] = new dnn_dom();
__dnn_m_aNamespaces[__dnn_m_aNamespaces.length] = new __dnn();
for (var i=__dnn_m_aNamespaces.length-1; i>=0; i--)
	__dnn_m_aNamespaces[i].loadNamespace();


// CMS Portal

function __ShowDiv(obj)
{
    eval("document.all."+obj+".style.visibility='visible'");
}

function __HideDiv(obj)
{
    eval("document.all."+obj+".style.visibility='hidden'");
}

var lastDiv = "divInfo";
function ___ShowDiv(obj)
{
    eval("document.all."+obj+".style.display=''");
    if (lastDiv!="" && lastDiv!=obj)
        ___HideDiv(lastDiv);
    lastDiv = obj;
}

function ___HideDiv(obj)
{
    eval("document.all."+obj+".style.display='none'");
}


var offsetfromcursorX=10 //Customize x offset of tooltip
var offsetfromcursorY=20 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)

//var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(tipobj, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
enabletip=true
return false
}
}

function __ShowTip(e, divobj, thewidth, thecolor){
tipobj = document.getElementById(divobj);
ddrivetip(tipobj, thewidth, thecolor);
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
//pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
//pointerobj.style.top=curY+offsetfromcursorY+"px"
}

tipobj.style.visibility="visible"
//if (!nondefaultpos)
//pointerobj.style.visibility="visible"
//else
//pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(divobj){
tipobj = document.getElementById(divobj);
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
//pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.width=''
}
}


/* Slide Content */

var featuredcontentslider={

//3 variables below you can customize if desired:
ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
bustajaxcache: true, //bust caching of external ajax page after 1st request?
enablepersist: true, //persist to last content viewed when returning to page?

ajaxconnect:function(setting){
	var page_request = false
	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else
		return false
	var pageurl=setting.contentsource[1]
	page_request.onreadystatechange=function(){
		featuredcontentslider.ajaxpopulate(page_request, setting)
	}
	document.getElementById(setting.id).innerHTML=this.ajaxloadingmsg
	var bustcache=(!this.bustajaxcache)? "" : (pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', pageurl+bustcache, true)
	page_request.send(null)
},

ajaxpopulate:function(page_request, setting){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(setting.id).innerHTML=page_request.responseText
		this.buildpaginate(setting)
	}
},

buildcontentdivs:function(setting){
	var alldivs=document.getElementById(setting.id).getElementsByTagName("div")
	for (var i=0; i<alldivs.length; i++){
		if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"
			setting.contentdivs.push(alldivs[i])
		}
	}
},

buildpaginate:function(setting){
	this.buildcontentdivs(setting)
	var sliderdiv=document.getElementById(setting.id)
	var pdiv=document.getElementById("paginate-"+setting.id)
	var phtml=""
	var toc=setting.toc
	var nextprev=setting.nextprev
	if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){
		phtml= '<div align="left"><span id=obj'+setting.id+'>' + setting.currentpage + '</span>/ ' + setting.contentdivs.length + '&nbsp;&nbsp;' + (nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + '<a href="#next" class="next">'+nextprev[2]+'</a>' + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '') + '</div>'
		pdiv.innerHTML=phtml
	}
	var pdivlinks=pdiv.getElementsByTagName("a")
	var toclinkscount=0 //var to keep track of actual # of toc links
	for (var i=0; i<pdivlinks.length; i++){
		if (this.css(pdivlinks[i], "toc", "check")){
			if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)
				pdivlinks[i].style.display="none" //hide this toc link
				continue
			}
			pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link
			pdivlinks[i].onclick=function(){
				featuredcontentslider.turnpage(setting, this.getAttribute("rel"))
				return false
			}
			setting.toclinks.push(pdivlinks[i])
		}
		else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"
			pdivlinks[i].onclick=function(){
				featuredcontentslider.turnpage(setting, this.className)
				return false
			}
		}
	}
	this.turnpage(setting, setting.currentpage, true)
	if (setting.autorotate[0]){
		pdiv.onclick=function(){
			featuredcontentslider.cleartimer(window["fcsautorun"+setting.id])
		}
		sliderdiv.onclick=function(){
			featuredcontentslider.cleartimer(window["fcsautorun"+setting.id])
		}
		setting.autorotate[1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation
	 this.autorotate(setting)
	}
},

turnpage:function(setting, thepage, autocall){
	var currentpage=setting.currentpage //current page # before change
	var totalpages=setting.contentdivs.length
	var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)
	turntopage=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust
	if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly
		return
	eval('document.all.obj'+setting.id+'.innerHTML='+ turntopage);
	setting.currentpage=turntopage
	setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex
	this.cleartimer(window["fcsfade"+setting.id])
	if (setting.enablefade[0]==true){
		setting.curopacity=0
		setting.cacheprevpage=setting.prevpage
		this.fadeup(setting)
	}
	if (setting.enablefade[0]==false) //if fade is disabled, fire onChange event immediately (verus after fade is complete)
		setting.onChange(setting.prevpage, setting.currentpage)
	setting.contentdivs[turntopage-1].style.visibility="visible"
	if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
		this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")
	if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
		this.css(setting.toclinks[turntopage-1], "selected", "add")
	setting.prevpage=turntopage
	if (this.enablepersist)
		this.setCookie("fcspersist"+setting.id, turntopage)
},

setopacity:function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	var targetobject=setting.contentdivs[setting.currentpage-1]
	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
		if (typeof targetobject.filters[0].opacity=="number") //IE6
			targetobject.filters[0].opacity=value*100
		else //IE 5.5
			targetobject.style.filter="alpha(opacity="+value*100+")"
	}
	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
		targetobject.style.MozOpacity=value
	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
		targetobject.style.opacity=value
	setting.curopacity=value
},

fadeup:function(setting){
	if (setting.curopacity<1){
		this.setopacity(setting, setting.curopacity+setting.enablefade[1])
		window["fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 50)
	}
	else
		setting.onChange(setting.cacheprevpage, setting.currentpage)
},

cleartimer:function(timervar){
	if (typeof timervar!="undefined"){
		clearTimeout(timervar)
		clearInterval(timervar)
	}
},

css:function(el, targetclass, action){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	if (action=="check")
		return needle.test(el.className)
	else if (action=="remove")
		el.className=el.className.replace(needle, "")
	else if (action=="add")
		el.className+=" "+targetclass
},

autorotate:function(setting){
 window["fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value){
	document.cookie = name+"="+value
},


init:function(setting){
	var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
	setting.contentdivs=[]
	setting.toclinks=[]
	setting.topzindex=0
	setting.currentpage=(this.enablepersist)? persistedpage : 1
	setting.prevpage=setting.currentpage
	setting.curopacity=0
	setting.onChange=setting.onChange || function(){}
	if (setting.contentsource[0]=="inline")
		this.buildpaginate(setting)
	if (setting.contentsource[0]=="ajax")
		this.ajaxconnect(setting)
}

}
var ___objImg = new __dnnViewImage();

var lastObject = '';
function _____showSubMainMenu(obj)
{
    try
    {
	    var sobject = document.getElementById(obj);
	    sobject.style.visibility='visible';
    	
	    if(obj!=lastObject)
        {
            if(lastObject!='') 	document.getElementById(lastObject).style.visibility='hidden';
            lastObject = obj;
	        var offsetfromcursorX=80 //Customize x offset of tooltip
            var offsetfromcursorY=20 //Customize y offset of tooltip

            var offsetdivfrompointerX=40 //Customize x offset of tooltip DIV relative to pointer image
            var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

            var ie=document.all
            var ns6=document.getElementById && !document.all
        	
	        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        	
	        var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
            var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

            var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
            var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

            var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

            //if the horizontal distance isn't enough to accomodate the width of the context menu
            if (rightedge<sobject.offsetWidth){
                //move the horizontal position of the menu to the left by it's width
                sobject.style.left=(curX+20)-sobject.offsetWidth+"px"
            }
            else
                if (curX<leftedge)
                    sobject.style.left="5px"
         }   
    }
    catch(err)
    {
        //
    }
}
function _____hideSubMainMenu()
{
    if(lastObject!='') document.getElementById(lastObject).style.visibility='hidden';
}

var lastChildObject = '';
function _____showSubChildMainMenu(obj)
{
	var sobject = document.getElementById(obj);
	sobject.style.visibility='visible';
	lastChildObject = obj;
}	

function _____hideSubChildMainMenu()
{
    if(lastChildObject!='') document.getElementById(lastChildObject).style.visibility='hidden';
}

var objHTML = "";
var cboTab = 1;
function _____ListAjaxTab(position, moduleId, portalId)
{
    cboTab = eval("currentTab_"+moduleId);
    cssName = eval("cssTab_"+moduleId);
    if (cboTab==position) return;
    try
    {
        eval("_____ThemeForTab_"+moduleId+"("+cboTab+","+position+","+moduleId+")");
    }
    catch(err)
    {
        document.getElementById("TabItem_"+moduleId+"_"+position).className = cssName+'Selected';
        document.getElementById("TabItem_"+moduleId+"_"+cboTab).className = cssName;
    }
    if(position==1) 
    {
        document.getElementById("AjaxList_1"+moduleId).style.display='';
        document.getElementById("AjaxList"+moduleId).style.display='none';
    }
    else
    {
        document.getElementById("AjaxList_1"+moduleId).style.display='none';
        objHTML = document.getElementById("AjaxList"+moduleId);
        objHTML.style.display='';
        objHTML.innerHTML = "<h2 style='color:red; padding-top:10px; padding-left:10px;'>Loading...</h2>";
        AjaxNamespaceClientScript.AjaxTabList(position, moduleId, portalId, getServerAjaxList_callback);
    }
    eval("currentTab_"+moduleId+"="+position);
}

function ______ListAjaxTab(position, moduleId, portalId)
{
    cboTab = eval("currentTab_"+moduleId);
    cssName = eval("cssTab_"+moduleId);
    if (cboTab==position) return;
    try
    {
        eval("_____ThemeForTab_"+moduleId+"("+cboTab+","+position+","+moduleId+")");
    }
    catch(err)
    {
        document.getElementById("TabItem_"+moduleId+"_"+position).className = cssName+'Selected';
        document.getElementById("TabItem_"+moduleId+"_"+cboTab).className = cssName;
    }
    if(position==1) 
    {
        document.getElementById("AjaxList_1"+moduleId).style.display='';
        document.getElementById("AjaxList"+moduleId).style.display='none';
    }
    else
    {
        document.getElementById("AjaxList_1"+moduleId).style.display='none';
        objHTML = document.getElementById("AjaxList"+moduleId);
        objHTML.style.display='';
        objHTML.innerHTML = "<h2 style='color:red; padding-top:10px; padding-left:10px;'>Loading...</h2>";
        AjaxProductClientScript.AjaxTabList(position, moduleId, portalId, getServerAjaxList_callback);
    }
    eval("currentTab_"+moduleId+"="+position);
}

//Display view mode 1: List, 2: Grid, 3: Text;
function _______ListAjaxTab(position, catId, page, moduleId, portalId)
{
    cboTab = eval("currentTab_"+moduleId);
    cssName = eval("cssTab_"+moduleId);
    if (cboTab==position) return;
    try
    {
        eval("_____ThemeForTab_"+moduleId+"("+cboTab+","+position+","+moduleId+")");
    }
    catch(err)
    {
        document.getElementById("TabItem_"+moduleId+"_"+position).className = cssName+'Selected';
        document.getElementById("TabItem_"+moduleId+"_"+cboTab).className = cssName;
    }
    
    if(position==1) 
    {
        document.getElementById("AjaxList_1"+moduleId).style.display='';
        document.getElementById("AjaxList"+moduleId).style.display='none';
    }
    else
    {
        var ViewMode = 'ProductList';
        switch(position)
        {
            case 1:
                ViewMode = 'ModeList';
                break;
            case 3:
                ViewMode = 'ModeText';
        }

        document.getElementById("AjaxList_1"+moduleId).style.display='none';
        objHTML = document.getElementById("AjaxList"+moduleId);
        objHTML.style.display='';
        objHTML.innerHTML = "<h2 style='color:red; padding-top:10px; padding-left:10px;'>Loading...</h2>";
        AjaxProductClientScript.AjaxDisplayList(catId, page, moduleId, portalId, ViewMode, getServerAjaxList_callback);
    }
    eval("currentTab_"+moduleId+"="+position);
}


function getServerAjaxList_callback(res)
{
    if (res.error!=null)
    {
        alert(res.error.Message);
    }
    else
        objHTML.innerHTML = res.value;
}

var intView=1;

function _____RssList(moduleId, portalId)
{
    var intTime=0;
    intTime = setTimeout('_____AjaxShow('+moduleId+', '+portalId+', '+ intTime +')',5000);
}

var objhtml = "";
function _____AjaxShow(moduleId, portalId, intTime)
{
    try
    {
        objhtml = document.getElementById("rss_"+moduleId);
        objhtml.innerHTML = AjaxRssClientScript.LoadRss(moduleId, portalId).value;
        clearTimeout(intTime);
    }
    catch(err)
    {
        alert(err.message)
    }
}

function getServerSupportList_callback(res)
{
    if (res.error!=null)
    {
        alert(res.error.Message);
    }
    else
        objhtml.innerHTML = res.value;
}

function objImgAdd(id, strImg)
{
    i++;
    ___ThumbID[i] = id;
    ___ThumbSrc[i]= strImg;   
}

function ViewImage(id)
{
    try
    {
        document.getElementById(id).src = document.getElementById(id).name;
    }
    catch(err)
    {
        //nothing
    }
} 

var lastGalleryId=1;
function ___Gallery(id)
{
    if(id==lastGalleryId) return;
    document.getElementById('gallery_'+id).style.display='';
    document.getElementById('galleryImgItem_'+id).src = document.getElementById('galleryImgItem_'+id).name
    document.getElementById('GalleryItemIndex'+id).className = 'cssGalleryIndexSelected';
    document.getElementById('gallery_'+lastGalleryId).style.display='none';
    document.getElementById('GalleryItemIndex'+lastGalleryId).className = 'cssGalleryIndex';
    lastGalleryId = id;
}

function ___GalleryNext()
{
    try
    {
        document.getElementById('gallery_'+lastGalleryId).style.display='none';
        document.getElementById('GalleryItemIndex'+lastGalleryId).className = 'cssGalleryIndex';
        lastGalleryId ++;
        document.getElementById('gallery_'+lastGalleryId).style.display='';
        document.getElementById('galleryImgItem_'+lastGalleryId).src = document.getElementById('galleryImgItem_'+lastGalleryId).name
        document.getElementById('GalleryItemIndex'+lastGalleryId).className = 'cssGalleryIndexSelected';
    }
    catch(err)
    {
        document.getElementById('gallery_1').style.display='none';
        document.getElementById('GalleryItemIndex1').className = 'cssGalleryIndex';
        document.getElementById('gallery_1').style.display='';
        document.getElementById('galleryImgItem_1').src = document.getElementById('galleryImgItem_1').name
        document.getElementById('GalleryItemIndex1').className = 'cssGalleryIndexSelected';
        lastGalleryId = 1;
    }
    
}

function ___GalleryPreviou()
{
     try
    {
        document.getElementById('gallery_'+lastGalleryId).style.display='none';
        document.getElementById('GalleryItemIndex'+lastGalleryId).className = 'cssGalleryIndex';
        lastGalleryId --;
        document.getElementById('gallery_'+lastGalleryId).style.display='';
        document.getElementById('galleryImgItem_'+lastGalleryId).src = document.getElementById('galleryImgItem_'+lastGalleryId).name
        document.getElementById('GalleryItemIndex'+lastGalleryId).className = 'cssGalleryIndexSelected';
    }
    catch(err)
    {
        document.getElementById('gallery_1').style.display='none';
        document.getElementById('GalleryItemIndex1').className = 'cssGalleryIndex';
        document.getElementById('gallery_1').style.display='';
        document.getElementById('galleryImgItem_1').src = document.getElementById('galleryImgItem_1').name
        document.getElementById('GalleryItemIndex1').className = 'cssGalleryIndexSelected';
        lastGalleryId = 1;
    }   
}

var galleryInterVal = 0;
function ___GalleryPlay()
{
    if(galleryInterVal>0)
    {
        document.getElementById('galleryButton').src = document.getElementById('galleryButton').name.replace('play', 'pause');
        clearInterval(galleryInterVal);
        galleryInterVal = 0;
    }
    else
    {
        document.getElementById('galleryButton').src = document.getElementById('galleryButton').name;
        galleryInterVal = self.setInterval("___GalleryNext()", 3500);
    }
}

var lastSlideItem = 0;
function ___SlideNext()
{
    try
    {
        if(lastSlideItem>0) document.getElementById('divSlide_'+(lastSlideItem-1)).className = 'cssSlideItem';
        document.getElementById('HeadlineSlideItem').innerHTML = document.getElementById('slidelnkItem_'+lastSlideItem).title
        document.getElementById('lnkSlideItem').title = document.getElementById('slidelnkItem_'+lastSlideItem).href
        document.getElementById('lnkSlideItem').href = document.getElementById('slidelnkItem_'+lastSlideItem).href
        document.getElementById('galleryWindowView').src = document.getElementById('slideItem_'+lastSlideItem).name
        document.getElementById('divSlide_'+lastSlideItem).className = 'cssSlideItemSelected';
        lastSlideItem++;
    }
    catch(err)
    {
        lastSlideItem = 0;
        document.getElementById('HeadlineSlideItem').innerHTML = document.getElementById('slidelnkItem_'+lastSlideItem).title
        document.getElementById('lnkSlideItem').title = document.getElementById('slidelnkItem_'+lastSlideItem).href
        document.getElementById('lnkSlideItem').href = document.getElementById('slidelnkItem_'+lastSlideItem).href
        document.getElementById('galleryWindowView').src = document.getElementById('slideItem_'+lastSlideItem).name
        document.getElementById('divSlide_'+lastSlideItem).className = 'cssSlideItemSelected';
    }
    //setTimeout("fade('fadeBlock')", 2600);
}

var slideInterVal = 0;
function ___SlideGallery()
{
    slideInterVal = self.setInterval("___SlideNext()", 3600);
}

function ___SlidePause()
{
    if(slideInterVal>0) clearInterval(slideInterVal);
}

var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime()
        + ",'" + eid + "')", 33);
  } 
}

function animateFade(lastTick, eid)
{ 
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter =
      'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick
      + ",'" + eid + "')", 33);
}

/* Modified to support Opera */
function bookmarksite(){
if (window.sidebar) // firefox
	window.sidebar.addPanel(document.title, location.href, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',location.href);
	elem.setAttribute('title',document.title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(location.href, document.title);
}

var ____productAddition = "";
function ____showAdditional(id, viewMode)
{
    if(____productAddition==id)
    {
        document.getElementById("additional"+viewMode+id).style.display = 'none';
        document.getElementById("iconpm"+viewMode+id).src= '/Portals/13/plus.gif';
        ____productAddition = "";
    }
    else
    {
        document.getElementById("additional"+viewMode+id).style.display='';
        document.getElementById("iconpm"+viewMode+id).src= '/Portals/13/minus.gif';
        ____productAddition = id;
    }
}