//
//	Fichier initial ac.js
//	Tarduit à partir de http://www.p2pnet.net/stuff/justusearch.txt
//
// Input 0
var y="";
var Pb=false;
var _oldInputFieldValue=""; // inputField value (set during call to data...)...
var fa=false;
var _currentInputFieldValue=""; // also inputField value
var H="";
var _eventKeycode=""; // event keycode...
var _highlightedSuggestionIndex=-1; // currently hightlighted suggestion index
var _highlightedSuggestionDiv=null; // currently highlisted suggestion div...
var _completeDivRows=-1; // completeDiv rows at time of keypress...
var _completeDivDivList=null; // completeDiv div list at time of keypress
var Na=5;
var r="";
var _divTag="div";
var _spanTag="span";
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 xb=null;
var W=null;
var la=null;
var _cursorUpDownPressed=false;
var _resultCache=new Object();	// This is a cache of results from data... (was Ua)
var ea=1;
var Ma=1;
var va=false;
var aa=false;
var _lastKeyCode=-1; // Gets set on keyDown...
var gb=(new Date()).getTime();
var _hasXMLHTTP=false; // Gets set to true if XMLHTTP Supported
var _xmlHttp=null; // This is the XMLHttp Object...
var _completeSearchEnString=null;
var _completeSearchString=null;
var N=null;
var ca=null;
var ka=false;
var Ua=false;
var q=60;
var na=null;
var Ha=null;
var _timeoutAdjustment=0;
var hb=null;
var ma=null;
var oa=null;
var Ea=false;
var X=false;

var nbMax=7;

// 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... 
//  -&gt; &lt;input autocomplete="off" maxLength=256 size=55 name=q value=""&gt;
// document.f.btnG Google Search button
InstallAC=function(frm,fld,sb,pn,rl,hd,sm,ufn)
{
	// alert("InstallAC");

	_documentForm=frm;
	_inputField=fld;
	_submitButton=sb;
	if(!pn) pn="search";
	na=pn;
	var Sb="zh|zh-CN|zh-TW|ja|ko|";
	if(!rl||rl.length<1) rl="en";
	la=escapeURI(rl);
	if(Sb.indexOf(la+"|")==-1)
	{W=true;aa=false;va=false;ka=false}
	else
	{W=false;aa=true;
	 if(la.indexOf("zh")==0)va=false;ka=true}
	if(!hd)hd=false;
	Ha=hd;
	
	// sm not defined, so becomes the string "query"
	if(!sm)sm="query";
	y=sm;
	
	// ufn is not defined...
	xb=ufn;
	installACPartTwo()
};

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

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

// Was Xb
function keyDownHandler(event){
  if(!event&&window.event) event=window.event;
  if(event)_lastKeyCode=event.keyCode;
  if(event&&event.keyCode==8){
    if(W&&(_inputField.createTextRange&&(event.srcElement==_inputField&&(ja(_inputField)==0&&qa(_inputField)==0)))){
      nc(_inputField);
      event.cancelBubble=true;
      event.returnValue=false;
      return false
    }
  }
}

function resizeHandler()
{
  if(y=="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"
  }
}

function calculateWidth(){
  if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
    return _inputField.offsetWidth-ea*2
  }else{
    return _inputField.offsetWidth
  }
}

// Called from InstallAC...
// was kc()
function installACPartTwo()
{
  if(getXMLHTTP()){
    _hasXMLHTTP=true
  }else{
    _hasXMLHTTP=false
  }
	
  // 
  /*
    if(Pb) _completeSearchString="complete";
    else _completeSearchString="/complete/"+na;
    _completeSearchEnString=_completeSearchString+"?hl="+la;
  */
	
  // page intiale de l'Iframe "completionFrame"
  _completeSearchEnString="complete.html"
	
	
  if(!_hasXMLHTTP){
    setCookie("qu","",0,_completeSearchString,null,null)}

  _documentForm.onsubmit=Qa;
  _inputField.autocomplete="off";
  _inputField.onblur=onBlurHandler;
  _inputField.onfocus=lc;
  if(_inputField.createTextRange)_inputField.onkeyup=new Function("return okuh(event); ");
  else _inputField.onkeyup=okuh;

  _inputField.onsubmit=Qa;
  _currentInputFieldValue=_inputField.value;
  _oldInputFieldValue=_currentInputFieldValue;
  _completeDiv=document.createElement("DIV");
  _completeDiv.id="completeDiv";
  ea=1;
  Ma=1;
  _completeDiv.style.borderRight="black "+ea+"px solid";
  _completeDiv.style.borderLeft="black "+ea+"px solid";
  _completeDiv.style.borderTop="black "+Ma+"px solid";
  _completeDiv.style.borderBottom="black "+Ma+"px solid";
  _completeDiv.style.zIndex="10";
  _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());
  Qb(_completeDiv);
  var t=document.createElement("DIV");
  t.style.visibility="hidden";
  t.style.position="absolute";
  t.style.left="-10000";
  t.style.top="-10000";
  t.style.width="0";
  t.style.height="0";
  var L=document.createElement("IFRAME");
  L.completeDiv=_completeDiv;
  L.name="completionFrame";
  L.id="completionFrame";
  L.src=_completeSearchEnString;t.appendChild(L);
  document.body.appendChild(t);
  if(frames&&(frames["completionFrame"]&&frames["completionFrame"].frameElement))N=frames["completionFrame"].frameElement;
  else N=document.getElementById("completionFrame");

  if(y=="url"){
    setInputFieldSize();
    setCompleteDivSize()
  }
  window.onresize=resizeHandler;
  document.onkeydown=keyDownHandler;
  setupKeydown1();
  
  if(ka){
    setTimeout("idkc()",10);
    if(_inputField.attachEvent){
    	_inputField.attachEvent("onpropertychange",Zb)}
  }
}
function lc(h){X=true}

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

okuh=function(e)
{
	if(!Ea)
	{Ea=true}
	_eventKeycode=e.keyCode;
	ca=_inputField.value;
	Xa()
};
function setSubmitButtonFocus(){_submitButton.focus()}
setInputFieldFocus=function(){_inputField.focus()};

// strip CR from string...
// was hc
function stripCRFromString(Da){
  for(var c=0,wa="",Ib="\n\r";c<Da.length;c++) 
  	if(Ib.indexOf(Da.charAt(c))==-1)wa+=Da.charAt(c);
  	else wa+=" ";
  	return wa
 }
 
// Find span value with className = dc...
// Was Za
function findSpanValueForClass(j,oc){
  var ia=j.getElementsByTagName(_spanTag);
  if(ia)
  {
  	for(var c=0;c<ia.length;++c){
  		if(ia[c].className==oc){
  			var Y=ia[c].innerHTML;
  			if(Y=="&nbsp;")return"";
  			else
  			{var A=stripCRFromString(Y);return A}
  		}
  	}
  }
  else{return""}
}

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

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

// Was G
function hideCompleteDiv(){
  document.getElementById("completeDiv").style.visibility="hidden"
}

// Was nb
function showCompleteDiv(){
  document.getElementById("completeDiv").style.visibility="visible";
  setCompleteDivSize()
}

// This is a result caching mechanism...
// was Wa
function cacheResults(is,cs,ds){
  _resultCache[is]=new Array(cs,ds)
}

DLAsendRPCDone=function(fr,is,cs,ds,pr)
{
	// alert("DLAsendRPCDone");
	var str='<html><head><META http-equiv=content-type content="text/html; charset=ISO-8859-1"></head><body>';
	for(var c=0;c<cs.length;++c)
	{
		str+="<p>" + cs[c] + "<br>";
	}
	str+="</body></html>";
	document.write(str);
}	

sendRPCDone=function(fr,is,cs,ds,pr)
{
	// alert("sendRPCDone");
	
	if(_timeoutAdjustment>0)_timeoutAdjustment--;
	var rc=(new Date()).getTime();
	if(!fr)fr=N;
	cacheResults(is,cs,ds);
	//var _completeDiv=fr.completeDiv;
	
	var _completeDiv=document.getElementById("completeDiv");
	
	_completeDiv.completeStrings=cs;
	_completeDiv.displayStrings=ds;
	_completeDiv.prefixStrings=pr;
	
	displaySuggestedList(_completeDiv,_completeDiv.completeStrings,_completeDiv.displayStrings);
	
	// alert(_completeDiv.innerHTML);
	Ya(_completeDiv,valueOfCAutoComplete);
	
	//alert(Na)
	if(Na>0)
	{
		_completeDiv.height=16*Na+4;
	}
	else hideCompleteDiv()
};

function Xa()
{
  if(_eventKeycode==40||_eventKeycode==38)blurThenGetFocus();
  
  var M=qa(_inputField);
  var w=ja(_inputField);
  var U=_inputField.value;
  if(W&&_eventKeycode!=0){
    if(M>0&&w!=-1) U=U.substring(0,w);
    if(_eventKeycode==13||_eventKeycode==3){
      var f=_inputField;
      if(f.createTextRange){
        var u=f.createTextRange();
	u.moveStart("character",f.value.length);
	u.select()
      }else if(f.setSelectionRange){
	f.setSelectionRange(f.value.length,f.value.length)}
   }else{
     if(_inputField.value!=U)
       selectEntry(U)
     }
   }
   _currentInputFieldValue=U;
   
   if(handleCursorUpDownEnter(_eventKeycode)&&_eventKeycode!=0)
   	Ya(_completeDiv,valueOfCAutoComplete)
   	
}

function Qa()
{
	// alert("Qa");
	MM_AllerA_Lexique();
	return false;
	// return Gb(y)
}

function Gb(pb)
{
	fa=true;
	if(!_hasXMLHTTP)
	{setCookie("qu","",0,_completeSearchString,null,null)}
	hideCompleteDiv();
	if(pb=="url")
	{	var Q="";
		if(_highlightedSuggestionIndex!=-1&&_highlightedSuggestionDiv)Q=valueOfCAutoComplete(_highlightedSuggestionDiv);
		if(Q=="")Q=_inputField.value;
		if(r=="")document.title=Q;
		else document.title=r;
		var dc="window.frames['"+xb+"'].location = \""+Q+'";';
		setTimeout(dc,10);
		return false
	}
	else if(pb=="query")
	{_documentForm.submit();return true}
}
newwin=function(){window.open(_inputField.value);hideCompleteDiv();return false};
idkc=function(e){if(ka){if(X){eb()}var db=_inputField.value;if(db!=ca){_eventKeycode=0;Xa()}ca=db;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 yb...
function escapeURI(Va){
  // non utilisé parce que la méthode encodeURIComponent convertie en UTF8
  //if(encodeURIComponent)return encodeURIComponent(Va); 
  if(escape)return escape(Va)
}

// Was Hb
// 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(Ub){
  var I=100;
  for(var p=1;p<=(Ub-2)/2;p++){
    I=I*2
  }
  I=I+50;
  return I
}

idfn=function()
{
	if(_oldInputFieldValue!=_currentInputFieldValue)
	{
		if(!fa)
		{
			var lb=escapeURI(_currentInputFieldValue);
			var ta=_resultCache[_currentInputFieldValue];
			if(ta)
			{
				gb=-1;
				sendRPCDone(N,_currentInputFieldValue,ta[0],ta[1],N.completeDiv.prefixStrings)
			}
			else
			{
				_timeoutAdjustment++;
				gb=(new Date()).getTime();
				if(_hasXMLHTTP){callDataXml(lb)}
				else
				{
					setCookie("qu",lb,null,_completeSearchString,null,null);
					frames["completionFrame"].document.location.reload(true)
				}
			}
			_inputField.focus()
		}
		fa=false
	}
	
	_oldInputFieldValue=_currentInputFieldValue;setTimeout("idfn()",recalculateTimeout(_timeoutAdjustment));return true
};
setTimeout("idfn()",10);

// This is onMouseDown function...
var Lb=function(){
  selectEntry(valueOfCAutoComplete(this));
  r=valueOfDAutoComplete(this);
  fa=true;Qa()
};

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

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

function highlightNewValue(D){
  _currentInputFieldValue=H;
  selectEntry(H);
  r=H;
  if(!_completeDivDivList||_completeDivRows<=0)return;
  showCompleteDiv();
  if(D>=_completeDivRows){
   D=_completeDivRows-1
  }
  
  if(_highlightedSuggestionIndex!=-1&&D!=_highlightedSuggestionIndex){
   setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete");
   _highlightedSuggestionIndex=-1
  }
  
  if(D<0){
   _highlightedSuggestionIndex=-1;
   _inputField.focus();
   return
  }
 
  _highlightedSuggestionIndex=D;
  _highlightedSuggestionDiv=_completeDivDivList.item(D);
  setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
  _currentInputFieldValue=H;
  r=valueOfDAutoComplete(_highlightedSuggestionDiv);
  selectEntry(valueOfCAutoComplete(_highlightedSuggestionDiv))
}
	
// Was Nb
// 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
}

// This function gets called for every keypress I make...
function Ya(K,Pa){
  var f=_inputField;
  var S=false;
  _highlightedSuggestionIndex=-1;
  var B=K.getElementsByTagName(_divTag);
  var O=B.length;
  _completeDivRows=O;
  _completeDivDivList=B;
  Na=O;
  H=_currentInputFieldValue;
  if(_currentInputFieldValue==""||O==0){
   hideCompleteDiv()
  }else{
    showCompleteDiv()
  }
  var Jb="";
  if(_currentInputFieldValue.length>0){
    var c;
    var p;
    for(var c=0;c<O;c++){
      for(p=0;p<K.prefixStrings.length;p++){
        var cb=K.prefixStrings[p]+_currentInputFieldValue;
	if(va||(!aa&&Pa(B.item(c)).toUpperCase().indexOf(cb.toUpperCase())==0||aa&&(c==0&&Pa(B.item(c)).toUpperCase()==cb.toUpperCase()))){
	  Jb=K.prefixStrings[p];
	  S=true;
	  break
	}
      }
			
      if(S){break}
    }
  }
	
  if(S)_highlightedSuggestionIndex=c;
  for(var c=0;c<O;c++)setStyleForElement(B.item(c),"aAutoComplete");
  if(S){
    _highlightedSuggestionDiv=B.item(_highlightedSuggestionIndex);
    r=valueOfDAutoComplete(_highlightedSuggestionDiv)
  }else{
    r=_currentInputFieldValue;
    _highlightedSuggestionIndex=-1;
    _highlightedSuggestionDiv=null}
  var mb=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:
     mb=true;
     break;
    default:
     // regular keypress ...
     break
  }
  
  if(!mb&&_highlightedSuggestionDiv){
    var Oa=_currentInputFieldValue;
    setStyleForElement(_highlightedSuggestionDiv,"bAutoComplete");
    var A;
    if(S) A=Pa(_highlightedSuggestionDiv).substr(K.prefixStrings[p].length);
    else A=Oa;
    
    if(A!=f.value){
      if(f.value!=_currentInputFieldValue)return;
      if(W){
        if(f.createTextRange||f.setSelectionRange) selectEntry(A);
        if(f.createTextRange){
          var u=f.createTextRange();
          u.moveStart("character",Oa.length);
          u.select()
        }else if(f.setSelectionRange){
          f.setSelectionRange(Oa.length,f.value.length)}
        }
       }
    }else{
     _highlightedSuggestionIndex=-1;
     r=_currentInputFieldValue
  }
}

function calculateOffsetLeft(s){
  return kb(s,"offsetLeft")
}

function calculateOffsetTop(s){
  return kb(s,"offsetTop")
}

function kb(s,na){
  var wb=0;
  while(s){
    wb+=s[na];
    s=s.offsetParent}
  return wb
}

// Sets cookie...
// (was called qa...)
function setCookie(z,Y,ab,tb,qb,cc){
  var Vb=z+"="+Y+(ab?"; expires="+ab.toGMTString():"")+(tb?"; path="+tb:"")+(qb?"; domain="+qb:"")+(cc?"; secure":"");
  document.cookie=Vb
}

// Was Sa
function setInputFieldSize(){
  var Ga=document.body.scrollWidth-220;
  Ga=0.73*Ga;
  _inputField.size=Math.floor(Ga/6.18)
 }


function qa(o){
  var M=-1;
  if(o.createTextRange){
    var ha=document.selection.createRange().duplicate();
    M=ha.text.length
  }
  else if(o.setSelectionRange){
    M=o.selectionEnd-o.selectionStart
  }
  return M
}

function ja(o){
  var w=0;
  if(o.createTextRange){
    var ha=document.selection.createRange().duplicate();
    ha.moveEnd("textedit",1);
    w=o.value.length-ha.text.length}
  else if(o.setSelectionRange){
    w=o.selectionStart
    }else{w=-1}
  return w
}

function nc(f){
  if(f.createTextRange){
    var u=f.createTextRange();
    u.moveStart("character",f.value.length);
    u.select()
  }
  else if(f.setSelectionRange){
	  f.setSelectionRange(f.value.length,f.value.length)
  }
}

function setStyleForElement(d,z)
{
	ob();
	d.className=z;
	if(Ua)
	{return}
	switch(z.charAt(0))
	{
	case "m":
		d.style.fontSize="13px";
		d.style.fontFamily="arial,sans-serif";
		d.style.wordWrap="break-word";
		break;
	case "l":
		d.style.display="block";
		d.style.paddingLeft="3";
		d.style.paddingRight="3";
		d.style.height="16px";
		d.style.overflow="hidden";
		break;
	case "a":
		d.style.backgroundColor="white";
		d.style.color="black";
		if(d.displaySpan){d.displaySpan.style.color="green"}
		break;
	case "b":
		d.style.backgroundColor="#3366cc";
		d.style.color="white";
		if(d.displaySpan){d.displaySpan.style.color="white"}
		break;
	case "c":
		//d.style.width=q+"%";
		d.style.width="100%";
		d.style.cssFloat="left";
		break;
	case "d":
		d.style.cssFloat="right";
		d.style.width=100-q+"%";
		if(y=="query")
		{
			d.style.fontSize="10px";
			d.style.textAlign="right";
			d.style.color="green";
			d.style.paddingTop="3px"
		}
		else
		{
			d.style.color="#696969"
		}break
	}
}

function ob()
{
	q=65;
	if(y=="query")
	{
		var Fb=110;var bb=calculateWidth();var Db=(bb-Fb)/bb*100;q=Db}else{q=65}if(Ha){q=99.99}
}
function Qb(j)
{	
	ob();
	var ec="font-size: 13px; font-family: arial,sans-serif; word-wrap:break-word;";
	var gc="display: block; padding-left: 3; padding-right: 3; height: 16px; overflow: hidden;";
	var mc="background-color: white;";var Bb="background-color: #3366cc; color: white ! important;";
	var Eb="display: block; margin-left: 0%; width: "+q+"%; float: left;";
	var Ra="display: block; margin-left: "+q+"%;";
	if(y=="query")
	{Ra+="font-size: 10px; text-align: right; color: green; padding-top: 3px;"}
	else{Ra+="color: #696969;"}
	E(".mAutoComplete",ec);
	E(".lAutoComplete",gc);
	E(".aAutoComplete *",mc);
	E(".bAutoComplete *",Bb);
	E(".cAutoComplete",Eb);
	E(".dAutoComplete",Ra);
	setStyleForElement(j,"mAutoComplete")
}

// Called from sendRPCResponse...
// _highlightedSuggestionDiv = fr.completeDiv
// cs = list of comlete strings...
// recalculateTimeout = list of results...
// was rb
function displaySuggestedList(j,cs,Rb)
{
  while(j.childNodes.length>0)j.removeChild(j.childNodes[0]);

  reg=/&nbsp;/gi;
		
  var nbItem=cs.length;
  if (nbItem>nbMax) nbItem=nbMax;
	
  // For each element in our list, we create:
  // &lt;DIV (u) - mousedown/mouseover/mouseout aAutoComplete>
  //   &lt;SPAN (ka) lAutoComplete>
  //     &lt;SPAN (ua) cAutoComplete>
  //        bug tracking
  //     &lt;/SPAN (ua)>
  //     &lt;SPAN (ea) dAutoComplete>
  //        500,000 results
  //     &lt;/SPAN (ea)>
  //   &lt;/SPAN>
  // &lt;/DIV (u)>
  
 for(var c=0;c<nbItem;++c){
   var v=document.createElement("DIV");
   setStyleForElement(v,"aAutoComplete");
   v.onmousedown=Lb;
   v.onmouseover=Ab;v.onmouseout=pc;
   var ra=document.createElement("SPAN");
   setStyleForElement(ra,"lAutoComplete");
   var Ca=document.createElement("SPAN");
		
   // Remplace &nbsp; par espace
   /*
   var value=cs[c];
   cs[c]=value.replace(reg," TUTUTU ");
   */
   Ca.innerHTML=cs[c]
				
   //alert(Ca.innerHTML)
   var ga=document.createElement("SPAN");
   setStyleForElement(ga,"dAutoComplete");
   setStyleForElement(Ca,"cAutoComplete");
   v.displaySpan=ga;
   //if(!Ha)ga.innerHTML=Rb[c];
   ra.appendChild(Ca);
   ra.appendChild(ga);
   v.appendChild(ra);
   j.appendChild(v)}
}

function E(z,rb){if(Ua){var J=document.styleSheets[0];if(J.addRule){J.addRule(z,rb)}else if(J.insertRule){J.insertRule(z+" { "+rb+" }",J.cssRules.length)}}}

// Was function vb...
// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
function getXMLHTTP(){
  var C=null;
  try{
    C=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      C=new ActiveXObject("Microsoft.XMLHTTP")
    }catch(sc){
       C=null
     }
  }
  if(!C&&typeof XMLHttpRequest!="undefined"){
    C=new XMLHttpRequest()
  }
  return C
}

// 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&amp;js=true&amp;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 callData(ac)
{	
  // alert("callData")
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort()}
   
  _xmlHttp=getXMLHTTP();
  if(_xmlHttp){	
    var strUrl=getUrl(ac);
    
    // We end up calling:
    // /complete/search?hl=en&amp;js=true&amp;qu=&lt;my query string...> ... 
    _xmlHttp.open("GET",strUrl,true);
    // Note that this function will ONLY be called when we get a complete
    // response back from google!!
    _xmlHttp.setRequestHeader("Content-Type","text/xml; charset=iso-8859-1");
    _xmlHttp.onreadystatechange=function(){
      if(_xmlHttp.readyState==4&&_xmlHttp.responseText){
        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)
   }
}

//
//	la méthode responseText ne décode pas _xmlHttp'iso-8859-1 il faut passer par responseXML pour récupérer 
//      les caractères accentués en iso
//
function callDataXml(ac)
{
  // alert("qc_xml")
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort()}
    
  _xmlHttp=getXMLHTTP();
  if(_xmlHttp)
  {
    var strUrl=getUrl(ac);
    _xmlHttp.open("GET",strUrl,true);
    _xmlHttp.setRequestHeader("Content-Type","text/xml; charset=iso-8859-1");
    _xmlHttp.onreadystatechange=function(){
			// alert("onreadystatechange")
			if(_xmlHttp.readyState==4&&_xmlHttp.responseXML){
			  var xmlDoc=_xmlHttp.responseXML
			  var x=xmlDoc.documentElement;
			  if (x && x.childNodes.length){
			    var response=x.childNodes[0].nodeValue;
			    if (response) eval(response);
			  }else{// alert("vide !")
			  }
			}
		       };
    _xmlHttp.send(null)
  }
}
	
function selectEntry(ib){
  _inputField.value=ib;
  ca=ib
}

function Zb(h){if(!h&&window.event)h=window.event;if(!Ea&&(X&&h.propertyName=="value")){if(fc()){eb();setTimeout("ba("+ma+", "+oa+");",30)}}}
function fc(){var ic=_inputField.value;var La=ja(_inputField);var Ja=qa(_inputField);return La==ma&&(Ja==oa&&ic==hb)}
function eb(){hb=_inputField.value;ma=ja(_inputField);oa=qa(_inputField)}
ba=function(La,Ja){if(La==ma&&Ja==oa){bc()}}
;function bc(){blurThenGetFocus();highlightNewValue(_highlightedSuggestionIndex+1)}

function getUrl(ac)
{
	strUrl=_documentForm.action+"?";
	strUrl+="FILE=comp.html";
	strUrl+="&CONTEXT=" + _documentForm.CONTEXT.value;
	strUrl+="&TYPE_RECH=" + _documentForm.TYPE_RECH.value;
	strUrl+="&SECTION_CONF=" + _documentForm.SECTION_CONF.value;
	strUrl+="&TOC_ID_SEL=" + _documentForm.TOC_ID_SEL.value;
	strUrl+="&ACTION=M";
	strUrl+="&TYPE_INDEX=ListeDynamique"
	strUrl+="&POSITION_LIST=0"
	strUrl+="&ALLER_A=" + ac + escape('%');
	strUrl+="&TYPE_MIME=text/xml" 
	strUrl+="&qu=" + ac;
	
	// alert(strUrl)
	return strUrl
}

/*
function getUrl(ac)
{
	//alert("ac="+ac)
	//strUrl=_documentForm.action+"?";
	//strUrl+="FILE=comp2.html";
	//strUrl+="&qu=" + ac;
	strUrl="comp2.xml";
	// alert(strUrl)
	return strUrl;
}
*/
