var WIDTH  = 800; //Default screen width (constant)
var HEIGHT = 600; //Default screen height (constant)

var strBrowser;
var intVersion;
var detect;

function detectBrowser()
{
	detect = navigator.userAgent.toLowerCase();
	
	if (checkBrowser('opera')) 
		strBrowser = "Opera"; 
	else if (checkBrowser('msie')) 
		strBrowser = "IE";
	else if (!checkBrowser('compatible'))
	{
		strBrowser = "NS" + detect.charAt(8);
	}
	else 
		browser = "Unknown";
}

function checkBrowser(strCheck)
{
	place = detect.indexOf(strCheck) + 1;
	return place;
}

/*
function detectBrowser()
{
	if(navigator.userAgent.indexOf("MSIE") != -1)
		strBrowserType = "IE"; //Internet Explorer
	else if(document.all)
		strBrowserType = "NS4"; //Netscape 4
  else if(!document.all && document.getElementById)
		strBrowserType = "NS6"; //Netscape 6
	else
		strBrowserType = "UK"; //Unknown
		
	return strBrowserType;
}
*/

//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;
	
	strBrowserType = 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 the value provided, from the screen width or height.
	 
	-Always centers the popup window
*/
function newWindow(strURL, intWidth, intHeight)
{	
	var strFeatures;
	var intLeft;
	var intTop;
	
	strBrowserType = 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);
}

function getScreenWidth() //Screen Width
{
	if(strBrowser == "IE" || strBrowser == "NS5" || strBrowser == "Opera")
		return screen.width;
	else
		return WIDTH;	
}

function getScreenHeight() //Screen Height
{	
	if(strBrowser == "IE" || strBrowser == "NS5" || strBrowser == "Opera")
		return screen.height;
	else
		return HEIGHT;	
}

function getLeft(intWidth)
{
	return (getScreenWidth() / 2) - (intWidth / 2);
}

function getTop(intHeight)
{
	return (getScreenHeight() / 2) - (intHeight / 2);
}

function backInHistory()
{
	window.history.back(); 
	return false;
}

function closeWindow()
{
	window.close();
}

function createWindow(strURL, strFeatures)
{
	window.open(strURL, "", strFeatures);
}