// <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();
	setup_email();
	set_newWindow();
	set_new_window_for_id('commentary');
	
	// Set <a> tags to open in new window if in <ul> with class link, within id 'main'
	var id = document.getElementById('main');
	set_new_window_for_class('link', 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 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 sidebar = document.getElementById('sidebar');
	if (sidebar != null)
		var ul = sidebar.getElementsByTagName("ul");

	for (var i = 0; i < page.length; i++)
	{	href = getSimpleHref(page[i].href)	

		if (href == currentHref)
		{
			match = true;
			break;
		}
		else if (ul.length == 0)
			continue;

		else if ((ul[0].id == 'subnav-about') && (href == 'about.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-meetings') && (href == 'meetings.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-members') && (href == 'members.php'))
		{
			match = true;
			break;
		}
		else if ((ul[0].id == 'subnav-news') && (href == 'news.php'))
		{
			match = true;
			break;
		}
	}

	if (match)
	{	
		page[i].style.color = "#000";
		page[i].style.backgroundColor = "#cccc99";
		page[i].style.backgroundColor = "#ffcc33";
		page[i].style.fontWeight = "bold";
		//page[i].style.textTransform = "uppercase";	
	}
}

/*
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('sidebar');
	
	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 || (href == 'grants.php' && currentHref == 'mrfgp.php'))
		{	
			page[i].style.color = "#fff";	
			page[i].style.fontWeight = "bold";
			//page[i].style.textTransform = "uppercase";	
			page[i].style.backgroundColor = "#9a9a68";
			page[i].parentNode.style.background = "#9a9a68";				// Parent node is <li>
			page[i].parentNode.style.borderRight = "7px solid #ffcc33";	// Parent node is <li>
			page[i].parentNode.style.marginRight = "-10px";	// Parent node is <li>
			page[i].parentNode.style.marginLeft = "-10px";	// Parent node is <li>

			break;
		}
	}
}

/**************************************************************************************************
This function sets up a links associated with class names to send email. Email address cannot 
be read by spambots.
email_array is a multidimensional array. Each array corresponds to 1 email addrss and has 
the following format:

0: class name associated with email (this goes in html code)
1: 1st part of email (before @ symbol)
2: 2nd part of email (between @ and .)
3. Last part of email (com, net, etc.)
4. Full email address
**************************************************************************************************/

function setup_email()
{
	var email_array = new Array
	(	
		new Array('emailSMR', 'info', 'SocietyMelanomaResearch', 'org'),
		new Array('emailSusan', 'smr', 'salud.unm', 'edu')
	);
	
	for (i = 0; i < email_array.length; i++)
	{
		email_array[i][4] = email_array[i][1] + "@" + email_array[i][2] + "." + email_array[i][3];
	}

	var anchors = document.getElementsByTagName("a");

	for (var i = 0; i < anchors.length; i++)
	{
		for (j = 0; j < email_array.length ; j++)
		{
			if (anchors[i].className == email_array[j][0])
			{
				anchors[i].onclick = function()
				{
					document.location.href = "mail" + "to:" + email_array[j][4];
					return(false);
				}
				anchors[i].onmouseover = function()
				{
					this.firstChild.nodeValue = email_array[j][4];
				}
			}
		}
	}
}

/**************************************************************************************************
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;
}
***/

/***************************************************************************************************
This function displays a portrait of one of the officers or committee members when a mouseover
is performed over their name.
****************************************************************************************************/
function display_portrait(img_file)
{	
	if (img_file == '')
		return;
	
	var folder = '../portraits/';		// Folder where all images are kept

	document.images.portrait.src = folder + img_file + '_200px.jpg'; 

	// If file doesn't exist, use transparent image
	document.images.portrait.onerror = function()
	{
		document.images.portrait.src = "../portraits/transparent_200x200.gif";
	}
}

/***************************************************************************************************
This function is the same as above, but adds more margin-top to move portrait down.
****************************************************************************************************/
function display_portrait_1(img_file)
{	
	if (img_file == '')
		return;

	var folder = '../portraits/';		// Folder where all images are kept
		
	document.images.portrait.style.marginTop = "70px";	
	document.images.portrait.src = folder + img_file + '_200px.jpg'; 

	// If file doesn't exist, use transparent image
	document.images.portrait.onerror = function()
	{
		document.images.portrait.src = "../portraits/transparent_200x200.gif";
	}
	
	// Remove lower portrait for adhoc committee
	document.images.portraitadhoc.src = "../portraits/transparent_200x200.gif";
}

/***************************************************************************************************
This function is the same as above, but adds more margin-top to move portrait down.
****************************************************************************************************/
function display_portrait_2(img_file)
{	
	if (img_file == '')
		return;
	
	var folder = '../portraits/';		// Folder where all images are kept

	document.images.portrait.style.marginTop = "250px";	
	document.images.portrait.src = folder + img_file + '_200px.jpg'; 

	// If file doesn't exist, use transparent image
	document.images.portrait.onerror = function()
	{
		document.images.portrait.src = "../portraits/transparent_200x200.gif";
	}
	
	// Remove lower portrait for adhoc committee
	document.images.portraitadhoc.src = "../portraits/transparent_200x200.gif";
}

/***************************************************************************************************
This function displays a portrait of one of the officers or committee members when a mouseover
is performed over their name.
****************************************************************************************************/
function display_portrait_3(img_file)
{	
	if (img_file == '')
		return;
	
	var folder = '../portraits/';		// Folder where all images are kept
	document.images.portraitadhoc.src = folder + img_file + '_200px.jpg'; 

	// If file doesn't exist, use transparent image
	document.images.portraitadhoc.onerror = function()
	{
		document.images.portraitadhoc.src = "../portraits/transparent_200x200.gif";
	}
	
	// Remove upper portrait for steering committee
	document.images.portrait.src = "../portraits/transparent_200x200.gif";
}


// end hiding contents from old browsers  -->
// </script>