//	<SCRIPT TYPE="text/javascript" LANGUAGE="JAVASCRIPT">

//--------------------------------------------------------------------------------
//
// determine which browser being used

var w3c=(document.getElementById)?true:false;

var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;

var ns4=(document.layers)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;

//--------------------------------------------------------------------------------
//
// used for "pushing" the name into another browser window

var push_win;
var push_name;
var push_block = 0;

function push ()
{
//	alert ("push:\n"
//		+ "push_name = " + push_name + "\n"
//		+ "push_win =  " + push_win + "\n"
//		+ "typeof push_win =  " + (typeof push_win) + "\n"
//	);

	if (push_block) return true;

	push_block = 1;

	if	(	(typeof push_win != "undefined")
		&&	!push_win.closed
		)
		push_win.name = push_name;

	push_block = 0;
}

//--------------------------------------------------------------------------------
//
// to determine the position at the page level of an element

function getPageLeft(el)
{
	var x;
	if(ns4) return el.pageX;

	if(ie4||w3c)
	{
		x = 0;
		while(el.offsetParent!=null)
		{
			x+=el.offsetLeft;
			el=el.offsetParent;
		}
		x+=el.offsetLeft;
		return x;
	}
}

function getPageTop(el)
{
	if(ns4) return el.pageY;

	if(ie4||w3c)
	{
		var y = 0;

		while(el.offsetParent!=null)
		{
			y+=el.offsetTop;
			el=el.offsetParent;
		}

		y+=el.offsetTop;
		
		return y;
	}
}

//--------------------------------------------------------------------------------
//
// to set the focus of a named window

function win_focus (win_name, feature_param, obj)
{
	var feature_base = ""
			+ "location=no,"
			+ "menubar=no,"
			+ "resizable=yes,"
			+ "scrollbars=yes,"
			+ "toolbar=no,"
			+ "height=450,"
			+ "width=650,"
			+ "left=50,"
			;

	if (feature_param == null) feature_param = "";

	var features = feature_base + feature_param;

	if (0) alert
	(	""
		+ "win_name = '"             + win_name             + "';\n"
		+ "push_win = '"             + push_win             + "';\n"
		+ "do_please_wait = '"       + do_please_wait       + "';\n"
		+ "features = '"             + features             + "';\n"
	);

	if (win_name != "")
	{
//		alert ("focusing on: '" + win_name + "'");
		var vwin	= window.open ('', win_name, features);
		vwin.focus();

		push_win   = vwin;
		push_name  = win_name;
		push_block = 0;

		var i = 1;
		while (i <= (10 * 1000))		// for X seconds...
		{
			setTimeout ("push()", i);
			i += 100;						// every X millisec...
		}
	}
}

//--------------------------------------------------------------------------------
//
// support content links
//

var	wait 			= new function (){};
	wait.notice		= null;

wait.flash = function (object, time)
{
	// check parameters

		if	(	(!object)
			||	(time <= 0)
			)
			return (alert ("wait.flash(): bad parameters"), false);

	// find the wait notice object

		if	(	(!wait.notice)
			&&	(!(wait.notice = document.all['NOTICE-WAIT']))
			)
			return (alert ("wait.flash(): can't find NOTICE-WAIT"), false);

	// position wait notice

		wait.notice.style.visibility = "visible";
		wait.notice.style.left = 10 + getPageLeft (object);
		wait.notice.style.top  = 20 + getPageTop  (object);

	// set for turn off

		setTimeout ("wait.notice.style.visibility = \"hidden\"", time);

	return true;
}

var	content					= new function () { };
	content.winobj			= null;
	content.name			= null;
	content.features		= null;
	content.anchor			= null;
	content.feature_base	= ""
		+ "location=no,"
		+ "menubar=yes,"
		+ "resizable=yes,"
		+ "scrollbars=yes,"
		+ "toolbar=yes,"
		+ "height=450,"
		+ "width=650,"
		+ "left=50,"
		;

content.mouseout = function (anchor_object)
{
	window.status = "";
	return true;
}

content.mouseover = function (anchor_object)
{
	window.status = anchor_object.href;
	return true;
}

content.click = function (window_name, window_features, anchor_object)
{
	if (0) window.status = ""
		+ "TARGET: "   + window_name        + "; "
		+ "FEATURES: " + window_features    + "; "
		+ "LINK: "     + anchor_object.href + "; "
		;

	if (window_name == "")
	{
		alert ("Internal failure: content.click(): empty window name");
		return false;
	}

	// save relevant info in the content holder

		content.name		= window_name;
		content.features	= window_features;
		content.anchor		= anchor_object;

	// flash the "Please Wait..."

		wait.flash (anchor_object, 1500);

	// transfer to the showit helper (give time for wait to flash up)

		setTimeout ("content.click_pop()", 100);

	// stop the browser from processing the click

		return false;
}

content.click_pop = function ()
{
//		// create window if needed
//	
//			if	(	! content.winobj
//				||	content.winobj.closed
//				)
//			{
//				content.winobj =
//					window.open ('', content.name, (content.feature_base + content.features));
//			}

		var features = content.feature_base + content.features;

		if (0) alert ("features = " + features);

		content.winobj =
			window.open ('', content.name, features);

		content.winobj.focus();

	// push window name (vs. content page self.name = "xxx")

		content.push.block = 0;

		var i = 1;
		while (i <= (10 * 1000))		// for X seconds...
		{
			setTimeout ("content.push.action()", i);
			i += 100;						// every X millisec...
		}

	if (typeof (content.anchor.href) != "undefined")
	{
		// possibly send the URL thru our redirector

			if (0) alert (""
				+ "typeof (anchor.href) = " + (typeof content.anchor.href) + ";\n"
				);

			var url = content.anchor.href;

			if	(	(typeof redirector == "string")
				&&	(redirector != "")
				)
			{
				url = redirector + "?mode=redir"
					+ "&" +	"ref="		+ escape (window.location)
					+ "&" + "nexturl="	+ escape (url)
					;
			}

			if (0) alert (""
				+ "url = " + url
				);

		// send the link URL to the content window

			content.winobj.location = url;
	}
}

content.push = new function () {};

content.push.action = function () 
{
	if (content.push.block++) return;

	if	(	content.winobj
		&&	!content.winobj.closed
		)
		content.winobj.name = content.name;

	content.push.block = 0;
}


//--------------------------------------------------------------------------------
//
// manage window resizing
//
//	EXTERNAL VARS:
//
//		window_min_width
//		window_min_height	

function win_resize_event (e)
{
	var wm = window_min_width ;
	var hm = window_min_height;

	var wo = window.document.body.clientWidth;
	var ho = window.document.body.clientHeight;

	var wm = (wo < wm) ? wm : wo;
	var hm = (ho < hm) ? hm : ho;

	/*
	alert (
		"width = "  + wo + "; "
		+
		"height = " + ho + "; "
		+
		""
	);
	*/

	if (wm == wo && hm == ho)	return true;

	self.resizeTo (wm, hm);

	var wr = window.document.body.clientWidth;
	var hr = window.document.body.clientHeight;

	var wt = wm + (wm - wr);
	var ht = hm + (hm - hr);

	self.resizeTo (wt, ht);

	return false;
}

window.onresize = win_resize_event;

// EOF
