// Opens a window in the centre of the screen. 
// Pass the php function, the id to work from, window width and height. For windowId, just pass a random string.
// for resize pass yes or no. Scrollbars are automatic if image is too big for screen.

function doPopup(url, windowWidth, windowHeight, windowId, resize, returnType) {

	if(resize=='yes') {
		scrollbars='yes';
		windowWidth=windowWidth+20;
	}
	else if(windowWidth>screen.availWidth || windowHeight>screen.availHeight) {
		scrollbars='yes';
		windowWidth=windowWidth+20;
	}
	else scrollbars='no';
	
	// reduce size so it doesn't fill the screen. also allows space for windows toolbar
	if(windowWidth>screen.availWidth) windowWidth=screen.availWidth-20;
	if(windowHeight>screen.availHeight) windowHeight=screen.availHeight-55;
	
	// Calculate the position to centre on screen
	xPos = ((screen.availWidth/2)-(windowWidth/2));
	yPos = ((screen.availHeight/2)-(windowHeight/2));
			
	window.open(url,windowId,'left='+xPos+',top='+yPos+',width='+windowWidth+',height='+windowHeight+',scrollbars=auto,resizable='+resize+',location=no,directories=no,status=no');

	if(returnType=='false') return false;
	else return true;
}
