var WIDTH  = 800; //Default screen width (constant)
var HEIGHT = 600; //Default screen height (constant)

/*
	===========================
	Pop-up Window functionality
	===========================
*/


/*
	Sets the popup window to half of the screen width and height
*/
function newWindow(strURL)
{
	var intWidth;
	var intHeight;
	var intTop;
	var intLeft;
	var strFeatures;
	
	strBrowserTypeType = detectBrowser();
	
	intWidth = getScreenWidth() / 2;
	intHeight = getScreenHeight() / 2;
	
	intLeft = getLeft(intWidth);
	intTop = getTop(intHeight);
	
	strFeatures = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft;

	createWindow(strURL, strFeatures);
}


/*
	-Allows you to set the width or height of the popup window.
	-If the width or height equals Zero, this will set the size of 
	 the popup window to half of the screen width or height.
	-If the width or height provided is negative, this will get the screen width or height
	 and subtract that value from the screen width or height.
	-If width or height are greater then zero, that will be the size of the window
	 
	-Always centers the popup window
*/
function newWindow(strURL, intWidth, intHeight)
{	
	var strFeatures;
	var intLeft;
	var intTop;
	
	strBrowserTypeType = detectBrowser();
	
	if(intWidth == 0)
		intWidth = getScreenWidth() / 2;
	if(intHeight == 0)
		intHeight = getScreenHeight() / 2;
	if(intWidth < 0)
		intWidth = getScreenWidth() + intWidth;
	if(intHeight < 0)
		intHeight = getScreenHeight() + intHeight;
	
	intLeft = getLeft(intWidth);
	intTop = getTop(intHeight);
	
	strFeatures = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft;
	
	createWindow(strURL, strFeatures);
}


/*
	Returns the screen width if the browser is supported, 
	or else will return the default width defined at the top.
*/
function getScreenWidth()
{
	for(var i=0; i<= supportedBrowsers.length; i++)
	{
		if(supportedBrowsers[i] == strBrowserType)
			return screen.width;
	}

	return WIDTH;

//	if(strBrowserType == "IE" || strBrowserType == "NS5" || strBrowserType == "Opera")
//		return screen.width;
//	else
//		return WIDTH;	
}


/*
	Returns the screen height if the browser is supported, 
	or else will return the default height defined at the top.
*/
function getScreenHeight()
{
	for(var i=0; i<= supportedBrowsers.length; i++)
	{
		if(supportedBrowsers[i] == strBrowserType)
			return screen.height;
	}

	return HEIGHT;

//	if(strBrowserType == "IE" || strBrowserType == "NS5" || strBrowserType == "Opera")
//		return screen.height;
//	else
//		return HEIGHT;	
}


/*
	Returns the value of how far from the left side of the screen
	the pop-up should display. In effect centering it horizontally.
*/
function getLeft(intWidth)
{
	return (getScreenWidth() / 2) - (intWidth / 2);
}


/*
	Returns the value of how far from the top of the screen
	the pop-up should display. In effect centering it vertically.
*/
function getTop(intHeight)
{
	return (getScreenHeight() / 2) - (intHeight / 2);
}


/*
	Will get the browsers history, and go to the previous page.
*/
function backInHistory()
{
	window.history.back(); 
	return false;
}


/*
	Closes this browser window
*/
function closeWindow()
{
	window.close();
}


/*
	Creates the new pop-up window with the supplied values.
*/
function createWindow(strURL, strFeatures)
{
	window.open(strURL, "", strFeatures);
}


/*
	===============================
	Browser Detection Functionality
	===============================
*/


var strBrowserType; //Stores the browser type
var supportedBrowsers = new Array(); //An array that stores all supported browsers.

supportedBrowsers[0] = "IE";	//Internet Explorer
supportedBrowsers[1] = "NS5";	//Netscape 6
supportedBrowsers[2] = "NS6";	//Netscape 7
supportedBrowsers[3] = "Opera";	//Opera

/*
	Detects the browser the user is using. And stores the
	result in the global variable strBrowserType
*/
function detectBrowser()
{	
	var detect = agentString();

	if (checkBrowser('opera', detect)) 
		strBrowserType = "Opera"; 
	else if (checkBrowser('msie', detect)) 
		strBrowserType = "IE";
	else if (!checkBrowser('compatible', detect))
		strBrowserType = "NS" + detect.charAt(8);
	else 
		strBrowserType = "Unknown";
}


/*
	Returns the user agent string for the current browser.
*/
function agentString()
{
	return navigator.userAgent.toLowerCase();
}


/*
	Looks in the "user agent string" for the  suplied string to check.
*/
function checkBrowser(strCheck, strUserAgent)
{
	return strUserAgent.indexOf(strCheck) + 1;
}
