// ------------------------------------------------------------------------------------------------
// Common Javascript functions 
// ------------------------------------------------------------------------------------------------

// Set variable isNN or isIE true depending on browser type (Netscape Navigator or Internet Explorer)
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}

// ------------------------------------------------------------------------------------------------

// Create a popup window, load an image into it, then re-size and center that window.
// Note:	Image size must be specified.
//
// Usage:	openWindow(imageUrl,imageWidth,imageHeight,[imageTitle,[autoClose,[backColor]]])
// Where:	imageUrl is the quoted ('') relative or absolute url of the image file
//			imageWidth and imageHeight specify the image size in pixels
// 			imageTitle is the quoted ('') text to use as the window's title [optional, def=imageUrl]
//			autoClose specifies if the window closes on loss of focus (true or false) [optional, def=false]
//			backColor specified the background colour [optional, def=black]
//
// Author:	dom@thoth.org 2003-03-19
//
// Do not remove this notice.

function openWindow(imageUrl, initWidth, initHeight, initTitle, autoClose, backColor) {

	var imageTitle = initTitle;
	var imageWidth = initWidth;
	var imageHeight = initHeight;
	var screenWidth = screen.width;
	var screenHeight = screen.height;

	if ((imageWidth + 30 > screenWidth) || (imageHeight + 60 > screenHeight)) {
		if (imageWidth + 20 > screenWidth - 80) {var imageWidth = screenWidth - 80;}
		else {var imageWidth = imageWidth + 20;}
		if (imageHeight + 20 > screenHeight - 110) {var imageHeight = screenHeight - 110;}
		else {var imageHeight = imageHeight + 20;}
		var optScroll = "scrollbars=yes,resizable=yes";
	}
	else {
		var imageWidth = imageWidth + 5;
	    	var imageHeight = imageHeight + 5;
		var optScroll = "resizable=yes";
	}

	var initX = (screenWidth-imageWidth)/2;
	var initY = (screenHeight-imageHeight)/2 - 10;
	var optWin = optScroll+",width="+imageWidth+",height="+imageHeight+",screenX="+initX+",screenY="+initY+",left="+initX+",top="+initY;

	if (!imageTitle) {var imageTitle = imageUrl;}
	if (!backColor) {var backColor = '#000000';}

	imageWin = window.open('about:blank', "Image", optWin);
	with (imageWin.document) {
		writeln('<html><head><title>'+imageTitle+'</title><style>body{margin:0px;}</style></head>');
		if (!autoClose) {writeln('<body bgcolor='+backColor+'>');}
		else {writeln('<body bgcolor='+backColor+' onblur="self.close()">');}
		writeln('<img src='+imageUrl+'>');
		writeln('</body></html>');
		close();		
	}
	
	void imageWin.focus( );
}

// ------------------------------------------------------------------------------------------------


// Create a popup window, load an image into it, then re-size and center that window.
// Note:	Image size is automatically calculated
//
// Usage:	popImage(imageUrl,imageTitle,[autoClose,[backColor]])
// Where:	imageURL is the quoted ('') relative or absolute url of the image file
// 			imageTitle is the quoted ('') text to use as the window's title
//			autoClose specifies if the window closes on loss of focus (true or false) [optional, def=false]
//			backColor specified the background colour [optional, def=black]
//
// Original script source: CodeLifter.com (Copyright 2003)
//
// Heavily modified by dom@thoth.org 2003-03-19
//
// Do not remove this notice.

// Set variables to represent screen dimentions.
var screenWidth = screen.width;
var screenHeight = screen.height;
var maxWidth  = screenWidth - (screenWidth *10/100);
var maxHeight = screenHeight - (screenHeight *10/100);

if (isIE) {var initWidth  = 150; var initHeight = 100;}
else {var initWidth = maxWidth;	var initHeight = maxHeight;}

var initX = (screenWidth-initWidth)/2;
var initY = (screenHeight-initHeight)/2;

var optNN='scrollbars=yes,resizable=yes,width='+initWidth+',height='+initHeight+',screenX='+initX+',screenY='+initY;
var optIE='scrollbars=yes,resizable=yes,width='+initWidth+',height='+initHeight+',left='+initX+',top='+initY;

function popImage(imageUrl,imageTitle,autoClose,backColor){

	if (!imageTitle) {var imageTitle = imageUrl;}
	if (!backColor) {var backColor = '#000000';}

	if (isNN){
		imgWin=window.open('about:blank','',optNN);
	}
	if (isIE){
		imgWin=window.open('about:blank','',optIE);
	}
	with (imgWin.document){
		writeln('<html><head><title>Loading... '+imageTitle+'</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('var screenWidth = screen.width; var screenHeight = screen.height;');
		writeln('var maxWidth  = screenWidth - (screenWidth *10/100); var maxHeight = screenHeight - (screenHeight *10/100);');

		writeln('function reSizeToImage(){');
			writeln('if (isIE) {');
				writeln('window.resizeTo(100,100);');
				writeln('var newWidth=100-(document.body.clientWidth-document.images[0].width);');
				writeln('var newHeight=100-(document.body.clientHeight-document.images[0].height);');
				writeln('if (maxWidth < newWidth) var newWidth = maxWidth;')
				writeln('if (maxHeight < newHeight) var newHeight = maxHeight;')
				writeln('var newX = (screenWidth - newWidth)/2;');
				writeln('var newY = (screenHeight - newHeight)/2;');
				writeln('window.resizeTo(newWidth,newHeight);');
				writeln('window.moveTo(newX,newY);');
				writeln('document.body.style.overflow="scroll";}');

			writeln('else {');       
				writeln('var newWidth=document.images["myImage"].width + 5;');
				writeln('var newHeight=document.images["myImage"].height + 5;');
				writeln('if (maxWidth < newWidth) var newWidth = maxWidth;')
				writeln('if (maxHeight < newHeight) var newHeight = maxHeight;')
				writeln('var newX = (screenWidth - newWidth)/2;');
				writeln('var newY = (screenHeight - newHeight)/2 - 10;');
				writeln('window.innerWidth=newWidth;');writeln('window.innerHeight=newHeight;');
				writeln('window.moveTo(newX,newY);');
				writeln('}}');

		writeln('function doTitle() {document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		
		if (!autoClose) {
			writeln('</head><body bgcolor='+backColor+' onload="reSizeToImage();doTitle();self.focus()">')
			}
		else {
			writeln('</head><body bgcolor='+backColor+' onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			}
		
		writeln('<img name="myImage" src='+imageUrl+'></body></html>');
		writeln('<!-- end -->');
		close();		

	}
}

// ------------------------------------------------------------------------------------------------

// Create a popup window, load an html file into it, then re-size and center that window.
//
// Usage:	URLWindow(URL,imageWidth,imageHeight,[imageTitle])
// Where:	imageUrl is the quoted ('') relative or absolute url of the html file to load.
//		imageWidth and imageHeight specify the image size in pixels
//
// Author:	dom@thoth.org 2004-08-05
//
// Do not remove this notice.

function myURLWindow(imageUrl, initWidth, initHeight) {

	var imageWidth = initWidth;
	var imageHeight = initHeight;
	var screenWidth = screen.width;
	var screenHeight = screen.height;

	if ((imageWidth + 30 > screenWidth) || (imageHeight + 60 > screenHeight)) {
		if (imageWidth + 20 > screenWidth - 80) {var imageWidth = screenWidth - 80;}
		else {var imageWidth = imageWidth + 20;}
		if (imageHeight + 20 > screenHeight - 110) {var imageHeight = screenHeight - 110;}
		else {var imageHeight = imageHeight + 20;}
		var optScroll = "scrollbars=yes,resizable=yes";
	}
	else {
		var imageWidth = imageWidth;
	    	var imageHeight = imageHeight;
		var optScroll = "scrollbars=yes,resizable=yes";
	}

	var initX = (screenWidth-imageWidth)/2;
	var initY = (screenHeight-imageHeight)/2 - 10;
	var optWin = optScroll+",width="+imageWidth+",height="+imageHeight+",screenX="+initX+",screenY="+initY+",left="+initX+",top="+initY;

	imageWin = window.open(imageUrl,"Image", optWin);
	void imageWin.focus( );
}

// ------------------------------------------------------------------------------------------------
