
function sniffIE()
{
	var sAgent = navigator.userAgent

	var isIE = (sAgent.indexOf("MSIE")  > -1)

	return isIE;
}

function onmenuclick(obj,code)
{
	hide(obj);
	eval(code);
}

function show(obj)
{
 	if(typeof(obj) == "undefined")
		return;
 	obj.style.visibility = 'visible';
}

function hide(obj)
{
	if(typeof(obj) == "undefined")
		return;
	obj.style.visibility = 'hidden';
}


function SetColor(obj,bgColor,tColor)
{
	if(typeof(obj) == "undefined")
		return;
	obj.style.backgroundColor = bgColor;
	obj.style.color = tColor;
}

function SetCellColor(obj,bgColor)
{
	if(typeof(obj) == "undefined")
		return;
	obj.bgColor = bgColor;
}

function SetClass(obj,newClass)
{
	if(typeof(obj) == "undefined")
		return;
	obj.className = newClass;
}

function OnMouseOverBar(obj,rowid,colid,hbgColor,htColor)
{	
	SetColor(obj,hbgColor,htColor);
	window.status = menuArr[rowid][colid][2];
}

function OnMouseOutOfBar(obj,dbgColor,dtColor)
{
	SetColor(obj,dbgColor,dtColor);
	window.status = "";
}

function OnMouseOverCell(linkId,cellObjId,cellid,hClass,hbgColor)
{
	//first get a reference to the <td> and <a>
	var link = document.getElementById(linkId);
	var cell = document.getElementById(cellObjId);
	
	SetClass(link,hClass);
	SetCellColor(cell,hbgColor);
	window.status = titles[cellid][0];
}

function OnMouseOutOfCell(linkId,cellObjId,dClass,dbgColor)
{
	//first get a reference to the <td> and <a>
	var link = document.getElementById(linkId);
	var cell = document.getElementById(cellObjId);
	
	SetClass(link,dClass);
	SetCellColor(cell,dbgColor);
	window.status = "";
}

function Initialize(rows,cols)
{
  menuArr = new Array();
  titles =  new Array();
  for(i=0; i< rows; i++)
  {
     titles[i] =  new Array(2)
	 titles[i][0] = "";
	 titles[i][1] = 0;
  }
  for (i=0; i < rows; i++) 
  {
	menuArr[i] = new Array(cols)
	for (j=0; j < cols; j++) 
	{
		menuArr[i][j] = new Array(3)
		for(k=0; k < 3 ; k++)
		 menuArr [i][j][k] = "";
	}
  }
}

function CreatePopUpMenu(rowid,x,y,width,height,hbgColor,dbgColor,barColor,htColor,dtColor,font,items,align,border,padding)
{
	if(!items)
	{
	   return;
	}
	var divHTML ;

	divHTML = "<DIV id=\"popup_"+rowid+"\"" ;
	divHTML += "style=\"position:absolute;  cursor:pointer; top:"+y+"px; left:"+x+"px; width:"+width+"px; visibility:hidden; padding-left:"+border+"; background-color:"+barColor+"; "+font+" border-bottom: 1px solid #000042;\" ";
	divHTML += "onmouseover=\"show(this);\" onmouseout=\"HidePopUp("+rowid+");\" >";
	//divHTML += "<DIV class=\"separator\"></DIV>";

	for (i=0;i<items;i++)
	{
		divHTML += CreateMenuBar('popup_'+rowid,rowid,i,width-(border*2),height,hbgColor,dbgColor,htColor,dtColor,align,padding);
		//divHTML += "<DIV class=\"separator\"></DIV>";
	}  
	  
	divHTML += "</DIV>";
	document.write(divHTML);
}

function CreateMenuBar(parent,rowid,colid,width,hPixels,hbgColor,dbgColor,htColor,dtColor,align,padding)
{
	var subMenuHTML; 
	subMenuHTML = "<DIV align="+align+" id=\"div_"+rowid+"_"+colid+"\" style=\"position:relative; CURSOR: pointer; width:"+width+"px; height:"+hPixels+"px; color:"+dtColor+"; background-color:"+dbgColor+"; padding-top: "+padding+"px; padding-bottom: "+padding+"px; border-bottom: 1px solid #000042;\" ";
	subMenuHTML += " onmouseover=\"OnMouseOverBar(this,"+rowid+","+colid+",\'"+hbgColor+"\',\'"+htColor+"\');\" ";
	subMenuHTML += " onclick=\"onmenuclick(document.getElementById(\'"+parent+"\'),\'" + menuArr[rowid][colid][1] + "\');\" ";
	subMenuHTML += " onmouseout=\"OnMouseOutOfBar(this,\'"+dbgColor+"\',\'"+dtColor+"\');\" >";
	subMenuHTML +=  menuArr[rowid][colid][0];
	subMenuHTML += "</DIV>";
	return subMenuHTML;
}

function TrackPopUp(objId,event)
{

	if(typeof(objId) == "undefined")
		return;
		
	obj = document.getElementById(objId)
	var winWidth  = document.body.clientWidth;
	var winHeight = document.body.clientHeight;
	
	if (sniffIE()){
		//MSIE
		x = winWidth - (obj.offsetWidth + window.event.x);
		y = winHeight - (obj.offsetHeight + window.event.y);
		obj.style.left = x<0 ? window.event.x + (x + 20): window.event.x + 20;
		obj.style.top = y<0 ? window.event.y + y : window.event.y;	
	}else{
		//Mozilla/Netscape
		x = winWidth - (obj.offsetWidth + event.pageX);
		y = winHeight - (obj.offsetHeight + event.pageY);
		obj.style.left = x<0 ? event.pageX + x : event.pageY;
		obj.style.top = y<0 ? event.pageY + y : event.pageY;
	}
	show(obj);
	return false;
}

//
// Assumes the PopUp will be attached to a <td> table cell.
// Supports nesting of tables within tables.
// NOT tested when nested within other elements.
//
// Parms : objId = the element id of the popup menu
// Parms : parentId = the element id of the <td> table row to place the popup next to
//
function PositionPopUp(objId,parentId,link)
{
	// Hide all popup menus
	
	for (i = 0; i < numberOfMenus; i++)
	{
		hideObj = document.getElementById("popup_" + i);
		
		if (hideObj != null)
		{
			hide(hideObj);	
		}
	}

	//first get a reference to the popup menu
	obj = document.getElementById(objId)
	//next get a reference to the <td>
	var thisParent = document.getElementById(parentId);
	
 	if (obj != null)
	{				
		//now walk up the DOM until the BODY element is reached.
		//along the way, add up the Left & Top offsets
		var myLeft = 0;
		var myTop = 0;
		var trParent = thisParent.offsetParent;
		myLeft += trParent.offsetLeft;
		myTop += trParent.offsetTop;	
		while (trParent.offsetParent.tagName != 'BODY')
		{
			trParent = trParent.offsetParent;	//get the next parent up the nest
			myLeft += trParent.offsetLeft;
			myTop += trParent.offsetTop;
		}

		obj.style.left = myLeft + thisParent.offsetLeft;
		obj.style.top = myTop + thisParent.offsetTop + 25;
		
		show(obj);	
	}
	
	for (i=0; i < numberOfMenus;i++)
	{
		cell = document.getElementById("td" + i);
		thisLink = document.getElementById("a" + i);
		
		if (cell != null &&
			thisParent != null &&
			cell != thisParent)
		{
			cell.className = "nav";
			thisLink.className = "nav";
		}	
	}	

	if (thisParent != null)
	{
 		thisParent.className = "navHL";
		var thisLink = document.getElementById(link);
		thisLink.className = "navHL";
	}
			
	return false;
}

function HidePopUp(id)
{
	if(typeof(id) == "undefined")
		return;

	//first get a reference to the popup menu
	popupObj = document.getElementById("popup_"+id);
	
	if (popupObj == null)
	{
		return;
	}
	else
	{
		hide(popupObj);
	}
	
	cellObj = document.getElementById("td"+id);
	
	if (cellObj != null &&
		popupObj.style.visibility != 'visible')
	{
		//cellObj.style.backgroundColor = "#BBAF2B";
		cellObj.className = "nav";
	}
	/*
	linkObj = document.getElementById("a"+id);	
	
	if (linkObj != null)
	{
		linkObj.className = "nav";
	}*/
	
	return false;
}

