/////////////////////////////////////////////////////////////////////////
//
//	This function calls a pop-up window and centers it horizontally and
//	vertically on the page.  The parameters passed to it are:
//	* aObject = The <A> object calling the pop-up.  This can be handled
//		by using "this" as the first parameter in an onClick event, such as:
//		<a href="foo.html" onClick="popUp(this,....
//	* theWidth = The width of the pop-up window
//	* theHeight = The height of the pop-up window
//
/////////////////////////////////////////////////////////////////////////

function popUp(aObject, theWidth, theHeight) {
	var sURL = aObject.href;	//	The URL in the A object's href attribute.  This will be the URL of the
								//	pop-up window.
	
	//////////////////////////////////////////////////////////////////////////
	//	If we are linking into an /images/ directory, we will call the 
	//	img-popup.html page and add a query string to it (rather than just link
	//	to the image.  The img-popup.html page has a script to read the query
	//	string and place the right image within the page.
	if(sURL.indexOf("/images/") > -1) {
		sURL = "/img-popup.html?" + sURL;

	} else {	//	Linking to a webpage
		sURL += "?";	//	Adding a "?" add the end of the URL as a way to indicate that is has been called by
						//	this function since IE and Opera cannot tell the difference between a window called
						//	by the JS window.open method and one called by right-mouse clicking "Open Link in
						//	New Window".
	}
	
	//////////////////////////////////////////////////////////////////////////
	//	Grab a name for the window based on the URL that is being called.
	var aURL = sURL.split("/");				//	Split up the URL by slashes
	var tempWinName = aURL[aURL.length-1];	//	Grab the last element of the array
	
	//	IE does not like window names with hyphens, so strip them out
	var aWinName = tempWinName.split("-");			//	Divide the URL into an array by hypens
	var sWinName;									//	String to hold the name of the window
	for (var a = 0; a < aWinName.length; a++) {		// Cycle through the array and add each element to sWinName
		sWinName += aWinName[a];
	}
	
	sWinName = sWinName.substring(0,sWinName.indexOf("."));	//	Strip off the extention
	//	Done getting the name for the window
	//////////////////////////////////////////////////////////////////////////

	//	Set the height and width of the pop-up
	var winHeight = theHeight;
	var winWidth = theWidth;
	
	//	Grab screen size
	var iPageWidth, iPageHeight;
	if (self.innerHeight) {
		iPageWidth = self.innerWidth;
		iPageHeight = self.innerHeight;
	}
	else if (document.all && document.getElementById) {
		iPageWidth = screen.availWidth;
		iPageHeight = screen.availHeight;
	}
	else if (document.body) {
		iPageWidth = document.body.clientWidth;
		iPageHeight = document.body.clientHeight;
	}

	//	Determine where to put the pop-up on the screen
	leftSideOfPopup = (iPageWidth - winWidth)/2;
	topSideOfPopup = (iPageHeight - winHeight)/2;
	
	//	Define the features list
	features = "toolbar=0,width=" + winWidth + ",height=" + winHeight + ",status=0,scrollbars=0,resize=0,menubar=0,location=0,directories=0,screenX=" + leftSideOfPopup + ",left=" + leftSideOfPopup + ",screenY=" + topSideOfPopup + ",top=" + topSideOfPopup;    <!-- One line and no spaces  -->
	
	//	Call the pop-up
	theWindow = window.open(sURL, sWinName, features); 
	
	//	Return the pop-to the front in case it has already been called.
	theWindow.focus();
}
