// <script type="text/javascript">
<!--  to hide script contents from old browsers

window.onload = init;

function init()
{
	/**
	var start = new Date();
	start = start.getTime();
	**/

	display_urhere();
	display_subnav_urhere();
	display_subsubnav_urhere();
	setup_email();
	set_newWindow();

	// Set <a> tags to open in new window if in <ul> with class links, within id 'main'
	var id = document.getElementById('main');
	set_new_window_for_class('links', id, 'ul');

	/**
	var end = new Date();
	end = end.getTime();
	var time = end - start;
	alert(start + '  ' + end + '   time = ' + time);
	//Took about 15 msecs on my computer.
	**/
}

/***************************************************************************************************
This function hides or displays camp form registration fields depending on whether the user
selects a radio box indicating whether they're a JCC member or not. This function is called when
the user selects one of the radio buttons for JCC Member.
***************************************************************************************************/
function jcc_member_selected(jcc_member, form)
{
	var id, p, registration;

	registration = '0';

	// See whether this function called from camp or aquatics registration
	if (form.action.indexOf('camp') > 0)
		registration = 'camp';
	else if (form.action.indexOf('aquatic') > 0)
		registration = 'aquatics';

	/***
	if (registration == 'camp' && jcc_member != 1)
		alert('Non-members are not eligible to sign up for Specialty Camps until March 18. ' +
			'Non-members can sign up for Camp Chai anytime.');
	***/

	// Get all <input> tags
	var inputs = form.getElementsByTagName("input");

	for (i = 0; i < inputs.length; i++)
	{
		if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')
		{
			// Get <li> elements
			var li = inputs[i].parentNode;
			var value = inputs[i].value;


			// If JCC member
			if (jcc_member == 1)
			{
				// Hide nonmember choices
				if (value.substring(0, 9) == 'nonmember')
				{
					li.style.display = 'none';
					//Deselect check boxes
					inputs[i].checked = false;
				}
				// Show member choices
				if (value.substring(0, 6) == 'member' || value.substring(0, 10) == 'early_bird')
				{
					li.style.display = 'block';
					//Deselect check boxes
					inputs[i].checked = false;
				}
			}
			// If not a JCC member
			else
			{
				// Hide member choices
				if (value.substring(0, 6) == 'member' || value.substring(0, 10) == 'early_bird')
				{
					li.style.display = 'none';
					//Deselect check boxes
					inputs[i].checked = false;
				}

				// Show member choices
				if (value.substring(0, 9) == 'nonmember')
				{
					li.style.display = 'block';
					//Deselect check boxes
					inputs[i].checked = false;
				}
			}
		}
	}
}

/***************************************************************************************************
This function hides or displays camp form registration fields depending on whether the user
selects a radio box indicating whether they're a JCC member or not. The only difference with the
above function is that this one is invoked from a script on the page when the page is redisplayed.
***************************************************************************************************/
function jcc_member(jcc_member)
{
	var id, p;

	// Get all <input> tags
	var inputs = document.getElementsByTagName("input");

	for (i = 0; i < inputs.length; i++)
	{
		if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')
		{
			// Get <li> elements
			var li = inputs[i].parentNode;
			var value = inputs[i].value

			// If JCC member
			if (jcc_member == 1)
			{
				// Hide nonmember choices
				if (value.substring(0, 9) == 'nonmember')
					li.style.display = 'none';

				// Show member choices
				if (value.substring(0, 6) == 'member' || value.substring(0, 10) == 'early_bird')
					li.style.display = 'block';
			}
			// If not a JCC member
			else
			{
				// Hide member choices
				if (value.substring(0, 6) == 'member' || value.substring(0, 10) == 'early_bird')
					li.style.display = 'none';

				// Show member choices
				if (value.substring(0, 9) == 'nonmember')
					li.style.display = 'block';
			}

			//Deselect check boxes
			//inputs[i].checked = false;
		}
	}
}

/***************************************************************************************************
This function alters the style of the navigation bar to indicate urhere.
I added code from the original to shorten the href string so that it does
not include any bookmarks (....#bookmark). Otherwise, the strings would not
match and the urhere formatting would not be applied.

Remember that if the specified element does not exist, getElementsByTagName returns a NodeList of
length 0.
***************************************************************************************************/
function display_urhere()
{	var list; var page; var currentHref; var href; var anchorPosition;
	var match = false;

	if (!document.getElementById)
	{
		return true;
	}

	list = document.getElementById("navbar");
	page = list.getElementsByTagName("a");
	currentHref = document.location.href;

	anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{	currentHref = currentHref.substring(0, anchorPosition);
	}

	currentHref = getSimpleHref(currentHref);

	var subnav = document.getElementById('subnav');
	if (subnav != null)
		var ul = subnav.getElementsByTagName("ul");

	for (var i = 0; i < page.length; i++)
	{	href = getSimpleHref(page[i].href)

		if (href == currentHref)
		{
			match = true;
			break;
		}
		else if ((href.indexOf('events_programs.php') >= 0) && (currentHref.indexOf('events_programs.php') >= 0))
		{
			match = true;
			break;
		}
		else if (subnav == null || ul.length == 0)
			continue;

		else if ((ul[0].id == 'subnav-facilities') && (href == 'facilities.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-fitness') && (href == 'health_fitness.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-events') && (href == 'events.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-members') && (href == 'membership.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-about-us') && (href == 'about.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-children-services') && (href == 'children_services.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-donations') && (href == 'donations.php'))
		{
			match = true;
			break;
		}
	}

	if (match)
	{
		page[i].style.color = "#000";
		page[i].style.fontWeight = "bold";
		page[i].style.background = "#c5b232";
	}
}

/*
This function was added because Mac Safari does not include the directory structure
before the href, so there was never a match. This function strips the beginning directory structure
away and just leaves the end part--such as about_us.htm
**************************************************************************************************/
function getSimpleHref(s)
{	var length;
	var anchorPosition = 0;

	while (anchorPosition >= 0)
	{	anchorPosition = s.indexOf('/');
		length = s.length;

		if (anchorPosition >= 0)
		{	s = s.substring(anchorPosition + 1, length);
		}
	}

	return(s);
}

/*******************************************************************************
This function sets the urhere for the sub navigation menu for the portfolio pages.
If there is no sub-nav ID on the page, then the function simply returns.
*******************************************************************************/
function display_subnav_urhere()
{
	var href;

	var list = document.getElementById('subnav');

	if (list == null)
	{
		return;
	}

	var page = list.getElementsByTagName("a");
	var currentHref = document.location.href;

	var anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{	currentHref = currentHref.substring(0, anchorPosition);
	}

	currentHref = getSimpleHref(currentHref);

	for (var i = 0; i < page.length; i++)
	{
		//alert('href = ' + href + '  currentHref = ' + currentHref);

		href = getSimpleHref(page[i].href)

		if ((href == currentHref) ||
			(currentHref == 'fitness_center.php') ||
			(currentHref == 'personal_training.php') ||
			(currentHref == 'nutrition.php') ||
			(currentHref == 'body_for_life.php'))
		{
			page[i].style.color = "#000";
			page[i].style.fontWeight = "bold";
			page[i].parentNode.style.background = "#c5b232";	// Parent node is <li>

			page[i].style.borderTop = "1px solid #666";
			page[i].style.borderLeft = "1px solid #666";
			page[i].style.borderRight = "1px solid #ddd";
			page[i].style.borderBottom = "1px solid #ddd";

			break;
		}
	}
}

/*******************************************************************************
This function sets the urhere for the subsub navigation menu for the Fitness pages.
If there is no subsub-nav ID on the page, then the function simply returns.
*******************************************************************************/
function display_subsubnav_urhere()
{
	var href;

	var list = document.getElementById('subsubnav');

	if (list == null)
	{
		return;
	}

	var page = list.getElementsByTagName("a");
	var currentHref = document.location.href;

	var anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{	currentHref = currentHref.substring(0, anchorPosition);
	}

	currentHref = getSimpleHref(currentHref);

	for (var i = 0; i < page.length; i++)
	{
		href = getSimpleHref(page[i].href)

		if (href == currentHref)
		{
			page[i].style.color = "#000";
			page[i].style.fontWeight = "bold";
			//page[i].parentNode.style.background = "#c5b232";	// Parent node is <li>

			page[i].style.borderTop = "1px solid #666";
			page[i].style.borderLeft = "1px solid #666";
			page[i].style.borderRight = "1px solid #ddd";
			page[i].style.borderBottom = "1px solid #ddd";

			break;
		}
	}
}

/**************************************************************************************************
This function sets up a links associated with class names to send email. Email address cannot
be read by spambots. email_array is an associative array. Each array corresponds to 1 email address.

To use in html code, as an exampke, add <a href="" class="emailMichele">Email Michele</a> where each
email address has an email**** associated with it.

To add another email address, add to email_array and add another case statement.
**************************************************************************************************/
function setup_email()
{
	var email_array = new Array();
	email_array['Jay'] = 'JayJ';
	email_array['Adeo'] = 'AJ';
	email_array['Butch'] = 'ButchK';
	email_array['Debra'] = 'DebraB';
	email_array['Cathy'] = 'CathyD';
	email_array['Chris'] = 'ChrisR';
	email_array['Genny'] = 'GennyH';
	email_array['Jeremiah'] = 'JeremiahK';
	email_array['Josh'] = 'JoshW';
	email_array['Kristine'] = 'KristineR';
	email_array['Matt'] = 'Aquatics';
	email_array['MattW'] = 'MattW';
	email_array['Mike'] = 'MikeW';
	email_array['Nate'] = 'NateW';
	email_array['Patricia'] = 'PatriciaP';
	email_array['Peggy'] = 'PeggyH';
	email_array['Phyllis'] = 'PhyllisW';
	email_array['Richard'] = 'RichardR';
	email_array['Sarah'] = 'SarahK';
	email_array['Susanna'] = 'SusannaP';
	email_array['Sherri'] = 'SherriD';
	email_array['Tom'] = 'TomG';

	email_array['BodyForLife'] = 'BodyForLife';
	email_array['JCC'] = 'jccabq';
	email_array['MemberServices'] = 'MemberServices';

	for (var name in email_array)
	{
		email_array[name] += "@" + 'jccabq' + "." + 'org';
		//alert(class + '   ' + email_array[class]);
	}
	email_array['Kerry'] = 'KerryArtist' + '@' + 'yahoo' + '.' + 'com';

	var anchors = document.getElementsByTagName("a");

	for (var i = 0; i < anchors.length; i++)
	{
		switch(anchors[i].className)
		{
			case "emailJay":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Jay'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Jay'];
				}
				break;
			}
			case "emailButch":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Butch'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Butch'];
				}
				break;
			}
			case "emailCathy":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Cathy'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Cathy'];
				}
				break;
			}
			case "emailChris":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Chris'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Chris'];
				}
				break;
			}
			case "emailDebra":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Debra'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Debra'];
				}
				break;
			}
			case "emailSherri":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Sherri'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Sherri'];
				}
				break;
			}
			case "emailJeremiah":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Jeremiah'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Jeremiah'];
				}
				break;
			}
			case "emailAdeo":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Adeo'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Adeo'];
				}
				break;
			}
			case "emailKristine":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Kristine'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Kristine'];
				}
				break;
			}
			case "emailMatt":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Matt'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Matt'];
				}
				break;
			}
			case "emailMattW":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['MattW'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['MattW'];
				}
				break;
			}
			case "emailNate":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Nate'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Nate'];
				}
				break;
			}
			case "emailPatricia":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Patricia'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Patricia'];
				}
				break;
			}
			case "emailPhyllis":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Phyllis'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Phyllis'];
				}
				break;
			}
			case "emailRichard":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Richard'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Richard'];
				}
				break;
			}
			case "emailSarah":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Sarah'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Sarah'];
				}
				break;
			}
			case "emailKerry":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Kerry'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Kerry'];
				}
				break;
			}

			case "emailTom":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Tom'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Tom'];
				}
				break;
			}

			case "emailMike":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Mike'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Mike'];
				}
				break;
			}

			case "emailSusanna":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Susanna'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Susanna'];
				}
				break;
			}

			case "emailPeggy":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Peggy'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Peggy'];
				}
				break;
			}

			case "emailJosh":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Josh'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Josh'];
				}
				break;
			}

			case "emailGenny":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['Genny'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['Genny'];
				}
				break;
			}

			case "emailBodyForLife":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['BodyForLife'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['BodyForLife'];
				}
				break;
			}
			case "emailJCC":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['JCC'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['JCC'];
				}
				break;
			}
			case "emailMemberServices":
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array['MemberServices'];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array['MemberServices'];
				}
				break;
			}
		}
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> that has class "newWindow".
Remember that if the specified element does not exist, getElementsByTagName returns a NodeList of
length 0.
**************************************************************************************************/
function set_newWindow()
{
	var anchors = document.getElementsByTagName("a");

	for (var i = 0; i < anchors.length; i++)
	{
		if (anchors[i].className == "newWindow")
		{
			anchors[i].onclick = function()
			{
				window.open(this.href);
				return false;
			}
		}
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> within the id. The parameter "id" should
be a string indicating the id name.
Remember that if the specified element does not exist, getElementsByTagName returns a NodeList of
length 0.
**************************************************************************************************/
function set_new_window_for_id(id)
{
	var element = document.getElementById(id);
	if (element == null)
		return;

	var anchors = element.getElementsByTagName("a");

	for (var i = 0; i < anchors.length; i++)
	{
		anchors[i].onclick = function()
		{
			window.open(this.href);
			return false;
		}
	}
}

/**************************************************************************************************
This function causes a new window to open for any link <a> within a class.
The parameters are:
	searchClass: this is the class within which any <a> link should open a new window
	node: this restricts the search to elements within the node. Using 'document' will include everything.
	tag: this restricts the search to a certain tag associated with the className
**************************************************************************************************/
function set_new_window_for_class(searchClass, node, tag)
{
	var list = getElementsByClass(searchClass, node, tag);

	for (var i = 0; i < list.length; i++)
	{
		anchors = list[i].getElementsByTagName('a');

		for (j = 0; j < anchors.length ; j++)
		{
			anchors[j].onclick = function()
			{
				window.open(this.href);
				return false;
			}
		}
	}
}

/***************************************************************************************************
The original script from Dustin Diaz is below, but I decided to rewrite it and
make it simpler using className instead of RegExp.

It’s simple. It works just how you think getElementsByClass would work, except better.

1. Supply a class name as a string.

2. Supply a node. This can be obtained by getElementById, or simply by just
throwing in “document” (it will be document if don’t supply a node)). It’s mainly useful
if you know your parent and you don’t want to loop through the entire D.O.M.

3. Limit your results by adding a tagName. Very useful when you’re toggling
checkboxes and etcetera. You could just supply “input“. Or, if you’re like me, and you
said Good Bye to IE5, you can use the “*” asterisk as a catch-all (meaning ‘any element).
****************************************************************************************************/
function getElementsByClass(searchClass, node, tag)
{
	var classElements = new Array();
	//classElements = null;

	if (node == null)
		node = document;
	if (tag == null)
		tag = '*';

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;


	for (i = 0, j = 0; i < elsLen; i++)
	{
		if (els[i].className == searchClass)
		{
			classElements[j++] = els[i];
		}
	}

	return classElements;
}


/***
{
	var classElements = new Array();
	classElements = null;

	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';


	//node = document;

	alert('searchclass = ' + searchClass + '   node = ' + node + '  tag = ' + tag);

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	alert('elslen = ' + elsLen);

	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++)
	{
		if ( pattern.test(els[i].className) )
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
***/

// end hiding contents from old browsers  -->
// </script>