Create Event)
	newDiv.style.left = shim.style.left;
	
	var secondDiv = document.createElement("DIV");
	secondDiv.style.visibility = "hidden";
	secondDiv.style.position = "absolute";
	secondDiv.style.left="-10000";
	secondDiv.style.top="-10000";
	secondDiv.style.width="0";
	secondDiv.style.height="0";
	
	var iFrame = document.createElement("IFRAME");
	iFrame.completeDiv = newDiv;
	iFrame.shim = shim;
	iFrame.name = "completionFrame_" + displayFld.name;
	iFrame.id = "completionFrame_" + displayFld.name;
	iFrame.src = acAjaxURL;
	
	secondDiv.appendChild(iFrame);
	document.body.appendChild(secondDiv);
	acResultDivs[displayFld.name] = iFrame;
}
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
}
var acSuggestionMouseOver = function() {
	//if(_highlightedSuggestionDiv) {
		//setStyleForElement(_highlightedSuggestionDiv,"aAutoComplete");
	//}
	setStyleForElement(this,"bAutoComplete")
};
var acSuggestionMouseOut = function() {
	setStyleForElement(this,"aAutoComplete")
};
// Called by parseAjaxResponse to display the suggestions
function displaySuggestedList(acDiv, listResults, listIDs){
	while(acDiv.childNodes.length > 0) {
		acDiv.removeChild(acDiv.childNodes[0]);
	}
	acNumResults[acCurDisplayField.name] = listResults.length;
	// For each element in our list, we create:
	// 
	//   
	//     
	//        M. KREULEN Brian
	//     
	//      // This span is hidden
	//        0000d50000001fdb
	//     
	//   
	// 
	for(var f = 0; f < listResults.length; ++f) {
		var u=document.createElement("DIV");
		setStyleForElement(u,"aAutoComplete");
		u.onmousedown = acOnMouseDown;
		u.onmouseover = acSuggestionMouseOver;
		u.onmouseout = acSuggestionMouseOut;
		var ka=document.createElement("SPAN");
		setStyleForElement(ka,"lAutoComplete");
		
		var ua=document.createElement("SPAN");
		ua.innerHTML=listResults[f]; // the text for the suggested result...
		
		var ea=document.createElement("SPAN");
		setStyleForElement(ea,'dAutoComplete');
		setStyleForElement(ua,"cAutoComplete");
		u.displaySpan=ea;
		ea.innerHTML=listIDs[f]; // The ID of the suggested result
		
		ka.appendChild(ua);
		ka.appendChild(ea);
		u.appendChild(ka);
		acDiv.appendChild(u);
	}
}
function hideFieldDiv(){
	if (!acCurDisplayField) {
		return;
	}
	
	if (!acResultDivs[acCurDisplayField.name]) {
		return;
	}
	
	acResultDivs[acCurDisplayField.name].completeDiv.style.visibility = "hidden";
	acResultDivs[acCurDisplayField.name].shim.style.visibility = "hidden";
	acResultDivs[acCurDisplayField.name].shim.style.display = "none";
	acCurHighlightedDiv = null;
}
function showFieldDiv(){
	if (!acCurDisplayField) {
		return;
	}
	
	if (!acResultDivs[acCurDisplayField.name]) {
		return;
	}
	acResultDivs[acCurDisplayField.name].completeDiv.style.visibility = "visible";
	acResultDivs[acCurDisplayField.name].shim.style.visibility = "visible";
	acResultDivs[acCurDisplayField.name].shim.style.display = "block";
}
function setCompleteDivSize(divToSet, sourceField){
	if(divToSet){
		divToSet.style.left = acCalcDisplayOffset(sourceField, "offsetLeft") + "px";
		divToSet.style.top = acCalcDisplayOffset(sourceField, "offsetTop") + sourceField.offsetHeight - 1 + "px";
		divToSet.style.width = calculateDisplayWidth(sourceField) + "px";
	}
}
// Called in resposne to a successfull ajax phone home
parseAjaxResponse = function(iFrame, searchTerm, listResults, listIDs) {
	if(acTimeoutAdjustment > 0) {
		acTimeoutAdjustment--;
	}
	acCacheResults(acCurDisplayField.name, searchTerm, listResults, listIDs);
	var b = iFrame.completeDiv;
	var s = iFrame.shim;
	b.completeStrings = listResults;
	b.displayStrings = listIDs;
	
	//b.prefixStrings=pr;
	displaySuggestedList(b,b.completeStrings,b.displayStrings);
	checkKeypress(b);
	if(acCurrentDisplayValues[acCurDisplayField.name] == "" || 0 == listResults.length) {
		hideFieldDiv()
	}else{
		showFieldDiv()
	}
	if(listResults.length > 0) {
		s.style.width = b.offsetWidth;
		b.height = 16 * listResults.length + 4;
		s.style.height = b.height;
	} else {
		hideCompleteDiv();
	}
}
// Function that calls home and gets the data.
function callEDeal(escapedSearchTerm) {
	if(xmlHTTP && xmlHTTP.readyState!=0){
		xmlHTTP.abort()
	}
	if (!acCurDisplayField) {
		return;
	}
	var fldName = acCurDisplayField.name;
	var acField = fldName.substring(3,fldName.length);
	//JSA
	if (acField.indexOf('-')>0) {
		acField=acField.substring(0,acField.indexOf('-'));
	}
	var url = acAjaxURL + '?field=' + acField + '&search=' + escapedSearchTerm;
	var querField = '_' + acField + '_query';
	try {
		eval('url += \'&query=\' + escape(' + querField + ');');
	} catch (error) {
	}
	
	xmlHTTP=getXMLHTTP();
	if(xmlHTTP){
		// We end up calling:
		// /complete/search?hl=en&js=true&qu= ... 
		xmlHTTP.open("GET", url, 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 = acResultDivs[acCurDisplayField.name];
				if(xmlHTTP.responseText.charAt(0) == "<") {
					acTimeoutAdjustment--;
				} 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);
	}
}
function recalculateTimeout(Mb){
	var H=100;
	for(var o=1; o<=(Mb-2)/2; o++){
		H=H*2
	}
	H=H+50;
	return H
}
// Main timeout based loop
var mainLoop = function() {
	if (!acCurDisplayField) {
		setTimeout("mainLoop()",recalculateTimeout(acTimeoutAdjustment));
		return true;
	}
	
	var lastValue; 
	try {
		lastValue = acLastDisplayValues[acCurDisplayField.name];
	} catch (err) {
		lastValue = "";
	}
	var newValue;
	try {
		newValue = acCurrentDisplayValues[acCurDisplayField.name];
	} catch (err) {
		newValue = "";
	}
	
	if (newValue != '' && lastValue != newValue) {
		var escapedValue = escapeURI(newValue);
		var ourCache = acResultCache[acCurDisplayField.name];
		var ma = null;
		
		if (ourCache) {
			ma = ourCache[newValue];
		}
		
		if (ma) {
			parseAjaxResponse(acResultDivs[acCurDisplayField.name], newValue, ma[0], ma[1], acResultDivs[acCurDisplayField.name].completeDiv.prefixStrings);
		} else {
			acTimeoutAdjustment++;
			callEDeal(escapedValue);
		}
		acCurDisplayField.focus();
	}
	
	acLastDisplayValues[acCurDisplayField.name] = acCurrentDisplayValues[acCurDisplayField.name];
	setTimeout("mainLoop()",recalculateTimeout(acTimeoutAdjustment));
	return true;
};
setTimeout("mainLoop()", 10);
function escapeURI(toEncode) {
	if (escape) {
		return escape(toEncode);
	}
	if(encodeURIComponent) {
		return encodeURIComponent(toEncode);
	}
	return toEncode;
}
function isMSIE() {
	return (navigator && navigator.userAgent.toLowerCase().indexOf("msie") >= 0);
}
function displayOnFocus(dispField) {
	var f = document.forms[0];
	var nameID = dispField.name.substring(3, dispField.name.length);	
	acCurDisplayField = dispField;
	acCurIDField = f[nameID];
	if (acCurIDField==null) {
		acCurIDField=document.getElementById(nameID);
	}
	acLastCompleteValues[acCurDisplayField.name] = acCurDisplayField.value;
	acLastCompleteValues[acCurIDField.name] = acCurIDField.value;
	acCurDisplayField.value = '';
	acCurIDField.value = '';
	acLastDisplayValues[acCurDisplayField.name] = '';
	acCurrentDisplayValues[acCurDisplayField.name] = '';
}
function displayOnFocusTwo(dispField,formIndex) {
	var f = document.forms[formIndex];
	var nameID = dispField.name.substring(3, dispField.name.length);	
	acCurDisplayField = dispField;
	acCurIDField = f[nameID];
	if (acCurIDField==null) {
		acCurIDField=document.getElementById(nameID);
	}
	acCurDisplayField.value = '';
	acCurIDField.value = '';
	acLastDisplayValues[acCurDisplayField.name] = '';
	acCurrentDisplayValues[acCurDisplayField.name] = '';
}
function stripCRFromString(strToStrip){
	var rtrn = '';
	var crVal = "\n\r";
	for(var cnt = 0; cnt < strToStrip.length; cnt++) {
		if (crVal.indexOf(strToStrip.charAt(cnt)) == -1) {
			rtrn += strToStrip.charAt(cnt);
		} else {
			rtrn += " ";
		}
	}
	return rtrn;
}
acOnMouseDown = function() {
	selectEntry(valueOfCAutoComplete(this), valueOfDAutoComplete(this));
	hideFieldDiv();
};
function highlightNewValue(newValueIndex) {
	var resultDiv = acResultDivs[acCurDisplayField.name];
	var numResults = acNumResults[acCurDisplayField.name];
	
	if (!resultDiv || !numResults || !acCurSuggestionList) {
		return;
	}
	if(newValueIndex >= numResults){
		newValueIndex = numResults - 1;
	}
	
	if(acCurHighlightedIndex != -1 && newValueIndex != acCurHighlightedIndex){
		setStyleForElement(acCurHighlightedDiv,"aAutoComplete"); 
		acCurHighlightedIndex = -1;
	}
	if(newValueIndex < 0){
		acCurHighlightedIndex = -1;
		acCurDisplayField.focus();
		return;
	}
	
	acCurHighlightedIndex = newValueIndex;
	acCurHighlightedDiv = acCurSuggestionList.item(newValueIndex);
	setStyleForElement(acCurHighlightedDiv,"bAutoComplete");
}
// Just a bad hack: as all the Autocomplete stuff is based on the .name, and that for some reason we wish to be based on the id
// instead => we just replace the name by the id. The correct value replacement will be done as usual
// but at the end the doTriggerChangeFromAC will put back the correct name, stored in an arbitrary attribute 
function installFobACbasedOnID(displayFld) {
	var realElement=document.getElementById(displayFld.id.substr(3));
	
	$(displayFld).attr("ed:realname",displayFld.name);
	$(realElement).attr("ed:realname",realElement.name);
	displayFld.name=displayFld.id;
	realElement.name=realElement.id;
	
	installFobAC(displayFld);
	
}