function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popUp(page,w,h,scr) {
  var newWindow;
 
  var scnWidth = (screen.width - w)/2;
  var scnHeight = (screen.height - h)/2;
  if (scnWidth < 0) scnWidth = 0;
  if (scnHeight < 0) scnHeight = 0;

  var features = "toolbar=no, status=no, menubar=no, location=no, scrollbars= " + scr + ", resizable=no";    
  var settings = 'height=' + h + ',' + 'width=' + w + ',' + 'top=' + scnHeight + ',' + 'left=' + scnWidth + ',' + features;
  
  newWindow = window.open(page,"popup",settings);
  newWindow.window.focus();
}

function Menu ( id, cssClass, cssOverClass ) {
	this.overCSS = cssOverClass;

	this.id = Menu.register( this );

	this.cell = document.getElementById( id );
	this.cell.menuInst = this;
	this.cell.onmouseover = Menu.forwardCellEvent;
	this.cell.onmouseout = Menu.forwardCellEvent;

	this.menu = document.createElement( "SPAN" );
	document.body.appendChild( this.menu );
	this.menu.style.position = "absolute";
	this.menu.style.display = "none";

	var table = document.createElement( "TABLE" );
	this.menu.appendChild( table );
	table.cellSpacing = 0;
	table.cellPadding = 0;
	table.className = cssClass;

	this.tableBody = document.createElement( "TBODY" );
	table.appendChild( this.tableBody );
}

Menu.prototype.hideTimeout = null;
Menu.prototype.shown = false;

Menu.prototype.addItem = function ( text, url ) {
	var tr = document.createElement( "TR" );
	this.tableBody.appendChild( tr );
	var cell = document.createElement( "TD" );
	tr.appendChild( cell );

	cell.menuInst = this;
	cell.url = url;
	cell.innerHTML = "<img src='/fcd/images/drop.gif' width=15 height=17>" + "&nbsp;&nbsp;" + text;
	cell.style.borderBottom = "1px solid #043A7C";
	cell.style.padding = "4 4 4 4";
	cell.style.cursor = ns ? "pointer" : "hand";
	cell.onmouseover = Menu.forwardItemEvent;
	cell.onmouseout = Menu.forwardItemEvent;
	cell.onclick = Menu.forwardItemEvent;
}

Menu.prototype.showMenu = function () {
	var image = this.getImage();
	image.src = this.getImageURL( "on" );

	var topOffset = leftOffset = 0;
	var curParent = this.cell;
	while ( curParent ) {
		topOffset += curParent.offsetTop;
		leftOffset += curParent.offsetLeft;
		curParent = curParent.offsetParent;
	}

	this.menu.style.top = topOffset + this.cell.offsetHeight;
	this.menu.style.left = leftOffset;
	this.menu.style.display = "block";

	if ( !this.shown ) {
		Menu.closeAll();
		this.shown = true;
	}
}

Menu.prototype.getImage = function () {
	if ( this.cell.children ) return this.cell.children[ 0 ].children[ 0 ];
	var child = this.cell.childNodes[ 1 ];
	if ( child.childNodes[0].tagName == "IMG" ) return child.childNodes[ 0 ];
	return child.childNodes[ 1 ];
}

Menu.prototype.getImageURL = function ( status ) {
	var url = this.getImage().src;
	return url.substr( 0, url.indexOf(this.cell.id) ) + this.cell.id + "-" + status + ".gif";
}

Menu.prototype.hideMenu = function () {
	this.getImage().src = this.getImageURL( "off" );
	this.menu.style.display = "none";
	this.shown = false;
}

Menu.prototype.mouseoverCellHandler = function () {
	this.cancelHide();
	this.showMenu();
}

Menu.prototype.startHide = function () {
	this.cancelHide();
	this.hideTimeout = setTimeout( "Menu.insts[" + this.id + "].hideMenu()", 400 );
}

Menu.prototype.mouseoutCellHandler = Menu.prototype.startHide;

Menu.prototype.cancelHide = function () {
	if ( this.hideTimeout ) clearTimeout( this.hideTimeout );
}

Menu.prototype.clickItemHandler = function ( cell ) {
	document.location.href = cell.url;
}

Menu.prototype.mouseoverItemHandler = function ( cell ) {
	this.cancelHide();
	cell.className = this.overCSS;
}

Menu.prototype.mouseoutItemHandler = function ( cell ) {
	cell.className = "";
	this.startHide();
}

Menu.forwardCellEvent = function ( event ) {
	Menu.forwardEvent( event, "Cell" );
}

Menu.forwardItemEvent = function ( event ) {
	Menu.forwardEvent( event, "Item" );
}

Menu.forwardEvent = function ( event, type ) {
	if ( !event ) event = window.event;
	var curElement = event.srcElement || event.target;
	while ( curElement && curElement.tagName != "TD" )
		curElement = curElement.parentElement || curElement.parentNode;
	if ( !curElement ) return;
	curElement.menuInst[ event.type + type + "Handler" ]( curElement );
}

Menu.insts = [];

Menu.register = function ( inst ) {
	var id = Menu.insts.length;
	Menu.insts[ id ] = inst;
	return id;
}

Menu.closeAll = function () {
	for ( var i=0; i < Menu.insts.length; i++ ) {
		var inst = Menu.insts[ i ];
		if ( inst.shown ) inst.hideMenu();
	}
}

Menu.unavailable = document.layers || ( navigator.platform == "MacPPC" && this.name == "Microsoft Internet Explorer" );

var ns = ( navigator.appName == "Netscape" );
if ( ns ) {
	HTMLElement.prototype.__defineGetter__(
		"children",
		function () {
			var tmp = [];
			var j = 0;
			var n;
			for ( var i = 0; i < this.childNodes.length; i++ ) {
				n = this.childNodes[ i ];
				if ( n.nodeType == 1 ) {
					tmp[ j++ ] = n;
					if ( n.name ) {
						if ( !tmp[n.name] )
							tmp[n.name] = [];
						tmp[ n.name ][ tmp[n.name].length ] = n;
					}
					if ( n.id ) tmp[ n.id ] = n;
				}
			}
			return tmp;
		}
	);
}
