// 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;
}


function setContent(element, html) {
	box=document.getElementById(element);
	box.innerHTML=html;
}

function showNavPopup(panel) {
	for (var i=0; i<topNavIds.length; i++) {
		document.getElementById(topNavIds[i]).style.display='none';
	}
	
	document.getElementById('topNavPopup').style.display='block';
	document.getElementById(panel).style.display='block';
}

function hideNavPopup(panel) {
	document.getElementById('topNavPopup').style.display='none';
}

function showWhenChecked(el, control) {
	elem=document.getElementById(el);
	controller=document.getElementById(control);
	if (controller.checked==true) { 
		elem.style.display='block';
	}
	else {
		elem.style.display='none' 
	};
}

function showWhenMulti(el, control, when1, when2){
	elem=document.getElementById(el);
	controller=document.getElementById(control);
	if (controller.value==when1) { 
		elem.style.display='block';
	}
	else if(controller.value==when2) { 
		elem.style.display='block';
	}
	else {
		elem.style.display='none' 
	}
}

