// file name: window_handling.js 
// Generic External Window Handling Functions
// Joseph Astrue (joe@astrue.com)
var newWindow1	= null;
var popUpWin	= null;
// -----------------------------------------------------------------------------
// openExtWin - Call this function from anywhere on the page, where you
// 		would otherwise use an HTML HREF anchor.  This function
// 		will open the link in a separate window that has no chrome
// 		so that the user will remain fixed to the site while off on a
// 		temporary tangent.  If the external site window is already
// 		open, this will just populate it with the new URL.  If it has
// 		been used and closed, this will reopen it with the new URL.
// urlarg	= URL of the desired target (Required)
// -----------------------------------------------------------------------------

function openExtWin(urlarg) {
	var argconst = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
	var argstrfeat = '"' + argconst + '"';
	if (newWindow1 && newWindow1.open) {
		if (newWindow1.closed) {
			newWindow1 = null;
		newWindow1 = window.open(urlarg,"extwin1",argstrfeat);
		} else {
			newWindow1.location.href = urlarg;
		} 
	} else {
		newWindow1 = window.open(urlarg,"extwin1",argstrfeat);
	}
}

// -----------------------------------------------------------------------------
// openPopUp - Call this function from the onLoad event handler for the
// 		page, so that it pops up a text window.  Use the
// 		closePopUp function to close the text window.
// urlarg	= URL of the desired pop-up window (Required)
// x		= x-coordinate [from left] of pop-up window (Optional, default to 20)
// y		= y-coordinate [from top] of pop-up window (Optional, default to 20)
// h		= height of pop-up window (Optional, default to 500)
// w		= width of pop-up window (Optional, default to 700)
// -----------------------------------------------------------------------------

function openPopUp (urlarg, x, y, h, w) {
	var argstrurl = '"' + urlarg + '"';
	var argconst = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes";
	var argx = ",screenX=";
	var argy = ",screenY=";
	var argl = ",left=";
	var argt = ",top=";
	var argh = ",height=";
	var argw = ",width=";
	var argih = ",innerHeight=";
	var argiw = ",innerWidth=";

	if (x) {
		argl += x;
		argx += x;
	} else {
		argl += "20";
		argx += "20";
	}

	if (y) {
		argt += y;
		argy += y;
	} else {
		argt += "20";
		argy += "20";
	}

	if (h) {
		var intih = parseInt(h) - 4;
		argh += h;
		argih += intih;
	} else {
		argh += "500";
		argih += "496";
	}

	if (w) {
		var intiw = parseInt(w) - 4;
		argw += w;
		argiw += intiw;
	} else {
		argw += "700";
		argiw += "696";
	}

	var argstrfeat = '"' + argconst + argh + argw + argih + argiw + argx + argy + argl + argt + '"';

	if (popUpWin && popUpWin.open) {
		if (popUpWin.closed) {
			popUpWin = null;
			popUpWin = window.open(argstrurl,"popUpWindow",argstrfeat);
		}
	} else {
		popUpWin = window.open(urlarg,"popUpWindow",argstrfeat);
	}
}

// -----------------------------------------------------------------------------
// closePopUp - Call this function from the onUnload event handler for the
// 		page, so that it closes the pop-up text window when the
// 		parent window is unloaded from the browser.
// (no arguments)
// -----------------------------------------------------------------------------

function closePopUp () {
	if (popUpWin && popUpWin.open && ! popUpWin.closed) popUpWin.close()
}
