function popup(){
	// Close the popup window if it already exists; fail gracefully
	// You can't just use a window.focus method here, as the window may need to be a new size
	try{
		popup.close();
	} catch(e){}
	// Open the popup with the attributes defined in popupInit
	popup = window.open(this.href + "&popup=true",this.windowName,this.features + ",resizable=1");
	// Return false (stops the user agent following the link)
	return false;
}
function windowClose(){
	// Close the current window
	window.close();
	// Return false (stops the user agent following the link; may be redundant as the window no longer exists to display the page)
	return false;
}
function popupInit(){
	// Gather all the a tags in the document; we will be attaching events to a subset of them
	var alinks = document.getElementsByTagName("a");
	// Cycle through these a tags
	for(var i=0;i<alinks.length;i++){
		// Add popup behaviours to popup links
		if(alinks[i].className == "popup"){
			// Extract window features encoded in the query string; convert ampersand separation to comma separation (this is a workaround, a possible alternative would be to put hidden fields within the a tag or to encode these values in the class attribute; reject the interesting and useful notion of custom attributes as this method fails to validate)
			alinks[i].features = alinks[i].href.split("?")[1].split("&").join(",");
			// Assign window name
			alinks[i].windowName = "popup";
			// Attach event
			alinks[i].onclick = popup;
		}
		// Add window close behaviour to return links iff the current window has been popped up
		if(alinks[i].className == "return" && window.name == "popup"){
			alinks[i].onclick = windowClose;
		}
	}
}
// Assign popupInit to page load event
window.onload = popupInit;

