/* livingLink.js - JavaScript functions for Living Links web site
Written: Peter Johnson
Revised: 02/29/09  Added header comment block
*/

// show the last modified date for the page
function modDate( )
{
	//document.write("<div id='modDate'>");
   document.write(document.lastModified);
	//document.write("</div>");
}

// print out two parts of email address
// to protect from spam spiders
function eContact(text, part1, part2)
{
  document.write(text + "<a href='mailto:" + part1 + "@" + part2 + "'>"
  + part1 + "@" + part2 + "<a>");
}

// set optChoice radio button automatically
// if user clicks on a delete radio button
function setOptChoice(itemNum)
{
  var item = document.getElementsByTagName("input");

  // Set the appropriate choice radio button
  for(var x=0; x<item.length; x++)
  {
	  if( item[x].getAttribute("name") == "optChoice"
		  && item[x].getAttribute("value") == itemNum)
	  {
			 item[x].checked = true;
	  }
  }
} //end of setOptChoice( )


// if the user clicks on a choice button than nothing should be deleted
// Make certain all of the optDelete radio buttons are cleared
function clearDelete( )
{
  var item = document.getElementsByTagName("input");
  // Step through each input field
  for(var x=0; x<item.length; x++)
  {
	 // find all the delete radio buttons
	 // then check the corresponding choice radio button
	 if( item[x].getAttribute("name") == "optDelete"
		  && item[x].checked == true)
		{
			 // clear the delete choice
			 item[x].checked = false;
		}
  }
} // end of clearDelete( )

	 
// Make certain at least one radio button is clicked
function isSelection( )
{
  var isSelectionFlag = false;
  var item = document.getElementsByTagName("input");
  // Step through each input field
  for(var x=0; x<item.length; x++)
  {
	 // find all the delete radio buttons
	 // then check the corresponding choice radio button
	 if( item[x].checked == true)
	 {
		 isSelectionFlag = true;
		 break;
	 }
  }
  if(!isSelectionFlag)
  {
		// tell the user then set the focus to the first element
	  alert("Please select at least one option.");
	  selectFirstElement( );
  }
  return isSelectionFlag // false will keep hyperlink from jumping
} // end of isSelection( )
	 
// no matter what inputs are disabled on a form, the focus finds its way to the first one that is enabled.
//http://www.codeproject.com/jscript/FocusFirstInput.asp?df=100&forumid=214651&exp=0&select=1225603
function selectFirstElement( )
{
var bFound = false;
	for(i=0; i < document.forms[0].length; i++)
	{
	  if (document.forms[0][i].type != "hidden")
	  {
		 if (document.forms[0][i].disabled != true)
		 {
			  document.forms[0][i].focus();
			  document.forms[0][i].checked = true;
			  var bFound = true;
		 }
	  }
	  if (bFound == true)
		 break;
	}
}

