/************************************************************

	Created:	4/26/2001
	File: 		dolphintop.js
	File Type:	Include
 	Purpose: 	This file is referenced by the top templates and 
				should be cachable for performance reasons.  
				These functions should be included in any top include 
				files that require/use help or popup windows.
				
 	ASP Functions:	N/A
	JS Functions:	PopUpNewBWCWindow, help, doBWCProcess, popupWindow
	Modified:		Created
					09/24/2002 - Added popupWindow Function
					02/03/2003 - Added method for printing
************************************************************/

/************************************************************
Purpose:	Gets information about the browser that is 
			critical to code other scripts correctly
Output:	Creates a browser object that has 3 items
		isNN, isIE, version 
************************************************************/
var gobjBrowser = new Object();

//Setup the default values of the object
gobjBrowser.isNN = false;
gobjBrowser.isIE = false;

//Set the appropriate value depending on the appName
if(navigator.appName.indexOf("Netscape") != -1)
{
	gobjBrowser.isNN = true;
	gobjBrowser.version = navigator.appVersion.indexOf("Netscape");
	gobjBrowser.version = parseFloat(navigator.appVersion.substring(gobjBrowser.version+8, gobjBrowser.version+12));
}
else if(navigator.appName.indexOf("Microsoft") != -1)
{
	gobjBrowser.isIE = true;
	gobjBrowser.version = navigator.appVersion.indexOf("MSIE");
	gobjBrowser.version = parseFloat(navigator.appVersion.substring(gobjBrowser.version+5, gobjBrowser.version+10));
}

/************************************************************
Name:		PopUpNewBWCWindow
Purpose:	To popup new window where developer specifies

Input:	strURL - the url where the pop-ups source resides
		strWinName - the name of the window
		strHortAlign ("l","c" or "r") left, center, right
		strVertAlign ("t","c" or "b") top, center, bottom
		blnRelativeSizeToParent
						0 -	Inputted width / Inputted height
						1 - Inputted width + parent's width / Inputted height
						2 - Inputted width / Inputted height + parent's width
						3 - Inputted width + parent's width / Inputted height + parent's width
		intWinWidth	 - Inputted Width
		intWinHeight - Inputted Height
		blnShowToolbars	 - Should the pop-up have a toolbar true/false
Output:	Window Handle
************************************************************/    
function PopupBWCWindow(strURL, strWinName, strHortAlign, strVertAlign, intRelativeToParent, intWinWidth, intWinHeight, blnShowToolbars)
{
	var parent	= new Array(4);	// array to hold our parent window coordinates
	var child	= new Array(4);	// array to hold our help window coordinates
	var childWindow = null;		// window handle for pop-up window							
	var strAttributes = ""			// string that states if a toolbar is needed for the pop-up
	var intNNOffset =0;
	if (document.all)										// Internet Explorer
	{
		parent[0] = window.screenLeft;						// main window X coordinate

		parent[1] = window.screenTop;						// main window Y coordinate
		parent[2] = window.document.body.clientWidth;		// main window Width
		parent[3] = window.document.body.clientHeight;		// main window Height
		if(blnShowToolbars){parent[3] -= 95;}
	}
	else if (document.layers)								// Netscape Navigator
	{
		parent[0] = window.screenX;							// main window X coordinate
		parent[1] = window.screenY;							// main window Y coordinate
		parent[2] = window.innerWidth;						// main window Width
		parent[3] = window.innerHeight;						// main window Height
		if(blnShowToolbars)
		{
			parent[3] -= 50;
			intNNOffset = window.outerHeight - parent[3]-95;
		}
		else
		{intNNOffset=window.outerHeight - parent[3]-24	}
	}
	
	if (intRelativeToParent==1 || intRelativeToParent==3)
	{	//Make sure that the width is a positive and viewable size	
		if((intWinWidth+parent[2]) > 100) 
			intWinWidth+=parent[2];	//Add the specified width to the parent window
	}
	if (intRelativeToParent>=2)
	{	//Make sure that the height is a positive and viewable size
		if((intWinHeight+parent[3]) > 100)
			intWinHeight+=parent[3];//Add the specified height to parent window
	}
	child[2] = intWinWidth;		// Assign the window width
	child[3] = intWinHeight;	// Assign the window height
		
	child[0] = parent[0]; 
	//If win centered horizontally
	if(strHortAlign=="c") 
		child[0] += (parent[2]/2 - intWinWidth/2);
		
	//If win right aligned horizontally
	else if (strHortAlign=="r")
		child[0] += (parent[2] - intWinWidth);
	
	child[1] = parent[1];
	//If win centered vertically
	if(strVertAlign=="c")
		child[1] += (parent[3]/2 - intWinHeight/2);
		
	//If win aligned vertically to the bottom of the parent
	else if(strVertAlign=="b")
		child[1] += (parent[3] - intWinHeight -5);
	
	if (document.all)	// Internet Explorer
	{	// Adjusting child window width
		child[2] +=10;
		child[3] -=10;
	}
	else
	{	//Making adjustments X-Coord, Y-Coord, Width and Height
		child[0] += 5; child[1] += intNNOffset;
		child[2] -= 10;	child[3] -= 10;
	}
	
	if(childWindow)
		childWindow.close();
	
	if((blnShowToolbars !== void(0)) && (blnShowToolbars))
		{strAttributes="toolbar=yes,location=yes, menubar=yes";}
	else {strAttributes="toolbar=no,location=no, menubar=no";}
	
	childWindow = window.open(strURL, strWinName, 'width='+child[2]+',height='+child[3]+',top='+child[1]+',screenY='+child[1]+',left='+child[0]+',screenX='+child[0]+',resizable,scrollbars,' + strAttributes);
	return childWindow;
}

/************************************************************
Name:		help
Purpose:	To open a popup window that will display page 
			context sensitive help.
Input:	N/A
Output:	N/A
Notes:	To work this function requires a form named 'frmGUID' with a hidden element
		named PageID. This value is used to look up the help for the page.
		In some computations below we add or subtract literal values. These are needed
		to compensate for how each browser calculates the values for browser
		sizes in pixels so that our window will appear where we want it to.

************************************************************/    
function help()
{
	// initialize the page to default.asp which will be use regardless of anything else
	PageName = "/help/default.asp";
	
	// check to see if the current page has the required form
	if(document.frmGUID)
	{
		// the form is there so check if the hidden input variable is there
		if(document.frmGUID.PageID)
		{
			// looks like we have everything so grab the pageid and load it's help
			PageName += "?PageID=" + document.frmGUID.PageID.value;
		}
	}
	var win_handle = PopupBWCWindow(PageName, "help", "r", "t", 2, 300, 0)
	win_handle.focus();
}

/************************************************************
Name:		doBWCProcess
Purpose:	To perform the action or inform the user that 
			the action has already been done.  This is only for 
			JS that would interrupt a submit process or is the 
			submit process
Input:		zstrAction - The Javascript that needs to be executed
			zstrNameOfAction - A business description of what is being executed
Output:		Returns true/false based on if the Javascript was executed
************************************************************/    
function doBWCProcess(zstrAction,zstrNameOfAction)
{
	if(gstrJSCall == "")
	{
		gstrJSCall=zstrAction;
		eval(zstrAction);
	}
	else if(gstrJSCall == zstrAction)
		eval(zstrAction);
	else
	{
		if(!confirm("Is it OK to override your current action (" + gstrJSDesc + 
			") with what you requested (" + zstrNameOfAction + ")?"))
			eval(zstrAction);
		else 
			return false;
	}
	return true;
}
/************************************************************
Name:		popupWindow
Purpose:	To popup new window in a predefined, hardcoded place
			on the users screen.  This function should be used for
			most popup instances, except when the developer needs
			more control on the location or parameter of the popup 
			window.
Input:		strURL - the url where the pop-ups source resides
Output:		N/A
************************************************************/    
function popupWindow(strURL)
{
	PopupBWCWindow(strURL, 'WinName' , 'c', 'c', 3, -200, -200, true);
}

/************************************************************
Name:		displayBWButton
Purpose:	Display either a previous or next button on BW
			Pages based on the window history.  This function
			also writes out the javascript that is triggered
			when the user clicks the button.  If there is 
			any history to the browser window, the user is 
			returned to the previous page.  If there is no
			browser history, the window is closed.
Input:		none
Output:		none
************************************************************/    
function displayBWButton()
{
	if (window.history.length < 1) 
	{
		document.writeln ("<table cellpadding='0' cellspacing='0' border='0' width='600'><tr><td align='center'><a href='javascript:void window.close()'><img src='/images/common/buttons/BtnCombleftend.gif'  border='0' width='10' height='20' alt=''><img src='/images/common/buttons/BtnComBClose.gif'  border='0' width='75' height='20' alt='close'><img src='/images/common/buttons/BtnCombrightend.gif' border='0' width='10' height='20' alt=''></a></td></tr></table>");
	}
	else
	{
		document.writeln ("<table cellpadding='0' cellspacing='0' border='0' width='600'><tr><td align='center'><a href='javascript:void window.GoBack()'><img src='/images/common/buttons/BtnCombleftend.gif'  border='0' width='10' height='20' alt=''><img src='/images/common/buttons/BtnComBPrevious.gif'  border='0' width='75' height='20' alt='previous'><img src='/images/common/buttons/BtnCombrightend.gif' border='0' width='10' height='20' alt=''></a></td></tr></table>");
	}
}

/************************************************************
Name:		printScreen
Purpose:	Called by the print friendly link. creates a new 
			window for displaying the HTML without the menus
************************************************************/
function printScreen()
{			
	//used instead of PopupBWCWindow because we need the menubar and specific formatting that 
	//function doesn't offer
	window.open("/includes/printfriendly.asp","","width=250,height=100,toolbar=no,menubar=no,location=no,scrollbars=no");
}