

//<script>

function CenterWindow(width, height)
{
	// Resizing solo con dimensioni specificate
	if ( arguments.length < 2 )
	{
		height = window.height;
		width = window.width;
	}
	else
		window.resizeTo(width, height);

	var x = (window.screen.width - width) / 2;
	var y = (window.screen.height - height) / 2;
	window.moveTo(x, y);
}

function GetCenterCoords(width, height, bOpen)
{
	var x = (window.screen.width - width) / 2;
	var y = (window.screen.height - height) / 2;
	if (IsEmpty(bOpen) || bOpen)
		return "top="+ y +"px,left="+ x +"px";
	else		
		return [x, y];
}



// MENU ITEMS
var MENU_SUB 		= 1;
var MENU_SUBMENU	= 2;
var MENU_LINK 		= 3;
var MENU_ACTION 	= 4;
var MENU_SEPARATOR 	= 5;
var MENU_CHECK 		= 6;
var MENU_RADIO 		= 7;

// MENU ITEMS SHOW
var MENU_NORMAL		= 0;
var MENU_UP			= 1;
var MENU_DOWN		= 2;
var MENU_HIGHLITE	= 3;

// DEFAULT TARGET
var MENU_DEFAULT_TARGET = "_same";


  /////////
 // CMenu
//
function CMenu(id, cls, autoSub)
{
	// default
	if ( IsEmpty(cls) ) cls = "CMenu";
	if ( IsEmpty(autoSub) ) autosub = false;
	
	this.id = id;
	this.cls = cls;
	this.text = "";
	this.title = "";

	this.all = []; 
	this.all[0] = this;

	this.item = [];
	this.activeItem = null;
	this.showSub = false;

	this.html = new Object();
	this.html.table = new CHtmlElement("TABLE", [["ID","#id#_idTABLE"],["CLASS","#cls#-clsTABLE"],["onselectstart","return false"],["onmousedown","return false"],["onmouseover","Page.Popup.over(#id#)"],["onmouseout","Page.Popup.out()"]], null, "CELLSPACING=0 CELLPADDING=0");
	
	this.autoSub = autoSub;
}
CMenu.prototype.submenuOffset = [0, 1];

CMenu.prototype.writeHTML = function() { document.write(this.HTML()) }

CMenu.prototype.HTML = function ()
{
	var i;
	var id = this.id;
	var ref = this.id;
/*	
	var HTML = '\n<TABLE CLASS="' + this.cls + '-clsTABLE" onselectstart="return false;" onmousedown="return false;" ID='+ id +'_idTABLE'+ this.outerHTML;
	HTML += ' onmouseover="Page.Popup.over('+ ref +');" onmouseout="Page.Popup.out();">';
*/	
	var HTML = MacroReplace(this.html.table.openHTML(), [["#id#", this.id], ["#cls#", this.cls]]);	
	HTML +='<TR>';
	for (i=0; i<this.item.length; i++)
		HTML += this.item[i].HTML();
	HTML += '<TD CLASS="'+ this.cls +'-clsTD-text" TITLE="'+ this.title +'" onselectstart="return true;" onmousedown="'+ ref +'.hideAll(); return true;">'+ (IsEmpty(this.text) ? "&nbsp;" : this.text) +'</TD></TR></TABLE>';

	for (i in this.all)
		if ( this.all[i].type == MENU_SUBMENU )
			HTML += this.all[i].HTML();

//window.alert(HTML);
	return HTML;
}

CMenu.prototype.loadArray = function(menuArray)
{
	// idParent, type, id, text, title, icon, value, arg1, arg2
	this.all = []; 
	this.all[0] = this;
	this.item = [];
	for (var i=0; i<menuArray.length; i++) 
		this.add(menuArray[i][0], menuArray[i][1],menuArray[i][2],menuArray[i][3],menuArray[i][4],menuArray[i][5],menuArray[i][6],menuArray[i][7],menuArray[i][8]);
}

CMenu.prototype.add = function (parent, type, id, text, title, icon, value, arg1, arg2)
{
	// default
	var idParent = parent == null ? 0 : (IsNumber(parent) ? parent : parent.index);
	if ( IsEmpty(text) 	)	text  = null;
	if ( IsEmpty(title) ) 	title = "";
	if ( IsEmpty(icon) 	) 	icon  = null;
	if ( IsEmpty(value)	) 	value = null;
	if ( IsEmpty(arg1) 	) 	arg1  = null;
	if ( IsEmpty(arg2) 	) 	arg2  = null;

	if (type==MENU_SUB)
		id = 0.1 + id;

	if ( idParent == 0 )
	{
		this.all[id] = new CMenuItem(id, this.cls+"Item");
		this.item[this.item.length] = this.all[id];
	}
	else
	{
		if ( type == MENU_SUBMENU )
		{
			this.all[id] = new CSubMenu(id, this.cls+"Sub");
			this.all[id].menu = this;
			this.all[id].index = id; 
			this.all[id].parent = this.all[idParent];
			this.all[idParent].subMenu = this.all[id];
			return this.all[id];
		}
		else
		{
			this.all[id] = new CSubMenuItem(id);
			this.all[idParent].item[this.all[idParent].item.length] = this.all[id];
		}
	}	

	this.all[id].menu = this;
	this.all[id].index = id; 
	this.all[id].parent = this.all[idParent];
	this.all[id].type = type;
	this.all[id].text = text;
	this.all[id].title = title;
	this.all[id].icon = icon;
	this.all[id].arg1 = arg1;
	this.all[id].arg2 = arg2;

	// value, arg1, arg2
	switch ( type )
	{
		case MENU_LINK:
			this.all[id].value = value;
			if ( arg1 != null )
				this.all[id].target = arg1;
			if ( arg2 != null )
				this.all[id].features = arg2;
			break;

		case MENU_ACTION:
			this.all[id].value = value;
			break;

		case MENU_CHECK:
			if ( value == null )
				value = false;
			this.all[id].value = value;
			break;
	
		case MENU_RADIO:
			if ( value == null )
				value = false;
			this.all[id].value = value;
			if ( arg1 != null )
				this.all[id].group = arg1;
			break;
	}
	if (type== MENU_SUB)
		return this.add(this.all[id], MENU_SUBMENU, Math.round(id), text, title, icon, value, arg1, arg2);
	else
		return this.all[id];
}


//
// CMenu.hideAll
//
function CMenu_hideAll()
{
	if ( this.activeItem != null )
		this.activeItem.hideSub();
	this.activeItem = null;
}
CMenu.prototype.hideAll = CMenu_hideAll;

//
//	CMenu.close
//
function CMenu_close()
{
	this.hideAll();
	this.showSub = false;
}
CMenu.prototype.close = CMenu_close;



  /////////////
 // CMenuItem
//
function CMenuItem(id, cls)
{
	// default
	if ( IsEmpty(cls) ) cls = "CMenuSub";

	this.id = id;
	this.cls = cls

	this.type = null;
	this.text = null;
	this.title = "";
	this.icon = null;

	this.menu = null;
	this.index = null;
	this.parent = null;
	this.subMenu = null;
	this.value = null;

	this.group = 0;
	this.target = MENU_DEFAULT_TARGET;
	this.features = null;
}


//
// CMenuItem_HTML
//
function CMenuItem_HTML()
{
	var HTML = "";
	var id = this.menu.id +"_"+ this.id;
	var ref = this.menu.id +".all["+ this.index +"]";

	// Separator
	if ( this.type == MENU_SEPARATOR )
	{
		HTML += '\n<TD ID="' + this.id + '_idTD" NOWRAP';
		HTML += ' onmouseover="' + this.parent.id + '.hideAll();"';
		if ( IsEmpty(this.text) )
			HTML += ' CLASS="' + this.cls + '-clsTD-separator">' + '&nbsp';
		else
			HTML += ' CLASS="' + this.cls + '-clsTD-separatorEmpty">' + this.text;
		HTML += '</TD>';
		return HTML;
	}
	
	// MenuItem
	HTML += '\n<TD CLASS="' + this.cls + '-clsTD-normal" ID="'+ id +'_idTD" TITLE="' + this.title + '" NOWRAP';
	HTML += ' onmouseover="' + ref + '.onmouseover(event);"';
	HTML += ' onmouseout="' + ref + '.onmouseout(event);"';
	HTML += ' onmousedown="' + ref + '.onmousedown(event);"';
	HTML += ' onclick="' + ref + '.onclick(event);">';

	HTML += '\n<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100% HEIGHT=100%><TR>';

	// Icon
	if ( this.icon != null )
	{
		HTML += '\n<TD CLASS="' + this.cls + '-clsTD-icon" NOWRAP>';
	 	HTML += '<IMG CLASS="' + this.cls + '-clsIMG-icon" SRC="' + this.icon + '">';
		HTML += '</TD>';
	}

	// Text
	if ( this.text != null )
		HTML += '\n<TD CLASS="' + this.cls + '-clsTD-text" NOWRAP>' + this.text + '</TD>';

	// Sub
	if ( this.icon != null && this.subMenu != null )
		HTML += '\n<TD CLASS="' + this.cls + '-clsTD-sub" NOWRAP>&nbsp;</TD>';

	HTML += '\n</TR></TABLE></TD>';

//window.alert(HTML);
	return HTML;
}
CMenuItem.prototype.HTML = CMenuItem_HTML;


//
// CMenuItem.onmouseover
//
function CMenuItem_onmouseover(e)
{
	if ( this.parent.activeItem != null )
		if ( this.parent.activeItem != this )
			this.parent.activeItem.hideSub();

	this.parent.activeItem = this;
	if ( this.type == MENU_SUB )
	{
		if ( this.menu.autoSub )
			this.parent.showSub = true;
		if ( this.parent.showSub )
		{
			this.showItem(MENU_DOWN);
			this.showSub();
		}
		else
			this.showItem(MENU_UP);
	}
	else
		this.showItem(MENU_UP);
}
CMenuItem.prototype.onmouseover = CMenuItem_onmouseover;

//
// CMenuItem.onmouseout
//
function CMenuItem_onmouseout(e)
{
	if ( !this.parent.showSub )
		this.parent.hideAll();
}
CMenuItem.prototype.onmouseout = CMenuItem_onmouseout;

//
// CMenuItem.onmousedown
//
function CMenuItem_onmousedown(e)
{
	if ( !Page.Event.leftButton(e) )
		return;
		
	if ( this.parent.activeItem != null )
		this.parent.activeItem.hideSub();		
	if ( this.type == MENU_SUB )
	{
		this.parent.showSub = this.menu.autoSub ? true : !this.parent.showSub;
		if ( this.parent.showSub )
		{
			this.showItem(MENU_DOWN);
			this.showSub();
		}
		else
			this.showItem(MENU_UP);
	}
	else
		this.showItem(MENU_DOWN);
}
CMenuItem.prototype.onmousedown = CMenuItem_onmousedown;
				
CMenuItem.prototype.onclick = function CMenuItem_onclick(e)
{
	if ( this.parent.activeItem == this )
	{
		switch ( this.type )
		{
			case MENU_LINK:
				OpenUrl(this.value, this.target, this.features);
				break;

			case MENU_ACTION:
				var cmd = this.value.replace(/#id#/g, this.index);
				eval(cmd);
				break;

			case MENU_CHECK:
				window.alert("MENU_CHECK \n value = " + this.value);
				break;
				 
			case MENU_RADIO:
				window.alert("MENU_RADIO \n value = " + this.value + "\n group = " + this.group);
				break;

			default:
				return;
		}
		this.showItem(MENU_UP);
	}
}

//
// CMenuItem.showItem
//
function CMenuItem_showItem(mode)
{
	var target = document.getElementById(this.menu.id +"_"+ this.id +"_idTD");
	switch ( mode )
	{
		case MENU_UP:	target.className = this.cls + "-clsTD-up"; 		break;
		case MENU_DOWN:	target.className = this.cls + "-clsTD-down"; 	break;
		default:		target.className = this.cls + "-clsTD-normal";
	}
}
CMenuItem.prototype.showItem = CMenuItem_showItem;

//
// CMenuItem.showSub
//
function CMenuItem_showSub()
{
	if ( this.type == MENU_SUB )
	{
		if ( this.parent.showSub )
		{
			if ( this.subMenu != null )
			{
				var target = document.getElementById(this.menu.id +"_"+ this.id + "_idTD");
				pos = WindowPos(target);
				pos[0] += this.menu.submenuOffset[0];
				pos[1] += target.offsetHeight + this.menu.submenuOffset[1];
/*				
				if ( !this.menu.autoSub )
				{
					pos[0] += 2;
					pos[1] += 2;
				}
*/				
				this.subMenu.show(pos[0], pos[1], target.offsetWidth, target.offsetHeight);
			}
			return;
		}
	}
}
CMenuItem.prototype.showSub = CMenuItem_showSub;

//
// CMenuItem.hideSub
//
function CMenuItem_hideSub()
{
	document.getElementById(this.menu.id +"_"+ this.id + "_idTD").className = this.cls + "-clsTD-normal";

	if ( this.subMenu != null )
		this.subMenu.hide();
}
CMenuItem.prototype.hideSub = CMenuItem_hideSub;



  ////////////
 // CSubMenu
//
function CSubMenu(id, cls)
{
	if ( IsEmpty(cls) ) cls = "CMenuSub";

	this.id = id;
	this.cls = cls;
	this.type = MENU_SUBMENU;

	this.menu = null;
	this.index = null;
	this.parent = null;
	this.item = [];
	this.activeItem = null;
}

//
// CSubMenu.hideAll
//
function CSubMenu_hideAll()
{
	if ( this.activeItem != null )
	{
		this.activeItem.showItem(MENU_NORMAL);
		this.activeItem.hideSub();
	}
	this.activeItem = null;
}
CSubMenu.prototype.hideAll = CSubMenu_hideAll;

function CSubMenu_HTML()
{
	var bFirst = false;
	var bLast = false;
	var id = this.menu.id +"_"+ this.id;
	var ref = this.menu.id +".all["+ this.index +"]"
	var HTML = '\n<DIV onselectstart="return false;" ID="' + id + '_idDIV" CLASS="' + this.cls + '-clsDIV"';
	HTML += ' onmouseover="Page.Popup.over(' + this.menu.id + ');" onmouseout="Page.Popup.out();">';
	HTML += '\n<TABLE ID="' + id + '_TABLE" CLASS="' + this.cls + '-clsTABLE" CELLPADDING=0 CELLSPACING=0>';

	for (var i=0; i<this.item.length; i++)
	{
		if ( this.menu.autoSub )
		{
			bFirst = bLast = false;
			if ( i == 0 )
				bFirst = true;
			if ( i == this.item.length-1 )
				bLast = true;
		}
		HTML += this.item[i].HTML(bFirst, bLast);
	}
	HTML += '</TABLE></DIV>';

//window.alert(HTML);
	return HTML;
}
CSubMenu.prototype.HTML = CSubMenu_HTML;

function CSubMenu_writeHTML()
{
	document.write( this.HTML() );
}
CSubMenu.prototype.writeHTML = CSubMenu_writeHTML;

function CSubMenu_show(x, y, w, h)
{
	target = document.getElementById(this.menu.id + "_" +this.id + "_idDIV");

	var clientWidth, clientHeight;
	if ( IE )
	{
		clientWidth = document.body.clientWidth;
		clientHeight = document.body.clientHeight;
	}
	else
	{
		clientWidth = (window.innerWidth < window.outerWidth)? window.innerWidth : window.outerWidth;
		clientHeight = (window.innerHeight < window.outerHeight)? window.innerHeight : window.outerHeight;
	}
	
	if ( x + target.offsetWidth > clientWidth && x - target.offsetWidth - w > 0 )
	{
		if (this.parent.parent == undefined || this.parent.parent.type == undefined)
			x = x - target.offsetWidth;
		else
			x = x - target.offsetWidth - w;
	}
	
	if ( y + target.offsetHeight > clientHeight && y - target.offsetHeight + h > 0 )
		y = y - target.offsetHeight + h;

	target.style.left = x;
	target.style.top = y;
	target.style.visibility = "visible";
	Page.Popup.open(this.menu);
}
CSubMenu.prototype.show = CSubMenu_show;

function CSubMenu_hide()
{
	if ( this.activeItem != null )
	{
		this.activeItem.showItem(MENU_NORMAL);
		this.activeItem.hideSub();
	}
	var target = document.getElementById(this.menu.id + "_" +this.id + "_idDIV");
	if ( target )
		document.getElementById(this.menu.id + "_" +this.id + "_idDIV").style.visibility = "hidden";
}
CSubMenu.prototype.hide = CSubMenu_hide;



  ////////////////
 // SUBMENU ITEM 
//
function CSubMenuItem(id, cls)
{
	// default
	if ( IsEmpty(cls) ) cls = "CMenuSubItem";

	this.id = id;
	this.cls = cls;

	this.type = null;
	this.text = null;
	this.title = null;
	this.icon = null;

	this.menu = null;
	this.index = null; 
	this.parent = null;
	this.subMenu = null;
	this.value = null;
	this.group = 0;
	this.target = MENU_DEFAULT_TARGET;
	this.features = null;

	CSubMenuItem.prototype.HTML = CSubMenuItem_HTML;
	CSubMenuItem.prototype.showItem = CSubMenuItem_showItem;
	CSubMenuItem.prototype.showSub = CSubMenuItem_showSub;
	
	// Notified events
	this.eventCheck = function () {};
}

//
// CSubMenuItem.HTML
//
function CSubMenuItem_HTML(bFirst, bLast)
{
	var id = this.menu.id + "_" + this.id;
	var ref = this.menu.id +".all["+ this.id +"]";
	var HTML = '<TR CLASS="'+ this.cls +'-clsTR" ID="'+ id +'_idTR"';

	// Separator
	if ( this.type == MENU_SEPARATOR )
	{
//		HTML += ' onmouseover="' + this.menu.id + '.onmouseover(this);"';
		HTML += ' onmouseout="' + ref + '.onmouseout(this);"';
		HTML += ' ><TD CLASS="' + this.cls + '-clsTD-separator" COLSPAN=3 >&nbsp</TD></TR>';
		return HTML;
	}

	// Item
	if ( this.title != null )
		HTML += " TITLE='" + this.title + "'";
	if ( this.id != null )
	{
		HTML += " onmouseover='" + ref + ".onmouseover(this);'";
		HTML += " onmouseout='" + ref + ".onmouseout(this);'";
		HTML += " onclick='" + ref + ".onclick(this);'";
	}
	HTML += ">";

	// Icon
	HTML += '\n<TD ID="' + id + '_idTD_icon" NOWRAP CLASS="' + this.cls;
	switch ( this.type )
	{
		case MENU_CHECK:
			if ( this.value )
				HTML += '-clsTD-check">&nbsp</TD>';
			else
				HTML += '-clsTD-icon">&nbsp</TD>';
			break;

		case MENU_RADIO:
			if ( this.value )
				HTML += '-clsTD-radio">&nbsp</TD>';
			else
				HTML += '-clsTD-icon">&nbsp</TD>';
			break;

		default:
			HTML += '-clsTD-icon">';
			if ( this.icon != null )
				HTML += '<IMG CLASS="' + this.cls + '-clsIMG-icon" ID="' + id + '_idIMG_icon" ALIGN=middle SRC="' + this.icon + '">';
			else
				HTML += '&nbsp;';
			HTML += '</TD>';
	}

	// Text
	HTML += '\n<TD CLASS="' + this.cls + '-clsTD-text" ID="' + id + '_idTD_text" NOWRAP>';
	if ( this.text != null )
		HTML += this.text;

	// Sub
	HTML += '\n</TD><TD CLASS="' + this.cls;
	if ( this.subMenu != null )
		HTML += '-clsTD-sub"';
	else
		HTML += '-clsTD-subNone"';
	HTML += ' ID="' + id + '_idTD_sub" NOWRAP>';
	HTML += '&nbsp;</TD></TR>';

//window.alert(HTML);
	return HTML;
}
CSubMenuItem.prototype.HTML = CSubMenuItem_HTML;

//
// CSubMenuItem.onmouseover
//
function CSubMenuItem_onmouseover()
{	
	if ( this.type == MENU_SEPARATOR )
	{
		this.parent.hideAll();
		return;
	}

	if ( this.parent.activeItem != null )
	{
		if ( this.parent.activeItem != this )
		{
			this.parent.activeItem.showItem(MENU_NORMAL);
			this.parent.activeItem.hideSub();
		}
	}
	this.parent.activeItem = this;	
	this.showItem(MENU_HIGHLITE);
	if ( this.type == MENU_SUB)
		this.showSub();
}
CSubMenuItem.prototype.onmouseover = CSubMenuItem_onmouseover;

//
// CSubMenuItem.onmouseout
//
function CSubMenuItem_onmouseout()
{
}
CSubMenuItem.prototype.onmouseout = CSubMenuItem_onmouseout;

CSubMenuItem.prototype.onclick = function ()
{
	switch ( this.type )
	{
		case MENU_ACTION:
			this.menu.hideAll();
			if (this.value != null)
			{
				var cmd = this.value.replace(/#id#/g, this.index);
				eval(cmd);
			}
			break;

		case MENU_LINK:
			OpenUrl(this.value, this.target, this.features);
			break;

		case MENU_CHECK:
		case MENU_RADIO:
			if ( this.type == MENU_RADIO )
			{
				for (var i=0; i< this.parent.item.length; i++)
				{
					if ( this.parent.item[i].type == MENU_RADIO && this.parent.item[i].group == this.group )
					{
						this.parent.item[i].value = false;
						this.parent.item[i].showItem(MENU_NORMAL);
					}
				}
				this.value = true;
			}
			else
			{
				this.value = !this.value;
				this.eventCheck(this);
			}
			break;
	}
	this.showItem(MENU_HIGHLITE);
}


function CSubMenuItem_showItem(mode)
{
	// Icon
	var id = this.menu.id +"_"+ this.id;
	var className = this.cls + "-clsTD-";
	switch ( this.type )
	{
		case MENU_CHECK:
			if ( this.value )
				className += "check";
			else
				className += "icon";
			break;

		case MENU_RADIO:
			if ( this.value )
				className += "radio";
			else
				className += "icon";
			break;

		default:
			if ( this.icon != null )
			{
				if ( mode == MENU_HIGHLITE )
					document.getElementById(id + "_idIMG_icon").className = this.cls + "-clsIMG-iconHighlite";
				else
					document.getElementById(id + "_idIMG_icon").className = this.cls + "-clsIMG-icon";
			}
			className += "icon";
	}
	if ( mode == MENU_HIGHLITE )
		className += "Highlite";
	document.getElementById(id + "_idTD_icon").className = className;

	// Text
	className = this.cls + "-clsTD-text";
	if ( mode == MENU_HIGHLITE )
		className += "Highlite";
	document.getElementById(id + "_idTD_text").className = className;

	// SubMenu
	if ( this.subMenu == null )
		className = this.cls + "-clsTD-subNone";
	else
		className = this.cls + "-clsTD-sub";
	if ( mode == MENU_HIGHLITE )
		className += "Highlite";
	document.getElementById(id + "_idTD_sub").className = className;
}
CSubMenuItem.prototype.showItem = CSubMenuItem_showItem;

function CSubMenuItem_showSub()
{
	if ( this.subMenu != null )
	{
		var target = document.getElementById(this.menu.id +"_"+ this.id + "_idTR");
		pos = WindowPos(target);
		pos[0] += target.offsetWidth + pos[0];
		pos[1] -= 0;
		this.subMenu.show(pos[0], pos[1], target.offsetWidth, target.offsetHeight);
	}
}
CSubMenuItem.prototype.showSub = CSubMenuItem_showSub;

function CSubMenuItem_hideSub()
{
	if ( this.subMenu != null )
		this.subMenu.hide();
}
CSubMenuItem.prototype.hideSub = CSubMenuItem_hideSub;



  //////////////
 // CMenuPopup
//
function CMenuPopup(id, cls)
{
	// default
	if ( IsEmpty(cls) ) cls = "CMenu";

	this.id = id;
	this.cls = cls;
	
	this.menu = this;
	
	this.all = []; 
	this.all[0] = new CSubMenu(this.id + ".all[0]");
	this.all[0].menu = this;
	this.all[0].parent = this;
	this.subMenu = this.all[0];

	this.item = [];
	this.activeItem = null;
	this.showSub = false;
	
	this.onpopup = function() { return true; }
}

//
// CMenuPopup.add
//
function CMenuPopup_add(parent, type, id, text, title, icon, value, arg1, arg2)
{
	// default
	if ( IsEmpty(text) 	)	text  = null;
	if ( IsEmpty(title) ) 	title = "";
	if ( IsEmpty(icon) 	) 	icon  = null;
	if ( IsEmpty(value)	) 	value = null;
	if ( IsEmpty(arg1) 	) 	arg1  = null;
	if ( IsEmpty(arg2) 	) 	arg2  = null;

	if ( type == MENU_SUBMENU )
	{
		this.all[id] = new CSubMenu(id, this.cls+"Sub");
		this.all[id].menu = this;
		this.all[id].index = id;
		this.all[id].parent = this.all[parent];
		this.all[parent].subMenu = this.all[id];
		return this.all[id];
	}
	else
	{
		this.all[id] = new CSubMenuItem(id);
		this.all[parent].item[this.all[parent].item.length] = this.all[id];
	}

	this.all[id].menu = this;
	this.all[id].index = id;
	this.all[id].parent = this.all[parent];
	this.all[id].type = type;
	this.all[id].text = text;
	this.all[id].title = title;
	this.all[id].icon = icon;

	if  ( type == MENU_LINK )
	{
		this.all[id].value = value;
		if ( arg1 != null )
			this.all[id].target = arg1;
		if ( arg2 != null )
			this.all[id].features = arg2;
	}
	else if ( type == MENU_ACTION )
	{
		this.all[id].value = value;
	}
	else if ( type == MENU_SEPARATOR )
	{
	}
	else if ( type == MENU_CHECK )
	{
		if ( value == null )
			value = false;
		this.all[id].value = value;
	}
	else if ( type == MENU_RADIO )
	{
		if ( value == null )
			value = false;
		this.all[id].value = value;
		if ( arg1 != null )
			this.all[id].group = arg1;
	}
	return this.all[id];
}
CMenuPopup.prototype.add = CMenuPopup_add;

//
// CMenuPopup.addSub
//
function CMenu_addSub(parent, text, title, icon, value, arg1, arg2)
{
	parent = IsEmpty(parent) ? 0 : parent.index;
	var sub = this.add(parent, MENU_SUB, this.all.length, text, title, icon, value, arg1, arg2);
	return this.add(sub.index, MENU_SUBMENU, this.all.length);
}
CMenuPopup.prototype.addSub = CMenu_addSub;

//
// CMenuPopup.addItem
//
function CMenuPopup_addItem(parent, type, text, title, icon, value, arg1, arg2)
{
	parent = IsEmpty(parent) ? 0 : parent.index;
	return this.add(parent, type, this.all.length, text, title, icon, value, arg1, arg2);
}
CMenuPopup.prototype.addItem = CMenuPopup_addItem;

//
// CMenuPopup.writeHTML
//
function CMenuPopup_writeHTML()
{
	var i;
	var HTML = "";
	
	for (i in this.all)
		if ( this.all[i].type == MENU_SUBMENU )
			this.all[i].writeHTML();
}
CMenuPopup.prototype.writeHTML = CMenuPopup_writeHTML;

//
// CMenuPopup.displayItem
//
function CMenuPopup_displayItem(item, bDisplay)
{
	document.getElementById(this.id +"_"+ item.index + "_idTR").style.display = bDisplay ? "block" : "none";
}
CMenuPopup.prototype.displayItem = CMenuPopup_displayItem;


//
// CMenuPopup.hideAll
//
function CMenuPopup_hideAll()
{
	this.all[0].hide();
}
CMenuPopup.prototype.hideAll = CMenuPopup_hideAll;

//
//	CMenuPopup.close
//
function CMenuPopup_close()
{
	this.hideAll();
}
CMenuPopup.prototype.close = CMenuPopup_close;

//
// CMenuPopup.show
//
CMenuPopup.prototype.show = function CMenuPopup_show(x, y)
{
	this.hideAll();
	this.all[0].show(x, y);
}

//
// CMenuPopup.popup
//
function CMenuPopup_popup(e)
{
	var x, y;
	
	if ( IE )
	{
		e = window.event;
		if ( WndDialog.focus() )
		{
			e.returnValue = false;
			return;
		}		
		if ( window.event.altKey || window.event.ctrlKey || window.event.shiftKey )
			return;
		x = window.event.x;
		y = window.event.y;
		window.event.returnValue = false;
	}
	if ( NE )
	{
		if ( WndDialog.focus() )
		{
			e.preventDefault(); 
			return;
		}		
		if ( e.altKey || e.ctrlKey || e.shiftKey || e.button != 3 )
			return;
		x = e.clientX;
		y = e.clientY;
		e.preventDefault();
	}
	if ( this.onpopup() )
	{
		this.show(x, y);
		this.activeItem = this.all[1];
	}
}
CMenuPopup.prototype.popup = CMenuPopup_popup;

//
// CMenuPopup.attach
//
function CMenuPopup_attach(idSource)
{
	var target = document.getElementById(idSource);
	var code; 
	if ( IE )
	{
		code = this.id +".popup()";
		target.oncontextmenu = function(){ eval(code) };
	}
	if ( NE )
	{
		code = this.id +".popup(e)";
		target.onmouseup = function(e) { eval(code); return false; };
	}
}
CMenuPopup.prototype.attach = CMenuPopup_attach;

//</script>

