
function PTPMAction(confirmMessage)
{
	this.confirmMessage = (confirmMessage) ? confirmMessage : '';
	return this;
}

PTPMAction.TYPE_GET_XML		= 'PTPMHTTPGetXMLAction';
PTPMAction.TYPE_JAVASCRIPT	= 'PTPMJavaScriptAction';
PTPMAction.TYPE_URL			= 'PTPMURLAction';
PTPMAction.TYPE_ACTION_CHAIN	= 'PTPMActionChain';
PTPMAction.prototype.getHref = function (TokenObjects)
{
	if (this.type == PTPMAction.TYPE_URL)
	{
		var t = PTPMTokenizer.parseTokens(this.URL,TokenObjects,false,PTPMTokenizer.ESCAPE);
		return t;
	}
	else if (this.type == PTPMAction.TYPE_JAVASCRIPT)
	{
		return '#';
	}
	else if (this.type == PTPMAction.TYPE_GET_XML)
	{
		return '#';
	}
	else if (this.type == PTPMAction.TYPE_ACTION_CHAIN)
	{
		return '#';
	}
}

PTPMAction.prototype.getOnclick = function (TokenObjects,ignoreConfirm,cancelEvent,loadMessageCommand,cancelEscape)
{
	var onclickTxt = '';
	var doConfirm = ((this.confirmMessage.length > 0) && !ignoreConfirm);
	if (doConfirm)
	{
		var cmDeTokenized = PTPMTokenizer.parseTokens(this.confirmMessage,TokenObjects);
		if (cancelEvent)
		{
			if (!loadMessageCommand) { var loadMessageCancelCommand = ''; }
			else
			{
				var loadMessageCancelCommand = new String(loadMessageCommand);
				if (loadMessageCancelCommand.lastIndexOf(')') != (loadMessageCancelCommand.length - 1)) { loadMessageCancelCommand += '(false)'; }
			}
			onclickTxt += 'if (!confirm(\'' + cmDeTokenized + '\')) { ' + loadMessageCancelCommand + ';return false; }';
		}
		else
		{
			onclickTxt += 'if (confirm(\'' + cmDeTokenized + '\')) { ';
		}
	}
	if (!cancelEvent) { cancelEvent = false; }
	if (this.type == PTPMAction.TYPE_URL)
	{
		if (this.target && (this.target.length > 0))
		{
			onclickTxt += 'try {';
			onclickTxt +=	 'if (!window.' + this.target + ') {';
			onclickTxt +=		 'window.' + this.target + ' = window.open(\'about:blank\',\'' + this.target + '\');';
			onclickTxt +=	 '}';
			onclickTxt +=	 'window.' + this.target + '.document.location.href=\'' + this.getHref(TokenObjects) + '\';';
			onclickTxt += '} catch(e) {';
			onclickTxt +=	 'var xmlw = window.open(\'about:blank\',\'_blank\');';
			onclickTxt +=	 'xmlw.document.location.href = \'' + action.getHref(TokenObjects) + '\';';
			onclickTxt += '}';
		}
		else
		{
			var href = this.getHref(TokenObjects);
			if (href.indexOf('javascript:') == 0)
			{
				onclickTxt += href.substring(11);
			}
			else
			{
				onclickTxt += 'document.location.href=\'' + href + '\'';
			}
		}
	}
	else if (this.type == PTPMAction.TYPE_JAVASCRIPT)
	{
		onclickTxt += PTPMTokenizer.parseTokens(this.js,TokenObjects,false,PTPMTokenizer.JAVASCRIPT_ESCAPE);
		if (cancelEvent) { onclickTxt += ';return false'; }
		var hash = { '"' : '&quot;' }
		if (!cancelEscape) { onclickTxt = PTStringUtil.substituteChars(onclickTxt,hash); }
	}
	else if (this.type == PTPMAction.TYPE_GET_XML)
	{
		var deTokenized = PTPMTokenizer.parseTokens(this.URL,TokenObjects,false,PTPMTokenizer.ESCAPE);
		if (!loadMessageCommand) { loadMessageCommand = ''; }
		var props = '{';
		var hasProps = false;
		for (var p in this.properties)
		{
			props += '\'' + p + '\':\'' + this.properties[p] + '\',';
			hasProps = true;
		}
		if (hasProps) { props = props.substr(0,(props.length - 1)); }  
		props += '}';
		onclickTxt += '(new PTHTTPGETRequest(\'' + deTokenized + '\',\'' + this.callback + '\',false,' + props + ')).invoke(\'' + loadMessageCommand + '\')';
		if (cancelEvent) { onclickTxt += ';return false'; }
	}
	else if (this.type == PTPMAction.TYPE_ACTION_CHAIN)
	{
		var numActions = this.actions.length;
		for (var a = 0; a < numActions; a++)
		{
			var action = this.actions[a];
			if (this.callback) { action.callback = this.callback; }
			onclickTxt += action.getOnclick(TokenObjects,ignoreConfirm,false,loadMessageCommand,cancelEscape);
			if (a < (this.actions.length - 1)) { onclickTxt += ';'; }
		}
		if (cancelEvent) { onclickTxt += ';return false'; }
	}
	if (doConfirm && !cancelEvent) { onclickTxt += ' }'; }
	return onclickTxt;
}

PTPMAction.prototype.invoke = function()
{
	if (this.onclick) { eval(this.onclick); }
}

function PTPMHTTPGetXMLAction(URL,callback,isGatewayed)
{
	this.URL			= (URL) ? URL : '';
	this.callback		= (callback) ? callback : false;
	this.isGatewayed	= (isGatewayed) ? isGatewayed : false;
	this.properties		= {};
	this.type			= PTPMAction.TYPE_GET_XML;
	this.className		= 'PTPMHTTPGetXMLAction';
	return this;
}

PTPMHTTPGetXMLAction.prototype = new PTPMAction();
PTPMHTTPGetXMLAction.prototype.constructor = PTPMHTTPGetXMLAction;
PTPMHTTPGetXMLAction.prototype._super = PTPMAction;
PTPMHTTPGetXMLAction.prototype.toString = function() { return this.URL; }
function PTPMJavaScriptAction(js)
{
	this.js 		= (js) ? js : '';
	this.type		= PTPMAction.TYPE_JAVASCRIPT;
	this.className	= 'PTPMJavaScriptAction';
	return this;
}

PTPMJavaScriptAction.prototype = new PTPMAction();
PTPMJavaScriptAction.prototype.constructor = PTPMJavaScriptAction;
PTPMJavaScriptAction.prototype._super = PTPMAction;
PTPMJavaScriptAction.prototype.toString = function() { return this.js; }
function PTPMURLAction(URL,target,isGatewayed)
{
	this.URL			= (URL) ? URL : '';
	this.target			= (target) ? target : '';
	this.isGatewayed	= (isGatewayed) ? isGatewayed : false;
	this.type			= PTPMAction.TYPE_URL;
	this.className		= 'PTPMURLAction';
	return this;
}

PTPMURLAction.prototype = new PTPMAction();
PTPMURLAction.prototype.constructor = PTPMURLAction;
PTPMURLAction.prototype._super = PTPMAction;
PTPMURLAction.prototype.toString = function() { return this.URL; }
function PTPMActionChain(actions)
{
	this.actions		= (actions) ? actions : new Array();
	this.type			= PTPMAction.TYPE_ACTION_CHAIN;
	this.className		= 'PTPMActionChain';
	return this;
}

PTPMActionChain.prototype = new PTPMAction();
PTPMActionChain.prototype.constructor = PTPMActionChain;
PTPMActionChain.prototype._super = PTPMAction;
PTPMActionChain.prototype.toString = function() { return '[object Action Chain (' + this.actions.length + ' actions)]'; }
function PTPMImage(imgSrc,imgWidth,imgHeight,tooltip,altText,border,align,customStyle)
{
	this.imgSrc 			= (imgSrc) ? imgSrc : '';
	this.imgWidth			= (imgWidth) ? new String(imgWidth) : '';
	this.imgHeight			= (imgHeight) ? new String(imgHeight) : '';
	this.tooltip			= (tooltip) ? tooltip : '';
	this.altText			= (altText) ? altText : '';
	this.border				= (border) ? border : 0;
	this.align				= (align) ? align : false;
	this.customStyle		= (customStyle) ? customStyle : false;
	this.imgId				= 'PTImg_' + PTPMImage.ITEM_INDEX++;
	this.className			= 'PTPMImage';
	return this;
}

if (!PTPMImage.ITEM_INDEX) { PTPMImage.ITEM_INDEX = 0; }
PTPMImage.prototype.genHTML = function(customStyle, tooltip)
{
	var html = '';
	if (customStyle) {  customStyle = ' style="' + customStyle + '"'; }
	else if (this.customStyle) {  customStyle = ' style="' + this.customStyle + '"'; }
	else { customStyle = ''; }
	var heightText 	= '';
	if (this.imgHeight.length > 0)
	{
		heightText = ' height="' + this.imgHeight + '"';
	}
	var widthText	= '';
	if (this.imgWidth.length > 0)
	{
		widthText = ' width="' + this.imgWidth + '"';
	}
	var tooltipText = '';
	if (tooltip && (tooltip.length > 0))
	{
		tooltipText = ' title="' + tooltip + '"';
	}
	else if (this.toolTip && (this.toolTip.length > 0))
	{
		tooltipText = ' title="' + this.tooltip + '"';
	}
	var altText = '';
	if (this.altText && (this.altText.length > 0))
	{
		altText = ' alt="' + this.altText + '"';
	}
	var align = 'absmiddle';
	if (this.align) { align = this.align; }
	var alignment = ' align="' + align + '"';
	html += '<img id="' + this.imgId + '" src="' + this.imgSrc + '"' + tooltipText + heightText + widthText + ' border="' + this.border + '"' + alignment + altText + customStyle + '/>';
	return html;
}

function PTPMTokenizer()
{
	return this;
}

PTPMTokenizer.NativeObjects =
{
	'DOCUMENT'	: document,
	'TOP'		: top,
	'MATH'		: Math,
	'NAVIGATOR'	: navigator,
	'WINDOW'	: window
}

PTPMTokenizer.startMarker = '${';
PTPMTokenizer.endMarker = '}';
PTPMTokenizer.ESCAPE = 1;
PTPMTokenizer.DOUBLE_ESCAPE = 2;
PTPMTokenizer.JAVASCRIPT_ESCAPE = 3;
PTPMTokenizer.parseTokens = function(inputText,TokenObjects,returnTokensOnly,escapeHow)
{
	var sb = new PTStringBuffer();
	inputText = new String(inputText);
	var tokens = new Array();
	if (!TokenObjects) { TokenObjects = {}; }
	while ( (inputText.indexOf(PTPMTokenizer.startMarker) > -1) && (inputText.indexOf(PTPMTokenizer.endMarker) > -1) ) {
		var start = inputText.indexOf(PTPMTokenizer.startMarker);
		var end	= inputText.indexOf(PTPMTokenizer.endMarker);
		sb.append( inputText.substring(0,start) );
		var token = new String(inputText.substring(start + PTPMTokenizer.startMarker.length,end));
		var literal = PTPMTokenizer.startMarker + token + PTPMTokenizer.endMarker;
		if ((token.length > 0)) {
			var dot = token.indexOf('.');
			var objName = token;
			var cmdText = '';
			if (dot > -1)
			{
				cmdText = token.substr(dot + 1);
				objName = token.substring(0,dot);
			}
			if (returnTokensOnly) {
				tokens[tokens.length] = new PTPMToken(objName,cmdText);
			}
			if (TokenObjects[objName] || (TokenObjects[objName] == 0)) {
				var val = literal;
				var evalJS;
				if (cmdText.length > 0)	{ evalJS = 'TokenObjects[\'' + objName + '\'].' + cmdText; }
				else					{ evalJS = 'TokenObjects[\'' + objName + '\']'; }
				try
				{
					if (escapeHow)
					{
						if (escapeHow == PTPMTokenizer.ESCAPE) { sb.append( PTStringUtil.encodeURL(eval(evalJS),true) ); }
						else if (escapeHow == PTPMTokenizer.DOUBLE_ESCAPE) { sb.append( escape(PTStringUtil.encodeURL(eval(evalJS))) ); }
						else if (escapeHow == PTPMTokenizer.JAVASCRIPT_ESCAPE) { sb.append( PTStringUtil.escapeJS(eval(evalJS)) ); }
					}
					else { sb.append( eval(evalJS) ); }
				}
				catch(e) { sb.append( literal ); }
			} else if (window[objName]) {
				var val = literal;
				var evalJS;
				if (cmdText.length > 0)	{ evalJS = 'window[\'' + objName + '\'].' + cmdText; }
				else					{ evalJS = 'window[\'' + objName + '\']'; }
				try
				{
					if (escapeHow)
					{
						if (escapeHow == PTPMTokenizer.ESCAPE) { sb.append( PTStringUtil.encodeURL(eval(evalJS),true) ); }
						else if (escapeHow == PTPMTokenizer.DOUBLE_ESCAPE) { sb.append( escape(PTStringUtil.encodeURL(eval(evalJS))) ); }
						else if (escapeHow == PTPMTokenizer.JAVASCRIPT_ESCAPE) { sb.append( PTStringUtil.escapeJS(eval(evalJS)) ); }
					}
					else { sb.append( eval(evalJS) ); }
				}
				catch(e) { sb.append( literal ); }
			} else if (PTPMTokenizer.NativeObjects[objName]) {
				var val = literal;
				try {
					if (escapeHow)
					{
						if (escapeHow == PTPMTokenizer.ESCAPE)
						{
							sb.append( PTStringUtil.encodeURL(eval('PTPMTokenizer.NativeObjects[\'' + objName + '\'].' + cmdText),true) );
						}
						else if (escapeHow == PTPMTokenizer.DOUBLE_ESCAPE)
						{
							sb.append( escape(PTStringUtil.encodeURL(eval('PTPMTokenizer.NativeObjects[\'' + objName + '\'].' + cmdText))) );
						}
						else if (escapeHow == PTPMTokenizer.JAVASCRIPT_ESCAPE)
						{
							sb.append( PTStringUtil.escapeJS(eval('PTPMTokenizer.NativeObjects[\'' + objName + '\'].' + cmdText)) );
						}
					}
					else { sb.append( eval('PTPMTokenizer.NativeObjects[\'' + objName + '\'].' + cmdText) ); }
				}
				catch(e) { sb.append( literal ); }
			}
			else { sb.append( literal ); }
		}
		else { sb.append( literal ); }
		inputText = inputText.substr(end + PTPMTokenizer.endMarker.length);
	}
	sb.append( inputText );
	if (returnTokensOnly) {
		return tokens;
	} else {
		return sb.toString();
	}
}

PTPMTokenizer.prepareResource = function(inputText,TokenObjects)
{
	var oldStartMarker = PTPMTokenizer.startMarker;
	var oldEndMarker = PTPMTokenizer.endMarker;
	PTPMTokenizer.startMarker = '{';
	PTPMTokenizer.endMarker = '}';
	var str = PTPMTokenizer.parseTokens(inputText,TokenObjects);
	PTPMTokenizer.startMarker = oldStartMarker;
	PTPMTokenizer.endMarker = oldEndMarker;
	return str;
}

PTPMTokenizer.stringIsTokenized = function(str)
{
	str = new String(str);
	var minSize = PTPMTokenizer.startMarker.length + PTPMTokenizer.endMarker.length;
	return (str.indexOf(PTPMTokenizer.startMarker) <= (str.indexOf(PTPMTokenizer.endMarker) - minSize));
}

PTPMTokenizer.serializeTokenObjects = function(TokenObjects)
{
	var str = '';
	str += '{';
	for (var to in TokenObjects)
	{
		str += '\'' + to + '\' :';
		var obj = TokenObjects[to];
		var objName = obj.objName;
		var isGlobal = false;
		if (objName)
		{
			if (window[objName]) { isGlobal = true; }
		}
		if (!isGlobal)
		{
			if (!objName) { objName = 'anonymousObject'; }
			objName = objName + '_' + (new Date()).getTime();
			window[objName] = TokenObjects[to];
		}
		str += objName + ',';
	}
	if (str.length > 1) { str = str.substring(0,str.length-1); }
	str += '}';
	return str;
}

function PTPMToken(baseObject,property)
{
	this.baseObject		= (baseObject) ? baseObject : '';
	this.property		= (property) ? property : '';
	return this;
}

function PTPMMenuCacheObject()
{
	this._count		= 0;
	this._idPrefix	= '-PTPMMenu-cache-';
	return this;
}

PTPMMenuCacheObject.prototype.getId = function()
{
	return this._idPrefix + this._count++;
}

PTPMMenuCacheObject.prototype.remove = function(o)
{
	delete this[ o.id ];
}

if (!PTPMMenuCache) { var PTPMMenuCache = new PTPMMenuCacheObject(); }
function PTPMMenu()
{
	this.items					= [];
	this.parentMenu				= null;
	this.parentMenuItem			= null;
	this.popup					= null;
	this.shownSubMenu			= null;
	this.isDisabled				= false;
	this._aboutToShowSubMenu	= false;
	this.selectedIndex			= -1;
	this._drawn					= false;
	this._scrollingMode			= false;
	this._showTimer				= null;
	this._closeTimer			= null;
	this._onCloseInterval		= null;
	this._closed				= true;
	this._closedAt				= 0;
	this._cachedSizes			= {};
	this._measureInvalid		= true;
	this.id						= PTPMMenuCache.getId();
	this.cssFile				= PTPMMenu.defaultCssFile;
	this.ptname					= ''; 
	PTPMMenuCache[this.id]	= this;
	this.type					= 'PTPMMenu';
	this.className				= 'PTPMMenu';
}

PTPMMenu.defaultCssFile = 'styles/css/PTPMMenu.css';
PTPMMenu.prototype.cssText = null;
PTPMMenu.prototype.mouseHoverDisabled = true;
PTPMMenu.prototype.showTimeout = 250;
PTPMMenu.prototype.closeTimeout = 250;
PTPMMenu.keyboardAccelKey = 27;				
PTPMMenu.keyboardAccelProperty = 'ctrlKey';
PTPMMenu.scrollbarWidth = false;
PTPMMenu.useDivs = (PTBrowserInfo.IS_MSIE_5 || PTBrowserInfo.IS_NETSCAPE_DOM || PTBrowserInfo.IS_HTTPS || PTBrowserInfo.IS_XP_SP2);
PTPMMenu.resetMenus = function()
{	PTPMMenu._measureFrame = null;
}

PTPMMenu.getMenuItemElement = function(el)
{
	while ((el != null) && (el._menuItem == null)) { el = el.parentNode; }
	return el;
}

PTPMMenu.getTrElement = function(el)
{
	while ((el != null) && (el.tagName != 'TR')) { el = el.parentNode; }
	return el;
}

PTPMMenu.prototype.disable = function()
{
	this.isDisabled = true;
}

PTPMMenu.prototype.enable = function()
{
	this.isDisabled = false;
}

PTPMMenu.prototype.add = function( mi, beforeMi )
{
	if ( beforeMi != null )
	{
		var items = this.items;
		var l = items.length;
		for ( var i = 0; i < l; i++ ) {
			if ( items[i] == beforeMi )
				break;
		}
		this.items = items.slice( 0, i ).concat( mi ).concat( items.slice( i, l ) );
	}
	else
	{
		this.items[this.items.length] = mi;
	}
	mi.parentMenu = this;
	mi.itemIndex = this.items.length - 1;
	if ( mi.subMenu ) {
		mi.subMenu.parentMenu = this;
		mi.subMenu.parentMenuItem = mi;
	}
	return mi;
}

PTPMMenu.prototype.remove = function( mi )
{
	var res = [];
	var items = this.items;
	var l = items.length;
	for (var i = 0; i < l; i++) {
		if ( items[i] != mi ) {
			res[res.length] = items[i];
			items[i].itemIndex = res.length - 1;
		}
	}
	this.items = res;
	mi.parentMenu = null;
	return mi;
}

PTPMMenu.prototype.toHtml = function()
{
	var items = this.items;
	var len = items.length
	var itemsHtml = new PTStringBuffer();
	for (var i = 0; i < len; i++) { itemsHtml.append( items[i].toHtml() ); }
	var numSS = document.styleSheets.length;
	for (var i = 0; i < numSS; i++)
	{
		var loc = new String(document.styleSheets[i].href);
		if (loc.indexOf('PTPMMenu.css') > -1)
		{
			this.cssFile = loc;
			break;
		}
	}
	var sb = new PTStringBuffer();
	if (!PTPMMenu.useDivs)
	{
		sb.append('<html><head>');
		if (this.cssText == null)
		{
			sb.append('<link type="text/css" rel="StyleSheet" href="' + this.cssFile + '" id="PTPMMenuStylesheet"/>');
		}
		else
		{
			sb.append('<style type="text/css">' + this.cssText + '</style>');
		}
		sb.append('</head><body class="PTPMMenuBody">');
	}
	sb.append('<div class="outer-border"><div class="inner-border"><table id="scroll-up-item" cellspacing="0" style="display: none"><tr class="disabled"><td><span class="disabled-container"><span class="disabled-container">5</span></span>' + '</td></tr></table><div id="scroll-container');
	sb.append( this.id );
	sb.append('" style="display:table"><table cellspacing="0">');
	sb.append( itemsHtml.toString() );
	sb.append('</table></div><table id="scroll-down-item" cellspacing="0" style="display: none"><tr><td><span class="disabled-container"><span class="disabled-container">6</span></span></td></tr></table></div></div>');
	if (!PTPMMenu.useDivs)
	{
		sb.append('</body></html>');
	}
	return sb.toString();
}

PTPMMenu.prototype.createPopup = function()
{
	if (PTPMMenu.useDivs)
	{
		if (this.popup)
		{
			this.popup.style.visibility = 'visible';
		}
		else
		{
			var div = document.createElement('DIV');
			div.className = 'PTPMMenuBody';
			div.style.overflow = 'visible';			if (PTBrowserInfo.IS_MSIE) { div.style.width = '50px'; }
			document.body.appendChild(div);
			this.popup = div;
		}
	}
	else
	{
		var w;
		var pm = this.parentMenu;
		if (pm == null) { w = window; }
		else { w = pm.getDocument().parentWindow; }
		this.popup = w.createPopup();
	}
}

PTPMMenu.prototype.getMeasureDocument = function()
{
	if (this.isShown() && this._drawn) { return this.getDocument(); }
	var mf = PTPMMenu._measureFrame;
	if (mf == null)
	{
		mf = PTPMMenu._measureFrame = document.createElement('IFRAME');
		mf.src = 'javascript:void(0)'; 
		var mfs = mf.style;
		mfs.position = 'absolute';
		mfs.visibility = 'hidden';
		mfs.left = '-100px';
		mfs.top = '-100px';
		mfs.width = '10px';
		mfs.height = '10px';
		mf.frameBorder = 0;
		document.body.appendChild(mf);
		PTCommonUtil.wait(10);
	}
	var d = mf.contentWindow.document;
	if ((PTPMMenu._measureMenu == this) && !this._measureInvalid) { return d; }
	d.open('text/html', 'replace');
	d.write(this.toHtml());
	d.close();
	PTPMMenu._measureMenu = this;
	this._measureInvalid = false;
	return d;
}

PTPMMenu.prototype.getDocument = function()
{
	if (this.popup)
	{
		if (PTPMMenu.useDivs)
		{
			return this.popup;
		}
		else
		{
			return this.popup.document;
		}
	}
	else { return null; }
}

PTPMMenu.prototype.getPopup = function() {
	if (this.popup == null) { this.createPopup(); }
	return this.popup;
}

PTPMMenu.prototype.invalidate = function()
{
	if (this._drawn) {		if (this._scrollUpButton) { this._scrollUpButton.destroy(); }
		if (this._scrollDownButton) { this._scrollDownButton.destroy(); }
		var items = this.items;
		var l = items.length;
		var mi;
		for (var i = 0; i < l; i++)
		{
			mi = items[i];
			mi._htmlElement_menuItem = null;
			mi._htmlElement = null;
		}
		this.detachEvents();
	}
	this._drawn = false;
	this.resetSizeCache();
	this._measureInvalid = true;	
}

PTPMMenu.prototype.redrawMenu = function()
{
	this.invalidate();
	this.drawMenu();
}

PTPMMenu.prototype.drawMenu = function()
{
	if (this._drawn) { return; }
	this.getPopup();
	var d = this.getDocument();
	if (PTPMMenu.useDivs)
	{
		d.innerHTML = this.toHtml();	}
	else
	{
		d.open('text/html', 'replace');
		d.write(this.toHtml());
		d.close();
	}
	this._drawn = true;
	var doc = (PTPMMenu.useDivs) ? document : d;
	var scrollContainer = doc.getElementById('scroll-container' + this.id);
	var rows = scrollContainer.firstChild.tBodies[0].rows;
	var items = this.items;
	var l = rows.length;
	var mi;
	for (var i = 0; i < l; i++)
	{
		if (items[i])
		{
			mi = items[i];
			rows[i]._menuItem = mi;
			mi._htmlElement = rows[i];
		}
	}
	window.setTimeout( "PTPMMenuCache['"+this.id+"'].hookupMenu(PTPMMenuCache['"+this.id+"'].getDocument())", 10 );
}

PTPMMenu.prototype.show = function(left, top, w, h)
{
	var pm = this.parentMenu;
	if (pm) { pm.closeAllSubs(this); }
	this.drawMenu();
	if (!left) { left = 0; }
	if (!top ) { top = 0; }
	w = w || Math.min( window.screen.width, this.getPreferredWidth() );
	h = h || Math.min( window.screen.height, this.getPreferredHeight() );
	if (PTPMMenu.useDivs)
	{
		if (window.event)
		{
			left = window.event.clientX + document.body.scrollLeft;
			top = window.event.clientY + document.body.scrollTop;
		}
		else if (this.parentMenuItem && PTDOMUtil.getElementById('menu-row' + this.parentMenuItem.id))
		{
			left = PTDOMUtil.getElementLeft(PTDOMUtil.getElementById('menu-row' + this.parentMenuItem.id)) + PTDOMUtil.getElementWidth(PTDOMUtil.getElementById('menu-row' + this.parentMenuItem.id));
			var checkWidth = (PTBrowserInfo.IS_MSIE) ? Math.max(w, 200) : w;
			if (left + checkWidth > PTDOMUtil.getWindowWidth())
			{
				left = PTDOMUtil.getElementLeft(PTDOMUtil.getElementById('menu-row' + this.parentMenuItem.id)) - w;
			}		
			var elm = PTDOMUtil.getElementById('menu-row' + this.parentMenuItem.id);
			top = Math.max(elm.offsetParent.offsetHeight, PTDOMUtil.getElementTop(elm));
		}
		if (this.popup && this.popup.style)
		{
			if (PTBrowserInfo.IS_MSIE)
			{
				this.popup.style.pixelLeft = left;
				this.popup.style.pixelTop = top;
			}
			else if (PTBrowserInfo.IS_NETSCAPE_DOM)
			{
				this.popup.style.left = left;
				this.popup.style.top = top;	
			}
			this.popup.style.visibility = 'visible';
		}
		if (pm)
		{
			pm.shownSubMenu = this;
			pm._aboutToShowSubMenu = false;
		}
		return;
	}
	else
	{		this.popup.show(left, top, w, h);
	}
	if (this.getPreferredWidth() == 0)
	{
		this.invalidate();
		this.show(left, top, w, h);
		return;
	}
	if (this.selectedIndex != -1)
	{
		if (this.items[this.selectedIndex]) { this.items[this.selectedIndex].setSelected(false); }
	}
	if (pm)
	{
		pm.shownSubMenu = this;
		pm._aboutToShowSubMenu = false;
	}
	window.clearTimeout(this._showTimer);
	window.clearTimeout(this._closeTimer);
	this._drawn = false;
	this.drawMenu();
	this._closed = false;
	this._startClosePoll();
}

PTPMMenu.prototype.isShown = function()
{
	if (PTPMMenu.useDivs)	{ var shown = ((this.popup != null) && (this.popup.style.visibility != 'hidden')); }
	else				{ var shown = ((this.popup != null) && (this.popup.isOpen)); }
	return shown;
}

PTPMMenu.prototype.fixSize = function() {
	var w = Math.min( window.screen.width, this.getPreferredWidth() );
	var h = Math.min( window.screen.height, this.getPreferredHeight() );
	var l = Math.max( 0, this.getLeft() );
	var t = Math.max( 0, this.getTop() );
	this.popup.show( l, t, w, h );
}

PTPMMenu.prototype.getWidth = function()
{
	var d = this.getDocument();
	if ( d != null )
		return d.body.offsetWidth;
	else
		return 0;
}

PTPMMenu.prototype.getHeight = function()
{
	var d = this.getDocument();
	if (d != null)
	{
		var doc = (PTPMMenu.useDivs) ? d : d.body;
		return doc.offsetHeight;
	}
	else { return 0; }
}

PTPMMenu.prototype.getPreferredWidth = function()
{
	this.updateSizeCache();
	if (PTPMMenu.useDivs && PTBrowserInfo.IS_MSIE_5) { return 10; } 
	return this._cachedSizes.preferredWidth;
}

PTPMMenu.prototype.getPreferredHeight = function()
{
	this.updateSizeCache();
	if (PTPMMenu.useDivs && PTBrowserInfo.IS_MSIE_5) { return 10; } 
	else { return this._cachedSizes.preferredHeight; }
}

PTPMMenu.prototype.getLeft = function()
{
	var d = this.getDocument();
	if (d != null)
	{
		if (PTPMMenu.useDivs)
		{
			var left = PTPMPosition.getLeft(d);
			return left;
		}
		else
		{
			return d.parentWindow.screenLeft;
		}
	}
	else { return 0; }
}

PTPMMenu.prototype.getTop = function() {
	var d = this.getDocument();
	if (d != null)
	{
		if (PTPMMenu.useDivs)
		{
			return PTPMPosition.getTop(d);
		}
		else
		{
			return d.parentWindow.screenTop;
		}
	}
	else { return 0; }
}

PTPMMenu.prototype.getInsetLeft = function() {
	this.updateSizeCache();
	return this._cachedSizes.insetLeft;
}

PTPMMenu.prototype.getInsetRight = function() {
	this.updateSizeCache();
	return this._cachedSizes.insetRight;
}

PTPMMenu.prototype.getInsetTop = function() {
	this.updateSizeCache();
	return this._cachedSizes.insetTop;
}

PTPMMenu.prototype.getInsetBottom = function() {
	this.updateSizeCache();
	return this._cachedSizes.insetBottom;
}

PTPMMenu.prototype.areSizesCached = function() {
	var cs = this._cachedSizes;
	return (this._drawn && cs['preferredWidth'] && cs['preferredHeight'] && cs['insetLeft'] && cs['insetRight'] && cs['insetTop'] && cs['insetBottom']);
}

PTPMMenu.prototype.resetSizeCache = function()
{
	this._cachedSizes = {};
}

PTPMMenu.prototype.updateSizeCache = function(bForce)
{
	if (PTPMMenu.useDivs && PTBrowserInfo.IS_MSIE_5) { return; }
	if (this.areSizesCached() && !bForce) { return; }
	var d = this.getMeasureDocument();
	var body = d.body;
	if (!d.body) { return; }
	var cs = this._cachedSizes = {};	
	if (PTPMMenu.useDivs)
	{
		cs.preferredWidth = d.body.scrollWidth;
		cs.preferredHeight = d.body.scrollHeight - 25;
		return; 
	}
	else
	{		if (!PTPMMenu.scrollbarWidth)
		{
			var md = document.createElement('DIV');
			md.style.width = '100px';
			md.style.height = '5px';
			md.style.overflowY = 'auto';
			md.style.display = 'block';
			md.innerHTML = '<br><br><br>';
			md.id = 'PTControlsMeasureDiv';
			document.body.appendChild(md);
			PTPMMenu.scrollbarWidth = (md.offsetWidth - md.scrollWidth) + 1;
			md.style.display = 'none';
			document.body.removeChild(md);
		}		cs.preferredWidth = d.body.scrollWidth + PTPMMenu.scrollbarWidth;
	}
	var scrollContainer = d.getElementById('scroll-container' + this.id);
	scrollContainer.style.overflow = 'visible';
	cs.preferredHeight = d.body.firstChild.scrollHeight + 4; 
	cs.insetLeft = PTPMPosition.getLeft(scrollContainer);
	cs.insetRight = d.body.scrollWidth - PTPMPosition.getLeft(scrollContainer) - scrollContainer.offsetWidth;
	var up = d.getElementById('scroll-up-item');
	if (up.currentStyle && up.currentStyle.display == 'none') { cs.insetTop = PTPMPosition.getTop(scrollContainer); }
	else if (up.style && up.style.display == 'none') { cs.insetTop = PTPMPosition.getTop(scrollContainer); }
	else { cs.insetTop = PTPMPosition.getTop(up); }
	var down = d.getElementById('scroll-down-item');
	if (down.currentStyle && down.currentStyle.display == 'none')
	{
		cs.insetBottom = d.body.scrollHeight - PTPMPosition.getTop(scrollContainer) - scrollContainer.offsetHeight;
	}
	else if (down.style && down.style.display == 'none')
	{
		cs.insetBottom = d.body.scrollHeight - PTPMPosition.getTop(scrollContainer) - scrollContainer.offsetHeight;
	}
	else
	{
		cs.insetBottom = d.body.scrollHeight - PTPMPosition.getTop(down) - down.offsetHeight;
	}
	scrollContainer.style.overflow = 'hidden';
}

PTPMMenu.prototype.closeAllMenus = function()
{
	if (this.parentMenu) { this.parentMenu.closeAllMenus(); }
	else { this.close(); }
}

PTPMMenu.prototype.close = function()
{
	this.closeAllSubs();
	window.clearTimeout( this._showTimer );
	window.clearTimeout( this._closeTimer );
	if (PTPMMenu.useDivs)
	{
		window.clearInterval(this._onCloseInterval);
		this._closed = true;
		this._closedAt = new Date().valueOf();
	}
	if (this.popup)
	{
		if (PTPMMenu.useDivs)	{ this.popup.style.visibility = 'hidden'; }
		else				{ this.popup.hide(); }
	}
	var pm = this.parentMenu;
	if (pm && (pm.shownSubMenu == this)) { pm.shownSubMenu = null; }
	this.setSelectedIndex( -1 );
	this._checkCloseState();
}

PTPMMenu.prototype.closeAllSubs = function( oNotThisSub) {		var items = this.items;
	var l = items.length;
	for (var i = 0; i < l; i++)
	{
		if (items[i].subMenu != null && items[i].subMenu != oNotThisSub) { items[i].subMenu.close(); }
	}
}

PTPMMenu.prototype.getSelectedIndex = function() {
	return this.selectedIndex;
}

PTPMMenu.prototype.setSelectedIndex = function( nIndex ) {
	if ( this.selectedIndex == nIndex ) return;
	if ( nIndex >= this.items.length )
		nIndex = -1;
	var mi;
	if ( this.selectedIndex != -1 ) {
		mi = this.items[ this.selectedIndex ];
		mi.setSelected( false );
	}
	this.selectedIndex = nIndex;
	mi = this.items[ this.selectedIndex ];
	if ( mi != null )
		mi.setSelected( true );
}

PTPMMenu.prototype.goToNextMenuItem = function() {
	var i = 0;
	var items = this.items;
	var length = items.length;
	var index = this.getSelectedIndex();
	var tmp;
	do
	{
		if ( index == -1 || index >= length )
			index = 0;
		else 
			index++;
		i++;
		tmp = items[index]
	}
	while ( !( tmp != null && tmp instanceof PTPMSimpleMenuItem &&
			!(tmp instanceof PTPMDividerMenuItem) || i >= length ) )
	if (tmp != null) { this.setSelectedIndex(index); }
}

PTPMMenu.prototype.goToPreviousMenuItem = function() {
	var i = 0;
	var items = this.items;
	var length = items.length;
	var index = this.getSelectedIndex();
	var tmp;
	do
	{
		if ( index == -1 || index >= length )
			index = length - 1;
		else 
			index--;
		i++;
		tmp = items[index]
	} while ( !( tmp != null && tmp instanceof PTPMSimpleMenuItem &&
			!(tmp instanceof PTPMDividerMenuItem) || i >= length ) )
	if (tmp != null) { this.setSelectedIndex(index); }
}

PTPMMenu.prototype.goToNextMenu = function() {
	var index = this.getSelectedIndex();
	var mi = this.items[ index ];
	if ( mi && mi.subMenu && !mi.isDisabled ) {
		mi.subMenu.setSelectedIndex( 0 );
		mi.showSubMenu( false );
	}
	else {		var mb = this.getMenuBar();
		if ( mb != null )
			mb.goToNextMenuItem();
	}
}

PTPMMenu.prototype.goToPreviousMenu = function() {
	if ( this.parentMenuItem && this.parentMenuItem instanceof PTPMMenuButton ) {
		this.parentMenu.goToPreviousMenuItem();
	}
	else if ( this.parentMenuItem ) {
		this.close();
	}
}

PTPMMenu.prototype.getMenuBar = function() {
	if ( this.parentMenu == null )
		return null;
	return this.parentMenu.getMenuBar();
}

PTPMMenu.prototype.makeEventListeners = function() {
	if ( this.eventListeners != null )
		return;
	this.eventListeners = {
		onscroll:			new Function( "e", "PTPMMenuEventListeners.menu.onscroll(e,\"" + this.id + "\")" ),
		onmouseover:		new Function( "e", "PTPMMenuEventListeners.menu.onmouseover(e,\"" + this.id + "\")" ),
		onmouseout:			new Function( "e", "PTPMMenuEventListeners.menu.onmouseout(e,\"" + this.id + "\")" ),
		onmouseup:			new Function( "e", "PTPMMenuEventListeners.menu.onmouseup(e,\"" + this.id + "\")" ),
		onmousewheel:		new Function( "e", "PTPMMenuEventListeners.menu.onmousewheel(e,\"" + this.id + "\")" ),
		onreadystatechange:	new Function( "e", "PTPMMenuEventListeners.menu.onreadystatechange(e,\"" + this.id + "\")" ),
		onkeydown:			new Function( "e", "PTPMMenuEventListeners.menu.onkeydown(e,\"" + this.id + "\")" ),
		oncontextmenu:		new Function( "e", "PTPMMenuEventListeners.menu.oncontextmenu(e,\"" + this.id + "\")" ),
		onunload:			new Function( "PTPMMenuEventListeners.menu.onunload(\"" + this.id + "\")" )		
	};
}

PTPMMenu.prototype.detachEvents = function()
{	if (this.eventListeners == null)	{ return; }
	var d = this.getDocument();
	var w = d.parentWindow;
	var doc = (PTPMMenu.useDivs) ? document : d;
	var scrollContainer = doc.getElementById('scroll-container' + this.id);
	PTEventUtil.detachEventListener(scrollContainer, "onscroll", this.eventListeners.onscroll );	
	PTEventUtil.detachEventListener(d, "onmouseover", this.eventListeners.onmouseover );
	PTEventUtil.detachEventListener(d, "onmouseout", this.eventListeners.onmouseout );
	PTEventUtil.detachEventListener(d, "onmouseup", this.eventListeners.onmouseup );
	PTEventUtil.detachEventListener(d, "onmousewheel", this.eventListeners.onmousewheel );	
	if ((this.cssText == null) && !PTPMMenu.useDivs)
	{
		var linkEl = d.getElementById('PTPMMenuStylesheet');
		if (linkEl) 
		{ 
			PTEventUtil.detachEventListener(linkEl, "onreadystatechange", this.eventListeners.onreadystatechange ); 
		}
	}
	PTEventUtil.detachEventListener(d, "onkeydown", this.eventListeners.onkeydown );
	PTEventUtil.detachEventListener(d, "oncontextmenu", this.eventListeners.oncontextmenu );
	if (document.all) { window.detachEvent( "onunload", this.eventListeners.onunload ); }
}

PTPMMenu.prototype.hookupMenu = function()
{
	this.detachEvents();
	this.makeEventListeners();
	var oThis = this;
	var d = this.getDocument();
	var w = d.parentWindow;
	var doc = (PTPMMenu.useDivs) ? document : d;
	var scrollContainer = doc.getElementById('scroll-container' + this.id);
	this.attach(scrollContainer,'scroll',this.eventListeners.onscroll);
	this.attach(d,'mouseover',this.eventListeners.onmouseover);
	this.attach(d,'mouseout',this.eventListeners.onmouseout);
	this.attach(d,'mouseup',this.eventListeners.onmouseup);
	this.attach(d,'mousewheel',this.eventListeners.onmousewheel);
	if ((this.cssText == null) && !PTPMMenu.useDivs)
	{
		var linkEl = doc.getElementById('PTPMMenuStylesheet');
		if (linkEl && linkEl.readyState != 'complete')
		{
			linkEl.attachEvent('onreadystatechange', this.eventListeners.onreadystatechange);
		}
	}
	this.attach( d, "keydown", this.eventListeners.onkeydown );
	this.attach( d, "contextmenu", this.eventListeners.oncontextmenu );
	this.attach( window, "unload", this.eventListeners.onunload );
	if (!PTBrowserInfo.IS_NETSCAPE_DOM)
	{
		var all = d.all;
		var l = all.length;
		for (var i = 0; i < l; i++) { all[i].unselectable = 'on'; }
	}
	if (PTPMMenu.useDivs)
	{
		var availableHeight = parseInt(document.body.clientHeight) - PTPMPosition.getClientTop(d);
		if (PTPMPosition.getHeight(d) > availableHeight)
		{
			d.style.overflowY = 'auto';
			d.style.height = (availableHeight - 20) + 'px';
		}
	}
}

PTPMMenu.prototype.handleKeyEvent = function(oEvent)
{
	if ( this.shownSubMenu ) {		return;
	}
	var nKeyCode = oEvent.keyCode;
	oEvent.returnValue = false;
	try { oEvent.keyCode = 0; } catch(e) {}

	switch ( nKeyCode ) {
		case 40:	
			this.goToNextMenuItem();
			break;
		case 38:	
			this.goToPreviousMenuItem();
			break;
		case 39:	
			this.goToNextMenu();
			break;
		case 37:	
			this.goToPreviousMenu();
			break;
		case 13:	
			var mi = this.items[ this.getSelectedIndex() ];
			if ( mi )
				mi.dispatchAction();
			break;
		case 27:	
			this.close();
			break;
		case PTPMMenu.keyboardAccelKey:
			this.closeAllMenus();
			break;
		default:			var c = String.fromCharCode( nKeyCode ).toLowerCase();
			var items = this.items;
			var l = items.length;
			for ( var i = 0; i < l; i++ ) {
				if ( items[i].mnemonic == c ) {
					items[i].dispatchAction();
					break;
				}					
			}
	}
}

PTPMMenu.prototype.attach = function(obj,evtName,func,nsDir)
{
	if (PTBrowserInfo.IS_NETSCAPE_DOM)
	{
		nsDir = (nsDir) ? true : false;
		obj.addEventListener(evtName,func,nsDir);
	}
	else
	{
		evtName = 'on' + evtName;
		obj.attachEvent(evtName,func);
	}
}

PTPMMenu.prototype.detach = function(obj,evtName,func,nsDir)
{
	if (PTBrowserInfo.IS_NETSCAPE_DOM)
	{
		nsDir = (nsDir) ? true : false;
		obj.removeEventListener(evtName,func,nsDir);
	}
	else
	{
		evtName = 'on' + evtName;
		obj.detachEvent(evtName,func);
	}
}

PTPMMenu.prototype._startClosePoll = function()
{
	var oThis = this;
	window.clearInterval(this._onCloseInterval);
	this._onCloseInterval = window.setInterval('PTPMMenuEventListeners.menu.oncloseinterval(\'' + this.id + '\')', 100 );
}

PTPMMenu.prototype._checkCloseState = function()
{
	if (PTPMMenu.useDivs)
	{
		var closed = ((this.popup == null) || (!this.popup.style.visibility == 'hidden'));
	}
	else
	{
		var closed = ((this.popup == null) || !this.popup.isOpen);
	}
	if (closed && (this._closed != closed))
	{
		this._closed = closed;
		this._closedAt = new Date().valueOf();
		window.clearInterval( this._onCloseInterval );
		if (typeof this._onclose == 'function')
		{
			var e = (PTPMMenu.useDivs) ? window.event : this.getDocument().parentWindow.event;
			if ((e != null) && (e.keyCode == 27))	{ this._closeReason = 'escape'; }
			else									{ this._closeReason = 'unknown'; }
			this._onclose();
		}
	}
}

PTPMMenu.prototype._isCssFileLoaded = function()
{
	if ((this.cssText != null) || PTPMMenu.useDivs) { return true; }
	var d = this.getMeasureDocument();
	var linkEl = d.getElementById('PTPMMenuStylesheet');
	if (linkEl) { return (linkEl.readyState == 'complete'); }
	else { return false; }
}

PTPMMenu.prototype.destroy = function()
{
	var l = this.items.length;
	for ( var i = l -1; i >= 0; i-- )
		this.items[i].destroy();
	this.detachEvents();
	this.items = [];
	this.parentMenu = null;
	this.parentMenuItem = null;
	this.shownSubMenu = null;
	this._cachedSizes = null;
	this.eventListeners = null;
	if (this.popup != null)
	{
		if (PTPMMenu.useDivs)
		{
			var d = this.popup;
			d.innerHTML = '';
			document.body.removeChild(d);
		}
		else
		{
			var d = this.popup.document;
			d.open('text/plain', 'replace');
			d.write('');
			d.close();
		}
		this.popup = null;
	}
	if ( PTPMMenu._measureMenu == this )
	{
		PTPMMenu._measureMenu = null;
		if (PTPMMenu.useDivs)
		{
		}
		else
		{
			try {
				var d = PTPMMenu._measureFrame.contentWindow.document;
				d.open('text/plain', 'replace');
				d.write('');
				d.close();
				PTPMMenu._measureFrame.parentNode.removeChild(PTPMMenu._measureFrame);
				PTPMMenu._measureFrame = null;
			} catch(e) {}

		}
	}
	PTPMMenuCache.remove( this );
}

function PTPMSelectMenu()
{
	this.type = 'PTPMSelectMenu';
	this.items = [];
	this.parentMenu = null;
	this.parentMenuItem = null;
	this.shownSubMenu = null;
	this._aboutToShowSubMenu = false;
	this.styleClass = 'navMidtabBtn';
	this.active = false;
	this.className = 'PTPMSelectMenu';
	this.id = PTPMMenuCache.getId();
	this.ptname = '';	
	PTPMMenuCache[ this.id ] = this;
}

PTPMSelectMenu.leftMouseButton = 1;
PTPMSelectMenu.init = function(menu, divID, buttonText, menuDirection, TokenObjectNamePairs, callback, loadMessageCommand)
{
	var selectMenu = new PTPMSelectMenu();
	var preparedMenu = PTPMMenu.prepare(menu);
	var menuButton = new PTPMMenuButton(buttonText,preparedMenu);
	menuButton.ptname = 'ddmenu'+divID;	
	selectMenu.add(menuButton);
	PTDOMUtil.getElementById(divID).innerHTML = selectMenu.toHtml();
	if (document.readyState == 'complete')
	{
		selectMenu.finishHookup(menuDirection);
	}
	else if (document.PCC)
	{
		var md = ((menuDirection) ? menuDirection : '');
		var func = 'new Function(window.setTimeout(\'PTPMMenuCache[\\\'' + selectMenu.id + '\\\'].finishHookup(\\\'' + md + '\\\')\',5))';
		document.PCC.RegisterForWindowEvent('onload', func);
	}
	return selectMenu;
}

PTPMSelectMenu.prototype = new PTPMMenu;
PTPMSelectMenu.prototype.finishHookup = function(menuDirection)
{
	var menubuttondiv = PTDOMUtil.getElementById(this.id);
	this.hookupMenu(menubuttondiv);
	menubuttondiv.onselectstart = new Function('return false');
	menubuttondiv.oncontextmenu = new Function('return false');
	if (menuDirection) { this.setMenuDirection(menuDirection); }
}

PTPMSelectMenu.prototype.setMenuDirection = function(dir)
{
	if (this.items && this.items[0] && this.items[0].subMenuDirection)
	{
		if (!dir) { dir = PTPMMenuItem.DIRECTION_VERTICAL; }
		this.items[0].subMenuDirection = dir;
	}
}

PTPMSelectMenu.prototype.toHtml = function()
{
	var items = this.items;
	var l = items.length;
	var itemsHtml = new Array(l);
	for (var i = 0; i < l; i++)
	{
		itemsHtml[i] = items[i].toHtml();
	}
	return '<div class="' + this.styleClass + '" id="' + this.id + '">' + itemsHtml.join('') + '</div>';
}

PTPMSelectMenu.prototype.createPopup = function() {};
PTPMSelectMenu.prototype.getPopup= function() {};
PTPMSelectMenu.prototype.drawMenu = function() {};
PTPMSelectMenu.prototype.getDocument = function() {
	return document;
}

PTPMSelectMenu.prototype.show = function(left, top, w, h) {};
PTPMSelectMenu.prototype.isShown = function() { return true; };
PTPMSelectMenu.prototype.fixSize = function() {}

PTPMSelectMenu.prototype.getWidth = function() {
	return this._htmlElement.offsetWidth;		
}

PTPMSelectMenu.prototype.getHeight = function() {
	return this._htmlElement.offsetHeight;
}

PTPMSelectMenu.prototype.getPreferredWidth = function() {
	var el = this._htmlElement;
	el.runtimStyle.whiteSpace = "nowrap";
	var sw = el.scrollWidth;
	el.runtimStyle.whiteSpace = "";
	return sw + parseInt( el.currentStyle.borderLeftWidth ) +
				parseInt( el.currentStyle.borderRightWidth );
}

PTPMSelectMenu.prototype.getPreferredHeight = function() {
	var el = this._htmlElement;
	el.runtimStyle.whiteSpace = "nowrap";
	var sw = el.scrollHeight;
	el.runtimStyle.whiteSpace = "";
	return sw + parseInt( el.currentStyle.borderTopWidth ) +
				parseInt( el.currentStyle.borderBottomWidth );
}

PTPMSelectMenu.prototype.getLeft = function() {
	return PTPMPosition.getScreenLeft( this._htmlElement );
}

PTPMSelectMenu.prototype.getTop = function() {
	return PTPMPosition.getScreenLeft( this._htmlElement );
}

PTPMSelectMenu.prototype.setLeft = function( l ) {};
PTPMSelectMenu.prototype.setTop = function( t ) {};
PTPMSelectMenu.prototype.setLocation = function( l, t ) {};
PTPMSelectMenu.prototype.setRect = function( l, t, w, h ) {};
PTPMSelectMenu.prototype.getInsetLeft = function() {
	return parseInt( this._htmlElement.currentStyle.borderLeftWidth );
}

PTPMSelectMenu.prototype.getInsetRight = function() {
	return parseInt( this._htmlElement.currentStyle.borderRightWidth );
}

PTPMSelectMenu.prototype.getInsetTop = function() {
	return parseInt( this._htmlElement.currentStyle.borderTopWidth );
}

PTPMSelectMenu.prototype.getInsetBottom = function() {
	return parseInt( this._htmlElement.currentStyle.borderBottomWidth );
}

PTPMSelectMenu.prototype.makeEventListeners = function()
{
	if (this.eventListeners != null) { return; }
	this.eventListeners = {
		onmouseover:		new Function( "e", "PTPMMenuEventListeners.menuBar.onmouseover(e,\"" + this.id + "\")" ),
		onmouseout:			new Function( "e", "PTPMMenuEventListeners.menuBar.onmouseout(e,\"" + this.id + "\")" ),
		onmousedown:		new Function( "e", "PTPMMenuEventListeners.menuBar.onmousedown(e,\"" + this.id + "\")" ),
		onkeydown:			new Function( "e", "PTPMMenuEventListeners.menuBar.onkeydown(e,\"" + this.id + "\")" ),
		onunload:			new Function( "PTPMMenuEventListeners.menuBar.onunload(\"" + this.id + "\")" )
	};
}

PTPMSelectMenu.prototype.detachEvents = function()
{
	if (this.eventListeners == null) { return; }
	PTEventUtil.attachEventListener(this._htmlElement, "onmouseover",	this.eventListeners.onmouseover );
	PTEventUtil.attachEventListener(this._htmlElement, "onmouseout", this.eventListeners.onmouseout );
	PTEventUtil.attachEventListener(this._htmlElement, "onmousedown", this.eventListeners.onmousedown );
	PTEventUtil.attachEventListener(document, "onkeydown", this.eventListeners.onkeydown );
	PTEventUtil.detachEventListener(window, "onunload", this.eventListeners.onunload );
}

PTPMSelectMenu.prototype.hookupMenu = function(element,buttonElement)
{
	if (!element) { return; }
	this.detachEvents();
	this.makeEventListeners();
	this._htmlElement = element;
	element.unselectable = 'on';
	var cs = element.childNodes;
	var items = this.items;
	var l = cs.length;
	for (var i = 0; i < l; i++)
	{
		if (cs[i] && items[i])
		{
			items[i]._htmlElement = cs[i];			if (buttonElement) { items[i]._buttonHTMLElement = buttonElement; }
			cs[i]._menuItem = items[i];
		}
	}
	PTEventUtil.attachEventListener(element, 'onmouseover',this.eventListeners.onmouseover);
	PTEventUtil.attachEventListener(element, 'onmouseout',this.eventListeners.onmouseout);
	PTEventUtil.attachEventListener(element, 'onmousedown',this.eventListeners.onmousedown);
	PTEventUtil.attachEventListener(document, 'onkeydown',this.eventListeners.onkeydown);
	PTEventUtil.attachEventListener(window, 'onunload',this.eventListeners.onunload);
}

PTPMSelectMenu.prototype.write = function()
{
	document.write(this.toHtml());
	var el = PTDOMUtil.getElementById(this.id);
	this.hookupMenu(el);
}

PTPMSelectMenu.prototype.create = function()
{
	var dummyDiv = document.createElement('DIV');
	dummyDiv.innerHTML = this.toHtml();
	var el = dummyDiv.removeChild(dummyDiv.firstChild);
	this.hookupMenu(el);
	return el;
}

PTPMSelectMenu.prototype.handleKeyEvent = function( e ) {
	if ( this.getActiveState() == "open" )
		return;
	var nKeyCode = e.keyCode;
	e.returnValue = false;
	if ( this.active && e[ PTPMMenu.keyboardAccelProperty ] )
		try { e.keyCode = 0; } catch(e) {}

	if ( nKeyCode == PTPMMenu.keyboardAccelKey ) {
		if ( !e.repeat ) {
			this.toggleActive();
		}
		try { e.keyCode = 0; } catch(e) {}

		return;
	}
	if ( !this.active ) {
		e.returnValue = true;
		return;
	}
	switch ( nKeyCode ) {
		case 39:	
			this.goToNextMenuItem();
			break;
		case 37:	
			this.goToPreviousMenuItem();
			break;
		case 40:	
		case 38:	
		case 13:	
			var mi = this.items[ this.getSelectedIndex() ];
			if ( mi ) {
				mi.dispatchAction();
				if ( mi.subMenu )
					mi.subMenu.setSelectedIndex( 0 );
			}
			break;
		case 27:	
			this.setActive( false );
			break;
		default:			var c = String.fromCharCode( nKeyCode ).toLowerCase();
			var items = this.items;
			var l = items.length;
			for ( var i = 0; i < l; i++ ) {
				if ( items[i].mnemonic == c ) {
					items[i].dispatchAction();
					break;
				}					
			}
	}
}

PTPMSelectMenu.prototype.getMenuBar = function() {
	return this;
}

PTPMSelectMenu.prototype._menu_goToNextMenuItem = PTPMMenu.prototype.goToNextMenuItem;
PTPMSelectMenu.prototype.goToNextMenuItem = function() {
	var expand = this.getActiveState() == "open";
	this._menu_goToNextMenuItem();
	var mi = this.items[ this.getSelectedIndex() ];
	if ( expand && mi != null ) {
		window.setTimeout(
			"PTPMMenuEventListeners.menuBar.ongotonextmenuitem(\"" + this.id + "\")",
			1 );
	}	
}

PTPMSelectMenu.prototype._menu_goToPreviousMenuItem = PTPMMenu.prototype.goToPreviousMenuItem;
PTPMSelectMenu.prototype.goToPreviousMenuItem = function() {
	var expand = this.getActiveState() == "open";
	this._menu_goToPreviousMenuItem();
	var mi = this.items[ this.getSelectedIndex() ];
	if ( expand && mi != null ) {
		window.setTimeout(
			"PTPMMenuEventListeners.menuBar.ongotopreviousmenuitem(\"" + this.id + "\")",
			1 );
	}
}

PTPMSelectMenu.prototype._menu_setSelectedIndex = PTPMMenu.prototype.setSelectedIndex;
PTPMSelectMenu.prototype.setSelectedIndex = function( nIndex ) {
	this._menu_setSelectedIndex( nIndex );
	this.active = nIndex != -1;
}

PTPMSelectMenu.prototype.setActive = function( bActive ) {
	if ( this.active != bActive ) {
		this.active = Boolean( bActive );
		if ( this.active ) {
			this.setSelectedIndex( 0 );
			this.backupFocused();
			window.focus();
		}
		else {
			this.setSelectedIndex( -1 );
			this.restoreFocused();
		}
	}
}

PTPMSelectMenu.prototype.toggleActive = function()
{
	if (this.getActiveState() == 'active') { this.setActive(false); }
	else if (this.getActiveState() == 'inactive') { this.setActive(true); }
}

PTPMSelectMenu.prototype.getActiveState = function()
{
	if ((this.shownSubMenu != null) || this._aboutToShowSubMenu) { return 'open'; }
	else if (this.active) { return 'active'; }
	else { return 'inactive'; }
}

PTPMSelectMenu.prototype.backupFocused = function() {
	this._activeElement = document.activeElement;
}

PTPMSelectMenu.prototype.restoreFocused = function() {
	try {
		this._activeElement.focus();
	}
	catch (ex) {}

	delete this._activeElement;
}

PTPMSelectMenu.prototype.destroy = function()
{
	var l = this.items.length;
	for (var i = l -1; i >= 0; i--) { this.items[i].destroy(); }
	this.detachEvents();
	this._activeElement = null;
	this._htmlElement = null;
	this.items = [];
	this.shownSubMenu = null;
	this.eventListeners = null;
	PTPMMenuCache.remove( this );
}

function PTPMMenuBarMenu()
{
	this.type = 'PTPMMenuBarMenu';
	return this;
}

PTPMMenuBarMenu.prototype = new PTPMSelectMenu();
PTPMMenuBarMenu.prototype.constructor = PTPMMenuBarMenu;
PTPMMenuBarMenu.prototype._super = PTPMSelectMenu;
if (!window.PTPMMenuEventListeners)
{
	PTPMMenuEventListeners = {
		menu: {
			onkeydown:	function( e, id ) {
				if (!e) e = window.event;
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var w = oThis.getDocument().parentWindow;
					oThis.handleKeyEvent( e );
				}
			},
			onunload:	function( id ) {
				if (PTPMMenuCache[id]) {
					PTPMMenuCache[id].closeAllMenus();
					PTPMMenuCache[id].destroy();
				}			},
			oncontextmenu:	function( e, id )
			{	
				var oThis = PTPMMenuCache[id];
				var w = (PTPMMenu.useDivs) ? window : oThis.getDocument().parentWindow;
				if (!e) e = w.event;
				e.returnValue = false;
			},
			onscroll:	function( e, id ) {			},
			onmouseover:	function( e, id ) {
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var w = (PTPMMenu.useDivs) ? window : oThis.getDocument().parentWindow;
					if (!e) e = w.event;
					var fromEl	= PTPMMenu.getTrElement( PTEventUtil.getMouseOverFromElement(e) );
					var toEl	= PTPMMenu.getTrElement( PTEventUtil.getMouseOverToElement(e) );
					if ( toEl != null && toEl != fromEl ) {
						var mi = toEl._menuItem;
						if ( mi ) {
							if ( !mi.isDisabled || oThis.mouseHoverDisabled ) {
								mi.setSelected( true );
								mi.showSubMenu( true );
							}
						}
						else {	
							if (toEl.className == "disabled" || toEl.className == "disabled-hover" )
								toEl.className = "disabled-hover";
							else
								toEl.className = "hover";
							oThis.selectedIndex = -1;
						}
					}
				}
			},
			onmouseout:	function( e, id )
			{
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var w = (PTPMMenu.useDivs) ? window : oThis.getDocument().parentWindow;
					if (!e) e = w.event;
					var fromEl	= PTPMMenu.getTrElement( PTEventUtil.getMouseOutFromElement(e) );
					var toEl	= PTPMMenu.getTrElement( PTEventUtil.getMouseOutToElement(e) );
					if ( fromEl != null && toEl != fromEl ) {
						var id = fromEl.parentNode.parentNode.id;
						var mi = fromEl._menuItem;
						if ( id == "scroll-up-item" || id == "scroll-down-item" ) {
							if (fromEl.className == "disabled-hover" || fromEl.className == "disabled" )
								fromEl.className = "disabled";
							else
								fromEl.className = "";
							oThis.selectedIndex = -1;
						}
						else if ( mi &&
							( toEl != null || mi.subMenu == null || mi.isDisabled ) ) {
							mi.setSelected( false );
						}
					}
				}
			},
			onmouseup:	function( e, id )
			{
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var w = (PTPMMenu.useDivs) ? window : oThis.getDocument().parentWindow;
					if (!e) e = w.event;
					var srcEl	= PTPMMenu.getMenuItemElement( PTEventUtil.getSrcElement(e) );
					if (srcEl != null)
					{
						var id = srcEl.parentNode.parentNode.id;
						if ((id == 'scroll-up-item') || (id == 'scroll-down-item')) { return; }
						oThis.selectedIndex = srcEl.rowIndex;
						var menuItem = oThis.items[oThis.selectedIndex];
						var action = menuItem.dispatchAction();
						if (oThis.parentMenuButton) { oThis.parentMenuButton.notifyClick(menuItem); }
					}
					if (PTPMMenu.useDivs) { PTEventUtil.stopBubbling(e); }
				}
			},
			onmousewheel:	function( e, id )
			{
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var d = oThis.getDocument();
					var w = (PTPMMenu.useDivs) ? window : d.parentWindow;
					if (!e) e = w.event;
					var doc = (PTPMMenu.useDivs) ? document : d;
				}
			},		
			onreadystatechange:	function( e, id )
			{
				if (!e) e = window.event;
				var oThis = PTPMMenuCache[id];
				var d = oThis.getDocument();
				var linkEl = d.getElementById('PTPMMenuStylesheet');
				if (linkEl &&  linkEl.readyState == 'complete' )
				{
					oThis.resetSizeCache();	
					oThis.fixSize();
				}
			},
			oncloseinterval: function( id )
			{
				 PTPMMenuCache[id]._checkCloseState();
			}
		},
		menuItem:	{
			onshowtimer: function( id ) {
				var oThis = PTPMMenuCache[id];
				var sm = oThis.subMenu;
				var pm = oThis.parentMenu;
				var selectedIndex = sm.getSelectedIndex();
				pm.closeAllSubs( sm );
				window.setTimeout('PTPMMenuEventListeners.menuItem.onshowtimer2("' + id + '")', 1);
			},
			onshowtimer2: function( id ) {
				var oThis = PTPMMenuCache[id];
				var sm = oThis.subMenu;
				var selectedIndex = sm.getSelectedIndex();
				oThis.positionSubMenu();
				sm.setSelectedIndex( selectedIndex );
				oThis.setSelected( true );
				var el = oThis._htmlElement;
				el.mshown = '1';	
			},
			onclosetimer: function( id ) {
				var oThis = PTPMMenuCache[id];
				var sm = oThis.subMenu;
				sm.close();
				var el = oThis._htmlElement;
				el.mshown = '0';	
			},
			onpositionsubmenutimer:	function( id ) {
				var oThis = PTPMMenuCache[id];
				var sm = oThis.subMenu;
				sm.resetSizeCache();	
				oThis.positionSubMenu();
				sm.setSelectedIndex( 0 );
			}	
		},
		menuBar:	{
			onmouseover: function( e, id )
			{
				if (!e) e = window.event;
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{					var fromEl = PTPMMenu.getMenuItemElement( PTEventUtil.getMouseOverFromElement(e) );
					var toEl = PTPMMenu.getMenuItemElement( PTEventUtil.getMouseOverToElement(e) );
					if ( toEl != null && toEl != fromEl ) {
						var mb = toEl._menuItem;
						var m = mb.parentMenu;
						if ( m.getActiveState() == "open" ) {
							window.setTimeout( function() {
								mb.dispatchAction();
							}, 1);
						}
						else if ( m.getActiveState() == "active" ) {
							mb.setSelected( true );			
						}
						else {
							mb._hover = true;
						}
					}
				}
			},
			onmouseout:	function( e, id )
			{
				if (!e) e = window.event;
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{					var fromEl = PTPMMenu.getMenuItemElement( PTEventUtil.getMouseOutFromElement(e) );
					var toEl = PTPMMenu.getMenuItemElement( PTEventUtil.getMouseOutToElement(e) );
					if ( fromEl != null && toEl != fromEl ) {
						var mb = fromEl._menuItem;
						mb._hover = false;
					}
				}
			},
			onmousedown: function(e, id)
			{					if (!e) e = window.event;				var oThis = PTPMMenuCache[id];				if (!oThis.isDisabled)
				{
					if (PTEventUtil.getButtonClicked(e) != PTEventUtil.SRC_BUTTON_LEFT && PTEventUtil.getButtonClicked(e) != false) 					{ return; }
					var el = PTPMMenu.getMenuItemElement(PTEventUtil.getSrcElement(e));					if (el != null)
					{
						var mb = el._menuItem;
						if (mb && mb.subMenu)
						{
							mb.subMenu._checkCloseState();
							if ( new Date() - mb.subMenu._closedAt > 100 )
							{	
								mb.dispatchAction();
							}
							else
							{
								mb._hover = true;
							}
						}
					}
				}
				PTEventUtil.stopBubbling(e);
			},
			onkeydown: function( e, id ) {
				if (!e) e = window.event;				
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					oThis.handleKeyEvent( e );
				}
			},
			onunload: function( id ) {
				PTPMMenuCache[id].destroy();
			},
			ongotonextmenuitem:	function( id ) {
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var mi = oThis.items[ oThis.getSelectedIndex() ];
					mi.dispatchAction();
					if ( mi.subMenu )
						mi.subMenu.setSelectedIndex( 0 );
				}
			},
			ongotopreviousmenuitem:	function( id ) {
				var oThis = PTPMMenuCache[id];
				if (!oThis.isDisabled)
				{
					var mi = oThis.items[ oThis.getSelectedIndex() ];
					mi.dispatchAction();
					if ( mi.subMenu )
						mi.subMenu.setSelectedIndex( 0 );
				}
			}
		},
		menuButton:
		{
			onclose: function( id )
			{
				PTPMMenuCache[id].subMenuClosed();
			}
		}
	}
}

PTPMMenu.prepare = function(menu, TokenObjectNamePairs, callback, loadMessageCommand)
{
	var TokenObjects = new Object();
	TokenObjects['MENU'] = menu;
	for (var n in TokenObjectNamePairs)
	{
		TokenObjects[n] = eval(TokenObjectNamePairs[n]);
	}
	var m = new PTPMMenu();
	if (menu && menu.menuItems)
	{
		var numMenuItems = menu.menuItems.length;
		for (var i = 0; i < numMenuItems; i++)
		{
			m = PTPMMenu.recurseMenu(m, menu.menuItems[i], TokenObjects, callback, loadMessageCommand);
		}
	}
	return m;
}

PTPMMenu.recurseMenu = function(m, item, TokenObjects, callback, loadMessageCommand)
{
	if (item.action)
	{		
		TokenObjects['MITM']		= item;
		TokenObjects['MENUITEM']	= item;  
		if (item.action.type ==  PTPMAction.TYPE_URL)
		{
			item.action.onclick = 'top.document.location.href = \'' + item.action.getHref(TokenObjects) + '\'';
		}
		else if (item.action.type == PTPMAction.TYPE_JAVASCRIPT)
		{
			item.action.onclick = item.action.getOnclick(TokenObjects, false, false, loadMessageCommand, true);
		}
		else if (item.action.type == PTPMAction.TYPE_GET_XML)
		{
			if (callback) { item.action.callback = callback; }
			item.action.onclick = item.action.getOnclick(TokenObjects, false, false, loadMessageCommand, true);
		}
		else if (item.action.type == PTPMAction.TYPE_ACTION_CHAIN)
		{
			if (callback) { item.action.callback = callback; }
			item.action.onclick = item.action.getOnclick(TokenObjects, false, false, loadMessageCommand, true);
		}
		item.action.parent = item;
	}
	var type = parseInt(item.type);
	if (type == PTPMMenuItem.SIMPLE_MENU_ITEM)
	{
		var icon = '';
		if (item.image) { icon = item.image.imgSrc; }
		var mi = new PTPMSimpleMenuItem(item.text, item.action, icon);
		if (item.image)
		{
			mi.imgWidth = item.image.imgWidth;
			mi.imgHeight = item.image.imgHeight;
		}
		if (item.secondaryImage)
		{
			mi.secondaryIcon = item.secondaryImage.imgSrc;
			mi.secondaryImgWidth = item.secondaryImage.imgWidth;
			mi.secondaryImgHeight = item.secondaryImage.imgHeight;
		}
		mi.isDisabled = item.isDisabled;
		m.add(mi);
	}
	else if (type == PTPMMenuItem.DIVIDER_MENU_ITEM)
	{
		m.add(new PTPMDividerMenuItem());
	}
	else if (type == PTPMMenuItem.RADIO_MENU_ITEM)
	{
		var mi = new PTPMRadioButtonMenuItem(item.text, item.isChecked, item.radioGroupName, item.action);
		mi.isDisabled = item.isDisabled;
		m.add(mi);
	}
	else if (type == PTPMMenuItem.CHECKBOX_MENU_ITEM)
	{
		var mi = new PTPMCheckBoxMenuItem(item.text, item.isChecked, item.action);
		mi.isDisabled = item.isDisabled;
		m.add(mi);
	}
	else if (type == PTPMMenuItem.CASCADING_MENU_ITEM)
	{
		var m1 = new PTPMMenu();
		if (item.menu && item.menu.menuItems)
		{
			var numMenuItems = item.menu.menuItems.length;
			for (var i = 0; i < numMenuItems; i++)
			{
				m1 = PTPMMenu.recurseMenu(m1, item.menu.menuItems[i], TokenObjects, callback, loadMessageCommand);
			}
		}
		var icon = '';
		if (item.image) { icon = item.image.imgSrc; }
		var label = item.text;
		var mi = new PTPMSimpleMenuItem(label, null, icon, m1);
		if (item.image)
		{
			mi.imgWidth = item.image.imgWidth;
			mi.imgHeight = item.image.imgHeight;
		}
		if (item.secondaryImage)
		{
			mi.secondaryIcon = item.secondaryImage.imgSrc;
			mi.secondaryImgWidth = item.secondaryImage.imgWidth;
			mi.secondaryImgHeight = item.secondaryImage.imgHeight;
		}
		mi.isDisabled = item.isDisabled;
		m.add(mi);
	}
	if ((type != PTPMMenuItem.DIVIDER_MENU_ITEM) && item.objName) { window[item.objName] = mi; }
	return m;
}

PTPMMenu.showContextMenu = function(event, menu, left, top)
{
	var el;
	if(event) { el = PTEventUtil.getSrcElement(event); }
	var showEditMenu = el != null;
	while ((el != null) && (el.tagName != 'A')) { el = el.parentNode; }
	var showOpenItems = ((el != null) && (el.tagName == 'A'));
	var left, top;
	if (showEditMenu) { el = event.srcElement; }
	else if (!showOpenItems) { el = document.documentElement; }
	if(event)
	{
		if (PTPMMenu.useDivs)
		{
			left = PTEventUtil.getMouseX(event);
			top = PTEventUtil.getMouseY(event);
		}
		else
		{
			left = event.screenX;
			top = event.screenY;
		}
	}
	if (PTPMMenu.useDivs && !menu.parentMenu && !PTPMMenu.useDivs)
	{
		PTPMMenu.closeAll();
		document.onmousedown = PTPMMenu.closeAll;
	}
	if (PTPMMenu.useDivs)
	{
		PTPMMenu.closeAll();
		PTPMMenu.oldOnclick = document.onclick;
		document.onclick = new Function('PTPMMenu.closeAll(); document.onclick = PTPMMenu.oldOnclick;');
	}
	menu.invalidate();
	menu.show(left, top);
	if(event)
		event.returnValue = false;
	lastKeyCode = 0;
}

PTPMMenu.closeAll = function()
{
	for (var i in PTPMMenuCache)
	{
		try {
			PTPMMenuCache[i].closeAllMenus();
		} catch(e) {}

	}
	if (PTPMMenu.useDivs)
	{
		if (PTPMMenu.mouseupStorage) { document.body.onmouseup = PTPMMenu.mouseupStorage; }
		PTPMMenu.toggleSelectVisibility('visible');
		PTPMMenu.engaged = false;
	}
}

PTPMMenu.toggleSelectVisibility = function(vis,left,top,width,height)
{
	var docSelects = document.getElementsByTagName("SELECT");
	for (var i=0; i<docSelects.length; i++)
	{
		var s = docSelects[i];
		if (vis == 'hidden' && !PTBrowserInfo.IS_MSIE_5)
		{
			var sLeft = PTDOMUtil.getElementLeft(s);	
			var sTop = PTDOMUtil.getElementTop(s);
			var sWidth = PTDOMUtil.getElementWidth(s);
			var sHeight = PTDOMUtil.getElementHeight(s);
			if ((sLeft+sWidth > left && sLeft+sWidth < left+width && sTop > top && sTop < top+height) ||
				(sLeft > left && sLeft < left+width && sTop > top && sTop < top+height))
			{
				s.style.visibility = 'hidden';
			}
		}
		else
		{
			s.style.visibility = vis;
		}
	}
}

function PTPMContextMenu()
{
	this.menuItems				= new Array();
	this.beforeDisplayHandler	= false;
	return this;
}

PTPMContextMenu.prototype = new PTPMMenu();
PTPMContextMenu.prototype.constructor = PTPMContextMenu;
PTPMContextMenu.prototype._super = PTPMMenu;
PTPMContextMenu.invoke = function(menu, TokenObjects, callback, loadMessageCommand, left, top, e)
{
	if (!e) var e = window.event;
	if (menu.beforeDisplayHandler)
	{
		var preparedHandlerStatement = menu.beforeDisplayHandler.getOnclick(TokenObjects,true,false,loadMessageCommand);
		var handlerResult = eval(preparedHandlerStatement);
		if (handlerResult === false) { return; }
	}
	var m = new PTPMMenu();
	if (menu && menu.menuItems)
	{
		var numMenuItems = menu.menuItems.length;
		for (var i = 0; i < numMenuItems; i++)
		{
			m = PTPMMenu.recurseMenu(m, menu.menuItems[i], TokenObjects, callback, loadMessageCommand);
		}
	}
	PTPMMenu.showContextMenu(e, m, left, top);
}

PTPMMenu.clickJSPortalMenu = function(menuID ,searchtext)
{
	var oMenu = document.getElementById(menuID);
	var pdoc = oMenu._menuItem.subMenu.getDocument();
	var rows = pdoc.body.getElementsByTagName("TR");
	for ( var i = 0; i < rows.length; i++ ) 
	{
	  if ( rows[i].outerText.indexOf(searchtext)!= -1 && rows[i].outerText.length == 2+(searchtext.length)) {
	  	if ( rows[i].outerText.indexOf("<b>") == -1 || rows[i].outerText.indexOf("<B>") == -1 ) 
	  	{
	  	  window.location = window.location;
	  	  return;
	  	}
		rows[i].fireEvent('onmouseup');
		return;
	  }
	}
}

function PTPMMenuItem(text,tooltip,image,action,textBeforeImg) 
{
	return this;
}

PTPMMenuItem.SIMPLE_MENU_ITEM		= 0;
PTPMMenuItem.DIVIDER_MENU_ITEM	= 1;
PTPMMenuItem.RADIO_MENU_ITEM		= 2;
PTPMMenuItem.CHECKBOX_MENU_ITEM	= 3;
PTPMMenuItem.CASCADING_MENU_ITEM	= 4;
PTPMMenuItem.DIRECTION_HORIZONTAL	= 'horizontal';
PTPMMenuItem.DIRECTION_VERTICAL	= 'vertical';
function PTPMMenuContainer(text,tooltip,image,action,textBeforeImg) {
	this.text			= (text) ? text : '';
	this.tooltip		= (tooltip) ? tooltip : '';
	this.image			= (image) ? image : new PTPMImage();
	this.action			= (action) ? action : false;
	this.textBeforeImg	= (textBeforeImg) ? textBeforeImg : false;
	this.menuItems		= new Array();
	this.isSelected		= false;
	return this;
}

function PTPMSimpleMenuItem(sLabelText, fAction, sIconSrc, oSubMenu)
{	this.icon					= (sIconSrc) ? (sIconSrc) : '';
	this.imgWidth				= '';
	this.imgHeight				= '';
	this.secondaryIcon			= '';
	this.secondaryImgWidth		= '';
	this.secondaryImgHeight		= '';
	this.text					= sLabelText;
	this.action					= fAction;
	this.subMenu				= oSubMenu;
	this.parentMenu				= null;
	this.isDisabled				= false;
	this.mnemonic				= null;
	this.shortcut				= null;
	this.toolTip				= '';
	this.target					= null;
	this.visible				= true;
	this._selected				= false;
	this._useInsets				= true;	
	this.id = PTPMMenuCache.getId();
	PTPMMenuCache[ this.id ] = this;
}

PTPMSimpleMenuItem.prototype.type = PTPMMenuItem.SIMPLE_MENU_ITEM;
PTPMSimpleMenuItem.prototype.subMenuDirection = PTPMMenuItem.DIRECTION_HORIZONTAL;
PTPMSimpleMenuItem.prototype.disable = function()
{
	this.isDisabled = true;
	this.parentMenu.invalidate();
}

PTPMSimpleMenuItem.prototype.enable = function()
{
	this.isDisabled = false;
	this.parentMenu.invalidate();
}

PTPMSimpleMenuItem.prototype.toHtml = function()
{
	var cssClass = this.getCssClass();
	var toolTip = this.getTooltip();
	var html = "<tr" +
			(cssClass != "" ? " class=\"" + cssClass + "\"" : "") +
			(toolTip != "" ? " title=\"" + toolTip + "\"" : "") +
			(!this.visible ? " style=\"display: none\"" : "") +
			" id=\"menu-row" + this.id + "\">" +
			this.getIconCellHtml() +
			this.getTextCellHtml() +
			this.getShortcutCellHtml() +
			this.getSubMenuArrowCellHtml() +
			"</tr>";
	return html;
}

PTPMSimpleMenuItem.prototype.getTextHtml = function()
{
	var s = this.text;
	if (this.mnemonic == null)
		return s;
	var re = new RegExp( "(" + this.mnemonic + ")", "i" ); 
	var a = re.exec( s );
	var c = a != null ? a[1] : "";
	return s.replace( re, "<u>" + c + "</u>" );
}

PTPMSimpleMenuItem.prototype.getIconHtml = function()
{
	var width = (this.imgWidth != '') ? ' width="' + this.imgWidth + '"' : ' width="16"';
	var height = (this.imgHeight != '') ? ' height="' + this.imgHeight + '"' : ' height="16"';
	var iconHTML = (this.icon != '') ? '<img src="' + this.icon + '"' + width + height + ' border="0"/>' : '<span>&nbsp;</span>';
	var secondIconHTML = '';
	if (this.secondaryIcon.length > 0)
	{
		var w2 = (this.secondaryImgWidth != '') ? ' width="' + this.secondaryImgWidth + '"' : ' width="16"';
		var h2 = (this.secondaryImgHeight != '') ? ' height="' + this.secondaryImgHeight + '"' : ' height="16"';
		secondIconHTML = '<img src="' + this.secondaryIcon + '"' + w2 + h2 + ' border="0"/>';
	}
	return secondIconHTML + iconHTML;
}

PTPMSimpleMenuItem.prototype.getTextCellHtml = function()
{
	var cellClass = (PTPMMenu.useDivs) ? 'label-cell-div' : 'label-cell-popup';
	return '<td class="' + cellClass + '" nowrap="nowrap">' +
			this.makeDisabledContainer(
				this.getTextHtml()
			) +
			'</td>';
}

PTPMSimpleMenuItem.prototype.getIconCellHtml = function()
{
	var iconClass = (this.icon != '') ? 'icon-cell' : 'empty-icon-cell';
	var html = '<td class="' + iconClass + '" nowrap="true">' + this.makeDisabledContainer(this.getIconHtml()) + '</td>';
	return html;
}

PTPMSimpleMenuItem.prototype.getCssClass = function()
{
	if (this.isDisabled && this._selected)	{ return 'disabled-hover'; }
	else if (this.isDisabled)				{ return 'disabled'; }
	else if (this._selected)				{ return 'hover'; }
	else 									{ return ''; }
}

PTPMSimpleMenuItem.prototype.getTooltip = function()
{
	return this.toolTip;
}

PTPMSimpleMenuItem.prototype.getShortcutHtml = function()
{
	if ( this.shortcut == null )
		return "&nbsp;";
	return this.shortcut;
}

PTPMSimpleMenuItem.prototype.getShortcutCellHtml = function()
{
	return "<td class=\"shortcut-cell\" nowrap=\"nowrap\">" +
			this.makeDisabledContainer(
				this.getShortcutHtml()
			) +
			"</td>";
}

PTPMSimpleMenuItem.prototype.getSubMenuArrowHtml = function()
{
	if ( this.subMenu == null )
		return "&nbsp;";
	if (PTBrowserInfo.IS_MSIE)
	{
		return 4;	
	}
	else
	{
		return '\u25B6';
	}
}

PTPMSimpleMenuItem.prototype.getSubMenuArrowCellHtml = function()
{
	return "<td class=\"arrow-cell\">" +
			this.makeDisabledContainer(
				this.getSubMenuArrowHtml()
			) +
			"</td>";
}

PTPMSimpleMenuItem.prototype.makeDisabledContainer = function( s )
{
	if ( this.isDisabled )
		return	"<span class=\"disabled-container\"><span class=\"disabled-container\">" +
				s + "</span></span>";
	return s;
}

PTPMSimpleMenuItem.prototype.dispatchAction = function()
{
	if (this.isDisabled) { return; }
	this.setSelected(true);
	if (this.subMenu)
	{		if (!this.subMenu.isShown()) { this.showSubMenu(false); }
		return;
	}
	if (!this.action || !this.action.type) { return; }
	eval(this.action.onclick);
	this.parentMenu.closeAllMenus();
}

PTPMSimpleMenuItem.prototype.setSelected = function( bSelected )
{
	if (this._selected == bSelected) { return; }
	this._selected = Boolean(bSelected);
	var tr = this._htmlElement;
	if (tr) { tr.className = this.getCssClass(); }
	if (!this._selected) { this.closeSubMenu(true); }
	var pm = this.parentMenu;
	if (bSelected)
	{	
		pm.setSelectedIndex(this.itemIndex);
		this.scrollIntoView();
		if (pm.parentMenuItem) { pm.parentMenuItem.setSelected(true); }
	}
	else
	{
		pm.setSelectedIndex(-1);
	}
	if (this._selected)
	{		window.clearTimeout(pm._closeTimer);
	}
}

PTPMSimpleMenuItem.prototype.getSelected = function()
{
	return this.itemIndex == this.parentMenu.selectedIndex;
}

PTPMSimpleMenuItem.prototype.showSubMenu = function(bDelayed)
{
	var sm = this.subMenu;
	var pm = this.parentMenu;
	if (sm && !this.isDisabled)
	{
		pm._aboutToShowSubMenu = true;
		window.clearTimeout( sm._showTimer );
		window.clearTimeout( sm._closeTimer );
		var showTimeout = bDelayed ? sm.showTimeout : 0;
		var oThis = this;		sm._showTimer = window.setTimeout('PTPMMenuEventListeners.menuItem.onshowtimer(\'' + this.id + '\')', showTimeout);
	}
}

PTPMSimpleMenuItem.prototype.closeSubMenu = function( bDelay )
{
	var sm = this.subMenu;
	if ( sm ) {
		window.clearTimeout( sm._showTimer );
		window.clearTimeout( sm._closeTimer );
		if ( sm.popup ) {
			if ( !bDelay )
				sm.close();
			else {
				var oThis = this;
				sm._closeTimer = window.setTimeout(
					"PTPMMenuEventListeners.menuItem.onclosetimer(\"" + this.id + "\")",
					sm.closeTimeout );
			}
		}
	}
}

PTPMSimpleMenuItem.prototype.scrollIntoView = function()
{
	if (PTPMMenu.useDivs) { return; }
	if (this.parentMenu._scrollingMode) {
		var d = this.parentMenu.getDocument();
		var sc = d.getElementById('scroll-container' + this.parentMenu.id);
		var scrollTop = sc.scrollTop;
		var clientHeight = sc.clientHeight;
		var offsetTop = this._htmlElement.offsetTop;
		var offsetHeight = this._htmlElement.offsetHeight;
		if ( offsetTop < scrollTop )
			sc.scrollTop = offsetTop;
		else if ( offsetTop + offsetHeight > scrollTop + clientHeight )
			sc.scrollTop = offsetTop + offsetHeight - clientHeight;
	}
}

PTPMSimpleMenuItem.prototype.positionSubMenu = function()
{
	var dir = this.subMenuDirection;
	var el = this._htmlElement;
	var buttonEl = this._buttonHTMLElement;  
	var useInsets = this._useInsets;
	var sm = this.subMenu;
	var oThis = this;
	if (!sm._isCssFileLoaded())
	{
		window.setTimeout('PTPMMenuEventListeners.menuItem.onpositionsubmenutimer(\'' + this.id + '\')',1);
		return;
	}
	if (buttonEl)
	{
		var rect = {
			left:	PTPMPosition.getScreenLeft(buttonEl),
			top:	PTPMPosition.getScreenTop(buttonEl),
			width:	buttonEl.offsetWidth,
			height:	buttonEl.offsetHeight
		};
	}
	else
	{
		var rect = {
			left:	PTPMPosition.getScreenLeft(el),
			top:	PTPMPosition.getScreenTop(el),
			width:	el.offsetWidth,
			height:	el.offsetHeight
		};
	}
	var menuRect = {
		left:			sm.getLeft(),
		top:			sm.getTop(),
		width:			sm.getPreferredWidth(),
		height:			sm.getPreferredHeight(),
		insetLeft:		useInsets ? sm.getInsetLeft() : 0,
		insetRight:		useInsets ? sm.getInsetRight() : 0,
		insetTop:		useInsets ? sm.getInsetTop() : 0,
		insetBottom:	useInsets ? sm.getInsetBottom() : 0
	};
	var screenWidth = screen.width;
	var screenHeight = screen.height;
	while ( rect.left > screenWidth )
		screenWidth += screen.width;
	while ( rect.top > screenHeight )
		screenHeight += screen.height;
	var left, top, width = menuRect.width, height = menuRect.height;
	if (dir == PTPMMenuItem.DIRECTION_VERTICAL) {
		if ( rect.left + menuRect.width - menuRect.insetLeft <= screenWidth ) {
			left = rect.left - menuRect.insetLeft;
		} else if ( screenWidth >= menuRect.width ) {
			left = screenWidth - menuRect.width;
		} else {
			left = 0;
		}
		if ( rect.top + rect.height + menuRect.height - menuRect.insetTop <= screenHeight ) {
			top = rect.top + rect.height - menuRect.insetTop;
		} else if ( rect.top - menuRect.height + menuRect.insetBottom >= 0 ) {
			top = rect.top - menuRect.height + menuRect.insetBottom;
		} else {	
			var sizeAbove = rect.top + menuRect.insetBottom;
			var sizeBelow = screenHeight - rect.top - rect.height + menuRect.insetTop;
			if ( sizeBelow >= sizeAbove ) {
				top = rect.top + rect.height - menuRect.insetTop;
				height = sizeBelow;			
			}
			else {
				top = 0;
				height = sizeAbove;
			}
		}
	}
	else {  
		if ( rect.top + menuRect.height - menuRect.insetTop <= screenHeight ) {
			top = rect.top - menuRect.insetTop;
		} else if ( rect.top + rect.height - menuRect.height + menuRect.insetBottom >= 0) {
			top = rect.top + rect.height - menuRect.height + menuRect.insetBottom;
		} else if ( screenHeight >= menuRect.height ) {
			top = screenHeight - menuRect.height;
		} else {
			top = 0;
			height = screenHeight;
		}
		if ( rect.left + rect.width + menuRect.width - menuRect.insetLeft <= screenWidth ) {
			left = rect.left + rect.width - menuRect.insetLeft;
		} else if ( rect.left - menuRect.width + menuRect.insetRight >= 0 ) {
			left = rect.left - menuRect.width + menuRect.insetRight;
		} else if ( screenWidth >= menuRect.width ) {
			left = screenWidth - menuRect.width;
		} else {
			left = 0;
		}
	}
	var scrollBefore = sm._scrollingMode;
	if (PTPMMenu.useDivs)
	{
		var div = buttonEl ? buttonEl : document.getElementById(this.parentMenu.id);
		if (div)
		{
			if (dir == PTPMMenuItem.DIRECTION_VERTICAL)
			{				left = PTDOMUtil.getElementLeft(div);
				var checkWidth = (PTBrowserInfo.IS_MSIE) ? Math.max(width, 200) : width;
				if (left + checkWidth > PTDOMUtil.getWindowWidth())
				{
					left = PTDOMUtil.getWindowWidth() - checkWidth;
				}
				top = PTDOMUtil.getElementTop(div) + PTDOMUtil.getElementHeight(div);
			}
			else
			{
				left = PTPMPosition.getClientLeft(div) + PTPMPosition.getWidth(div.parentElement);
				top = PTPMPosition.getTop(div);
			}
			if (PTPMMenu.engaged) { PTPMMenu.closeAll(); }
			PTPMMenu.engaged = true;
			PTPMMenu.mouseupStorage = (document.body.onmouseup) ? document.body.onmouseup : new Function('true');
			window.setTimeout('document.body.onmouseup = PTPMMenu.closeAll',350);
			PTPMMenu.toggleSelectVisibility('hidden',left,top,sm.getPreferredWidth(),sm.getPreferredHeight());
		}
	}
	sm.show(left,top,width,height);
	if (sm._scrollingMode != scrollBefore) { this.positionSubMenu(); }
}

PTPMSimpleMenuItem.prototype.destroy = function()
{
	if ( this.subMenu != null )
		this.subMenu.destroy();
	this.subMenu = null;
	this.parentMenu = null;
	var el = this._htmlElement
	if ( el != null )
		el._menuItem = null;
	this._htmlElement = null;
	PTPMMenuCache.remove( this );
}

function PTPMCheckBoxMenuItem( sLabelText, bChecked, fAction, oSubMenu )
{
	this.PTPMSimpleMenuItem = PTPMSimpleMenuItem;
	this.PTPMSimpleMenuItem( sLabelText, fAction, null, oSubMenu);
	this.isChecked = bChecked;
}

PTPMCheckBoxMenuItem.prototype = new PTPMSimpleMenuItem;
PTPMCheckBoxMenuItem.prototype.type = PTPMMenuItem.CHECKBOX_MENU_ITEM;
PTPMCheckBoxMenuItem.prototype.getIconHtml = function()
{
	if (PTBrowserInfo.IS_MSIE)
	{
		var html = '<span class="check-box">' + ((this.isChecked == true) ? 'a' : '') + '</span>';
		return html;
	}
	else
	{
		if (this.isChecked)	{ return '\u2714'; }
		else				{ return ''; }
	}
}

PTPMCheckBoxMenuItem.prototype.getIconCellHtml = function()
{
	return "<td class=\"icon-cell\">" +
			this.makeDisabledContainer(
				this.getIconHtml()
			) +
			"</td>";
}

PTPMCheckBoxMenuItem.prototype.getCssClass = function()
{
	var s = ((this.isChecked == true) ? ' checked' : '');
	if (this.isDisabled && this._selected)
	{
		var cls = 'disabled-hover' + s;
	}
	else if (this.isDisabled)
	{
		var cls = 'disabled' + s;
	}
	else if (this._selected)
	{
		var cls = 'hover' + s;
	}
	else
	{
		var cls = s;
	}
	return cls;
}

PTPMCheckBoxMenuItem.prototype._menuItem_dispatchAction =
	PTPMSimpleMenuItem.prototype.dispatchAction;
PTPMCheckBoxMenuItem.prototype.dispatchAction = function()
{
	if (!this.isDisabled) {
		this.isChecked = !this.isChecked;
		if (this.action)
		{
			this.action.parent.isChecked = !this.action.parent.isChecked;
		}
		this._menuItem_dispatchAction();
		this.parentMenu.invalidate();
		this.parentMenu.closeAllMenus();
	}
}

function PTPMRadioButtonMenuItem( sLabelText, bChecked, sRadioGroupName, fAction, oSubMenu )
{
	this.PTPMSimpleMenuItem = PTPMSimpleMenuItem;
	this.PTPMSimpleMenuItem( sLabelText, fAction, null, oSubMenu);
	this.isChecked = bChecked;
	this.radioGroupName = sRadioGroupName;
}

PTPMRadioButtonMenuItem.prototype = new PTPMSimpleMenuItem;
PTPMRadioButtonMenuItem.prototype.type = PTPMMenuItem.RADIO_MENU_ITEM;
PTPMRadioButtonMenuItem.prototype.getIconHtml = function()
{
	if (PTBrowserInfo.IS_MSIE)
	{
		return '<span class="radio-button">' +
			(this.isChecked ? 'n' : '') +
			'</span>';
	}
	else
	{
		if (this.isChecked) return '\u25CF';
		else return ''; 
	}
}

PTPMRadioButtonMenuItem.prototype.getIconCellHtml = function()
{
	return "<td class=\"icon-cell\">" +
			this.makeDisabledContainer(
				this.getIconHtml()
			) +
			"</td>";
}

PTPMRadioButtonMenuItem.prototype.getCssClass = function()
{
	var s = (this.isChecked ? " checked" : "");
	if ( this.isDisabled && this._selected )
		return "disabled-hover" + s;
	else if ( this.isDisabled )
		return "disabled" + s;
	else if ( this._selected )
		return "hover" + s;
	return s;
}

PTPMRadioButtonMenuItem.prototype._menuItem_dispatchAction =
	PTPMSimpleMenuItem.prototype.dispatchAction;
PTPMRadioButtonMenuItem.prototype.dispatchAction = function()
{
	if (!this.isDisabled) {
		if ( !this.isChecked ) {			var items = this.parentMenu.items;
			var l = items.length;
			for ( var i = 0; i < l; i++ ) {
				if ( items[i] instanceof PTPMRadioButtonMenuItem ) {
					if ( items[i].radioGroupName == this.radioGroupName ) {
						items[i].isChecked = items[i] == this;
						if (items[i].action && items[i].action.parent) {
							items[i].action.parent.isChecked = items[i] == this;
						}
					}
				}
			}
			this.parentMenu.invalidate();
		}
		this._menuItem_dispatchAction();
		this.parentMenu.closeAllMenus();
	}
}

function PTPMDividerMenuItem() {
	this.PTPMSimpleMenuItem = PTPMSimpleMenuItem;
	this.PTPMSimpleMenuItem();
}

PTPMDividerMenuItem.prototype = new PTPMSimpleMenuItem;
PTPMDividerMenuItem.prototype.type = PTPMMenuItem.DIVIDER_MENU_ITEM;
PTPMDividerMenuItem.prototype.toHtml = function()
{
	var sb = new PTStringBuffer();
	sb.append('<tr class=""');
	sb.append((!this.visible ? ' style="display:none;"' : ''));
	sb.append('><td class="empty-icon-cell"></td>\n');
	sb.append('<td colspan="3"><div class="separator-line"></div></td>\n</tr>');
	return sb.toString();
}

PTPMDividerMenuItem.prototype.getCssClass = function()
{
	return 'separator';
}

function PTPMCascadingMenuItem(oMenu, sIconSrc)
{
	this.menu = (oMenu) ? oMenu : new PTPMMenuContainer();
	this.icon = (sIconSrc) ? (sIconSrc) : '';
	return this;
}

PTPMCascadingMenuItem.prototype = new PTPMSimpleMenuItem;
PTPMCascadingMenuItem.prototype.type = PTPMMenuItem.CASCADING_MENU_ITEM;
function PTPMMenuButton( sLabelText, oSubMenu, bDoClassOverride )
{
	this.PTPMSimpleMenuItem = PTPMSimpleMenuItem;
	this.PTPMSimpleMenuItem( sLabelText, null, null, oSubMenu );
	this.doClassOverride = bDoClassOverride;  
	this._hover = false;
	this._useInsets = false;	
	var oThis = this;
	this.subMenu._onclose = new Function( "PTPMMenuEventListeners.menuButton.onclose(\"" + this.id + "\")" );
}

PTPMMenuButton.prototype = new PTPMSimpleMenuItem;
PTPMMenuButton.prototype.subMenuDirection = PTPMMenuItem.DIRECTION_VERTICAL;
PTPMMenuButton.prototype.scrollIntoView = function() {};
PTPMMenuButton.prototype.toHtml = function()
{
	var toolTip = this.getTooltip();
	var sb = new PTStringBuffer();
	sb.append('<span id="'+ this.ptname +'" unselectable="on"'); 
	sb.append( (toolTip != '' ? ' title="' + toolTip + '"' : ' title=""') );
	sb.append(' class="navMidtabText">');
	sb.append('<a href="#" onclick="return false" onmouseover="window.status=\'' + toolTip + '\';return true" onmouseout="window.status=\'\';return true">');
	sb.append( this.getTextHtml() );
	sb.append('</a></span>');
	return sb.toString();
}

PTPMMenuButton.prototype.getCssClass = function()
{
	return 'navMidtabText';
}

PTPMMenuButton.prototype.subMenuClosed = function()
{
	if (this.subMenu._closeReason == 'escape')	{ this.setSelected(true); }
	else 										{ this.setSelected( false ); }
	if (this.parentMenu.getActiveState() == 'inactive') { this.parentMenu.restoreFocused(); }
}

PTPMMenuButton.prototype.setSelected = function(bSelected)
{
	var oldSelected = this._selected;
	this._selected = Boolean(bSelected);
	var tr = this._htmlElement;
	if (tr)
	{
		if (!this.doClassOverride) { tr.className = this.getCssClass(); }
	}
	if (this._selected == oldSelected) { return; }
	if (!this._selected){ this.closeSubMenu(true); }
	if (bSelected)
	{
		this.parentMenu.setSelectedIndex(this.itemIndex);
		this.scrollIntoView();
	}
	else
	{
		this.parentMenu.setSelectedIndex( -1 );
	}
}

PTPMPosition = new Object();
PTPMPosition.getClientLeft = function(element)
{
	var r = PTPMPosition.getBoundingClientRectXP(element);
	return r.left - this.getBorderLeftWidth(this.getCanvasElement(element));
}

PTPMPosition.getClientTop = function(element)
{
	var r = PTPMPosition.getBoundingClientRectXP(element);
	return r.top - this.getBorderTopWidth(this.getCanvasElement(element));
}

PTPMPosition.getLeft = function(element)
{
	return this.getClientLeft(element) + this.getCanvasElement(element).scrollLeft;
}

PTPMPosition.getTop = function(element)
{
	return this.getClientTop(element) + this.getCanvasElement(element).scrollTop;
}

PTPMPosition.getWidth = function(element)
{
	if (element)
	{
		return element.offsetWidth;
	}
	else
	{
		return 0;
	}
}

PTPMPosition.getHeight = function(element)
{
	if (element) { return element.offsetHeight; }
	else { return 0; }
}

PTPMPosition.getCanvasElement = function(element)
{
	var failed = false;
	try {
		var doc = element.ownerDocument || element.document || document;
	} catch(e) { failed = true; }
	if (failed)
	{
		try {
			var doc = element.document || document;
		} catch(e) {
			var doc = document;
		}
	}
	if (doc && doc.compatMode && (doc.compatMode == 'CSS1Compat')) { return doc.documentElement; }
	else { return doc.body; }
}

PTPMPosition.getBorderLeftWidth = function(element)
{
	return ((element.clientLeft) ? element.clientLeft : 0);
}

PTPMPosition.getBorderTopWidth = function(element)
{
	return ((element.clientTop) ? element.clientTop : 0);
}

PTPMPosition.getScreenLeft = function(element)
{
	if (PTBrowserInfo.IS_MSIE)
	{
		var doc = element.ownerDocument || element.document;
		var w = doc.parentWindow;
		return w.screenLeft + this.getBorderLeftWidth(this.getCanvasElement(element)) + this.getClientLeft(element);
	}
	else if (PTBrowserInfo.IS_MOZILLA)
	{
		return window.screenX + this.getBorderLeftWidth(this.getCanvasElement(element)) + this.getClientLeft(element);
	}
}

PTPMPosition.getScreenTop = function(element)
{
	if (PTBrowserInfo.IS_MSIE)
	{
		var doc = element.ownerDocument || element.document;
		var w = doc.parentWindow;
		return w.screenTop + this.getBorderTopWidth(this.getCanvasElement(element)) + this.getClientTop(element);
	}
	else if (PTBrowserInfo.IS_MOZILLA)
	{
		return window.screenY + this.getBorderTopWidth(this.getCanvasElement(element)) + this.getClientTop(element);
	}
}

PTPMPosition.getBoundingClientRectXP = function(element)
{
	if (PTBrowserInfo.IS_MSIE)
	{
		if (element && element.getBoundingClientRect)
		{
			return element.getBoundingClientRect();
		}
		else
		{
			return 0;
		}
	}
	else if (PTBrowserInfo.IS_MOZILLA)
	{
		var obj = new Object();
		obj.left = PTDOMUtil.getElementLeft(element);
		obj.top = PTDOMUtil.getElementTop(element);
		obj.right = obj.left + element.offsetWidth;
		obj.bottom = obj.top + element.offsetHeight;
		return obj;
	}
}

PTPMPosition.setTop = function(element,size)
{
	if (PTBrowserInfo.IS_MSIE)	{ element.style.pixelTop = size; }
	else				{ element.style.top = size; }
}

PTPMPosition.setLeft = function(element,size)
{
	if (PTBrowserInfo.IS_MSIE)	{ element.style.pixelLeft = size; }
	else				{ element.style.left = size; }
}

PTPMPosition.setWidth = function(element,size)
{
	if (PTBrowserInfo.IS_MSIE)	{ element.style.pixelWidth = size; }
	else				{ element.style.width = size; }
}

PTPMPosition.setHeight = function(element,size)
{
	if (PTBrowserInfo.IS_MSIE)	{ element.style.pixelHeight = size; }
	else				{ element.style.height = size; }
}