// <script>
// Author:		Colin Turner
// Date:		12 Sep 2003
// Purpose:		JavaScript common to new support site
//
// Change History:
// Date			Author			Comments
// 31 Oct 2003	Colin Turner	Bug 5452 Added function viewAccessRights
// 13 Nov 2005  Simon Hewerdine SOL KL Search makeover.  Added new globals and functions.
// 10 Jan 2005  Simon Hewerdine Resubmit search if right frame location changed.
// 14 Feb 2005  Simon Hewerdine Corrected result numbering bug.
// 20 Feb 2005  Simon Hewerdine Add font size adjustment functions.
// 24 Jul 2008  Rakesh R Modified to viewAccessRights function to show a hardcoded acces right denied 
//						page for CC4 Help Files.
function viewTechDoc(pstrDoc)
{
	// Open the tech article viewer
	window.open(pstrDoc, "", "scrollbars=Yes, resizable=Yes, toolbar=Yes, menubar=Yes, location=no, directories=no, width=795,height=450");
}

function viewAccessRights(pstrContentRef)
{
	var strDoc;
	if(pstrContentRef=='CC4HelpFile')
	strDoc = '/Utils/CC4HelpAccessRestricted.htm';
	else
	strDoc = '/Utils/ContentAccessRights.asp?cref=' + pstrContentRef;
	
	window.open(strDoc, "", "scrollbars=Yes, resizable=No, toolbar=No, menubar=No, location=no, directories=no, width=375,height=425");
}

function viewSubscriptions()
{
	// Just navigate to My Account Subscriptions area
	document.location = '/account/member/subscriptions.asp';
}

//records id of intended event target to avoid cross browser even bubbling 
//problems
var gstrTargetId;

//Handy var to remember last results folder selected
var gstrPrevTarget;

//sets the intended target
function SetTarget()
{
	gstrTargetId = this.id;
	window.status = '';
	return true;
}

//shows or hides the branch of the search results tree
function ShowHideBranch()
{
	//Hides every UL that is not a Sibling or an Ancestor of pstrFolderToKeep 
	function HideNonContextFolders(poBrowserDoc,pstrFolderToKeep)
	{
		//get all the LI's on the browser page using saved array
		var oLIs = window.parent.frames.fraRight.gaLIs;
		var strFolderToKeepLength = pstrFolderToKeep.split('/').length;

		for (var numLI=0; numLI < oLIs.length; numLI++)
		{
			var oLI = oLIs[numLI];

			if (oLI.id != 'LI_ShowAllResults')
			{
				var strNextFolder = oLI.id;
			
				//if the LI has more than 1 child it has an UL.  Should it be shown?
				if (oLI.childNodes.length > 1)  
				{
					var oUL = oLI.childNodes[1];

					oUL.style.display='block';

					//if not an ancestor hide it!
					if (	   (strNextFolder.split('/').length <= strFolderToKeepLength) 
						&& (pstrFolderToKeep.substr(0,strNextFolder.length).valueOf() != strNextFolder.valueOf() ) 
					   )
					{
						oUL.style.display='none';
					}

					//if deeper hide it!
					if (strNextFolder.split('/').length > strFolderToKeepLength) 
					{
						oUL.style.display='none';
					}
				}
			}
		}
	}

	//Filters what is shown in the right results frame to only
	//include the results appearing at or below this strFolderToShow
	function ShowFolderResults(poDoc,paDivs,strFolderToShow)
	{
		var strFolder;
		var numResult = 0; 
	
		//check each div id for id="FOLDER_aaaaaa,FOLDER_xxxxx,FOLDER_strFolderToShow". 	

		//hide all search result divs 
		for (var numDiv=0; numDiv < paDivs.length; numDiv++)
		{
				paDivs[numDiv].style.display='none';
		}			

		//show search result divs that have pstrFolderToKeep in their list of taxonomy folders
		for (var numDiv=0; numDiv < paDivs.length; numDiv++)
		{	
			var oDiv = paDivs[numDiv];
			var oIdFolders = oDiv.id;
			var oIDparts = oIdFolders.split(','); 
			
			//show results that include strFolderToShow
			for (var numIDpart=0; numIDpart < oIDparts.length; numIDpart++)
			{
				//if not already shown then see if we should be showing it.
				if (oDiv.style.display == 'none')
				{			
					var strIDpart = oIDparts[numIDpart];
					var strFolder = strIDpart.substr(7);

					//if strFolderToShow apppears in the strFolder, strFolder is a descendent so show it
					if( strFolder.substr(0,strFolderToShow.length).valueOf() == strFolderToShow.valueOf())
					{
						//display this div
						oDiv.style.display='block';

						//get the anchor for this result
						var oAnchor = poDoc.getElementById('A_'+numDiv);

						//manipulate the anchor
						if (oAnchor && oAnchor.childNodes && oAnchor.childNodes.length)
						{
							//get the old text
							var oOldText = oAnchor.firstChild;

							//increment counter for results number display
							numResult++;

							//replace text before the period with new record number
							oOldText.replaceData(0, oOldText.data.indexOf('.'), numResult);
						}
					}
				}
			}
		}
	}

	//ShowHideBranch() proper really starts here.

	//get reference to the destination docs to query.
	var oBrowserDoc = window.parent.frames.fraLeft.document;
	var oResultsDoc = window.parent.frames.fraRight.document;

	//if the user had navigated the right frame elsewhere
	//e.g. to the can't find it page, resubmit the search
	var oInput = oBrowserDoc.getElementById('ID_fraRight_Location');     
	if (oInput.value != oResultsDoc.location)
	{
		oResultsDoc.location = oInput.value;
		return false;
	}

	// if this.id matches gstrTargetId the event was meant for me and did not 
	// reach me through event bubbling, so act on it
	var strId = this.id;

	if (strId == gstrTargetId)
	{
		//get folder number
		var strNumber = strId.substr(2); 

		//get this folders name from the parent node id
		var strThisFolder = this.parentNode.id;

		//get all of the divs on the results page
		var aDivs = window.parent.frames.fraRight.gaResultDivs;
		
		//get the UL that displays this folders children
		var oUL = oBrowserDoc.getElementById('UL_' + strNumber);     
		
		//if this branch has a list below then show it
		//and display all results in it
		if (oUL)
		{
			//if hidden
			if (oUL.style.display == 'none')
			{
				//this.parentNode.className = 'openBranch';	
				//show this UL
				oUL.style.display = '';
			}
		}

		//hide all superfluous folders 
		HideNonContextFolders(oBrowserDoc,strThisFolder);

		//show search results
		ShowFolderResults(oResultsDoc,aDivs,strThisFolder);
		
		//un highlight previosuly selected element
		if (gstrPrevTarget) 
		{	
			oBrowserDoc.getElementById(gstrPrevTarget).style.backgroundColor = '#FFFFFF';	
		}
		this.style.backgroundColor = '#E9F0F8';		
		gstrPrevTarget = strId;
		window.status = ''; 

		//record that this is the selected cluster
		oResultsDoc.frmKLSearch.inpCluster.value = this.firstChild.data;

		//stop further unneccessary bubbling
		try
		{
			event.cancelBubble = true;
		}
		catch(e)
		{
		}
	}
	else
	{
	}
	return false;
}

//show all search results
function ShowAllResults()
{
	// if this.id matches gstrTargetId the event was meant for me and did not 
	// reach me through event bubbling, so act on it
	
	if (this.id == gstrTargetId)
	{
		//get reference to the destination docs to query.
		var oBrowserDoc = window.parent.frames.fraLeft.document;
		var oResultsDoc = window.parent.frames.fraRight.document;

		//get all of the divs on the results page
		var aDivs = window.parent.frames.fraRight.gaResultDivs;

		//un highlight previosuly selected element
		if (gstrPrevTarget) 
		{	
			oBrowserDoc.getElementById(gstrPrevTarget).style.backgroundColor = '#FFFFFF';	
		}
		
		//highlight this one
		this.style.backgroundColor = '#E9F0F8';		
		gstrPrevTarget = this.id;

		oResultsDoc.frmKLSearch.inpCluster.value = 'All';

		var	numResult = 0;

		for (var numDiv=0; numDiv < aDivs.length; numDiv++)
		{
			aDivs[numDiv].style.display='block';

			//get the anchor for this result
			var oAnchor = oResultsDoc.getElementById('A_'+numDiv);
					
			//increment counter for results number display
			numResult++;

			//manipulate the anchor
			if (oAnchor && oAnchor.childNodes && oAnchor.childNodes.length)
			{
				//get the old text
				var oOldText = oAnchor.firstChild;

				//replace text before the period with new record number
				oOldText.replaceData(0, oOldText.data.indexOf('.'), numResult);
			}
		}
		//stop further unneccessary bubbling
		try
		{
			event.cancelBubble = true;
		}
		catch(e)
		{
		}
	}
	else
	{
	}
	return false;
}

//show login message
function LoginMsg()
{
	alert('You must be logged in to view this article');
	//prevent navigation
	return false;
}

function setFocus()
{	
	if (top
		&& top.frames[0]
		&& top.frames[0].frames
		&& top.frames[0].frames.fraRight
		&& top.frames[0].frames.fraRight.document
		);
	{
		var oInput = top.frames[0].frames.fraRight.document.getElementById('homeInputField');
		if (oInput)
		{
			oInput.focus();
		}
	}
}

//reduce font size for low res screens  
function setLeftRightFontSize()
{	
	if (screen && screen.height && screen.height < 768)
	{
		var oLeftDoc = window.parent.frames.fraLeft.document;
		var oRightDoc = window.parent.frames.fraRight.document;

		if (oLeftDoc)
		{ 
			oLeftDoc.body.style.fontSize='70%';
		}
		if (oRightDoc)
		{ 
			oRightDoc.body.style.fontSize='65%';
		}
	} 
}

function setLeftFontSize()
{	
	if (screen && screen.height && screen.height < 768)
	{
		var oLeftDoc = window.parent.frames.fraLeft.document;
		if (oLeftDoc)
		{ 
			oLeftDoc.body.style.fontSize='70%';
		}
	} 
}

function incLeftRightFontSize()
{	
	var oLeftDoc = window.parent.frames.fraLeft.document;
	var oRightDoc = window.parent.frames.fraRight.document;

	changeTxtSize(oLeftDoc,'inc',70);
	changeTxtSize(oRightDoc,'inc',75);
}

function decLeftRightFontSize()
{	
	var oLeftDoc = window.parent.frames.fraLeft.document;
	var oRightDoc = window.parent.frames.fraRight.document;

	changeTxtSize(oLeftDoc,'dec',75);
	changeTxtSize(oRightDoc,'dec',75);
}
