/*	File: controls.js
*/

var controls = new _objControls();

var CONTROL_TYPE_DROPDOWN = 1;
var CONTROL_TYPE_INLINEPOPUP = 2;

try
{
	if(dragNDrop){};
}
catch(e)
{
	var dragNDrop;
}

function _objControls()
{
	this.items = new Array;
	this.addControl = _addControl;
	this.displayButton = _displayButton;
	this.displayButtonAlt = _displayButtonAlt;
	this.displayProgressBar = _displayProgressBar;
	this.setIcon = _setIcon;
	this.setCaption = _setCaption;
	
	return this;
}

function _setIcon(name_id_img, icon)
{
	var obj;
	
	for(count = 0; count < document.getElementsByName(name_id_img).length; count++)
	{
		obj = document.getElementsByName(name_id_img)[count];
		if(obj)
		{
			obj.src = icon;
		}
	}
}

function _setCaption(name_id_caption, caption)
{
	var obj;

	for(count = 0; count < document.getElementsByName(name_id_caption).length; count++)
	{
		obj = document.getElementsByName(name_id_caption)[count];
		if(obj)
		{
			obj.innerHTML = caption;
		}
	}
}

function _addControl(type, caption)
{
	var item;
	
	switch(type)
	{
		case CONTROL_TYPE_DROPDOWN:
			item = new _objDropdown(caption);
			break;
		case CONTROL_TYPE_INLINEPOPUP:
			item = new _objInlinePopup(caption);
			break;
	}
	item.id = this.items.length;
	this.items[this.items.length] = item;
	
	return item;
}

function _displayButton(icon, caption, call, isLink)
{
	var output = '';
	var tabIndex = '';
	var disabled = false;
	var hint = '';
	var name_id_img = '';
	var name_id_caption = '';

	if(arguments.length > 4)
	{
		if(!(arguments[4] == null || arguments[4] <= 0))
		{
			tabIndex = ' tabindex=\"' + arguments[4] + '\"';
		}
	}
	if(arguments.length > 5)
	{
		if(!(arguments[5] == null))
		{
			disabled = arguments[5];
		}
	}
	if(arguments.length > 6)
	{
		if(!(arguments[6] == null || arguments[6] == ''))
		{
			//hint = ' onmouseover=\"this.T_WIDTH=250;return escape(\'' + arguments[6] + '\')\"';
		}
	}
		
	if(arguments.length > 7)
	{
		if(!(arguments[7] == null || arguments[7] == ''))
		{
			name_id_img = arguments[7];
		}
	}

	if(arguments.length > 8)
	{
		if(!(arguments[8] == null || arguments[8] == ''))
		{
			name_id_caption = arguments[8];
		}
	}
			
	if(!disabled)
	{
		if(isLink)
		{
			output = '<a class=\"BUTTON\" href=\"' + call + '\"' + tabIndex + hint + '>';
		}
		else
		{
			output = '<a class=\"BUTTON\" href=\"javascript:;\" onclick=\"' + call + ';return false\"' + tabIndex + hint + '>';
		}
	}
	else
	{
		output = '<span class=\"BUTTONDISABLED\"' + hint + '>';
	}
	
	
	output += '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
			  '<tr>';

	if(icon != '')
	{
		if(name_id_img != '')
		{
			output += '<td class=\"IMG\"><img id=\"' + name_id_img + '\" name=\"' + name_id_img + '\" align=\"absmiddle\" src=\"' + icon + '\"></td>';
		}
		else
		{
			output += '<td class=\"IMG\"><img align=\"absmiddle\" src=\"' + icon + '\"></td>';
		}
	}
	if(name_id_caption != '')
	{
	   output += '<td class=\"TEXT\" id=\"' + name_id_caption + '\" name=\"' + name_id_caption + '\" nowrap>' + caption + '</td>';
	}
	else
	{
	   output += '<td class=\"TEXT\" nowrap>' + caption + '</td>';
	}
		
	output += '</tr>' +
			  '</table>';
			  
	if(!disabled)
	{
		output += '</a>';
	}
	else
	{
		output += '</span>';
	}	
	
	document.write(output);
}

function _displayButtonAlt(icon, caption, call, isLink)
{
	var output = '';
	var tabIndex = '';
	var disabled = false;
	var hint = '';

	if(arguments.length > 4)
	{
		if(!(arguments[4] == null || arguments[4] <= 0))
		{
			tabIndex = ' tabindex=\"' + arguments[4] + '\"';
		}
	}
	if(arguments.length > 5)
	{
		if(!(arguments[5] == null))
		{
			disabled = arguments[5];
		}
	}
	if(arguments.length > 6)
	{
		if(!(arguments[6] == null || arguments[6] == ''))
		{
			hint = ' onmouseover=\"this.T_WIDTH=250;return escape(\'' + arguments[6] + '\')\"';
		}
	}

	if(!disabled)
	{
		if(isLink)
		{
			output = '<a class=\"BUTTONALT\" href=\"' + call + '\"' + tabIndex + hint + '>';
		}
		else
		{
			output = '<a class=\"BUTTONALT\" href=\"javascript:;\" onclick=\"' + call + ';return false\"' + tabIndex + hint + '>';
		}
	}	
	else
	{
		output = '<span class=\"BUTTONALTDISABLED\"' + hint + '>';
	}
	
	output += '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
			  '<tr>';
	if(icon != '')
	{
		output += '<td class=\"IMG\"><img align=\"absmiddle\" src=\"' + icon + '\"></td>' +
				  '<td class=\"TEXT\" nowrap>' + caption + '</td>';
	}
	else
	{
		output += '<td class=\"TEXT\" nowrap>' + caption + '</td>';
	}
	output += '</tr>' +
			  '</table>';
			  
	if(!disabled)
	{
		output += '</a>';
	}
	else
	{
		output += '</span>';
	}	

	document.write(output);
}

function _displayProgressBar(value, size)
{
	var WARNING_LEVEL = 90;
	var output = '';
	var width;
	var percentage = value;
	var className = 'PROGRESSBAR';
	
	width = Math.round(percentage * (size - 2) / 100);	// Subtract 2 pixels for the border
	if(percentage >= WARNING_LEVEL)
	{
		className = 'PROGRESSBARWARNING';
	}
	
	output = '<table class=\"PROGRESSBAR\" width=\"' + size + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
			 '<tr>' +
			 '<td><img src=\"/__o3sis_UICACHETOKEN__/app_pic/bg_progressbar_border.gif\" width=\"1\" height=\"100%\"></td>' +
			 '<td class=\"' + className + '\" width=\"' + width + '\"><img src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"' + width + '\" height=\"1\"></td>' +
			 '<td width=\"100%\"></td>' +
			 '<td><img src=\"/__o3sis_UICACHETOKEN__/app_pic/bg_progressbar_border.gif\" width=\"1\" height=\"100%\"></td>' +
			 '</tr>' +
			 '</table>';
	
	document.write(output);
}

// *****************************************************************************************

function _objDropdown(caption)
{
	this.controlName = '';
	this.height = 19;
	this.caption = caption;
	this.popup = new _objPopup(this);
	this.enabled = true;
	this.id = -1;
	this.allowDrop = false;
	this.onDrop = null;
	this.addItem = _addDropdownItem;
	this.display = _displayDropdown;
	this.displayItems = _displayDropdownItems;
	this.setCaption = _setDropdownCaption;
	
	return this;
}

function _addDropdownItem(icon, caption, call, isLink)
{
	var value = '';
	
	if(arguments.length > 4)
	{
		value = arguments[4];
	}
	this.popup.addItem(icon, caption, call, isLink, value);
}

function _displayDropdown(controlName)
{
	var CELL_HEIGHT = 20;
	var output = '';
	var width = 0;
	var mouseOver = '';
	
	if(arguments.length > 1)
	{
		width = arguments[1];
	}
	
	this.controlName = controlName;
	
	if(this.allowDrop && dragNDrop)
	{
		mouseOver = ' onmouseover=\"if(controls.items[' + this.id + '].onDrop != null){dragNDrop.onDrop = controls.items[' + this.id + '].onDrop}if(dragNDrop.isDragging){controls.items[' + this.id + '].displayItems(\'' + controlName + '\',true)}\"';
	}
	
	if(width > 0)
	{
		output = '<table id=\"' + controlName + '\" class=\"DROPDOWN\" width=\"' + width + '\" height=\"' + CELL_HEIGHT + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"' + mouseOver + '>' +
				 '<tr>' +
				 '<td class=\"DROPDOWN\" width=\"100%\" height=\"' + (CELL_HEIGHT - 2) + '\" nowrap onclick=\"controls.items[' + this.id + '].displayItems(\'' + controlName + '\')\">';
	}
	else
	{
		output = '<table id=\"' + controlName + '\" class=\"DROPDOWN\" height=\"' + CELL_HEIGHT + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"' + mouseOver + '>' +
				 '<tr>' +
				 '<td class=\"DROPDOWN\" height=\"' + (CELL_HEIGHT - 2) + '\" nowrap onclick=\"controls.items[' + this.id + '].displayItems(\'' + controlName + '\')\">';
	}
	output += '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"7\" height=\"1\"><span id=\"caption_' + controlName + '\">' +
			  this.caption +
			  '</span><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"7\" height=\"1\">' +
			  '</td>' +
			  '<td class=\"DROPDOWN\" nowrap onclick=\"controls.items[' + this.id + '].displayItems(\'' + controlName + '\')\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/btn_dropdown.gif\" border=\"0\"></td>' +
			  '</tr>' +
			  '</table>';
	
	document.write(output);
}

function _displayDropdownItems(controlName)
{
	var noHide = false;
	
	if(arguments.length > 1)
	{
		noHide = arguments[1];
	}
	
	if(this.popup.showing && !noHide)
	{
		this.popup.hide();
	}
	else
	{
		this.popup.display(controlName);
	}
}

function _setDropdownCaption(caption)
{
	var obj;
	
	obj = document.getElementById('caption_' + this.controlName);
	if(obj)
	{
		this.caption = caption;
		obj.innerHTML = caption;
	}
}

// *****************************************************************************************

var POPUP_MAX_ITEMS = 10;
var POPUP_TYPE_DEFAULT = 0;		// Standard type (not yet defined)
var POPUP_TYPE_DROPDOWN = 1;	// Select box
var POPUP_TYPE_INLINE = 2;		// List views
var POPUP_SCROLL_UP = 1;
var POPUP_SCROLL_DOWN = -1;
var POPUP_SCROLL_STEP = 25;

var _popupHandle;
var _currentPopupHandle;
var _timedPopupHandle;
var _popupContainerDiv;
var _popupContentDiv;

function _objPopup()
{
	this.items = new Array;
	this.parent = null;
	this.owner = null;
	if(arguments.length > 0)
	{
		this.owner = arguments[0];
	}
	this.type = POPUP_TYPE_DROPDOWN;
	if(arguments.length > 1)
	{
		this.type = arguments[1];
	}
	this.limit = 0;			// 0 - No limit
	this.limitation = false;
	this.control = null;
	this.controlName = '';
	this.hoverLevel = 0;
	this.timeout = 200;		// milliseconds
	this.ownerTimeoutObj = null;
	this.scrollTimeout = 200;	// milliseconds
	this.scrollInterval = 500;	// milliseconds
	this.scrollTimer = null;
	this.showing = false;
	this.commonIcon = '';
	this.useCommonIcon = false;
	this.context = '';
	this.setCommonIcon = _setPopupCommonIcon;
	this.addItem = _addPopupItem;
	this.setLimit = _setPopupDisplayLimit;
	this.display = _displayPopup;
	this.hide = _hidePopup;
	this.clearMouseTimer = _clearPopupMouseTimer;
	this.setAsCurrent = _setPopupAsCurrent;
	this.scroll = _scrollPopup;
	this.createScrollTimerDnD =_createScrollTimerDnD;
	this.killScrollTimerDnD =_killScrollTimerDnD;
	this.onMouseOver = _onPopupMouseOver;
	this.onMouseOut = _onPopupMouseOut;
	this.onTimer = _onPopupTimer;
	
	return this;
}

function _objPopupItem(icon, caption, call, isLink)
{
	this.icon = icon;
	this.caption = caption;
	this.call = call;
	this.isLink = isLink;
	this.allowDrop = false;
	this.value = null;
	if(arguments.length > 4)
	{
		this.value = arguments[4];
	}
	this.disabled = false;
	if(arguments.length > 5)
	{
		this.disabled = arguments[5];
	}
	
	return this;
}

function _setPopupCommonIcon(icon)
{
	if(icon != '')
	{
		this.commonIcon = icon;
		this.useCommonIcon = true;
	}
}

function _addPopupItem(icon, caption, call, isLink)
{
	var item;
	var value = null;
	var disabled = false;
	
	if(arguments.length > 4)
	{
		value = arguments[4];
	}
	if(arguments.length > 5)
	{
		disabled = arguments[5];
	}
	
	item = new _objPopupItem(icon, caption, call, isLink, value, disabled);
	this.items[this.items.length] = item;
}

function _setPopupDisplayLimit(limit)
{
	if(limit > 0)
	{
		this.limit = limit;
		if(limit < this.items.length)
		{
			this.limitation = true;
		}
	}
}

function _displayPopup(controlName)
{
	var BORDER_WIDTH = 2;
	var CELL_HEIGHT = 24;
	var CELL_HEIGHT_INLINE = 20;
	var ICON_WIDTH = 22;
	var ICON_HEIGHT = 16;
	var value = null;
	var hideIcons = false;
	var call;
	var left;
	var top;
	var width;
	var popupContainer;
	var popupFrame;
	var output = '';
	var count;
	var height;
	var heightLimit;
	var heightContent;
	var popupHeight;
	var item;
	var scrollPosY;
	var offsetHeight;
	var itemClassDisabled = '';
	
	if(this.items.length == 0)
	{
		return;
	}
	
	if(this.parent)
	{
		if(this.parent.clearMouseTimer)
		{
			this.parent.clearMouseTimer();
		}
	}
	
	if(arguments.length > 1)
	{
		value = arguments[1];
	}
	if(arguments.length > 2)
	{
		hideIcons = arguments[2];
	}
	if(hideIcons && this.useCommonIcon)
	{
		hideIcons = false;
	}
	
	this.hint = '';
	
	if(controlName.indexOf('|') == -1)
	{
		this.control = document.getElementById(controlName);
		this.controlName = controlName;
	}
	else
	{
		this.control = document.getElementsByName(controlName.split('|')[0])[controlName.split('|')[1] - 1];
		this.controlName = controlName.split('|')[0];
		this.owner = this.control;
	}
	this.setAsCurrent();
	
	if(this.owner != null)
	{
		this.showing = true;
		
		left = getOffsetLeft(this.control);
		top = getOffsetTop(this.control);
		width = this.control.offsetWidth;
		
		if(document.all && !(bw.op8 || bw.iemac))
		{
			popupFrame = document.getElementById('popupShadow' + this.controlName);
			if(popupFrame == null)
			{
				popupFrame = document.createElement('iframe');
				popupFrame.setAttribute('id', 'popupShadow' + this.controlName);
				popupFrame.scrolling = 'no';
				document.body.appendChild(popupFrame);
			}
		}
		else
		{
			popupFrame = document.getElementById('popupShadow' + this.controlName);
			if(popupFrame == null)
			{
				popupFrame = document.createElement('div');
				popupFrame.setAttribute('id', 'popupShadow' + this.controlName);
				document.body.appendChild(popupFrame);
			}
		}
		popupFrame.style.position = 'absolute';
		popupFrame.style.visibility = 'hidden';
		popupContainer = document.getElementById('popupContent' + this.controlName);
		if(popupContainer == null)
		{
			popupContainer = document.createElement('div');
			popupContainer.setAttribute('id', 'popupContent' + this.controlName);
			if(this.type != POPUP_TYPE_INLINE)
			{
				popupContainer.className = 'POPUP' + this.context;
			}
			document.body.appendChild(popupContainer);
		}
		popupContainer.style.position = 'absolute';
		if(this.type == POPUP_TYPE_INLINE)
		{
			popupContainer.style.left = left - BORDER_WIDTH;
			popupContainer.style.top = top - BORDER_WIDTH;
			width += 2 * BORDER_WIDTH;	// Add left & right border defined in style INLINEPOPUP
		}
		if(this.type == POPUP_TYPE_DROPDOWN)
		{
			popupContainer.style.left = left;
			popupContainer.style.top = top;
		}
		popupContainer.style.visibility = 'hidden';
		
		height = 0;
		heightLimit = 0;
		heightContent = 0;
		if(this.type == POPUP_TYPE_INLINE)
		{
			output = '<table class=\"INLINEPOPUP\" width=\"' + width + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
					 '<tr>' +
					 '<td height=\"' + CELL_HEIGHT_INLINE + '\" onmouseover=\"_popupHandle.onMouseOver()\" onmouseout=\"_popupHandle.onMouseOut()\"><img src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"1\" height=\"' + CELL_HEIGHT_INLINE + '\"></td>' +
					 '</tr>' +
					 '<tr>' +
					 '<td class="POPUPTITLESPLITTER" height=\"1\" onmouseover=\"_popupHandle.onMouseOver()\" onmouseout=\"_popupHandle.onMouseOut()\"><img src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"1\"></td>' +
					 '</tr>';
			height += CELL_HEIGHT + 1;	// Upper margin
		}
		if(this.type == POPUP_TYPE_DROPDOWN)
		{
			if(this.limitation && (this.items.length > this.limit))
			{
				output = '<table class=\"POPUPCONTAINER' + this.context + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">' +
						 '<tr>' +
						 '<td class=\"POPUPCONTENTSCROLL' + this.context + '\" height=\"' + CELL_HEIGHT + '\" align=\"center\" onclick=\"_popupHandle.scroll(POPUP_SCROLL_UP)\" onmouseover=\"_popupHandle.onMouseOver(this);_popupHandle.createScrollTimerDnD(POPUP_SCROLL_UP)\" onmouseout=\"_popupHandle.onMouseOut(this);_popupHandle.killScrollTimerDnD()\"><img id=\"btnScrollUp' + this.controlName + '\" align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_up_d.gif\"></td>' +
						 '</tr>' +
						 '<tr>' +
						 '<td>' +
						 '<div id=\"divPopupContainer' + this.controlName + '\" style=\"position:relative;overflow:hidden\">' +
						 '<div id=\"divPopupContent' + this.controlName + '\" style=\"position:absolute;left:0px;top:0px\">' +
						 '<table class=\"POPUP' + this.context + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">';
				heightLimit += CELL_HEIGHT;	// Scroll up button
			}
			else
			{
				output = '<table class=\"POPUP' + this.context + '\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">';
			}
		}
		for(count = 0; count < this.items.length; count++)
		{
			item = this.items[count];
			call = item.call;
			if((value != null) && (item.call.indexOf('%s') > -1))
			{
				call = call.replace(/%s/, value);
			}
			itemClassDisabled = '';
			if(item.disabled)
			{
				itemClassDisabled = ' POPUPITEMDISABLED' + this.context;
			}
			if(count > 0)
			{
				output += '<tr>' +
						  '<td class=\"POPUPSPLITTER' + this.context + '\" height=\"1\" onmouseover=\"_popupHandle.onMouseOver()\" onmouseout=\"_popupHandle.onMouseOut()\"><img src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"1\" height=\"1\"></td>' +
						  '</tr>';
				height += 1;	// Row height (splitter)
				if(count < this.limit)
				{
					heightLimit += 1;
					heightContent += 1;
				}
			}
			output += '<tr>';
			if(call == '')
			{
				if(!item.disabled && item.allowDrop && dragNDrop)
				{
					output += '<td class=\"POPUPITEM' + this.context + '\" height=\"' + CELL_HEIGHT + '\" nowrap onmouseover=\"_popupHandle.onMouseOver(this);dragNDrop.handleDropTarget(\'' + item.caption + '\',true)\" onmouseout=\"_popupHandle.onMouseOut(this,false,\'' + this.context + '\');dragNDrop.handleDropTarget(\'' + item.caption + '\',false)\">';
				}
				else
				{
					output += '<td class=\"POPUPITEM' + this.context + itemClassDisabled + '\" height=\"' + CELL_HEIGHT + '\" nowrap onmouseover=\"_popupHandle.onMouseOver(this,' + item.disabled + ')\" onmouseout=\"_popupHandle.onMouseOut(this,' + item.disabled + ',\'' + this.context + '\')\">';
				}
				output += '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\">';
				if(!hideIcons)
				{
					if(this.useCommonIcon)
					{
						output += '<img align=\"absmiddle\" src=\"' + this.commonIcon + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"' + CELL_HEIGHT + '\">';
					}
					else
					{
						output += '<img align=\"absmiddle\" src=\"' + item.icon + '\" width=\"' + ICON_WIDTH + '\" height=\"' + ICON_HEIGHT + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"' + CELL_HEIGHT + '\">';
					}
				}
				output += item.caption + '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\"></td>';
			}
			else
			{
				if(item.isLink)
				{
					if(!item.disabled && item.allowDrop && dragNDrop)
					{
						output += '<td class=\"POPUPITEM' + this.context + '\" height=\"' + CELL_HEIGHT + '\" nowrap onclick=\"_popupHandle.hide(\'' + controlName + '\'),location=\'' + call + '\'\" onmouseover=\"_popupHandle.onMouseOver(this);dragNDrop.handleDropTarget(\'' + item.caption + '\',true)\" onmouseout=\"_popupHandle.onMouseOut(this,false,\'' + this.context + '\');dragNDrop.handleDropTarget(\'' + item.caption + '\',false)\">';
					}
					else
					{
						output += '<td class=\"POPUPITEM' + this.context + itemClassDisabled + '\" height=\"' + CELL_HEIGHT + '\" nowrap onclick=\"_popupHandle.hide(\'' + controlName + '\'),location=\'' + call + '\'\" onmouseover=\"_popupHandle.onMouseOver(this,' + item.disabled + ')\" onmouseout=\"_popupHandle.onMouseOut(this,' + item.disabled + ',\'' + this.context + '\')\">';
					}
					output += '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\">';
					if(!hideIcons)
					{
						if(this.useCommonIcon)
						{
							output += '<img align=\"absmiddle\" src=\"' + this.commonIcon + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"' + CELL_HEIGHT + '\">';
						}
						else
						{
							output += '<img align=\"absmiddle\" src=\"' + item.icon + '\" width=\"' + ICON_WIDTH + '\" height=\"' + ICON_HEIGHT + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"' + CELL_HEIGHT + '\">';
						}
					}
					output += item.caption + '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\"></td>';
				}
				else
				{
					if(!item.disabled && item.allowDrop && dragNDrop)
					{
						output += '<td class=\"POPUPITEM' + this.context + '\" nowrap onclick=\"_popupHandle.hide(\'' + controlName + '\'),' + call + '\" onmouseover=\"_popupHandle.onMouseOver(this);dragNDrop.handleDropTarget(\'' + item.caption + '\',true)\" onmouseout=\"_popupHandle.onMouseOut(this,false,\'' + this.context + '\');dragNDrop.handleDropTarget(\'' + item.caption + '\',false)\">';
					}
					else
					{
						output += '<td class=\"POPUPITEM' + this.context + itemClassDisabled + '\" nowrap onclick=\"_popupHandle.hide(\'' + controlName + '\'),' + call + '\" onmouseover=\"_popupHandle.onMouseOver(this,' + item.disabled + ')\" onmouseout=\"_popupHandle.onMouseOut(this,' + item.disabled + ',\'' + this.context + '\')\">';
					}
					output += '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\">';
					if(!hideIcons)
					{
						if(this.useCommonIcon)
						{
							output += '<img align=\"absmiddle\" src=\"' + this.commonIcon + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"1\">';
						}
						else
						{
							output += '<img align=\"absmiddle\" src=\"' + item.icon + '\" width=\"' + ICON_WIDTH + '\" height=\"' + ICON_HEIGHT + '\"><img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"6\" height=\"1\">';
						}
					}
					output += item.caption + '<img align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/1x1_trans.gif\" width=\"10\" height=\"' + CELL_HEIGHT + '\"></td>';
				}
			}
			output += '</tr>';
			height += CELL_HEIGHT;	// Row height (content)
			if(count < this.limit)
			{
				heightLimit += CELL_HEIGHT;
				heightContent += CELL_HEIGHT;
			}
		}
		if(this.limitation && (this.items.length > this.limit))
		{
			output += '</table>' +
					  '</td>' +
					  '</tr>' +
					  '</div>' +
					  '</div>' +
					  '<tr>' +
					  '<td class=\"POPUPCONTENTSCROLL\" height=\"' + CELL_HEIGHT + '\" align=\"center\" onclick=\"_popupHandle.scroll(POPUP_SCROLL_DOWN)\" onmouseover=\"_popupHandle.onMouseOver(this);_popupHandle.createScrollTimerDnD(POPUP_SCROLL_DOWN)\" onmouseout=\"_popupHandle.onMouseOut(this);_popupHandle.killScrollTimerDnD()\"><img id=\"btnScrollDown' + this.controlName + '\" align=\"absmiddle\" src=\"/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_down.gif\"></td>' +
					  '</tr>' +
					  '</table>';
			heightLimit += CELL_HEIGHT;	// Scroll down button
		}
		else
		{
			output += '</table>';
		}
		
		if(window.innerHeight)
		{
			scrollPosY = window.pageYOffset;
		}
		else
		{
			if(document.documentElement && document.documentElement.scrollTop)
			{
				scrollPosY = document.documentElement.scrollTop;
			}
			else
			{
				if(document.body)
				{
					scrollPosY = document.body.scrollTop;
				}
			}
		}
		if(window.innerHeight)
		{
			offsetHeight = window.innerHeight;
		}
		else
		{
			if(document.body.offsetHeight)
			{
				offsetHeight = document.body.offsetHeight;
			}
		}
		if(this.limitation)
		{
			popupHeight = heightLimit;
		}
		else
		{
			popupHeight = height;
		}
		if((top - scrollPosY + popupHeight) > offsetHeight - 20)	// Subtract 20px to avoid hidden portions of popup when unfolding under the dropdown
		{
			top = top - (popupHeight + 3);
		}
		else
		{
			top = top + parseInt(this.owner.height);
		}
		
		popupContainer.innerHTML = output;
		popupContainer.onmouseover = this.onMouseOver;
		popupContainer.onmouseout = this.onMouseOut;
		popupContainer.style.height = popupHeight;
		popupFrame.style.left = popupContainer.offsetLeft;
		popupFrame.style.top = popupContainer.offsetTop;
		popupFrame.style.height = popupContainer.offsetHeight;
		if(this.type == POPUP_TYPE_INLINE)
		{
			popupFrame.style.top = popupContainer.offsetTop + CELL_HEIGHT + BORDER_WIDTH;
			popupFrame.style.height = popupContainer.offsetHeight - (CELL_HEIGHT + BORDER_WIDTH);
		}
		if(this.type == POPUP_TYPE_DROPDOWN)
		{
			popupContainer.style.top = top;
			popupFrame.style.top = popupContainer.offsetTop;
			if(this.context == '')
			{
				popupContainer.style.left = popupContainer.offsetLeft - 1;
				popupFrame.style.left = popupContainer.offsetLeft;
			}
			if(this.limitation && (this.items.length > this.limit))
			{
				_popupContainerDiv = document.getElementById('divPopupContainer' + this.controlName);
				_popupContentDiv = document.getElementById('divPopupContent' + this.controlName);
				_popupContainerDiv.style.height = heightContent;
				_popupContainerDiv.style.clip = 'rect(0px, ' + _popupContainerDiv.offsetWidth + 'px, ' + _popupContainerDiv.offsetHeight + 'px, 0px)';
			}
			popupFrame.style.top = popupContainer.offsetTop;
		}
		popupFrame.style.width = popupContainer.offsetWidth;
		popupFrame.style.visibility = 'visible';
		popupContainer.style.visibility = 'visible';
		
		if(this.parent)
		{
			// if popup is used in main menu context ...
			if(this.parent.onPopupShow)
			{
				this.parent.onPopupShow();
			}
		}
	}
}

function _onPopupMouseOver(caller)
{
	var disabled = false;
	
	if(this.parent)
	{
		if(this.parent.clearMouseTimer)
		{
			this.parent.clearMouseTimer();
		}
	}
	
	if(arguments.length > 1)
	{
		disabled = arguments[1];
	}
	if(caller && !disabled)
	{
		caller.className = 'ACTIVEPOPUPITEM';
	}
	this.hoverLevel += 1;
}

function _onPopupMouseOut(caller)
{
	var disabled = false;
	var itemClassDisabled = '';
	var contextClassName = '';
	
	if(arguments.length > 1)
	{
		disabled = arguments[1];
	}
	if(arguments.length > 2)
	{
		contextClassName = arguments[2];
	}
	if(disabled)
	{
		itemClassDisabled = ' POPUPITEMDISABLED' + contextClassName;
	}
	if(caller && !disabled)
	{
		caller.className = 'POPUPITEM' + contextClassName + itemClassDisabled;
	}
	this.hoverLevel -= 1;
	if(this.hoverLevel == 0)
	{
		_timedPopupHandle = this;
		this.ownerTimeoutObj = setTimeout('_timedPopupHandle.onTimer()', this.timeout);
	}
}

function _clearPopupMouseTimer()
{
	clearTimeout(this.ownerTimeoutObj);
}

function _scrollPopup(direction)
{
	var scrollStep;
	var newScrollPos;
	
	scrollStep = direction * POPUP_SCROLL_STEP;
	newScrollPos = _popupContentDiv.offsetTop + scrollStep;
	switch(direction)
	{
		case POPUP_SCROLL_UP:
			if(newScrollPos > 0)
			{
				newScrollPos = 0;
			}
			break;
		case POPUP_SCROLL_DOWN:
			if(newScrollPos < (-1) * (_popupContentDiv.offsetHeight - _popupContainerDiv.offsetHeight))
			{
				newScrollPos = (-1) * (_popupContentDiv.offsetHeight - _popupContainerDiv.offsetHeight);
			}
			break;
	}
	if(newScrollPos >= 0)
	{
		document.getElementById('btnScrollUp' + this.controlName).src = '/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_up_d.gif';
		this.killScrollTimerDnD();
	}
	else
	{
		document.getElementById('btnScrollUp' + this.controlName).src = '/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_up.gif';
	}
	if(newScrollPos <= (-1) * (_popupContentDiv.offsetHeight - _popupContainerDiv.offsetHeight))
	{
		document.getElementById('btnScrollDown' + this.controlName).src = '/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_down_d.gif';
		this.killScrollTimerDnD();
	}
	else
	{
		document.getElementById('btnScrollDown' + this.controlName).src = '/__o3sis_UICACHETOKEN__/app_pic/ico_scroll_down.gif';
	}
	_popupContentDiv.style.top = newScrollPos;
}

function _createScrollTimerDnD(direction)
{
	if(dragNDrop)
	{
		if(!dragNDrop.isDragging)
		{
			return;
		}
		this.scrollTimer = window.setInterval('_currentPopupHandle.scroll(' + direction + ')', this.scrollInterval);
	}
	else
	{
		return;
	}
}

function _killScrollTimerDnD()
{
	if(!this.scrollTimer)
	{
		return;
	}
	window.clearInterval(_currentPopupHandle.scrollTimer);
	this.scrollTimer = null;
}

function _onPopupTimer()
{
	if(this.hoverLevel > 0)
	{
		return;
	}

	this.hoverLevel = 0;
	this.hide();
}

function _hidePopup()
{
	var popupFrame;
	var popupContainer;

	if(this.parent)
	{
		// if popup is used in main menu context ...
		if(this.parent.onPopupHide)
		{
			this.parent.onPopupHide(this);
		}
	}
	
	this.showing = false;
	popupFrame = document.getElementById('popupShadow' + this.controlName);
	popupContainer = document.getElementById('popupContent' + this.controlName);
	if(popupFrame != null)
	{
		popupFrame.style.visibility = 'hidden';
	}
	if(popupContainer != null)
	{
		popupContainer.style.visibility = 'hidden';
	}
}

function _setPopupAsCurrent()
{
	_popupHandle = this;
	if(_currentPopupHandle != null)
	{
		_currentPopupHandle.hide();
	}
	_currentPopupHandle = this;
}

/* HELPER FUNCTIONS ***********************************************************/

/* GENERAL FUNCTIONS ***********************************************************/

function preventBubbling(evt)
{
    (window.event) ? window.event.cancelBubble = true : evt.cancelBubble = true;
}

/* ARRAY HELPER ***************************************************************/

// check if specified value is in array
Array.prototype.contains = function(value)
{
	var count;
	var retVal = false;
	
	for(count = 0; count < this.length; count++)
	{
		if(this[count] == value)
		{
			retVal = true;
			break;
		}
	}
	
	return retVal;
}

// duplicate array content into specified target array
Array.prototype.clone = function(target)
{
	var count;
	
	for(count = 0; count < this.length; count++)
	{
		target[count] = this[count];
	}
}


