var g_typeAheadTextChangeTimer=null;function isTypeaheadDivShowing(e){return e.style.display!=="none"}function setInvalidTextClass(e,t){var a=e.className,i="invalidTextField";if(t){if(a.indexOf(i)<0){a=trim(a+" "+i)}}else{a=trim(a.replace(i,""))}e.className=a}function updateTypeaheadTextboxValidation(e){var t=e.typeaheadDiv;if(t.typeAheadConfigParams&&t.typeAheadConfigParams.forceMatchItem){var a=getObj(t.typeAheadConfigParams.formId)||0,i=a[t.typeAheadConfigParams.textFieldName]||0,n=a[t.typeAheadConfigParams.idFieldName]||0,r=i.value||"";if(n.value||!r.length){setInvalidTextClass(i,0)}else if(i.form&&i.form.ignoreFieldValue&&i.form.ignoreFieldValue.value===r){setInvalidTextClass(i,0)}else{setInvalidTextClass(i,1)}}}function hideTypeAheadDiv(){var e=getObj("typeAheadDiv"),t=0;if(e){updateTypeaheadTextboxValidation({typeaheadDiv:e});t=isTypeaheadDivShowing(e);e.scrollTop=0;e.ignoreBlur=false;e.typeAheadConfigParams=null;e.innerHTML="";e.style.display="none"}return t}function hideTypeAheadDivIfNotTypeAheadDiv(e){var t=getObj("typeAheadDiv"),a=(t||{}).typeAheadConfigParams;if(a){var i=true,n=getObj(a.formId),r=(n||{})[a.textFieldName];if(r){i=e!==r}if(i){hideTypeAheadDiv()}}}function fireTypeAheadOnChangeIfNecessary(params_){var objTextControl=params_.textField,tmpUseAsynchForOnChange=params_.useAsynchForOnChange,strOnChangeFunction=objTextControl.getAttribute("mjttypeaheadonchange");if(strOnChangeFunction){if(tmpUseAsynchForOnChange){setTimeout(function(){eval(unescape(strOnChangeFunction))},0)}else{eval(unescape(strOnChangeFunction))}}}function handleExplicitTypeAheadSelection(e){e=e||{};var t=e.resultOptions,a=false,i=getObj("typeAheadDiv");if(i){var n=i.typeAheadConfigParams,r=n?StringificationUtils.getOrResolveFunction({functionNameOrReference:n.fnHandleExplicitSelection,descriptionOfFunctionBeingResolved:"typeAheadConfigParams.fnHandleExplicitSelection",suppressErrorsOnMissingNameOrReference:1}):null,o=n?StringificationUtils.getOrResolveFunction({functionNameOrReference:n.fnHandleExplicitSelectionP,descriptionOfFunctionBeingResolved:"typeAheadConfigParams.fnHandleExplicitSelectionP",suppressErrorsOnMissingNameOrReference:1}):null,s={};if(r||o){if(typeof i.selectedRowIndex!=="undefined"&&i.selectedRowIndex!==null&&i.selectedRowIndex>-1){var d=getObj("typeAheadRow"+i.selectedRowIndex);if(d){if(o){o({idxSelectedRow:i.selectedRowIndex,selectedRow:d,formId:n.formId,typeAheadConfigParams:n,explicitSelectionFnParameter:n.explicitSelectionFnParameter,arrTypeaheadRowVals:mjtElemData(i,"arrTypeaheadRowVals")||null,explicitSelectionResultOptions:s});if(t){t.suppressSetFocus=s.suppressSetFocus}}else{r(i.selectedRowIndex,d,n.formId,n,n.explicitSelectionFnParameter,mjtElemData(i,"arrTypeaheadRowVals")||null)}a=true}else{if(n.fnHandleExplicitEmptySelection){if(n.fnHandleExplicitEmptySelection()){a=true}}}}else{if(n.fnHandleExplicitEmptySelection){if(n.fnHandleExplicitEmptySelection()){a=true}}}}}return a}function scrollTypeaheadSelectionIntoViewIfNecessary(){var e=getObj("typeAheadDiv");if(!e.typeAheadConfigParams){return}if(-1===e.selectedRowIndex){return}var t=getObj("typeAheadRow"+e.selectedRowIndex);if(t){scrollElementIntoViewWithinContainerElement(t,e)}}function getLastTypeaheadDisplayValue(e){return e.getAttribute("data-mjtLastTypeAheadDisplayValue")}function setLastTypeaheadDisplayValue(e,t,a){e.setAttribute("data-mjtLastTypeAheadDisplayValue",t);if(!a){e.value=t}}function checkIfTypeaheadDisplayValueChangedAndSetLastValue(e){var t=getLastTypeaheadDisplayValue(e),a=e.value,i=t!==a;if(i){setLastTypeaheadDisplayValue(e,a,1)}return i}function setClassWhileRetainingPriorSelectionInd(e){var t=e.targetElement,a=e.newClassName,i;if(t){i=t.classList.contains("typeAheadPriorSelection");t.className=a+(i?" typeAheadPriorSelection":"");t.setAttribute("mjtclass",t.className)}}function selectTypeAheadItem(e,t,a,i){var n=false,r=getObj("typeAheadDiv");if(i&&i.button&&i.button!==1){return false}if(!r.typeAheadConfigParams){return false}r.ignoreBlur=a?true:false;if(r.selectedRowIndex!==e){setClassWhileRetainingPriorSelectionInd({targetElement:getObj("typeAheadRow"+r.selectedRowIndex),newClassName:"typeAheadRow"})}r.selectedRowIndex=e;var o=getObj("typeAheadRow"+e),s=r.typeAheadConfigParams,d=s.formId,l=s.textFieldName,f=s.idFieldName,c=s.asyncFocusOnSelect,h=getObj(d),p=h[l],y={};if(o){n=true;setClassWhileRetainingPriorSelectionInd({targetElement:o,newClassName:"typeAheadSelectedRow"});var u=h[f];setInvalidTextClass(p,0);r.ignoreTextChange=true;if(g_typeAheadTextChangeTimer){clearTimeout(g_typeAheadTextChangeTimer)}setLastTypeaheadDisplayValue(p,unescape(o.getAttribute("mjtvalue")));u.value=unescape(o.getAttribute("mjtid"));r.ignoreTextChange=false;scrollTypeaheadSelectionIntoViewIfNecessary();fireTypeAheadOnChangeIfNecessary({textField:p,useAsynchForOnChange:false});if(t){handleExplicitTypeAheadSelection({resultOptions:y})}}if(a){if(!y.suppressSetFocus){if(c){setTimeout(function(){setFocus(p)},0)}else{setFocus(p)}}if(t){hideTypeAheadDiv()}}return n}function removeTypeAheadSelectionOrHoverHighlight(e){var t,a,i=e?"typeAheadSelectedRow":"typeAheadHoverRow";a=getObj("typeAheadRow0");for(t=0;a;++t){if(a.className===i){a.className="typeAheadRow";if(!e){var n=getObj("typeAheadDiv");n.selectedRowIndex=t}}a=getObj("typeAheadRow"+(t+1))}}function mousedownOnTypeahead(e){var t=getObj("typeAheadDiv");t.ignoreBlur=true}function blurTypeahead(e){hideTypeAheadDiv()}function setFocusToTextField(e,t){var a=getObj(e);if(a){var i=a[t];if(i){setFocus(i)}}}function clearSelection(){var e=getObj("typeAheadDiv");if(e){var t=getObj("typeAheadRow"+e.selectedRowIndex);if(t){t.className="typeAheadRow";e.selectedRowIndex=-1}}}function getNoMatchFoundHtml(e,t,a,i){var n=e.noDataMessage,r=i?i(e.showAdditionalLastRow,a):"",o=n?n+r:"No matches found",s=e.typeAheadTableAdditionalClasses,d=s?' class="'+s+'" ':"",l='
'+''+"| "+o+" | "+"
";if(e){if(t&&e.showAdditionalLastRow){l+=t}}l+="
";return l}function processTypeAheadSearchTextArray(e,t,a,i,n,r,o,s,L){var d=getObj("typeAheadDiv"),l=d.typeAheadConfigParams;if(!l){return}d.onmousedown=mousedownOnTypeahead;d.onblur=blurTypeahead;d.ignoreBlur=false;d.selectedRowIndex=-1;var f=getObj(l.formId);if(!f){ConsoleLogging.logBlockClose("no Form! looking for formId="+l.formId);return}var c=f[l.textFieldName],h=f[l.idFieldName],k=h?h.value:null,M=c.value.length>0,p=false,y=false,u=l.autoMatchOnKeyInput;if(typeof o==="undefined"||null===o||o<0){o=-1}if(!(e&&e.length)){if(M){var _=getNoMatchFoundHtml(l);d.style.display="none";d.style.zIndex=501;d.innerHTML=_;setTimeout(doPositionPicker,0)}else{mjtElemData(d,"arrTypeaheadRowVals",null);hideTypeAheadDiv();if(t){fireTypeAheadOnChangeIfNecessary({textField:c,useAsynchForOnChange:false})}}}else{setInvalidTextClass(c,0);var m=o>-1?' colspan="2"':"",g=l?l.typeAheadTableAdditionalClasses||"":"",A="'+"",T=c.value,v=L||l.ignoreCurrentTextForBold?"":T,x=0,C,I=[];d.itemCount=e.length;mjtElemData(d,"arrTypeaheadRowVals",I);for(C=0;C'+" | "+""}else{var w=b.split(":");I[C]=w;var R=w[i],j=w[n],P=unescape(j);if(!y&&P&&P.toLowerCase()===T.toLowerCase()){var D=unescape(R),S=h&&D===k;if(u&&(S||!p)){if(h){h.value=D}y=y||S;p=true;d.selectedRowIndex=x}}var V=typeof r!=="undefined"&&r!==null&&r>-1,N=V?"1"===w[r]:false,B=typeof s!=="undefined"&&s!==null&&s>-1,K=B?"1"===w[s]:false,U=P.substring(0,v.length),W=P.substring(v.length),H="'+"| ";if(N){H+=''}H+=''+htmlEncode(U)+""+htmlEncode(W);if(N){H+=""}H+=" | ";if(o>-1){H+="";if(o"}H+=" |
";A+=H;++x}}if(a){var G=" There are more items"+(v?' starting with "'+htmlEncode(v)+'"':"");A+=''+"| "+G+" | "+"
"}A+=""+"
";d.style.display="none";d.style.zIndex=501;d.innerHTML=A;if(p&&u){var E=getObj("typeAheadRow"+d.selectedRowIndex);E.className="typeAheadSelectedRow";E.setAttribute("mjtclass","typeAheadSelectedRow");fireTypeAheadOnChangeIfNecessary({textField:c,useAsynchForOnChange:false})}setTimeout(doPositionPicker,0)}}function rsCallbackGetTypeAheadSearchText(e,t,a){var i=getObj("typeAheadDiv"),n=i.typeAheadConfigParams;if(!n){return}if(n.expectedContextId&&t&&n.expectedContextId!==t){ConsoleLogging.logMessage("TypeAheadPopup: expected to receive callback from ContextId="+n.expectedContextId+", but instead received callback from ContextId="+t);return}if(checkResponseForError(e)){var r,o;if(!trim(e)){r=[]}else{o=e.substring(0,1)==="1";e=e.substring(2);r=e.split(",")}var s=typeof a.extraHTMLColumnIndex!=="undefined"&&a.extraHTMLColumnIndex!==null,d=s?a.extraHTMLColumnIndex:-1,l=typeof a.isInactiveColumnIndex!=="undefined"&&a.isInactiveColumnIndex!==null,f=l?a.isInactiveColumnIndex:-1,c=typeof a.inactiveMeansCompleteColumnIndex!=="undefined"&&a.inactiveMeansCompleteColumnIndex!==null,h=c?a.inactiveMeansCompleteColumnIndex:-1;processTypeAheadSearchTextArray(r,false,o,0,1,f,d,h,a.forceIgnoreCurrentTextForBold?1:0)}}function taGetItemIndexFromTypeAheadRowChildElem(e){var t=null,a=checkAttribute(e,"data-mjtTAIdx");if(a){t=parseInt(a.getAttribute("data-mjtTAIdx"),10)}return t}function processTypeAheadSearchOfJSONArray(e){var t=getObj("typeAheadDiv"),a=t.typeAheadConfigParams;if(!a){return}t.onmousedown=mousedownOnTypeahead;t.onblur=blurTypeahead;t.ignoreBlur=false;t.selectedRowIndex=-1;var i=getObj(a.formId);if(!i){ConsoleLogging.logBlockClose("No Form! looking for formId="+a.formId);return}var n=i[a.textFieldName],r=i[a.idFieldName],o=r?r.value:null,s=n.value.length>0,d=false,l=false,f=a.autoMatchOnKeyInput,c=e.extraHTMLPropertyName,h=e.renderExtraOnTheLeftPropertyName,p=e.arrObjects,y=e.forceFireTypeAheadOnChange;if(!(p&&p.length)){if(s){var L=getNoMatchFoundHtml(a,e.additionalLastRowHtml,e.originalPayload,e.fnNoMessagePostfix);t.style.display="none";t.style.zIndex=501;t.innerHTML=L;setTimeout(doPositionPicker,0)}else{mjtElemData(t,"arrTypeaheadRowVals",null);hideTypeAheadDiv();if(y){fireTypeAheadOnChangeIfNecessary({textField:n,useAsynchForOnChange:false})}}}else{setInvalidTextClass(n,0);var u=c?' colspan="2"':"",m=a?a.typeAheadTableAdditionalClasses||"":"",g="'+"",A=n.value,T=e.forceIgnoreCurrentTextForBold||a.ignoreCurrentTextForBold?"":A,v=0,x;t.itemCount=p.length;var C=[];mjtElemData(t,"arrTypeaheadRowVals",C);if(e.additionalFirstRowHtml){g+=e.additionalFirstRowHtml}for(x=0;x"+" | "+""}else{C[v]=I;var w=I.id,R=I.name;if(I&&!(w||R)&&w!==""&&R!==""){w=I;R=I}if(!l&&R&&R.toLowerCase()===A.toLowerCase()){var j=r&&w===o;if(f&&(j||!d)){if(r){r.value=w}l=l||j;d=true;t.selectedRowIndex=v}}var P=I.isInactive,k=I.inactiveMeansComplete,M=R.substring(0,T.length),_=R.substring(T.length),D=a.existingSelectionText,V=D&&R&&R.toLowerCase()===D.toLowerCase(),B=V?" typeAheadPriorSelection":"",S="',N=h?I[h]:false,H;H=c?I[c]||"":"";if(c){H="| "+(H?H:"")+" | "}if(H&&N){S+=H}S+="";if(P){S+=''}S+=''+htmlEncode(M)+""+htmlEncode(_);if(P){S+=" ("+(k?"Complete":"Inactive")+")"+""}S+=" | ";if(H&&!N){S+=H}S+="
";g+=S;++v}}if(e.areMoreItems){var K=" There are more items"+(T?' starting with "'+htmlEncode(T)+'"':"");g+=''+"| "+K+" | "+"
"}if(a){if(e.additionalLastRowHtml&&a.showAdditionalLastRow){g+=e.additionalLastRowHtml}}g+=""+"
";t.style.display="none";t.style.zIndex=501;t.innerHTML=g;if(d&&f){var E=getObj("typeAheadRow"+t.selectedRowIndex);E.className="typeAheadSelectedRow";E.setAttribute("mjtclass","typeAheadSelectedRow");fireTypeAheadOnChangeIfNecessary({textField:n,useAsynchForOnChange:false})}if(e.fnPostProcessTypeaheadDisplay){e.fnPostProcessTypeaheadDisplay({typeaheadDiv:t,arrObjects:p})}setTimeout(doPositionPicker,0)}}function rsCallbackGetTypeAheadSearchTextJSON(e,t){var a=t.originalOptions,i=t.originalPayload,n=t.contextId,r=getObj("typeAheadDiv"),o=(r||{}).typeAheadConfigParams,s=a.arrayPropertyName?a.arrayPropertyName:"array",d=e[s],l=a.fnPreprocessArray,f=a.fnPreprocessObject,c=(i||{}).term||"",h=e.isMore;if(!o){return}if(o.expectedContextId&&n&&o.expectedContextId!==n){ConsoleLogging.logMessage("TypeAheadPopup: expected to receive json-callback from ContextId="+o.expectedContextId+", but instead received callback from ContextId="+n);return}if(l){l({arrItems:d,searchTerm:c})}if(f&&d){d.forEach(function(e){f(e)})}processTypeAheadSearchOfJSONArray({extraHTMLPropertyName:a.extraHTMLPropertyName,renderExtraOnTheLeftPropertyName:a.renderExtraOnTheLeftPropertyName,forceIgnoreCurrentTextForBold:a.forceIgnoreCurrentTextForBold,arrObjects:d,areMoreItems:h,fnPostProcessTypeaheadDisplay:a.fnPostProcessTypeaheadDisplay,additionalLastRowHtml:a.additionalLastRowHtml,additionalFirstRowHtml:a.additionalFirstRowHtml,originalPayload:t.originalPayload,fnNoMessagePostfix:a.fnNoMessagePostfix})}function updateTypeAheadBoxTimerFired(){var e=getObj("typeAheadDiv"),t=e.typeAheadConfigParams;if(t){var a=getObj(t.formId);if(!a[t.textFieldName]){console.log("\n"+"\n"+"!!!!\n"+"Can not find text field for type-ahead.\n"+' configParams.textFieldName="'+t.textFieldName+'"\n'+"!!!!")}var i=a[t.textFieldName].value.toLowerCase(),n;if(i.length===0&&!t.showTypeAheadWhenUnmatched){processTypeAheadSearchTextArray([],true,false,0,1)}else{n=StringificationUtils.getOrResolveFunction({functionNameOrReference:t.fnGetTypeAheadData,descriptionOfFunctionBeingResolved:"configParams.fnGetTypeAheadData"});if(n){n(a,i,t,t.getTypeAheadDataFnParameter)}}}}function getSelectedTypeAheadRow(e){var t=-1;if(e){if(typeof e.selectedRowIndex==="undefined"){return e.selectedRowIndex}}return t}function handleTypeAheadTextBoxBlur(e,t){var a=getObj("typeAheadDiv");if(a&&!a.ignoreBlur){hideTypeAheadDiv()}}function fireAsynchHandleTypeAheadTextChange(){if(g_typeAheadTextChangeTimer){clearTimeout(g_typeAheadTextChangeTimer)}var e=300;if(getObj("typeAheadDiv").typeAheadConfigParams.forceImmediatePopup){e=0}g_typeAheadTextChangeTimer=setTimeout(updateTypeAheadBoxTimerFired,e)}function handleTypeAheadTextBoxFocus(e,t,a){var i=getObj("typeAheadDiv");i.ignoreBlur=false;if(!i.ignoreFocus){i.typeAheadConfigParams=a;var n=getObj(a.formId),r=n[a.idFieldName];if(a.forceTypeAheadOnFocus||a.showTypeAheadWhenUnmatched&&!r.value.length){fireAsynchHandleTypeAheadTextChange()}}}function incrementTypeAheadSelectionIndex(e){var t=getObj("typeAheadDiv"),a=t.itemCount?t.itemCount:0;removeTypeAheadSelectionOrHoverHighlight(false);if(typeof t.selectedRowIndex==="undefined"){selectTypeAheadItem(0,false)}else{var i=parseInt(t.selectedRowIndex,10);if(e){i++}else{--i}if(i>=a){i=a-1}if(i<0){i=0}selectTypeAheadItem(i,false)}}function selectFirstLastInTypeahead(e,t,a){if(isTypeaheadDivShowing(e)){var i=e.itemCount?e.itemCount:0;if(i){selectTypeAheadItem(a?0:i-1,false,false)}}}function pageTypeAheadIfNecessary(e,t,a){if(isTypeaheadDivShowing(e)){var i=e.itemCount?e.itemCount:0,n=e.selectedRowIndex?e.selectedRowIndex:0,r=0,o=i-1,s=e.scrollTop,d=s+e.clientHeight-1,l;for(l=0;l=f.offsetTop&&s+f.offsetHeight/2=f.offsetTop&&d-f.offsetHeight/2r){c=r}else if(!a&&n=i){c=i-1}if(c<0){c=0}selectTypeAheadItem(c,false,false)}}function clearForAndHandleTypeAheadChange(e){var t=e.idField,a=e.textField,i=e.useAsynchForOnChange;if(t&&t.value.length){t.value="";fireTypeAheadOnChangeIfNecessary({textField:a,useAsynchForOnChange:i})}fireAsynchHandleTypeAheadTextChange()}function handleTypeAheadTextBoxOnInput(e,t,a){var i=getObj("typeAheadDiv");if(!i.ignoreTextChange){i.typeAheadConfigParams=a;var n=getObj(a.formId),r=n[a.textFieldName],o=n[a.idFieldName];if(checkIfTypeaheadDisplayValueChangedAndSetLastValue(r)){clearForAndHandleTypeAheadChange({idField:o,textField:r,useAsynchForOnChange:false})}}}function handleTypeAheadTextBoxKeyDown(e_,formId_,typeAheadConfigParams_,handlingEnter_,skipHideDialogOnEnter_){var objTypeAheadDiv=getObj("typeAheadDiv");if(!objTypeAheadDiv.ignoreTextChange){objTypeAheadDiv.typeAheadConfigParams=typeAheadConfigParams_;var theForm=getObj(typeAheadConfigParams_.formId),objTextField=theForm[typeAheadConfigParams_.textFieldName],objIdField=theForm[typeAheadConfigParams_.idFieldName];switch(e_.keyCode){case 38:incrementTypeAheadSelectionIndex(false);break;case 40:if(e_.altKey){var strPickerActivation=objTextField.getAttribute("mjttypeaheadactivation");if(strPickerActivation){hideTypeAheadDiv();eval(strPickerActivation)}}else{incrementTypeAheadSelectionIndex(true)}break;case 33:pageTypeAheadIfNecessary(objTypeAheadDiv,objTextField,true);return false;case 34:pageTypeAheadIfNecessary(objTypeAheadDiv,objTextField,false);return false;case 27:if(hideTypeAheadDiv()){cancelEvent(e_);return false}break;case 13:if(handleExplicitTypeAheadSelection()){return false}else{if(!skipHideDialogOnEnter_){hideTypeAheadDiv()}if(!handlingEnter_){return false}}break;case 9:break;case 116:break;case 37:break;case 39:break;case 16:break;case 36:if(e_.ctrlKey){selectFirstLastInTypeahead(objTypeAheadDiv,objTextField,true)}break;case 35:if(e_.ctrlKey){selectFirstLastInTypeahead(objTypeAheadDiv,objTextField,false)}break;case 17:break;case 18:break;default:if(e_.altKey){break}if(e_.ctrlKey&&(65===e_.keyCode||82===e_.keyCode)){break}clearSelection();clearForAndHandleTypeAheadChange({idField:objIdField,textField:objTextField,useAsynchForOnChange:true});break}}}function typeaheadDivHidingExplicitTypeaheadSelectionHandlerV2(e,t,a,i,n,r){var o=getObj(a),s=o?o[i.textFieldName]:0;hideTypeAheadDiv();if(s){setTimeout(function(){setFocusIfFocusable(s)},0)}}var TypeAheadPopup=function(){var n="All",r=-1;function o(e){var t=e.length,a=n.length,i=0;if(t<=a){if(!t){i=1}else{i=stringStartsWith(n,e,1)}}return i}function e(e){var t=e.arrItems,a=e.searchTerm;if(t&&o(a)){var i={id:r,name:n};t.unshift(i)}return t}function t(e){var t=e.stringifiableParams,a=JSON.stringify(t);return a}return{prependAllItemToArray:e,buildStringifiedTypeaheadInfo:t,PROTECTED:{}}}();