// <script type="text/javascript">
<!--  to hide script contents from old browsers

/***************************************************************************************************
This function hides or displays the service hours that the agency is open by being called when the
form is displayed.
***************************************************************************************************/

function set_hours_selected(form_id)
{
	form = document.getElementById(form_id);
	inputs = form.getElementsByTagName("input");

	// Go through each input
	for (j = 0; j < inputs.length; j++)
	{
		// Only looking for radio buttons indicating Open or Closed for a given day
		if (inputs[j].type != 'radio')
			continue;

		var li = inputs[j].parentNode;
		var ul = li.parentNode;
		var th = ul.parentNode;
		var tr = th.parentNode;

		// Get the <td> element
		td = tr.getElementsByTagName("td");

		// Get the <div> elements in the <td>
		div = td[0].getElementsByTagName("div");

		// Get the <p> elements in the <td>
		p = td[0].getElementsByTagName("p");

		// If radio button is checked, see whether 1 (Open) or 0 (Closed)
		if (inputs[j].checked == true)
		{
			if (inputs[j].value == 1)
				open = 1;
			else
				open = 0;
		}
		else
			continue;

		if (open == 1)
			var display = '';
		else
			display = 'none';

		for (i = 0; i < div.length; i++)
			div[i].style.display = display;

		for (i = 0; i < p.length; i++)
		{
			//alert(p[i].innerHTML);

			if (p[i].innerHTML == "Open From:" || p[i].innerHTML == "Open To:")
				p[i].style.display = display;
		}
	}
}

/***************************************************************************************************
This function hides or displays the service hours that the agency is open based on clicking a radio
button.
***************************************************************************************************/

function hours_selected(open, input)
{
	//alert(open + '  ' + input);

	var li = input.parentNode;
	var ul = li.parentNode;
	var th = ul.parentNode;
	var tr = th.parentNode;

	// Get the <td> element
	td = tr.getElementsByTagName("td");

	// Get the <div> elements in the <td>
	div = td[0].getElementsByTagName("div");

	// Get the <p> elements in the <td>
	p = td[0].getElementsByTagName("p");

	if (open == 1)
		var display = '';
	else
		display = 'none';

	for (i = 0; i < div.length; i++)
		div[i].style.display = display;

	for (i = 0; i < p.length; i++)
	{
		if (p[i].innerHTML == "Open From:" || p[i].innerHTML == "Open To:")
			p[i].style.display = display;
	}
}


/***************************************************************************************************
This function hides or displays <tr> rows from the Service Ares form. If a user selects that their
agency services all NM communities, then all the counties and communities are hidden. Otherwise,
the communities are displayed.
***************************************************************************************************/

function all_nm_selected(service_all_nm, form_id)
{
	form = document.getElementById(form_id);

	// 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')
		{
			if (inputs[i].id == 'service-all-nm1' || inputs[i].id == 'service-all-nm2')
			{
				continue;
			}

			// Get <li> elements
			var li = inputs[i].parentNode;
			var ul = li.parentNode;
			var td = ul.parentNode;
			var tr = td.parentNode;

			// If service for all NM, hide community checkboxes
			if (service_all_nm == 1)
			{
				// Hide
				tr.style.display = 'none';
				//Deselect check boxes
				//inputs[i].checked = false;
			}
			// If not service for all NM, show coommunity checkboxes
			else
			{
				// Show
				tr.style.display = '';
				//Deselect check boxes
				//inputs[i].checked = false;
			}
		}
	}
}

/**************************************************************************************************
This function changes the display from "none" to "block" or "block" to "none"of the selected
section. This only includes selected tags.
**************************************************************************************************/
function display_text(link)
{
	// Get <h3>
	var h3 = link.parentNode;
	// Get <div>
	var div = h3.parentNode;
	// Get <ul>
	var ul = div.getElementsByTagName('ul');

	//var li = ul[0].getElementsByTagName('li');

	//for (var i = 0; i < li.length; i++)
	{
		if (ul[0].style.display == "block")
			ul[0].style.display = "none";
		else
			ul[0].style.display = "block";
	}
}

/**************************************************************************************************
This function changes the display to "block".
**************************************************************************************************/
function display_categories(link)
{
	var h3 = document.getElementsByTagName('h3');
	var num_h3 = h3.length;

	// Get last h3
	var this_h3 = h3[num_h3 - 1];

	// Get <div>
	var div = this_h3.parentNode;

	// Get <ul>
	var ul = div.getElementsByTagName('ul');
	ul[0].style.display = "block";
}

/**************************************************************************************************
This function generates an alert box to confirm that user wants to delete something.
**************************************************************************************************/
function confirm_delete($str)
{
	return confirm('Are you sure you want to delete this ' + $str + '?');
}


// end hiding contents from old browsers  -->
// </script>