var oPopup = null;
try
{
	if ('object' == typeof(window.createPopup))
		oPopup = window.createPopup()
}
catch(exception)
{
	oPopup = null;
}

function goPop(oHeight)
{
  if(null != oPopup)
  {
	var oPopupBody = oPopup.document.body;
	var lefter = event.offsetY+10;
	var topper = event.offsetX+10;

	oPopupBody.innerHTML = styleDiv.innerHTML;
	oPopup.show(topper, lefter, 200, oHeight, document.body);
	document.body.onmouseup = closePopup;
  }
}

function goContext(oContainer, oContextMenu, oHeight, oWidth)
{
  if(null != oPopup)
  {
	var oPopupBody = oPopup.document.body;
	var lefter = event.y;//screenX ;
	var topper = event.x;//screenY;

	oPopupBody.innerHTML = oContextMenu.innerHTML;
	oPopup.show(topper, lefter, oWidth, oHeight, document.body);
	document.body.onmouseup = closePopup;
	return false;
  }
  else
    return true; 
}

function closePopup()
{
  if(null != oPopup)
	oPopup.hide();
}

function fillPopup(titler, texter, linker)
{
  oTitle.innerText=titler;
  oText.innerText=texter;
  oLinkStore.innerText=linker;
}

////////////////////////////////////
var CONTEXT_MENU_SEPARATOR = ''
var CONTEXT_MENUACTION_DISABLED = ''
function ContextMenu(nameMenu)
{
	var count;
	var arrTitle;
	var arrAction;
	var maxTitleLength;
	
	this.name = nameMenu;
	this.count = 0;
	
	this.maxTitleLength = 0;
	
	this.arrTitle = new Array();
	this.arrAction = new Array();
	
	this.addItem = ContextMenu_addItem;
	this.addSeparator = ContextMenu_addSeparator;
	this.createContextMenu = ContextMenu_createContextMenu;
	this.showMenu = ContextMenu_showMenu;
	
}

function ContextMenu_addItem(title, action, disabled)
{
	this.arrTitle[this.count] = title;
	if(disabled)
		this.arrAction[this.count] = CONTEXT_MENUACTION_DISABLED;
	else
		this.arrAction[this.count] = action;
		
	this.count++;
	
	if (this.maxTitleLength < title.length)
	{
		this.maxTitleLength = title.length;
	}	
}

function ContextMenu_addSeparator()
{
	this.addItem(CONTEXT_MENU_SEPARATOR, '');
}

function onContextMenuOver(item)
{
	item.style.background='#000000';
	item.style.color='#ffffff';
}

function onContextMenuOut(item)
{
	item.style.background='menu';
	item.style.color='#000000';
}

function ContextMenu_showMenu(oContainer)
{
	oHeight = 16 * this.count + 4;
	oWidth = 250;//10 * this.maxTitleLength;
	
	goContext(oContainer, this.createContextMenu(), oHeight, oWidth);
}

var defaultStyle = 'position:relative; top:0; left:0; ' + 
									'background:menu; border:2px menu outset; ' + 
									'color:black; font-family:tahoma; font-size:8pt; '
									
function ContextMenu_createContextMenu()
{
	var str = '';

	str +='<div dir="rtl" ID="' + this.name +'" STYLE="display: none;border:1px solid black; border-top: 1px solid white; border-left:1px solid white; ">\r\n'
	str +='	<div STYLE="' + defaultStyle + '">\r\n'

	var i;
	for(i = 0; i < this.count; i++)
	{
		if (CONTEXT_MENU_SEPARATOR == this.arrTitle[i])
		{
			str +='		<div style="height:16;">\r\n';
			str +=			'<hr width=100% style="">\r\n'
			str +='		</div>'
		}
		else
		{
			if (CONTEXT_MENUACTION_DISABLED == this.arrAction[i])
				str +='		<div dir="rtl" style="height:16;" style="cursor:default;color:gray;">\r\n';
			else
				str +='		<div dir="rtl" style="height:16;" style="cursor:hand;" onmouseover="javascript:parent.onContextMenuOver(this);" onmouseout="javascript:parent.onContextMenuOut(this);" onclick="javascript:parent.' + this.arrAction[i] + ';parent.closePopup();">\r\n';
			
			//str +='			<img SRC="img/ielogo.gif" ALIGN="absmiddle">&nbsp;&nbsp;
			str +='&nbsp;'	+		this.arrTitle[i] + '\r\n';
			str +='		</div>\r\n'
		}
			
	}			

	str +='	</div>'
	str +='</div>'
	
	var cont = eval('CONTEXT_MENU_CONTAINER');
	cont.innerHTML=str;
	//alert(str)
	
	return eval(this.name);
}