// <script type="text/javascript">
<!--  to hide script contents from old browsers

$(document).ready(function()
{
	display_urhere();
	setup_email();

	// Show/hide FAQs answers
	$('dl.partner-faqs dt a').click(function()
	{
		$(this).parent('dt').next('dd').toggle();
		return 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.
******************************************************************************/

function display_urhere()
{	var list; var page; var currentHref; var href; var anchorPosition;

	if (!document.getElementById)
	{
		return true;
	}

	list = document.getElementById("navbar");
	if (list == null)
		return;

	page = list.getElementsByTagName("a");
	currentHref = document.location.href;

	anchorPosition = currentHref.indexOf("#");
	if (anchorPosition >= 0)
	{
		currentHref = currentHref.substring(0, anchorPosition);
	}

	parameterPosition = currentHref.indexOf("?");
	if (parameterPosition >= 0)
	{
		currentHref = currentHref.substring(0, parameterPosition);
	}

	currentHref = getSimpleHref(currentHref);

	for (var i = 0; i < page.length; i++)
	{
		href = getSimpleHref(page[i].href)

		//alert(href + '   ' + currentHref);

		if ((href == currentHref) || (href == 'client_index.php' && currentHref == 'client_form_main.php') ||
			(currentHref.indexOf('salud_manual_') >= 0 && href == 'salud_manual_main.php'))
		{
			page[i].style.color = "#000";
			page[i].style.textDecoration = "none";
			page[i].style.background = "#ed7b23";
			page[i].parentNode.style.background = "#ed7b23";
			break;
		}
	}

	display_subnav_urhere();
}

/******************************************************************************
This function is called from the client section to highlight the current form.
******************************************************************************/
function display_client_subnav_urhere(form_name)
{
	var list; var page; var currentHref; var href; var anchorPosition;

	if (!document.getElementById)
		return true;

	list = document.getElementById("navbar-forms-client");
	if (list == null)
		return;

	page = list.getElementsByTagName("a");
	currentHref = document.location.href;

	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 on the appropriate page
		if (href.indexOf(form_name) >= 0)
			var match = true;
		else
			match = false;

		if (href == currentHref || match == true)
		{
			page[i].style.color = "#000";
			page[i].style.backgroundColor = "#fff";
			page[i].style.textDecoration = "none";
			page[i].parentNode.style.backgroundColor = "#fff";
			break;
		}
	}

	//display_subnav_urhere();
}

/*
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++)
	{
		href = getSimpleHref(page[i].href)

		if (href == currentHref)
		{
			page[i].style.color = "#000";
			page[i].style.textDecoration = "none";
			page[i].style.background = "#ed7b23";
			page[i].parentNode.style.background = "#ed7b23";
			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 <span class="emailMichele"></span> where each
email address has an email**** associated with it.

To add another email address, add to email_array.
**************************************************************************************************/
function setup_email()
{
	// Get all <span> tags
	var tags = document.getElementsByTagName("span");

	for (var i = 0; i < tags.length; i++)
	{
		// Get className of <span> tag
		var cname = tags[i].className;

		// Now look for classes that begin with 'email'
		var s = cname.indexOf('email');

		// If <span> tag and class starts with 'email'
		if (s == 0)
		{
			// Get index to email_array (strip off 'email')
			index = cname.substring(5);
			insert_email(tags[i], index);
		}
	}
}

/**************************************************************************************************
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 <span class="emailMichele"></span> 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 insert_email(tag, index)
{
	var email_array = new Array();
	email_array['Admin'] = 'admin, mycommunitynm, org';
	email_array['Sara'] = 'sara, mycommunitynm, org';
	email_array['Leigh'] = 'lmason, bernco, gov';

	var temp = email_array[index];

	// Remove any spaces, leave commas
	while (temp.indexOf(' ') != -1)
		temp = temp.replace(' ', '');

	// Split email string by commas
	var temp = temp.split(',');

	address = temp[0] + '@' + temp[1] + '.' + temp[2];

	tag.innerHTML = '<a href="mailto:' + address + '">' + address + '</a>';
}


/*******************************************************************************
It’s simple. It works just how you think getElementsByClass would work, except better.

1. Supply a class name as a string.

2. (optional) 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. (optional) 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();

	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';

	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;

	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 simply prints an alert box with help for basic searching of agencies.
**************************************************************************************************/
function basic_search_help(language)
{
	var text;

	if (language == 'sp')
	{
		text = 'SEARCH HELP \n' +
			'Enter any word or group of words in the search box and then click the "Go" button. ' +
			'All agency information will be searched (not just the name of the agency), and the results ' +
			'of your search will be returned. Click on the name of any agency to see ' +
			'detailed information about that agency. ' +
			'\n\nYou can also click on the search results table headings to sort the search results.' +
			'\n\nIf you enter more than one word (for example: health clinic), the results will include any agencies that have ANY of the words.' +
			'\n\nIf you enter more than one word and surround the words by double quotes (for example: "health clinic"), the results ' +
			'will include only agencies that contain the exact phrase.'
			;
	}
	else
	{
		text = 'SEARCH HELP \n' +
			'Enter any word or group of words in the search box and then click the "Go" button. ' +
			'All agency information will be searched (not just the name of the agency), and the results ' +
			'of your search will be returned. Click on the name of any agency to see ' +
			'detailed information about that agency. ' +
			'\n\nYou can also click on the search results table headings to sort the search results.' +
			'\n\nIf you enter more than one word (for example: health clinic), the results will include any agencies that have ANY of the words.' +
			'\n\nIf you enter more than one word and surround the words by double quotes (for example: "health clinic"), the results ' +
			'will include only agencies that contain the exact phrase.' +
			'\n\nTARGET GROUP ICONS \n' +
			'If you hover over any of the target group icons with your mouse, you can view the description of each target group.'
			;
	}

	alert(text);
}

/**************************************************************************************************
This function simply prints an alert box with help for advanced searching of agencies.
**************************************************************************************************/
function advanced_search_help(language)
{
	var text;

	if (language == 'sp')
	{
		text = 'SEARCH HELP \n' +
			'Enter any word or group of words in the search box and then click the "Go" button. ' +
			'All agency information will be searched (not just the name of the agency), and the results ' +
			'of your search will be returned. Click on the name of any agency to see ' +
			'detailed information about that agency. ' +
			'\n\nYou can also click on the search results table headings to sort the search results.' +
			'\n\nIf you enter more than one word (for example: health clinic), the results will include any agencies that have ANY of the words.' +
			'\n\nIf you enter more than one word and surround the words by double quotes (for example: "health clinic"), the results ' +
			'will include only agencies that contain the exact phrase.'
			;
	}
	else
	{
		text = 'SEARCH HELP \n' +
			'If you would like to search by categories, click the "Categories" link to view all the categories, ' +
			'and check the checkboxes of the categories that you would like to search. ' +
			'You may also enter any word or group of words in the "Agency name or service you\'re looking for" text box ' +
			'as well as the "City Name" and/or "County Name" fields to further filter your search. ' +
			'\n\nAll agency information will be searched (not just the name of the agency), and the results ' +
			'of your search will be returned. Click on the name of any agency to see ' +
			'detailed information about that agency. ' +
			'\n\nYou can also click on the search results table headings to sort the search results.' +
			'\n\nIf you enter more than one word (for example: health clinic), the results will include any agencies that have ANY of the words.' +
			'\n\nIf you enter more than one word and surround the words by double quotes (for example: "health clinic"), the results ' +
			'will include only agencies that contain the exact phrase.' +
			'\n\nTARGET GROUP ICONS \n' +
			'If you hover over any of the target group icons with your mouse, you can view the description of each target group.'
			;
	}

	alert(text);
}

/**************************************************************************************************
This function shows a tooltip on mouseover for a target group icon. A new <div id="tooltip-div">
is created to display the tooltip. It is appended to the <body> tag.

It could also be appended to the <div id="container"> and displayed with
position: absolute to make it relative to the container which is position: relative.
**************************************************************************************************/

function show_tooltip(pix, tooltip)
{
	var left, top, pos;

	pos = findPos(pix);

	left = pos[0];
	top = pos[1];
	//alert(left + ' ' + top);

	pos = correct_position_for_browser(left, top);
	left = pos[0];
	top = pos[1];
	//alert(left + ' ' + top);

	var newDiv = document.createElement('div');
	newDiv.id = 'tooltip-div';

	document.getElementsByTagName('body')[0].appendChild(newDiv);
	//document.getElementById('container').appendChild(newDiv);

	newDiv.style.position = 'absolute';
	newDiv.style.top = top + 'px';
	newDiv.style.left = left + 'px';
	newDiv.style.fontSize = '1.1em';
	newDiv.style.padding = '5px';
	newDiv.style.background = '#ccc';
	newDiv.style.border = '1px solid #aaa';
	newDiv.innerHTML = tooltip;
}

/**************************************************************************************************
This function finds the left and top coordinates of the target group icon image.

Note that the do/while loop could end if obj.id == 'container.' This gets the coordiates relative
to the container so that when the tooltip is displayed as position: asbolute, it will be relative
to the "container" which is position: relative.

If the break is not there, the position would be found relative to the screen. This does not work
with IE because the position is different when a sidebar is used.
**************************************************************************************************/
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			// Break at container to get coordinates relative to the container.
			if (obj.id == 'container')
				; //break;

			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
	}

	return [curleft,curtop];
}

/**************************************************************************************************
This function simply prints an alert box with help for searching agencies.
**************************************************************************************************/
function correct_position_for_browser(left, top)
{
	BrowserDetect.init();

	var new_x = left;
	var browser = BrowserDetect.browser;
	var version = BrowserDetect.version;
	//alert(browser);

	if (browser == 'Firefox')
		//new_x += -300;
		new_x += 0;
	else if (browser == 'Explorer')
	{
		//alert(version);
		if (version >= 7)
			new_x += -230;
		else if (version >= 6)
			new_x += -300;
		else if (version >= 5)
			new_x += -50;
	}
	else if (browser == 'Opera')
	{
		if (version >= 9.5)
			new_x += -630;
	}

	//alert(browser + '  ' + version + '  ' + left + '  ' + new_x);

	//return[left, top+25];
	return[new_x, top+25];
}

/**************************************************************************************************
This function simply prints an alert box with help for searching agencies.
**************************************************************************************************/
function remove_tooltip(pix)
{
	tooltip = document.getElementById('tooltip-div');
	if (tooltip)
		tooltip.parentNode.removeChild(tooltip);
}

/**************************************************************************************************
This detects the browser type and version
**************************************************************************************************/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

// end hiding contents from old browsers  -->
// </script>