// Copyright 2009: Thomson Reuters Global Resources. All Rights Reserved. Proprietary and Confidential information of TRGR. Disclosure, Use or Reproduction without the written authorization of TRGR is prohibited
/// <reference path="~/shared/js/namespaces.js"/>

/*****************************************************
** FileName: ChargeWarningCancel.js                 **
** Notes: This files requires that                  **
**   shared\js\SetupWestlawFrameRef.js be included  **
**   on the page as well.                           **
*****************************************************/

/*****************************************************
** FunctionName: CWAdvancedCancel                   **
** Parameters:                                      **
**   strFN - The Frame Name, required for the       **
**     getWestlawFrameReference() call              **
**   strPopup - Holds "true" for "false".  This     **
**     should only be passed in as "true" when we   **
**     know we are in a popup.                      **
**   pagesBack - The number of pages to go back.    **
**     This is the equivalent of pressing the       **
**     browser's back button the specified number   **
**     of times.                                    **
*****************************************************/
function CWAdvancedCancel(strFN, strPopup, pagesBack)
{
    CWDoBrowserBack(strFN, strPopup, pagesBack);
}

/*****************************************************
** FunctionName: CWCancel                           **
**   This function is depricated.                   **
**   Please call:                                   **
**         CWAdvancedCancel(strFN, strPopup, 1)     **
**   instead.
** Parameters:                                      **
**   strFN - The Frame Name, required for the       **
**     getWestlawFrameReference() call              **
**   strPopup - Holds "true" for "false".  This     **
**     should only be passed in as "true" when we   **
**     know we are in a popup.                      **
*****************************************************/
function CWCancel(strFN, strPopup)
{
	return CWDoBrowserBack(strFN, strPopup, 1);
}

/*****************************************************
** FunctionName: CWDoBrowserBack                    **
**   Please do not call this function directly.     **
**   Instead call:  CWAdvancedCancel                **
** Parameters:                                      **
**   strFN - The Frame Name, required for the       **
**     getWestlawFrameReference() call              **
**   strPopup - Holds "true" for "false".  This     **
**     should only be passed in as "true" when we   **
**     know we are in a popup.                      **
**   pagesBack - The number of pages to go back.    **
**     This is the equivalent of pressing the       **
**     browser's back button the specified number   **
**     of times.                                    **
** ProcessingLogic: Check the bLinkViewer variable. **
**   This will only be defined when we are in Link  **
**   Viewer, so we need to check it in a try/catch  **
**   block.  Next, if we are in a popup, close it,  **
**   otherwise, go back the specified number of     **
**   pages.                                         **
*****************************************************/
function CWDoBrowserBack(strFN, strPopup, pagesBack)
{
	var bLV = false;
	var intBlankHistory = 0; //length of history for a brand new window.

	if (navigator.appName == "Netscape")
	{
		intBlankHistory = 1;
	}

	if (typeof (West) !== "undefined")
	{
	    if (typeof (Westlaw.Core.Analytics) !== "undefined")
	    {
	        // Track cancel event for workflow analytics
	        West.Westlaw.Web.UI.Services.WorkflowAnalyticsTracking.TrackChargeWarningCancelClick();
	    }
	}

	try
	{
		if (bLinkViewer)
		{
			bLV = true;
		}
	}
	catch(err){}

	var topFrame = getWestlawFrameReference(strFN);

	if (bLV || strPopup=="true" || topFrame.history.length==intBlankHistory)
	{
		topFrame.close();
	}
	else
	{
		if (pagesBack > 0)
		{
			pagesBack = pagesBack * -1;
		}
		getWestlawFrameReference(strFN).history.go(pagesBack);
	}
	return true;
}

if(typeof(Sys) !== "undefined") {
	Sys.Application.notifyScriptLoaded();
}