<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl"%><% response.setContentType("application/x-javascript"); %> // These are the currently active fob fields. // These two variables are set by the fields' onFocus() method var acCurDisplayField__Text__; var acCurIDField__Text__; var acCurFieldName__Text__; var maxLimit__Text__; var caseSensitive__Text__; var fieldTable__Text__; var triggerSize__Text__; var distinct__Text__; // The last key that was pressed while the focus was on a FOB field var acLastKeyPressed__Text__; // The cache of all the results received thus far. Helpful on slow connections var acResultCache__Text__ = new Object(); // The link that will be called by ajax var acAjaxURL__Text__ = '/TextAjaxAutoComplete'; // xml http object used to call home var xmlHTTP__Text__; // Each fob field has its own div to hold results. This array holds these divs // Index is the field name, ie. "lblEntActID" var acResultDivs__Text__ = new Object(); // The old and new display values for each fob field. Old values become new values after each timeout period, // not after each keypress. // Index is the field name, ie. "lblEntActID" var acLastDisplayValues__Text__ = new Object(); var acCurrentDisplayValues__Text__ = new Object(); // acLastCompleteValues__Text__ is an array storing the last "good" values of a field. Both the ID and // display value are stored here, as two seperate strings. var acLastCompleteValues__Text__ = new Array(); // acDisplayDivs__Text__ is used to store the divs and iframes. When a user clicks on // a text field, the position of the AC elements are recalculated. This is // because fobAC fields that are contained in small tabs need this. var acDisplayDivs__Text__ = new Array(); // The number of suggestions a given fob field currently has. // Index is the field name, ie. "lblEntActID" var acNumResults__Text__ = new Object(); // The currently highlighted suggestion var acCurHighlightedIndex__Text__ = -1; // The complete list of suggestions var acCurSuggestionList__Text__; // The div which contains the currently highlighted suggestion. // This div is a subcomponent of the acCurSuggestionList__Text__ div var acCurHighlightedDiv__Text__; // Variable used to calculate how much time we should give for a timeout. Useful // on slower connections var acTimeoutAdjustment__Text__ = 0; // Mouse click handler function var acOnMouseDown__Text__; function doBlurThenGetFocus__Text__() { blurThenGetFocus=true; acCurDisplayField__Text__.blur(); setTimeout("setInputFieldFocus__Text__();",10); } /** * 'Unconverts' a string that has been formatted to the web. See the method to see which * characters are currently converted */ function formatFromWeb__Text__(pStr) { return pStr.replace('&','&').replace('"','"').replace('<','<').replace('>','>'); } function selectEntry__Text__(newValue, newID) { if (!newID || newID == '' || newID.length != 16) { return; } if (!newValue || newValue == '') { return; } var displayVar = formatFromWeb__Text__(newValue); acCurDisplayField__Text__.value = displayVar; acCurIDField__Text__.value = newID; acLastCompleteValues__Text__[acCurDisplayField__Text__.name] = displayVar; acLastCompleteValues__Text__[acCurIDField__Text__.name] = newID; // Is there a field change function? var changeFuncName = 'do' + acCurDisplayField__Text__.name.substring(3) + 'Change'; //alert("changeFuncName"+changeFuncName) if (changeFuncName.indexOf('-')<0) { eval('try{' + changeFuncName + '();}catch(error){}'); } // Add doTriggerChange for new grid edition mode if (typeof(doTriggerChangeFromAc) == 'function') { doTriggerChangeFromAc(acCurDisplayField__Text__.name.substring(3)); } } // This method restores the display and id field of the given edeal field to the // last known "good" value. This is only called from the onBlur method. function restoreCurrentEntries__Text__() { // Added for the edit_selection2 action. if (!acCurDisplayField__Text__) { return; } acCurDisplayField__Text__.value = acLastCompleteValues__Text__[acCurDisplayField__Text__.name]; acLastDisplayValues__Text__[acCurDisplayField__Text__.name] = acLastCompleteValues__Text__[acCurDisplayField__Text__.name]; acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name] = acLastCompleteValues__Text__[acCurDisplayField__Text__.name]; acCurIDField__Text__.value = acLastCompleteValues__Text__[acCurIDField__Text__.name]; } function checkKeypress__Text__(localCompleteDiv){ var localInputField = acCurDisplayField__Text__; var T=false; acCurHighlightedIndex__Text__ = -1; //alert(localCompleteDiv); acCurSuggestionList__Text__ = localCompleteDiv.getElementsByTagName("div"); var listLength = acCurSuggestionList__Text__.length; if(acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name] == "" || listLength == 0) { hideFieldDiv__Text__(); } else { showFieldDiv__Text__(); } acCurHighlightedIndex__Text__ = -1; acCurHighlightedDiv__Text__ = null; } // This onBlurHandler is responsable for maintaining the integrity of the two fields of a // FOB input. function acOnBlurHandler__Text__(event) { if(!event && window.event) { event=window.event; } if (acLastKeyPressed__Text__ != 38 && acLastKeyPressed__Text__ != 40) { hideFieldDiv__Text__(); //restoreCurrentEntries__Text__(); } } function acResizeDisplayDiv__Text__(targetField) { setCompleteDivSize__Text__(acDisplayDivs__Text__[targetField.name], targetField); setCompleteDivSize__Text__(acDisplayDivs__Text__["shim_" + targetField.name], targetField); } var acKeyPressHandler__Text__ = function(e) { acLastKeyPressed__Text__ = e.keyCode; //JSA prevent event to bubble if (acCurHighlightedDiv__Text__!=null) { if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } } acHandleKey__Text__(); }; setInputFieldFocus__Text__=function(){ acCurDisplayField__Text__.focus(); }; function acGetRange__Text__(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 acGetSelection__Text__(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 handleCursorUpDownEnter__Text__(eventCode) { if(eventCode == 40){ highlightNewValue__Text__(acCurHighlightedIndex__Text__ + 1); return false; } else if(eventCode == 38) { highlightNewValue__Text__(acCurHighlightedIndex__Text__ - 1); return false; } else if(eventCode == 13 || eventCode == 3) { selectEntry__Text__(valueOfCAutoComplete__Text__(acCurHighlightedDiv__Text__), valueOfDAutoComplete(acCurHighlightedDiv__Text__)); hideFieldDiv__Text__(); return false; } return true; } function findSpanValueForClass__Text__(i,dc){ var ga=i.getElementsByTagName("span"); if(ga){ for(var f=0; fCreate 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 = "javascript:false;"; secondDiv.appendChild(iFrame); document.body.appendChild(secondDiv); acResultDivs__Text__[displayFld.name] = iFrame; } function getXMLHTTP__Text__(){ 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__Text__ = function() { //if(_highlightedSuggestionDiv) { //setStyleForElement__Text__(_highlightedSuggestionDiv,"aAutoComplete"); //} setStyleForElement__Text__(this,"bAutoComplete") }; var acSuggestionMouseOut__Text__ = function() { setStyleForElement__Text__(this,"aAutoComplete") }; // Called by parseAjaxResponse__Text__ to display the suggestions function displaySuggestedList__Text__(acDiv, listResults, listIDs){ while(acDiv.childNodes.length > 0) { acDiv.removeChild(acDiv.childNodes[0]); } acNumResults__Text__[acCurDisplayField__Text__.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__Text__(u,"aAutoComplete"); u.onmousedown = acOnMouseDown__Text__; u.onmouseover = acSuggestionMouseOver__Text__; u.onmouseout = acSuggestionMouseOut__Text__; var ka=document.createElement("SPAN"); setStyleForElement__Text__(ka,"lAutoComplete"); var ua=document.createElement("SPAN"); ua.innerHTML=listResults[f]; // the text for the suggested result... var ea=document.createElement("SPAN"); setStyleForElement__Text__(ea,'dAutoComplete'); setStyleForElement__Text__(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__Text__(){ if (!acCurDisplayField__Text__) { return; } if (!acResultDivs__Text__[acCurDisplayField__Text__.name]) { return; } acResultDivs__Text__[acCurDisplayField__Text__.name].completeDiv.style.visibility = "hidden"; acResultDivs__Text__[acCurDisplayField__Text__.name].shim.style.visibility = "hidden"; acResultDivs__Text__[acCurDisplayField__Text__.name].shim.style.display = "none"; acCurHighlightedDiv__Text__ = null; } function showFieldDiv__Text__(){ if (!acCurDisplayField__Text__) { return; } if (!acResultDivs__Text__[acCurDisplayField__Text__.name]) { return; } acResultDivs__Text__[acCurDisplayField__Text__.name].completeDiv.style.visibility = "visible"; acResultDivs__Text__[acCurDisplayField__Text__.name].shim.style.visibility = "visible"; acResultDivs__Text__[acCurDisplayField__Text__.name].shim.style.display = "block"; } function setCompleteDivSize__Text__(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__Text__(sourceField) + "px"; } } // Called in resposne to a successfull ajax phone home parseAjaxResponse__Text__ = function(iFrame, searchTerm, query, listResults, listIDs) { if(acTimeoutAdjustment__Text__ > 0) { acTimeoutAdjustment__Text__--; } acCacheResults__Text__(acCurDisplayField__Text__.name, searchTerm, query, listResults, listIDs); var b = iFrame.completeDiv; var s = iFrame.shim; b.completeStrings = listResults; b.displayStrings = listIDs; //b.prefixStrings=pr; displaySuggestedList__Text__(b,b.completeStrings,b.displayStrings); checkKeypress__Text__(b); if(acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name] == "" || 0 == listResults.length) { hideFieldDiv__Text__() }else{ showFieldDiv__Text__() } 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__Text__(escapedSearchTerm) { if(xmlHTTP__Text__ && xmlHTTP__Text__.readyState!=0){ xmlHTTP__Text__.abort() } if (!acCurDisplayField__Text__) { return; } var fldName = acCurDisplayField__Text__.name; var acField = fldName; //JSA if (acField.indexOf('-')>0) { acField=acField.substring(0,acField.indexOf('-')); } var nameFieldToComplete_ = document.getElementById(acField+'Field __').value; var maxLimit_ = document.getElementById(acField+'MaxLimit__').value; var caseSensitive_ = document.getElementById(acField+'CaseSensitive__').value; var fieldTable_ = document.getElementById(acField+'Table__').value; var triggerSize_ = document.getElementById(acField+'Trigger__').value; var distinct_ = document.getElementById(acField+'Distinct__').value; var url = acAjaxURL__Text__ + '?field=' + nameFieldToComplete_ + '&search=' + escapedSearchTerm + '&maxlimit=' + maxLimit_ + '&casesensitive=' + caseSensitive_ + '&table=' + fieldTable_ +'&trigger=' + triggerSize_ + '&distinct=' + distinct_; var querField = document.getElementById(acField+'Query__').value; //queryField = escape(' + querField + '); //alert(queryField); try { //eval('url'); eval('url += \'&query=\' + querField'); //eval('url += \'&query=\' + escape(' + querField + ');'); } catch (error) { } xmlHTTP__Text__=getXMLHTTP__Text__(); if(xmlHTTP__Text__){ // We end up calling: // /complete/search?hl=en&js=true&qu= ... xmlHTTP__Text__.open("GET", url, true); // Note that this function will ONLY be called when we get a complete // response back from google!! xmlHTTP__Text__.onreadystatechange=function() { if(xmlHTTP__Text__.readyState == 4 && xmlHTTP__Text__.responseText) { var frameElement = acResultDivs__Text__[acCurDisplayField__Text__.name]; if(xmlHTTP__Text__.responseText.charAt(0) == "<") { acTimeoutAdjustment__Text__--; } else { // The response text gets executed as javascript... eval(xmlHTTP__Text__.responseText); } } }; // DON'T TRY TO TALK WHEN WE'RE LOCAL... // Comment out when running from a local file... xmlHTTP__Text__.send(null); } } function recalculateTimeout__Text__(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__Text__ = function() { if (!acCurDisplayField__Text__) { setTimeout("mainLoop__Text__()",recalculateTimeout__Text__(acTimeoutAdjustment__Text__)); return true; } var lastValue; try { lastValue = acLastDisplayValues__Text__[acCurDisplayField__Text__.name]; } catch (err) { lastValue = ""; } var newValue; try { newValue = acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name]; } catch (err) { newValue = ""; } if (newValue != '' && lastValue != newValue) { var escapedValue = escapeURI(newValue); var ourCache = acResultCache__Text__[acCurDisplayField__Text__.name]; var ma = null; if (ourCache) { ma = ourCache[newValue]; } if (ma) { parseAjaxResponse__Text__(acResultDivs__Text__[acCurDisplayField__Text__.name], newValue, ma[0], ma[1], acResultDivs__Text__[acCurDisplayField__Text__.name].completeDiv.prefixStrings); } else { acTimeoutAdjustment__Text__++; callEDeal__Text__(escapedValue); } acCurDisplayField__Text__.focus(); } acLastDisplayValues__Text__[acCurDisplayField__Text__.name] = acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name]; setTimeout("mainLoop__Text__()",recalculateTimeout__Text__(acTimeoutAdjustment__Text__)); return true; }; setTimeout("mainLoop__Text__()", 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__Text__(dispField) { var f = document.forms[0]; //var nameID = dispField.name.substring(3, dispField.name.length); var nameID = dispField.name+"Hidden__"; acCurDisplayField__Text__ = dispField; acCurIDField__Text__ = f[nameID]; if (acCurIDField__Text__==null) { acCurIDField__Text__=document.getElementById(nameID); } acLastCompleteValues__Text__[acCurDisplayField__Text__.name] = acCurDisplayField__Text__.value; acLastCompleteValues__Text__[acCurIDField__Text__.name] = acCurIDField__Text__.value; //acCurDisplayField__Text__.value = ''; //acCurIDField__Text__.value = ''; //acLastDisplayValues__Text__[acCurDisplayField__Text__.name] = ''; //acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name] = ''; } function displayOnFocusTwo__Text__(dispField,formIndex) { var f = document.forms[formIndex]; //var nameID = dispField.name.substring(3, dispField.name.length); var nameID = dispField.name+"Hidden__"; acCurDisplayField__Text__ = dispField; acCurIDField__Text__ = f[nameID]; if (acCurIDField__Text__==null) { acCurIDField__Text__=document.getElementById(nameID); } //acCurDisplayField__Text__.value = ''; //acCurIDField__Text__.value = ''; //acLastDisplayValues__Text__[acCurDisplayField__Text__.name] = ''; //acCurrentDisplayValues__Text__[acCurDisplayField__Text__.name] = ''; } function stripCRFromString__Text__(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__Text__ = function() { selectEntry__Text__(valueOfCAutoComplete__Text__(this), valueOfDAutoComplete(this)); hideFieldDiv__Text__(); }; function highlightNewValue__Text__(newValueIndex) { var resultDiv = acResultDivs__Text__[acCurDisplayField__Text__.name]; var numResults = acNumResults__Text__[acCurDisplayField__Text__.name]; if (!resultDiv || !numResults || !acCurSuggestionList__Text__) { return; } if(newValueIndex >= numResults){ newValueIndex = numResults - 1; } if(acCurHighlightedIndex__Text__ != -1 && newValueIndex != acCurHighlightedIndex__Text__){ setStyleForElement__Text__(acCurHighlightedDiv__Text__,"aAutoComplete"); acCurHighlightedIndex__Text__ = -1; } if(newValueIndex < 0){ acCurHighlightedIndex__Text__ = -1; acCurDisplayField__Text__.focus(); return; } acCurHighlightedIndex__Text__ = newValueIndex; acCurHighlightedDiv__Text__ = acCurSuggestionList__Text__.item(newValueIndex); setStyleForElement__Text__(acCurHighlightedDiv__Text__,"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__Text__(displayFld) { // //var realElement=document.getElementById(displayFld.id.substr(3)); // var realElement=document.getElementById(displayFld.id); // $(displayFld).attr("ed:realname",displayFld.name); // $(realElement).attr("ed:realname",realElement.name); // displayFld.name=displayFld.id; // realElement.name=realElement.id; // // installFobAC(displayFld); // //}