/*
$Id: pint_popupwindowDEBUG.js,v 1.4 2003/04/09 01:55:48 cory Exp $

Creator: J. Brock

Description:
	Pop up a new window

Dependancies:
	none

Usage:
	TODO:
*/

/*************************************** global variables *****************************/

var PINTPW_capablePopupWin = true; // assume popup window capable
var PINTPW_popAnchors;
PINTPW_capablePopupWin = ((PINTPW_popAnchors = new Array()) ? true : false );

var PINTPW_featureBasic = 'alwaysLowered=no,alwaysRaised=no,dependent=yes,directories=no,hotkeys=no,'; // features that all popup windows will have
var PINTPW_featureNoChrome = 'location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,'; // features that no chrome popup windows will have

//enumerated constant types for poptype
var PINTPW_FULLCHROME = 5;
var PINTPW_NOCHROME = 6;

//enumerated constant types for positioning
var PINTPW_SCREENCENTER = 10;
var PINTPW_WINDOWCENTER = 11;
var PINTPW_FREE = 12;

/************************************* public methods ****************************/


function PINTPW_InitPopupWinFullChrome(anchorid, newurl, windowname, featurestring)
{
	PINTPW_InitPopupWin(anchorid, newurl, windowname, FULLCHROME, featurestring);
}


/*********************************************************
function PINTPW_InitPopupWin
Initializes an anchor to popup a new browser window onclick. 
To make popup windows re-use themselves, give them all the same name.
Arguments:
	1. name/id of an anchor element
	2. url to open in new browser window
	3. name of new browser window, or '' (null string)
	4. extra feature string as passed to window.open, or '' (null string)
Returns: false, to cancel the anchor href
*/
function PINTPW_InitPopupWin(anchorid, newurl, windowname, poptype, popWidth, popHeight, positioning, featurestring)
{
	if (!(PINTPW_capablePopupWin)) return false;
	if (!(window)) return false;	

	if (PINTPW_popAnchors[anchorid]) return false; // already a popup window attatched to this anchor

	PINTPW_popAnchors[anchorid] = new Array();
	PINTPW_popAnchors[anchorid]['newurl'] = newurl;
	PINTPW_popAnchors[anchorid]['windowname'] = windowname;
	PINTPW_popAnchors[anchorid]['poptype'] = poptype;
	PINTPW_popAnchors[anchorid]['popWidth'] = popWidth;
	PINTPW_popAnchors[anchorid]['popHeight'] = popHeight;
	PINTPW_popAnchors[anchorid]['positioning'] = positioning;
	PINTPW_popAnchors[anchorid]['featurestring'] = featurestring;

	alert( anchorid );
	document.anchors[anchorid].onclick = PINTPW_Pop;
	//document.forms['formname'][anchorid].onclick = PINTPW_PopH;
	return false;
}


/*************************************************************
PINTPW_InitPopupWinNoChrome
Initializes an anchor element that, onclick, pops up a no-chrome window to specification. 
To make popup windows re-use themselves, give them all the same name.
Arguments:
	1. name/id of an anchor element
	2. url to open in window
	3. name of new browser window, or '' (null string)
	4. horizontal size of new window in pixels
	5. vertical size of new window in pixels
	6. constant indicating the positioning of the new window. Possible values:
		PINTPW_SCREENCENTER	centered in screen
		PINTPW_WINDOWCENTER	centered in parent browser window
		PINTPW_FREE		pops up wherever the client feels like it
Returns: always false
*/
function PINTPW_InitPopupWinNoChrome(anchorid, newurl, windowname, popWidth, popHeight, positioning)
{
	if (!(PINTPW_capablePopupWin)) return false;
	if (!(window)) return false;	

	return PINTPW_InitPopupWin(anchorid, newurl, windowname, PINTPW_NOCHROME, popWidth, popHeight, positioning, '');
}

function PINTPW_Pop(newurl, windowname, poptype, popWidth, popHeight, positioning, featurestring)
	{
	var winLeft, winTop, winWidth, winHeight;
	var newXlocation, newYlocation;
	var allfeature = PINTPW_featureBasic;

	if (popWidth && popHeight)
		{
		allfeature += 
		'innerWidth=' + popWidth + ',' +
		'innerHeight=' + popHeight + ',' +
		'width=' + popWidth + ',' +
		'height=' + popHeight + ',';

		if( positioning == PINTPW_SCREENCENTER )
			{
			if (screen)
				{
				winWidth = screen.availWidth;// only in netscape?
				winHeight = screen.availHeight;
				winLeft = 0;
				winTop = 0;

				if (winWidth)
					{
					newXlocation = Math.floor(((winWidth - popWidth) / 2) + winLeft);
					newYlocation = Math.floor(((winHeight - popHeight) / 2) + winTop);
					allfeature += 'left=' + newXlocation + ','; // for ie
					allfeature += 'top=' + newYlocation + ',';
					allfeature += 'screenx=' + newXlocation + ','; //for netscape
					allfeature += 'screeny=' + newYlocation + ',';
					}					
				}
			}
		else if( positioning ==	PINTPW_WINDOWCENTER )
			{
			if (window.innerWidth)// only netscape can do window centering
				{
				winLeft = (window.screenLeft || window.screenX);
				winTop = (window.screenTop || window.screenY);
				winWidth = (window.innerWidth || window.width ); 
				winHeight = (window.innerHeight || window.height);
				}
			else // so do screen centering instead
				{
				winWidth = screen.availWidth;
				winHeight = screen.availHeight;
				winLeft = 0;
				winTop = 0;
				}

			if (winWidth)
				{
				newXlocation = Math.floor(((winWidth - popWidth) / 2) + winLeft);
				newYlocation = Math.floor(((winHeight - popHeight) / 2) + winTop);
				allfeature += 'left=' + newXlocation + ','; // for ie
				allfeature += 'top=' + newYlocation + ',';
				allfeature += 'screenx=' + newXlocation + ','; //for netscape
				allfeature += 'screeny=' + newYlocation + ',';
				}					
			}
		}
	if (poptype == PINTPW_NOCHROME)
		{
		allfeature += PINTPW_featureNoChrome;
		}
	allfeature += featurestring;
	return window.open(newurl, windowname, allfeature);
	}


/********************************** private methods ****************************/



function PINTPW_PopH(e)
{
	if (!(PINTPW_capablePopupWin)) return false;

	var eventSource;
	if (!(eventSource = PINT_GetEventSource(e))) return false;
//	alert(eventSource.name);
	var anchorname;
	if (!(anchorname = eventSource.name)) return false;

	return (PINTPW_popAnchors[anchorname] ?
		PINTPW_Pop(
			PINTPW_popAnchors[anchorname]['newurl'], 
			PINTPW_popAnchors[anchorname]['windowname'], 
			PINTPW_popAnchors[anchorname]['poptype'], 
			PINTPW_popAnchors[anchorname]['popWidth'], 
			PINTPW_popAnchors[anchorname]['popHeight'], 
			PINTPW_popAnchors[anchorname]['positioning'], 
			PINTPW_popAnchors[anchorname]['featurestring']
		) : false );


/*	if (PINTPW_popAnchors[anchorname])
	{
		alert(PINTPW_popAnchors[anchorname]['featurestring']);
		window.open(PINTPW_popAnchors[anchorname]['newurl'], PINTPW_popAnchors[anchorname]['windowname'], PINTPW_popAnchors[anchorname]['featurestring']);
	}

	return false;*/
}

// old school popup for projector calculator //

function pop_up(location,width,height) {	
 window.open( location , 'pop_up_window' , eval("'status=no,location=no,menubar=no,toolbar=no,resizable=no,scrollbars=no," + "width=" + width + ",height=" + height + "'"));
}
