function debug(a){ds+=a+"\n"}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}}}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("Gecko/200")!=-1;this.isSafari=navigator.userAgent.indexOf("Safari")!=-1;this.isWinIE=navigator.userAgent.indexOf("Win")!=-1&&navigator.userAgent.indexOf("MSIE")!=-1;this.showCredit=false}function activateCurrentSmartInputMatch(){baseValue=getUserInputBase();if((selIndex=getCurrentlySelectedSmartInputItem())!=null){addedValue=siw.matchCollection[selIndex].cleanValue;theString=(baseValue?baseValue:"")+addedValue+", ";siw.inputBox.value=theString;runMatchingLogic(addedValue,true)}}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 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 deSelectSmartInputMatchItem(a){siw.matchCollection[a].isSelected=false}function selectSmartInputMatchItem(a){siw.matchCollection[a].isSelected=true}function getCurrentlySelectedSmartInputItem(){answer=null;for(i=0;i<siw.matchCollection.length&&!answer;i++){if(siw.matchCollection[i].isSelected)answer=i}return answer}function getIndexFromElement(a){index=0;while(a=a.previousSibling){index++}return index}function selectFromMouseClick(){activateCurrentSmartInputMatch();siw.inputBox.focus();hideSmartInputFloater()}function selectFromMouseOver(a){currentIndex=getCurrentlySelectedSmartInputItem();if(currentIndex!=null)deSelectSmartInputMatchItem(currentIndex);newIndex=getIndexFromElement(a);selectSmartInputMatchItem(newIndex);modifySmartInputBoxContent(getSmartInputBoxContent())}function modifySmartInputBoxContent(a){siw.floaterContent.innerHTML='<div id="smartInputResults">'+a+(siw.showCredit?'<p class="siwCredit">Powered By: <a target="PhrawgBlog" href="http://chrisholland.blogspot.com/?from=smartinput&ref='+escape(location.href)+'">Chris Holland</a></p>':"")+"</div>";siw.matchListDisplay=document.getElementById("smartInputResults")}function getSmartInputBoxContent(){a=null;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,"<").replace(/\} */gi,">")+"</p>"}}return a}function setSmartInputData(){if(siw){orgUserInput=siw.inputBox.value;orgUserInput=getUserInputToMatch(orgUserInput);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 runMatchingLogic(a,b){a=simplify(a);uifc=a.charAt(0).toLowerCase();if(uifc=='"')uifc=(n=a.charAt(1))?n.toLowerCase():"z";if(b)a=uifc;if(siw)siw.matchCollection=new Array;pointerToCollectionToUse=collection;if(siw&&siw.revisedCollection&&siw.revisedCollection.length>0&&siw.lastUserInput&&a.indexOf(siw.lastUserInput)==0){pointerToCollectionToUse=siw.revisedCollection}else if(collectionIndex[a]&&collectionIndex[a].length>0){pointerToCollectionToUse=collectionIndex[a]}else if(collectionIndex[uifc]&&collectionIndex[uifc].length>0){pointerToCollectionToUse=collectionIndex[uifc]}else if(siw&&a.length==1&&!collectionIndex[uifc]){siw.buildIndex=true}else if(siw){siw.buildIndex=false}tempCollection=new Array;re1m=new RegExp('^([ "><-]*)('+a+")","i");re2m=new RegExp('([ "><-]+)('+a+")","i");re1=new RegExp('^([ "}{-]*)('+a+")","gi");re2=new RegExp('([ "}{-]+)('+a+")","gi");for(i=0,j=0;i<pointerToCollectionToUse.length;i++){displayMatches=!b&&j<siw.MAX_MATCHES;entry=pointerToCollectionToUse[i];mEntry=simplify(entry);if(!b&&mEntry.indexOf(a)==0){a=a.replace(/\>/gi,"\\}").replace(/\< ?/gi,"\\{");re=new RegExp("("+a+")","i");if(displayMatches){siw.matchCollection[j]=new smartInputMatch(entry,mEntry.replace(/\>/gi,"}").replace(/\< ?/gi,"{").replace(re,"<b>$1</b>"))}tempCollection[j]=entry;j++}else if(mEntry.match(re1m)||mEntry.match(re2m)){if(!b&&displayMatches){siw.matchCollection[j]=new smartInputMatch(entry,mEntry.replace(/\>/gi,"}").replace(/\</gi,"{").replace(re1,"$1<b>$2</b>").replace(re2,"$1<b>$2</b>"))}tempCollection[j]=entry;j++}}if(siw){siw.lastUserInput=a;siw.revisedCollection=tempCollection.join(",").split(",");collectionIndex[a]=tempCollection.join(",").split(",")}if(b||siw.buildIndex){collectionIndex[uifc]=tempCollection.join(",").split(",");if(siw)siw.buildIndex=false}}function getUserInputBase(){s=siw.inputBox.value;a=s;if((lastComma=s.lastIndexOf(","))!=-1){a=a.replace(/^(.*\,[ \r\n\t\f\s]*).*$/i,"$1")}else a="";return a}function getUserInputToMatch(b){a=b;fields=b.split(",");if(fields.length>0)a=fields[fields.length-1];return a}function simplify(a){return a.toLowerCase().replace(/^[ \s\f\t\n\r]+/,"").replace(/[ \s\f\t\n\r]+$/,"")}function smartInputMatch(a,b){this.cleanValue=a;this.value=b;this.isSelected=false}function processSmartInput(a){if(!siw)siw=new smartInputWindow;siw.inputBox=a;classData=a.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();if(content){modifySmartInputBoxContent(content);showSmartInputFloater()}else hideSmartInputFloater()}function hideSmartInputFloater(){if(siw){siw.floater.style.display="none";siw.floater.style.visibility="hidden";siw=null}}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"}}function handleMouseOver(a){e=getEvent(a);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 handleClick(a){e2=getEvent(a);eL2=getEventElement(e2);if(siw&&siw.selectingSomething){selectFromMouseClick()}}function handleBlur(a){e=getEvent(a);eL=getEventElement(e);if(blurEl=isWithinNode(eL,null,"wickEnabled",null,null)){if(siw&&!siw.selectingSomething)hideSmartInputFloater()}}function handleFocus(a){e=getEvent(a);eL=getEventElement(e);if(focEl=isWithinNode(eL,null,"wickEnabled",null,null)){if(!siw||siw&&!siw.selectingSomething)processSmartInput(focEl)}}function handleKeyDown(a){e=getEvent(a);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 handleKeyPress(a){e=getEvent(a);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 findElementPosY(a){curtop=0;if(a.offsetParent){while(a.offsetParent){curtop+=a.offsetTop;a=a.offsetParent}}else if(a.y)curtop+=a.y;return curtop}function findElementPosX(a){curleft=0;if(a.offsetParent){while(a.offsetParent){curleft+=a.offsetLeft;a=a.offsetParent}}else if(a.x)curleft+=a.x;return curleft}function getEventElement(a){return a.srcElement?a.srcElement:a.target?a.target:a.currentTarget}function getEvent(a){return a?a:window.event}function isWithinNode(a,b,c,d,e){answer=false;te=a;while(te&&!answer){if(te.id&&te.id==b||te.className&&te.className==b+"Class"||!d&&c&&te.className&&te.className==c||!d&&c&&te.className&&te.className.indexOf(c)!=-1||d&&te.tagName&&te.tagName.toLowerCase()==d||e&&te==e){answer=te}else{te=te.parentNode}}return te}function freezeEvent(a){if(a.preventDefault)a.preventDefault();a.returnValue=false;a.cancelBubble=true;if(a.stopPropagation)a.stopPropagation();return false}siw=null;if(document.addEventListener){document.addEventListener("keydown",handleKeyDown,false);document.addEventListener("keyup",handleKeyPress,false);document.addEventListener("mouseup",handleClick,false);document.addEventListener("mouseover",handleMouseOver,false)}else{document.onkeydown=handleKeyDown;document.onkeyup=handleKeyPress;document.onmouseup=handleClick;document.onmouseover=handleMouseOver}registerSmartInputListeners();document.write('<table id="smartInputFloater" class="floater" cellpadding="0" cellspacing="0"><tr><td id="smartInputFloaterContent" nowrap="nowrap">'+"</td></tr></table>");for(x=0;x<collection.length;x++){collection[x]=collection[x].replace(/\,/gi,"")}collectionIndex=new Array;ds=""
