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