var g_LBL_ENTER_TO_SEARCH=1;var g_LBL_NO_MATCHES_FOUND=2;var g_SearchCutoff=10;var g_AutoCompletes={};var g_caretPos=-1;var TAB=9;var ESC=27;var KEYLEFT=37;var KEYUP=38;var KEYRIGHT=39;var KEYDN=40;var BACKSPACE=8;var SPACE=32;var DELETE=127;var SHIFT=16;var CTRL=17;var ENTER=13;var SPACE1=new RegExp("^\\s*|\\s*$","g");var SPACE2=new RegExp("\\s\\s+","g");var idCounter=0;function waitForResults(a){var b=g_AutoCompletes[a];if(b&&b.stillLoading){setTimeout(waitForResults,200)}else{if(b){b.siftList(b.inputText.toLowerCase())}}}function hideLabel(a){var d=g_AutoCompletes[a];var c=docGet(a);var b=docGet(a+"label");if(b==null){b=makeMsgLabel(a)}b.style.display="none";if(!d.addressBook){c.focus()}}function makeMsgLabel(a){var c=docMake("div");c.id=a+"label";var b=docGet("divjail");b.appendChild(c);return c}function promptIfNoMatch(a){var d=g_AutoCompletes[a];if(d&&d.stillLoading){setTimeout('promptIfNoMatch("'+me.elem.id+'")',500);return}var f=docGet("autosuggestContainer");if(f&&f.style.display!="none"){return}var c=docGet(a);var b=docGet(a+"label");if(b==null){b=makeMsgLabel(a)}var e=findPos(c);b.style.position="absolute";b.style.left=e.x+"px";b.style.top=(e.y-22)+"px";b.style.display="block";b.innerHTML=strtxt}function AS_setActivateAlways(){this.bActivateAlways=true}function AutoSuggest(f,e,a,g){if(!f){return}this.page=document.location.toString();var h=this;this.elem=f;this.addressBook=false;var k=this.elem.getAttribute("addressbook");if(ok(k)&&k=="true"){this.addressBook=true}f.setAttribute("autocomplete","off");this.elemlabel=docGet(f.id+"label");if(this.elemlabel==null||typeof(this.elemlabel)=="undefined"){this.elemlabel=makeMsgLabel(f.id)}if(!f.id){var c="autosuggest"+idCounter;idCounter++;f.id=c}this.bActivateAlways=false;this.setActivateAlways=AS_setActivateAlways;this.theform=e;this.suggesturl=a;this.activateFunction=g;this.selectedId=-1;this.stillLoading=false;this.noMatchLabel="No matches found.";this.noMatchTimeout=2000;this.timeoutCounter=0;this.localCache={};this.deadEnds={};this.requested={};this.inputText=null;this.eligible=new Array();this.visible=new Array();this.highlighted=-1;this.div=getDropDown(this.addressBook);var d=f.parentNode;while(d!=null){if(d.getAttribute){var b=d.getAttribute("closelink");if(b!=null){var j=parseInt(d.style.zIndex);if(!isNaN(j)){++j;this.div.style.zIndex=j;maxZ=++j}}}d=d.parentNode}this.lastResult=100;this.handleAjaxError=function(l){};this.ajaxAction=function(o){var n="";var m=h.suggesturl;var l=m.indexOf("?");h.lastStub=o.toLowerCase();if(l>-1){n=m.substring(l+1);m=m.substring(0,l);m=m+"?stub="+h.lastStub+"&"+n}else{m=m+"?stub="+h.lastStub}var m=m+"?stub="+h.lastStub;h.showLoading();http("GET",m,h.callback,null,h.handleAjaxError)};this.isDuplicate=function(m,n){for(var l in m){if(m[l]==n){return true}}return false};this.callback=function(m){h.hideLoading();if(m.length==0){h.deadEnds[h.inputText]=1;if(h.elemlabel){h.setLabel(g_LBL_NO_MATCHES_FOUND)}return}if(m.length<g_SearchCutoff){h.deadEnds[h.inputText]=1}while(h.eligible.length>0){h.eligible.splice(0,1)}while(h.visible.length>0){h.visible.splice(0,1)}if(m.length&&m.length>0){var n=0;for(n=0;n<m.length;n++){h.eligible[h.eligible.length]=m[n].itemid+"_"+m[n].fullname;h.visible[h.visible.length]=m[n].itemid+"_"+m[n].fullname}h.elemlabel.style.display="none"}h.lastResult=h.eligible.length;var p=h.inputText.substring(0,1).toLowerCase();if(!h.localCache[p]){var o=new Array();var n=0;for(n=0;n<h.eligible.length;n++){o[n]=h.eligible[n]}h.localCache[p]=o;if(h.eligible.length==0){return}}else{if(h.eligible.length>0){if(h.elemlabel){h.elemlabel.style.display="none"}var l=h.localCache[p];for(n=0;n<h.eligible.length;n++){if(!h.isDuplicate(l,h.eligible[n])){l[l.length]=h.eligible[n]}}h.localCache[p]=l;h.populateWithLocal(p)}else{if(h.elemlabel){h.setLabel(g_LBL_NO_MATCHES_FOUND)}}}if(!h.addressBook){h.siftList(h.inputText.toLowerCase())}else{h.siftList(getStub(h.elem))}if(!h.addressBook){h.elem.focus()}};this.populateWithLocal=function(n){while(h.eligible.length>0){h.eligible.splice(0,1)}while(h.visible.length>0){h.visible.splice(0,1)}var m=h.localCache[n.toLowerCase()];var l=0;for(l=0;l<m.length;l++){h.eligible[l]=m[l];h.visible[l]=m[l]}};this.siftList=function(u){if(h.stillLoading){setTimeout("waitForResults('"+h.elem.id+"')",200);return}var o=0;while(h.visible.length>0){h.visible.splice(0,1)}u=u.toLowerCase();h.eligible.sort(h.sortByWholeName);for(o=0;o<h.eligible.length;o++){var l=h.eligible[o];var q=l.split("_")[0];var v=l.split("_")[1];var t="";var m="";var s="";var r=v.split(" ");var n=v.toLowerCase().split(" ");t=r[0];if(r.length==2){s=r[1]}else{if(r.length==3){m=r[1];s=r[2]}}if(t.toLowerCase().indexOf(u)==0||s.toLowerCase().indexOf(u)==0||m.toLowerCase().indexOf(u)==0||v.toLowerCase().indexOf(u)==0){var p=h.eligible[o];p=h.tagName(p);h.visible[h.visible.length]=p}else{if(v.toLowerCase().indexOf("&lt;")>-1){if((t.toLowerCase().indexOf("&lt;")==0&&t.toLowerCase().indexOf(u)==4)||(s.toLowerCase().indexOf("&lt;")==0&&s.toLowerCase().indexOf(u)==4)){var p=h.eligible[o];p=h.tagName(p);h.visible[h.visible.length]=p}}}}h.visible.sort(h.sortByWholeName);h.createDiv();h.positionDiv();if(h.visible.length>0){h.showDiv();h.changeHighlight(-1)}else{h.hideDiv();if(h.elemlabel){h.setLabel(g_LBL_NO_MATCHES_FOUND)}}};f.onclick=function(l){if(!h.addressBook){f.value=""}};f.onfocus=function(l){var m=docGet(f.id+"label");m.style.display="none"};f.onkeydown=function(m){var l=h.getKeyCode(m);switch(l){case ENTER:if(h.stillLoading){break}h.useSuggestion();h.hideDiv();if(!h.addressBook){f.blur()}break;case DELETE:case BACKSPACE:if(h.elemlabel){h.elemlabel.style.display="none"}h.lastResult=100;break;case TAB:if(h.elem.value!=""){h.useSuggestion()}break;case ESC:h.hideDiv();break;case KEYUP:if(h.addressBook&&h.div.prototype.style.display=="none"&&h.visible.length>0){return}if(h.div.prototype.style.display=="none"&&h.visible.length>0){h.showDiv()}if(h.div.prototype.style.display=="block"){if(h.highlighted>0){h.highlighted--}h.changeHighlight(l);return false}break;case KEYDN:if(h.addressBook&&h.div.prototype.style.display=="none"&&h.visible.length>0){return}if(h.div.prototype.style.display=="none"&&h.visible.length>0){h.showDiv()}if(h.highlighted<(h.visible.length-1)){h.highlighted++}h.changeHighlight(l);return false;break;default:break}};f.onkeyup=function(n){var m=h.getKeyCode(n);switch(m){case KEYUP:case KEYDN:case KEYLEFT:case KEYRIGHT:case TAB:case ENTER:case ESC:case DELETE:return;default:var l="";if(!h.addressBook){l=this.value}else{l=getStub(this)}if(l.length>0){h.inputText=l.toLowerCase();if(h.inputText.length==1&&h.localCache[h.inputText]){h.populateWithLocal(h.inputText);h.lastResult=h.eligible.length;h.siftList(h.inputText.toLowerCase())}else{if(h.requested[h.inputText]==null&&!h.deadEnd()&&h.inputText.length<g_SearchCutoff){h.requested[h.inputText]=1;h.ajaxAction(h.inputText)}else{h.siftList(h.inputText.toLowerCase())}}h.selectedId=-1}else{h.hideDiv()}}};this.deadEnd=function(){var l=h.inputText;for(var m=l.length-1;m>0;m--){if(h.deadEnds[l.substring(0,m)]!=null){return true}}return false};this.useSuggestion=function(){var q=-1;if(this.highlighted>-1){q=this.highlighted}else{q=0}if(this.visible.length>0){var n=this.visible[q];var r=n.substring(0,n.indexOf("_"));n=n.substring(n.indexOf("_")+1);while(n.indexOf("&lt;")>-1){n=n.replace("&lt;","<")}while(n.indexOf("&gt;")>-1){n=n.replace("&gt;",">")}while(n.indexOf("<b>")>-1){n=n.replace("<b>","")}while(n.indexOf("</b>")>-1){n=n.replace("</b>","")}if(h.addressBook&&n.indexOf("FameBuddy")==-1&&n.indexOf("FACEBOOK")==-1&&n.indexOf("<")>0){n='"'+n.replace(" <",'" <')}if(h.selectedId==-1&&r>-1){if(h.addressBook){n=n+",";var m=getCaretPos(this.elem);m-=h.inputText.length;var s=this.elem.value.substring(0,m);var o=this.elem.value.substring(m+h.inputText.length);this.elem.value=s+" "+n+o;setCaretPos(this.elem,m+n.length+1)}else{this.elem.value=n}h.selectedId=r;h.activateFunction(h.selectedId,this.elem.value,this.elem.id)}this.hideDiv();if(!h.addressBook){setTimeout("docGet('"+this.elem.id+"').focus()",0)}}else{if(h.bActivateAlways){h.activateFunction(-1,this.elem.value,this.elem.id);var p=h.inputText.substring(0,1).toLowerCase();var l=h.localCache[p];if(!l){l=new Array()}l[l.length]="-1_"+this.elem.value;h.localCache[p]=l}else{h.ajaxAction(h.inputText);h.selectedId=-1;this.hideDiv()}}};this.showDiv=function(){if(this.visible.length>0){this.div.prototype.style.display="block"}};this.hideDiv=function(){this.div.prototype.style.display="none";this.highlighted=-1};this.changeHighlight=function(){var m=this.div.getElementsByTagName("LI");for(i in m){var l=m[i];if(this.highlighted==i){if(l){l.className="selected"}}else{if(l){l.className=""}}}};this.positionDiv=function(){var m=this.elem;var l=0;var o=m.offsetHeight;while(m.offsetParent&&m.tagName.toUpperCase()!="BODY"){l+=m.offsetLeft;o+=m.offsetTop;m=m.offsetParent}l+=m.offsetLeft;o+=m.offsetTop;if(browser.isIE&&browser.version<7){o+=10;l+=5;this.div.prototype.style.backgroundColor="#eeeeee"}var n=findPos(f);l=n.x;o=n.y;if(this.elem.id=="searchbox"){o+=40;if(this.page.indexOf("Home.do")>-1){l-=120}}if(this.addressBook){o+=50}this.div.prototype.style.left=l+"px";this.div.prototype.style.top=o+"px"};this.createDiv=function(){var p=docMake("ul");for(var o=0;o<this.visible.length;o++){var n=this.visible[o].toString();var l=docMake("li");var m=docMake("a");m.href="javascript:void(0)";m.innerHTML=n.substring(n.indexOf("_")+1);l.appendChild(m);if(h.highlighted==o){l.className="selected"}p.appendChild(l)}this.div.replaceChild(p,this.div.childNodes[0]);p.onmouseover=function(s){var t=h.getEventSource(s);while(t.parentNode&&t.tagName.toUpperCase()!="LI"){t=t.parentNode}var r=h.div.getElementsByTagName("LI");for(o in r){var q=r[o];if(q==t){h.highlighted=o;break}}h.changeHighlight()};p.onclick=function(q){h.useSuggestion();h.hideDiv();h.cancelEvent(q);return false}};this.getKeyCode=function(l){if(l){return l.keyCode}if(window.event){return window.event.keyCode}};this.getEventSource=function(l){if(l){return l.target}if(window.event){return window.event.srcElement}};this.cancelEvent=function(l){if(l){l.preventDefault();l.stopPropagation()}if(window.event){window.event.returnValue=false}};this.sortByWholeName=function(q,o){var s=q.split("_")[1];s=s.replace("<b>","");s=s.replace("</b>","");var n="";var p=h.inputText.toLowerCase();if(s.indexOf(" ")>-1){n=s.substring(s.lastIndexOf(" ")+1).toLowerCase()}var r=s.substring(0,s.lastIndexOf(" ")).toLowerCase();var m=o.split("_")[1];m=m.replace("<b>","");m=m.replace("</b>","");var t="";if(m.indexOf(" ")>-1){t=m.substring(m.lastIndexOf(" ")+1).toLowerCase()}var l=m.substring(0,m.lastIndexOf(" ")).toLowerCase();if(r.indexOf(p)==0&&l.indexOf(p)!=0&&t.indexOf(p==0)){if(r>t){return 1}if(r<t){return -1}return 0}else{if(r.indexOf(p)!=0&&l.indexOf(p)==0&&n.indexOf(p==0)){if(n>l){return 1}if(n<l){return -1}return 0}}if(s.indexOf(p)==0&&m.indexOf(p)==0){if(r>l){return 1}if(r<l){return -1}return 0}else{if(n.indexOf(p)==0&&t.indexOf(p)==0){if(n>t){return 1}if(n<t){return -1}return 0}else{if(r.indexOf(p)==0&&l.indexOf(p)==0){if(r>l){return 1}if(r<l){return -1}return 0}}}return 0};this.setLabel=function(o){var m="";var n="";var l="";if(o==g_LBL_ENTER_TO_SEARCH){l="fb-bdy small suggestion_label";strtxt="hit enter to search";h.elemlabel.className=l;setTimeout('promptIfNoMatch("'+h.elem.id+'")',500);return}else{if(o==g_LBL_NO_MATCHES_FOUND){l="fb-bdy small suggestion_error";if(typeof(h.noMatchLabel)!="undefined"){strtxt=h.noMatchLabel}else{strtxt="No matches found."}h.elemlabel.className=l;if(!h.addressBook){f.value=""}if(strtxt!=""){if(h.elemlabel){var p=findPos(h.elem);h.elemlabel.style.position="absolute";if(this.elem.id=="searchbox"){if(this.page.indexOf("Home.do")>-1){p.x-=120}}h.elemlabel.style.left=p.x+"px";h.elemlabel.style.top=(p.y-22)+"px";h.elemlabel.style.display="block";h.elemlabel.innerHTML=strtxt}if(h.noMatchTimeout==0){h.noMatchTimeout=2000}setTimeout("hideLabel('"+f.id+"')",h.noMatchTimeout)}}}};this.tagName=function(w){var u=h.inputText;var n=u.toLowerCase();var s=w.split("_")[0];var l=w.split("_")[1];l=l.replace("  "," ");var m=l.toLowerCase();var z="";var A="";var x="";var r="";var B="";var v="";var o=false;var y=m.split(" ");var p=l.split(" ");if(p.length==1){r=p[0];z=y[0]}else{if(p.length==2){z=y[0];r=p[0];x=y[1];v=p[1]}else{if(p.length==3){z=y[0];r=p[0];A=y[1];B=p[1];x=y[2];v=p[2]}else{var D=1;var C=p.length-1;z=y[0];r=p[0];x=y[C];v=p[C];while(D<C){B+=p[D];if(D<C-1){B+=" "}D++}A=B}}}if(z!=""&&z.indexOf(n)==0&&z.indexOf("&lt;")==-1){r="<b>"+r.substring(0,u.length)+"</b>"+r.substring(u.length);o=true}if(A!=""&&A.indexOf(n)==0&&z.indexOf("&lt;")==-1){B="<b>"+B.substring(0,u.length)+"</b>"+B.substring(u.length);o=true}if(x!=""&&x.indexOf(n)==0&&x.indexOf("<")==-1&&x.indexOf("&lt;")==-1){v=v.substring(0,x.indexOf(n))+"<b>"+v.substring(x.indexOf(n),x.indexOf(n)+u.length)+"</b>"+v.substring(x.indexOf(n)+u.length);o=true}else{if(x!=""&&x.indexOf(n)>0&&(x.indexOf("<")>-1||x.indexOf("&lt;")>-1)){v=v.replace("<","&lt;");v=v.replace(">","&gt;");var t=x.replace("&lt;","").replace("&gt;","");if(t.indexOf(n)>-1){v=v.substring(0,(t.indexOf(n)+4))+"<b>"+v.substring(t.indexOf(n)+4,t.indexOf(n)+u.length+4)+"</b>"+v.substring(t.indexOf(n)+u.length+4)}}else{if(z!=""&&z.indexOf(n)>0&&(z.indexOf("<")>-1||z.indexOf("&lt;")>-1)){r=r.replace("<","&lt;");r=r.replace(">","&gt;");var q=z.replace("&lt;","").replace("&gt;","");if(q.indexOf(n)>-1){r=r.substring(0,(q.indexOf(n)+4))+"<b>"+r.substring(q.indexOf(n)+4,q.indexOf(n)+u.length+4)+"</b>"+r.substring(q.indexOf(n)+u.length+4)}}}}if(p.length==1){w=r}else{if(p.length==2){w=r+" "+v}else{w=r+" "+B+" "+v}}if(w.indexOf("<b>")==-1&&m.indexOf(n)==0){w="<b>"+w.substring(0,u.length)+"</b>"+w.substring(u.length)}w=s+"_"+w;return w};this.showLoading=function(){h.stillLoading=true;var l=docGet("imgAutocompleteLoading");if(!l){l=docMake("img");l.id="imgAutocompleteLoading";l.src="http://"+g_httpHost+"/images/loading-small.gif";l.style.position="absolute";document.body.appendChild(l)}var m=findPos(h.elem);l.style.top=m.y+"px";l.style.left=(m.x+100)+"px";l.style.display="block"};this.hideLoading=function(){h.stillLoading=false;var l=docGet("imgAutocompleteLoading");if(!l){return}l.style.display="none"};g_AutoCompletes[f.id]=this}function setCaretPos(c,a){c.focus();if(c.selectionStart||c.selectionStart=="0"){c.selectionStart=a;c.selectionEnd=a}else{var b=document.selection.createRange();b.move("character",a)}}function getCaretPos(e){var b=-1;if(document.selection){var f="\001";var d=document.selection.createRange();b=0;d.text=f;var a=d.duplicate();a.moveToElementText(e);b=(a.text.indexOf(f));if(b>-1){g_caretPos=b}d.moveStart("character",-1);d.text=""}else{if(e.selectionStart||e.selectionStart=="0"){b=e.selectionStart;if(b>-1){g_caretPos=b}}else{return -1}}if(b>-1){return b}else{return g_caretPos}}function getStub(d){var c=0;var b=getCaretPos(d);c=b;if(b==-1){return null}var e=d.value.substring(b,c);while(c<d.value.length){if(e.indexOf('"')<0&&e.indexOf(",")<0){c++}else{break}e=d.value.substring(b,c)}var a=e.replace(/\"+/g,"");a=a.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(a!=""){return null}while(b>0){if(e.indexOf(",")!=0){b--}else{break}e=d.value.substring(b,c)}var a=e.replace(/\"/g,"");a=a.replace(/\,/g,"");a=a.replace(/^\s\s*/,"").replace(/\s\s*$/,"");return a}function getDropDown(b){var d;if(b){d=docGet("abautosuggest")}else{d=docGet("autosuggest")}if(d!=null){return d}var a=docMake("div");a.id="autosuggestContainer";a.setAttribute("style","float:none");a.style.styleFloat="none";a.style.zIndex="1000";var h=docMake("div");var c=docMake("div");var g=docMake("div");if(b){g.id="abautosuggest"}else{g.id="autosuggest"}g.style.border="1px solid #dddddd";g.style.backgroundColor="white";g.style.height="100%";g.style.width="100%";g.style.overflow="hidden";c.className="shadowbox";h.className="outerpair2";h.style.width="100%";if(b){a.style.width="280px"}else{a.style.width="180px"}a.prototype=g;if(!browser.isIE||browser.version>7){a.className="outerpair1"}a.style.position="absolute";var e=docMake("ul");g.appendChild(e);g.prototype=a;g.className="suggestion_list";if(browser.isIE&&browser.version<7){a.appendChild(g)}else{c.appendChild(g);h.appendChild(c);a.appendChild(h)}var f=docGet("divjail");f.appendChild(a);f.style.zIndex=255;g.prototype.style.display="none";return g};