/****************************

 Global JavaScript functions and conditions for CADDIE projects
 Version:
 	0.1 Beta 1, Aug 25, 2005

 Usage:
 	This file must be included within <body>
	<script type="text/javascript" src="global.js"></script>

****************************/




/****************************
 Global variables for CADDIE sites.
****************************/
if (!documentRoot) var documentRoot = '/';
if (!graphicsRoot) var graphicsRoot = documentRoot + '_graphics/';
if (!linkRoot) var linkRoot = documentRoot + '_link/';
if (!flashRoot) var flashRoot = documentRoot + '_flash/';
if (!calendarRoot) var calendarRoot = documentRoot + '_calendar/';
if (!mailing_listsRoot) var mailing_listsRoot = documentRoot + '_mailing_lists/';

// Optional DeBugging Output, set to 1 or true for output window
if (!dbo) var dbo = 0;




/****************************
 documentOnloadQ()
 
 How it works:
 Create a queue of functions to run once the window has loaded all
 HTML-specified content
 
 Use:
 	function documentOnloadQ()
	{
		functionToExecute();
		anotherFunctionToExecute();
		anotherFunctionTo... and so on...
	}
 	window.onload = documentOnloadQ; 

 Returns: n/a
****************************/
function documentOnloadQ()
{
}
window.onload = documentOnloadQ; 




/****************************
 createDbo()
 
 How it works:
 Creates textarea#debugoutput, appended within <body> based on if (dbo == 1).
 
 Use:
 	var dbo = 1;
 	createDbo()
 	dbo.value += 'This will append a line to the dbo box for all to see\n'

 Returns: n/a
****************************/
if (dbo == 1)
{
	// create textarea.dbo node for placement
	dbo = document.createElement('textarea');
	dbo.id = 'debugoutput';
	dbo.wrap = 'off';
	dbo.style.position = 'fixed';
	dbo.style.left = '10px';
	dbo.style.bottom = '10px';
	dbo.style.height = '100px';
	dbo.style.width = '98%';
	dbo.style.zIndex = '50000';
	dbo.style.backgroundColor = '#eeeeee';
	dbo.style.borderWidth = '1px';
	dbo.style.borderStyle = 'solid';
	dbo.style.borderColor = '#999999';
	dbo.style.padding = '2px';
	dbo.style.overflow = 'auto';
	document.getElementsByTagName('body').item(0).appendChild(dbo);
	document.getElementsByTagName('body').item(0).style.paddingBottom = dbo.style.height;
	dbo = document.getElementById('debugoutput');
	dbo.value += ("dbo created successfully!\n");
}
else if (dbo == 'undefinded')
{
	dbo = new Array();
}





/****************************
 Functions for JS popup windows.

 Usage:
 	<a href="javascript: popup('whichType', [arguments0], [arguments1], ... );">
****************************/
function popup (whichType, postArgs)
{
	var openerURI;
	var openerArgs = 'toolbar=1,status=1,resizable=1,scrollbars=1';
	switch (whichType)
	{
		case 'aboutprinting' :
			openerURI = documentRoot + '_printpopup.phtml';
			if (postArgs) openerURI += '?' + postArgs;
			openerArgs += ',height=410,width=600';
			break;

		case 'aboutacrobat' :
			openerURI = documentRoot + '_acrobatpopup.phtml';
			if (postArgs) openerURI += '?' + postArgs;
			openerArgs += ',height=410,width=600';
			break;

		case 'calendar' :
			openerURI = calendarRoot + 'calendar.phtml';
			if (postArgs) openerURI += '?' + postArgs;
			openerArgs += ',height=460,width=600';
			break;

		case 'mailinglist' :
			openerURI = mailing_listsRoot;
			if (postArgs) openerURI += '?mailing_list_id=' + postArgs;
			openerArgs += ',height=410,width=600';
			break;

		case 'newsletter' :
			openerURI = documentRoot;
			if (postArgs && ('archive' == postArgs))
			{
				openerURI += '_archive_newsletter.phtml';
			}
			else if (postArgs)
			{
				openerURI = mailing_listsRoot + '?mailing_list_id=' + postArgs;
			}
			else
			{
				openerURI += '_current_newsletter.phtml';
			}
			openerArgs += ',height=410,width=600';
			break;

		case 'privacypolicy' :
			openerURI = documentRoot + '_privacypolicy.phtml';
			if (postArgs) openerURI += '?' + postArgs;
			openerArgs += ',height=410,width=600';
			break;

		case "image" :
			openerURI = documentRoot + '_popup.phtml?whatType=image&&imageURL=' + arguments[1] + '&&';
			openerArgs = 'toolbar=1,status=0,scrollbars=1,resizable=1,height=320,width=400';
			break;

		case 'register' :
			openerURI = documentRoot + 'event_registration/?special_event_id=';
			if (postArgs) openerURI += postArgs;
			openerArgs += ',height=410,width=600';
			break;

		default :
			return false;
	}
	window.open(openerURI, whichType, openerArgs);
	return false;
}


// Opens a URL in opener window, and brings window to foreground
// Usage: <a href="javascript: openInOpeneer(this, 'http://www.URL.com');">
function openInOpeneer (whereFrom, openerURI)
{
	whereFrom.opener.location = openerURI;
	whereFrom.opener.focus();
}


// Resizes window to fit #theImage width and height properties
// Usage: <body onload="resize2img()"> <img id="theImage">
function resize2img ()
{
	if(document.getElementById)
	{
		window.resizeTo(document.getElementById('theImage').width + 40, document.getElementById('theImage').height + 90 );
	}
}







/****************************
 Loaded Announce
****************************/
dbo.value += ("global.js loaded!\n");