//<script language="javascript">
// Author:		Colin Turner
// Date:		12 Sep 2003
// Purpose:		JavaScript for the Knowledge Library Results page
//
// Change History:
// Date			Author			Comments
// 16 Oct 2003	Colin Turner	Bug 5452 Added function showAccessRights
// 05 Nov 2003	Colin Turner	Moved some functions to SupportCommon.js
// Feb 2004		Donna Coles		Changes to make generic
// 06 Dec 2004	Colin Turner	Removed function to view RM Equip file
// 16 Nov 2005	Simon Hewerdine showSummary now tolerates missing divs.
//								Aded new functions for SOL KL Search makeover.
//								Changes some var names to meet standards
// 10 Jan 2006	Simon Hewerdine Added searchwithin support.  
//								Made event handlers cross browser tolerant
// 24 Feb 2006	Simon Hewerdine Add unapproved option handling

function showSummary(pbOn, pbInformParent) {
	
	var aDivArray;
	
	// Record the value in the parent document.
	if(pbInformParent==true) {
		top.showSummary(pbOn);
	}
	
	if (pbOn) {
		if(document.getElementById('divHide')) {
			document.getElementById('divHide').style.display = "inline";
		}
		if(document.getElementById('divShow')) {
			document.getElementById('divShow').style.display = "none";
		}
		
		aDivArray = document.getElementsByTagName('div');
				
		for (var numDiv = 0; numDiv < aDivArray.length; numDiv++) {	
			if(aDivArray[numDiv].id.substr(0,9)=='divResult') {
				aDivArray[numDiv].style.display = "block";
			}
		}
	}
	else {
		if(document.getElementById('divHide')) {
			document.getElementById('divHide').style.display = "none";
		}
		if(document.getElementById('divShow')) {
			document.getElementById('divShow').style.display = "inline";
		}
		
		aDivArray = document.getElementsByTagName('div');
				
		for (var numDiv = 0; numDiv < aDivArray.length; numDiv++) {	
			if(aDivArray[numDiv].id.substr(0,9)=='divResult') {
				aDivArray[numDiv].style.display = "none";
			}
		}		
	}
}

function tabSelect(pstrTabID, pstrDivID)
{

	// Make the correct div visible
	var aDivArray = document.getElementsByTagName('div');
				
	for (var numDiv = 0; numDiv < aDivArray.length; numDiv++) {	
		if(aDivArray[numDiv].id.substr(0,7)=='divData') {
			if (aDivArray[numDiv].id == pstrDivID) {
				aDivArray[numDiv].style.display = "inline";
			}
			else {
				aDivArray[numDiv].style.display = "none";
			}
		}
	}		
	
	// Select the required tab
	var strCurrentTabID = document.frmKLResults.inpCurrentTab.value;

	if (pstrTabID == strCurrentTabID) strCurrentTabID='';

	// highlight newly selected tab
	showTabXP(pstrTabID, strCurrentTabID);

	// reset to new TabID
	document.frmKLResults.inpCurrentTab.value = pstrTabID;
}

function submitKLSearch2(pstrSearchType,bSortByDate) {
	
	var strContentCatTypes = ''; 
	var strContentTypes = '';
	var strPreview = '';
	var oReContentRef;
		
	var strSearchString = document.frmKLSearch.inpSearchString.value.trim();
	
	// perform basic validation
	if (pstrSearchType == 'SERIALNOSEARCH') {
		if (document.frmKLSearch.inpSearchString.value == '') {
			alert('Please enter a Serial Number to search for!');
			return false;
		}
			
		// CD 17/12/03: check for w0/wo confusion
		var oReSerialNo = /^\D0/;
		if (oReSerialNo.test(document.frmKLSearch.inpSearchString.value)) {
			if (!confirm('Serial numbers for RM equipment generally begin WO, MO or TO (that is, W-oh, not W-zero, etc.)\n\nIf you still wish to submit the search, click OK, if not, click Cancel and alter the serial number.')) {
				return false;
			}
		}
	} 
	else if(strSearchString.length == 0) {
		// Prevent the search with no text
		alert('Please enter some text to search for.');
		return false;
	}
	
	//extract regular expressionvalue
	oReContentRef = new RegExp(parent.parent.document.frmKL.inpContentRef.value);
					
	//If search string looks like a content ref, assume it is and open doc
	//Don't accomodate unapproved content anymore.
	if(oReContentRef.test(strSearchString)) {

		// Open the tech doc and be done
		viewTechDoc('/_RMVirtual/Includes/CSRedirect.asp?cref=' + strSearchString + strPreview + '&nav=0');
		return false;
	}

	// set mode value
	document.frmKLSearch.inpMode.value = pstrSearchType;
		
	// Convert the form contents into a query string
	var strOption, strQuery = '?mode=' + pstrSearchType + '&taxonomyid=' + document.frmKLSearch.inpTaxonomyID.value + '&taxonomy=' + document.frmKLSearch.inpTaxonomy.value;
		
	if (pstrSearchType == 'SERIALNOSEARCH') {
		strQuery += '&serialNo=' + escape(document.frmKLSearch.inpSearchString.value);
	}
	else {
		strQuery += '&searchString=' + escape(document.frmKLSearch.inpSearchString.value);
		strQuery += '&getfolders=true';	
	}

	if (bSortByDate) 
	{
		strQuery += '&sortByDate=true';	
	}

	if (pstrSearchType == 'SearchWithin') {
		strQuery += '&sNode=' + parent.parent.document.frmKL.inpTaxonomyNode.value;
	}
		
	if (document.frmKLSearch.inpUsage.value.length > 0) {
		strQuery += '&Usage=' + document.frmKLSearch.inpUsage.value;
	}

	strQuery += '&searchType=' + escape(document.frmKLSearch.inpSearchType.value);
	strOption = document.frmKLSearch.inpSummary.value;
	if (strOption.length > 0) {
		strQuery += '&summary=' + strOption;
	}
	strQuery += '&titleOnly=' + document.frmKLSearch.inpTitleOnly.value;
	strQuery += '&taxonomyRoot=' + document.frmKLSearch.inpTaxonomyRoot.value;
		
	// Internal only options
	if (document.frmKLSearch.inpInternalOnly)
	{	strQuery += '&internalOnly=' + document.frmKLSearch.inpInternalOnly.value;
	}

	if (parent.frames.fraLeft.document.frmKLBrowser.inpUnapproved) {
		strQuery += '&unapproved=' + parent.frames.fraLeft.document.frmKLBrowser.inpUnapproved.checked;
	}

	// Navigate the result pane to the new query string
	location = '/_RMVirtual/Frames/KnowledgeLibrary/knowledgelibraryresults.asp' + strQuery;
	
	return true;
}

// Event handler to allow submission of search when 'Enter' pressed
// on new SOL KL screens
function submitOnEnter2(oEvent,pstrAction) { 	
		
	// Get the keypress
	numCode = oEvent.which||oEvent.keyCode;
	// If it's 'Enter' then fire off the form with appropriate action
	if (numCode == 13)
	{
		submitKLSearch2(pstrAction);
		return false;
	}
}

function submitKLSerialNoSearch2(pstrSerialNoSearchType)
{
	// perform basic validation
	if (pstrSerialNoSearchType == 'SERIALNOSEARCH')
	{
		if (document.frmKLSearch.inpSearchString.value == '')
		{
			alert('Please enter a Serial Number to search for!');
			document.frmKLSearch.inpSearchString.focus();
			return false;
		}		
			
		var oReSerialNo = /^\D0/;
		if (oReSerialNo.test(document.frmKLSearch.inpSearchString.value))
		{
			if (!confirm('Serial numbers for RM equipment generally begin WO, MO or TO (that is, W-oh, not W-zero, etc.)\n\nIf you still wish to submit the search, click OK, if not, click Cancel and alter the serial number.'))
			{
				return false;
			}
		}
	} 
			
	// set mode value
	document.frmKLSearch.inpMode.value = pstrSerialNoSearchType;		
	// Convert the form contents into a query string	
	var strOption, strQuery = '?mode=' + pstrSerialNoSearchType + '&taxonomyid=' + document.frmKLSearch.inpTaxonomyID.value + '&taxonomy=' + document.frmKLSearch.inpTaxonomy.value;
		
	if (pstrSerialNoSearchType == 'SERIALNOSEARCH')
	{
		strQuery += '&serialNo=' + escape(document.frmKLSearch.inpSearchString.value);
	}
		
	if (document.frmKLSearch.inpUnapproved)
	{
		strQuery += '&unapproved=false';	
	}
						
	// Navigate the result pane to the new query string
	document.location = '/_RMVirtual/Frames/KnowledgeLibrary/knowledgelibraryresults.asp' + strQuery;
		
	return true;
}

//Opens content while logging recordno in url
function viewContent(pstrAnchorID,pstrDoc)
{
	var oAnchor = window.document.getElementById(pstrAnchorID);
	if (oAnchor && oAnchor.childNodes && oAnchor.childNodes.length)
	{
		//get the old text
		var oOldText = oAnchor.firstChild;

		//replace text before the period with new record number
		var numResult = oOldText.data.substring(0, oOldText.data.indexOf('.'));
		pstrDoc = pstrDoc + '&recordno=' + numResult + '&cluster=' + document.frmKLSearch.inpCluster.value;
	}
	// Open the tech article viewer
	window.open(pstrDoc, "", "scrollbars=Yes, resizable=Yes, toolbar=Yes, menubar=Yes, location=no, directories=no, width=795,height=450");
}


//Opens content while logging recordno in url
function viewFile(pstrAnchorID,pstrDoc)
{
	var oAnchor = window.document.getElementById(pstrAnchorID);
	if (oAnchor && oAnchor.childNodes && oAnchor.childNodes.length)
	{
		//get the old text
		var oOldText = oAnchor.firstChild;

		//replace text before the period with new record number
		var numResult = oOldText.data.substring(0, oOldText.data.indexOf('.'));
		pstrDoc = pstrDoc + '?recordno=' + numResult + '&cluster=' + document.frmKLSearch.inpCluster.value;
	}
	// Open the tech article viewer
	window.open(pstrDoc);
}


// Construct a clustered results tree based on search results and put it in the left frame
// Parse the results Listing div to extract Taxonomy info.
// Build list of taxonomies.
// Sort and total
// Render the clustered resutlts tree

//Array of all the result divs
var gaResultDivs = new Array();
var gaLIs = new Array();

function ClusterResults() 
{ 	
	var aFolderNames = new Array(); //Associative array
	var aFolderNamesSorted = new Array(); //Genuine array
	var oFolderTotalResultsArray = new Object();
	var oForm;
	//var bDebug = true;
	var bDebug = false;
	var numNextFolderAtThisLevel = 0;
	var numLIs = 0;

	function RenderFolderHTML(poDoc,pNumNextFolder,poParentNode,poLookupForm,pbHideChildren)
	{
		//Check we are not done
		if (pNumNextFolder < aFolderNamesSorted.length)
		{
			var strFolder = aFolderNamesSorted[pNumNextFolder];
			var strDisplayFolder = 'Uncategorised';

			//Lookup the friendly name for the full folder path. 
			if (poLookupForm.elements.length > 0)
			{
				if (poLookupForm.elements[strFolder])
				{
				    strDisplayFolder = poLookupForm.elements[strFolder].value;
				}
			}
		    
			//Always need a <LI> for this folder
			var oLI = poDoc.createElement("li");
			
			//cache a reference
			gaLIs[numLIs++] = oLI;
			
			var oAnchor = poDoc.createElement("a");
			var oText;			

			//record in the LI ID which taxonomy branch it is to display / hide 
			oLI.id = strFolder;
			
			//assume a leaf node
			//oLI.className = 'leaf';
			
			oAnchor.className = 'imgOpenFold';

			oText = poDoc.createTextNode(strDisplayFolder + ' (' + oFolderTotalResultsArray[strFolder] + ')');
			oAnchor.appendChild(oText);

			//Add control to allow tree to be expanded and collapsed.
					
			//Note:Event bubbling differences across browsers make it difficult for nested elements to know
			//if they were the intended target for an event.  Therefore the event target is set in a global variable 
			//when the target is moused over and checked later.
			
			//ShowHideBranch is scripted in support_common_vN.js
			oAnchor.id = 'A_' + pNumNextFolder;
			oAnchor.onclick = ShowHideBranch;

			//the onmouseover has to be on the anchor as it is the only non nested element
			//and therefore free from unpredictable event firing order
			oAnchor.onmouseover = SetTarget;
			oAnchor.href="/Support/KnowledgeLibrary.asp";
			
			//if there is another folder
			if (pNumNextFolder < (aFolderNamesSorted.length -1))
			{
				var strThis = strFolder;
				var oStrNext = new String(aFolderNamesSorted[pNumNextFolder+1]);
							
				//if it contains this folder it is a child, so render a list with it and its children in
				//and then all it's siblings
				if (oStrNext.substr(0,strThis.length) == strThis.valueOf())
				{
					//make sure we appear as a branch - assume the last branch
					//oLI.className = 'closedBranchBottom';

					//append this link with folder name
					oLI.appendChild(oAnchor);

					//now add the list of all chldren to the UL
					var oUL = poDoc.createElement('ul')
					
					//give it an ID to show / hide it in ShowHideBranch
					oUL.id = 'UL_' + pNumNextFolder;

					RenderFolderHTML(poDoc,pNumNextFolder+1,oUL,poLookupForm,pbHideChildren);
					
					//Now append any siblings to the parent
					oStrNext = new String(aFolderNamesSorted[numNextFolderAtThisLevel]);
					while (	(oStrNext.substr(0,strThis.length) == strThis.valueOf()) &&
							(numNextFolderAtThisLevel < (aFolderNamesSorted.length -1)) )
					{
						RenderFolderHTML(poDoc,numNextFolderAtThisLevel,oUL,poLookupForm,pbHideChildren);
						oStrNext = new String(aFolderNamesSorted[numNextFolderAtThisLevel]);
						//clearly not the last branch so correct our style
						//oLI.className = 'closedBranch';
					}
					//append the UL to this folder 
					if (pbHideChildren)
					{
						oUL.style.display = 'none';
					}
					
					oLI.appendChild(oUL);
					
					//append this LI to the parent
					poParentNode.appendChild(oLI);
				}
				else //we have reached a terminal node in the tree descent so start closing
				{
					oLI.appendChild(oAnchor);
					poParentNode.appendChild(oLI);

					//force progression to next folder
					numNextFolderAtThisLevel = pNumNextFolder+1;
				}
			}
			else
			{
				oLI.appendChild(oAnchor);
				poParentNode.appendChild(oLI);

				//force recursion to cease
				numNextFolderAtThisLevel = aFolderNamesSorted.length + 99;
			}
		}
	}

	//get the divs
	var oDivs = document.getElementsByTagName('DIV');
	if (oDivs) 
	{
		var oSparseFolderResultsArray = new Array();
		var aResultFolders = new Array();
		var strTaxonomies = new String;
		var oStr = new String;
		var strFolder;
		var numResultFolders = 0;
		var numResultDivs = 0;
	
		//get an array of clean folder names each result appears in
		//for every result row
		for (numDivRow=0; numDivRow < oDivs.length; numDivRow++)
		{
			var oDiv = oDivs[numDivRow];
			var oIDparts = oDiv.id.split(','); 
			var aCleanFolders = new Array();
			var oProcessedFolderNames = new Array;
			var numCleanFolder = 0;
			
			//for every comma separaed part of the ID
			for (numIDpart = 0; numIDpart < oIDparts.length; numIDpart++)
			{
				//get the next part
				var strIDpart = oIDparts[numIDpart];

				//if it starts with folder it is one of our result row divs
				if (strIDpart.substr(0,7) == 'FOLDER_')
				{
					//the strIDpart is a folder name.  Copy it. 
					var strFolder = strIDpart.substr(7);

					//generate a list of all unique ancestor folders the result is also 
					//to be included in.
					while (strFolder != '')
					{
						//if already processed ignore
						if (oProcessedFolderNames[strFolder])
						{
							strFolder = '';
						}
						else //if not processed, record the folder name
						{
							//push onto list of folders this result is in
							aCleanFolders[numCleanFolder] = strFolder;
							numCleanFolder++;

							//record existence for sorting later.
							//There may be duplicates in this array of several results are in the same folder
							aFolderNames[strFolder] = 1;

							//record that this ancestor was processed (stops duplicate counting for this particular result)
							oProcessedFolderNames[strFolder] = 1;
							
							//if it has a parent folder, get the next one (cut at the right most slash)
							var k = strFolder.lastIndexOf('/');
							if (k >= 0)
							{
								strFolder = strFolder.substr(0,k);
							}
							else  //no more ancestors so done with this folder
							{
								strFolder = '';
							}
						}
					}
				}
			}
			//if folder names were extracted from this div, save for this result row
			if (aCleanFolders.length > 0)
			{
				//build list of folders
				aResultFolders[numResultFolders] = aCleanFolders;
				numResultFolders++;

				//build list of just the result divs
				gaResultDivs[numResultDivs++] = oDiv;

			}
		}

		//now build a sorted list of all unique folders (you can only sort real arrays, not associative)
		var numFolder = 0;
		for (strFolder in aFolderNames)
		{
			aFolderNamesSorted[numFolder] = strFolder;
			numFolder++;
		}
		//sort them
		aFolderNamesSorted.sort();

		//so now we have....
		//aFolderNamesSorted[0] == 'A1'
		//aFolderNamesSorted[1] == 'A1/A2'
		//aFolderNamesSorted[2] == 'A1/A2/A3' etc

		//now roll up the total result count for each folder in the tree.
		for (numResult = 0; numResult < aResultFolders.length; numResult++)
		{
			//get folder names this result is in
			var aFolderNames = aResultFolders[numResult];
				
			//increment the rolled up results tally for every folder this result sits below
			for (k = 0; k < aFolderNames.length; k++)
			{
				strFolder = aFolderNames[k];
				oFolderTotalResultsArray[strFolder] ? oFolderTotalResultsArray[strFolder]++ : oFolderTotalResultsArray[strFolder] = 1 ;
			}
		}
		//oFolderTotalResultsArray['A1/A2'] = 2
		//oFolderTotalResultsArray['A1/B2'] = 3 
		//oFolderTotalResultsArray['A1/B2/C1'] = 1 etc
		
		if (bDebug)
		{
			strMsg = 'aFolderNamesSorted (with count)\n\n';
			for (i=0; i < aFolderNamesSorted.length; i++)
			{
				strMsg = strMsg + aFolderNamesSorted[i] + '(' + oFolderTotalResultsArray[aFolderNamesSorted[i]]+ ')' + '\n';
			}
			alert(strMsg);
			strMsg = '';
		}

		oForm = document.getElementById("frmDisplayNames");
		
		//get a ref to the destination doc as nodes must be created in that context		
		var oDoc = window.parent.frames.fraLeft.document;
		
		//get a ref to the tree div
		var oPlaceHolder  = oDoc.getElementById("Tree");

		//create a new empty div
		var oDiv = oDoc.createElement('div');

		//if some results fill the div with a tree 
		if (gaResultDivs.length > 0)
		{
			var oULresults = oDoc.createElement('ul');
			var oElement;
		
			var oULtopNode = oDoc.createElement('ul');
			oULtopNode.className = 'Outer';
			oULtopNode.style.display = '';
		
			var oLItop = oDoc.createElement("li");

			//cache a reference
			gaLIs[numLIs++] = oLItop;

			oLItop.id = 'LI_ShowAllResults';
		
			var oAnchorTop = oDoc.createElement("a");
			oAnchorTop.className = 'imgOpenFold';
			oAnchorTop.onclick = ShowAllResults;
			oAnchorTop.onmouseover=SetTarget;
			oAnchorTop.href="javascript:return false;";
			oAnchorTop.id = 'A_ShowAllResults'
			oAnchorTop.style.backgroundColor = '#E9F0F8';		
			gstrPrevTarget = oAnchorTop.id;
		
			var oTextTop;			
			oTextTop = oDoc.createTextNode('All Search Results');

			//set up the results tree
			oULtopNode.appendChild(oLItop);
			oLItop.appendChild(oAnchorTop);
			oAnchorTop.appendChild(oTextTop);

			oDiv.id = 'taxonomyTree';
			oULresults.id = '_ULTopLevelTree';

			// render all top level folder trees
			for (i=0; i < aFolderNamesSorted.length; i++)
			{
				var oStr = new String(aFolderNamesSorted[i]);
				if (oStr.indexOf('/') == -1)
				{
					RenderFolderHTML(oDoc,i,oULresults,oForm,true);
				}
			}

			oLItop.appendChild(oULresults);
			oDiv.appendChild(oULtopNode);
			
			var oFormLocation = oDoc.createElement("form");
			oFormLocation.name = 'formLocation';
			var oInputLocation = oDoc.createElement("input");
			oInputLocation.type = 'hidden';
			oInputLocation.name = 'inpLocation';
			oInputLocation.id = 'ID_fraRight_Location';
			oInputLocation.value = parent.fraRight.location;
		
			oFormLocation.appendChild(oInputLocation);
			oDiv.appendChild(oFormLocation);

		}
		if (oPlaceHolder)
		{
			//remove previous content
			if (oPlaceHolder.childNodes.length > 0)
			{
				oPlaceHolder.removeChild(oPlaceHolder.firstChild);
			}
			//add our new div
			oPlaceHolder.appendChild(oDiv);
		}
	}
}

//constants used in manipulating the search tabs
var gcstrSerialTabID = "serialTab"
var gcstrKWTabID = "keywordTab"
var gcstrSearchTabSelected = 'searchTabSelected';
var gcstrSearchTabNotSelected = 'searchTab';
var gcstrKWexampleID = 'KWexample';
var gcstrSerialExampleID = 'serialExample';

//function wrappers to easily allow function pointer assignments at run time
var gcoSubmitKLSearch2Serial = function()
{
	submitKLSerialNoSearch2('SERIALNOSEARCH');
}
var gcoSubmitOnEnter2Serial = function (oIEevent)
{
	//If oIEevent does not exist (if it isnt sent to the function), make it a reference to window.event. 
	//Now oIEevent refers to the event in all browsers
	if (!oIEevent) 
	{
		submitOnEnter2(window.event,'SERIALNOSEARCH');
	}
	else
	{
		submitOnEnter2(oIEevent,'SERIALNOSEARCH');
	}
}
var gcoSubmitKLSearch2KW = function()
{
	submitKLSearch2('Search');
}
var gcoSubmitOnEnter2KW = function(oIEevent)
{
	//If oIEevent does not exist (if it isnt sent to the function), make it a reference to window.event. 
	//Now oIEevent refers to the event in all browsers
	if (!oIEevent) 
	{
		submitOnEnter2(window.event,'Search');
	}
	else
	{
		submitOnEnter2(oIEevent,'Search');
	}
}

//change the search tabs to highlight serial search
function tabToSerialSearch()
{
	var oEl = document.getElementById(gcstrSerialTabID);
	if (oEl.className != gcstrSearchTabSelected)
	{
		oEl.className = gcstrSearchTabSelected;
		oEl = document.getElementById(gcstrKWTabID);
		oEl.className = gcstrSearchTabNotSelected;
		oEl = document.getElementById(gcstrKWexampleID);
		oEl.style.display ='none';
		oEl = document.getElementById(gcstrSerialExampleID);
		oEl.style.display ='inline';

		oEl = document.getElementById('homeInputField');
		oEl.onkeypress = gcoSubmitOnEnter2Serial; 
		oEl = document.getElementById('btnSearch');
		oEl.onclick= gcoSubmitKLSearch2Serial;
	}
}

//change the search tabs to highlight kewyword search
function tabToKWSearch()
{
	var oEl = document.getElementById(gcstrKWTabID);
	if (oEl.className != gcstrSearchTabSelected)
	{
		oEl.className = gcstrSearchTabSelected;
		oEl = document.getElementById(gcstrSerialTabID);
		oEl.className = gcstrSearchTabNotSelected;
		oEl = document.getElementById(gcstrKWexampleID);
		oEl.style.display ='inline';
		oEl = document.getElementById(gcstrSerialExampleID);
		oEl.style.display ='none';

		oEl = document.getElementById('homeInputField');
		oEl.onkeypress= gcoSubmitOnEnter2KW;
		oEl = document.getElementById('btnSearch');
		oEl.onclick= gcoSubmitKLSearch2KW;
	}
}

//Return both the left and right panes to original initial browse state.
//Use an appended unique id to avoid page caching as left frames dom is modified
//locally in jscript and browser may not really reload if the url remains identical.
function returnToBrowseMode()
{
	var oLeft = window.parent.frames.fraLeft;
	var oDate = new Date();
	var strUniqueID = oDate.getTime() + '' + Math.random();
	var strUsage;
	var strLeftLocation;
	var strRightLocation;
	var strUsage;

	strLeftLocation = '/_RMVirtual/Frames/KnowledgeLibrary/KnowledgeLibraryBrowser.asp?frameInit=1&taxonomy=SupportOnline&taxonomyid=1&uniqueid='+ strUniqueID; 
	strRightLocation = '/_RMVirtual/Frames/KnowledgeLibrary/KnowledgeLibraryResults.asp?frameInit=1&taxonomy=SupportOnline&taxonomyid=1&pagelocation=/support/&mode=BrowseInitial&uniqueid='+strUniqueID;
	strUsage = document.frmKLSearch.inpUsage.value;
	
	if (document.frmKLSearch.inpUsage.value.length > 0)
	{
		strLeftLocation = strLeftLocation + '&usage=' + document.frmKLSearch.inpUsage.value;
		strRightLocation = strRightLocation + '&usage=' + document.frmKLSearch.inpUsage.value;
	}

	oLeft.location = strLeftLocation;
	document.location  = strRightLocation;
}

//use the search words to do a service call search
function SearchServiceCall()
{
	var strContentCatTypes = ''; 
	var strContentTypes = '';
	var strPreview = '';
	var strSearchString = document.frmKLSearch.inpSearchString.value.trim();
	
	// perform basic validation
	if(strSearchString.length == 0) {
		// Prevent the search with no text
		alert('Please enter some text to search for.');
		document.frmKLSearch.inpSearchString.focus();
		return false;
	}
	
	ShowLeftPaneMsg('Searching Call Notes - this may take a few moments.');
	
	// Convert the form contents into a query string
	var strQuery = '?mode=Search&taxonomyid=' + document.frmKLSearch.inpTaxonomyID.value + '&taxonomy=' + document.frmKLSearch.inpTaxonomy.value;
		
	strQuery += '&searchString=' + escape(document.frmKLSearch.inpSearchString.value);
		
	strQuery += '&searchType=' + escape(document.frmKLSearch.inpSearchType.value);

	strQuery += '&titleOnly=false&taxonomyRoot=AllAreas&unapproved=false&addOptions=true&techArea=CaesarNotes&inpOpSystem=%28All%29'

	// Navigate the result pane to the new query string
	location = '/_RMVirtual/Frames/KnowledgeLibrary/knowledgelibraryresults.asp' + strQuery;
	return false;
}

function ShowLeftPaneMsg(pstrMsg)
{
	var oDoc = window.parent.frames.fraLeft.document;
	var oPlaceHolder  = oDoc.getElementById("Tree");
	if (oPlaceHolder)
	{
		if (oPlaceHolder.childNodes.length > 0)
		{
			oPlaceHolder.removeChild(oPlaceHolder.firstChild);
		}
		var oDiv = oDoc.createElement('div');
		var oTextMsg = oDoc.createTextNode(pstrMsg);
		oDiv.id = 'footerBar';
		oDiv.appendChild(oTextMsg);
		oPlaceHolder.appendChild(oDiv);
	}
}

function KLResultsOnLoad(pstrMode,pstrTaxonomy,pbNotServiceCall)
{
	if (pstrMode=='Search')
	{
		if(pstrTaxonomy == 'SupportOnline')
		{
			if (pbNotServiceCall)
			{
				ClusterResults();
			}
			else
			{
				ShowLeftPaneMsg('Search Complete.');
			}
		}
	}
	//optionally display the unapproved 
	var oEl = document.getElementById('inpShowUnapprovedOption');
	if (oEl)
	{
		oEl = parent.frames.fraLeft.document.getElementById('DivUnapproved');
		if (oEl)
		{
			oEl.style.display = "block";		
		}
	}
	
}

//use the search words to do a communities search
//Note that returning a value causes ie to navigate to the return value, so don't!
function SearchCommunities()
{
	var strSearchString = document.frmKLSearch.inpSearchString.value.trim();
	
	// perform basic validation
	if(strSearchString.length == 0) {
		// Prevent the search with no text
		alert('Please enter some text to search for.');
		document.frmKLSearch.inpSearchString.focus();
	}
	else
	{
		OpenWindow('http://communities.rm.com/forums/SearchResults.aspx?boardID=1&amp;o=1&amp;sd=632384928000000000&amp;f=0&amp;m=Any&amp;q='+document.frmKLSearch.inpSearchString.value.trim(), 'SupportOnlineCommunitiesSearch', 600, 800, false, true);
	}
}
