

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




/*
 * 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 'photo' :
			openerURI = documentRoot + popup.arguments[1];
			var w = popup.arguments[2];
			var h = popup.arguments[3];
			
			var window_width = String(Number(w) + 20);
			var window_height = String(Number(h) + 20);
			var window_scroll = "no";
			if(screen.width)
			{
				if((Number(w) + 20) > screen.width)
				{
					window_width = String(Number(screen.width) - 80);
					window_scroll = "yes";
				}
				if((Number(h) + 20) > screen.height)
				{
					window_height = String(Number(screen.height) - 80);
					window_scroll = "yes";
				}
			}
			else
			{
				if(w > 560)
				{
					window_height = "560";
					window_scroll = "yes";
				}
				if(h > 400)
				{
					window_height = "400";
					window_scroll = "yes";
				}
			}
			openerArgs = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + window_scroll + ',resizable=1,copyhistory=0,height=' + window_height + ',width=' + window_width + ',top=10,left=10';
			break;

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

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




/*
 * 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 + 20, document.getElementById('theImage').height + 30 );
	}
}




/*
 * Collapsable Nav for Strict Doctypes, ver 0.2
 * Copyright 2005, Brian Sage, http://sagehome.com/brian
 * Not for use without written permission. If you want to use the code you can ask, but don't rip off my work.
 *
 * DOCTYPE compliance: HTML 4.01 Strict.
 * Compatability:
 *   HTML structure works in all browsers.
 *   DHTML works in DOM-compatable only.
 *   NOTE: Special event handler exceptions are included for diferences in FFox 1.0, IE6, and Safari 1.0, but they all work--including Opera 7.
 *
 * Usage: Put this in your document, and that's it. JS does the rest.
 
	<ul class="nav_collapsing">
		<li><a href="#"><img src="o.gif" alt="">Home Page</a>
		<li><a href="#"><img src="o.gif" alt="">Customer Service</a>
			<ul>
				<li><a href="#"><img src="o.gif" alt="">Current Customers</a>
			</ul>
		</li>
	</ul>

 *
 * Set one A.className to "active", and nav will automatically open to display active page.
 
	<li><a href="#" class="active"><img src="o.gif" alt="">Current Customers</a>
	
 *
 * Debug: Put the following in the document for handy-dandy debug output:
 
	<form name="debug" id="debug" action="#">
	<p><textarea cols="23" rows="12" name="debugoutput" id="debugoutput"></textarea></p>
	</form>

 *
 */
 
/********************************
 Define some global variables
 that make all these crazy
 things work
********************************/

if (!documentRoot) var documentRoot = './';
if (!graphicsRoot) var graphicsRoot = documentRoot + '_graphics/';

var colnavNodeImgOpen = new Image();
colnavNodeImgOpen.src = graphicsRoot + '-.gif';
var colnavNodeImgClosed = new Image();
colnavNodeImgClosed.src = graphicsRoot + '+.gif';
var dbo;



// Makes all <UL.nav> structures in the document clickable and "expand" to display full tree to <a.acive>
function colnavInit()
{
	if (document.getElementsByTagName && document.getElementById)
	{

		if (document.getElementById('debugoutput'))
		{
			dbo = document.getElementById('debugoutput'); // debug output
		}
		else
		{
			dbo = new Array();
		}

	dbo.value += "colnavInit()\n";

	// set the onclick cascading action for '.nav_collapsing's
		// loop throught all <UL>s in the document to find '.nav_collapsing's
		dbo.value += ("Looping through UL tags:\n");
		for (var i = 0; i < document.getElementsByTagName('UL').length; i++) 
		{
			var el = document.getElementsByTagName('UL').item(i);
			if (el.className == 'nav_collapsing')
			{
				dbo.value += ("	UL.nav_collapsing found in UL#" + i + ", colnavClick() attached to onclick\n");
				el.onclick = colnavClick;
			}
		}


	// collapse <UL> tree
		
		// find  <UL.nav> structures
		dbo.value += "Looping through A tags for tags in UL.nav_collapsing's\n";
		for (var i = 0; i < document.getElementsByTagName('A').length; i++) 
		{
			var el = document.getElementsByTagName('A').item(i);
			if (el.parentNode.childNodes.length >= 3)
			{
				if (el.parentNode.childNodes[2].nodeName == 'UL')
				{
					dbo.value += "	Found A with sibling UL in A#"+ i;
					if ( testAllParentsForColnav(el) )
					{
						dbo.value += "\n";
						
						dbo.value += ("		setting daughter UL to show" + "\n");
						changeElementDisplay(el.parentNode.childNodes[2], 'show');

						dbo.value += ("		setting daughter IMG to open" + "\n");
						changeColnavNodeImg(el.parentNode.childNodes[0].childNodes[0], 'open');
						
						dbo.value += ("		'clicking' IMG tag, collapsing branch\n");
						colnavClick( el.parentNode.childNodes[0].childNodes[0], 1 );
					}
					dbo.value += "\n";
				}
			}
			var el = null;
		}
		


	// open the cascading <UL> path from <a.active> back up to <UL.nav_collapsing>
		dbo.value += "\nLooping through A tags for A.active tag in UL.nav_collapsings\n";
		for (var i = 0; i < document.getElementsByTagName('A').length; i++) 
		{
			var el = document.getElementsByTagName('A').item(i);
			if (el.className == 'active')
			{
				dbo.value += "	Found A.active in A#"+ i;
				if( testAllParentsForColnav(el) )
				{
					dbo.value += "\n";
					dbo.value += ("	'clicking' A#" + i + "'s IMG tag, opening child branch\n");
					colnavClick( el.childNodes[0], 1 );
					dbo.value += "\n";
					
					var elStepBack = el.parentNode.parentNode.parentNode;
					dbo.value += ("	el.parentNode.parentNode.parentNode.nodeName = " + el.parentNode.parentNode.parentNode.nodeName + "\n");

					while ( elStepBack.nodeName == 'LI' )
					{
						dbo.value += ("	'clicking' LI A IMG tag, opening child branch\n");
						dbo.value += ("	elStepBack.childNodes[0].childNodes[0].nodeName = " +elStepBack.childNodes[0].childNodes[0].nodeName + "\n");
						
						if (elStepBack.childNodes[0].childNodes[0].nodeName =='IMG') colnavClick( elStepBack.childNodes[0].childNodes[0], 1 );
						elStepBack = elStepBack.parentNode.parentNode;
					}
				}
				dbo.value += "\n";
			}
			var el = null;
		}
	}
}
window.onload = colnavInit;




function testAllParentsForColnav()
{
	if (arguments.length >= 1)
	{
		var el = arguments[0];
		var theParentTag = el.parentNode;
		while ((theParentTag.nodeName == 'LI') || (theParentTag.nodeName == 'UL'))
		{
			if ((theParentTag.nodeName == 'UL') && (theParentTag.className == 'nav_collapsing'))
			{
				dbo.value += ", IS child to UL.nav_collapsing";
				return true;
			}
			theParentTag = theParentTag.parentNode;
		}

		dbo.value += ", is NOT child to UL.nav_collapsing";
		return false;
	}
	else
	{
		dbo.value += ", is NOT child to UL.nav_collapsing";
		return false;
	}
}




function colnavClick(e, calledFromFunc)
{
	dbo.value += ("colnavClick()\n");
	if (document.getElementById)
	{
		// BEGIN create the var targ for handling the argument|obejct e
		var targ;
		if (1 == calledFromFunc) // if this was called from a function...
		{	// ...make var targ out of passed object
			dbo.value += ("	calledFromFunc == " + calledFromFunc + "\n"); // Debug output: We're inside!
			targ = e;
		}
		else
		{	// ...make var targ out of different browser event handling models
			dbo.value += ("	calledFromFunc == " + calledFromFunc + "\n"); // Debug output: We're inside!
			if (!e) var e = window.event;                  // for IE's event model
			if (e.target) targ = e.target;                 // for W3C/Moz Event model
			else if (e.srcElement) targ = e.srcElement;    // also for IE's event model
			if (targ.nodeType == 3)                        // defeat Safari bug (thanks, quirksmode.org)
			targ = targ.parentNode;                        // realize the target node, itself
		}
		
		dbo.value += ("	targ.tagName == " + targ.tagName + "\n");
		// END var targ

		// Check to make sure the target was an image in the right structure
		if ( (targ.nodeName == 'IMG') && (targ.parentNode.nodeName == 'A') && (targ.parentNode.parentNode.nodeName == 'LI') )
		{
			// Check for a long enough node structure to include a daughter
			// <UL> node, because some clicked <LI> nodes won't have daughters
			if (targ.parentNode.parentNode.childNodes.length >= 3)
			{
				//alert (targ.parentNode.parentNode.childNodes[2].nodeName);
				// Change the [+] to a [-], or vice-versa
				changeColnavNodeImg(targ);
				// Open/close the <Ul> node
				changeElementDisplay (targ.parentNode.parentNode.childNodes[2]);
			}
			
			// Return false for all image clicks, so the link isn't fired
			return false;
		}
	}
	else
	{
		return false;
	}
	
}



// Usage: changeNavNodeImg(targ, ['open'|'close'|'toggle']);
function changeColnavNodeImg(targ, doThis)
{
	if ( (document.getElementById) && (targ.nodeName == 'IMG') && (colnavNodeImgOpen) )
	{
		// alert (targ.nodeName);

		// take care of miscelaneous doThises... (1)
		if ( (doThis != 'open') && (doThis != 'close') )
		{
			// doThis = (targ.style.display == 'block') ? 'close' : 'open';
			doThis = (targ.src.indexOf(colnavNodeImgOpen.src) != -1) ? 'close' : 'open';
		}

		// (1) ...then do the action
		targ.src = (doThis == 'open') ? colnavNodeImgOpen.src : colnavNodeImgClosed.src;
	}
}

// Usage: changeDisplay(targ, ['show'|'hide'|'swap']);
function changeElementDisplay(targ, doThis)
{
	if ( (document.getElementById) && (targ != null) )
	{
		// take care of miscelaneous doThises... (1)
		if ( (doThis != 'show') && (doThis != 'hide') )
		{
			doThis = (targ.style.display == 'block') ? 'hide' : 'show';
		}

		// (1) ...then do the action
		targ.style.display = (doThis == 'show') ? 'block' : 'none';
	}
}