// Multiple window.onload functions and body onLoad="this_included_too()"
var aSafeOnload = new Array();
function fSafeAddOnload(fFunctionName) { // v2.0.2 2005-02-23; like:; req: fSafeOnload;
	if (window.addEventListener) { // W3C, Firefox
		window.addEventListener('load',fFunctionName,false)
	} else if (document.addEventListener) { // W3C, Opera
		document.addEventListener('load',fFunctionName,false)
	} else if (document.attachEvent) { // IE
		window.attachEvent('onload',fFunctionName)
	} else { // Mac IE 4.5 blows out on testing window.onload
		window.onload = fSafeOnload;
		aSafeOnload[aSafeOnload.length] = fFunctionName;
	}
}
function fSafeOnload() { // v1.01 2003-11-10; like: fSafeAddOnload; req:;
	for (var i=0;i<aSafeOnload.length;i++)
		aSafeOnload[i]();
}
function fOpenWin(sURL,iW,iH,sName,bScrollBars) { // v1.5.1 2005-10-14; like:; req:;
	iXPos=0, iYPos=15;
	if (window.innerWidth) { // NN4, NN6, O7
		iXPos = (window.innerWidth-iW)/2;
		iYPos = (window.innerHeight-iH)/2;
		iXPos+=window.screenX; iYPos+=window.screenY;
	} else {	// screen width (1 600) not used because I want centred in window on screen
		iXPos = (document.body.clientWidth-iW)/2;	// current window width (800) - new window width (400) / 2 = 200 on each side
		iBrowserHeight = (document.compatMode=="CSS1Compat")?document.documentElement.clientHeight:document.body.clientHeight;
		iYPos = (iBrowserHeight-iH)/2;
		iXPos+=window.screenLeft; iYPos+=window.screenTop;	// current position of window (400) + iXPos (200) = 600 is left pos
	} // left space (600) + new width (400) + right space (600) = screen res (1 600)

	if (typeof bScrollBars == 'boolean')
		bScrollBars = (bScrollBars==true)?'yes':'no';
	else
		bScrollBars = 'yes' // not defined set to default

	sArgs="width=" +iW+ ",height=" +iH+ ",resizable=yes,scrollbars=" +bScrollBars+ ",status=yes,screenx=" +iXPos+ ",screeny=" +iYPos+ ",left=" +iXPos+ ",top=" +iYPos
	if (!sName) sName = 'popup';
	oWin=window.open(sURL,sName,sArgs);

	if (oWin != null) {
		if (oWin.opener == null) // give orphan child window this parent
			oWin.opener = self;
		oWin.focus()
	}
}
function fApplyLinkBehaviour(sContainerName) { // v1.5.6 2004-10-10; like:fSafeAddOnload; req:fPopupFromTarget(v1.3);
	// sContainerName (optional)
	if (!document.getElementsByTagName) return;
	if (typeof(sContainerName) == 'string') // if page too large force links to behave
		var tAs = document.getElementById(sContainerName).getElementsByTagName('a');
	else // check enitre document
		var tAs = document.getElementsByTagName('a');

	for (i=0; i<tAs.length; i++) {
		tA = tAs[i];
		if (tA.target) {
			if (tA.target == 'fresh')
				tA.target = '_blank';
			else if (tA.target.indexOf('popup') != -1)
				tA.onclick = fPopupFromTarget;
			else if (tA.target == 'self')
				tA.target = '_self';
		} else if (tA.href) { // force PDF into new window, unless target set to self
			if (tA.href.indexOf('.pdf') != -1)
				tA.target = '_blank';
		}
	}
}
fSafeAddOnload(fApplyLinkBehaviour);

function fPopupFromTarget(oA) { // v1.5.0 2005-10-14; like:fApplyLinkBehaviour(v1.5); req:fOpenWin(v1.4);
	oSelf = (this.target) ? this : oA; // if onlick from fApplyLinkBehaviour use THIS else hardcoded onclick use oA (hardcoded as 'this')
	sWinHref = oSelf.href.toString();
	aWinArgs = oSelf.target.split(':');
	sWinTitle = (aWinArgs.length > 3) ? aWinArgs[3] : 'popup'; // window name = fourth argument

	aFilename = sWinHref.split('.');
	sFileType = aFilename[aFilename.length-1];
	
	if (sFileType == "jpg" || sFileType == "gif" || sFileType == "png") { // if image then no scrollbars
		bScrollBars = false; // hide scrollbars with image cuz each browser has different padding
		iImgWinEnlargeOffset = 20; // add this # to w,h cuz opening a win. without HTML (ie img), each browser adds margin/padding
	} else {
		bScrollBars = true;
		iImgWinEnlargeOffset = 0;
	}

	if (aWinArgs[4] == "false") // passed argument precedence over image file type
		bScrollBars = false;
	else
		bScrollBars = true;

	fOpenWin(sWinHref,parseInt(aWinArgs[1])+iImgWinEnlargeOffset,parseInt(aWinArgs[2])+iImgWinEnlargeOffset,sWinTitle,bScrollBars) // href, width, height, name, scrollbars
	return false; // prevent href and target from HTML launching second window
}
function fFreshFormField(oFormField) { // v1.0.0 2004-10-04; like:; req:;
	if (oFormField.value == oFormField.defaultValue) oFormField.value = "";
}