/**
* @author Yasmina Chitti
* @copyright SRI International, 
* 
**/

function navigateInBrowser(strn) {
  window.location.href = strn;
  return true;
}

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,fgcolor) {
	if(typeof(obj) == "undefined") return;
 obj.style.color = fgcolor;
	obj.style.backgroundColor = bgcolor;
}

function OnMouseOverBar(obj,rowid,colid,bgcolor,fgcolor) {
	SetColor(obj,bgcolor,fgcolor);
	window.status = menuArray[rowid][colid];
}

function OnMouseOutOfBar(obj,rowid,colid,bgcolor,fgcolor) {
	SetColor(obj,bgcolor,fgcolor);
	window.status = "";
}



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;
}

function PositionPopUp(objId,parentId) {
	if(typeof(objId) == "undefined")
		return;

	//first get a reference to the popup menu
	obj = document.getElementById(objId)

	//next get a reference to the <tr>
	var thisParent = document.getElementById(parentId);
	
	//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;	

	obj.style.left = myLeft + thisParent.offsetLeft+"px";
	obj.style.top = myTop + thisParent.offsetTop+"px";
	
	show(obj);
	return false;
}

function ErasePopUp(objId,parentId)
{
	if(typeof(objId) == "undefined")
		return;

	//first get a reference to the popup menu
	obj = document.getElementById(objId)
	hide(obj);
	return false;
}

function CreateMenuBar(rowid,obj,cssClass) {
	var subMenuHTML; 
	current_id = "div_"+ rowid +"_"+ obj;
	navigationLink =  navigationArray[rowid][obj];

	subMenuHTML = "\n<div id=\""+current_id+"\" ";
	subMenuHTML += "class=\""+cssClass+"\" ";	
	subMenuHTML += " > " ;
	subMenuHTML +=  "<a href=\""+navigationLink+"\">";
	subMenuHTML +=  menuArray[rowid][obj];
	subMenuHTML += "</a>\n";
	subMenuHTML += "</div> \n";
	return subMenuHTML;
}

function CreatePopUpMenu(menuIndex,menuLength) {
	var divHTML ;

	if(!menuLength) {
		return;
	}

	divHTML = "<div id=\"popup_"+ menuIndex +"_0\"" ;
	// Give it the class by default
	divHTML += " class=\"menu\" ";
	// Make it invisible by default
	divHTML += " style=\"visibility:hidden;\"";
	// Add javascript handler for mouseOver, mouseOut
	divHTML += " onmouseover=\"show(this);\" onmouseout=\"hide(this);\" >\n";

// RECREATE menu title to override current menu made in navigation.js
//	divHTML += CreateMenuBar(menuIndex,0,"menuTitle");
	
	// Create submenu items
	for (obj = 1;obj < menuLength; obj++) {
		divHTML += CreateMenuBar(menuIndex,obj,"menuText");
	}  
	divHTML += "</div>";

	document.write(divHTML);
}


function createMenus() {
	for (parent_id = 0; parent_id < menuArray.length; parent_id++) {
		menuLength = menuArray[parent_id].length;
		CreatePopUpMenu(parent_id,menuLength);
	}
}



