// Copyright 2004 and onwards Google Inc.
//
// uncompressed / commented / renamed by Chris...
//

var test = "";
var C1_oldInputFieldValue=""; // inputField value (set during call to google...)...(was ta)
var C1_currentInputFieldValue=""; // also inputField value (was g)
var C1_G="";
var C1_eventKeycode=""; // event keycode... (was m)
var C1_highlightedSuggestionIndex=-1; // currently hightlighted suggestion index (was j)
var C1_highlightedSuggestionDiv=null; // currently highlisted suggestion div... (was h)
var C1_completeDivRows=-1; // completeDiv rows at time of keypress... (was Z)
var C1_completeDivDivList=null; // completeDiv div list at time of keypress (was za)
var C1_completeDivRows2=5; // was Ca... initially 5? not sure difference between this and _completeDivRows...
var C1_q="";
var C1_divTag="div"; // Was Lb
var C1_spanTag="span"; // Was Bb
var C1_inputField=null; // Input field on form... (was a)
var C1_completeDiv=null; // document.completeDiv (was b)
var C1_X=null;
var C1_cursorUpDownPressed=false;  // Was ra...
var C1_resultCache=new Object(); // This is a cache of results from google... (was Ua)
var C1_ca=1;
var C1_Aa=1;
var C1_Y=false;
var C1_lastKeyCode=-1; // Gets set on keyDown... Was na...
var C1_Va=(new Date()).getTime();
var C1_hasXMLHTTP=false; // Gets set to true if XMLHTTP Supported (was Q)
var C1_xmlHttp=null; // This is the XMLHttp Object... (was k)
var C1_B=null;
var C1_aa=null;
var C1_Ba=false;
var C1_Ka=false;
var C1_p=80; //percentage of column width
var C1_timeoutAdjustment=0; // timeout adjustment... (was W)... gets adjusted over time...
var C1_autoWidth = true;

// This is the function that get's called from the google html page...
// Line from page:
// InstallAC(document.f,document.f.q,document.f.btnG,"search","en");
// document.f is the name of the form on the page...
// document.f.q is the input text box on the page...
//  -> <input autocomplete="off" maxLength=256 size=55 name=q value="">
// document.f.btnG Google Search button

C1_InstallAC=function(auto,fld){
C1_InstallACA(auto, fld);
}

C1_InstallACA=function(auto,fld){
C1_autoWidth = auto;
C1_inputField=fld;

C1_Y=true;
C1_Ba=true;

C1_installACPartTwo();
}
;

// blurs focus, then sets focus again...
// This is getting aclled when we press cursor up / cursor down...
// Was Yb...
function C1_blurThenGetFocus(){
  C1_cursorUpDownPressed=true;
  C1_inputField.blur();
  setTimeout("C1_setInputFieldFocus();",10);
  return
}

// Was Pb
function C1_keyPressHandler(event){
  if(!event&&window.event) {
    event=window.event;
  }

  // Tri
  if(event.keyCode==13){
  	C1_Fa();
  	event.cancelBubble=true;
    event.returnValue=true;
  	return false;
  }
  var xMoz;
  if(xMoz && event && event.keyCode==188){
  	return false;
  }

  if(event) {
    C1_lastKeyCode=event.keyCode;
  }

  // We are backspacing here...
  if(event&&event.keyCode==8){
  	if (isNaN(C1_inputField.value))
	  C1_X=true;
	else
	  C1_X=false;

    if(C1_X&&(C1_inputField.createTextRange&&(event.srcElement==C1_inputField&&(C1_bb(C1_inputField)==0&&C1_lb(C1_inputField)==0)))){
      C1_cc(C1_inputField);
      event.cancelBubble=true;
      event.returnValue=false;
      return false
    }
  }
}

// Was Db..
function C1_resizeHandler(){
  C1_setCompleteDivSize()
}

// was ba...
function C1_setCompleteDivSize(){
  if(C1_completeDiv){
    C1_completeDiv.style.left=C1_calculateOffsetLeft(C1_inputField)+"px";
    C1_completeDiv.style.top=C1_calculateOffsetTop(C1_inputField)+C1_inputField.offsetHeight-1+"px";
    if (C1_autoWidth) {
    	C1_completeDiv.style.width=C1_calculateWidth()+"px";
    }
  }
}

// calculate width of inputField... Note browser specific adjustments...
// Was Ja()
function C1_calculateWidth(){
  if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
    return C1_inputField.offsetWidth-C1_ca*2
  }else{
    return C1_inputField.offsetWidth
  }
}


// Called from InstallAC...
// was ac()
function C1_installACPartTwo(){
  if(C1_getXMLHTTP()){
    C1_hasXMLHTTP=true
  }else{
    C1_hasXMLHTTP=false
  }

  C1_inputField.autocomplete="off";
  C1_inputField.onblur=C1_onBlurHandler;
  if(C1_inputField.createTextRange) {
  	// for IE
    C1_inputField.onkeyup=new Function("return C1_okuh(event);");
  } else {
    C1_inputField.onkeyup=C1_okuh;
  }
  C1_inputField.onsubmit=C1_Fa;
  C1_currentInputFieldValue=C1_inputField.value;
  C1_oldInputFieldValue=C1_currentInputFieldValue;
  C1_completeDiv=document.createElement("DIV");
  C1_completeDiv.id="C1_completeDiv";
  C1_ca=1;
  C1_Aa=1;

  C1_setCompleteDivSize();
  document.body.appendChild(C1_completeDiv);
  C1_cacheResults("",new Array(),new Array());
  C1_Gb(C1_completeDiv);
  var s=document.createElement("DIV");
  s.style.visibility="hidden";
  s.style.display="none";
  s.style.position="absolute";
  s.style.left="-10000";
  s.style.top="-10000";
  s.style.width="0";
  s.style.height="0";
  var M=document.createElement("DIV");
  M.completeDiv=C1_completeDiv;
  M.name="C1_completionFrame";
  M.id="C1_completionFrame";

  s.appendChild(M);
  document.body.appendChild(s);
  if(frames&&(frames["C1_completionFrame"]&&frames["C1_completionFrame"].frameElement)) {
    C1_B=frames["C1_completionFrame"].frameElement;
  } else {
    C1_B=document.getElementById("C1_completionFrame");
  }
  window.onresize=C1_resizeHandler;
  C1_inputField.onkeypress=C1_keyPressHandler;

 //Tri document.onkeydown=C1_keyDownHandler;
 // C1_setupKeydown1();

}

// Was Ob
function C1_onBlurHandler(event){
  if(!event&&window.event) {
    event=window.event;
  }
  if(!C1_cursorUpDownPressed){
    C1_hideCompleteDiv();
  }
  C1_cursorUpDownPressed=false
}

C1_okuh=function(e){
  C1_eventKeycode=e.keyCode;
  C1_aa=C1_inputField.value;
  C1_Oa();
}
;

// Was sfi..
C1_setInputFieldFocus=function(){
  C1_inputField.focus()
}
;

// strip CR from string...
// was Wb
function C1_stripCRFromString(va){
  for(var f=0,oa="",zb="\n\r"; f<va.length; f++) {
    if (zb.indexOf(va.charAt(f))==-1) {
      oa+=va.charAt(f);
    } else {
      oa+=" ";
    }
  }
return oa
}

// Find span value with className = dc...
// Was Qa
function C1_findSpanValueForClass(i,dc){
  var ga=i.getElementsByTagName(C1_spanTag);
  if(ga){
    for(var f=0; f<ga.length; ++f){
      if(ga[f].className==dc){
        var value=ga[f].innerHTML;
        if(value=="&nbsp;") {
          return"";
        } else{
          var z=C1_stripCRFromString(value);
          return z
        }
      }
    }
  }else{
    return""
  }
}

// Return null if i undefined...
// otherwise return value of span cAutoComplete...
// was U
function C1_valueOfCAutoComplete(i){
  if(!i) {
    return null;
  }
  //return C1_findSpanValueForClass(i,"cAutoComplete")
  return C1_findSpanValueForClass(i,"C1_Parta") + C1_findSpanValueForClass(i,"C1_Partb") + C1_findSpanValueForClass(i,"C1_Partc");

}

// Return null if i undefined...
// otherwise return value of span dAutoComplete...
// was wa
function C1_valueOfDAutoComplete(i){
  if(!i) {
    return null;
  }
  return C1_findSpanValueForClass(i,"C1_dAutoComplete")
}

// Was F
function C1_hideCompleteDiv(){
  document.getElementById("C1_completeDiv").style.visibility="hidden";
  document.getElementById("C1_completeDiv").style.display="none";

  //workaround IE bug
//  document.getElementById("css-select").style.visibility="visible";
//  document.getElementById("css-select").style.display="block";
}

// Was cb
function C1_showCompleteDiv(){

  document.getElementById("C1_completeDiv").style.visibility="visible";
  document.getElementById("C1_completeDiv").style.display="block";

  //workaround IE bug
//  document.getElementById("css-select").style.visibility="hidden";
//  document.getElementById("css-select").style.display="none";


  C1_setCompleteDivSize();
}

// This is a result caching mechanism...
// was Ma
function C1_cacheResults(is,cs,ds){
  C1_resultCache[is]=new Array(cs,ds)
}

// We get the following javascript code dynamically returned from google:
// sendRPCDone(frameElement, "fast bug", new Array("fast bug track", "fast bugs", "fast bug", "fast bugtrack"), new Array("793,000 results", "2,040,000 results", "6,000,000 results", "7,910 results"), new Array(""));
C1_sendRPCDone=function(fr,is,cs,ds,pr){
  if(C1_timeoutAdjustment>0) {
    C1_timeoutAdjustment--;
  }
  var lc=(new Date()).getTime();
  if(!fr) {
    fr=C1_B;
  }
  C1_cacheResults(is,cs,ds);
  var b=fr.completeDiv;
  b.completeStrings=cs;
  b.displayStrings=ds;
  b.prefixStrings=pr;
  C1_displaySuggestedList(b,b.completeStrings,b.displayStrings);
  C1_Pa(b,C1_valueOfCAutoComplete);
  if(C1_completeDivRows2>0) {
    b.height=16*C1_completeDivRows2+4;
  } else {
    C1_hideCompleteDiv();
  }
}

function C1_Oa(){
  // 38 is up cursor key, 40 is down cursor key...
  if(C1_eventKeycode==40||C1_eventKeycode==38) {
    C1_blurThenGetFocus();
  }
  var N=C1_lb(C1_inputField);
  var v=C1_bb(C1_inputField);
  var V=C1_inputField.value;

  if (isNaN(V))
  	C1_X=true;
  else
  	C1_X=false;

  if(C1_X&&C1_eventKeycode!=0){
    if(N>0&&v!=-1) {
      V=V.substring(0,v);
    }

    if(C1_eventKeycode==13||C1_eventKeycode==3){
      var d=C1_inputField;
      if(d.createTextRange){
        var t=d.createTextRange();
        t.moveStart("character",d.value.length);
        t.select()
      } else if (d.setSelectionRange){
        d.setSelectionRange(d.value.length,d.value.length)
      }
    } else {
      if(C1_inputField.value!=V){
        C1_selectEntry(V)
      }
    }
  }
  C1_currentInputFieldValue=V;

  //Tri reset selection
  var J=C1_completeDiv.getElementsByTagName(C1_divTag);
  var O=J.length;
  var f;
  for(var f=0; f<O; f++) {
    C1_setStyleForElement(J.item(f),"C1_aAutoComplete");
  }
  C1_handleCursorUpDownEnter(C1_eventKeycode);

}

function C1_Fa() {
  C1_hideCompleteDiv();
  return true
}

// Go read about encodeURIComponent here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmthencodeuricomponent.asp
// Basically converts a string to a valid uri... (spaces become %20, etc, etc..)
// this function was nb...
function C1_escapeURI(La){
  if(encodeURIComponent) {
    return encodeURIComponent(La);
  }
  if(escape) {
    return escape(La)
  }
}

// Was yb
// If Mb is 0, will return 150...
// If Mb is 3, will return 250...
// If Mb is 4, will return 450...
// If Mb is X, will return 850...
function C1_recalculateTimeout(Mb){
  var H=100;
  for(var o=1; o<=(Mb-2)/2; o++){
    H=H*2
  }
  H=H+50;
  return H
}

// This function sets itself up and gets called over and over (timeout driven)
// was idfn...
C1_mainLoop=function(){
	//tri - add test for enter key
  if ((C1_oldInputFieldValue!=C1_currentInputFieldValue) && C1_eventKeycode!=13){

    var Za=C1_escapeURI(C1_currentInputFieldValue);
    var ma=C1_resultCache[C1_currentInputFieldValue];

    if(ma){
      // Found in our cache...
      C1_Va=-1;
      C1_sendRPCDone(C1_B,C1_currentInputFieldValue,ma[0],ma[1],C1_B.completeDiv.prefixStrings);
    }else{
      C1_timeoutAdjustment++;
      C1_Va=(new Date()).getTime();
      if(C1_hasXMLHTTP){
        C1_callFindNearest(Za);
      }
    }
    C1_inputField.focus();
  }
  C1_oldInputFieldValue=C1_currentInputFieldValue;
  setTimeout("C1_mainLoop()",C1_recalculateTimeout(C1_timeoutAdjustment));
  return true
}
;
// Call mainLoop() after 10 milliseconds...
setTimeout("C1_mainLoop()",10);

// This is onMouseDown function...
var C1_Cb=function(){
  C1_q=C1_valueOfDAutoComplete(this);
  C1_selectEntry(C1_valueOfCAutoComplete(this));
  C1_Fa();
}
;

// on mouseover...
var C1_pb=function(){
  if(C1_highlightedSuggestionDiv) {
    C1_setStyleForElement(C1_highlightedSuggestionDiv,"C1_aAutoComplete");
  }
  //Tri
  C1_highlightedSuggestionIndex =this.id;
  C1_setStyleForElement(this,"C1_bAutoComplete")
}
;

// On Mouse out...
var C1_ec=function(){
  C1_setStyleForElement(this,"C1_aAutoComplete")
}
;

// Called when cursor up/down pressed... selects new entry in completeDiv...
// was Na
function C1_highlightNewValue(C){

  C1_currentInputFieldValue=C1_G;
  C1_selectEntry(C1_G);

  C1_q=C1_G;

  if(!C1_completeDivDivList||C1_completeDivRows<=0) {
    return;
  }

  C1_showCompleteDiv();
  if(C>=C1_completeDivRows){
    C=C1_completeDivRows-1;
  }

  if(C1_highlightedSuggestionIndex!=-1&&C!=C1_highlightedSuggestionIndex){
    C1_setStyleForElement(C1_highlightedSuggestionDiv,"C1_aAutoComplete");
    C1_highlightedSuggestionIndex=-1;
  }

  if(C<0){
    C1_highlightedSuggestionIndex=-1;
    C1_inputField.focus();
    return
  }

  C1_highlightedSuggestionIndex=C;

  //test = test + '\nC1_highlightNewValue2 : ' + C1_highlightedSuggestionIndex
  //peek(test);

  C1_highlightedSuggestionDiv=C1_completeDivDivList.item(C);
  C1_setStyleForElement(C1_highlightedSuggestionDiv,"C1_bAutoComplete");
  C1_currentInputFieldValue=C1_G;
  //C1_q=C1_valueOfDAutoComplete(C1_highlightedSuggestionDiv);

  C1_selectEntry(C1_valueOfCAutoComplete(C1_highlightedSuggestionDiv));
}

// Was Eb
// returns false if cursor up / cursor down or enter pressed...
function C1_handleCursorUpDownEnter(eventCode){

  //test = test + '\nC1_handleCursorUpDownEnter : ' + C1_highlightedSuggestionIndex
  //peek(test);

  if(eventCode==40){
    C1_highlightNewValue(1*C1_highlightedSuggestionIndex+1);
    return false
  }else if(eventCode==38){
    C1_highlightNewValue(1*C1_highlightedSuggestionIndex-1);
    return false
  }else if(eventCode==13||eventCode==3){
    return false
  }
  return true
}

// Pa(completeDiv,H)
// This function gets called for every keypress I make...except up down
function C1_Pa(localCompleteDiv,ib){
  var localInputField=C1_inputField;
  var T=false;
  C1_highlightedSuggestionIndex=-1;
  // This becomes the rows in our suggestion list...
  var J=localCompleteDiv.getElementsByTagName(C1_divTag);
  // # of rows in list...
  var O=J.length;
  C1_completeDivRows=O;
  C1_completeDivDivList=J;
  C1_completeDivRows2=O;
  C1_G=C1_currentInputFieldValue;
  if(C1_currentInputFieldValue==""||O==0){
    C1_hideCompleteDiv()
  }else{
    C1_showCompleteDiv()
  }

  var Ab="";
  if(C1_currentInputFieldValue.length>0){
    var f;
    var o;
    // My prefixStrings was always an empty array...
    // So local variable T never would be set to true...
    // And the local variable Ab would remain empty...
    for(var f=0; f<O; f++){
      for(o=0; o<localCompleteDiv.prefixStrings.length; o++){
        var Ib=localCompleteDiv.prefixStrings[o]+C1_currentInputFieldValue;

        if(C1_Y||ib(J.item(f)).toUpperCase().indexOf(Ib.toUpperCase())==0) {
          Ab=localCompleteDiv.prefixStrings[o];
          T=true;
          break
        }
      }
      if(T){
        break
      }
    }
  }
  if(T) {
    C1_highlightedSuggestionIndex=f;

  	//test = test + '\nC1_Pa : ' + C1_highlightedSuggestionIndex;
  	//peek(test);
  }

  for(var f=0; f<O; f++) {
    C1_setStyleForElement(J.item(f),"C1_aAutoComplete");
  }
  if(T){
    C1_highlightedSuggestionDiv=J.item(C1_highlightedSuggestionIndex);
    C1_q=C1_valueOfDAutoComplete(C1_highlightedSuggestionDiv)
  }else{
    C1_q=C1_currentInputFieldValue;
    C1_highlightedSuggestionIndex=-1;
    C1_highlightedSuggestionDiv=null
  }
  var ab=false;
  switch(C1_eventKeycode){
    // cursor left, cursor right, others??
    case 8:
    case 33:
    case 34:
    case 35:
    case 35:
    case 36:
    case 37:
    case 39:
    case 45:
    case 46:
    case 188:
      ab=true;
      break;
    default:
      // regular keypress ...
      break
  }

  if(!ab&&C1_highlightedSuggestionDiv){
    var Da=C1_currentInputFieldValue;
    C1_setStyleForElement(C1_highlightedSuggestionDiv,"C1_bAutoComplete");
    var z;
    if(T) {

      z=ib(C1_highlightedSuggestionDiv).substr(localCompleteDiv.prefixStrings[o].length);

    } else {
      z=Da;
    }

    if(z!=localInputField.value){
      if(localInputField.value!=C1_currentInputFieldValue) {
        return;
      }

	  if (isNaN(C1_inputField.value))
	  	C1_X=true;
	  else
	  	C1_X=false;

      if(C1_X){
        if(localInputField.createTextRange||localInputField.setSelectionRange) {
          C1_selectEntry(z);
        }
        if(localInputField.createTextRange){
          var t=localInputField.createTextRange();
          t.moveStart("character",Da.length);
          t.select()
        }else if(localInputField.setSelectionRange){
          localInputField.setSelectionRange(Da.length,localInputField.value.length)
        }
      }
    }
  }else{
    C1_highlightedSuggestionIndex=-1;
    C1_q=C1_currentInputFieldValue
  }
}

// Called as:
// calculateOffsetLeft(_inputField)
// was ob
function C1_calculateOffsetLeft(r){
  return C1_Ya(r,"offsetLeft")
}

// Called as:
// calculateOffsetTop(_inputField)
// Was Qb...
function C1_calculateOffsetTop(r){
  return C1_Ya(r,"offsetTop")
}

function C1_Ya(r,attr){
  var kb=0;
  while(r){
    kb+=r[attr];
    r=r.offsetParent
  }
  return kb
}

// Was Ha
function C1_setInputFieldSize(){
  var xa=document.body.scrollWidth-220;
  xa=0.73*xa;
  C1_inputField.size=Math.floor(xa/6.18)
}
function C1_lb(n){
  var N=-1;
  if(n.createTextRange){
    var fa=document.selection.createRange().duplicate();
    N=fa.text.length
  }else if(n.setSelectionRange){
    N=n.selectionEnd-n.selectionStart
  }
  return N
}

function C1_bb(n){
  var v=0;
  if(n.createTextRange){
    var fa=document.selection.createRange().duplicate();
    fa.moveEnd("textedit",1);
    v=n.value.length-fa.text.length
  }else if(n.setSelectionRange){
    v=n.selectionStart
  }else{
    v=-1
  }
  return v
}
function C1_cc(d){
  if(d.createTextRange){
    var t=d.createTextRange();
    t.moveStart("character",d.value.length);
    t.select()
  } else if(d.setSelectionRange) {
    d.setSelectionRange(d.value.length,d.value.length)
  }
}

// Ex: setStyleForElement(document.createElement("DIV"), "aAutoComplete");
// was l
function C1_setStyleForElement(c,name){
  C1_db();
  c.className=name;
  if(C1_Ka){
    return
  }

  //Tri
  //switch(name.charAt(0)){
	switch(name.charAt(3)){

    case "a":
      c.style.backgroundColor="white";
      c.style.color="black";
      if(c.displaySpan){
        c.displaySpan.style.color="#F46C0C"
        c.displaySpan.style.align="right";
      }
      break;
    case "b":
      c.style.backgroundColor="#0073BA";
      c.style.color="white";
      if(c.displaySpan){
        c.displaySpan.style.color="white"
      }
      break;
    case "c":
      c.style.width=C1_p+"%";
      c.style.cssFloat="left";
      break;
    case "d":
      c.style.cssFloat="right";
      c.style.width=100-C1_p+"%";
      c.style.textAlign="right";
      c.style.color="#F46C0C";
      c.style.paddingTop="0px"
      if (xIE4Up) {
      	c.style.paddingLeft="10px"
      }

      break
  }
}

//function to calculate and set column widths
function C1_db(){
var wb=10;
var Sa;
if (C1_autoWidth) {
	Sa = C1_calculateWidth();
} else {
	Sa = 250;
}

var tb=(Sa-wb)/Sa*100;
C1_p=tb

}

function C1_Gb(i){
  C1_db();
  var Ub="font-size: 13px; font-family: arial,sans-serif; word-wrap:break-word; ";
  var Vb="display: block; padding-left: 3; padding-right: 3; height: 16px; overflow: hidden; ";
  var bc="background-color: white; ";
  var qb="background-color: #3366cc; color: white ! important; ";
  var ub="display: block; margin-left: 0%; width: "+C1_p+"%; float: left; ";
  var Ga="display: block; margin-left: "+C1_p+"%; ";

  Ga+="font-size: 10px; text-align: right; color: green; padding-top: 3px; "

  C1_D(".C1_mAutoComplete",Ub);
  C1_D(".C1_lAutoComplete",Vb);
  C1_D(".C1_aAutoComplete *",bc);
  C1_D(".C1_bAutoComplete *",qb);
  C1_D(".C1_cAutoComplete",ub);
  C1_D(".C1_dAutoComplete",Ga);
  C1_setStyleForElement(i,"C1_mAutoComplete")
}

// Called from sendRPCResponse...
// i = fr.completeDiv
// cs = list of comlete strings...
// Hb = list of results...
// was rb
function C1_displaySuggestedList(i,cs,Hb){
  while(i.childNodes.length>0) {
    i.removeChild(i.childNodes[0]);
  }
  // For each element in our list, we create:
  // <DIV (u) - mousedown/mouseover/mouseout aAutoComplete>
  //   <SPAN (ka) lAutoComplete>
  //     <SPAN (ua) cAutoComplete>
  //        bug tracking
  //     </SPAN (ua)>
  //     <SPAN (ea) dAutoComplete>
  //        500,000 results
  //     </SPAN (ea)>
  //   </SPAN>
  // </DIV (u)>
  for(var f=0; f<cs.length; ++f){
    var u=document.createElement("DIV");
    C1_setStyleForElement(u,"C1_aAutoComplete");
    u.id = f;
    u.onmousedown=C1_Cb;
    u.onmouseover=C1_pb;
    u.onmouseout=C1_ec;
    var ka=document.createElement("SPAN");
    C1_setStyleForElement(ka,"C1_lAutoComplete");

    var ua=document.createElement("SPAN");
    //ua.innerHTML=cs[f]; // the text for the suggested result...

    var objParta=document.createElement("SPAN");
    var objPartb=document.createElement("SPAN");
    var objPartc=document.createElement("SPAN");
    var objStr1, objStr2, intPos;
    var objExp;

    objStr1 = new String(C1_currentInputFieldValue);
    objStr1 = new String(objStr1.toUpperCase());

    objStr2 = new String(cs[f]);
    objStr2 = new String(objStr2.toUpperCase());

	intPos = objStr2.indexOf(objStr1.toString());
	objParta.innerHTML=objStr2.substr(0,intPos);
   	objPartb.innerHTML=objStr1.toString();
   	objExp = new RegExp(" ", "gi")
   	objPartc.innerHTML=objStr2.substr(objStr1.length+intPos).replace(objExp, "&nbsp;");

    var ea=document.createElement("SPAN");
    C1_setStyleForElement(ea,"C1_dAutoComplete");
    C1_setStyleForElement(ua,"C1_cAutoComplete");
    C1_setStyleForElement(objParta,"C1_Parta");
    C1_setStyleForElement(objPartb,"C1_Partb");
    C1_setStyleForElement(objPartc,"C1_Partc");
    //u.displaySpan=ea;

   	ua.appendChild(objParta);
   	ua.appendChild(objPartb);
   	ua.appendChild(objPartc);
    ka.appendChild(ua);
    ka.appendChild(ea);
    u.appendChild(ka);
    i.appendChild(u)
  }
}

function C1_D(name,gb){
  if(C1_Ka){
    var I=document.styleSheets[0];
    if(I.addRule){
      I.addRule(name,gb)
    }else if(I.insertRule){
      I.insertRule(name+" { "+gb+" }",I.cssRules.length)
    }
  }
}

// Was function jb...
// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
//function C1_getXMLHTTP(){
//  var A=null;
//  try{
//    A=new ActiveXObject("Msxml2.XMLHTTP")
//  }catch(e){
//    try{
//      A=new ActiveXObject("Microsoft.XMLHTTP")
//    } catch(oc){
//      A=null
//    }
//  }
//  if(!A && typeof XMLHttpRequest != "undefined") {
//    A=new XMLHttpRequest()
//  }
//  return A
//}

  function C1_getXMLHTTP(){
	var req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	return req
}



// This function uses the xmlHttp object to send a message back to google...
// This is the primary function that dynamically communicates with google.
// was fc
// This is the call:
// http://www.google.com/complete/search?hl=en&js=true&qu=fast%20bug
// And we get back:
// sendRPCDone(frameElement, "fast bug", new Array("fast bug track", "fast bugs", "fast bug", "fast bugtrack"), new Array("793,000 results", "2,040,000 results", "6,000,000 results", "7,910 results"), new Array(""));
function C1_callFindNearest(Rb){

  if(C1_xmlHttp&&C1_xmlHttp.readyState!=0){
    C1_xmlHttp.abort()
  }
  C1_xmlHttp=C1_getXMLHTTP();
  if(C1_xmlHttp){
    // We end up calling:
    // /complete/search?hl=en&js=true&qu=<my query string...> ...

    //<tri> - call SSS
//    C1_xmlHttp.open("GET","/sss/xml/sss_ac.asp?ci=1&lin="+Rb,true);
    C1_xmlHttp.open("GET","/ziumsystem/vbs_autocomplete.asp?ci=1&lin="+Rb,true);
    //C1_xmlHttp.open("GET","http://home/sss/xml/sss_ac.asp?ci=1&lin="+Rb,true);
	//</tri>

    // Note that this function will ONLY be called when we get a complete
    // response back from FindNearest!!
    C1_xmlHttp.onreadystatechange=function() {
      if(C1_xmlHttp.readyState==4&&C1_xmlHttp.responseText) {
        var frameElement=C1_B;
        if(C1_xmlHttp.responseText.charAt(0)=="<"){
          C1_timeoutAdjustment--
        }else{
          // The response text gets executed as javascript...
          eval(C1_xmlHttp.responseText)
          //alert(C1_xmlHttp.responseText);
        }
      }
    }
    ;
    // DON'T TRY TO TALK WHEN WE'RE LOCAL...
    // Comment out when running from a local file...
    C1_xmlHttp.send(null)
  }
}

// Select suggested entry...
// Wa is the value to set the inputfield to...
// was S
function C1_selectEntry(Wa){
var objExp, objStr, strInputFieldValue;
var index;

objExp = new RegExp("&nbsp;", "gi")
objStr = new String(Wa);

//alert(Wa);

strInputFieldValue = objStr.replace(objExp, " ").toString();
index=C1_GetSelectedIndex(strInputFieldValue)
try
	{
	document.getElementById("spatialsearch").originlocalityid.value=C1_resultCache[C1_currentInputFieldValue][1][index]
	}
	catch(err)
	{
	}

//alert(C1_resultCache[C1_currentInputFieldValue][1][index]);
//window.status=document.getElementById("spatialsearch").originlocalityid.value;

C1_inputField.value=strInputFieldValue;
C1_aa=strInputFieldValue;
}

// Tri
function C1_GetSelectedIndex(Selected){
	try{
		var x;
		var foundindex;
		var found;

		found = false;
		x=0;
		foundindex = -1;
		while (x<C1_resultCache[C1_currentInputFieldValue][0].length && !found){

			if (Selected==C1_resultCache[C1_currentInputFieldValue][0][x]){
				foundindex = x;
				found = true;
			}
			x=x+1;

		}
		//window.status=foundindex;
		return foundindex;
	}
	catch(err)
	{
		//err handling here
	}
}


