/*
	Script: popup.js

	Copyright: Fishnet NewMedia (c) 2003

	Create: 04.01.03

	Version: 1.0

	Compatibility: JavaScript 1.1

	Functions: none

	Changes: none

	Description:  

	   This script is backwards-compatible for creating popup windows.
	   Any version 3+ browser will support the javascript features used
	   to create a new window with the parameters specified, unsupported
	   browsers will create a new window as if target="_blank" were used.

	   Opening a page in a new window:

		   <A href="PAGENAME" target="popup:width=500,height=400,toolbar">LINK</A>

	   Opening a page in an existing window:

		   <A href="PAGENAME" target="popup:width=500,height=400,toolbar:WINDOWNAME">LINK</A>

	   "WINDOWNAME" is that name of the target window,
	   "LINK" is the linkable image or text content and
	   "PAGENAME" is the name of the page to be loaded

	   The script also contains PopUp() a function for manually calling
	   a new popup window.  This script is useful for creating windows
	   triggered by events, such as onload or onunload.

*/

// This function must be called from the onload for the AutoPopUp() function to operate
// This function traverses the page links and any link whose target contains the string 
// "popup" sets an onclick attribute whose action is the AutoPopUp() function.
function InitPopUp() {
	var link;
	for (var i = 0; (link = document.links[i]); i++) {
		if (link.target && link.target.indexOf("popup") == 0) link.onclick = AutoPopUp;
	}
}


// This function is called by the onclick event assigned to a link by the InitPopUp() function
// The function parses the caller link's target value extracting the window parameters and name
// values.  If no values are defined, a random number is assigned for the window name, and
// the window's parameters are assigned generic values.
function AutoPopUp() {
	// collect attributes
	var link = this.target.split(":");
	var parameters = link[1] ? link[1] : "width=400,height=300,resizable=yes,scrollbars=yes,menubar=yes";
	var windowname = link[2] ? link[2] : Math.round(Math.random() * 1000000000);
	// open popup window
	var newWin = window.open(this.href, windowname, parameters);
	// set focus on the new window
	if (newWin) newWin.focus();
	// cancel links href action
	return false;
}

// This function is for manually creating a popup window using the "javascript:" pseudo-protocol 
// specifier to initiate the function from a link's href attribute value or using an event action
// such as onload, or onunload
function PopUp(URL,Name,w,h,a,t) {
	// collect attributes
	var winN = Name ? Name : Math.round(Math.random() * 1000000000);
	var winW = w ? w : 400;
	var winH = h ? h : 300;
	var aVal = a ? a : "yes";
	var tVal = t ? t : "yes";
	// open popup window
	var win = window.open(URL,winN,'width=' + winW + ',height=' + winH + ',resizable=' + aVal + ',scrollbars=' + aVal + ',toolbar=' + tVal);
	// set focus on the new window
	if (win) win.focus();
}
