﻿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, nHeight, nWidth)
{
  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, nWidth, nHeight, 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;
}

/********************************************************************************************************************/
/************************************** Control Styles **************************************************************/
var STYLE_BACKCOLOR = '#d9eafc';
var STYLE_COLOR = 'midnightblue';
var STYLE_BACKCOLORHOVER = 'MidnightBlue';
var STYLE_COLORHOVER = 'Gold';
var STYLE_MENU = 'position:relative; top:0; left:0; ' + 
									'background:'+STYLE_BACKCOLOR+'; border:1px '+STYLE_BACKCOLOR+' outset; ' + 
									'color:' + STYLE_COLOR + '; font-family:tahoma; font-size:8pt; '
function onContextMenuOver(item)
{
	item.style.background= STYLE_BACKCOLORHOVER;
	item.style.color= STYLE_COLORHOVER
}

function onContextMenuOut(item)
{
	item.style.background = STYLE_BACKCOLOR;
	item.style.color= STYLE_COLOR;
}
/********************************************************************************************************************/
////////////////////////////////////
var CONTEXT_MENU_SEPARATOR = ''
var CONTEXT_MENUACTION_DISABLED = ''
var HEIGHT_ITEM = 23
var HEIGHT_SEP = 23
var WIDTH_ICON = 23;
function ContextMenu(nameMenu)
{
	var count;
	var countItem;
	var countSep;
	var maxTitleLength;
	var arrItems;
	var dir;
	
	this.name = nameMenu;
	this.count = 0;
	this.countItem = 0;
	this.countSep = 0;
	this.maxTitleLength = 0;
	this.dir = 'ltr';
	
	this.arrItems = new Array();
	
	
	this.addItem = ContextMenu_addItem;
	this.addItemData = ContextMenu_addItemData;
	this.addSeparator = ContextMenu_addSeparator;
	this.createContextMenu = ContextMenu_createContextMenu;
	this.showMenu = ContextMenu_showMenu;
	
}
function ContextMenuItem()
{
	var title;
	var action;
	var icon;
	var disabled;
	
	this.title='';
	this.action = 'alert(\'No Action\');';
	this.icon = '';
	this.disabled = false;
}

function ContextMenu_addItemData(title, action, icon, disabled)
{
	var oItem = new ContextMenuItem();
	oItem.title = title;
	oItem.action = action;
	oItem.icon = icon;
	oItem.disabled = disabled;
	this.addItem(oItem);
}

function ContextMenu_addItem(oItem)
{
	if(oItem.disabled)
		oItem.action = CONTEXT_MENUACTION_DISABLED;
		
	this.arrItems[this.count] = oItem;
	this.count++;
	
	if(CONTEXT_MENU_SEPARATOR == oItem.title)
		this.countSep++;
	else
		this.countItem++;
	
	if (this.maxTitleLength < oItem.title.length)
	{
		this.maxTitleLength = oItem.title.length;
	}	
}

function ContextMenu_addSeparator()
{
	this.addItemData(CONTEXT_MENU_SEPARATOR);
}


function ContextMenu_showMenu(oContainer)
{
	var nHeight = HEIGHT_ITEM * this.countItem + HEIGHT_SEP * (1+this.countSep);
	var nWidth = 7 * this.maxTitleLength; + WIDTH_ICON
	
	goContext(oContainer, this.createContextMenu(oContainer), nHeight, nWidth);
}

									
function ContextMenu_createContextMenu(oContainer)
{
	var str = '';
	str +='<div dir="'+this.dir+'" ID="' + this.name +'" STYLE="display: none;border:0px solid black;">\r\n'
	str +='	<table width="100%" border=0 cellpadding=2 cellspacing=0 STYLE="' + STYLE_MENU + '">\r\n'

	var i;
	for(i = 0; i < this.count; i++)
	{
		var oItem = this.arrItems[i];
		if (CONTEXT_MENU_SEPARATOR == oItem.title)
		{
			str +='		<tr><td style="height:' + HEIGHT_SEP + ';">\r\n';
			str +=			'<hr width=100% style="HEIGHT:1PX;">\r\n'
			//str +=			'<table style="height:5px;" width=100%><tr><td border:1px inset red;"></td></tr></table>'
			str +='		</td></tr>'
		}
		else
		{
			str +='		<tr><td dir="'+this.dir+'" style="height:'+HEIGHT_ITEM+';"';
			if (CONTEXT_MENUACTION_DISABLED == oItem.action)
				str +=' style="cursor:default;color:gray;">\r\n';
			else
				str +=' style="cursor:hand;" onmouseover="javascript:parent.onContextMenuOver(this);" onmouseout="javascript:parent.onContextMenuOut(this);" onclick="javascript:parent.' + oItem.action + ';parent.closePopup();">\r\n';
				
			if('' != oItem.icon)
			{
				var disstyle = ''
				if (CONTEXT_MENUACTION_DISABLED == oItem.action)
					disstyle = ';filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1, xray=0, mirror=0, invert=0, opacity=0.3, rotation=0)';

				str +='			<img style="width:'+WIDTH_ICON+disstyle+';" SRC="'+oItem.icon+'" ALIGN="absmiddle">';
			}
		  else
				str +='			<span style="width:'+WIDTH_ICON+'"></span>';
				
			str +='&nbsp;'	+		oItem.title + '\r\n';
			str +='		</td></tr>\r\n'
		}
			
	}			

	str +='	</table>'
	str +='</div>'
	
	oContainer.innerHTML=str;
	return eval(this.name);
}
