/**
*	This function called from the XML/PDF/IPC documents
*/
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;
function openLinkDoc(a_DocID, a_Unit, a_Part)
{
	var props = new Object();

	var docID = a_DocID;
	var index=a_DocID.indexOf("(^)");
	if(index!=-1)
		docID = a_DocID.substring(0,index)+"#"+a_DocID.substring(index+3,a_DocID.length);
	props.docId="Document(storage=REPOSITORY,docID=" + docID + ")";

	if (arguments.length > 1 && arguments[1]!='null')
	{
		props.unitname=a_Unit;
	}

	if(arguments.length > 2 && arguments[2]!=null && arguments[2]!="undefined")
	{
		props.itemNumber=a_Part;
	}

	props.locSource="input";
	props.docLoc=docID;

	if(queryID != "null")
	{
		props.queryId=queryID;
		props.page=pageNbr;
	}

	URLUtil.openLinkUnified("GetDocument.do", props);
}

// example: openMultiLinkDoc([{ref:'$REP_ROOT$(^)node-id(98)',title:'Toyota Corolla CE'}]);
// a_links: array of objects with 2 members: title and ref (href syntax is equals to the same parameter in openLinkDoc()
function openMultiLinkDoc(a_links)
{
	if(ns6) //if browser is NS6 and above use other function
	{
		openMultiLink_NS(a_links);
	}
	else
	{

		var oMultiLinkPopup = window.createPopup();
		var maxLinksShow =a_links.length;
		var height = maxLinksShow*20;
		if(maxLinksShow>10)	//max 10 item will be shown ,for the rest use scroll bar
			maxLinksShow=10;
		var Context="<DIV style='HEIGHT:"+height+"px;color:#000000;background:#FFFFFF; OVERFLOW: scroll; overflow-x:auto; border:1px solid black;'>";

		//input string format: {multiTarget:'same',singleTarget:'same',linksTargets:['TargetID1','TargetTitle1','TargetID2','TargetTitle2','']}
		// last element is empty string (work around for some xsl problem, we shouldn't deal with it
		for(var i=0; i<a_links.length; i++)
		{
			Context += "<DIV  onmouseover=\"this.style.background = \'#E7EFF7\'\" onmouseout= \"this.style.background = \'#FFFFFF\'\"";
			Context += " style=\"overflow: hidden;font-family:tahoma;font-size:11px; padding:3px; cursor:hand;\"";
			Context += " TITLE='"+a_links[i].title+"' ONCLICK='parent.openLinkDoc(\"";
			Context += a_links[i].ref+"\")'>"+a_links[i].title+"</DIV>";
		}
		Context+="</DIV>";
		oMultiLinkPopup.document.body.innerHTML = Context;
		oMultiLinkPopup.show(15, 20, 250,height ,event.srcElement);
		event.cancelBubble = true;

	}
}


// example: openMultiLinkDoc([{ref:'$REP_ROOT$(^)node-id(98)',title:'Toyota Corolla CE'}]);
// a_links: array of objects with 2 members: title and ref (href syntax is equals to the same parameter in openLinkDoc()
//This function is for Netscape only, It creates a popUp Div insted of the popup Window
function openMultiLink_NS(a_links)
{
	var popupDiv = document.getElementById("multiLinkDiv");			//get the popup div
	var top = (self.pageYOffset + self.innerHeight/2) + "px" ;		//get popDiv top position
	var left = (self.pageXOffset + (self.innerWidth-250)/2)+"px" ;		//get popDiv leftPosition

	//find the height of the popDiv
	var maxLinksShow =a_links.length;
	var height = maxLinksShow*20 + "px";

	if(popupDiv==null)			//if no popDiv defined - create one
	{
		var oMultiLinkPopup = document.createElement("DIV");
		oMultiLinkPopup.id = "multiLinkDiv";
		oMultiLinkPopup.style.visibility = "hidden";
		oMultiLinkPopup.style.width = "250px";
		oMultiLinkPopup.style.zIndex=0;
		oMultiLinkPopup.style.position="absolute";
		document.body.appendChild(oMultiLinkPopup);
		popupDiv = oMultiLinkPopup;
	}
	//check if the same link was clicked than hide the popDiv
	else if(popupDiv.style.visibility=="visible" && popupDiv.style.top==top
						     && popupDiv.style.left==left
						     && popupDiv.style.height==height)
	{
		popupDiv.style.visibility="hidden";
		return;
	}

	//set Div's position and height
	popupDiv.style.height = height;
	popupDiv.style.top = top;
	popupDiv.style.left = left;


	if(maxLinksShow>10)	//max 10 item will be shown ,for the rest use scroll bar
		maxLinksShow=10;
	//build div's content
	var Context="<DIV style='HEIGHT:"+height+"px;color:#000000;background:#FFFFFF; overflow:auto; border:1px solid black;'>";
	Context+="<a href=\"javascript:closePopup();\"><img src=\"Images/closed.gif\"></a>";

	//input string format: {multiTarget:'same',singleTarget:'same',linksTargets:['TargetID1','TargetTitle1','TargetID2','TargetTitle2','']}
	// last element is empty string (work around for some xsl problem, we shouldn't deal with it
	for(var i=0; i<a_links.length; i++)
	{
		Context += "<DIV  onmouseover=\"this.style.background = \'#E7EFF7\'\" onmouseout= \"this.style.background = \'#FFFFFF\'\"";
		Context += " style=\"overflow: hidden;font-family:tahoma;font-size:11px; padding:3px; cursor:hand;\"";
		Context += " TITLE='"+a_links[i].title+"' ONCLICK='parent.openLinkDoc(\"";
		Context += a_links[i].ref+"\")'>"+a_links[i].title+"</DIV>";
	}
	Context+="</DIV>";
	popupDiv.innerHTML = Context;
	popupDiv.style.visibility = "visible"; //show div
}


function closePopup()
{
	document.getElementById("multiLinkDiv").style.visibility="hidden";
}

