// Revision: change ViewAsPDF() to view PDF file pre-exisitng on FileSystem
//            Instead of generating it on the fly (too slow)
//            08/31/05  Lih
//view as pdf funtion
function ViewAsPDF(pdfFileUrl)
{
	//var	locString="ViewAsPDF.do?docId=" + escape(a_docID)+"&popup=true";
	//window.open(locString);
	var reg = /\s|,|\'|\&/g;
	pdfFileUrl = pdfFileUrl.replace(reg, "");

// changed pdf for entire manual to open in new window for Release 2. RS
//	window.location.href = pdfFileUrl;
	window.open(pdfFileUrl, null, "height=600,width=800, resizable=yes", null);
}


//get Next Chunk function
function nextChunk(a_isNext,a_docClass,a_docID,a_showHits,a_nextPosition,a_queryID,a_pageNumber,a_hits)
{
	//if there is next chunk

	if(a_isNext=="true")
	{
		//prepare document properties
		var props = new Object();
		if(a_docClass != "null")	// if request has meaningful URL ... pass it on
			props.docClass = "<%=docClass%>";
		props.docId     = a_docID;
		props.locSource = "output";
		props.showHits  = a_showHits;
		props.chunkDir  = "next";
		props.docLoc    = a_nextPosition;
		props.hits		= a_hits;
		if(queryID != "null")
		{
			props.queryId  = a_queryID;
			props.page     = a_pageNumber;
		}

		//get next chunk
		URLUtil.openLinkUnified("GetDocument.do", props);
	}
}

//get Previous Chunk function
function prevChunk(a_isPrev,a_docClass,a_docID,a_showHits,a_prevPosition,a_queryID,a_pageNumber,a_hits)
{
	//if there is previous chunk

	if(a_isPrev=="true")
	{
		//prepare document properties
		var props = new Object();
		if(a_docClass != "null") // if request has meaningful URL ... pass it on
		{
			props.docClass = a_docClass;
		}
		props.docId       = a_docID;
		props.locSource = "output";
		props.showHits  = a_showHits;
		props.chunkDir  = "prev";
		props.docLoc    = a_prevPosition;
		props.hits		= a_hits;
		if(a_queryID != "null")
		{
			props.queryId   = a_queryID;
			props.page      = a_pageNumber;
		}

		//get previous chunk
		URLUtil.openLinkUnified("GetDocument.do", props);
	}
}


//get entire document function
function getEntireDoc(a_docID, a_showHits, a_docClass, a_queryID, a_pageNbr)
{
	var props = new Object();

	props.docId = a_docID;
	props.showHits = a_showHits;
	props.locSource="input";

	//define a large chunk that should contain the entire document
	props.chunkSize="5000000";

	if(a_docClass != "null") // if request has meaningful URL ... pass it on
	{
		props.docClass = a_docClass;
	}

	if(a_queryID != "null")
	{
		props.queryId = a_queryID;
		props.page = a_pageNbr;
	}

	//get entire document
	URLUtil.openLinkUnified("GetDocument.do", props);
}


// Support for the Horizontal Toc navigation (disabled)
function nextDoc(a_canonicalId)
{
		var url = "GetHorizontalDocument.do?dir=forward&curNode="+escape(a_canonicalId);
		url = URLUtil.getVerifiedUrl(url,version);
		document.location = url;
}

function prevDoc(a_canonicalId)
{
		var url = "GetHorizontalDocument.do?dir=backward&curNode="+escape(a_canonicalId);
		url = URLUtil.getVerifiedUrl(url,version);
		document.location = url;
}

<!-- nextHit and PrevHit handlers -->
function nextHit(a_docClass, a_docId, a_nextHit, a_queryID, a_pageNbr, a_version, a_hits)
{
	gotoHit(a_docClass, a_docId, a_nextHit, a_queryID, a_pageNbr, a_version, a_hits)
}

function prevHit(a_docClass, a_docId, a_prevHit, a_queryID, a_pageNbr, a_version, a_hits)
{
	gotoHit(a_docClass, a_docId, a_prevHit, a_queryID, a_pageNbr, a_version, a_hits)
}

function gotoHit(a_docClass, a_docId, a_hit, a_queryID, a_pageNbr, a_version, a_hits)
{
	var url = "GetDocument.do?";
	if(a_docClass != "null")	// if request has meaningful URL ... pass it on
	{
		url += "docClass=" + a_docClass + "&";
	}

	url += "docId=" + escape(a_docId);
	url += "&showHits=true";
	url += "&focusHit=" + a_hit;
	url += "&hits=" + a_hits

	url += "&queryId="+a_queryID+"&page="+a_pageNbr;
	url = URLUtil.getVerifiedUrl(url,a_version); // add version control

	document.location = url;
}

function openDocClearSearch() {

	isSearchCleared = true;
	document.getElementById("HitsNoTable").style.visibility="hidden";
	var elements = document.getElementsByTagName('span');
	removeHighlight(elements);
}

function removeHighlight(a_elements) {

	for(var i = 0; i < a_elements.length; i++){
		var node = a_elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == 'highlight') {
					eval('node.className="nohighlight"');					
				}
			}
		}
	}
}

