// Declare a variable for a single pop up window
var win_popup = null;

// Open a pop up window and assign to the winPopUp variable
function popup(url, width, height) {
	popup_close();
	opts = "height=" + height + ", width=" + width;
	opts += ", toolbar=no, directories=no, status=no, scrollbars=yes, resizable=yes, menubar=no";
	win_popup = window.open(url, 'popUp', opts);
	win_popup.focus();
}

// Open a pop up window with tool bar and menu and assign to the winPopUp variable
function popup_with_menu(url, width, height) {
	popup_close();
	opts = "height=" + height + ", width=" + width +", toolbar, location, status, scrollbars, resizable, menubar";
	win_popup = window.open(url, 'popUp', opts);
	win_popup.focus();
}

// Close the pop up window
function popup_close() {
	if (win_popup != null) {
	   win_popup.close();
	   win_popup = null;
	}
}

//Opens a pop-up browser window for displaying an image and a link to close the window.
function openViewerWin(imageURL, winTitle, width, height) {
   popup_close();
   winOptions="height=" + height + ", width=" + width;
   winOptions += ", toolbar=no, directories=no, status=no, scrollbars=no, resizable=no";
   win_popup=window.open('', 'ViewerWin', winOptions);
   win_popup.document.open();
   win_popup.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");
   win_popup.document.writeln("<html>");
   win_popup.document.writeln("<head>");
   win_popup.document.writeln("<title>" + winTitle + "</title>");
   win_popup.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
   win_popup.document.writeln("<link rel='stylesheet' href='default.css' type='text/css'>");
   win_popup.document.writeln("</head>");
   win_popup.document.writeln("<body>");
   win_popup.document.writeln("<div id='popup_content' style='position: absolute; z-index: 1; left: 0px; top: 0px'>");
   win_popup.document.writeln("<img src='" + imageURL + "' alt='" + winTitle + "'><br><a href='javascript:self.close()'>Close this pop-up window</a>");
   win_popup.document.writeln("</div>");
   win_popup.document.writeln("</body>");
   win_popup.document.writeln("</html>");
   win_popup.document.close();
   win_popup.focus();
}
