/* Open Picture Window 
   Copyright 2007 Ajay D. Sousa

   Popup a new window ad load a url (typ. image)
   specify w/h for window and if centered on screen, and title
   window has no decor, button provided to dismiss window.
 
   Usage: opw(picture_url, target, web window features, w, h, centered, title)
	picture_url = regular URL to the image to be displayed
	winName = as in href target=; if the same in multiple calls of the
                  function, then each image goes to the same window
	features = javascript doc.window attributes:	
		   ALL FEATURES ARE "0" (off) by DEFAULT
		    *  toolbar=0|1 : display the toolbar in the new window.
		    * location=0|1 : display the address line in the new window.
		    *   status=0|1 : display the browser status bar in footer.
		    *  menubar=0|1 : display the browser menu bar.
		  * scrollbars=0|1 : the new window will have scrollbars.
		   * resizable=0|1 : the new window is resizable.
 */
			
	
function opw(theURL, winName, features, myWidth, myHeight, isCenter, myTitle)
{
	var opw = null;
	var settings;
	var myHeightWithButton = myHeight + 80; //spacer
	myHeight = myHeightWithButton;
	settings = 'width='+myWidth+',height='+myHeight;
	
	if(!myTitle) myTitle = "Hillside Haflingers";
	
	if(isCenter)		// Position in center of window
	{
		var myLeft = (screen.width) ? (screen.width-myWidth)/2 : 0;
		var myTop = (screen.height) ? (screen.height-myHeight)/2 : 0;
		
		settings +=',left='+myLeft+',top='+myTop;
	}
	
	if(features!='') settings +=','+features;		// add features passed as argument

	opw = window.open('',winName,settings);	
	with (opw.document)
	{
		open('text/html', 'replace');
		write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n');
		write('<html xmlns="http://www.w3.org/1999/xhtml">\n');
		write('<head><title>');
		write(myTitle);
		write('</title>\n');
		write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n');
		write('<meta http-equiv="imagetoolbar" content="no" />\n');
		write('<meta name="generator" content="OPW Plugin" />\n');
		write('<script type="text/javascript">\n');
		write('self.resizeTo('+myWidth+','+myHeight+');\n');
		write('self.focus()\n');
		write('</script>\n');
		write('</head>\n');
		write('<body style="border:0;margin:0;background-color:black">\n');
		write('<img src="'+ theURL +'" ');
		write('title="'+ myTitle +'" alt="'+ myTitle +'" ');
		write('/>\n');
		write('<table><tr><td align="middle">\n');
		write('<form>\n<input type=button value="Close This Window" onClick="javascript:window.close();">\n</form>\n');
		write('Debug: myHeight is: '+ myHeight +'</td></tr></table>\n');
		write('</body>\n</html>\n');
		close();
	}

}
