collection=arrAutoF;var hdnAutoFillDefault=document.getElementById(m_sAutoFillDefaultCtrlID);var hdnAutoFillAllValue=document.getElementById(m_sAutoFillAllValueCtrlID);var hdnAutoFillNoMatch=document.getElementById(m_sAutoFillNoMatchCtrlID);var m_bAutoFillAllRestSelected=false;try{if(WRITE_WICK_WRAPPER==undefined)var WRITE_WICK_WRAPPER=true;if(WRITE_WICK_WRAPPER)writeWrapper()}catch(err){writeWrapper()}var m_bAlreadyWritten=false;
function writeWrapper(){if(!m_bAlreadyWritten)document.write('<div id="PopupDiv" class="floaterDiv"><table id="smartInputFloater" class="floater" cellpadding="0" cellspacing="0"><tr><td id="smartInputFloaterContent" nowrap="nowrap"><!-- ie --\></td></tr></table><div class="dupfix"><!-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||| --\></div></div>');m_bAlreadyWritten=true}
function freezeEvent(e){if(e.preventDefault)e.preventDefault();e.returnValue=false;e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();return false}function isWithinNode(e,i,c,t,obj){answer=false;te=e;while(te&&!answer)if(te.id&&te.id==i||te.className&&te.className==i+"Class"||!t&&c&&te.className&&te.className==c||!t&&c&&te.className&&te.className.indexOf(c)!=-1||t&&te.tagName&&te.tagName.toLowerCase()==t||obj&&te==obj)answer=te;else te=te.parentNode;return te}
function getEvent(event){return event?event:window.event}function getEventElement(e){return e.srcElement?e.srcElement:e.target?e.target:e.currentTarget}function findElementPosX(obj){curleft=0;if(obj.offsetParent)while(obj.offsetParent){curleft+=obj.offsetLeft;obj=obj.offsetParent}else if(obj.x)curleft+=obj.x;return curleft}function findElementPosY(obj){curtop=0;if(obj.offsetParent)while(obj.offsetParent){curtop+=obj.offsetTop;obj=obj.offsetParent}else if(obj.y)curtop+=obj.y;return curtop}
function handleKeyPress(event){e=getEvent(event);eL=getEventElement(e);upEl=isWithinNode(eL,null,"wickEnabled",null,null);kc=e["keyCode"];if(siw&&(kc==13||kc==9)){siw.selectingSomething=true;if(siw.isSafari)siw.inputBox.blur();siw.inputBox.focus();siw.inputBox.value=siw.inputBox.value.replace(/[ \r\n\t\f\s]+$/gi," ");hideSmartInputFloater()}else if(upEl&&kc!=38&&kc!=40&&kc!=37&&kc!=39&&kc!=13&&kc!=27){if(!siw||siw&&!siw.selectingSomething)processSmartInput(upEl)}else if(siw&&siw.inputBox)siw.inputBox.focus()}
function handleKeyDown(event){e=getEvent(event);eL=getEventElement(e);if(siw&&(kc=e["keyCode"]))if(kc==40){siw.selectingSomething=true;freezeEvent(e);if(siw.isGecko)siw.inputBox.blur();selectNextSmartInputMatchItem()}else if(kc==38){siw.selectingSomething=true;freezeEvent(e);if(siw.isGecko)siw.inputBox.blur();selectPreviousSmartInputMatchItem()}else if(kc==13||kc==9){siw.selectingSomething=true;activateCurrentSmartInputMatch();freezeEvent(e)}else if(kc==27){hideSmartInputFloater();freezeEvent(e)}else siw.selectingSomething=
false}function handleFocus(event){e=getEvent(event);eL=getEventElement(e);if(focEl=isWithinNode(eL,null,"wickEnabled",null,null))if(!siw||siw&&!siw.selectingSomething){ClearAutoFillRestSearch();processSmartInput(focEl)}}function handleBlur(event){e=getEvent(event);eL=getEventElement(e);if(blurEl=isWithinNode(eL,null,"wickEnabled",null,null))if(siw&&!siw.selectingSomething)hideSmartInputFloater()}
function handleClick(event){e2=getEvent(event);eL2=getEventElement(e2);if(siw&&siw.selectingSomething)selectFromMouseClick()}function handleMouseOver(event){e=getEvent(event);eL=getEventElement(e);if(siw&&(mEl=isWithinNode(eL,null,"matchedSmartInputItem",null,null))){siw.selectingSomething=true;selectFromMouseOver(mEl)}else if(isWithinNode(eL,null,"siwCredit",null,null))siw.selectingSomething=true;else if(siw)siw.selectingSomething=false}
function showSmartInputFloater(){if(!siw.floater.style.display||siw.floater.style.display=="none"){if(!siw.customFloater){x=findElementPosX(siw.inputBox);y=findElementPosY(siw.inputBox)+siw.inputBox.offsetHeight;if(!siw.isGecko&&!siw.isWinIE)x+=8;if(!siw.isGecko&&!siw.isWinIE)y+=10;siw.floater.style.left=x;siw.floater.style.top=y}else;siw.floater.style.display="block";siw.floater.style.visibility="visible";DivSetVisible(true,siw.matchCollection.length)}}
function hideSmartInputFloater(){if(siw){siw.floater.style.display="none";siw.floater.style.visibility="hidden";DivSetVisible(false,0);siw=null}}
function processSmartInput(inputBox){if(!siw)siw=new smartInputWindow;siw.inputBox=inputBox;if(siw.inputBox!=null)if(siw.inputBox.value.length==0)updateSelects(false,0);classData=inputBox.className.split(" ");siwDirectives=null;for(i=0;!siwDirectives&&classData[i];i++)if(classData[i].indexOf("wickEnabled")!=-1)siwDirectives=classData[i];if(siwDirectives&&siwDirectives.indexOf(":")!=-1){siw.customFloater=true;newFloaterId=siwDirectives.split(":")[1];siw.floater=document.getElementById(newFloaterId);
siw.floaterContent=siw.floater.getElementsByTagName("div")[0]}setSmartInputData();if(siw.matchCollection&&siw.matchCollection.length>0)selectSmartInputMatchItem(0);content=getSmartInputBoxContent();show=false;if(content){modifySmartInputBoxContent(content);showSmartInputFloater();show=true;updateSelects(show,siw.matchCollection.length)}else{hideSmartInputFloater();updateSelects(show,0)}}
function smartInputMatch(cleanValue,value,ID){this.cleanValue=cleanValue;this.value=value;this.isSelected=false;this.weight=0;this.ID=ID}function simplify(s){theRet=s.replace(/^[ \s\f\t\n\r]+/,"").replace(/[ \s\f\t\n\r]+$/,"");return theRet}function CleanInput(s){var sVal="";sVal=s.replace(/^[ \s\f\t\n\r]+/,"");return sVal}
function isValidSrchInput(s){var bValid=true;try{var regSpcPfx=new RegExp("^\\s]");var regSpcSfx=new RegExp("\\s+$");var daResult=s.match(regSpcPfx);if(daResult!=null)bValid=false;if(bValid){var daResult=s.match(regSpcSfx);if(daResult!=null)bValid=true}return bValid}catch(e){return false}}function cleanInputFurther(input){theCleanIp=input.replace(/[\.|~|`|!|@|#|$|%|\^|&|\*|(|)|_|\+|=|\-|{|}|\||\\|\]|\[|:|"|;|'|<|>|\?|/|\.|,]/gi,"");return theCleanIp}
function GenerateRegexForUserInput(input){theCleanIp=input.replace("AE","(AE|\u00c6)");theCleanIp=theCleanIp.replace("A","(A|\u00c0|\u00c1|\u00c2|\u00c3|\u00c4|\u00c5)");theCleanIp=theCleanIp.replace("C","(C|\u00c7)");theCleanIp=theCleanIp.replace("E","(E|\u00c8|\u00c9|\u00ca|\u00cb)");theCleanIp=theCleanIp.replace("I","(I|\u00cc|\u00cd|\u00ce|\u00cf)");theCleanIp=theCleanIp.replace("D","(D|\u00d0)");theCleanIp=theCleanIp.replace("N","(N|\u00d1)");theCleanIp=theCleanIp.replace("O","(O|\u00d2|\u00d3|\u00d4|\u00d5|\u00d6|\u00d7|\u00d8)");
theCleanIp=theCleanIp.replace("U","(U|\u00d9|\u00da|\u00db|\u00dc)");theCleanIp=theCleanIp.replace("Y","(Y|u00DD)");theCleanIp=theCleanIp.replace("P","(P|\u00de)");theCleanIp=theCleanIp.replace("B","(B|\u00df)");theCleanIp=theCleanIp.replace("ae","(ae|\u00e6)");theCleanIp=theCleanIp.replace("a","(a|\u00e0|\u00e1|\u00e2|\u00e4|\u00e5)");theCleanIp=theCleanIp.replace("c","(c|\u00e7)");theCleanIp=theCleanIp.replace("e","(e|\u00e8|\u00e9|\u00ea|\u00eb)");theCleanIp=theCleanIp.replace("i","(i|\u00ec|\u00ed|\u00ee|\u00ef)");
theCleanIp=theCleanIp.replace("n","(n|\u00f1)");theCleanIp=theCleanIp.replace("o","(o|\u00f2|\u00f3|\u00f4|\u00f5|\u00f6|\u00f8)");theCleanIp=theCleanIp.replace("u","(u|\u00f9|\u00fa|\u00fb|\u00fc)");theCleanIp=theCleanIp.replace("y","(y|\u00fd|\u00ff)");theCleanIp=theCleanIp.replace("p","(p|\u00fe)");return theCleanIp}
function isSpcCharMatch(sInput){try{var regForbidden=new RegExp("([.|~|`|!|@|#|$|%|^|&|*|(|)|_|+|=|-|{|}|||\\|]|[|:|\"|;|'|<|>|?|/|.|,])","gi");var daResult=sInput.match(regForbidden);if(daResult!=null)return true;return false}catch(e){return false}}function getUserInputToMatch(s){a=s;return a}function getUserInputBase(){s=siw.inputBox.value;a=s;a="";return a}
function runMatchingLogic(userInput,standalone){var OriginalEntry="";userInput=CleanInput(userInput);origUInput=userInput;userInput=cleanInputFurther(userInput);uifc=userInput.charAt(0).toLowerCase();if(uifc=='"')uifc=(n=userInput.charAt(1))?n.toLowerCase():"z";if(standalone)userInput=uifc;if(siw)siw.matchCollection=new Array;pointerToCollectionToUse=collection;if(siw&&siw.revisedCollection&&siw.revisedCollection.length>0&&siw.lastUserInput&&userInput.indexOf(siw.lastUserInput)==0)pointerToCollectionToUse=
siw.revisedCollection;else if(collectionIndex[userInput]&&collectionIndex[userInput].length>0)pointerToCollectionToUse=collectionIndex[userInput];else if(collectionIndex[uifc]&&collectionIndex[uifc].length>0)pointerToCollectionToUse=collectionIndex[uifc];else if(siw&&userInput.length==1&&!collectionIndex[uifc])siw.buildIndex=true;else if(siw)siw.buildIndex=false;userInput=GenerateRegexForUserInput(userInput);tempCollection=new Array;re1m=new RegExp('^([ "><-]*)('+userInput+")","i");re2m=new RegExp('([ "><-]+)('+
userInput+")","i");re1=new RegExp('^([ "}{-]*)('+userInput+")","gi");re2=new RegExp('([ "}{-]+)('+userInput+")","gi");nonWord=new RegExp("W","gi");tempUserInput=origUInput.toLowerCase();userInputMarker=0;weightSeed=300;computeWeight=false;wordPos=1;var iRID=0;for(i=0,j=0;i<pointerToCollectionToUse.length;i++){displayMatches=!standalone;OriginalEntry=pointerToCollectionToUse[i];var arrRestInfo=OriginalEntry.split("^");entry=arrRestInfo[0];iRID=arrRestInfo[1];mEntry=simplify(entry);cleanedEntry=cleanInputFurther(mEntry);
computeWeight=false;if(!standalone&&cleanedEntry.indexOf(userInput)==0){userInput=userInput.replace(/\>/gi,"\\}").replace(/\< ?/gi,"\\{");re=new RegExp("("+userInput+")","i");if(displayMatches)siw.matchCollection[j]=new smartInputMatch(entry,mEntry.replace(/\>/gi,"}").replace(/\< ?/gi,"{").replace(re,"<b>$1</b>"),iRID);tempCollection[j]=OriginalEntry;j++;computeWeight=true}else if(cleanedEntry.match(re1m)||cleanedEntry.match(re2m)){if(!standalone&&displayMatches)siw.matchCollection[j]=new smartInputMatch(entry,
mEntry.replace(/\>/gi,"}").replace(/\</gi,"{").replace(re1,"$1<b>$2</b>").replace(re2,"$1<b>$2</b>"),iRID);tempCollection[j]=OriginalEntry;j++;computeWeight=true}if(computeWeight&&siw.matchCollection[j-1])siw.matchCollection[j-1].weight=ComputeMatchWeight(cleanedEntry,re1m,re2m,weightSeed)}if(siw){siw.lastUserInput=userInput;siw.revisedCollection=tempCollection.join(",").split(",");collectionIndex[userInput]=tempCollection.join(",").split(",")}if(standalone||siw.buildIndex){collectionIndex[uifc]=
tempCollection.join(",").split(",");if(siw)siw.buildIndex=false}if(siw.matchCollection.length>0)siw.matchCollection=siw.matchCollection.sort(sortDesc);siw.matchCollection=siw.matchCollection.slice(0,siw.MAX_MATCHES);if(siw.matchCollection!=null&&userInput.length>0&&userInput!=hdnAutoFillDefault.value)if(siw.matchCollection.length==0)siw.matchCollection[0]=new smartInputMatch(hdnAutoFillAllValue.value,hdnAutoFillNoMatch.value,0)}
function ComputeMatchWeight(RestNameEntry,RegxMatchPrefix,RegxMatchSuffix,WeightSeed){var Weight=0;PrefixMatches=RestNameEntry.match(RegxMatchPrefix);SuffixMatches=RestNameEntry.match(RegxMatchSuffix);if(PrefixMatches!=null)Weight+=WeightSeed/(PrefixMatches.index+1);else if(SuffixMatches!=null)Weight+=WeightSeed/(SuffixMatches.index+1);return Weight}
function sortDesc(match1,match2){if(match1.weight>match2.weight)return-1;if(match1.weight<match2.weight)return 1;if(match1.cleanValue.toLowerCase()>match2.cleanValue.toLowerCase())return 1;if(match1.cleanValue.toLowerCase()<match2.cleanValue.toLowerCase())return-1;return 0}
function setSmartInputData(){if(siw){orgUserInput=siw.inputBox.value;orgUserInput=getUserInputToMatch(orgUserInput);if(isValidSrchInput(orgUserInput)){orgUserInput=CleanInput(orgUserInput.toLowerCase());userInput=orgUserInput.toLowerCase().replace(/ +/gi," ").replace(/\\/gi,"").replace(/\[/gi,"").replace(/\(/gi,"").replace(/\./gi,".").replace(/\?/gi,"")}else{orgUserInput=simplify(orgUserInput.toLowerCase());userInput=orgUserInput.toLowerCase().replace(/[\r\n\t\f\s]+/gi," ").replace(/^ +/gi,"").replace(/ +$/gi,
"").replace(/ +/gi," ").replace(/\\/gi,"").replace(/\[/gi,"").replace(/\(/gi,"").replace(/\./gi,".").replace(/\?/gi,"")}if(userInput&&userInput!=""&&userInput!='"')runMatchingLogic(userInput);else siw.matchCollection=null}}
function getSmartInputBoxContent(){a=null;var hdnRestIDfld=document.getElementById(hdnAFRestID);hdnRestIDfld.value="";if(siw&&siw.matchCollection&&siw.matchCollection.length>0){a="";for(i=0;i<siw.matchCollection.length;i++){selectedString=siw.matchCollection[i].isSelected?" selectedSmartInputItem":"";a+='<p class="matchedSmartInputItem'+selectedString+'">'+siw.matchCollection[i].value.replace(/\{ */gi,"&lt;").replace(/\} */gi,"&gt;")+"</p>"}}try{if(siw&&siw.matchCollection&&siw.matchCollection.length==
1)if(siw.matchCollection[0].cleanValue==siw.inputBox.value){if(hdnRestIDfld)if(siw.matchCollection[0].ID>0)hdnRestIDfld.value=siw.matchCollection[0].ID;return null}}catch(e){return null}return a}function modifySmartInputBoxContent(content){siw.floaterContent.innerHTML='<div id="smartInputResults">'+content+"</div>";siw.matchListDisplay=document.getElementById("smartInputResults")}
function selectFromMouseOver(o){currentIndex=getCurrentlySelectedSmartInputItem();if(currentIndex!=null)deSelectSmartInputMatchItem(currentIndex);newIndex=getIndexFromElement(o);selectSmartInputMatchItem(newIndex);try{clearAFSelection();o.className="matchedSmartInputItem selectedSmartInputItem"}catch(err){modifySmartInputBoxContent(getSmartInputBoxContent())}}
function clearAFSelection(){var eSmartInputResults=document.getElementById("smartInputResults");if(eSmartInputResults)for(var i=0;i<eSmartInputResults.childNodes.length;i++)if(eSmartInputResults.childNodes[i].className)eSmartInputResults.childNodes[i].className="matchedSmartInputItem"}function selectFromMouseClick(){activateCurrentSmartInputMatch();siw.inputBox.focus();hideSmartInputFloater()}function getIndexFromElement(o){index=0;while(o=o.previousSibling)index++;return index}
function getCurrentlySelectedSmartInputItem(){answer=null;for(i=0;i<siw.matchCollection.length&&!answer;i++)if(siw.matchCollection[i].isSelected)answer=i;return answer}function selectSmartInputMatchItem(index){siw.matchCollection[index].isSelected=true}function deSelectSmartInputMatchItem(index){siw.matchCollection[index].isSelected=false}
function selectNextSmartInputMatchItem(){currentIndex=getCurrentlySelectedSmartInputItem();if(currentIndex!=null){deSelectSmartInputMatchItem(currentIndex);if(currentIndex+1<siw.matchCollection.length)selectSmartInputMatchItem(currentIndex+1);else selectSmartInputMatchItem(0)}else selectSmartInputMatchItem(0);modifySmartInputBoxContent(getSmartInputBoxContent())}
function selectPreviousSmartInputMatchItem(){currentIndex=getCurrentlySelectedSmartInputItem();if(currentIndex!=null){deSelectSmartInputMatchItem(currentIndex);if(currentIndex-1>=0)selectSmartInputMatchItem(currentIndex-1);else selectSmartInputMatchItem(siw.matchCollection.length-1)}else selectSmartInputMatchItem(siw.matchCollection.length-1);modifySmartInputBoxContent(getSmartInputBoxContent())}
function activateCurrentSmartInputMatch(){baseValue=getUserInputBase();if((selIndex=getCurrentlySelectedSmartInputItem())!=null){addedValue=siw.matchCollection[selIndex].cleanValue;if(siw.matchCollection[selIndex].ID==0&&addedValue==hdnAutoFillAllValue.value)m_bAutoFillAllRestSelected=true;else m_bAutoFillAllRestSelected=false;theString=(baseValue?baseValue:"")+addedValue;theString=theString.replace(/\|\d+/gi,"");siw.inputBox.value=theString;runMatchingLogic(addedValue,true)}}
function smartInputWindow(){this.customFloater=false;this.floater=document.getElementById("smartInputFloater");this.floaterContent=document.getElementById("smartInputFloaterContent");this.selectedSmartInputItem=null;this.MAX_MATCHES=15;this.isGecko=navigator.userAgent.indexOf("Firefox/")!=-1;this.isSafari=navigator.userAgent.indexOf("Safari")!=-1;this.isWinIE=navigator.userAgent.indexOf("Win")!=-1&&navigator.userAgent.indexOf("MSIE")!=-1;this.showCredit=false}
function registerSmartInputListeners(){inputs=document.getElementsByTagName("input");texts=document.getElementsByTagName("textarea");allinputs=new Array;z=0;y=0;while(inputs[z]){allinputs[z]=inputs[z];z++}while(texts[y]){allinputs[z]=texts[y];z++;y++}for(i=0;i<allinputs.length;i++)if((c=allinputs[i].className)&&c=="wickEnabled"){allinputs[i].setAttribute("autocomplete","OFF");allinputs[i].onfocus=handleFocus;allinputs[i].onblur=handleBlur;allinputs[i].onkeydown=handleKeyDown;allinputs[i].onkeyup=
handleKeyPress}}siw=null;
if(document.addEventListener){document.addEventListener("keydown",handleKeyDown,false);document.addEventListener("keyup",handleKeyPress,false);var popupDiv=document.getElementById("PopupDiv");var listenerTarget=popupDiv?popupDiv:document;listenerTarget.addEventListener("mouseup",handleClick,false);listenerTarget.addEventListener("mouseover",handleMouseOver,false)}else{document.onkeydown=handleKeyDown;document.onkeyup=handleKeyPress;document.onmouseup=handleClick;document.onmouseover=handleMouseOver}registerSmartInputListeners();
for(x=0;x<collection.length;x++)collection[x]=collection[x].replace(/\,/gi,"").replace(/\|\d+/gi,"");collectionIndex=new Array;ds="";function debug(s){ds+=s+"\n"}function updateSelects(state,matchCount){try{if(matchCount<=1&&state==true)state=false;if(matchCount==0)state=false}catch(e){}}
function DivSetVisible(state,matchCount){var DivRef=document.getElementById("PopupDiv");if(state){DivRef.style.left=0;DivRef.style.top=0;DivRef.style.visibility="visible";DivRef.style.display="block"}else{DivRef.style.visibility="hidden";DivRef.style.display="none"}updateSelects(state,matchCount)}
function ClearAutoFillRestSearch(){var txtAutoFill=document.getElementById(m_stheRestFinderCtrlID);if(hdnAutoFillDefault==null)hdnAutoFillDefault=document.getElementById(m_sAutoFillDefaultCtrlID);if(txtAutoFill==null)return;if(txtAutoFill.value==hdnAutoFillDefault.value){txtAutoFill.value="";m_bAutoFillAllRestSelected=false}ClearAFRestSearchABRecipeB(txtAutoFill)}
function ClearAFRestSearchABRecipeB(eAutofillControl){try{if(typeof m_oCurrentSearchModuleABRecipe!="undefined"&&m_oCurrentSearchModuleABRecipe==SearchModuleABRecipes.RecipeB){var hdnAutoFillAllValue=document.getElementById(m_sAutoFillAllValueCtrlID);if(m_bAutoFillAllRestSelected==false&&hdnAutoFillAllValue!=null&&eAutofillControl.value==hdnAutoFillAllValue.value){eAutofillControl.value="";m_bAutoFillAllRestSelected=false;eAutofillControl.removeClassName("GrayText")}}}catch(e){}};

