1 function AutoComplete(TextInputID
,AllowMultipleChoices
){this.TimeOut
=-1;this.MouseSupport
=true;if(AllowMultipleChoices
){this.Delimiter
=new Array(";",",")}else{this.Delimiter
=new Array("")}this.StartCharacter
=1;this.KeywordSourceUrl
="autocomplete.php?Search=";this.ResultContainerClass
="AutoCompleteContainer";this.StandardRowClass
="AutoCompleteRow";this.HoverRowClass
="AutoCompleteHoverRow";this.TableID
="AutoCompleteTable";var _DelimWords
=new Array();var _CDelimWord
=0;var _DelimChar
=new Array();var _Display
=false;var _Pos
=0;var _Total
=0;var _Curr
=null;var _RangeU
=0;var _RangeD
=0;var _Bool
=new Array();var _Pre
=0;var _ToId
;var _ToMake
=false;var _GetPre
="";var _MouseOnList
=1;var _KWCount
=0;var _CaretMove
=false;this._Keywords
=new Array();var _Self
=this;_Curr
=null;_Curr
=document
.getElementById(TextInputID
);if(_Curr
){addEvent(_Curr
,"focus",SetupEvents
);_Curr
.setAttribute("autocomplete","off")}function SetupEvents(){addEvent(document
,"keydown",CheckKey
);addEvent(_Curr
,"blur",ClearEvents
);addEvent(document
,"keypress",KeyPress
)}function ClearEvents(evt
){if(!evt
){evt
=event
}removeEvent(document
,"keydown",CheckKey
);removeEvent(_Curr
,"blur",ClearEvents
);removeEvent(document
,"keypress",KeyPress
);RemoveAutocomplete()}function GenerateItems(Request
){_Self
._Keywords
=Request
.responseText
.split(",");_KWCount
=_Self
._Keywords
.length
;if(_KWCount
==1&&_Self
._Keywords
[0]==""){_KWCount
=0;_Self
._Keywords
=new Array()}_Total
=_KWCount
;if(document
.getElementById(_Self
.TableID
)){_Display
=false;document
.body
.removeChild(document
.getElementById(_Self
.TableID
))}if(document
.getElementById(_Self
.TableID
+"_iefix")){document
.body
.removeChild(document
.getElementById(_Self
.TableID
+"_iefix"))}if(_KWCount
==0){_MouseOnList
=0;RemoveAutocomplete();return }a
=document
.createElement("table");a
.className
=_Self
.ResultContainerClass
;a
.style
.position
="absolute";a
.style
.top
=eval(curTop(_Curr
)+_Curr
.offsetHeight
)+"px";a
.style
.left
=curLeft(_Curr
)+"px";a
.id
=_Self
.TableID
;a
.cellPadding
="0";a
.cellSpacing
="0";a
.style
.zIndex
="200";document
.body
.appendChild(a
);var i
;var first
=true;var j
=1;if(_Self
.MouseSupport
){a
.onmouseout
=TableBlur
;a
.onmouseover
=TableFocus
}var counter
=0;for(i
=0;i
<_Self
._Keywords
.length
;i
++){counter
++;r
=a
.insertRow(-1);if(first
&&!_ToMake
){r
.className
=_Self
.HoverRowClass
;first
=false;_Pos
=counter
}else{if(_Pre
==i
){r
.className
=_Self
.HoverRowClass
;first
=false;_Pos
=counter
}else{r
.className
=_Self
.StandardRowClass
}}r
.id
="tat_tr"+(j
);c
=r
.insertCell(-1);c
.innerHTML
=_Self
._Keywords
[i
];c
.id
="tat_td"+(j
);c
.setAttribute("pos",j
);if(_Self
.MouseSupport
){c
.onmousedown
=MouseClick
;c
.onmouseover
=TableHighlight
}j
++}_RangeU
=1;_RangeD
=j
-1;_Display
=true;if(_Pos
<=0){_Pos
=1}if(document
.body
.insertAdjacentHTML
&&navigator
.userAgent
.indexOf("Opera")==-1){document
.body
.insertAdjacentHTML("beforeEnd",'<iframe id="'+a
.id
+'_iefix" style="position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);top:'+a
.style
.top
+";left:"+a
.style
.left
+";width:"+a
.offsetWidth
+"px;height:"+a
.offsetHeight
+'px;z-index:100;border:0;" src="javascript:false;" frameborder="0" scrolling="no"></iframe>')}}function GoUp(){if(!_Display
){return }if(_Pos
==1){return }document
.getElementById("tat_tr"+_Pos
).className
=_Self
.StandardRowClass
;_Pos
--;document
.getElementById("tat_tr"+_Pos
).className
=_Self
.HoverRowClass
;if(_ToId
){clearTimeout(_ToId
)}if(_Self
.TimeOut
>0){_ToId
=setTimeout(function(){_MouseOnList
=0;RemoveAutocomplete()},_Self
.TimeOut
)}}function GoDown(){if(!_Display
){return }if(_Pos
==_Total
){return }document
.getElementById("tat_tr"+_Pos
).className
=_Self
.StandardRowClass
;_Pos
++;document
.getElementById("tat_tr"+_Pos
).className
=_Self
.HoverRowClass
;if(_ToId
){clearTimeout(_ToId
)}if(_Self
.TimeOut
>0){_ToId
=setTimeout(function(){_MouseOnList
=0;RemoveAutocomplete()},_Self
.TimeOut
)}}function MouseClick(evt
){if(!evt
){evt
=event
}if(!_Display
){return }_MouseOnList
=0;_Pos
=this.getAttribute("pos");PressEnter()}function TableFocus(){_MouseOnList
=1}function TableBlur(){_MouseOnList
=0;if(_ToId
){clearTimeout(_ToId
)}if(_Self
.TimeOut
>0){_ToId
=setTimeout(function(){_MouseOnList
=0;RemoveAutocomplete()},_Self
.TimeOut
)}}function TableHighlight(){_MouseOnList
=1;document
.getElementById("tat_tr"+_Pos
).className
=_Self
.StandardRowClass
;_Pos
=this.getAttribute("pos");document
.getElementById("tat_tr"+_Pos
).className
=_Self
.HoverRowClass
;if(_ToId
){clearTimeout(_ToId
)}if(_Self
.TimeOut
>0){_ToId
=setTimeout(function(){_MouseOnList
=0;RemoveAutocomplete()},_Self
.TimeOut
)}}function InsertWord(a
){if(_Self
.Delimiter
.length
>0){str
="";l
=0;for(i
=0;i
<_DelimWords
.length
;i
++){if(_CDelimWord
==i
){prespace
=postspace
="";gotbreak
=false;for(j
=0;j
<_DelimWords
[i
].length
;++j
){if(_DelimWords
[i
].charAt(j
)!=" "){gotbreak
=true;break}prespace
+=" "}for(j
=_DelimWords
[i
].length
-1;j
>=0;--j
){if(_DelimWords
[i
].charAt(j
)!=" "){break}postspace
+=" "}str
+=prespace
;str
+=a
;l
=str
.length
;if(gotbreak
){str
+=postspace
}}else{str
+=_DelimWords
[i
]}if(i
!=_DelimWords
.length
-1){str
+=_DelimChar
[i
]}}_Curr
.value
=str
;setCaret(_Curr
,l
)}else{_Curr
.value
=a
}_MouseOnList
=0;RemoveAutocomplete()}function PressEnter(){if(!_Display
){return }_Display
=false;var word
=_Self
._Keywords
[_Pos
-1];InsertWord(word
);l
=getCaretStart(_Curr
);_Curr
.focus()}function RemoveAutocomplete(){_Display
=0;if(document
.getElementById(_Self
.TableID
)){document
.body
.removeChild(document
.getElementById(_Self
.TableID
))}if(document
.getElementById(_Self
.TableID
+"_iefix")){document
.body
.removeChild(document
.getElementById(_Self
.TableID
+"_iefix"))}if(_ToId
){clearTimeout(_ToId
)}}function KeyPress(e
){if(_CaretMove
&&_Curr
.id
==getTargetElement(e
).id
){stopEvent(e
)}return !_CaretMove
}function CheckKey(evt
){if(!evt
){evt
=event
}if(_Curr
.id
!=getTargetElement(evt
).id
){return }a
=evt
.keyCode
;caret_pos_start
=getCaretStart(_Curr
);_CaretMove
=0;switch(a
){case 38:GoUp();_CaretMove
=1;return false;break;case 40:GoDown();_CaretMove
=1;return false;break;case 13:case 9:if(_Display
){_CaretMove
=1;PressEnter();return false}else{return true}break;default:setTimeout(function(){GetItems(a
)},1000);break}}function GetItems(kc
){if(kc
==38||kc
==40||kc
==13||kc
==9){return }var i
;if(_Display
){var word
=0;var c
=0;for(var i
=0;i
<=_Self
._Keywords
.length
;i
++){if(_Bool
[i
]){c
++}if(c
==_Pos
){word
=i
;break}}_Pre
=word
}else{_Pre
=-1}if(_Curr
.value
==""){_MouseOnList
=0;RemoveAutocomplete();return }if(_Self
.Delimiter
.length
>0){caret_pos_start
=getCaretStart(_Curr
);caret_pos_end
=getCaretEnd(_Curr
);delim_split
="";for(i
=0;i
<_Self
.Delimiter
.length
;i
++){delim_split
+=_Self
.Delimiter
[i
]}if(delim_split
==""){delim_split
="##void##"}delim_split
=delim_split
.addslashes();delim_split_rx
=new RegExp("("+delim_split
+")");c
=0;_DelimWords
=new Array();_DelimWords
[0]="";for(i
=0,j
=_Curr
.value
.length
;i
<_Curr
.value
.length
;i
++,j
--){if(_Curr
.value
.substr(i
,j
).search(delim_split_rx
)==0){ma
=_Curr
.value
.substr(i
,j
).match(delim_split_rx
);_DelimChar
[c
]=ma
[1];c
++;_DelimWords
[c
]=""}else{_DelimWords
[c
]+=_Curr
.value
.charAt(i
)}}var l
=0;_CDelimWord
=-1;for(i
=0;i
<_DelimWords
.length
;i
++){if(caret_pos_end
>=l
&&caret_pos_end
<=l
+_DelimWords
[i
].length
){_CDelimWord
=i
}l
+=_DelimWords
[i
].length
+1}var ot
=_DelimWords
[_CDelimWord
].trim();var t
=_DelimWords
[_CDelimWord
].addslashes().trim()}else{var ot
=_Curr
.value
;var t
=_Curr
.value
.addslashes()}if(ot
.length
==0){_MouseOnList
=0;RemoveAutocomplete()}if(ot
.length
<_Self
.StartCharacter
){return this}var dm
=new DataManager();dm
.RequestCompleteEvent
=GenerateItems
;dm
.RequestFailedEvent
=HandleFailure
;dm
.LoadData(_Self
.KeywordSourceUrl
+escape(t
))}function HandleFailure(Request
){HideResults()}function HideResults(){_MouseOnList
=0;RemoveAutocomplete()}}function addEvent(C
,B
,A
){if(C
.attachEvent
){C
.attachEvent("on"+B
,A
)}else{if(C
.addEventListener
){C
.addEventListener(B
,A
,true)}else{C
["on"+B
]=A
}}}function removeEvent(C
,B
,A
){if(C
.detachEvent
){C
.detachEvent("on"+B
,A
)}else{if(C
.removeEventListener
){C
.removeEventListener(B
,A
,true)}else{C
["on"+B
]=null}}}function stopEvent(A
){A
||window
.event
;if(A
.stopPropagation
){A
.stopPropagation();A
.preventDefault()}else{if(typeof A
.cancelBubble
!="undefined"){A
.cancelBubble
=true;A
.returnValue
=false}}return false}function getElement(A
){if(window
.event
){return window
.event
.srcElement
}else{return A
.currentTarget
}}function getTargetElement(A
){if(window
.event
){return window
.event
.srcElement
}else{return A
.target
}}function stopSelect(A
){if(typeof A
.onselectstart
!="undefined"){addEvent(A
,"selectstart",function(){return false})}}function getCaretEnd(D
){if(typeof D
.selectionEnd
!="undefined"){return D
.selectionEnd
}else{if(document
.selection
&&document
.selection
.createRange
){var E
=document
.selection
.createRange();try{var A
=E
.duplicate();A
.moveToElementText(D
)}catch(C
){var A
=D
.createTextRange()}A
.setEndPoint("EndToEnd",E
);var B
=A
.text
.length
;if(B
>D
.value
.length
){return -1}return B
}}}function getCaretStart(D
){if(typeof D
.selectionStart
!="undefined"){return D
.selectionStart
}else{if(document
.selection
&&document
.selection
.createRange
){var E
=document
.selection
.createRange();try{var A
=E
.duplicate();A
.moveToElementText(D
)}catch(C
){var A
=D
.createTextRange()}A
.setEndPoint("EndToStart",E
);var B
=A
.text
.length
;if(B
>D
.value
.length
){return -1}return B
}}}function setCaret(B
,A
){B
.focus();if(B
.setSelectionRange
){B
.setSelectionRange(A
,A
)}else{if(B
.createTextRange
){m
=B
.createTextRange();m
.moveStart("character",A
);m
.collapse();m
.select()}}}function setSelection(C
,A
,B
){C
.focus();if(C
.setSelectionRange
){C
.setSelectionRange(A
,B
)}else{if(C
.createTextRange
){m
=C
.createTextRange();m
.moveStart("character",A
);m
.moveEnd("character",B
);m
.select()}}}String
.prototype.addslashes=function(){return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g,"\\$1")};String.prototype.trim=function(){return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1")};function curTop(A){toreturn=0;while(A){toreturn+=A.offsetTop;A=A.offsetParent}return toreturn}function curLeft(A){toreturn=0;while(A){toreturn+=A.offsetLeft;A=A.offsetParent}return toreturn}function isNumber(A){return typeof A=="number
"&&isFinite(A)}function replaceHTML(A,B){while(el=A.childNodes[0]){A.removeChild(el)}A.appendChild(document.createTextNode(B))};