var $a=null;
var $b=null;
var $c=null;
var $d=new Object();
var $e=-1;
var $f=false;
var $g=null;
var $h=0;
var $i="";
var $j="";
var $k=0;
var $l=false;
var $m=0;
var $n="DIV";
var $o="SPAN";
var $l=false;
var $p=null;
var _acElement=null;
var $q=-1;
var $r=null;
var $s=1;
var $t=1;
var $u=30;
var $v=-1;
var $w=null;
var $x=null;
$exch=null;

HookAC=function($y,$z,$A,$B,$C,$D,$Exch){
  $a=$y;
  $b=$z;
  $c=$A;
  $exch=$Exch;
  if(!$C){$C=30;};
  $u=$C;
  if($B){$m=$B;};
  $f=!(!getXMLHttpObject());
  if(!$D){
    $x=function(){
      return true;
    };
  } else {
    $x=$D;
  };
  
  $a.onsubmit=searchformSubmit;
  $b.autocomplete="off";
  $b.onblur=$E;
  if($b.createTextRange){
    $b.onkeyup=new Function("return OnKeyUpHandler(event);");
  } else {
    $b.onkeyup=OnKeyUpHandler;
  };
  
  $b.onsubmit=searchformSubmit;
  $j=$b.value;
  $i=$j;
  $p=document.createElement($n);
  $p.id="autocompleteDiv";
  $p.style.borderRight="black "+$s+"px solid";
  $p.style.borderLeft="black "+$s+"px solid";
  $p.style.borderTop="black "+$t+"px solid";
  $p.style.borderBottom="black "+$t+"px solid";
  $p.style.zIndex="1";
  $p.style.paddingRight="0";
  $p.style.paddingLeft="0";
  $p.style.paddingTop="0";
  $p.style.paddingBottom="0";
  setCompleteDivSize();
  $p.style.visibility="hidden";
  $p.style.position="absolute";
  $p.style.backgroundColor="white";
  $p.style.cursor="pointer";
  document.body.appendChild($p);
  setStyleForElement($p,"mAutoComplete");
  var s=document.createElement("DIV");
  s.style.visibility="hidden";
  s.style.position="absolute";
  s.style.left="-10000";
  s.style.top="-10000";
  s.style.width="0";
  s.style.height="0";
  var M=document.createElement("IFRAME");
  M.completeDiv=$p;
  M.name="completionFrame";
  M.id="completionFrame";
  s.appendChild(M);
  document.body.appendChild(s);
  
  autoCache("",new Array(),new Array());
  _acElement=M;
  document.onkeydown=keyDownHandler;
  addResizeEvent(resizeHandler);
};

function displaySuggestions($F,$G,$H){
  while($F.childNodes.length>0){
    $F.removeChild($F.childNodes[0]);
  };
  for(var i=0;i<$G.length;i++){
    var $I=document.createElement($n);
    var $J=document.createElement($o);
    var $K=document.createElement($o);
    var $L=document.createElement($o);
    setStyleForElement($I,"aAutoComplete");
    $I.onmousedown=$M;
    $I.onmouseover=$N;
    $I.onmouseout=$O;
    setStyleForElement($J,"lAutoComplete");
    setStyleForElement($K,"cAutoComplete");
    setStyleForElement($L,"dAutoComplete");
    $K.innerHTML=htmlencode($G[i]);
    $L.innerHTML=htmlencode($H[i]);
    $I.displaySpan=$L;
    $J.appendChild($L);
    $J.appendChild($K);
    $I.appendChild($J);
    $F.appendChild($I);
  };
};

function serverCall($P){
  if($g&&$g.readyState!=0){$g.abort();};
  $g=getXMLHttpObject();
  if($g){
    $g.open('Get','irRPC.php?q='+$P+'&exch='+$exch,true);
    $g.onreadystatechange=function(){
      if($g.readyState==4&&$g.responseText){
        if(($g.responseText.charAt(0)=="<")||($g.responseText.charAt(0)=="")){
          $Q--;
        } else {eval($g.responseText);};
      };
    };
    $g.send(null);
  };
};

mainLoop=function(){
  if(!$l){
    if($i!=$j){
      var $R=escapeURI($j);
      var $S=$d[$j];
      if($S){
        rpcCallback(_acElement,$j,$S[0],$S[1],new Array(''));
      } else {
        $h++;if($f){serverCall($j);};
      };
      setInputFocus();
    };
  };
  
  $i=$j;
  setTimeout("mainLoop()",recalculateTimeout($h));
  return true;
};

setTimeout("mainLoop()",10);

function recalculateTimeout(Mb){
  return 50;
};

OnKeyUpHandler=function(e){
  $k=e.keyCode;
  $l=false;
  ProcessKeys();
};

$E=function(e){
  if(!$l){hideAC();};
};

var $M=function(){
  $b.value=htmldecode(getSpanByName(this,"cAutoComplete"));
  searchformSubmit();
};

var $N=function(){
  if($w){
    setStyleForElement($w,"aAutoComplete");
  };
  setStyleForElement(this,"bAutoComplete");
};

var $O=function(){
  setStyleForElement(this,"aAutoComplete");
};

function ProcessKeys(){
  var $T=new String($b.value);
  $j=$T.substr(0,UserTextLength($b));
  if($k==40||$k==38){
    $l=true;
    $b.blur();
    setTimeout("setInputFocus();",10);
    if(!isACVisible()){return;};
    if($k==40){
      doHighlight($v+1);
      return;
    } else if($k==38){
      doHighlight($v-1);
      return;
    };
  } else {
    $l=false;
    $v=-1;
    var $U=$p.getElementsByTagName($n);
    var $V=$U.length;
    $q=$V;
    $r=$U;
    if($j==""||$V==0){
      hideAC();
      return;
    } else { showAC();};
    for(var i=0;i<$V;i++){
      setStyleForElement($U.item(i),"aAutoComplete");
    };
    var $W=$j;
    var $X=htmldecode(getSpanByName($r.item(0),"cAutoComplete"));
    var $Y=$X.indexOf($W.toUpperCase())==0;
    if($Y&&$k!=8&&$k!=46){
      doHighlight(0);
      var $Z=$W.length;
      if($W!=$X){
        if($b.createTextRange){
          $b.value=$X;
          var $00=$b.createTextRange();
          $00.moveStart("character",$Z);
          $00.select();
        } else if($b.setSelectionRange){
          $b.value=$X;
          $b.setSelectionRange($Z,$X.length);
        };
      };
    };
  };
};

rpcCallback=function(frameElement,$01,$G,$H,$02){
  if(!frameElement){frameElement=_acElement;};
  autoCache($01,$G,$H);
  var b=frameElement.completeDiv;
  b.shortnameList=$G;
  b.longnameList=$H;
  displaySuggestions(b,b.shortnameList,b.longnameList);
  ProcessKeys();
  if($q>0){showAC();}else{hideAC();};
};
  
function resizeHandler(){
  setCompleteDivSize();
};

function keyDownHandler(event){
  if(!event&&window.event){event=window.event;};
  if(event){$03=event.keyCode;};
};

function doHighlight($04){
  if(!$r||$q<=0){return;};
  if($04>=$q){$04=$q-1;};
  if($v!=-1&&$04!=$v){
    setStyleForElement($w,"aAutoComplete");
    $v=-1;
  };
  if($04<0){$v=-1;$b.focus();return;};
  $v=$04;
  $w=$r.item($04);
  setStyleForElement($w,"bAutoComplete");
  if($l){
    $b.value=htmldecode(getSpanByName($w,"cAutoComplete"));};
};

function SuggestedPortionLength($05){
  var $06=-1;
  if($05.createTextRange){
    var $07=document.selection.createRange().duplicate();
    $06=$07.text.length;
  } else if($05.setSelectionRange){
    $06=$05.selectionEnd-$05.selectionStart;
  };
  return $06;
};

function UserTextLength($05){
  var $06=0;
  if($05.createTextRange){
    var $07=document.selection.createRange().duplicate();
    $07.moveEnd("textedit",1);
    $06=$05.value.length-$07.text.length;
  } else if($05.setSelectionRange){
    $06=$05.selectionStart;
  } else {$06=-1;};
  return $06;
};

function getSpanByName($08,$09){
  if(!$08){return null;};
  var $0a=$08.getElementsByTagName($o);
  if($0a){
    for(var i=0;i<$0a.length;i++){
      if($0a[i].className==$09){
        return $0a[i].innerHTML;
      };
    };
  };
};

function escapeURI($0b){
  if(encodeURIComponent){return encodeURIComponent($0b);};
  if(escape){return escape($0b);};
};

function unescapeURI($0b){
  if(decodeURIComponent){
    return decodeURIComponent($0b);
  };
};

function htmlencode(t){
  return t.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
};

function htmldecode(t){
  return t.toString().replace(/&amp;/g,"&").replace(/&quot;/g,"\"").replace(/&lt;/g,"<").replace(/&gt;/g,">");
};

function setStyleForElement(c,name){
  c.className=name;
  switch(name.charAt(0)){
    case "m":c.style.fontSize="13px";
    c.style.fontFamily="arial,sans-serif";
    c.style.wordWrap="break-word";
    break;
    case "l":c.style.display="block";
    c.style.paddingLeft="3";
    c.style.paddingRight="3";
    c.style.height="16px";
    c.style.overflow="hidden";
    break;
    case "a":c.style.backgroundColor="white";
    c.style.textAlign="left";
    c.style.color="black";
    if(c.displaySpan){
      c.displaySpan.style.color="green";
    }
    break;
    case "b":c.style.backgroundColor="#3366cc";
    c.style.color="white";
    c.style.textAlign="left";
    if(c.displaySpan){
      c.displaySpan.style.color="white";
    }
    break;
    case "c":
    // c.style.width=$u+"%";
    c.style.cssFloat="left";
    c.style.textAlign="left";
    break;
    case "d":c.style.cssFloat="right";
    c.style.styleFloat="right";
    c.style.width=100-$u+"%";
    c.style.fontSize="10px";
    c.style.textAlign="right";
    c.style.color="navy";
    c.style.paddingTop="3px";
    c.style.paddingLeft="0px";
    c.style.marginLeft="0px";
    break;
  };
};

function hideAC(){
  document.getElementById("autocompleteDiv").style.visibility="hidden";
};

function showAC(){
  document.getElementById("autocompleteDiv").style.visibility="visible";
  setCompleteDivSize();
};

function isACVisible(){
  return(document.getElementById("autocompleteDiv").style.visibility=="visible");
};

function autoCache($0c,$G,$H){
  $d[$0c]=new Array($G,$H);
};

setInputFocus=function(){$b.focus();};

$0d=function(){$c.focus();};

function searchformSubmit(){
  hideAC();
  return true;
};

function setCompleteDivSize(){
  if($p){
    $p.style.left=calculateOffsetLeft($b)+"px";
    $p.style.top=calculateOffsetTop($b)+$b.offsetHeight-1+"px";
    $p.style.width=calculateWidth()+"px";
  };
};

function calculateWidth(){
  if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
    return $m+$b.offsetWidth-$s*2;
  } else {
    return $m+$b.offsetWidth;
  };
};

function calculateOffsetLeft(r){
  return GetAttr(r,"offsetLeft");
};

function calculateOffsetTop(r){return GetAttr(r,"offsetTop");};
function GetAttr(r,$0e){var kb=0;while(r){kb+=r[$0e];r=r.offsetParent;};return kb;};


