/*
 * Opens and closes CADDIE site nav
 *
 * Usage:
 * Yeah, right. Don't know? Don't ask.
 */
function showHideChildren(whereItIs)
{
	
	if (document.getElementById)
	{
		// identify the parent HTML tag of where this got clicked
		m = whereItIs.parentNode.parentNode;

		// if the style of the parent is closed...
		if ('closed' == m.className)
		{
			// ...open it.
			whereItIs.childNodes[0].src = documentRoot + 'graphics/nav_arrow_open.gif';
			m.className = 'open';
		}
		// ...or if the style of the parent is open...
		else if ('open' == m.className)
		{
			// ...close it.
			whereItIs.childNodes[0].src = documentRoot + 'graphics/nav_arrow_closed.gif';
			m.className = 'closed';
		}
		
		whereItIs.blur();
	}
	return false;
}



/*
 * Functions for JS popup windows.
 *
 * Usage:
 * <a href="javascript: popup('whichType', [arguments0], [arguments1], ... );">
 */
function popup (whichType, postArgs)
{
	if (!documentRoot) documentRoot = '/';
	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 = documentRoot + 'calendar/calendar.phtml';
			if (postArgs) openerURI += '?' + postArgs;
			openerArgs += ',height=510,width=600';
			break;

		case 'mailinglist' :
			openerURI = documentRoot + 'mailing_lists/';
			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_lists/?mailing_list_id=' + postArgs;
			}
			else
			{
				openerURI += '_current_newsletter.phtml';
			}
			openerArgs += ',height=410,width=600';
			break;

		case 'privacypolicy' :
			document.location = documentRoot + 'privacy_policy';
			return;

			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 );
	}
}






































/***************************
 Breaking News iframe
 Content Loader:
 
 Places H1 and .blocklink A tag content of iframe into recentstories div on page
***************************/
function bniframe(message)
{
	if (document.getElementById)
	{
		var bnCmsContent = document.getElementById('bniframe').contentWindow.document;
		var bnlist = document.getElementById('breakingnews');

		var bn_Divs = bnCmsContent.getElementsByTagName('div');

		for (i=0; i < bn_Divs.length; i++)
		{
			if (bn_Divs[i].parentNode.className == 'child')
			{
				document.getElementById('breakingnews').style.visibility = 'visible';
				if (bn_Divs[i].childNodes[0].nodeName == 'A')
				{
					bnlist.innerHTML += '<div>' + bn_Divs[i].innerHTML + '</div>';
				}
				else
				{
					bnlist.innerHTML += '<div>' + bn_Divs[i].innerHTML.slice(0,80) + '...</div>';
				}
			}
		}
	}
}

/***************************
Charter Members iframe
Content Loader:
 
Places H1 and .blocklink A tag content of iframe into recentstories div on page
***************************/
function membersframe(message) {
    if (document.getElementById) {
        var bnCmsContent = document.getElementById('membersframe').contentWindow.document;
        var bnlist = document.getElementById('membersframe');

        var bn_Divs = bnCmsContent.getElementsByTagName('div');

        for (i = 0; i < bn_Divs.length; i++) {
            if (bn_Divs[i].parentNode.className == 'child') {
                document.getElementById('membersframe').style.visibility = 'visible';
                if (bn_Divs[i].childNodes[0].nodeName == 'A') {
                    bnlist.innerHTML += '<div>' + bn_Divs[i].innerHTML + '</div>';
                }
                else {
                    bnlist.innerHTML += '<div>' + bn_Divs[i].innerHTML.slice(0, 80) + '...</div>';
                }
            }
        }
    }
}