// JavaScript Document
function init_func() {
	if(document.getElementById("include_highlight_script")) highlightSearchTerms(highlight_text,  false);
	
	//if(document.getElementById && document.compatMode && window.XMLHttpRequest) return;
	var MainNavItems = document.getElementById("nav").getElementsByTagName("li");
	var SubNavItems = document.getElementById("sub_nav").getElementsByTagName("li");
	if(document.getElementById("map")) {
		var mapItems = document.getElementById("map").getElementsByTagName("li");
		ie_hover_li(mapItems);	
	}
	if(document.getElementsByTagName("button")) {
		var buttons = document.getElementsByTagName("button");	
		ie_hover_li(buttons);	
	}
	ie_hover_li(MainNavItems);
	ie_hover_li(SubNavItems);

	
	}
	
function ie_hover_li(navItems) {
	for (var i=0; i<navItems.length; i++) {
		if(navItems[i].className == "menuparent") {
			navItems[i].onmouseover=function() { 	
			this.className += " over";
			 }
			navItems[i].onmouseout=function() { 
			this.className = "menuparent"; 
			}
		}
	}
}

function doHighlight(bodyText, searchTerm) 
{
  // the highlightStartTag and highlightEndTag parameters are optional

    highlightStartTag = "<span class='highlight' >";
    highlightEndTag = "</span>";

  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
  
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
		if(lcBodyText.charAt(i-1) != ' ') {
			if(lcBodyText.charAt(i-1) != '>') continue;
		}
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}
function highlightSearchTerms(searchText, warnOnFailure)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
	if(searchText == '') return false;
    searchArray = searchText.split(",");
	
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.getElementById('container').innerHTML;
  for (var i = 0; i < searchArray.length; i++) {

   if(searchArray[i] != '' && searchArray[i] != ' ') bodyText = doHighlight(bodyText, searchArray[i]);
  }
  
  document.getElementById('container').innerHTML = bodyText;
  return true;
}