
// Global variables
var crlf = "\n";
var br = "<br>";
var oScript = "<script ";
var cScript = "</script>";
var docT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
var docO = "<html>" + crlf + "<head>";
var docC = "</body>" + crlf + "</html>";

function openWindow(winSize,painting,altText)
{
	// Parameters 
	// P1 = Window Features -- size or other features, as per scripting language
	// P2 = Painting Name   -- Folder and name of picture to be displayed
	// P3 = ALT Text        -- For browsers that cannot display pictures

	var newWindow;          // Place holder for the new window name
	var txt = "";           // Stores the HTML mark-up for the new page
	var newAltText = "";    // Place holder for alternate text describing the painting
	var title = "";         // Place holder for a title for the page
	var winName = "";       // Container for completed window name

	winName = newWinName("Painting", "Window");

	// Default if no "alt" text is provided
	if(altText == "")
	{
		newAltText = "Large View of Painting";
	}
	else
	{
		newAltText = altText;
	}

	// Use the alt text if provided, otherwise the default title
	if(altText != "")
	{
		title = "Large View of " + altText;
	}
	else
	{
		title = "Large view of Painting";
	}

	// Construct the document contents for displaying the large scale painting
	txt += docT + crlf;
	txt += docO + crlf;
	txt += crlf + "<Title>" + title + "</title>";
	txt += crlf + "<style>";
	txt += crlf + "body";
	txt += crlf + "{";
	txt += crlf + "background-color: #B1AC97;";
	txt += crlf + "background-image: none;";
	txt += crlf + "margin: 0pt;";
	txt += crlf + "padding: 0pt;";
	txt += crlf + "text-align: center;";
	txt += crlf + "vertical-align: middle;";
	txt += crlf + "}";
	txt += crlf + "</style>";
	txt += crlf + "</head>";
	txt += crlf + "<body>";
	txt += crlf + "<img src='" + painting + "' alt='" + newAltText + "' border='0'>";
	txt += crlf;
	txt += docC + crlf;

	// Open the new window and put in the document contents and painting
	newWindow = window.open("",winName,winSize);
	newWindow.document.write(txt);
	newWindow.document.close();

	// When the window contents are loaded give it the focus
	newWindow.focus();
}

function newWinName(txt1,txt2)
{
	// Each window name must be unique so generate random numbers
	// to append to the window name and put the current milliseconds
	// between "Picture" and "Window" allowing a number of windows to
	// be open at the same time without a conflict of names.

	var winName = ""; // Container for completed window name
	var num1 = 0;     // Three random numbers between 1 and 10
	var num2 = 0;     // The number may be from 111 to 999999
	var num3 = 0;     // which should insure unique window names
	var str = "";     // The three random numbers are added into a string
	var dat = "";     // Container for the current date
	var msc = 0;      // Current millisecond count between 0 and 999

	num1 = Math.round((Math.random() * 10) + 1); 
	num2 = Math.round((Math.random() * 10) + 1); 
	num3 = Math.round((Math.random() * 10) + 1); 
	str  = num1.toString(); 
	str += num2.toString(); 
	str += num3.toString();
	dat  = new Date();
	msc  = dat.getMilliseconds();
	winName = txt1 + msc + txt2 + str;

	//alert("New window name is: " + winName);

	return( winName );

}

