
var SearchEngineVariable = 'query';

var excludearray = new Array("about", "above", "according","actually","after", "afterwards", "aforesaid", "afore", "added", "admitted", "again", "all", "allegedly", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "an", "and", "another", "any", "anyhow","anyone", "anything", "anywhere", "are", "aren't", "around", "albeit", "anybody", "anyway", "apart", "as", "asked", "at", "available", "back", "be", "been", "became", "because", "become", "becomes", "becoming", "before", "beforehand", "began", "begin", "behind", "being", "beside", "besides", "bring", "brings", "brought", "bought", "but", "by", "called", "come", "came", "can", "can't", "cannot", "certain", "choose", "click", "complete", "come", "considered", "could", "couldn't", "described", "describes", "determine", "determined","definitely", "did", "didn't", "different","discussed", "do" ,"does", "doesn't" ,"doing", "don't", "done" ,"during", "each", "earlier", "either", "else" ,"elsewhere" ,"ending","enough", "etc", "ever", "every", "everyone", "everybody", "everything", "everywhere", "except", "extent" ,"excepted", "excepting", "exception", "exclude", "excluding", "exclusive", "farther", "few", "feedback", "find", "for", "forming" ,"formerly" ,"found", "from", "further", "furthermore", "furthest", "given", "get", "go", "goes", "going", "got", "had" ,"hardly" ,"has" ,"hasn't", "have", "haven't", "he", "he'd", "he'll", "he's", "hence" ,"here", "here's", "hereafter", "hereby" ,"herein", "hereupon", "hers", "herself", "him" ,"his", "himself", "how", "however", "henceforth", "hereabouts" ,"hereto", "hindmost", "hither", "hitherto", "howsoever", "i'd" ,"if" ,"i'll", "i'm" ,"in" ,"i've", "ie", "indeed", "instead" ,"into", "is", "isn't","it", "it's", "its", "itself", "inasmuch", "include", "included", "including", "inside" ,"insomuch" ,"inward" ,"inwards" ,"just", "know" ,"known", "knowing", "knew", "kind", "later", "latter", "least", "less" ,"lest" ,"let" ,"let's", "like", "likely", "look", "made" ,"make", "makes", "many", "may", "maybe", "me", "meantime", "meanwhile", "might", "more", "moreover", "most", "mostly" ,"much", "must", "my", "myself", "namely" ,"neither", "never" ,"nevertheless", "no", "nobody", "none", "nonetheless", "nor", "not", "nothing", "now", "nowhere", "nope" ,"notwithstanding", "nowadays", "obtained" ,"of", "off", "often", "oft", "ok" ,"on" ,"once", "one" ,"one's" ,"only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "overall" ,"own" ,"ought" ,"outside", "per", "perhaps", "possible", "presented", "presents", "purpose", "purposes", "purposely", "provide", "provided", "provides", "put", "quite", "rather", "recently", "reply", "replying", "really" ,"related", "required", "said","sake" ,"same" ,"save", "saw", "say", "says" ,"seem", "seemed" ,"seeming", "seems", "several" ,"seeing", "seen", "selected", "selves", "sent", "she", "she'd", "she'll", "she's" ,"should" ,"shouldn't", "since", "so", "some", "somehow", "someone", "something", "sometime", "sometimes" ,"somewhere", "such", "suggested", "shalt", "shown", "similarly" ,"similar", "significant", "somebody", "somewhat", "spoke", "spoken", "supposing", "taken", "taking", "tells" ,"tell", "than", "that", "that'll", "that's", "that've" ,"the" ,"their", "them", "themselves", "then", "thence" ,"there", "there'd", "there'll", "there're","there's", "there've", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "they'd", "they'll", "they're", "they've", "thenceforth", "thereabout", "thereabouts", "thereof", "thereon", "thereto", "this" ,"those", "till", "tough", "though", "through", "throughout" ,"thus", "to", "together", "told", "too", "took", "toward", "towards", "turned", "unable", "under", "unless", "unlike", "unlikely", "until" ,"upward", "upwards", "upon", "us" ,"used", "using", "use", "very","via", "various", "want", "wants", "was", "wasn't", "we" ,"we'd", "we'll" ,"we're" ,"we've", "well" ,"went" ,"were", "weren't" ,"what", "what'll", "what's", "what've", "whatever", "when", "whence", "whenever", "where", "where's", "whereafter", "whereas" ,"whereby" ,"wherein" ,"whereupon" ,"wherever", "whether", "whatsoever", "whensoever" ,"whereabouts", "whereat", "wherefore", "wherefrom", "whereinto", "whereof", "whereon", "wheresoever", "whereto", "whereunto", "wherewith", "whew", "whichever", "whichsoever", "whilst", "which" ,"while", "whither", "who", "whomsoever", "whosoever", "who'd" ,"who'll" ,"who's", "whoever" ,"whole", "whom", "whomever", "whose", "why", "wilt", "with", "within" ,"without", "won't" ,"would", "wouldn't", "worse", "worst", "wow", "yet", "you'd", "you'll", "you're", "you've", "your", "yours", "yourself", "yourselves", "you", "a", "b", "c", "d", "e", "f" ,"g", "h", "i", "j" ,"k", "l", "m" ,"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "people","&","!","%","*");

// called 4th //
function KeyWordIncludeReferrer()
{
   try
   {
      var ref = document.referrer.toUpperCase();
      if (ref.indexOf('CONNEXIONS') > 0) { SearchEngineVariable = 'query'; return true; }
	  if (ref.indexOf('CONNEXIONS_DEV') > 0) { SearchEngineVariable = 'query'; return true; }
	  if (ref.indexOf('CONNEXIONS_NEW') > 0) { SearchEngineVariable = 'query'; return true; }
   }
   catch (exception) { KeyWordProcessError('KeyWordIncludeReferrer',exception); }
   return false;
}

// 2 //
function KeyWordIncludeUrl()
{
    var Href = document.location.href.toUpperCase();
 
    try
    {
      if (Href.indexOf('CONNEXIONS') > -1 ) { return true; }
	  if (Href.indexOf('CONNEXIONS_DEV') > -1 ) { return true; }
      if (Href.indexOf('LOCALHOST') > -1 ) { return true; }	
      if (Href.indexOf('CONNEXIONS_NEW') > -1 ) { return true; }	
    }
    catch (exception) { KeyWordProcessError('KeyWordIncludeUrl',exception); }
    return false;
}

/*
// To get different background colors for different keywords //

function KeyWordGetColor(idx)
{
    var color = '#CCCCCC';

    switch (idx)
    {
       case 0:
	       color='#99FF99'; break;
       case 1:
               color='yellow'; break;
       case 2:
               color='#FFCCFF'; break;
       case 3:
               color='#CC99FF'; break;
       case 4:
               color='#99CCFF'; break;
       case 5:
               color='#FFCC99'; break;
       case 6:
               color='#CCCCFF'; break;
       case 7:
               color='#66CCFF'; break;
       default:
               break;
    }
    return color;
}



 function KeyWordExcludePhrase(keyword)
 {

    var ret = false;

    switch (keyword.toUpperCase())
    {
      case "AND": return true;
      case "OR" : return true;
      case "IN" : return true;
    }
	     
    return false;
 }
*/
  
function KeyWordExcludePhrase(keyword)
 {

    var ret = false;
	var j = excludearray.length;
	for (i=0;i<j ;i++ )
	{
		var temp = excludearray[i].toUpperCase();
		switch (keyword.toUpperCase())
		{
		  case temp: return true;
		  case " " : return true;
		  break;
		}
	}
    return false;
 }
 
// called 3rd //
function KeyWordGetKeyWordsFromQueryString()
{
   if (KeyWordIncludeReferrer() == false) { return true; }

   var keywords = new Array();
   var ref = document.location.href;
   var pair;
   var qIndex = 0;
   var qs;
   var prm;

   try
   {

    
     qIndex = ref.indexOf('?');

     if (qIndex < 1) { return keywords; }
     
     ref = KeyWordReplace(ref,'%22','');
	 ref = KeyWordReplace(ref,'%20','+');
	 ref = KeyWordReplace(ref,'%2C','+');
	 ref = KeyWordReplace(ref,',','+');
	 ref = KeyWordReplace(ref,' ','+');

     qs = ref.substring(qIndex + 1,ref.length);
     prm = qs.split('&');
     for (i=0;i<prm.length;i++)
     {
		   pair = prm[i].split('=');

		   temp = unescape(pair[0]).split('+');
		   name = temp.join(' ');
		   if (name != SearchEngineVariable) { continue; }

		   temp = unescape(pair[1]).split('+');
		   for(k=0;k<temp.length;k++)
		   {
			 if (KeyWordExcludePhrase(temp[k]) == true) { continue; }
			 if (temp[k] != '')
			 {
				 keywords.push(temp[k]);
			 }
		   }
     }

   }
   catch (exception) { KeyWordProcessError('KeyWordGetKeyWordsFromQueryString',exception); }
   return keywords;
}



// 1st called onLoad() //
function KeyWordHiLite()
{ 
  if (KeyWordIncludeUrl() == false) { return true; }

  var Links;
  var rng;
  var before = '<font style="color:#0000FF;font-weight:bold;background-color:#FFFF00';
  var after = '</b></font>';

  try
  {
     
    keywords = KeyWordGetKeyWordsFromQueryString();
    if (keywords.length < 1) { return true; }
    //Links = KeyWordGetLinks();
    for(k=0;k<keywords.length;k++)
    {
		
	  rng = document.body.createTextRange();  
	  rng.moveToElementText(document.getElementById('searchsection'));
	  rng.moveEnd('sentence',4);
  
      for (i=0;rng.findText(keywords[k])!=false; i++)
      { 
 
        try       { rng.pasteHTML(before + '"><b>' +  rng.text + after);   }
        catch (e) { KeyWordProcessError('KeyWordHiLite Text Range',e);    }	
        finally   { rng.collapse(false); }
      
      }

      rng.collapse(true);
    }

   // KeyWordCleanLinks(Links);
        
  }
  catch (exception) { KeyWordProcessError('KeyWordHiLite',exception); }
  
}


// 5th called //
function KeyWordGetLinks()
{

   var Links = new Array();
   
   for (i=0;i<document.body.getElementsByTagName('A').length;i++)
   {
	  Links[i] = new Array (document.body.getElementsByTagName('A')[i].href, document.body.getElementsByTagName('A')[i].innerHTML); 
   }

   return Links;
}



function KeyWordCleanLinks(Links)
{
  for (i=0;i<document.body.getElementsByTagName('A').length;i++)
  { 
    document.body.getElementsByTagName('A')[i].href = Links[i][0]; 
    document.body.getElementsByTagName('A')[i].innerHTML = Links[i][1];
  }
}


function KeyWordProcessError(functionName,e)
{
  if (e.description == null)
  {
	  //alert(functionName + ' ' + e.message); 
  }
  else
  { 
	  //alert(functionName + ' ' + e.description);
  }
}

function KeyWordReplace(OrgVal,SearchVal,ReplaceVal)
{
  var Val;
  var RegExp = eval("/" + SearchVal + "/g");
  if (OrgVal.indexOf(SearchVal) <1) {  return OrgVal; }
  Val = OrgVal.replace(RegExp,ReplaceVal);
  return Val;
}

 