//<script>
document.body.oncontextmenu = context_handleContext;

var context_selectedObject = null;
var context_selectedMenu   = null;
var context_myContextMenu  = null;
var context_xhit;
var context_yhit;
var context_element_hit;

function context_handleContext()
{  
	if( window.event.ctrlKey ) {
		return true;
	}
try {
	context_xhit = window.event.clientX;
	context_yhit = window.event.clientY;

	context_element_hit = context_getElementHit(window.event);

  	if( context_element_hit.contextMenu ||
  		document.getElementById( "context" ) != null  ) 
  	{
  		// old style context menus
  		// used when lean code is needed (ie: if there are a lot of menus)
  		//
  		if( context_element_hit.contextMenu ) 
  		{  	var thisContext=String(context_element_hit.contextMenu);
			if( String( thisContext ).substr( 0, 1 ) == "/" || thisContext.indexOf("javascript:")==0)
			{
				context_clearContextMenu();
				context_myContextMenu = document.getElementById( "hiddenQuickContext" );
				if (thisContext.indexOf("javascript:")==0)
				{	thisContext=eval(thisContext.substr(11));
				}
				context_buildQuickPopup( thisContext );
				context_myContextMenu.style.posLeft = window.event.clientX + document.body.scrollLeft;
				context_myContextMenu.style.posTop  = window.event.clientY + document.body.scrollTop;
				context_myContextMenu.style.display = "";
				context_selectedObject              = context_element_hit;
				context_selectedMenu                = context_myContextMenu;
				showMenu( document.getElementById( "quickContext" ), new Boundaries(window.event.x + document.body.scrollLeft, window.event.y+ document.body.scrollTop), 'vertical');
				
				return false;
			}
			else
			{
				showMenu( document.getElementById( context_element_hit.contextMenu ), new Boundaries(window.event.x+ document.body.scrollLeft, window.event.y+ document.body.scrollTop), 'vertical');
  			}
  		}
  		else
  		{	
  			showMenu( document.getElementById( "context" ), new Boundaries(window.event.x+ document.body.scrollLeft, window.event.y+ document.body.scrollTop), 'vertical');
		}
	
		return false; 
	}

} catch(e)
{
	alert( e.description );
}
}

function context_getElementHit(ev)
{
	return ev.srcElement;
}

function context_buildQuickPopup( src )
{
	var thisMenu = new String( src );
	var menuEntries = thisMenu.split(/\<\|\|\>/);
	var thisLine;
	var pieces;
	var count;
	var actionText;
	var finalOutput = "<table cellspacing=\"0\" class=\"ss_menu\" id=\"quickContext\">\n";
	
	context_myContextMenu = document.getElementById( "hiddenQuickContext" );

	for( count = 0; count < menuEntries.length; count++ )
	{ 
		thisLine   = new String(menuEntries[count]);
		pieces     = thisLine.split(/\<\|\>/);
		
		if( String( pieces[ 2 ] ).match( /(javascript:)\s*if\s*/i ) != null )
		{
			actionText = "onclick=\"" + String( pieces[ 2 ] ).replace( /javascript:/i, "") +";parent.context_clearContextMenu();\"";
		}
		else if( String( pieces[ 2 ] ).match( /javascript:/i ) == "javascript:" )
		{
			actionText = "onclick=\"" + String( pieces[ 2 ] ).replace( /javascript:/i, "") +";parent.context_clearContextMenu();\"";
		}
		else
		{
			actionText = "href=\"" + pieces[ 2 ] +"\"";
		}
	
	 	finalOutput +=	"<tr " + actionText + " >\n" +
						"<td class=\"icon\"><img src=\"" + pieces[ 0 ] + "\" height=\"16\" width=\"16\"></td>\n" +
						"<td nowrap class=\"middle\">" + pieces[ 1 ] + "</td>\n" +
						"<td class=\"right\"></td></tr>\n";
	}
	//alert(finalOutput + "</table>");

	//alert(context_myContextMenu.outerHTML);
	context_myContextMenu.innerHTML = finalOutput + "</table>";
	//alert(context_myContextMenu.innerHTML);
}

function context_clearContextMenu()
{ 	
	if( context_selectedMenu )
	{ 
		if (parent.hideAllMenuScriptlets)
			parent.hideAllMenuScriptlets();
		else
			hideAllMenuScriptlets();
		context_selectedMenu.style.display	= "none"; 
		context_selectedObject				= null;
		context_selectedMenu				= null;
		return false;
	}
}


document.write(	"<scr"+"ipt language=\"javascript\" src=\"/include/javascript/widgets/menu3.js\"></scr"+"ipt>" +
		"<div ID=\"hiddenQuickContext\" UNSELECTABLE=\"true\" style=\"z-index:99;position:absolute;display:none\">stub content</div>");

