         
/***************************************************************************** 
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
	 Modified to load content using "newWindow.location.href=url" by M. Anderson-Smith 11-7-2003
	 in Anchorage, Alaska for use in AnalogicalPlanet.com
*****************************************************************************/
  
  /* This makeNewWindow(url) function creates a new window, recieves the variable "url" and loads it into the new window. If the newWindow already exists then it loads into the existing window. The function then brings newWindow to the front using newWindow.focus(). I am using this window to display the Glossary .  */
  
// global variable for subwindow reference
var newWindow;
// generate and fill the new window
function makeNewWindow(url) {
    // make sure it isn't already opened
    if (!newWindow || newWindow.closed) {
        newWindow = window.open(url,"sub","toolbar=yes,scrollbars=yes,resizable=yes,height=175,width=400");
		newWindow.focus();
        // delay writing until window exists in IE/Windows
		/* comment out writeToWindow which I believe needs a string parameter (as if from a form field). I'm passing a url.
        setTimeout("writeToWindow()", 50); */
    } else if (newWindow.focus) {
        // window is already open and focusable, so bring it to the front
        newWindow.focus();
		//load new url to newWindow
		newWindow.location.href=url
    }
}

/*** Use this script in a web page by passing the variable ('url') in the makeNewWindow('url) function in a null javascript link or event handler.
<a href="javascript: ;makeNewWindow('Sample1.html')">Load Sample1 page</a>
Here's the preferred method using  the onclick event handler:
<a href="EncapsulationQuotes.html#Hooke" class="sideLink" 		onclick="makeSideBarWindow(this.href); return false;">more</a>
***/


/*****************************************************************************/
/***This script defines my makeSideBarWindow(url)function. It is an alternate and hopefully faster way of creating a sub-window, loading a frameset, and populating the frames. This is based on the script, makeBarWindow, in test.js and follows exactly the same logic except I am writing the HTML for the frameset to the sub-window using the document.write() method. Remove the comment marks to write the HTML for the navigation bar to the historyFrame of the frameset. Finally I load the url that was passed as an argument of my  makeSideBarWindow(url) function into the mainFrame of the frameset.  ***/

// global variable for subwindow reference
var subWindow;
//global variable to make url available to other functions
var url2; 
// generate and fill the new window
function makeSideBarWindow(url) {
    // make sure it isn't already opened
     if (!subWindow || subWindow.closed) {
	 	url2=url; //assign url to a global variable for use by other functions
		//open SidebarWindow with a blank ,"", document or with ../Sidebars/SideBarFrameset.html
        subWindow = window.open("","SidebarWindow","toolbar=1,scrollbars=yes,resizable=yes,height=500,width=750");
		/*delay writing until window exists and frames are loaded.
		Set time delay to execute loading of  url until after SideBarFrameset.html if needed. 3000 is a typical value.*/
		//window.setTimeout("setlocation()",3000);
		/*I tried writeFramesetToWindow(). It was fast, but gave me problems with the browser's Back button going
		 to a blank page after the subWindow automatically closed (due to clicking in the main window). */
		window.setTimeout("writeFramesetToWindow()",100);
		window.setTimeout("setlocation()",200); /*I could'nt get this to work. Probably a problem with the global variable scope or something
		// subWindow.mainFrame.location.href=url; ***Same here.*/
		
		
		/***subWindow.mainFrame.location.href=url; doesn't work by itself because the frameset isn't built yet in the subWindow so I introduce a delay to allow the window with all it's objects to get built. Same goes if I write to the  subWindow.mainFrame--a delay is needed even for writing HTML to the page on the fly to allow the subWindow object to be completed.***/
		
		/***note: the names of the frames in SideBarFrameset.html are historyFrame and mainFrame ****/
     }   
     else if (subWindow.focus) {
	 	subWindow.focus();
        // window is already open and focusable, so load the url and bring it to the front
        subWindow.mainFrame.location.href=url;
		
    }
}


/*This function sets the url for the newly created window's mainFrame. It uses the location.replace() method to remove the blank source document (src="") from the history array that was originally created with the frameset src statements . */
function setlocation() {
		subWindow.focus();
		//set location for subWindow.mainFrame using the global variable,url2, initialized above
		subWindow.mainFrame.location.href=url2;
}	



function writeFramesetToWindow() {
		//assemble HTML content and assign it as a string to the variable NewContent. 
		//Write to subWindow.document to create the frameset.
		var newContent="<html>";
			newContent+="<head>";
			newContent+="<title>AnalogicalPlanet Sidebar</title>";		
			newContent+="<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
			newContent+="<script src='../../../analogicalplanet.js' language='Javascript' type='text/javascript'>";
			newContent+="</script>";
			newContent+="<link rel='stylesheet' href='../../../analogicalplanet.css' type='text/css'>";
			newContent+="</head>";
			newContent+="<frameset rows='20,*' frameborder='NO' border='0' framespacing='0' >";
  			newContent+="<frame name='historyFrame' scrolling='NO' MARGINWIDTH='0' MARGINHEIGHT='0' noresize src='../../../Images/ImagesSidebar/AnalogicalPlanetBar.gif' width='800' height='20' border='0' >";
  			newContent+="<frame name='mainFrame' MARGINWIDTH='0' MARGINHEIGHT='0 px' src='../../../Images/ImagesSidebar/TheEnd.gif' width='100 height='20' border='0''>";
			newContent+="</frameset>";
			newContent+="<noframes>"; 
			newContent+="<body bgcolor='#F9F7D9' text='#000000'>";
			newContent+="</body>";
			newContent+="</noframes>"; 
			newContent+="</html>";
	subWindow.document.write(newContent);
/*	//subWindow.document.close();
	//assemble HTML content for the subWindow.historyFrame 
	//and write to subWindow.historyFrame.document
		newContent="<html>";
		newContent+="<head>";
		newContent+="<title>AnalogicalPlanet historyFrame</title>";
		newContent+="<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
		newContent+="</head>";
		newContent+="<body bgcolor='#008040' text='#000000'>";
		newContent+="<img src='../../../Images/ImagesSidebar/AnalogicalPlanetBar.gif' width='240' height='20' border='0'>";
		newContent+="</body>";
		newContent+="</html>";
	subWindow.historyFrame.document.write(newContent);*/
	/*subWindow.document.close(); //close layout stream
	assemble HTML content for the subWindow.mainFrame 
	and write to subWindow.mainFrame.document*/
	/*	newContent="<html>";
		newContent+="<head>";
		newContent+="<title>AnalogicalPlanet mainFrame</title>";
		newContent+="<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
		newContent+="</head>";
		newContent+="<body bgcolor='#FFFFFF' text='#000000'>";
		newContent+="<img src='../../../Images/ImagesSidebar/TheEnd.gif' width='100 height='20' border='0'>";
		newContent+="</body>";
		newContent+="</html>";
	subWindow.mainFrame.document.write(newContent);*/
	subWindow.document.close(); //close layout stream 
	subWindow.focus(); 
}

function loadFrame(){
newContent="<html>";
		newContent+="<head>";
		newContent+="<title>AnalogicalPlanet historyFrame</title>";
		newContent+="<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
		newContent+="</head>";
		newContent+="<body bgcolor='#008040' text='#000000'>";
		newContent+="<img src='../../../Images/ImagesSidebar/AnalogicalPlanetBar.gif' width='240' height='20' border='0'>";
		newContent+="</body>";
		newContent+="</html>";
	subWindow.historyFrame.document.write(newContent);
	subWindow.document.close(); //close layout stream
}


/*************************************************************/
/* This is the function makeSideBarWindow2(url). I wrote it on Jan 8,2006. I'm trying to get a much simpler and more reliable window.Using my original sidebar function (makeSideBarWindow(url), Firefox and Netscape opened the new window but did not write the url to it unless the link was clicked a second time.  I am basing this new function exactly it on makeNewWindow(url) function that I use for the glossary. 
*/

// global variable for subwindow reference
var SideBarWindow;
// generate and fill the new window
function makeSideBarWindow2(url) {
    // make sure it isn't already opened
    if (!SideBarWindow || SideBarWindow.closed) {
        SideBarWindow = window.open(url,"sidebarWin", "toolbar=1, scrollbars=yes, resizable=yes, height=500,width=750");
		SideBarWindow.focus();
        // delay writing until window exists in IE/Windows
		/* comment out writeToWindow which I believe needs a string parameter (as if from a form field). I'm passing a url.
        setTimeout("writeToWindow()", 50); */
    } else if (SideBarWindow.focus) {
        // window is already open and focusable, so bring it to the front
        SideBarWindow.focus();
		//load new url to newWindow
		SideBarWindow.location.href=url
    }
}