
var apiUrl = "XMLGenerator.jsp";
var msie=true;  // this is boolean true if the browser is MicroSoft IE
var entityOneName=null;
var relationName=null;
var entityTwoName=null;

var baseDoc = null; //DELROY: 
var trail = null //DELROY: div to hold entire trails area
var marker = 0; //DELROY: marker for promoting divs at top
var deactivator = false; //deactivate all other span tags after one has been selected
var append = false; //DELROY determine whether to append trail or not
var allTrails = ""; //DELROY keep track of all trails
var deactivateSpanTags = false; //DELROY use the span tag that initiated the event to deactivate all other span tagsS
var bookmarkArray = new Array();//DELROY: document.createDocumentFragment();

// the function below is the first called function by html file. In order to
// show some popup menus, some <div> tags
// are put to html page. this function calls "clearThemAll" function which
// change the status of those div tags
// into invisible. this function also checks if the browser microsoft IE. if
// not, then the boolean msie variable
// are set to false. this boolean value will be used later, because different
// browsers use different methods for
// different tasks.
function onloadFunc(){
	clearThemAll();
	// loadXMLDoc("dontCare", "t1", "dontCare");
	if(navigator.appName != "Microsoft Internet Explorer"){
		msie=false;
	}
	// 	this function used to load ontologies and sortedSet. this function is a AJAX method. with the parameter "t13", it calls
	// appropriate method in Java class.
	// loadXMLDoc("dontCare", "t13", "dontCare")
	
	// Hide the "loading" message
	Element.toggle('loading');
	// Create the help dialog box
	// var hDlg = new Dialog.box("helpDiv");
	// Load database selection

	// DELROY: HACK: only database load for radiobuttons
	if(document.getElementById('dbSelector').tagName == "SELECT"){
		//do nothing
	}else{
		populateSelectDBSection();
	}
	showDomObjects();
}


//	this method are called by onLoadFunc fuction. Makes the div elements in the HTML file invisible.
function clearThemAll(){
	// because name of the div tag id's are PopupId1, PopupId2,...,PopupId6,  we just concatenate PopupId with numbers from
	// 1 to 6. and make the div tags with those id's invisible.
	for(i=1; i<=6; i++){
		var container = document.getElementById("PopupId"+i);
		container.style.display = "none";
	}
	var container = document.getElementById("SetPopupId");
	container.style.display = "none";
	var container = document.getElementById("SetPopup2Id");
	container.style.display = "none";
	
}


//	this methods makes the div elements in the HTML invisible when user clicks on anywhere in the html page.
// this function are put into the <body> tag of the html as
// OnClick="clearThemAllByClick()"
//DELROY: modified- called on clicking any div instead of on clicking body
function clearThemAllByClick(e){
	
	//	if the user click mouse while pointer is on one of the popup menus, we don't hide all popup menus. if user wants to 
	// hide the menus, we expect him to click outside of the menu.
	if(!onMenus){
		for(i=1; i<=6; i++){
			// because name of the div tag id's are PopupId1, PopupId2,...,PopupId6,  we just concatenate PopupId with numbers from
			// 1 to 6. and make the div tags with those id's invisible.
			var container = document.getElementById("PopupId"+i);
			container.style.display = "none";
		}
		//	Likewise, make other two div tags invisible.
		var container = document.getElementById("SetPopupId");
		container.style.display = "none";
		
		container = document.getElementById("SetPopup2Id");
		container.style.display = "none";

		//DELROY: removing main menu and snippet on clicking any div
		container = document.getElementById("snippetId");
		container.innerHTML = "";
		container.style.visibility = "hidden";
		
		var target = getTargetElement(e);
		if(target.tagName == "SPAN"){
			container = document.getElementById("mainmenuId");
			container.style.visibility = "visible";
		}else{
			container = document.getElementById("mainmenuId");
			container.innerHTML = "";
			container.style.visibility = "hidden";
		}
		
		// the boolean popup2Appeared is used for the reason that when user
		// hover on a namedEntity (the term with different color)
		// the first popup menu appears (PopupId1). When user hovers on another
		// named entity, we remove the previously appeared
		// popup menu, and generate a new popup menu (PopupId1). however, once
		// user hover on the popup1 menu, then popup2 menu
		// appears. after that when user hovers on another named entity, the two
		// menus would not be removed. the only way,
		// to get rid of them, is to click on somewhere on the page so that the
		// function clearThemAllByClick removes them.
		popup2Appeared=false;
		deactivateSpanTags = false;
		
	}
	
	//alert("popup2Appeared: "+popup2Appeared);
	
	

}


//	this function is called when the user hovers on the object of the triple which is in the history section of user interface.
// the parameter "e" is needed as a event handler for Mozilla FF browser.
// the parameter "obj" is the name of the object.
// the parameter "ttt" is "t12" here. it is used to call appropriate method in
// Java class.
// the parameter "container" is "PopupId6" here. the result returned is inserted
// into div with id "PopupId6".
function entityRelationMouseOverFromHist(e, obj, ttt, container){
	//	this function used to return the file names in which the object term appears. 
	// this function is a AJAX method. with the parameter "t12", it calls
	// appropriate method in Java class.
	loadXMLDoc(obj, ttt, container);	
	if(msie){	// if the browser is MS IE
		document.getElementById(container).style.pixelLeft = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft + 5;
		document.getElementById(container).style.pixelTop =  window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop + 2;
	}
	else{	// if the browser is NOT  MS IE
		document.getElementById(container).style.top = giveCoordY(e) + 'px';
		document.getElementById(container).style.left = giveCoordX(e) + 5 + 'px';
	}
}
  	

var lvlsofar=0;
var onMenus = false;

// used to get the X coordination of the mouse pointer at the time of event
// call.
// this is needed to position the menu to the where the user hovers on a named
// entity.
// the parameter "e" is needed for Mozilla FF as a event handler.
function getMouseX(e){	// works on IE6,FF,Moz,Opera7
	var mousex=0;
	var mousey=0;
	var algor=0;
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us
							// the event)
 
  if (e){
  	//alert("e.pageX= "+e.pageX+"\ne.clientX= "+e.clientX);
    if (e.pageX){ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
			mousex = e.pageX;
      algor = '[e.pageX]';
      // alert("e.pageX= "+e.pageX);
      if (e.clientX) algor += ' [e.clientX] '
    }
    else if (e.clientX){ 
      mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      algor = '[e.clientX]';
      // alert("e.clientX= "+e.clientX);
      
      if (e.pageX) algor += ' [e.pageX] '
    }
  }
  return mousex;
}


//	this function is called when the user hovers on the popup menus (PopupId1, PopupId2,..., PopupId5).
// the parameter "e" is needed for Mozilla FF as a event handler.
// the parameter "obj" varies. for the first popup menu, it is instance name.
// for the second popup menu it is class type.
// However when the user hovers on the relationship, in order to return the
// object classes, two parameter is needed;
// one is subject class type, and the other is relationship. then the parameter
// "obj" becomes the relationship, and
// the last parameter "subj", becomes subject class type.
// the parameter varies. this is how JSP file understand which method to call
// from the java class.
// the parameter container also varies. it tells which div tag needs to be used
// as a menu.
function entityRelationMouseOver(e, obj, lvl, ttt, container, subj){
	//alert("e: "+event+"\nUstte obj id: "+obj+" - \nttt: "+ttt+"\nlvl: "+lvl+" - \ncont: "+container);
	onMenus=true;
	var conOnce = container;
	var mydivs=document.getElementById("dDivId"+lvl).getElementsByTagName('div');
	for(i=1; i<mydivs.length; i++){
		mydivs[i].className = "cDivCls";
	}//end for
	
	lvl = Number(lvl);
	if(lvl>=lvlsofar){
		lvlsofar=lvl+1;
	}
	//alert(ttt);
	if(lvlsofar-lvl>1){	
		for(i=lvl+2; i<=lvlsofar; i++){
			var newId = "PopupId"+i;
			container = document.getElementById(newId);	// yeniId PopupId3 and PopupId4
			container.firstChild.innerHTML = " ";
			container.style.display = "none";	
		}
	}
	
	//alert("Altta objId: "+obj+" \nttt: "+ttt+" \nlvl: "+lvl+" \ncont: "+container+" ");
	loadXMLDoc(obj, ttt, conOnce, subj);
	if(ttt=="t4"){
		preRel=obj;
	}
	else if(ttt=="t6"){
		preObj=obj;
	}
	
	document.getElementById(obj).className = "ItemMouseOver";
	if(lvl==4){
		if(msie){
			document.getElementById(container).style.pixelTop =  window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop - 10;
			document.getElementById(container).style.pixelLeft = document.getElementById("PopupId4").getBoundingClientRect().right + Bdy.scrollLeft - 4;
		}
		else{
			//alert("e: "+e+"\nUstte obj id: "+obj+" - \nttt: "+ttt+"\nlvl: "+lvl+" - \ncont: "+container+"  ");
			var newX = findPosX(document.getElementById("PopupId4"));
			document.getElementById(container).style.top = giveCoordY(e) - 10 + 'px';
			document.getElementById(container).style.left = newX + popupWidth(document.getElementById("PopupId4")) - 0 + 'px';
		}
	}
	if(lvl==6){
		//alert("In if(lvl==6): obj= "+obj+" \nttt: "+ttt+" \nlvl: "+lvl+" \ncont: "+container+" ");
		document.getElementById("PopupId6").style.pixelLeft = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft - 200;
		document.getElementById("PopupId6").style.pixelTop =  window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
	}
}

var prelvl=0;

function entityRelationMouseOut(obj, lvl){
	prelvl = lvl;
	onMenus=false;
}

var preFile=null;
var curFile=null;
var preSubj=null;
var curSubj=null;
var preRel=null;
var curRel=null;
var preObj=null;
var curObj=null;

function setSubject(subj) {
	preSubj = subj;
	entityOneName = subj;
}
function setRelation(rel) {
	preRel = rel;
	relationName = rel;
}
function setObject(obj) {
	preObj = obj;
	entityTwoName = obj;
}


//	this function takes the file path as the first parameter. it takes the abstract part of the XML file and insert into,
//	the container which is specified as the last parameter of the function.
function filesMouseClick(obj, lvl, ttt, container,from){
	
	preFile=curFile;
	curFile=unescape(obj);
	
	if(from!="noHistory"){
		BuildHistory(preFile, lvl);
	}
	//DELROY: added a slight delay to allow ajax request to processs
	setTimeout("loadXMLDoc('"+obj+"', '"+ttt+"', '"+container+"')",200);
}


function filesMouseOut(obj){
	document.getElementById(obj).className = "cFilesCls";
}


//	this function is used only to highlight the file name by changing its classname.
function filesHoverMouseOver(ins, fromContId, container){
	ins = unescape(ins);
	document.getElementById(ins).className = "ItemMouseOver"; //DELROY: uniform behaviour on mouseover for popups
	loadSnippetXML(ins);
}


//	this function is used only to unhighlight the file name by changing its classname to its orijinal name.
function filesHoverMouseOut(ins, ttt, container){

	//DELROY: delete all snippets
	var snippet = document.getElementById("snippetId");
	snippet.innerHTML = "";
	snippet.style.visibility = "hidden";
	
	//alert("overda ins= "+ins+"\nttt= "+ttt+"\ncont= "+container);
	ins = unescape(ins);
	if(ins.substring(0,1)=="5"){
		document.getElementById(ins).className = "cDivCls";	// cDivCls for 5. menu. cFilesCls is for left 
	}
	else
		if(ins.substring(0,1)=="6"){
			document.getElementById(ins).className = "cFilesCls";	// cDivCls for left-most menu that has file names.
	}
	else
		if(ins.substring(0,1)=="7"){
			document.getElementById(ins).className = "cDivCls";	// cDivCls for 5. menu. cFilesCls is for left
	}
	else
		if(ins.substring(0,1)=="h"){
			document.getElementById(ins).className = "cHistFileName";	// cDivCls for 5. menu. cFilesCls is for left
	}
	else
		if(ins.substring(0,1)=="f"){
			document.getElementById(ins).className = "xx";	// cDivCls for 5. menu. cFilesCls is for left
	}
	//alert("at Out, class name"+document.getElementById(ins).className);
}


//	after the abstract part of the file is inserted into web page, the named entities are between <span> and </span> tags.
// and these terms are in different color. when the user hover over a named
// entity, the function below is called.
// the second parameter ttt is t2 in this case.
function spanHover(e, namedEntity, ttt, container, parentId){
	//alert("event:\n" + e +"namedEntity: "+namedEntity+"\nttt= "+ttt+"\nCont= "+container); 
	// the boolean popup2Appeared is used for the reason that when user hover on
	// a namedEntity (the term with different color)
	// the first popup menu appears (PopupId1). When user hovers on another
	// named entity, we remove the previously appeared
	// popup menu, and generate a new popup menu (PopupId1). however, once user
	// hover on the popup1 menu, then popup2 menu
	// appears. after that when user hovers on another named entity, the two
	// menus would not be removed. the only way,
	// to get rid of them, is to click on somewhere on the page so that the
	// function clearThemAllByClick removes them.
	
	//DELROY: get the element that triggered this event
	var target = getTargetElement(e);
	var targetID = target.parentNode.parentNode.getAttribute("id"); // event target id
	//target.style.background='#CC3300';
	baseDoc = document.getElementById(parentId);
	if(!deactivator){ //only set the base span if the second popup menu appears
		if(baseDoc == null){
			//baseDoc = document.getElementById(targetID);
		}
		entityOneName = namedEntity; //set entity name was throwing a bug earlier (was null)
	}
	//alert("the parent is: " + baseDoc.id);
	
	if(!popup2Appeared){
		if(ttt=="t2"){
			preSubj=namedEntity;
			loadXMLDoc(namedEntity, ttt, container);	// container is PopupId1 here And ttt is 't2'.
		}
		if(msie){	//	if the browser is MS IE
			document.getElementById(container).style.pixelLeft = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft + 5;
			document.getElementById(container).style.pixelTop =  window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop + 2;
		}
		else{	//	if the browser is NOT  MS IE
			document.getElementById(container).style.top = giveCoordY(e) + 15 + 'px';
			document.getElementById(container).style.left = giveCoordX(e) + 15 + 'px';
		}
		
	}
	
}



//	the function below gets the list of type classes in XML format from AJAX engine, builds the PopudId1 menu which
// includes the list of type classes of a named instance when user hover over
// them.
function BuildMenu(obj){	
	//	the boolean popup2Appeared is used for the reason that when user hover on a namedEntity (the term with different color)
	// the first popup menu appears (PopupId1). When user hovers on another
	// named entity, we remove the previously appeared
	// popup menu, and generate a new popup menu (PopupId1). however, once user
	// hover on the popup1 menu, then popup2 menu
	// appears. after that when user hovers on another named entity, the two
	// menus would not be removed. the only way,
	// to get rid of them, is to click on somewhere on the page so that the
	// function clearThemAllByClick removes them.
	if(!popup2Appeared){
		clearThemAll();
		var items =	obj.getElementsByTagName('item');
		var relIDs =	obj.getElementsByTagName('relID');
		var inss =	obj.getElementsByTagName('ins');
		var d = document.createElement('div');
		d.className="dDivCls";
		d.setAttribute('id', 'dDivId1');
		d.setAttribute('lvl', '1');
		c = document.createElement('div');
		c.className="cHeaderCls";
		c.setAttribute('id', inss[0].firstChild.nodeValue);
		c.appendChild(document.createTextNode(inss[0].firstChild.nodeValue.replace(/_/g," "))); 
		d.appendChild(c);
		for(i=0; i<items.length; i++){
			c = document.createElement('div');
			c.className="cDivCls";
			c.setAttribute('id', relIDs[i].firstChild.data);
			// the id of the entity of which these relations belong has to be
			// appended
			c.appendChild(document.createTextNode(items[i].firstChild.nodeValue.replace(/_/g," "))); 
			d.appendChild(c);	
		}

		var container = document.getElementById("PopupId1");
		container.style.display = "block";
		container.style.visibility = "visible";
		container.removeChild(container.firstChild);
		container.appendChild(d);
		
		var mydivs=d.getElementsByTagName('div');
		for(i=1; i<mydivs.length; i++) {
			//var innerarray=mydivs[i];
			mydivs[i].onmouseover = new Function("entityRelationMouseOver(\"event\", \""+mydivs[i].id+"\" ,\"1\" ,\"t3\" ,\"PopupId2\"); relationName=\""+ mydivs[i].innerHTML +"\";");
			// mydivs[i].onmouseover = entityRelationMouseOver(event);
			// displayCursorPosition(event);
			mydivs[i].onmouseout = new Function("entityRelationMouseOut(\""+mydivs[i].id+"\" ,\"1\");");
		}	
	}
}




var popup2Appeared = false;


// the function below gets the list of relationships in XML format from AJAX
// engine, builds the PopudId2 menu which
// includes the list of relationships which are connected to selected type class
// from first popup menu (PopudId1).
function FindSubMenu2(obj){
	//	the boolean popup2Appeared is used for the reason that when user hover on a namedEntity (the term with different color)
	// the first popup menu appears (PopupId1). When user hovers on another
	// named entity, we remove the previously appeared
	// popup menu, and generate a new popup menu (PopupId1). however, once user
	// hover on the popup1 menu, then popup2 menu
	// appears. after that when user hovers on another named entity, the two
	// menus would not be removed. the only way,
	// to get rid of them, is to click on somewhere on the page so that the
	// function clearThemAllByClick removes them.
	popup2Appeared = true;
	
	//DELROY: make span tag active if second popup appears
	if(popup2Appeared){
		deactivator = true;
		deactivateSpanTags = true;
	}//end if
	
	var inss =	obj.getElementsByTagName('ins');
	var subj = inss[0].firstChild.nodeValue;
	
	var items =	obj.getElementsByTagName('item');
	var entityID =	obj.getElementsByTagName('ID');
	var entityIDprev =	obj.getElementsByTagName('entityID');
	var relationID =	obj.getElementsByTagName('relationID');
	var d = document.createElement('div');
	d.className="dDivCls";
	d.setAttribute('id', 'dDivId2');
	d.setAttribute('lvl', '2');
	c = document.createElement('div');
	c.className="cHeaderCls";
	c.appendChild(document.createTextNode("List of Entities")); 
	d.appendChild(c);
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		c.className="cDivCls";
		if(entityID[i].firstChild != null) //DELROY: bug fix, was null
		c.setAttribute('id',entityIDprev[0].firstChild.data+"-"+relationID[0].firstChild.data +"-"   + entityID[i].firstChild.data);
		// the id here has to be modified ...have to append the id
		c.appendChild(document.createTextNode(items[i].firstChild.nodeValue.replace(/_/g," "))); 
		d.appendChild(c);
	}
	var container = document.getElementById("PopupId2");
	container.style.display = "block";
	container.style.visibility = "visible";
	container.removeChild(container.firstChild);
	container.appendChild(d);
	var mydivs=d.getElementsByTagName('div');

	for(i=1; i<mydivs.length; i++){
       mydivs[i].onmouseover = new Function("entityRelationMouseOver(\"event\", \""+mydivs[i].id+"\" ,\"2\" ,\"t6\" ,\"PopupId3\");entityTwoName=\""+ mydivs[i].innerHTML+"\";");
       mydivs[i].onmouseout = new Function("entityRelationMouseOut(\""+mydivs[i].id+"\" ,\"1\");");
	}
	
	var newX = findPosX(document.getElementById("PopupId1"));
	var newY = findPosY(document.getElementById("PopupId1"));
	document.getElementById("PopupId2").style.top = newY + 'px';
	document.getElementById("PopupId2").style.left = newX + popupWidth(document.getElementById("PopupId1")) - 0 + 'px';
	
} 


function entityRelationMouseOver1(e){
           onMenus=true;
	var conOnce = container;
	var mydivs=document.getElementById("dDivId3").getElementsByTagName('div');
	for(i=1; i<mydivs.length; i++){
		mydivs[i].className = "cDivCls";
	}  	
	ttt="t6";
	loadXMLDoc(obj, ttt, conOnce, subj);
	if(ttt=="t6"){
			preObj=obj;
	}
	document.getElementById(obj).className = "ItemMouseOver";
	// if(lvl==6){
		// alert("In if(lvl==6): obj= "+obj+" \nttt: "+ttt+" \nlvl: "+lvl+"
		// \ncont: "+container+" ");
		document.getElementById("PopupId6").style.pixelLeft = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft - 200;
		document.getElementById("PopupId6").style.pixelTop =  window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
	// }

}
function entityRelationMouseOut1(){
//alert("bye");
}

function popupWidth(el){
	var w; 
	if (document.getBoxObjectFor) { 
		var bo = document.getBoxObjectFor(el); 
		w = bo.width;
	} 
	else 
		if(el.getBoundingClientRect){
			var rect = el.getBoundingClientRect(); 
			w = rect.right - rect.left;
	} 
	el.w= w;
	// alert("Left: " + x + "\rTop: " + y + "\rWidth: " + w + "\rHeight: " + h);
	return w;
}

function popupHeight(el){
	var h; 
	if (document.getBoxObjectFor){
		var bo = document.getBoxObjectFor(el); 
		h = bo.height;
	} 
	else 
		if(el.getBoundingClientRect){
			var rect = el.getBoundingClientRect(); 
			h = rect.bottom - rect.top;
	} 
	el.h= h;
	// alert("Left: " + x + "\rTop: " + y + "\rWidth: " + w + "\rHeight: " + h);
	return h;
}



//	the function below gets the list of object class types in XML format from AJAX engine, builds the PopudId3 menu which
// includes the list of object class types which are connected to selected
// relationship and selected subject class type.
function FindSubMenu3(obj){
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('div');
	d.className="dDivCls";
	d.setAttribute('id', 'dDivId3');
	d.setAttribute('lvl', '3');
	c = document.createElement('div');
	c.className="cHeaderCls";
	c.appendChild(document.createTextNode("PMIDs"));
	d.appendChild(c);
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		c.className="cDivCls";
		c.setAttribute('id', items[i].firstChild.data);
		c.appendChild(document.createTextNode(items[i].firstChild.nodeValue.replace(/_/g," "))); 
		d.appendChild(c);
	}
	var container = document.getElementById("PopupId3");
	container.style.display = "block";
	container.style.visibility = "visible";
	container.removeChild(container.firstChild);
	container.appendChild(d);
	var mydivs=d.getElementsByTagName('div');
	for(i=1; i<mydivs.length; i++){
		mydivs[i].onmouseover = new Function("entityRelationMouseOver(\"event\", \""+mydivs[i].id+"\" ,\"3\" ,\"t5\" ,\"PopupId4\");");
		mydivs[i].onmouseout = new Function("entityRelationMouseOut(\""+mydivs[i].id+"\" ,\"3\");");
	}
	var newX = findPosX(document.getElementById("PopupId2"));
	var newY = findPosY(document.getElementById("PopupId2"));
	document.getElementById("PopupId3").style.top = newY + 'px';
	document.getElementById("PopupId3").style.left = newX + popupWidth(document.getElementById("PopupId2")) - 0 + 'px';
} 




//	the function below gets the list of file names in XML format from AJAX engine, builds the PopudId5 menu which
// includes the list of file names in which the selected instance in the fifth
// menu appears.
function createFilesMenu(obj){	// this builds PopupId5, the file names
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('div');
	d.className="dDivCls";
	d.setAttribute('id', 'dDivId5');
	d.setAttribute('lvl', '5');
	c = document.createElement('div');
	c.className="cHeaderCls";
	c.appendChild(document.createTextNode("File name")); 
	d.appendChild(c);
	
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		
			c.className="cDivCls";
		c.setAttribute('id', items[i].firstChild.data);
        // c.setAttribute('id', "fileid");
			c.setAttribute('lvl', '5');
		var cstr = items[i].firstChild.nodeValue.replace(/_/g," ");
		//alert("cstr " + cstr); 
		//cstr = cstr.substring(cstr.indexOf("outsent")+8);
		
		// var cstr="filename";
		c.appendChild(document.createTextNode(cstr));
		
		d.appendChild(c);
		c.onclick = new Function("filesMouseClick(\""+escape(c.id)+"\" ,\"6\" ,\"t1\" ,\"textFileArea\");");
		// this function is used only to highlight the file name by changing its
		// classname.
		c.onmouseover = new Function("filesHoverMouseOver(\""+escape(c.id)+"\", \'f5\', \'filesId1\');");	
		// this function is used only to unhighlight the file name by changing
		// its classname to its orijinal name.
		c.onmouseout = new Function("filesHoverMouseOut(\""+escape(c.id)+"\", \'f5\', \'filesId1\');this.className=\"cDivCls\"");	
	}
		var prevContainer = document.getElementById("PopupId2");
		var X=prevContainer.style.top;
		X=X.substr(0,X.indexOf("px"));	
		var Y=prevContainer.style.left;
		Y=Y.substr(0,Y.indexOf("px"));	
		
	var container = document.getElementById("PopupId3");
	
		container.style.display = "block";
		container.style.visibility = "visible";
		container.style.top = parseInt(X);
		container.style.left = parseInt(Y)+100;
		// document.getElementById(container).style.left =
		// prevContainer.style.left+ 5 + 'px';
	container.removeChild(container.firstChild);
	container.appendChild(d);

// var newX = findPosX(document.getElementById("PopupId2"));
// var newY = findPosY(document.getElementById("PopupId2"));
// document.getElementById("PopupId3").style.top = 100 +'px';
// document.getElementById("PopupId3").style.left = 100 + 'px';

	
} 


//	this function gets an array of file names and showed them on search Area (left column).
function FindSubMenu6(obj){
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('div');
	d.className="dFilesCls";
	d.setAttribute('id', 'dDivId6');
	c = document.createElement('div');
	c.className="cHeaderCls";
	c.appendChild(document.createTextNode("File Name"));
	d.appendChild(c);
	
	for(i=0; i<2; i++){
		c = document.createElement('div');
		c.className="cFilesCls";
		// the reason we concatenate the character "6" as prefix to id is
		// because that the functions filesHoverMouseOver and
		// filesHoverMouseOut are called from different parts of the user
		// interface. so, we need to know from which part the
		// functions are called. because when there are the same file names in
		// the page with also the same id, then when the
		// user hovers on any file name, then if there the same file name at
		// another place in the page,
		// then that file name may be highlighted, just because they have also
		// the same ids.
		c.setAttribute('id', items[i].firstChild.data);
// c.setAttribute('id', "fileid");
		var cstr = items[i].firstChild.nodeValue.replace(/_/g," ");
		// var cstr = "filename";
		// because the items are file paths (ex;
		// ALLNEOPLASM\Neoplasms\split\12345064), we get the substring after the
		// "split"
		// so we get the file name. and we insert it to the menu.
// cstr.substring(cstr.indexOf("outsent")+7);
		cstr="filename";
		c.appendChild(document.createTextNode(cstr)); 
		// alert(escape(c.id));
		c.onclick = new Function("filesMouseClick(\""+escape(c.id)+"\" ,\"6\" ,\"t1\" ,\"textFileArea\");");
		// this function is used only to highlight the file name by changing its
		// classname.
		c.onmouseover = new Function("filesHoverMouseOver(\""+escape(c.id)+"\", \'dDivId6\', \'filesId1\');");
		// this function is used only to unhighlight the file name by changing
		// its classname to its orijinal name.
		c.onmouseout = new Function("filesHoverMouseOut(\""+escape(c.id)+"\", \'f6\', \'filesId1\');");
		d.appendChild(c);
	}
	var container = document.getElementById("filesId1");
	container.innerHTML="";
	container.appendChild(d);
} 


//	this gets file names and showed them on search Area (left column)
function getPmidReturnAbs(obj){
	var items =	obj.getElementsByTagName('item');
	loadXMLDoc(items[0].firstChild.data, "t1", "textFileArea") 
}


var detailArr=new Array("PMID","OWN","STAT","DA","DCOM","LR","IS","VI","IP","DP","TI","PG");
// this builds Detail Menu
function GetDet(obj){
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('table');
	d.setAttribute('id', 'dDivId8');
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		c1 = document.createElement('span');
		c1.className="detHeaderCls";
		c1.appendChild(document.createTextNode(detailArr[i])); 
		c.appendChild(c1);
		c1 = document.createElement('span');
		c1.className="detContentCls";
		c1.appendChild(document.createTextNode(" = "+items[i].firstChild.nodeValue)); 
		c.appendChild(c1);
		d.appendChild(c);
	}
//	var container = document.getElementById("detailAreaId");
//	container.style.display = "block";
//	container.innerHTML = d.innerHTML;
}



//	this function builds History Menu
function BuildHistory(preFile, lvl){  
  clearThemAll();
  
  if(preFile!=null){
	  	//DELROY: HACK: to fix the triple-sentence name anomaly
	  	//alert(preFile + " " + preFile.split("-").length);
		if(preFile.split("-").length > 2){
			preFile = preFile.substring(0,preFile.lastIndexOf("-"));
		}//end if
		
  		var thumb_up = document.createElement('img');
  		thumb_up.className="thumb_up";
  		thumb_up.setAttribute("src", "img/thumb_up.png");
  		thumb_up.setAttribute("alt", "Approve Triple");
  		thumb_up.onclick = new Function("issueRating(\""+ preFile +"\", \"binary\", \"1\", \"" + getSelectedDB() + "\", \"" + getSelectedNavType() + "\");");
  		var thumb_down = document.createElement('img');
  		thumb_down.className="thumb_down";
  		thumb_down.setAttribute("src", "img/thumb_down.png");
  		thumb_down.setAttribute("alt", "Disapprove Triple");
  		thumb_down.onclick = new Function("issueRating(\""+ preFile +"\", \"binary\", \"0\", \"" + getSelectedDB() + "\", \"" + getSelectedNavType() + "\");");
  		
		trail = document.createElement('div');
		trail.className="dHistCls";
		trail.setAttribute('id', "dDivHistId");
		var c = document.createElement('div');
		c.className="cHistCls";
		c.setAttribute('id', 'cId');
		c1 = document.createElement('span');
		c1.className="cHistFileName";
		c1.appendChild(document.createTextNode(" ")); 
		c.appendChild(c1);
		c2 = document.createElement('span');
		
		c2.setAttribute('id', preFile);		
		c2.className="cHistFileName";
		
		if(entityOneName!=null && entityTwoName!=null && relationName!=null){
			//c2.appendChild(document.createTextNode("Relation ("+entityOneName+" "+relationName+" "+entityTwoName +") appears in "+ preFile.substring(preFile.indexOf("outsent")+8))); 
			c2.appendChild(document.createTextNode("Relation ("+entityOneName+" "+relationName+" "+entityTwoName +") appears in "+ preFile));
		}
		c2.onclick = new Function("filesMouseClick(\""+escape(c2.id)+"\" ,\"7\" ,\"t1\" ,\"textFileArea\",\""+ "noHistory"+"\");");	// mydivs[i].nodeValue
																																	// firstChild.nodeValue
		// this function is used only to highlight the file name by changing its
		// classname.
		c2.onmouseover = new Function("filesHoverMouseOver(\""+escape(c2.id)+"\", \'histAreaId\', \'filesId1\');");	 // mydivs[i].nodeValue
																														// firstChild.nodeValue
		// this function is used only to unhighlight the file name by changing
		// its classname to its orijinal name.
		c2.onmouseout = new Function("filesHoverMouseOut(\""+escape(c2.id)+"\", \'f9\', \'filesId1\');");	 // mydivs[i].nodeValue
																												// firstChild.nodeValue
		c.appendChild(c2);
		c.appendChild(thumb_up);
		c.appendChild(thumb_down);
		trail.appendChild(c);
		if(lvl=="5"){
			c = document.createElement('div');
			c.className="cHistCls";
			p = document.createElement('pre');
			p.appendChild(document.createTextNode("\t")); 
			c.appendChild(p);

			c1 = document.createElement('span');
			c1.className="histHeaderCls";
			c1.appendChild(document.createTextNode("MESH term= ")); 
			c.appendChild(c1);
			c2 = document.createElement('span');
			c2.className="cHistValues";
			c2.appendChild(document.createTextNode(preSubj.replace(/_/g," "))); 
			c.appendChild(c2);

			p = document.createElement('pre');
			p.appendChild(document.createTextNode("  ")); 
			c.appendChild(p);

			c1 = document.createElement('span');
			c1.className="histHeaderCls";
			c1.appendChild(document.createTextNode("--->")); 
			c.appendChild(c1);

			p = document.createElement('pre');
			p.appendChild(document.createTextNode("  ")); 
			c.appendChild(p);

			c1 = document.createElement('span');
			c1.className="histHeaderCls";
			c1.appendChild(document.createTextNode("Relation= ")); 
			c.appendChild(c1);
			c2 = document.createElement('span');
			c2.className="cHistValues";
			c2.appendChild(document.createTextNode(preRel.replace(/_/g," "))); 
			c.appendChild(c2);

			p = document.createElement('pre');
			p.appendChild(document.createTextNode("  ")); 
			c.appendChild(p);

			c1 = document.createElement('span');
			c1.className="histHeaderCls";
			c1.appendChild(document.createTextNode("--->")); 
			c.appendChild(c1);

			p = document.createElement('pre');
			p.appendChild(document.createTextNode("  ")); 
			c.appendChild(p);

			c1 = document.createElement('span');
			c1.className="histHeaderCls";
			c1.appendChild(document.createTextNode("Object= ")); 
			c.appendChild(c1);
			c2 = document.createElement('span');
			c2.className="cHistFileName";
			c2.setAttribute('id', 'cHistObjId');
			c2.onmouseover = new Function("entityRelationMouseOverFromHist(arguments[0], \""+preObj+"\", \"t12\", \"PopupId6\");");	
			c2.appendChild(document.createTextNode(preObj.replace(/_/g," "))); 
			c.appendChild(c2);
			trail.appendChild(c);
		}	
	
	}
}


function buildSubMenu5FromHist(obj){	// this builds PopupId5, the file names
	clearThemAll();
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('div');
	d.className="dDivCls";
	c = document.createElement('div');
	c.className="cHeaderCls";
	c.appendChild(document.createTextNode("File names")); 
	d.appendChild(c);
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		c.className="cDivCls";
		c.setAttribute('id', items[i].firstChild.data);
		c.setAttribute('lvl', '6');
		var cstr = items[i].firstChild.nodeValue.replace(/_/g," ");
		var cstr = cstr.substring(cstr.indexOf("split")+6);  
		c.appendChild(document.createTextNode(cstr)); 
		d.appendChild(c);
		c.onclick = new Function("filesMouseClick(\""+escape(c.id)+"\" ,\"6\" ,\"t1\" ,\"textFileArea\");");	// mydivs[i].nodeValue
																											// firstChild.nodeValue
		// this function is used only to highlight the file name by changing its
		// classname.
		c.onmouseover = new Function("filesHoverMouseOver(\""+escape(c.id)+"\", \'f5\', \'filesId1\');");	 // mydivs[i].nodeValue
																												// firstChild.nodeValue
		// this function is used only to unhighlight the file name by changing
		// its classname to its orijinal name.
		c.onmouseout = new Function("filesHoverMouseOut(\""+escape(c.id)+"\", \'f5\', \'filesId1\');");	 // mydivs[i].nodeValue
																											// firstChild.nodeValue
	}
	var container = document.getElementById("PopupId6");
	container.style.display = "block";
	container.style.visibility = "visible";
	container.removeChild(container.firstChild);
	container.appendChild(d);
} 


//	this function is called when the user begins typing some PMID numbers into "search by PMID" search box.
// this function takes the array of file paths from AJAX engine. each item in
// the array look like this;
// 12345064 -- ALLNEOPLASM\Neoplasms\split\12345064
// for each item, it assigns a class name as cSetCls. it assigns the path of the
// file as the id of item in the menu.
// for each item in the menu, three function is assigned (onclick, onmouseover,
// and onmouseout). what these functions do is
// explained just above the functions.
function GetSet2(obj){
	setTableExist2 = true;
	var items =	obj.getElementsByTagName('item');
	var d = document.createElement('div');
	d.className="dSet2Cls";
	d.setAttribute('id', 'dDivId72');
	for(i=0; i<items.length; i++){
		//alert(i+" th item= "+items[i].firstChild.data);
		c = document.createElement('div');
		c.className="cSetCls";
		// alert(items[i].firstChild.data);
		// c.setAttribute('id',
		// items[i].firstChild.data.substring(items[i].firstChild.data.indexOf("--")+3));
		c.setAttribute('id', items[i].firstChild.data);
		c.appendChild(document.createTextNode(items[i].firstChild.data)); 
		// this function takes the file fath as first parameter, and insert the
		// abstract part of the file into web page.
		// c.onclick = new Function("ClickFunctionFromGetSet2();");
		c.onclick = new Function("ClickFunctionFromGetSet2(\""+escape(c.id)+"\", \"t1\", \"textFileArea\");");
		// the function below is used only to highlight the item by changing the
		// class name.
		c.onmouseover = new Function("SetMouseOver(\""+escape(c.id)+"\");");
		// the function below is used only to unhighlight the item by changing
		// the class name.
		c.onmouseout = new Function("SetMouseOut(\""+escape(c.id)+"\");");
		d.appendChild(c);
	}
	//	the container below is to put the items in it.
	var container = document.getElementById("SetPopup2Id");
	// we make the container visible. because at the beginning we make it
	// invisible.

	container.style.display = "block";
	container.style.visibility = "visible";
	container.innerHTML="";
	container.appendChild(d);
	// we find the X and Y coordinators of the search box so that we can
	// position the suggestion menu right below it.
	var newX = findPosX(document.getElementById("set2AreaId"));
	var newY = findPosY(document.getElementById("set2AreaId"));
	// after finding the location of search box, we position the suggestion menu
	// below the suggestion menu.

	document.getElementById("SetPopup2Id").style.top = newY + 20 + 'px';
	document.getElementById("SetPopup2Id").style.left = newX + 'px';
}




//	this function is called when the user begins typing some keywords into "search by keyword" search box.
// this function takes the array of file paths from AJAX engine. each item in
// the array is a MeSH term
// for each item, it assigns a class name as cSetCls. it assigns the path of the
// file as the id of item in the menu.
// for each item in the menu, three function is assigned (onclick, onmouseover,
// and onmouseout). what these functions do is
// explained just above the functions.
function GetSet(obj){  // this builds Set Popup Menu
	// we use the boolean value below, because we will need it later.
	setTableExist = true;
	// obj parameter is a XML, where each MeSH terms are located between <item>
	// and </item> tags. by using
	// obj.getElementsByTagName('item'), we get the MeSH terms and put them in
	// array "items".
	var items =	obj.getElementsByTagName('item');
	// we create a div tag to put the items in it.
	var d = document.createElement('div');
	d.className="dSetCls";
	d.setAttribute('id', 'dDivId7');
	for(i=0; i<items.length; i++){
		c = document.createElement('div');
		c.className="cSetCls";
		c.setAttribute('id', items[i].firstChild.data);
		// alert((i+1)+" th item: "+items[i].firstChild.data.replace(/_/g," "));
		var text=items[i].firstChild.nodeValue.replace(/_/g," ");
		c.appendChild(document.createTextNode(text)); 
// c.onclick = new Function("ClickFunctionFromGetSet2();");
// c.onclick = new Function("ClickFunctionFromGetSet2(\""+"fart"+"\", \"t1\",
// \"textFileArea\");");
		c.onclick = new Function("ClickFunctionFromGetSet2(\""+escape(c.id)+"\", \"t1\", \"textFileArea\");");	 // mydivs[i].nodeValue
																													// firstChild.nodeValue
		c.onmouseover = new Function("SetMouseOver(\""+escape(c.id)+"\");");	 // mydivs[i].nodeValue
																					// firstChild.nodeValue
		c.onmouseout = new Function("SetMouseOut(\""+escape(c.id)+"\");");	 // mydivs[i].nodeValue
																				// firstChild.nodeValue
		d.appendChild(c);
	}
	var container = document.getElementById("SetPopupId");
	container.style.display = "block";
	container.style.visibility = "visible";
	container.innerHTML="";
	container.appendChild(d);
	
	var newX = findPosX(document.getElementById("setTextArea"));
	var newY = findPosY(document.getElementById("setTextArea"));
	document.getElementById("setTextArea").innerHTML="";
	document.getElementById("SetPopupId").style.top = newY + 20 + 'px';
	document.getElementById("SetPopupId").style.left = newX + 'px';
}



//function ClickFunctionFromGetSet2(){
function ClickFunctionFromGetSet2(ins, ttt, container){
	//	after user press enter when any item is highlighted, then we take the id of that item. the id is 
	// something like XXX\yyyyy\split\12345678. Then we take the just file name
	// which is after "split\" string.
	// we put this value into the search box, that is we complete the intended
	// file name in the search box.
	// document.getElementById("set2AreaId").value=unescape(ins).substring(unescape(ins).indexOf("split")+6);
	// alert("hi");
	// alert(escape(ins));
	filesMouseClick(ins, '6', 't1', 'textFileArea');
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


//	When the user types some keywords into search box on the left column, some subsets are generated with some MeSH term in it.
// When the user clicks on any term in the menu, then the function below is
// called.
// the second parameter ttt is "t7" in this case. this function gives the
// keyword to the AJAX engine. and AJAX gives the
// keyword to a Lucene indexing method in the java class and receives the paths
// of files in which the keywords appear.
function ClickFunctionFromGetSet(ins, ttt, container){
	document.getElementById("setTextArea").value=unescape(ins).replace(/_/g," ");
	loadXMLDoc(ins, ttt, container);
}


//	the function below is used only to highlight the item by changing the class name.
function SetMouseOver(ins){
	ins=unescape(ins);
	document.getElementById(ins).className = "ItemMouseOver";
}


//	the function below is used only to unhighlight the item by changing the class name.
function SetMouseOut(ins){
	ins=unescape(ins);
	document.getElementById(ins).className = "cSetCls";
}


// this method disables the enter key to submit while in the textarea.
function disableEnter() {	
    return false;
}



var isHL2 = false;  // is HighLighted?
var downArrowIter2 = -1;
var setTableExist2 = false;

// this function is called for each number when the user types in the "Search by
// PMID" search box on the left-most column.
// parameter "e" is needed for Mozilla FF browser as a event handler.
// the parameter "ins" is the string that the user types by that time. that is;
// it is the beginning part of the PMID number.
// the parameter "ttt" is "t11" in this case. it is needed so that the JSP calls
// the necessary method from the java class.
// the parameter "container" is "SetPopup2Id" in this case. it is needed so that
// the PMIDs which
// start with "ins" are inserted into that container.

function SetAjax(e, ins, ttt, container,fieldNumber){
	
	//	at the "Search by PMID" search box, the suggestion menu appears after the user types fourth letter.
	
var paramLength;
		if(fieldNumber==1){
		paramLength=2;
		}else if(fieldNumber==2){
		paramLength=2;
		}	
            	
	
	
	
	if(ins.length>paramLength){
		//	the next around 20 lines of code are needed for event handling. So, leave it as it is.		
		if( !e ){
			if(window.event){
				e = window.event; 
			}
			else{ 
				return; 
			} 
		}
		if(typeof(e.which) == 'number'){
			e = e.which; 
		} 
		else{
			if(typeof(e.keyCode) == 'number'){
				e = e.keyCode; 
			} 
			else { 
				if(typeof(e.charCode) == 'number'){ 
					e = e.charCode; 
				} 
				else{ 
					return; 
				} 
			} 
		}

var tableBool;
		var HL;
		var downArrow;
		var divName;	
	        var popUpName;
		var start;var end;	
if(fieldNumber==1){
		tableBool=setTableExist;
			HL=isHL;		
		downArrow=downArrowIter;
		divName="dDivId7";
		popUpName="SetPopupId";
		start="64";
		end="123";
		
		}
		else if(fieldNumber==2){
		tableBool=setTableExist2;
			HL=isHL2;		
		downArrow=downArrowIter2;
		popUpName="SetPopup2Id";
		divName="dDivId72";
		start="47";
		end="57";
	
		}
				
		//	the key code of down arrow key is 40. after user types into search box, the suggestion menu appears. 
		// when user press the down arrow key, we want to highlight the first
		// file name in the suggestion menu.
		// The boolean variable setTableExist2 below is used to make sure the
		// suggestion menu has appeared already.
		// otherwise there would not be any first file name if there was no menu
		// already.
		if(e=="40" && tableBool){
			//	the boolean variable isHL2 stands for "is any file name HighLighted?". if it is not, then we set the 
			// counter (downArrowIter2) to "-1", so that when we increase it by
			// one, it becomes "0", which is the first child.
			if(!HL){ 
				downArrow = -1;
				HL = true;
			}
			//	in order to avoid JS error, when the highlighted file name is the last child of the menu, then when the 
			// down arrow key is pressed, the counter should not be increased.
			// because there is no next child to highlight.
			if(downArrow<document.getElementById(divName).childNodes.length-1){
				//	because there is next child in the menu, so it is safe to increase the counter by one.
				downArrow +=1;
				// we change the class name of the <div> tag. And this is how we
				// highlight a spesific child of menu.
				// We set a different color for that class name in the CSS file.
				document.getElementById(divName).childNodes[downArrow].className = "ItemMouseOver";
			}
			//	when the user press on the arrow key, the next child is highlighted by changing the class name to "ItemMouseOver".
			// Then we need to change the class name of previous child to
			// "cSetCls" again, which it was before highlighted.
			// only exception is that when the counter is "0". because there
			// would not be a previous child to change the class name.
			if(downArrow!="0"){
				document.getElementById(divName).childNodes[downArrow-1].className = "cSetCls";
			}
		}
		else{
			//	the key code of up arrow key is 38. after user types into search box, the suggestion menu appears. 
			// unless the user types the down arrow key, not any child would be
			// highligted, and the counter will be
			// less than "0", which is "-1" in that case.
			// in order to to have the up key to make sense, any item in the
			// menu should have been highlighted already, and
			// that highlighted item should not be first item in the menu.
			if(e=="38" && downArrow>"0"){
				HL = true;
				// after pressing the up arrow key, the current highlighted item
				// is unhighlighted by setting the class name to its
				// orijinal name (cSetCls). then we decrease the counter by one,
				// and highlight that child by changing the class name
				// to "ItemMouseOver".
				document.getElementById(divName).childNodes[downArrow].className = "cSetCls";
				downArrow -=1;
				document.getElementById(divName).childNodes[downArrow].className = "ItemMouseOver";
			}
			else{
				//	if the key code is between 48 and 57, then it is number. The AJAX function does not call the java class unless
				// the typed character is either a number or backspace key
				// (e=="8").
				if((e>start && e<end) || e=="8"){
					//alert("ins="+ins+" ttt= "+ttt+" cont="+container);
					// the AJAX function below calls the "getFilesById" method
					// in the JSP, which in turn calls the "searchByPmidGetPath"
					// method in the java file. that method generates a subset
					// of the all PMID numbers that starts with a given
					// string parameter.
					loadXMLDoc(ins, ttt, container);
					// the user may have highlighted some items already. but
					// when he types another character, then a new menu is
					// generated. therefore "isHL2" should be set to "false",
					// because there is no highlighted item in the new menu.
					HL = false;
				}
				else{
					//	the key code of enter key is 13. after the user highlights any item in the menu, he would want to pick that 
					// item by pressing enter key.
					if(e=="13" && tableBool){
					
						if(HL){
							//	var container = document.getElementById(popUpName);
														
							// container.style.display = "none";
							// at the next two lines, we get the file name from
							// the id (file path), and put it into search box.
							// var
							// buid=document.getElementById(popUpName).childNodes[downArrow].id;
							// document.getElementById("set2AreaId").value=buid.substring(buid.indexOf("outsent"));
							
								// alert("id=
								// "+document.getElementById("dDivId72").childNodes[downArrowIter2].id);
							// the first parameter of the function below is the
							// path of the file (ex;
							// ALLNEOPLASM\Neoplasms\split\12345064).
							// alert(document.getElementById(divName).childNodes[downArrow].id);
							ClickFunctionFromGetSet2(document.getElementById(divName).childNodes[downArrow].innerHTML, "t1", "textFileArea");
							// ClickFunctionFromGetSet2("182\\outsent\\12370358",
							// "t1", "textFileArea");
							// after clicking a file name and inserting its
							// abstract in to web page, the suggestion menu
							// is not needed anymore. So, we find the suggestion
							// menu with PMID numbers, and make it invisible.
								
							
						}
						else{
							//	the user may type all part of a PMID, and then without highlighting it in the menu by either mouse,
							//	or using arrow keys, he may just press enter key. after typing all of it, that PMID will be the first
							// item in the menu. after hitting enter key, we
							// check; if whatever typed is the same with the
							// first item,
							// then we just take whatever typed and continue
							// process with it.
							// after typing enter, if whatever typed is not the
							// same as first item, then the enter key pressed is
							// ignored.
							if(ins==document.getElementById(divName).childNodes[0].id){
								
								loadXMLDoc(ins, "t7", "filesId1");
								var container = document.getElementById(popUpName);
								container.style.display = "none";
							}
						}
					}
				}
			}
		}
	}
	else{
		//	if size of the term typed in the search box is not bigger than 3, then we don't call AJAX function, and keep the 
		// visibility of menu invisible.
		// PABLO: deactivating for test
		// var container = document.getElementById(popUpName);
		// container.style.display = "none";
	}

	if(fieldNumber==1){
		tableBool=setTableExist;
		downArrowIter=downArrow;
		isHL=HL;		
	}
	else if(fieldNumber==2){
			tableBool=setTableExist2;
					isHL2=HL;
			downArrowIter2=downArrow;
	}


}



var isHL = false;  // is HighLighted?
var downArrowIter = -1;
var setTableExist = false;




function giveCoordX(e){
	if(!e){ 
		e = window.event; 
	} 
	if(!e || (typeof(e.pageX) != 'number' && typeof(e.clientX) != 'number')){ 
		return window.alert('Your browser did not pass the required information about the event'); 
	}
	if(typeof(e.pageX) == 'number'){
		var xcoord = e.pageX; 
	} 
	else{
		var xcoord = e.clientX;
		if( !(( window.navigator.userAgent.indexOf('Opera')+1) || (window.ScriptEngine && ScriptEngine().indexOf('InScript')+1 && !document.createElement) || window.navigator.vendor == 'KDE')){
			if(document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)){
				xcoord += document.documentElement.scrollLeft;
			} 
			else if(document.body && (document.body.scrollTop || document.body.scrollLeft)){
			xcoord += document.body.scrollLeft;
			}
		}
	}
	return xcoord;
}


function giveCoordY(e){ 
	if(!e){ 
		e = window.event; 
	} 
	if(!e || (typeof(e.pageX) != 'number' && typeof(e.clientX) != 'number')){ 
		return window.alert('Your browser did not pass the required information about the event'); 
	}
	if(typeof(e.pageX) == 'number'){
		var ycoord = e.pageY; 
	} 
	else{
		var ycoord = e.clientY;
		
		if( !(( window.navigator.userAgent.indexOf('Opera')+1) || (window.ScriptEngine && ScriptEngine().indexOf('InScript')+1 && !document.createElement) || window.navigator.vendor == 'KDE')){
			if(document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft)){
				ycoord += document.documentElement.scrollTop;
			} 
			else if(document.body && (document.body.scrollTop || document.body.scrollLeft)){
				ycoord += document.body.scrollTop;
			}
		}
	}
	return ycoord;
}



var req;
var url;

// this is the AJAX part.
function loadXMLDoc(ins, ttt, container, subj){
	var param = "username=" + unescape(ins);
    Element.show('loading');
    
	if(ttt == "t1") {
		//alert("param :"+ins);
		uri = "XMLGenerator.jsp";
		param = param + "&t1=true"; // param is path, and subj is filename
		// param = param +"&param="+subj;
		// alert("ustte T1 param: "+param);
		// alert("ustte T1 param: "+unescape(ins));
		
	}
	if(ttt == "t2") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t2=true";
		// alert("ustte T2 param: "+param+ "\npopup2Appeared: "+popup2Appeared);
		// // alerts username=Cronates&t2=true
	}
	if(ttt == "t3") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t3=true"; 
		// alert("ustte T3 param: "+param); // alerts username=Lipid&t3=true
	}
	if(ttt == "t4") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t4=true&subj=" + subj; 
		// alert("ustte T4 param: "+param); // alerts
		// username=isa&t4=true&subj=Lipid
	}
	if(ttt == "t5") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t5=true"; 
		// alert("ustte T5 param: "+param); // alerts username=Hormone&t5=true
	}
	if(ttt == "t6") { 	// this get the instance name from 4th popup menu and returns file paths
		uri = "XMLGenerator.jsp";
		param = param + "&t6=true"; 
		// alert("T6 param: "+param); // alerts username=17_Ketostroids&t6=true
	 
	}
	if(ttt == "t7") { 		// This gets instance name from left column and returns file paths
		uri = "XMLGenerator.jsp";
		param = param + "&t7=true"; 
		// alert("ustte T7 param: "+param);
	}
	if(ttt == "t8"){			//	this is called from SetAjax function. gets first letters of keyword and returns instance names.
		uri = "XMLGenerator.jsp";
		param = param + "&t8=true"; 
		// alert("ustte T8 param: "+param);
	}
	if(ttt == "t9") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t9=true"; 
		// alert(param);
	}
	if(ttt == "t10") { // This gets Pmid number and returns file paths
		uri = "XMLGenerator.jsp";
		param = param + "&t10=true"; 
		// alert(param);
	}
	if(ttt == "t11") { // This gets Pmid number and returns file paths
		uri = "XMLGenerator.jsp";
		param = param + "&t11=true";
		// alert(param);
		// alert(ins);
	}
	if(ttt == "t12") { 
		uri = "XMLGenerator.jsp";
		param = param + "&t12=true"; 
		// alert(param);
	}
	
	// Add the selectedDB parameter	
	param = param + "&databaseid=" + getSelectedDB() + "&navtype=" + getSelectedNavType();
	//alert('param:'+param);
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } 
        catch(e) {
			req = false;
 		} 
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) {
   		try {
    		req = new ActiveXObject("Msxml2.XMLHTTP");
  		} 
  		catch(e) {
    		try {
      			req = new ActiveXObject("Microsoft.XMLHTTP");
    		} 
    		catch(e) {
      			req = false;
    		}
		}
	}
    if(req) {
		req.onreadystatechange = function () {       
			processReqChange(container, ttt);
		};
	       	   
		req.open("POST", uri, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(param);
	}
}


//DELROY: changes to accomodate div swapping 
function processReqChange(container, ttt) {
	Element.hide('loading');
	
	if(req.readyState == 4){
		if(req.status == 200){
			if (ttt == 't1'){			
				var newObj = req.responseText;
				
				//DELROY:  
				if(document.getElementById("page") != null){ //HACK: for keyword search
					var temp = baseDoc;
					var parent = baseDoc.parentNode; 
					var deleteClassName = "abstract"; 
					if(parent.firstChild.className.substring(0,9) != deleteClassName){ //for navigation search
						baseDoc = document.getElementById(baseDoc.id); //reset base document
						addAnotherChildNode(newObj);// create a new div, and keep or delete it
						ssx = temp.getElementsByTagName('span');
					}else{ //insert for second keyword search
						baseDoc = document.getElementById(baseDoc.id); 
						addAnotherChildNode(newObj);
						ssx = temp.getElementsByTagName('span');
					}
					closeMenu();//close the main menu
				}else{ //for triple search
					var parent = document.getElementById("textFileArea");
					parent.innerHTML = str;
					baseDoc = parent.firstChild;  
					ssx = baseDoc.getElementsByTagName('span');
				} 	
			}
 			
			if (ttt == 't2'){ 
				//alert("en altta js de: "+req.responseText);
				BuildMenu(req.responseXML);
			}
			if (ttt == 't3'){ 
				//alert("en altta T3 : "+req.responseText);	// this returns relations					
				FindSubMenu2(req.responseXML);
			}
			if (ttt == 't4'){ 
				//alert("en altta T4 : "+req.responseText);		// this returns objTypes
				FindSubMenu3(req.responseXML);
			}
			if (ttt == 't5'){ 
				//alert("en altta T5 : "+req.responseText);	// this returns objInstances
				// FindSubMenu4(req.responseXML);
			}
			if (ttt == 't6'){ 
				//alert("en altta T6 : "+req.responseText);	// this returns File Names from Lucene
				createFilesMenu(req.responseXML);
			}
			if (ttt == 't7'){ 
				//alert("en altta T7 : "+req.responseText);	// this returns File Names from Lucene
				FindSubMenu6(req.responseXML);
			}
			if (ttt == 't8'){ 
				//alert("en altta T8 : "+req.responseText);	// gets first letters of keyword and returns instance names.
				GetSet(req.responseXML);
			}
			if (ttt == 't9'){ 
				//alert("en altta T9 : "+req.responseText);	// this returns file abstract from JSP
				GetDet(req.responseXML);
			}
			if (ttt == 't10'){ 
				//alert("en altta T10 : "+req.responseText);	// this returns file abstract from JSP
				getPmidReturnAbs(req.responseXML);
			}
			if (ttt == 't11'){ 
				//alert("en altta T11 : "+req.responseText);	// this returns file names to put into PopupSet2
				GetSet2(req.responseXML);
			}
			if (ttt == 't12'){ 
				//alert("en altta T12 req.responseText= "+req.responseText);	// this returns file abstract from JSP
				buildSubMenu5FromHist(req.responseXML);
			}
			if (ttt == 't13'){ 
				
			}
		
		} 
		else 
		{
			alert("There was a problem retrieving the XML data:\n" + req.statuspanText);
		}
	}
}

function issueRating(ratetripleid, ratetype, ratevalue, selectedDB, selectedNavType) { 
	var param = "ratetripleid=" + ratetripleid +
		 "&ratetype=" + ratetype + 
		 "&ratevalue=" + ratevalue +
		 "&databaseid=" + selectedDB + 
		 "&navtype=" + selectedNavType;
		
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } 
        catch(e) {
			req = false;
 		} 
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) {
    	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} 
      	catch(e) {
        	try {
         		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} 
        	catch(e) {
          		req = false;
        	}
		}
   	}
	
	if(req) {
			req.open("POST", apiUrl, true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.send(param);
		}
}


function getSelectedDB() {
	var selectedNum;
	// DELROY: HACK: modified
	if(document.getElementById('dbSelector').tagName == "SELECT"){
		//return "bioinfer";
		return "umls";
	}else{
		if(document.dbSelector.selectedDB.length == null)
			return document.dbSelector.selectedDB.value;
		
		for (i=0;i<document.dbSelector.selectedDB.length;i++){
			if (document.dbSelector.selectedDB[i].checked==true)
				selectedNum=i
		}
	return document.dbSelector.selectedDB[selectedNum].value;
	}
}

function getSelectedNavType() {
	var selectedNum;
	// DELROY: HACK: modified
	if(document.getElementById('navTypeSelector').tagName == "SELECT"){
		return "dependencies";
	}else{
		if(document.navTypeSelector.selectedNavType.length == null)
			return document.navTypeSelector.selectedNavType.value;
		
		for (i=0;i<document.navTypeSelector.selectedNavType.length;i++){
			if (document.navTypeSelector.selectedNavType[i].checked==true)
				selectedNum=i
		}
	}
	return document.navTypeSelector.selectedNavType[selectedNum].value;
}

function populateSelectDBSection() {
	
	if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) { } 
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
    	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
         		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} 
        	catch(e) { }
		}
   	}
	
	if(req) {
		req.onreadystatechange = function(){ populateSelectDBSectionCallback() };
		req.open("POST", apiUrl, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send("t14=true");
	}
}

function populateSelectDBSectionCallback() {
	if(req.readyState == 4) {
		if(req.status == 200) {
			var databases = req.responseXML.getElementsByTagName('database');
			
			for(var i = 0; i < databases.length; i++) {
				var database = databases[i].childNodes[0].nodeValue;
				
				if(i == 0) {
					$('dbSelector').innerHTML = database + ": <input type=\"radio\" name=\"selectedDB\" value=\"" + database + "\" checked=\"\"><br />";
				} else {
					$('dbSelector').innerHTML += database + ": <input type=\"radio\" name=\"selectedDB\" value=\"" + database + "\"><br />";
				}
			}
			
			req = false;
			populateSelectNavTypeSection();
		}
	}
}

function populateSelectNavTypeSection() {
	if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) { } 
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
    	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
         		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} 
        	catch(e) { }
		}
   	}
	
	if(req) {
		req.onreadystatechange = function(){ populateSelectNavTypeSectionCallback() };
		req.open("POST", apiUrl, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send("t15=true&databaseid=" + getSelectedDB());
	}
}

function populateSelectNavTypeSectionCallback() {
	if(req.readyState == 4) {
		if(req.status == 200) {
			var navtypes = req.responseXML.getElementsByTagName('navtype');
			
			for(var i = 0; i < navtypes.length; i++) {
				var navtype = navtypes[i].childNodes[0].nodeValue;
				
				if(i == 0) {
					$('navTypeSelector').innerHTML = navtype + ": <input type=\"radio\" name=\"selectedNavType\" value=\"" + navtype + "\" checked=\"\"><br />";
				} else {
					$('navTypeSelector').innerHTML += navtype + ": <input type=\"radio\" name=\"selectedNavType\" value=\"" + navtype + "\"><br />";
				}
			}
			
			req = false;
		}
	}
}

//DELROY: determines whether to add a new abstract to the workbench or not
function addAnotherChildNode(newObj){

	var temp = document.createElement("div");
	$(temp).insert(newObj);
	var nodes = $(temp).childElements();
	for(var i=0;i<nodes.length;i++){
		var node = nodes[i];
		if(document.getElementById(node.id) != null){ // if div exists then do not duplicate it	
			//alert("Sentence with id: " + node.id + " already exists in the SERP");
			baseDoc.className = baseDoc.className.replace(/-ext/g, "");
			baseDoc.className = baseDoc.className+"-ext"; //previously visited div
			document.getElementById(node.id).style.background = "#ffffdd";
			document.getElementById(node.id).style.border = "1px solid";
		}else{
			if(node.className == "Tabstract"){ //HACK: must fix with prototype
				node.className = "keyabstract";
			}else if(node.className == "keyabstract"){   
				node.className = "abstract";
			}else if(node.className == "bookmarkedabstract"){   
				node.className = "abstract";
			}else{
				node.className = "rel"+node.className;
			}
			//insert new node
			$(baseDoc).insert({'after': node});
			
			var tempTrail = document.getElementById("T"+node.id); //position temp trail info
			if(tempTrail != null){
				//alert(trail.className.substring(0,3));
				if(node.className.substring(0,3) == "rel"){
					tempTrail.innerHTML = baseDoc.id + " > " + entityOneName + " > " + relationName + " > " + entityTwoName + " > " + node.id;
					tempTrail.style.visibility = "visible";
					//tempTrail.style.border = "2px";
				}else{
					tempTrail.innerHTML = baseDoc.id + " > " + entityOneName + " > " + node.id;
					//tempTrail.style.background = "#777777";
					tempTrail.style.color = "#2647a0";
					tempTrail.style.visibility = "visible";
				}
			}
			node.style.border = "1px dotted #666666";
			updateTrails();
		}
	}//end for
}
//TODO: replace with prototype
//DELROY: remove all children of a div from the textarea, then remove the node itself 
function closeDIV(divToClose){
	var dtc = document.getElementById(divToClose);
	var dtcParent = dtc.parentNode;
	if((dtc != null) && (dtcParent != null)){
		var children = dtcParent.getElementsByTagName('div');
		for(i=0; i<children.length; i++){	
			//found div to close
			if(children[i].id == divToClose){ 	
				//remove all children
				while (document.getElementById(children[i].id).hasChildNodes()) { 
					document.getElementById(children[i].id).removeChild(document.getElementById(children[i].id).firstChild);
				 }//end while
				document.getElementById(children[i].id).parentNode.removeChild(children[i]);
			}//end if		
		}//end for
		marker--;
	}//end if
}//end 

//DELROY: code to promote or demote a div (later we may consider using yui)
function promoteDemoteDIV(divToPromote, promote){
	var dtp = document.getElementById(divToPromote);
	//HACK: (delroy) to fix class name
	dtp.className = dtp.className.replace(/-ext/g, "");
	dtp.className = dtp.className+"-ext";
	var dtpParent = dtp.parentNode;
		
	if((dtp != null) && (dtpParent != null)){
		var children = $(dtpParent).childElements();
		for(var i=0;i<children.length;i++){
			if(i==marker){
				$(children[i]).insert({'before': dtp});
				break;
			}//end if
		}//end for
		marker++;
		dtp.style.background = "#ffffdd";
		dtp.style.border = "1px solid";
		
		//disable the promote button
		
		($(dtp).getElementsByClassName("divPromote")[0]).disabled=true;
		
	}//end if 
}//end 

//DELROY: the workbench function allows the users to saves the current state of 
// the result list to an html file
function viewWorkbench(){
	var uri = "view.jsp";
	var theTrail = document.getElementById("textFileArea");
	var children = theTrail.getElementsByTagName('div');
	var param="";
	var end = 1;
	for(i=0; i<children.length; i++){	
		if(children[i].id=="")
			continue;
		if(document.getElementById(children[i].id).className == "GeneRif")
			continue;
		param = param + children[i].id+",";
		if(end==10)break; //display top ten results
		end++;
	}//end for
		
	param = param.substring(0,param.length-1);
	//alert(param);
	var workbenchForm = document.createElement("form");
	workbenchForm.setAttribute("id", "workbenchForm");
	var hiddenInput = document.createElement("input");
	hiddenInput.setAttribute("type", "hidden");
	hiddenInput.setAttribute("name", "ids");
	hiddenInput.value=param;
	
	var db = document.getElementById("dbSelector");
	var dbHidden = document.createElement("input");
	dbHidden.setAttribute("name", "databaseid");
	dbHidden.value = document.getElementById("dbSelector").value;
	
	var nt = document.getElementById("navTypeSelector");
	var ntHidden = document.createElement("input");
	ntHidden.setAttribute("name", "navtype");
	ntHidden.value = document.getElementById("navTypeSelector").value;
	
	workbenchForm.appendChild(hiddenInput);
	workbenchForm.appendChild(dbHidden);
	workbenchForm.appendChild(ntHidden);
	
	document.body.appendChild(workbenchForm);
	
	document.getElementById("workbenchForm").action = uri;
	document.getElementById("workbenchForm").submit();
		
}

//DELROY: the set form function sets the input to keyword or triple search
function setForm(formName){
	document.getElementById('page').innerHTML=formName;
	if(formName == "tripleSearch"){
		document.getElementById('keywordInput').value = "";
	}else{
		document.getElementById('subjectInput').value = "";
		document.getElementById('predicateInput').value = "";
		document.getElementById('objectInput').value = "";
	}
}

//DELROY: this function implements a show hide feature on the trails
function showTrails(){
	
	var histContainer = document.getElementById("histAreaClsID");
	var container = document.getElementById("histAreaId");
	var containerHeader = document.getElementById("histHeader");
	var theAction = document.getElementById("showHideTrailsID"); 
	
	if(theAction.innerHTML=='Show Trails'){	//HACK: This is dangerous coding here, but will allow for now
		container.innerHTML = allTrails;
		container.style.display = "block";
		container.style.visibility = "visible";
		containerHeader.style.visibility = "visible";
		histContainer.style.visibility = "visible";
		containerHeader.style.width = "550px";
		theAction.innerHTML = "Hide Trails";
		append = true;
	}else if(theAction.innerHTML=='Hide Trails'){
		allTrails = container.innerHTML;
		container.innerHTML = "";
		container.style.visibility = "hidden";
		containerHeader.style.visibility = "hidden";
		histContainer.style.visibility = "hidden";
		containerHeader.style.width = "0px";
		theAction.innerHTML = "Show Trails";
		append = false;
	}
}//end 

//DELROY: update trail to append new trail to trail list regardless
//of whether trail is visible of hidden. 
function updateTrails(){
	if(trail != null){
		allTrails = allTrails + trail.innerHTML;
		if(append){
			document.getElementById("histAreaId").innerHTML = allTrails;
		}//end if
	}//end if
}

//DELROY: the menu function creates the context menu
function menu(e){
	
	if(!deactivateSpanTags){
		var target = getTargetElement(e);
		var parent = target.parentNode.parentNode;
		baseDoc = parent;
		var mainmenu = document.getElementById("mainmenuId");
		mainmenu.innerHTML = "";
		
		var menuHeader = document.createElement("div");
		menuHeader.className="cHeaderCls";
		menuHeader.setAttribute("id","mh");
		menuHeader.appendChild(document.createTextNode("Context Menu"));
		menuHeader.style.display = "block";
		
		var menuBody = document.createElement("div");
		menuBody.className="menuBodyCls";
		var relImage = document.createElement("img");
		relImage.className = "divLikeAnchor";
		relImage.setAttribute("src", "img/direction.jpg");
		relImage.onmouseover = new Function("spanHover(arguments[0],'"+target.id+"','t2','PopupId1','"+parent.id+"');");
	
		var entityID = document.createElement("span");
		entityID.innerHTML = "EntityID: " + parent.id + "<br/>";
		entityID.style.font = "bold";
		entityID.style.margin = "";
		var meshDesc = document.createElement("span");
		meshDesc.innerHTML = "MeshID: <br/>";
		meshDesc.style.font = "bold";
		
		var breakTag = document.createElement("br");
		var pTag = document.createElement("p");
		var hrTag = document.createElement("hr");
				
		var newKeywordSearch = document.createElement("span");
		newKeywordSearch.innerHTML = "More results about ";
		var kword = document.createElement("span");
		kword.className = "divLikeAnchor";
		//kword.innerHTML = target.id;
		var keyword = target.innerHTML;
		kword.innerHTML = keyword;
		//alert('1');
	
		kword.onclick = new Function("doKeywordSearch('"+keyword+"');"); 
		//newKeywordSearch.appendChild(kword);
		
		var relations = document.createElement("span");
		relations.onmouseover = new Function("spanHover(arguments[0],'"+target.id+"','t2','PopupId1','"+parent.id+"');");
		var relationMsg = document.createTextNode("Explore relations: ");
		relations.appendChild(relationMsg);
		relations.className = "pushPin";
		
		entityOneName = keyword; 
		
		menuBody.appendChild(entityID);
		menuBody.appendChild(meshDesc);
		menuBody.appendChild(hrTag);
		menuBody.appendChild(newKeywordSearch);
		menuBody.appendChild(kword);
		menuBody.appendChild(pTag);
		menuBody.appendChild(relations);
		menuBody.appendChild(relImage);

		mainmenu.appendChild(menuHeader);
		mainmenu.appendChild(menuBody);
		
		mainmenu.style.top = giveCoordY(e) + 'px';
		mainmenu.style.left = giveCoordX(e) + 15 + 'px';
		mainmenu.style.visibility = "visible";
		
		deactivateSpanTags = true;
		deactivator = true;
		closeMM = true;
		
		mainmenu.onclick = new Function("closeMenu()");

	}
}

//DELROY: close the popup menu
function closeMenu(){
	removeMenu();
	deactivator = false;
	deactivateSpanTags = false;
}

//DELROY: remove the popup menu from the dom tree
function removeMenu(){
	var menuItem = document.getElementById("mainmenuId");
//	alert(menuItem.id);
	if(menuItem != null){
		menuItem.innerHTML = "";
		menuItem.style.visibility = "hidden";
	}//end if
}

//DELROY: target element that triggered this event	
function getTargetElement(e){
	var e = e || window.event; // event object
	var target = e.target || window.event.srcElement; // event target
	return target;
}

//DELROY: this method is called when the popup menu shows up and the user selects a keyword search
function doKeywordSearch(keyword){

	uri = "XMLGenerator.jsp";
	var container = document.getElementById("textFileArea");
	var ttt = "t1";
	//DELROY: add double quotes to keyword if more than one word so we can search complex entities
	if(keyword.split(" ").length > 1){
		keyword = "\""+keyword+"\"";
	}//end if
	
	var param = "username=" +keyword;
	param = param + "&t9=true";
	param = param + "&databaseid=" + getSelectedDB() + "&navtype=" + getSelectedNavType();
	
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } 
        catch(e) {
			req = false;
 		} 
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) {
   		try {
    		req = new ActiveXObject("Msxml2.XMLHTTP");
  		} 
  		catch(e) {
    		try {
      			req = new ActiveXObject("Microsoft.XMLHTTP");
    		} 
    		catch(e) {
      			req = false;
    		}
		}
	}
	if(req) {	
		req.onreadystatechange = function () { processReqChange(container, ttt); };
		req.open("POST", uri, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(param);
	}
	//close main menu
	closeMenu();
}

//DELROY: show dom elements only after page load
function showDomObjects(){
	document.getElementById("main-containerID").style.visibility = "visible";
	document.getElementById("copyrightID").style.visibility = "visible";
}

//DELROY: add or remove an abstract from the bookmark array
function addRemoveBookmarkItem(e, pmid){
	var obj = document.getElementById(pmid); 
	var target = getTargetElement(e);
	if($(target).src.endsWith("/img/unlock.gif")){
		bookmarkArray.push(obj);
		obj.className = "bookmarkedabstract";
		target.setAttribute("src", "img/lock.gif");
	}else{
		var startPos = $(bookmarkArray).indexOf(obj);
		if(bookmarkArray.length == 1){
			bookmarkArray = new Array();
		}else{
			bookmarkArray.splice(startPos, 1);
		}
		target.setAttribute("src", "img/unlock.gif");
	}
}//end

//DELROY: this is too much code duplication, but at the moment seems like a feasible approach
//the loadSnippetXML method queries the index for the abstract of the document with the file
//being hovered. 
function loadSnippetXML(fileId){
	
	//loadXML
	uri = "XMLGenerator.jsp";
	var param = "username=" +fileId;
	param = param + "&t1=true";
	param = param + "&databaseid=" + getSelectedDB() + "&navtype=" + getSelectedNavType();
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
    		req = new XMLHttpRequest();
        } 
        catch(e) {
        	req = false;
 		} 
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) {
   		try {
   			req = new ActiveXObject("Msxml2.XMLHTTP");
  		} 
  		catch(e) {
    		try {
    			req = new ActiveXObject("Microsoft.XMLHTTP");
    		} 
    		catch(e) {
    			req = false;
    		}
		}
	}
	if(req) {	
		req.onreadystatechange = function () { createSnippet(fileId); };
		req.open("POST", uri, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(param);
	}
}

//DELROY: the createSnippet function creates a div to show a snippet of the document hovered over
function createSnippet(fileId){
	if(req.readyState == 4){
		if(req.status == 200){
			var newObj = req.responseText;
			var file = document.getElementById(fileId);
			
			var className = "snippet";
			var snippet = document.getElementById("snippetId");
			snippet.className = className;
			
			snippet.style.visibility = "visible";
			snippet.style.top = findPosY(file)+5;
			snippet.style.left = findPosX(file)-340;
			$(snippet).insert(newObj);
			
			//DELROY: HACK: will use getElementsByTagName("img")..was breaking
			$(snippet).getElementsByClassName("divPromote")[0].style.visibility = "hidden";
			$(snippet).getElementsByClassName("divClose")[0].style.visibility = "hidden";
			$(snippet).getElementsByClassName("pushPin")[0].style.visibility = "hidden";
			$(snippet).getElementsByClassName("pushPin")[0].style.visibility = "hidden";
			$(snippet).getElementsByClassName("GeneRif")[0].className = className+"-content";
			
			//var tempTrail = "Trail: "+ baseDoc.id + " > " + entityOneName + " > " + relationName + " > " + entityTwoName + " > " + "ABS"+fileId;
			var tempTrail = "Trail:	" + entityOneName + " > " + relationName + " > " + entityTwoName + " >";
			tempTrail.className = className;
			
			snippet.appendChild(document.createTextNode(tempTrail));
			snippet.appendChild(document.createElement("p"));
						
		}//end if
	}//end if
}
