<!--

// Define global variables
var SEARCHANY     = 1;
var SEARCHALL     = 2;
var SEARCHURL     = 4;
var searchType  = '';
var showMatches   = 100;
var currentMatch  = 0;
var copyArray   = new Array();
var docObj      = parent.document;

// search term highlighting function
function highlightWord(node,word) { 
	if (node.hasChildNodes) { 
		var hi_cn; 
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) { 
			highlightWord(node.childNodes[hi_cn],word); 
		} 	
	} 
	if (node.nodeType == 3) { 
		tempNodeVal = node.nodeValue.toLowerCase(); 
		tempWordVal = word.toLowerCase(); 
		if (tempNodeVal.indexOf(tempWordVal)!= -1) { 
			pn = node.parentNode; 
			if (pn.className!= "searchword") { 
				nv = node.nodeValue; 
				ni = tempNodeVal.indexOf(tempWordVal); 
				before = document.createTextNode(nv.substr(0,ni)); 
				docWordVal = nv.substr(ni,word.length); 
				after = document.createTextNode(nv.substr(ni+word.length)); 
				hiwordtext = document.createTextNode(docWordVal); 
				hiword = document.createElement("span"); 
				hiword.className = "searchword"; 
				hiword.appendChild(hiwordtext); 
				pn.insertBefore(before,node); 
				pn.insertBefore(hiword,node); 
				pn.insertBefore(after,node); 
				pn.removeChild(node); 
			} 
		} 
	} 
};

// Determine the type of search, and make
// sure the user has entered something
function validate(entry) {  
  if (entry.charAt(0) == "+") {
    entry = entry.substring(1,entry.length);
    searchType = SEARCHALL;
    }
  else if (entry.substring(0,4) == "url:") {
    entry = entry.substring(5,entry.length);
    searchType = SEARCHURL;
    }
  else { searchType = SEARCHANY; }
  while (entry.charAt(0) == ' ') {
    entry = entry.substring(1,entry.length);
    document.forms['search'].query.value = entry;
    }
  while (entry.charAt(entry.length - 1) == ' ') {
    entry = entry.substring(0,entry.length - 1);
    document.forms['search'].query.value = entry;
    }
  if (entry.length < 3) {
	document.getElementById('noMatchList').innerHTML = ('<p><center>' +
    'Please enter a valid Search Term.<BR><BR>' +
	'Go back and <a href=\"#\" onclick=\"viewAll();return false;\" title=\"view all\">view all</a> criteria</center></p>');
  	document.getElementById('newContent').innerHTML = ('');
    document.forms['search'].query.focus();
    return;
    }	
  convertString(entry);     
  }

// Put the search terms in an array and
// and call appropriate search algorithm
function convertString(reentry) {
  var searchArray = reentry.split(" ");
  if (searchType == (SEARCHANY | SEARCHALL)) { requireAll(searchArray); }
  else { allowAny(searchArray); }  
  }

// Define a function to perform a search that requires
// a match of any of the terms the user provided
function allowAny(t) {	
  var findings = new Array(0);  
  for (i = 0; i < criteria.length; i++) {
    var compareElement  = criteria[i].toUpperCase();
    if(searchType == SEARCHANY) { var refineElement  = compareElement.substring(0,compareElement.indexOf('|HTTP')); }
    else { var refineElement = compareElement.substring(compareElement.indexOf('|HTTP'), compareElement.length); }
    for (j = 0; j < t.length; j++) {
      var compareString = t[j].toUpperCase();
      if (refineElement.indexOf(compareString) != -1) {
        findings[findings.length] = criteria[i];
        break;
        }
      }
    } 
  verifyManage(findings);
  }

// Define a function to perform a search that requires
// a match of all terms the user provided
function requireAll(t) {	
  var findings = new Array();
  for (i = 0; i < criteria.length; i++) {	  
    var allConfirmation = true;
    var allString       = criteria[i].toUpperCase();
    var refineAllString = allString.substring(0,allString.indexOf('|HTTP'));
    for (j = 0; j < t.length; j++) {
      var allElement = t[j].toUpperCase();	  
      if (refineAllString.indexOf(allElement) == -1) {
        allConfirmation = false;		
        continue;
        }
      }
    if (allConfirmation) {
      findings[findings.length] = criteria[i];
      }
    }	
  verifyManage(findings);
  }

// Determine whether the search was successful
// If so print the results; if not, indicate that, too
function verifyManage(resultSet) {
	
  if (resultSet.length == 0) { noMatch(); }
  else {	
    copyArray = resultSet.sort();
    /*formatResults(copyArray, currentMatch, showMatches);*/
	formatResults(copyArray, currentMatch, showMatches);	
    }
  }

// Define a function that indicates that the returned no results
function noMatch() {
  document.getElementById('noMatchList').innerHTML = ('<p><center>' +
    'Search Term: <B><I>"' + document.forms['search'].query.value +
    '"</I></B> returned no results.<BR><BR>' +
	'Go back and <a href=\"#\" onclick=\"viewAll();return false;\" title=\"view all\">view all</a> criteria</center></p>');
  document.getElementById('newContent').innerHTML = ('');
  docObj.close();
  }

// Define a function to print the results of a successful search
function formatResults(results, reference, offset) {	
  document.getElementById('newContent').innerHTML = ('');
  var currentRecord = (results.length < reference + offset ? results.length : reference + offset);  
  document.getElementById('noMatchList').innerHTML = ('<p><center>' +
    'Search Query: <B><I>' + document.forms['search'].query.value + '</I></B><BR>' +
	'Search Results: <B><I>' + (reference + 1) + ' - ' +
    currentRecord + ' of ' + results.length + '</I></B><BR><BR>' +
	'Go back and <a href=\"#\" onclick=\"viewAll();return false;\" title=\"view all\">view all</a> criteria</center><BR></p>');  
  /*document.forms['search'].query.style.backgroundColor = '#989898';*/

  if (searchType == SEARCHURL) {
    for (var i = reference; i < currentRecord; i++) {
      var divide = results[i].split("|");
      document.getElementById('newContent').innerHTML += ('<DIV class=squareboxbottom>' +
	  '<DIV class=squareboxgradientcaptionSelected>' +
	  '<DIV class=floatLeft >' + divide[2] + '</DIV>' +
	  '<DIV class=chevron ><IMG title=Show/Hide alt=Show/Hide src=../images/panel_expand.gif border=0></DIV>' +
	  '<DIV class=spacer >&nbsp;</DIV>' +
	  '</DIV>' +
	  '<DIV class=squareboxcontent yesPrint>' +
	  '<P>' + divide[1] + '</P>' +
	  '</DIV>' +
	  '</DIV></DIV><br />');
      }
    }
  else {
    for (var i = reference; i < currentRecord; i++) {
      var divide = results[i].split('|');	  
      document.getElementById('newContent').innerHTML += ('<DIV class=squareboxbottom>' +
	  '<DIV class=squareboxgradientcaptionSelected>' +
	  '<DIV class=floatLeft >' + divide[0] + '</DIV>' +
	  '<DIV class=chevron ><IMG title=Show/Hide alt=Show/Hide src=../images/panel_expand.gif border=0></DIV>' +
	  '<DIV class=spacer >&nbsp;</DIV>' +
	  '</DIV>' +
	  '<DIV class=squareboxcontent yesPrint>' +
	  '<P>' + divide[1] + '</P>' +
	  '</DIV></DIV><br />');	  
	  // highlighting 
		 if (!document.createElement) return; 
		 ref = document.referrer; 
		 highlightWord(document.getElementById('newContent'),document.forms['search'].query.value);
	  // end
      }
    }	
  docObj.close();
  document.forms['search'].query.select();
  }
  
  function viewAll() {
	  window.location.reload();
	  document.getElementById('searchTerm').value = ('');	  
  }
//-->