Athos
Monday, February 07, 2005
 
Google Suggest Dissected
http://www.google.com/webhp?complete=1&hl=en

<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif;}
.h{font-size: 20px;}
.q{color:#0000cc;}
//-->
</style>
<script>
<!--
function sf(){document.f.q.focus();}
function clk(el,ct,cd) {if(document.images){(new Image()).src="/url?sa=T&ct="+escape(ct)+"&cd="+escape(cd)+"&url="+escape(el.href)+"&ei=zpwFQrX7LbfAOJ2rhdEG";}return true;}
// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onLoad=sf()><center><img src="/images/logo_google_suggest.gif" width=276 height=110 alt="Google Suggest"><br><br>
<form action=/search name=f><script><!--
function qs(el) {if (window.RegExp && window.encodeURIComponent) {var qe=encodeURIComponent(document.f.q.value);if (el.href.indexOf("q=")!=-1) {el.href=el.href.replace(new RegExp("q=[^&$]*"),"q="+qe);} else {el.href+="&q="+qe;}}return 1;}
// -->
</script><table border=0 cellspacing=0 cellpadding=4><tr><td nowrap><font size=-1><b>Web</b> <a id=1a class=q href="/imghp?hl=en&tab=wi&complete=1" onClick="return qs(this);">Images</a> <a id=2a class=q href="http://groups-beta.google.com/grphp?hl=en&tab=wg&complete=1" onClick="return qs(this);">Groups</a> <a id=4a class=q href="/nwshp?hl=en&tab=wn&complete=1" onClick="return qs(this);">News</a> <a id=5a class=q href="/froogle?hl=en&tab=wf&complete=1" onClick="return qs(this);">Froogle</a> <a id=7a class=q href="/lochp?hl=en&tab=wl&complete=1" onClick="return qs(this);">Local</a><sup><a href="/lochp?hl=en&tab=wl&complete=1" style="text-decoration:none;" onclick="return qs(this);"><font color=red>New!</font></a></sup> <b><a href="/options/index.html" class=q>more ?</a></b></font></td></tr></table><table cellspacing=0 cellpadding=0><tr><td width=25%> </td><td align=center><input type=hidden name=complete value=1><input type=hidden name=hl value=en><input autocomplete="off" maxLength=256 size=55 name=q value=""><br><input type=submit value="Google Search" name=btnG><input type=submit value="I'm Feeling Lucky" name=btnI></td><td valign=top nowrap width=25%><font size=-2> <a href=/advanced_search?hl=en>Advanced Search</a><br> <a href=/preferences?hl=en>Preferences</a><br> <a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><font size=-1>As you type, Google will offer suggestions. Use the arrow keys to navigate the results. <a href=http://labs.google.com/suggest/faq.html>Learn more</a></font><br><br><br><font size=-1><a href="mailto:labs+suggest@google.com">Feedback</a> - <a href="http://groups-beta.google.com/group/google-labs-google-suggest">Discuss</a> - <a href="http://labs.google.com/labsterms.html">Terms of Use</a> - <a href="http://labs.google.com/suggest/faq.html">FAQ</a></font><p><font size=-2>?2005 Google - Searching 8,058,044,651 web pages</font></p></center></body><SCRIPT src="ac.js"></SCRIPT><SCRIPT>InstallAC(document.f,document.f.q,document.f.btnG,"search","en");</SCRIPT></html>


http://www.google.com/ac.js

// Copyright 2004 and onwards Google Inc.

var w="";var pa=false;var ta="";var da=false;var g="";var G="";var m="";var j=-1;var h=null;var Z=-1;var za=null;var Ca=5;var q="";var Lb="div";var Bb="span";var la=null;var a=null;var b=null;var Xa=null;var mb=null;var X=null;var ha=null;var ra=false;var kc=null;var hc=null;var Ua=new Object();var ca=1;var Aa=1;var Y=false;var na=-1;var Va=(new Date()).getTime();var Q=false;var k=null;var sa=null;var E=null;var B=null;var aa=null;var Ba=false;var Ka=false;var p=60;var ia=null;var ya=null;var W=0;InstallAC=function(frm,fld,sb,pn,rl,hd,sm,ufn){la=frm;a=fld;Xa=sb;if(!pn)pn="search";ia=pn;var Kb="en|";var Jb="zh-CN|zh-TW|ja|ko|vi|";if(!rl||Kb.indexOf(rl+"|")==-1)rl="en";ha=nb(rl);if(Jb.indexOf(ha+"|")==-1){X=true;Y=false;Ba=false}else{X=false;if(ha.indexOf("zh")==0)Y=false;else Y=true;Ba=true}if(!hd)hd=false;ya=hd;if(!sm)sm="query";w=sm;mb=ufn;ac()}
;function Yb(){ra=true;a.blur();setTimeout("sfi();",10);return}
function Fb(){if(document.createEventObject){var y=document.createEventObject();y.ctrlKey=true;y.keyCode=70;document.fireEvent("onkeydown",y)}}
function nc(vb){var y=document.createEventObject();y.ctrlKey=true;y.keyCode=vb;document.fireEvent("onkeydown",y)}
function gc(event){}
function ic(event){}
function Pb(event){if(!event&&window.event)event=window.event;if(event)na=event.keyCode;if(event&&event.keyCode==8){if(X&&(a.createTextRange&&(event.srcElement==a&&(bb(a)==0&&lb(a)==0)))){cc(a);event.cancelBubble=true;event.returnValue=false;return false}}}
function mc(){}
function Db(){if(w=="url"){Ha()}ba()}
function ba(){if(b){b.style.left=ob(a)+"px";b.style.top=Qb(a)+a.offsetHeight-1+"px";b.style.width=Ja()+"px"}}
function Ja(){if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){return a.offsetWidth-ca*2}else{return a.offsetWidth}}
function ac(){if(jb()){Q=true}else{Q=false}if(pa)E="complete";else E="/complete/"+ia;sa=E+"?hl="+ha;if(!Q){qa("qu","",0,E,null,null)}la.onsubmit=Fa;a.autocomplete="off";a.onblur=Ob;if(a.createTextRange)a.onkeyup=new Function("return okuh(event); ");else a.onkeyup=okuh;a.onsubmit=Fa;g=a.value;ta=g;b=document.createElement("DIV");b.id="completeDiv";ca=1;Aa=1;b.style.borderRight="black "+ca+"px solid";b.style.borderLeft="black "+ca+"px solid";b.style.borderTop="black "+Aa+"px solid";b.style.borderBottom="black "+Aa+"px solid";b.style.zIndex="1";b.style.paddingRight="0";b.style.paddingLeft="0";b.style.paddingTop="0";b.style.paddingBottom="0";ba();b.style.visibility="hidden";b.style.position="absolute";b.style.backgroundColor="white";document.body.appendChild(b);Ma("",new Array(),new Array());Gb(b);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=b;M.name="completionFrame";M.id="completionFrame";M.src=sa;s.appendChild(M);document.body.appendChild(s);if(frames&&(frames["completionFrame"]&&frames["completionFrame"].frameElement))B=frames["completionFrame"].frameElement;else B=document.getElementById("completionFrame");if(w=="url"){Ha();ba()}window.onresize=Db;document.onkeydown=Pb;Fb()}
function Ob(event){if(!event&&window.event)event=window.event;if(!ra){F();if(na==9){Xb();na=-1}}ra=false}
okuh=function(e){m=e.keyCode;aa=a.value;Oa()}
;function Xb(){Xa.focus()}
sfi=function(){a.focus()}
;function Wb(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}
function Qa(i,dc){var ga=i.getElementsByTagName(Bb);if(ga){for(var f=0;f<ga.length;++f){if(ga[f].className==dc){var value=ga[f].innerHTML;if(value==" ")return"";else{var z=Wb(value);return z}}}}else{return""}}
function U(i){if(!i)return null;return Qa(i,"cAutoComplete")}
function wa(i){if(!i)return null;return Qa(i,"dAutoComplete")}
function F(){document.getElementById("completeDiv").style.visibility="hidden"}
function cb(){document.getElementById("completeDiv").style.visibility="visible";ba()}
function Ma(is,cs,ds){Ua[is]=new Array(cs,ds)}
sendRPCDone=function(fr,is,cs,ds,pr){if(W>0)W--;var lc=(new Date()).getTime();if(!fr)fr=B;Ma(is,cs,ds);var b=fr.completeDiv;b.completeStrings=cs;b.displayStrings=ds;b.prefixStrings=pr;rb(b,b.completeStrings,b.displayStrings);Pa(b,U);if(Ca>0)b.height=16*Ca+4;else F()}
;function Oa(){if(m==40||m==38)Yb();var N=lb(a);var v=bb(a);var V=a.value;if(X&&m!=0){if(N>0&&v!=-1)V=V.substring(0,v);if(m==13||m==3){var d=a;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(a.value!=V)S(V)}}g=V;if(Eb(m)&&m!=0)Pa(b,U)}
function Fa(){return xb(w)}
function xb(eb){da=true;if(!Q){qa("qu","",0,E,null,null)}F();if(eb=="url"){var R="";if(j!=-1&&h)R=U(h);if(R=="")R=a.value;if(q=="")document.title=R;else document.title=q;var Tb="window.frames['"+mb+"'].location = \""+R+'";';setTimeout(Tb,10);return false}else if(eb=="query"){la.submit();return true}}
newwin=function(){window.open(a.value);F();return false}
;idkc=function(e){if(Ba){var Ta=a.value;if(Ta!=aa){m=0;Oa()}aa=Ta;setTimeout("idkc()",10)}}
;setTimeout("idkc()",10);function nb(La){if(encodeURIComponent)return encodeURIComponent(La);if(escape)return escape(La)}
function yb(Mb){var H=100;for(var o=1;o<=(Mb-2)/2;o++){H=H*2}H=H+50;return H}
idfn=function(){if(ta!=g){if(!da){var Za=nb(g);var ma=Ua[g];if(ma){Va=-1;sendRPCDone(B,g,ma[0],ma[1],B.completeDiv.prefixStrings)}else{W++;Va=(new Date()).getTime();if(Q){fc(Za)}else{qa("qu",Za,null,E,null,null);frames["completionFrame"].document.location.reload(true)}}a.focus()}da=false}ta=g;setTimeout("idfn()",yb(W));return true}
;setTimeout("idfn()",10);var Cb=function(){S(U(this));q=wa(this);da=true;Fa()}
;var pb=function(){if(h)l(h,"aAutoComplete");l(this,"bAutoComplete")}
;var ec=function(){l(this,"aAutoComplete")}
;function Na(C){g=G;S(G);q=G;if(!za||Z<=0)return;cb();if(C>=Z){C=Z-1}if(j!=-1&&C!=j){l(h,"aAutoComplete");j=-1}if(C<0){j=-1;a.focus();return}j=C;h=za.item(C);l(h,"bAutoComplete");g=G;q=wa(h);S(U(h))}
function Eb(ja){if(ja==40){Na(j+1);return false}else if(ja==38){Na(j-1);return false}else if(ja==13||ja==3){return false}return true}
function Pa(K,ib){var d=a;var T=false;j=-1;var J=K.getElementsByTagName(Lb);var O=J.length;Z=O;za=J;Ca=O;G=g;if(g==""||O==0){F()}else{cb()}var Ab="";if(g.length>0){var f;var o;for(var f=0;f<O;f++){for(o=0;o<K.prefixStrings.length;o++){var Ib=K.prefixStrings[o]+g;if(Y||ib(J.item(f)).toUpperCase().indexOf(Ib.toUpperCase())==0){Ab=K.prefixStrings[o];T=true;break}}if(T){break}}}if(T)j=f;for(var f=0;f<O;f++)l(J.item(f),"aAutoComplete");if(T){h=J.item(j);q=wa(h)}else{q=g;j=-1;h=null}var ab=false;switch(m){case 8:case 33:case 34:case 35:case 35:case 36:case 37:case 39:case 45:case 46:ab=true;break;default:break}if(!ab&&h){var Da=g;l(h,"bAutoComplete");var z;if(T)z=ib(h).substr(K.prefixStrings[o].length);else z=Da;if(z!=d.value){if(d.value!=g)return;if(X){if(d.createTextRange||d.setSelectionRange)S(z);if(d.createTextRange){var t=d.createTextRange();t.moveStart("character",Da.length);t.select()}else if(d.setSelectionRange){d.setSelectionRange(Da.length,d.value.length)}}}}else{j=-1;q=g}}
function ob(r){return Ya(r,"offsetLeft")}
function Qb(r){return Ya(r,"offsetTop")}
function Ya(r,ia){var kb=0;while(r){kb+=r[ia];r=r.offsetParent}return kb}
function qa(name,value,Ra,hb,fb,Sb){var Nb=name+"="+value+(Ra?"; expires="+Ra.toGMTString():"")+(hb?"; path="+hb:"")+(fb?"; domain="+fb:"")+(Sb?"; secure":"");document.cookie=Nb}
function Ha(){var xa=document.body.scrollWidth-220;xa=0.73*xa;a.size=Math.floor(xa/6.18)}
function 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 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 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)}}
function jc(Zb,Ea){if(!Ea)Ea=1;if(pa&&pa<=Ea){var Ia=document.createElement("DIV");Ia.innerHTML=Zb;document.getElementById("console").appendChild(Ia)}}
function l(c,name){db();c.className=name;if(Ka){return}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.color="black";if(c.displaySpan){c.displaySpan.style.color="green"}break;case "b":c.style.backgroundColor="#3366cc";c.style.color="white";if(c.displaySpan){c.displaySpan.style.color="white"}break;case "c":c.style.width=p+"%";c.style.cssFloat="left";break;case "d":c.style.cssFloat="right";c.style.width=100-p+"%";if(w=="query"){c.style.fontSize="10px";c.style.textAlign="right";c.style.color="green";c.style.paddingTop="3px"}else{c.style.color="#696969"}break}}
function db(){p=65;if(w=="query"){var wb=110;var Sa=Ja();var tb=(Sa-wb)/Sa*100;p=tb}else{p=65}if(ya){p=99.99}}
function Gb(i){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: "+p+"%; float: left;";var Ga="display: block; margin-left: "+p+"%;";if(w=="query"){Ga+="font-size: 10px; text-align: right; color: green; padding-top: 3px;"}else{Ga+="color: #696969;"}D(".mAutoComplete",Ub);D(".lAutoComplete",Vb);D(".aAutoComplete *",bc);D(".bAutoComplete *",qb);D(".cAutoComplete",ub);D(".dAutoComplete",Ga);l(i,"mAutoComplete")}
function rb(i,cs,Hb){while(i.childNodes.length>0)i.removeChild(i.childNodes[0]);for(var f=0;f<cs.length;++f){var u=document.createElement("DIV");l(u,"aAutoComplete");u.onmousedown=Cb;u.onmouseover=pb;u.onmouseout=ec;var ka=document.createElement("SPAN");l(ka,"lAutoComplete");var ua=document.createElement("SPAN");ua.innerHTML=cs[f];var ea=document.createElement("SPAN");l(ea,"dAutoComplete");l(ua,"cAutoComplete");u.displaySpan=ea;if(!ya)ea.innerHTML=Hb[f];ka.appendChild(ua);ka.appendChild(ea);u.appendChild(ka);i.appendChild(u)}}
function D(name,gb){if(Ka){var I=document.styleSheets[0];if(I.addRule){I.addRule(name,gb)}else if(I.insertRule){I.insertRule(name+" { "+gb+" }",I.cssRules.length)}}}
function jb(){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 fc(Rb){if(k&&k.readyState!=0){k.abort()}k=jb();if(k){k.open("GET",sa+"&js=true&qu="+Rb,true);k.onreadystatechange=function(){if(k.readyState==4&&k.responseText){var frameElement=B;if(k.responseText.charAt(0)=="<"){W--}else{eval(k.responseText)}}}
;k.send(null)}}
function S(Wa){a.value=Wa;aa=Wa}



http://www.google.com/complete/search?hl=en&js=true&qu=abs

sendRPCDone(frameElement, "abs", new Array("absinthe", "abs", "abstract art", "absinth", "abstract", "abs cbn", "absa", "abstinence", "absentee ballot", "absynth"), new Array("749,000 results", "15,000,000 results", "5,810,000 results", "827,000 results", "147,000,000 results", "205,000 results", "194,000 results", "1,820,000 results", "296,000 results", "109,000 results"), new Array(""));



http://www.google.com/complete/search?hl=en

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script>
function bodyLoad() {
if (parent == window) return;
var frameElement = this.frameElement;
parent.sendRPCDone(frameElement, "", new Array(), new Array(), new Array(""));
}
</script></head><body onload='bodyLoad();'></body></html>



ac.chris.js

// Copyright 2004 and onwards Google Inc.
//
// uncompressed / commented / renamed by Chris...
//

var w="";
var pa=false;
var _oldInputFieldValue=""; // inputField value (set during call to google...)...(was ta)
var da=false;
var _currentInputFieldValue=""; // also inputField value (was g)
var G="";
var _eventKeycode=""; // event keycode... (was m)
var _highlightedSuggestionIndex=-1; // currently hightlighted suggestion index (was j)
var _highlightedSuggestionDiv=null; // currently highlisted suggestion div... (was h)
var _completeDivRows=-1; // completeDiv rows at time of keypress... (was Z)
var _completeDivDivList=null; // completeDiv div list at time of keypress (was za)
var _completeDivRows2=5; // was Ca... initially 5? not sure difference between this and _completeDivRows...
var q="";
var _divTag="div"; // Was Lb
var _spanTag="span"; // Was Bb
var _documentForm=null; // Form on html page... (was la...)
var _inputField=null; // Input field on form... (was a)
var _completeDiv=null; // document.completeDiv (was b)
var _submitButton=null; // submit button (was Xa)
var mb=null;
var X=null;
var _enString=null; // This becomes the string "en" (was ha)
var _cursorUpDownPressed=false; // Was ra...
var kc=null;
var hc=null;
var _resultCache=new Object(); // This is a cache of results from google... (was Ua)
var ca=1;
var Aa=1;
var Y=false;
var _lastKeyCode=-1; // Gets set on keyDown... Was na...
var Va=(new Date()).getTime();
var _hasXMLHTTP=false; // Gets set to true if XMLHTTP Supported (was Q)
var _xmlHttp=null; // This is the XMLHttp Object... (was k)
var _completeSearchEnString=null; // Gets set to "/complete/search/?hl=en" (was sa)
var _completeSearchString=null; // Gets set to "/complete/search" ... (was E)
var B=null;
var aa=null;
var Ba=false;
var Ka=false;
var p=60;
var _searchString=null; // Gets set to "search" in installAC (was ia)
var ya=null;
var _timeoutAdjustment=0; // timeout adjustment... (was W)... gets adjusted over time...

// 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
InstallAC=function(frm,fld,sb,pn,rl,hd,sm,ufn){
_documentForm=frm;
_inputField=fld;
_submitButton=sb;
if(!pn) {
pn="search";
}
_searchString=pn;
var Kb="en|";
var Jb="zh-CN|zh-TW|ja|ko|vi|";
if(!rl||Kb.indexOf(rl+"|")==-1) {
rl="en";
}
_enString=escapeURI(rl);
if(Jb.indexOf(_enString+"|")==-1){
// We won't pass through here...
X=true;
Y=false;
Ba=false
}else{
// but will come through here...
X=false;
if(_enString.indexOf("zh")==0) {
// not here...
Y=false;
} else {
// but here...
Y=true;
}
Ba=true
}
// hd is not defined, so becomes false...
if(!hd) {
hd=false;
}
ya=hd;

// sm not defined, so becomes the string "query"
if(!sm) {
sm="query";
}
w=sm;

// ufn is not defined...
mb=ufn;

installACPartTwo()
}
;

// blurs focus, then sets focus again...
// This is getting aclled when we press cursor up / cursor down...
// Was Yb...
function blurThenGetFocus(){
_cursorUpDownPressed=true;
_inputField.blur();
setTimeout("setInputFieldFocus();",10);
return
}

// setup a keydown event...
// Was Fb...
function setupKeydown1(){
if(document.createEventObject) {
var y=document.createEventObject();
y.ctrlKey=true;
y.keyCode=70;
document.fireEvent("onkeydown",y)
}
}

// setup a keydown event...
// I can't figure out what calls this...
// was nc...
function setupKeydown2(vb){
var y=document.createEventObject();
y.ctrlKey=true;
y.keyCode=vb;
document.fireEvent("onkeydown",y)
}

function gc(event){}
function ic(event){}

// Was Pb
function keyDownHandler(event){
if(!event&&window.event) {
event=window.event;
}
if(event) {
_lastKeyCode=event.keyCode;
}

// We are backspacing here...
if(event&&event.keyCode==8){
if(X&&(_inputField.createTextRange&&(event.srcElement==a&&(bb(_inputField)==0&&lb(_inputField)==0)))){
cc(_inputField);
event.cancelBubble=true;
event.returnValue=false;
return false
}
}
}

function mc(){}

// Was Db..
function resizeHandler(){
if(w=="url"){
setInputFieldSize()
}
setCompleteDivSize()
}

// was ba...
function setCompleteDivSize(){
if(_completeDiv){
_completeDiv.style.left=calculateOffsetLeft(_inputField)+"px";
_completeDiv.style.top=calculateOffsetTop(_inputField)+_inputField.offsetHeight-1+"px";
_completeDiv.style.width=calculateWidth()+"px"
}
}

// calculate width of inputField... Note browser specific adjustments...
// Was Ja()
function calculateWidth(){
if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
return _inputField.offsetWidth-ca*2
}else{
return _inputField.offsetWidth
}
}


// Called from InstallAC...
// was ac()
function installACPartTwo(){
if(getXMLHTTP()){
_hasXMLHTTP=true
}else{
_hasXMLHTTP=false
}

// pa init'd to false at the top of this file...
if(pa) {
_completeSearchString="complete";
} else {
_completeSearchString="/complete/"+_searchString;
}

_completeSearchEnString=_completeSearchString+"?hl="+_enString;

if(!_hasXMLHTTP){
setCookie("qu","",0,_completeSearchString,null,null)
}

_documentForm.onsubmit=Fa;
_inputField.autocomplete="off";
_inputField.onblur=onBlurHandler;
if(_inputField.createTextRange) {
_inputField.onkeyup=new Function("return okuh(event);");
} else {
_inputField.onkeyup=okuh;
}
_inputField.onsubmit=Fa;
_currentInputFieldValue=_inputField.value;
_oldInputFieldValue=_currentInputFieldValue;
_completeDiv=document.createElement("DIV");
_completeDiv.id="completeDiv";
ca=1;
Aa=1;
_completeDiv.style.borderRight="black "+ca+"px solid";
_completeDiv.style.borderLeft="black "+ca+"px solid";
_completeDiv.style.borderTop="black "+Aa+"px solid";
_completeDiv.style.borderBottom="black "+Aa+"px solid";
_completeDiv.style.zIndex="1";
_completeDiv.style.paddingRight="0";
_completeDiv.style.paddingLeft="0";
_completeDiv.style.paddingTop="0";
_completeDiv.style.paddingBottom="0";
setCompleteDivSize();
_completeDiv.style.visibility="hidden";
_completeDiv.style.position="absolute";
_completeDiv.style.backgroundColor="white";
document.body.appendChild(_completeDiv);
cacheResults("",new Array(),new Array());
Gb(_completeDiv);
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=_completeDiv;
M.name="completionFrame";
M.id="completionFrame";
M.src=_completeSearchEnString;
s.appendChild(M);
document.body.appendChild(s);
if(frames&&(frames["completionFrame"]&&frames["completionFrame"].frameElement)) {
B=frames["completionFrame"].frameElement;
} else {
B=document.getElementById("completionFrame");
}
if(w=="url"){
setInputFieldSize();
setCompleteDivSize()
}
window.onresize=resizeHandler;
document.onkeydown=keyDownHandler;
setupKeydown1()
}

// Was Ob
function onBlurHandler(event){
if(!event&&window.event) {
event=window.event;
}
if(!_cursorUpDownPressed){
hideCompleteDiv();
// check if tab pressed...
if(_lastKeyCode==9){
setSubmitButtonFocus();
_lastKeyCode=-1
}
}
_cursorUpDownPressed=false
}

okuh=function(e){
_eventKeycode=e.keyCode;
aa=_inputField.value;
Oa()
}
;
// Was Xb...
function setSubmitButtonFocus(){
_submitButton.focus()
}

// Was sfi..
setInputFieldFocus=function(){
_inputField.focus()
}
;

// strip CR from string...
// was Wb
function 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 findSpanValueForClass(i,dc){
var ga=i.getElementsByTagName(_spanTag);
if(ga){
for(var f=0; f<ga.length; ++f){
if(ga[f].className==dc){
var value=ga[f].innerHTML;
if(value==" ") {
return"";
} else{
var z=stripCRFromString(value);
return z
}
}
}
}else{
return""
}
}

// Return null if i undefined...
// otherwise return value of span cAutoComplete...
// was U
function valueOfCAutoComplete(i){
if(!i) {
return null;
}
return findSpanValueForClass(i,"cAutoComplete")
}

// Return null if i undefined...
// otherwise return value of span dAutoComplete...
// was wa
function valueOfDAutoComplete(i){
if(!i) {
return null;
}
return findSpanValueForClass(i,"dAutoComplete")
}

// Was F
function hideCompleteDiv(){
document.getElementById("completeDiv").style.visibility="hidden"
}
// Was cb
function showCompleteDiv(){
document.getElementById("completeDiv").style.visibility="visible";
setCompleteDivSize()
}

// This is a result caching mechanism...
// was Ma
function cacheResults(is,cs,ds){
_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(""));
sendRPCDone=function(fr,is,cs,ds,pr){
if(_timeoutAdjustment>0) {
_timeoutAdjustment--;
}
var lc=(new Date()).getTime();
if(!fr) {
fr=B;
}
cacheResults(is,cs,ds);
var b=fr.completeDiv;
b.completeStrings=cs;
b.displayStrings=ds;
b.prefixStrings=pr;
displaySuggestedList(b,b.completeStrings,b.displayStrings);
Pa(b,valueOfCAutoComplete);
if(_completeDivRows2>0) {
b.height=16*_completeDivRows2+4;
} else {
hideCompleteDiv();
}
}

function Oa(){
// 38 is up cursor key, 40 is down cursor key...
if(_eventKeycode==40||_eventKeycode==38) {
blurThenGetFocus();
}
var N=lb(_inputField);
var v=bb(_inputField);
var V=_inputField.value;
if(X&&_eventKeycode!=0){
if(N>0&&v!=-1) {
V=V.substring(0,v);
}
if(_eventKeycode==13||_eventKeycode==3){
var d=_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(_inputField.value!=V) {
selectEntry(V)
}
}
}
_currentInputFieldValue=V;
if(handleCursorUpDownEnter(_eventKeycode)&&_eventKeycode!=0) {
Pa(_completeDiv,valueOfCAutoComplete)
}
}

function Fa(){
return xb(w)
}

function xb(eb) {
da=true;
if(!_hasXMLHTTP){
setCookie("qu","",0,_completeSearchString,null,null)
}
hideCompleteDiv();
if(eb=="url"){
var R="";
if(_highlightedSuggestionIndex!=-1&&h) {
R=valueOfCAutoComplete(_highlightedSuggestionDiv);
}
if(R=="") {
R=_inputField.value;
}
if(q=="") {
document.title=R;
} else {
document.title=q;
}
var Tb="window.frames['"+mb+"'].location = \""+R+'";';
setTimeout(Tb,10);
return false
} else if(eb=="query"){
_documentForm.submit();
return true
}
}

newwin=function(){
window.open(_inputField.value);
hideCompleteDiv();
return false
}
;

idkc=function(e){
if(Ba){
var Ta=_inputField.value;
if(Ta!=aa){
_eventKeycode=0;
Oa()
}
aa=Ta;
setTimeout("idkc()",10)
}
}
;
setTimeout("idkc()",10);

// 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 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 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...
mainLoop=function(){
if(_oldInputFieldValue!=_currentInputFieldValue){
if(!da){
var Za=escapeURI(_currentInputFieldValue);
var ma=_resultCache[_currentInputFieldValue];
if(ma){
// Found in our cache...
Va=-1;
sendRPCDone(B,_currentInputFieldValue,ma[0],ma[1],B.completeDiv.prefixStrings)
}else{
_timeoutAdjustment++;
Va=(new Date()).getTime();
if(_hasXMLHTTP){
callGoogle(Za)
}else{
setCookie("qu",Za,null,_completeSearchString,null,null);
frames["completionFrame"].document.location.reload(true)
}
}
_inputField.focus()
}
da=false
}
_oldInputFieldValue=_currentInputFieldValue;
setTimeout("mainLoop()",recalculateTimeout(_timeoutAdjustment));
return true
}
;
// Call mainLoop() after 10 milliseconds...
setTimeout("mainLoop()",10);

// This is onMouseDown function...
var Cb=function(){
selectEntry(valueOfCAutoComplete(this));
q=valueOfDAutoComplete(this);
da=true;
Fa()
}
;

// on mouseover...
var pb=function(){
if(_highlightedSuggestionDiv) {
setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete");
}
setStyleForElement(this,"bAutoComplete")
}
;

// On Mouse out...
var ec=function(){
setStyleForElement(this,"aAutoComplete")
}
;

// Called when cursor up/down pressed... selects new entry in completeDiv...
// was Na
function highlightNewValue(C){
_currentInputFieldValue=G;
selectEntry(G);
q=G;
if(!_completeDivDivList||_completeDivRows<=0) {
return;
}
showCompleteDiv();
if(C>=_completeDivRows){
C=_completeDivRows-1
}
if(_highlightedSuggestionIndex!=-1&&C!=_highlightedSuggestionIndex){
setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete");
_highlightedSuggestionIndex=-1
}
if(C<0){
_highlightedSuggestionIndex=-1;
_inputField.focus();
return
}
_highlightedSuggestionIndex=C;
_highlightedSuggestionDiv=_completeDivDivList.item(C);
setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
_currentInputFieldValue=G;
q=valueOfDAutoComplete(_highlightedSuggestionDiv);
selectEntry(valueOfCAutoComplete(_highlightedSuggestionDiv))
}

// Was Eb
// returns false if cursor up / cursor down or enter pressed...
function handleCursorUpDownEnter(eventCode){
if(eventCode==40){
highlightNewValue(_highlightedSuggestionIndex+1);
return false
}else if(eventCode==38){
highlightNewValue(_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...
function Pa(localCompleteDiv,ib){
var localInputField=_inputField;
var T=false;
_highlightedSuggestionIndex=-1;
// This becomes the rows in our suggestion list...
var J=localCompleteDiv.getElementsByTagName(_divTag);
// # of rows in list...
var O=J.length;
_completeDivRows=O;
_completeDivDivList=J;
_completeDivRows2=O;
G=_currentInputFieldValue;
if(_currentInputFieldValue==""||O==0){
hideCompleteDiv()
}else{
showCompleteDiv()
}
var Ab="";
if(_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]+_currentInputFieldValue;
if(Y||ib(J.item(f)).toUpperCase().indexOf(Ib.toUpperCase())==0) {
Ab=localCompleteDiv.prefixStrings[o];
T=true;
break
}
}
if(T){
break
}
}
}
if(T) {
_highlightedSuggestionIndex=f;
}
for(var f=0; f<O; f++) {
setStyleForElement(J.item(f),"aAutoComplete");
}
if(T){
_highlightedSuggestionDiv=J.item(_highlightedSuggestionIndex);
q=valueOfDAutoComplete(_highlightedSuggestionDiv)
}else{
q=_currentInputFieldValue;
_highlightedSuggestionIndex=-1;
_highlightedSuggestionDiv=null
}
var ab=false;
switch(_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:
ab=true;
break;
default:
// regular keypress ...
break
}
if(!ab&&_highlightedSuggestionDiv){
var Da=_currentInputFieldValue;
setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
var z;
if(T) {
z=ib(_highlightedSuggestionDiv).substr(localCompleteDiv.prefixStrings[o].length);
} else {
z=Da;
}
if(z!=localInputField.value){
if(localInputField.value!=_currentInputFieldValue) {
return;
}
if(X){
if(localInputField.createTextRange||localInputField.setSelectionRange) {
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{
_highlightedSuggestionIndex=-1;
q=_currentInputFieldValue
}
}

// Called as:
// calculateOffsetLeft(_inputField)
// was ob
function calculateOffsetLeft(r){
return Ya(r,"offsetLeft")
}

// Called as:
// calculateOffsetTop(_inputField)
// Was Qb...
function calculateOffsetTop(r){
return Ya(r,"offsetTop")
}

function Ya(r,attr){
var kb=0;
while(r){
kb+=r[attr];
r=r.offsetParent
}
return kb
}

// Sets cookie...
// (was called qa...)
function setCookie(name,value,Ra,hb,fb,Sb){
var Nb=name+"="+value+(Ra?";expires="+Ra.toGMTString():"")+(hb?";path="+hb:"")+(fb?";domain="+fb:"")+(Sb?";secure":"");
document.cookie=Nb
}

// Was Ha
function setInputFieldSize(){
var xa=document.body.scrollWidth-220;
xa=0.73*xa;
_inputField.size=Math.floor(xa/6.18)
}
function 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 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 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)
}
}

function jc(Zb,Ea){
if(!Ea)Ea=1;
if(pa&&pa<=Ea){
var Ia=document.createElement("DIV");
Ia.innerHTML=Zb;
document.getElementById("console").appendChild(Ia)
}
}

// Ex: setStyleForElement(document.createElement("DIV"), "aAutoComplete");
// was l
function setStyleForElement(c,name){
db();
c.className=name;
if(Ka){
return
}
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.color="black";
if(c.displaySpan){
c.displaySpan.style.color="green"
}
break;
case "b":
c.style.backgroundColor="#3366cc";
c.style.color="white";
if(c.displaySpan){
c.displaySpan.style.color="white"
}
break;
case "c":
c.style.width=p+"%";
c.style.cssFloat="left";
break;
case "d":
c.style.cssFloat="right";
c.style.width=100-p+"%";
if(w=="query"){
c.style.fontSize="10px";
c.style.textAlign="right";
c.style.color="green";
c.style.paddingTop="3px"
}else{
c.style.color="#696969"
}
break
}
}

function db(){
p=65;
if(w=="query"){
var wb=110;
var Sa=calculateWidth();
var tb=(Sa-wb)/Sa*100;
p=tb
}else{
p=65
}
if(ya){
p=99.99
}
}
function Gb(i){
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: "+p+"%; float: left; ";
var Ga="display: block; margin-left: "+p+"%; ";
if(w=="query"){
Ga+="font-size: 10px; text-align: right; color: green; padding-top: 3px; "
}else{
Ga+="color: #696969; "
}
D(".mAutoComplete",Ub);
D(".lAutoComplete",Vb);
D(".aAutoComplete *",bc);
D(".bAutoComplete *",qb);
D(".cAutoComplete",ub);
D(".dAutoComplete",Ga);
setStyleForElement(i,"mAutoComplete")
}

// Called from sendRPCResponse...
// i = fr.completeDiv
// cs = list of comlete strings...
// Hb = list of results...
// was rb
function 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");
setStyleForElement(u,"aAutoComplete");
u.onmousedown=Cb;
u.onmouseover=pb;
u.onmouseout=ec;
var ka=document.createElement("SPAN");
setStyleForElement(ka,"lAutoComplete");
var ua=document.createElement("SPAN");
ua.innerHTML=cs[f]; // the text for the suggested result...
var ea=document.createElement("SPAN");
setStyleForElement(ea,"dAutoComplete");
setStyleForElement(ua,"cAutoComplete");
u.displaySpan=ea;
if(!ya) {
ea.innerHTML=Hb[f]; // the text for # results for suggested result...
}
ka.appendChild(ua);
ka.appendChild(ea);
u.appendChild(ka);
i.appendChild(u)
}
}

function D(name,gb){
if(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 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
}

// 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 callGoogle(Rb){
if(_xmlHttp&&_xmlHttp.readyState!=0){
_xmlHttp.abort()
}
_xmlHttp=getXMLHTTP();
if(_xmlHttp){
// We end up calling:
// /complete/search?hl=en&js=true&qu=<my query string...> ...
_xmlHttp.open("GET",_completeSearchEnString+"&js=true&qu="+Rb,true);
// Note that this function will ONLY be called when we get a complete
// response back from google!!
_xmlHttp.onreadystatechange=function() {
if(_xmlHttp.readyState==4&&_xmlHttp.responseText) {
var frameElement=B;
if(_xmlHttp.responseText.charAt(0)=="<"){
_timeoutAdjustment--
}else{
// The response text gets executed as javascript...
eval(_xmlHttp.responseText)
}
}
}
;
// DON'T TRY TO TALK WHEN WE'RE LOCAL...
// Comment out when running from a local file...
_xmlHttp.send(null)
}
}

// Select suggested entry...
// wa is the value to set the inputfield to...
// was S
function selectEntry(Wa){
_inputField.value=Wa;
aa=Wa
}




Comments: Post a Comment

<< Home

Powered by Blogger