///////////////////////////////////////////////////////////////////////
// This function will visually display the inut element.
//////////////////////////////////////////////////////////////////////
function ShowElement(ElementId)
{ 
	// make sure the element exists
	if (document.getElementById(ElementId) != null)
	{
		// hide "update in progress" text and display
		document.getElementById(ElementId).style.display="";
		document.getElementById(ElementId).style.visibility="visible";
	}
}

///////////////////////////////////////////////////////////////////////
// This function will visually hide the inut element.
//////////////////////////////////////////////////////////////////////
function HideElement(ElementId)
{ 
	// make sure the element exists
	if (document.getElementById(ElementId) != null)
	{
		// hide "update in progress" text and display
		document.getElementById(ElementId).style.display="none";
		document.getElementById(ElementId).style.visibility="hidden";
	}
}

//////////////////////////////////////////////////////////////////
// returns true if the input string ends with a letter.
//////////////////////////////////////////////////////////////////
function endsWithletter(s) 
{
	if (s.length == 0)
	{
		return false;
	}
	
	if ( (s.toLowerCase().charAt(s.length - 1) >= 'a') && (s.toLowerCase().charAt(s.length - 1) <= 'z') )
	{
		return true;
	}
	
	return false;
}

///////////////////////////////////////////////////////////////////////
// Trims leading/trailing spaces
//////////////////////////////////////////////////////////////////////
function trim(str) 
{ 
  str = str.replace( /^\s+/g, "" ); // strip leading 
  str = str.replace( /\s+$/g, "" ); // strip trailing 

  return str; 
} 

//////////////////////////////////////////////////////////////////
// Determines if the input string represents a syntactically correct
// email address.
//////////////////////////////////////////////////////////////////
function isValidEmail(addr) {
   if ((addr.indexOf("@")  == -1) 
   ||  (addr.indexOf(".")  == -1) 
   ||  (addr.indexOf(" ")  != -1) 
   ||  (addr.indexOf(",")  != -1) 
   ||  (addr.indexOf(";")  != -1) 
   ||  (addr.indexOf(":")  != -1) 
   ||  (addr.indexOf("/")  != -1) 
   ||  (addr.indexOf("\\") != -1) 
   ||  (addr.indexOf("!")  != -1) 
   ||  (addr.indexOf("@@") != -1) 
   ||  (addr.indexOf("..") != -1) 
   ||  (addr.indexOf("@.") != -1) 
   ||  (addr.indexOf(")")  != -1) 
   ||  (addr.indexOf("(")  != -1) 
   ||  (addr.indexOf("#")  != -1) 
   ||  (endsWithletter(addr)  == false) 
      ) 
   {
      return false;
   } 
   else 
   {
		return true;
   }
}

//////////////////////////////////////////////////////////////////////
// This function will determine the number of checkboxes with their
// value checked.
//////////////////////////////////////////////////////////////////////
function NumberOfBoxesChecked(CheckboxObject)
{ 
	var NumChecked = 0;

	// loop thru all options
   	for (var i = 0; i < CheckboxObject.length; i++) 
	{
	   // if this option is checked
	   if (CheckboxObject[i].checked)
	   {
		NumChecked++;
	   }
	}
	return NumChecked;
}

//////////////////////////////////////////////////////////////////
// Determines if the input string contains only whitespace.
//////////////////////////////////////////////////////////////////
function isBlank(s) {
   if (s == "") return true
   for (var i = 0; i < s.length; i++) {
      var c = s.charAt(i);
      if ((c != " ") && (c != '\n') && (c != '\t')) return false;
   }
   return true; 
}

///////////////////////////////////////////////////////////////////////
// performSearch:  Asks the Ektron holder to resize for a search operation.
//////////////////////////////////////////////////////////////////////
function performSearch() 
{ 
	if (isBlank(document.getElementById('searchTerm').value))
	{
		alert('Please enter a search term');
		return;
	}
	window.location = document.getElementById('searchUrl').value+"?searchTerm="+document.getElementById('searchTerm').value;
} 

///////////////////////////////////////////////////////////////////////
// performSearch:  Asks the Ektron holder to resize for a search operation.
//////////////////////////////////////////////////////////////////////
function performHomeSearch(inEdition) 
{ 
	if (isBlank(document.getElementById('searchTerm').value))
	{
		alert('Please enter a search term');
		return;
	}
	
	// because of the stupid IE 6/7 bug with Google Ad Manager and document.domain. we use local (non-parent)
	// versions of some Javascript functions.  If it exists, use it.
	if(typeof local_displaySearchResults == 'function') 
	{ 
		local_displaySearchResults(inEdition,document.getElementById('searchTerm').value);
	}	
	else
	{
		window.parent.displaySearchResults(inEdition,document.getElementById('searchTerm').value);
	}
} 

///////////////////////////////////////////////////////////////////////
// This is my static function replacement method for Prototype $().present()
//////////////////////////////////////////////////////////////////////
function fieldValue(ElementId)
{ 
	// make sure the element exists
	if (document.getElementById(ElementId) != null)
	{
		return document.getElementById(ElementId).value;
	}
	return "";
}
