]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - themes/default/moacdropdown.js
No underscore for private function
[SourceForge/phpwiki.git] / themes / default / moacdropdown.js
1
2 function cBrowser(){var userAgent=navigator.userAgent.toLowerCase()
3 this.version=parseInt(navigator.appVersion)
4 this.subVersion=parseFloat(navigator.appVersion)
5 this.ns=((userAgent.indexOf('mozilla')!=-1)&&((userAgent.indexOf('spoofer')==-1)&&(userAgent.indexOf('compatible')==-1)))
6 this.ns2=(this.ns&&(this.version==2))
7 this.ns3=(this.ns&&(this.version==3))
8 this.ns4b=(this.ns&&(this.subVersion<4.04))
9 this.ns4=(this.ns&&(this.version==4))
10 this.ns5=(this.ns&&(this.version==5))
11 this.ie=(userAgent.indexOf('msie')!=-1)
12 this.ie3=(this.ie&&(this.version==2))
13 this.ie4=(this.ie&&(this.version==4)&&(userAgent.indexOf('msie 4.')!=-1))
14 this.ie5=(this.ie&&(this.version==4)&&(userAgent.indexOf('msie 5.0')!=-1))
15 this.ie55=(this.ie&&(this.version==4)&&(userAgent.indexOf('msie 5.5')!=-1))
16 this.ie6=(this.ie&&(this.version==4)&&(userAgent.indexOf('msie 6.0')!=-1))
17 this.op3=(userAgent.indexOf('opera')!=-1)
18 this.win=(userAgent.indexOf('win')!=-1)
19 this.mac=(userAgent.indexOf('mac')!=-1)
20 this.unix=(userAgent.indexOf('x11')!=-1)
21 this.name=navigator.appName
22 this.dom=this.ns5||this.ie5||this.ie55||this.ie6}
23 var bw=new cBrowser()
24 cDomEvent={e:null,type:'',button:0,key:0,x:0,y:0,pagex:0,pagey:0,target:null,from:null,to:null}
25 cDomEvent.init=function(e)
26 {if(window.event)e=window.event
27 this.e=e
28 this.type=e.type
29 this.button=(e.which)?e.which:e.button
30 this.key=(e.which)?e.which:e.keyCode
31 this.target=(e.srcElement)?e.srcElement:e.originalTarget
32 this.currentTarget=(e.currentTarget)?e.currentTarget:e.srcElement
33 this.from=(e.originalTarget)?e.originalTarget:(e.fromElement)?e.fromElement:null
34 this.to=(e.currentTarget)?e.currentTarget:(e.toElement)?e.toElement:null
35 this.x=(e.layerX)?e.layerX:(e.offsetX)?e.offsetX:null
36 this.y=(e.layerY)?e.layerY:(e.offsetY)?e.offsetY:null
37 this.screenX=e.screenX
38 this.screenY=e.screenY
39 this.pageX=(e.pageX)?e.pageX:e.x+document.body.scrollLeft
40 this.pageY=(e.pageY)?e.pageY:e.y+document.body.scrollTop}
41 cDomEvent.getEvent=function(e)
42 {if(window.event)e=window.event
43 return{e:e,type:e.type,button:(e.which)?e.which:e.button,key:(e.which)?e.which:e.keyCode,target:(e.srcElement)?e.srcElement:e.originalTarget,currentTarget:(e.currentTarget)?e.currentTarget:e.srcElement,from:(e.originalTarget)?e.originalTarget:(e.fromElement)?e.fromElement:null,to:(e.currentTarget)?e.currentTarget:(e.toElement)?e.toElement:null,x:(e.layerX)?e.layerX:(e.offsetX)?e.offsetX:null,y:(e.layerY)?e.layerY:(e.offsetY)?e.offsetY:null,screenX:e.screenX,screenY:e.screenY,pageX:(e.pageX)?e.pageX:(e.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)),pageY:(e.pageY)?e.pageY:(e.clientY+(document.documentElement.scrollTop||document.body.scrollTop))}}
44 cDomEvent.cancelEvent=function(e)
45 {if(e.preventDefault)
46 {e.preventDefault()}
47 e.returnValue=false
48 e.cancelBubble=true
49 return false}
50 cDomEvent.addEvent=function(hElement,sEvent,handler,bCapture)
51 {if(hElement.addEventListener)
52 {hElement.addEventListener(sEvent,handler,bCapture)
53 return true}
54 else if(hElement.attachEvent)
55 {return hElement.attachEvent('on'+sEvent,handler)}
56 else if(document.all||hElement.captureEvents)
57 {if(hElement.captureEvents)eval('hElement.captureEvents( Event.'+sEvent.toUpperCase()+' )')
58 eval('hElement.on'+sEvent+' = '+handler)}
59 else
60 {alert('Not implemented yet!')}}
61 cDomEvent.encapsulateEvent=function(hHandler)
62 {return function(hEvent)
63 {hEvent=cDomEvent.getEvent(hEvent)
64 hHandler.call(hEvent.target,hEvent.e)}}
65 cDomEvent.addEvent2=function(hElement,sEvent,handler,bCapture)
66 {if(hElement)
67 {if(hElement.addEventListener)
68 {hElement.addEventListener(sEvent,cDomEvent.encapsulateEvent(handler),bCapture)
69 return true}
70 else if(hElement.attachEvent)
71 {return hElement.attachEvent('on'+sEvent,cDomEvent.encapsulateEvent(handler))}
72 else
73 {alert('Not implemented yet!')}}
74 else
75 {}}
76 cDomEvent.addCustomEvent2=function(hElement,sEvent,handler)
77 {if(hElement)
78 {hElement[sEvent]=handler}
79 else
80 {}}
81 cDomEvent.removeEvent=function(hElement,sEvent,handler,bCapture)
82 {if(hElement.addEventListener)
83 {hElement.removeEventListener(sEvent,handler,bCapture)
84 return true}
85 else if(hElement.attachEvent)
86 {return hElement.detachEvent('on'+sEvent,handler)}
87 else if(document.all||hElement.captureEvents)
88 {eval('hElement.on'+sEvent+' = null')}
89 else
90 {alert('Not implemented yet!')}}
91 function MouseButton()
92 {if(document.layers)
93 {this.left=1
94 this.middle=2
95 this.right=3}
96 else if(document.all)
97 {this.left=1
98 this.middle=4
99 this.right=2}
100 else
101 {this.left=0
102 this.middle=1
103 this.right=2}}
104 var MB=new MouseButton()
105 if(document.ELEMENT_NODE==null)
106 {document.ELEMENT_NODE=1
107 document.TEXT_NODE=3}
108 function getSubNodeByName(hNode,sNodeName)
109 {if(hNode!=null)
110 {var nNc=0
111 var nC=0
112 var hNodeChildren=hNode.childNodes
113 var hCNode=null
114 while(nC<hNodeChildren.length)
115 {hCNode=hNodeChildren.item(nC++)
116 if((hCNode.nodeType==1)&&(hCNode.nodeName.toLowerCase()==sNodeName))
117 {return hCNode}}}
118 return null}
119 function getPrevNodeSibling(hNode)
120 {if(hNode!=null)
121 {do{hNode=hNode.previousSibling}while(hNode!=null&&hNode.nodeType!=1)
122 return hNode}}
123 function getNextNodeSibling(hNode)
124 {if(hNode!=null)
125 {do{hNode=hNode.nextSibling}while(hNode!=null&&hNode.nodeType!=1)
126 return hNode}}
127 function getLastSubNodeByName(hNode,sNodeName)
128 {if(hNode!=null)
129 {var nNc=0
130 var nC=0
131 var hNodeChildren=hNode.childNodes
132 var hCNode=null
133 var nLength=hNodeChildren.length-1
134 while(nLength>=0)
135 {hCNode=hNodeChildren.item(nLength)
136 if((hCNode.nodeType==1)&&(hCNode.nodeName.toLowerCase()==sNodeName))
137 {return hCNode}
138 nLength--}}
139 return null}
140 function getSubNodeByProperty(hNode,sProperty,sPropValue)
141 {if(hNode!=null)
142 {var nNc=0
143 var nC=0
144 var hNodeChildren=hNode.childNodes
145 var hCNode=null
146 var sAttribute
147 var hProp
148 sPropValue=sPropValue.toLowerCase()
149 while(nC<hNodeChildren.length)
150 {hCNode=hNodeChildren.item(nC++)
151 if(hCNode.nodeType==document.ELEMENT_NODE)
152 {hProp=eval('hCNode.'+sProperty)
153 if(typeof(sPropValue)!='undefined')
154 {if(hProp.toLowerCase()==sPropValue)
155 {return hCNode}}
156 else
157 {return hCNode}}
158 nNc++}}
159 return null}
160 function findAttribute(hNode,sAtt)
161 {sAtt=sAtt.toLowerCase()
162 for(var nI=0;nI<hNode.attributes.length;nI++)
163 {if(hNode.attributes.item(nI).nodeName.toLowerCase()==sAtt)
164 {return hNode.attributes.item(nI).nodeValue}}
165 return null}
166 function getSubNodeByAttribute(hNode,sAtt,sAttValue)
167 {if(hNode!=null)
168 {var nNc=0
169 var nC=0
170 var hNodeChildren=hNode.childNodes
171 var hCNode=null
172 var sAttribute
173 sAttValue=sAttValue.toLowerCase()
174 while(nC<hNodeChildren.length)
175 {hCNode=hNodeChildren.item(nC++)
176 if(hCNode.nodeType==document.ELEMENT_NODE)
177 {sAttribute=hCNode.getAttribute(sAtt)
178 if(sAttribute&&sAttribute.toLowerCase()==sAttValue)
179 return hCNode}
180 nNc++}}
181 return null}
182 function getLastSubNodeByAttribute(hNode,sAtt,sAttValue)
183 {if(hNode!=null)
184 {var nNc=0
185 var nC=0
186 var hNodeChildren=hNode.childNodes
187 var hCNode=null
188 var nLength=hNodeChildren.length-1
189 while(nLength>=0)
190 {hCNode=hNodeChildren.item(nLength)
191 if(hCNode.nodeType==document.ELEMENT_NODE)
192 {sAttribute=hCNode.getAttribute(sAtt)
193 if(sAttribute&&sAttribute.toLowerCase()==sAttValue)
194 return hCNode}
195 nLength--}}
196 return null}
197 function getParentByTagName(hNode,sParentTagName)
198 {while((hNode.tagName)&&!(/(body|html)/i.test(hNode.tagName)))
199 {if(hNode.tagName==sParentTagName)
200 {return hNode}
201 hNode=hNode.parentNode}
202 return null}
203 function getParentByAttribute(hNode,sAtt,sAttValue)
204 {while((hNode.tagName)&&!(/(body|html)/i.test(hNode.tagName)))
205 {var sAttr=hNode.getAttribute(sAtt)
206 if(sAttr!=null&&sAttr.toString().length>0)
207 {if(sAttValue!==null)
208 {if(sAttr==sAttValue)
209 {return hNode}}
210 else
211 {return hNode}}
212 hNode=hNode.parentNode}
213 return null}
214 function getParentByProperty(hNode,sProperty,sPropValue)
215 {while((hNode.tagName)&&!(/(body|html)/i.test(hNode.tagName)))
216 {var hProp=eval('hNode.'+sProperty)
217 if(hProp!=null&&hProp.toString().length>0)
218 {if(sPropValue!==null)
219 {if(hProp==sPropValue)
220 {return hNode}}
221 else
222 {return hNode}}
223 hNode=hNode.parentNode}
224 return null}
225 function getNodeText(hNode)
226 {if(hNode==null)
227 {return''}
228 var sRes
229 if(hNode.hasChildNodes())
230 {sRes=hNode.childNodes.item(0).nodeValue}
231 else
232 {sRes=hNode.text}
233 return sRes}
234 function cDomExtension(hParent,aSelectors,hInitFunction)
235 {this.hParent=hParent
236 this.aSelectors=aSelectors
237 this.hInitFunction=hInitFunction}
238 cDomExtensionManager={aExtensions:new Array()}
239 cDomExtensionManager.register=function(hDomExtension)
240 {cDomExtensionManager.aExtensions.push(hDomExtension)}
241 cDomExtensionManager.initSelector=function(hParent,sSelector,hInitFunction)
242 {var hSelectorRegEx
243 var hAttributeRegEx
244 var aSelectorData
245 var aAttributeData
246 var sAttribute
247 hSelectorRegEx=/([a-z0-9_]*)\[?([^\]]*)\]?/i
248 hAttributeRegEx=/([a-z0-9_]*)([\*\^\$]?)(=?)(([a-z0-9_=]*))/i
249 if(hSelectorRegEx.test(sSelector)&&!/[@#\.]/.test(sSelector))
250 {aSelectorData=hSelectorRegEx.exec(sSelector)
251 if(aSelectorData[1]!='')
252 {hGroup=hParent.getElementsByTagName(aSelectorData[1].toLowerCase())
253 for(nI=0;nI<hGroup.length;nI++)
254 {hGroup[nI].markExt=true}
255 for(nI=0;nI<hGroup.length;nI++)
256 {if(!hGroup[nI].markExt)
257 {continue}
258 else
259 {hGroup[nI].markExt=false}
260 if(aSelectorData[2]=='')
261 {if(hGroup[nI].tagName.toLowerCase()==aSelectorData[1].toLowerCase())
262 {hInitFunction(hGroup[nI])}}
263 else
264 {aAttributeData=hAttributeRegEx.exec(aSelectorData[2])
265 if(aAttributeData[1]=='class')
266 {sAttribute=hGroup[nI].className}
267 else
268 {sAttribute=hGroup[nI].getAttribute(aAttributeData[1])}
269 if(sAttribute!=null&&sAttribute.length>0)
270 {if(aAttributeData[3]=='=')
271 {if(aAttributeData[2]=='')
272 {if(sAttribute==aAttributeData[4])
273 {hInitFunction(hGroup[nI])}}
274 else
275 {switch(aAttributeData[2])
276 {case'^':if(sAttribute.indexOf(aAttributeData[4])==0)
277 {hInitFunction(hGroup[nI])}
278 break
279 case'$':if(sAttribute.lastIndexOf(aAttributeData[4])==sAttribute.length-aAttributeData[4].length)
280 {hInitFunction(hGroup[nI])}
281 break
282 case'*':if(sAttribute.indexOf(aAttributeData[4])>=0)
283 {hInitFunction(hGroup[nI])}
284 break}}}
285 else
286 {hInitFunction(hGroup[nI])}}}}
287 return}}
288 hSelectorRegEx=/([a-z0-9_]*)([\.#@]?)([a-z0-9_=~]*)/i
289 hAttributeRegEx=/([a-z0-9_]*)([=~])?([a-z0-9_]*)/i
290 aSelectorData=hSelectorRegEx.exec(sSelector)
291 if(aSelectorData[1]!='')
292 {var hGroup=hParent.getElementsByTagName(aSelectorData[1])
293 for(nI=0;nI<hGroup.length;nI++)
294 {hGroup[nI].markExt=true}
295 for(nI=0;nI<hGroup.length;nI++)
296 {if(!hGroup[nI].markExt)
297 {continue}
298 else
299 {hGroup[nI].markExt=false}
300 if(aSelectorData[2]!='')
301 {switch(aSelectorData[2])
302 {case'.':if(hGroup[nI].className==aSelectorData[3])
303 {hInitFunction(hGroup[nI])}
304 break
305 case'#':if(hGroup[nI].id==aSelectorData[3])
306 {hInitFunction(hGroup[nI])}
307 break
308 case'@':aAttributeData=hAttributeRegEx.exec(aSelectorData[3])
309 sAttribute=hGroup[nI].getAttribute(aAttributeData[1])
310 if(sAttribute!=null&&sAttribute.length>0)
311 {if(aAttributeData[3]!='')
312 {if(aAttributeData[2]=='=')
313 {if(sAttribute==aAttributeData[3])
314 {hInitFunction(hGroup[nI])}}
315 else
316 {if(sAttribute.indexOf(aAttributeData[3])>=0)
317 {hInitFunction(hGroup[nI])}}}
318 else
319 {hInitFunction(hGroup[nI])}}
320 break}}}}}
321 cDomExtensionManager.initialize=function()
322 {var hDomExtension=null
323 var aSelectors
324 for(var nKey in cDomExtensionManager.aExtensions)
325 {aSelectors=cDomExtensionManager.aExtensions[nKey].aSelectors
326 for(var nKey2 in aSelectors)
327 {cDomExtensionManager.initSelector(cDomExtensionManager.aExtensions[nKey].hParent,aSelectors[nKey2],cDomExtensionManager.aExtensions[nKey].hInitFunction)}}}
328 if(window.addEventListener)
329 {window.addEventListener('load',cDomExtensionManager.initialize,false)}
330 else if(window.attachEvent)
331 {window.attachEvent('onload',cDomExtensionManager.initialize)}
332 function cDomObject(sId)
333 {if(bw.dom||bw.ie)
334 {this.hElement=document.getElementById(sId)
335 this.hStyle=this.hElement.style}}
336 cDomObject.prototype.getWidth=function()
337 {return cDomObject.getWidth(this.hElement)}
338 cDomObject.getWidth=function(hElement)
339 {if(hElement.currentStyle)
340 {var nWidth=parseInt(hElement.currentStyle.width)
341 if(isNaN(nWidth))
342 {return parseInt(hElement.offsetWidth)}
343 else
344 {return nWidth}}
345 else
346 {return parseInt(hElement.offsetWidth)}}
347 cDomObject.prototype.getHeight=function()
348 {return cDomObject.getHeight(this.hElement)}
349 cDomObject.getHeight=function(hElement)
350 {if(hElement.currentStyle)
351 {var nHeight=parseInt(hElement.currentStyle.height)
352 if(isNaN(nHeight))
353 {return parseInt(hElement.offsetHeight)}
354 else
355 {return nHeight}}
356 else
357 {return parseInt(hElement.offsetHeight)}}
358 cDomObject.prototype.getLeft=function()
359 {return cDomObject.getLeft(this.hElement)}
360 cDomObject.getLeft=function(hElement)
361 {return parseInt(hElement.offsetLeft)}
362 cDomObject.prototype.getTop=function()
363 {return cDomObject.getTop(this.hElement)}
364 cDomObject.getTop=function(hElement)
365 {return parseInt(hElement.offsetTop)}
366 cDomObject.getOffsetParam=function(hElement,sParam,hLimitParent)
367 {var nRes=0
368 if(hLimitParent==null)
369 {hLimitParent=document.body.parentElement}
370 while(hElement!=hLimitParent)
371 {nRes+=eval('hElement.'+sParam)
372 if(!hElement.offsetParent){break}
373 hElement=hElement.offsetParent}
374 return nRes}
375 cDomObject.getScrollOffset=function(hElement,sParam,hLimitParent)
376 {nRes=0
377 if(hLimitParent==null)
378 {hLimitParent=document.body.parentElement}
379 while(hElement!=hLimitParent)
380 {nRes+=eval('hElement.scroll'+sParam)
381 if(!hElement.offsetParent){break}
382 hElement=hElement.parentNode}
383 return nRes}
384 function getDomDocumentPrefix(){if(getDomDocumentPrefix.prefix)
385 return getDomDocumentPrefix.prefix;var prefixes=["MSXML2","Microsoft","MSXML","MSXML3"];var o;for(var i=0;i<prefixes.length;i++){try{o=new ActiveXObject(prefixes[i]+".DomDocument");return getDomDocumentPrefix.prefix=prefixes[i];}
386 catch(ex){};}
387 throw new Error("Could not find an installed XML parser");}
388 function getXmlHttpPrefix(){if(getXmlHttpPrefix.prefix)
389 return getXmlHttpPrefix.prefix;var prefixes=["MSXML2","Microsoft","MSXML","MSXML3"];var o;for(var i=0;i<prefixes.length;i++){try{o=new ActiveXObject(prefixes[i]+".XmlHttp");return getXmlHttpPrefix.prefix=prefixes[i];}
390 catch(ex){};}
391 throw new Error("Could not find an installed XML parser");}
392 function XmlHttp(){}
393 XmlHttp.create=function(){try{if(window.XMLHttpRequest){var req=new XMLHttpRequest();if(req.readyState==null){req.readyState=1;req.addEventListener("load",function(){req.readyState=4;if(typeof req.onreadystatechange=="function")
394 req.onreadystatechange();},false);}
395 return req;}
396 if(window.ActiveXObject){return new ActiveXObject(getXmlHttpPrefix()+".XmlHttp");}}
397 catch(ex){}
398 throw new Error("Your browser does not support XmlHttp objects");};function XmlDocument(){}
399 XmlDocument.create=function(){try{if(document.implementation&&document.implementation.createDocument){var doc=document.implementation.createDocument("","",null);if(doc.readyState==null){doc.readyState=1;doc.addEventListener("load",function(){doc.readyState=4;if(typeof doc.onreadystatechange=="function")
400 doc.onreadystatechange();},false);}
401 return doc;}
402 if(window.ActiveXObject)
403 return new ActiveXObject(getDomDocumentPrefix()+".DomDocument");}
404 catch(ex){}
405 throw new Error("Your browser does not support XmlDocument objects");};if(window.DOMParser&&window.XMLSerializer&&window.Node&&Node.prototype&&Node.prototype.__defineGetter__){Document.prototype.loadXML=function(s){var doc2=(new DOMParser()).parseFromString(s,"text/xml");while(this.hasChildNodes())
406 this.removeChild(this.lastChild);for(var i=0;i<doc2.childNodes.length;i++){this.appendChild(this.importNode(doc2.childNodes[i],true));}};Document.prototype.__defineGetter__("xml",function(){return(new XMLSerializer()).serializeToString(this);});}
407 function cAutocomplete(sInputId)
408 {this.init(sInputId)}
409 var xmlrpc_url;cAutocomplete.CS_NAME='Autocomplete component'
410 cAutocomplete.CS_OBJ_NAME='AC_COMPONENT'
411 cAutocomplete.CS_LIST_PREFIX='ACL_'
412 cAutocomplete.CS_BUTTON_PREFIX='ACB_'
413 cAutocomplete.CS_INPUT_PREFIX='AC_'
414 cAutocomplete.CS_HIDDEN_INPUT_PREFIX='ACH_'
415 cAutocomplete.CS_INPUT_CLASSNAME='dropdown'
416 cAutocomplete.CB_AUTOINIT=true
417 cAutocomplete.CB_AUTOCOMPLETE=false
418 cAutocomplete.CB_FORCECORRECT=false
419 cAutocomplete.CB_MATCHSUBSTRING=false
420 cAutocomplete.CS_SEPARATOR=','
421 cAutocomplete.CS_ARRAY_SEPARATOR=','
422 cAutocomplete.CB_MATCHSTRINGBEGIN=true
423 cAutocomplete.CN_OFFSET_TOP=2
424 cAutocomplete.CN_OFFSET_LEFT=-1
425 cAutocomplete.CN_LINE_HEIGHT=19
426 cAutocomplete.CN_NUMBER_OF_LINES=10
427 cAutocomplete.CN_HEIGHT_FIX=2
428 cAutocomplete.CN_CLEAR_TIMEOUT=300
429 cAutocomplete.CN_SHOW_TIMEOUT=400
430 cAutocomplete.CN_REMOTE_SHOW_TIMEOUT=1000
431 cAutocomplete.CN_MARK_TIMEOUT=400
432 cAutocomplete.hListDisplayed=null
433 cAutocomplete.nCount=0
434 cAutocomplete.autoInit=function()
435 {var nI=0
436 var hACE=null
437 var sLangAtt
438 var nInputsLength=document.getElementsByTagName('INPUT').length
439 for(nI=0;nI<nInputsLength;nI++)
440 {if(document.getElementsByTagName('INPUT')[nI].type.toLowerCase()=='text')
441 {sLangAtt=document.getElementsByTagName('INPUT')[nI].getAttribute('acdropdown')
442 if(sLangAtt!=null&&sLangAtt.length>0)
443 {if(document.getElementsByTagName('INPUT')[nI].id==null||document.getElementsByTagName('INPUT')[nI].id.length==0)
444 {document.getElementsByTagName('INPUT')[nI].id=cAutocomplete.CS_OBJ_NAME+cAutocomplete.nCount}
445 hACE=new cAutocomplete(document.getElementsByTagName('INPUT')[nI].id)}}}
446 var nTALength=document.getElementsByTagName('TEXTAREA').length
447 for(nI=0;nI<nTALength;nI++)
448 {sLangAtt=document.getElementsByTagName('TEXTAREA')[nI].getAttribute('acdropdown')
449 if(sLangAtt!=null&&sLangAtt.length>0)
450 {if(document.getElementsByTagName('TEXTAREA')[nI].id==null||document.getElementsByTagName('TEXTAREA')[nI].id.length==0)
451 {document.getElementsByTagName('TEXTAREA')[nI].id=cAutocomplete.CS_OBJ_NAME+cAutocomplete.nCount}
452 hACE=new cAutocomplete(document.getElementsByTagName('TEXTAREA')[nI].id)}}
453 var nSelectsLength=document.getElementsByTagName('SELECT').length
454 var aSelect=null
455 for(nI=0;nI<nSelectsLength;nI++)
456 {aSelect=document.getElementsByTagName('SELECT')[nI]
457 sLangAtt=aSelect.getAttribute('acdropdown')
458 if(sLangAtt!=null&&sLangAtt.length>0)
459 {if(aSelect.id==null||aSelect.id.length==0)
460 {aSelect.id=cAutocomplete.CS_OBJ_NAME+cAutocomplete.nCount}
461 hACE=new cAutocomplete(aSelect.id)
462 nSelectsLength--
463 nI--}}}
464 if(cAutocomplete.CB_AUTOINIT)
465 {if(window.attachEvent)
466 {window.attachEvent('onload',cAutocomplete.autoInit)}
467 else if(window.addEventListener)
468 {window.addEventListener('load',cAutocomplete.autoInit,false)}}
469 cAutocomplete.prototype.init=function(sInputId)
470 {this.bDebug=false
471 this.sInputId=sInputId
472 this.sListId=cAutocomplete.CS_LIST_PREFIX+sInputId
473 this.sObjName=cAutocomplete.CS_OBJ_NAME+'_obj_'+(cAutocomplete.nCount++)
474 this.hObj=this.sObjName
475 this.hActiveSelection=null
476 this.nSelectedItemIdx=-1
477 this.sLastActiveValue=''
478 this.sActiveValue=''
479 this.bListDisplayed=false
480 this.nItemsDisplayed=0
481 this.bAssociative=true
482 this.sHiddenInputId=null
483 this.bHasButton=false
484 this.aData=null
485 this.aSearchData=new Array()
486 this.bSorted=false
487 this.nLastMatchLength=0
488 this.bForceCorrect=cAutocomplete.CB_FORCECORRECT
489 var sForceCorrect=document.getElementById(this.sInputId).getAttribute('autocomplete_forcecorrect')
490 if(sForceCorrect!=null&&sForceCorrect.length>0)
491 {this.bForceCorrect=eval(sForceCorrect)}
492 this.bMatchBegin=cAutocomplete.CB_MATCHSTRINGBEGIN
493 var sMatchBegin=document.getElementById(this.sInputId).getAttribute('autocomplete_matchbegin')
494 if(sMatchBegin!=null&&sMatchBegin.length>0)
495 {this.bMatchBegin=eval(sMatchBegin)}
496 this.bMatchSubstring=cAutocomplete.CB_MATCHSUBSTRING
497 var sMatchSubstring=document.getElementById(this.sInputId).getAttribute('autocomplete_matchsubstring')
498 if(sMatchSubstring!=null&&sMatchSubstring.length>0)
499 {this.bMatchSubstring=eval(sMatchSubstring)}
500 this.bAutoComplete=cAutocomplete.CB_AUTOCOMPLETE
501 this.bAutocompleted=false
502 var sAutoComplete=document.getElementById(this.sInputId).getAttribute('autocomplete_complete')
503 if(sAutoComplete!=null&&sAutoComplete.length>0)
504 {this.bAutoComplete=eval(sAutoComplete)}
505 this.formatOptions=null
506 var sFormatFunction=document.getElementById(this.sInputId).getAttribute('autocomplete_format')
507 if(sFormatFunction!=null&&sFormatFunction.length>0)
508 {this.formatOptions=eval(sFormatFunction)}
509 this.onSelect=null
510 var sOnSelectFunction=document.getElementById(this.sInputId).getAttribute('autocomplete_onselect')
511 if(sOnSelectFunction!=null&&sOnSelectFunction.length>0)
512 {this.onSelect=eval(sOnSelectFunction)}
513 if(this.getListArrayType()=='url'||this.getListArrayType()=='xmlrpc')
514 {this.bAssociative=false
515 this.bRemoteList=true
516 this.sListURL=this.getListURL()
517 this.hXMLHttp=XmlHttp.create()
518 this.bXMLRPC=(this.getListArrayType()=='xmlrpc')}
519 else
520 {this.bRemoteList=false}
521 var sAssociative=document.getElementById(this.sInputId).getAttribute('autocomplete_assoc')
522 if(sAssociative!=null&&sAssociative.length>0)
523 {this.bAssociative=eval(sAssociative)}
524 this.initListArray()
525 this.initListContainer()
526 this.initInput()
527 eval(this.hObj+'= this')}
528 cAutocomplete.prototype.initInput=function()
529 {var hInput=document.getElementById(this.sInputId)
530 hInput.hAutocomplete=this
531 var hContainer=document.getElementById(this.sListId)
532 hContainer.hAutocomplete=this
533 var nWidth=hInput.offsetWidth
534 if(!nWidth||nWidth==0)
535 {var hOWInput=hInput.cloneNode(true)
536 hOWInput.style.position='absolute'
537 hOWInput.style.top='-1000px'
538 document.body.appendChild(hOWInput)
539 var nWidth=hOWInput.offsetWidth
540 document.body.removeChild(hOWInput)}
541 var sInputName=hInput.name
542 var hForm=hInput.form
543 var bHasButton=false
544 var sHiddenValue=hInput.value
545 var sValue=hInput.type.toLowerCase()=='text'?hInput.value:''
546 var sHasButton=hInput.getAttribute('autocomplete_button')
547 if(sHasButton!=null&&sHasButton.length>0)
548 {bHasButton=true}
549 if(hInput.type.toLowerCase()=='select-one')
550 {bHasButton=true
551 if(hInput.selectedIndex>=0)
552 {sHiddenValue=hInput.options[hInput.selectedIndex].value
553 sValue=hInput.options[hInput.selectedIndex].text}}
554 if(hForm)
555 {var hHiddenInput=document.createElement('INPUT')
556 hHiddenInput.id=cAutocomplete.CS_HIDDEN_INPUT_PREFIX+this.sInputId
557 hHiddenInput.type='hidden'
558 hForm.appendChild(hHiddenInput)
559 if(this.bAssociative)
560 {hHiddenInput.name=sInputName
561 hInput.name=cAutocomplete.CS_INPUT_PREFIX+sInputName}
562 else
563 {hHiddenInput.name=cAutocomplete.CS_INPUT_PREFIX+sInputName}
564 hHiddenInput.value=sHiddenValue
565 this.sHiddenInputId=hHiddenInput.id}
566 if(bHasButton)
567 {this.bHasButton=true
568 var hInputContainer=document.createElement('DIV')
569 hInputContainer.className='acinputContainer'
570 hInputContainer.style.width=nWidth
571 var hInputButton=document.createElement('INPUT')
572 hInputButton.id=cAutocomplete.CS_BUTTON_PREFIX+this.sInputId
573 hInputButton.type='button'
574 hInputButton.className='button'
575 hInputButton.tabIndex=hInput.tabIndex+1
576 hInputButton.hAutocomplete=this
577 var hNewInput=document.createElement('INPUT')
578 if(this.bAssociative)
579 {hNewInput.name=cAutocomplete.CS_INPUT_PREFIX+sInputName}
580 else
581 {hNewInput.name=sInputName}
582 hNewInput.type='text'
583 hNewInput.value=sValue
584 hNewInput.style.width=nWidth-22
585 hNewInput.className=cAutocomplete.CS_INPUT_CLASSNAME
586 hNewInput.tabIndex=hInput.tabIndex
587 hNewInput.hAutocomplete=this
588 hInputContainer.appendChild(hNewInput)
589 hInputContainer.appendChild(hInputButton)
590 hInput.parentNode.replaceChild(hInputContainer,hInput)
591 hNewInput.id=this.sInputId
592 hInput=hNewInput}
593 if(hInput.attachEvent)
594 {hInput.attachEvent('onkeyup',cAutocomplete.onInputKeyUp)
595 hInput.attachEvent('onkeyup',cAutocomplete.saveCaretPosition)
596 hInput.attachEvent('onkeydown',cAutocomplete.onInputKeyDown)
597 hInput.attachEvent('onblur',cAutocomplete.onInputBlur)
598 hInput.attachEvent('onfocus',cAutocomplete.onInputFocus)
599 if(hInputButton)
600 {hInputButton.attachEvent('onclick',cAutocomplete.onButtonClick)}}
601 else if(hInput.addEventListener)
602 {hInput.addEventListener('keyup',cAutocomplete.onInputKeyUp,false)
603 hInput.addEventListener('keyup',cAutocomplete.saveCaretPosition,false)
604 hInput.addEventListener('keydown',cAutocomplete.onInputKeyDown,false)
605 hInput.addEventListener('keypress',cAutocomplete.onInputKeyPress,false)
606 hInput.addEventListener('blur',cAutocomplete.onInputBlur,false)
607 hInput.addEventListener('focus',cAutocomplete.onInputFocus,false)
608 if(hInputButton)
609 {hInputButton.addEventListener('click',cAutocomplete.onButtonClick,false)}}
610 hInput.setAttribute('autocomplete','OFF')
611 if(hForm)
612 {if(hForm.attachEvent)
613 {hForm.attachEvent('onsubmit',cAutocomplete.onFormSubmit)
614 if(this.bDebug){this.debug("attachEvent added")}}
615 else if(hForm.addEventListener)
616 {hForm.addEventListener('submit',cAutocomplete.onFormSubmit,false)
617 if(this.bDebug){this.debug("addEventListener")}}}}
618 cAutocomplete.prototype.initListContainer=function()
619 {var hInput=document.getElementById(this.sInputId)
620 var hContainer=document.createElement('DIV')
621 hContainer.className='autocomplete_holder'
622 hContainer.id=this.sListId
623 hContainer.style.zIndex=10000+cAutocomplete.nCount
624 hContainer.hAutocomplete=this
625 var hFirstBorder=document.createElement('DIV')
626 hFirstBorder.className='autocomplete_firstborder'
627 var hSecondBorder=document.createElement('DIV')
628 hSecondBorder.className='autocomplete_secondborder'
629 var hList=document.createElement('UL')
630 hList.className='autocomplete'
631 hSecondBorder.appendChild(hList)
632 hFirstBorder.appendChild(hSecondBorder)
633 hContainer.appendChild(hFirstBorder)
634 document.body.appendChild(hContainer)
635 if(hContainer.attachEvent)
636 {hContainer.attachEvent('onblur',cAutocomplete.onListBlur)
637 hContainer.attachEvent('onfocus',cAutocomplete.onListFocus)}
638 else if(hInput.addEventListener)
639 {hContainer.addEventListener('blur',cAutocomplete.onListBlur,false)
640 hContainer.addEventListener('focus',cAutocomplete.onListFocus,false)}
641 if(hContainer.attachEvent)
642 {hContainer.attachEvent('onclick',cAutocomplete.onItemClick)}
643 else if(hContainer.addEventListener)
644 {hContainer.addEventListener('click',cAutocomplete.onItemClick,false)}}
645 cAutocomplete.prototype.createList=function()
646 {var hInput=document.getElementById(this.sInputId)
647 var hContainer=document.getElementById(this.sListId)
648 var hList=hContainer.getElementsByTagName('UL')[0]
649 if(hList)
650 {hList=hList.parentNode.removeChild(hList)
651 while(hList.hasChildNodes())
652 {hList.removeChild(hList.childNodes[0])}}
653 var hListItem=null
654 var hListItemLink=null
655 var hArrKey=null
656 var sArrEl=null
657 var hArr=this.aData
658 var nI=0
659 var sRealText
660 for(hArrKey in hArr)
661 {sArrEl=hArr[hArrKey]
662 hListItem=document.createElement('LI')
663 hListItemLink=document.createElement('A')
664 hListItemLink.setAttribute('itemvalue',hArrKey)
665 var sArrData=sArrEl.split(cAutocomplete.CS_ARRAY_SEPARATOR)
666 if(sArrData.length>1)
667 {this.aData[hArrKey]=sArrData[0]
668 hListItemLink.setAttribute('itemdata',sArrEl.substring(sArrEl.indexOf(cAutocomplete.CS_ARRAY_SEPARATOR)+1))
669 sRealText=sArrData[0]}
670 else
671 {sRealText=sArrEl}
672 hListItemLink.href='#'
673 hListItemLink.appendChild(document.createTextNode(sRealText))
674 hListItemLink.realText=sRealText
675 if(nI==this.nSelectedItemIdx)
676 {this.hActiveSelection=hListItemLink
677 this.hActiveSelection.className='selected'}
678 hListItem.appendChild(hListItemLink)
679 hList.appendChild(hListItem)
680 this.aSearchData[nI++]=sRealText.toLowerCase()}
681 var hSecondBorder=hContainer.firstChild.firstChild
682 hSecondBorder.appendChild(hList)
683 this.bListUpdated=false}
684 cAutocomplete.prototype.initListArray=function()
685 {var hInput=document.getElementById(this.sInputId)
686 var hArr=null
687 if(hInput.type.toLowerCase()=='select-one')
688 {hArr=new Object()
689 for(var nI=0;nI<hInput.options.length;nI++)
690 {hArrKey=hInput.options.item(nI).value
691 sArrEl=hInput.options.item(nI).text
692 hArr[hArrKey]=sArrEl
693 if(hInput.options.item(nI).selected)
694 {this.nSelectedItemIdx=nI}}}
695 else
696 {var sAA=hInput.getAttribute('autocomplete_list')
697 var sAAS=hInput.getAttribute('autocomplete_list_sort')
698 var sArrayType=this.getListArrayType()
699 switch(sArrayType)
700 {case'array':hArr=eval(sAA.substring(6))
701 break
702 case'list':hArr=new Array()
703 var hTmpArray=sAA.substring(5).split('|')
704 var aValueArr
705 for(hKey in hTmpArray)
706 {aValueArr=hTmpArray[hKey].split(cAutocomplete.CS_ARRAY_SEPARATOR)
707 if(aValueArr.length==1)
708 {hArr[hKey]=hTmpArray[hKey]
709 this.bAssociative=false}
710 else
711 {hArr[aValueArr[0]]=aValueArr[1]}}
712 break}
713 if(sAAS!=null&&eval(sAAS))
714 {this.bSorted=true
715 this.aData=hArr.sort()
716 hArr=hArr.sort()}}
717 this.setArray(hArr)}
718 cAutocomplete.prototype.setArray=function(sArray)
719 {if(typeof sArray=='string')
720 {this.aData=eval(sArray)}
721 else
722 {this.aData=sArray}
723 this.bListUpdated=true}
724 cAutocomplete.prototype.setListArray=function(sArray)
725 {this.setArray(sArray)
726 this.updateAndShowList()}
727 cAutocomplete.prototype.getListArrayType=function()
728 {var hInput=document.getElementById(this.sInputId)
729 var sAA=hInput.getAttribute('autocomplete_list')
730 if(sAA!=null&&sAA.length>0)
731 {if(sAA.indexOf('array:')>=0)
732 {return'array'}
733 else if(sAA.indexOf('list:')>=0)
734 {return'list'}
735 else if(sAA.indexOf('url:')>=0)
736 {return'url'}
737 else if(sAA.indexOf('xmlrpc:')>=0)
738 {return'xmlrpc'}}}
739 cAutocomplete.prototype.getListURL=function()
740 {var hInput=document.getElementById(this.sInputId)
741 var sAA=hInput.getAttribute('autocomplete_list')
742 if(sAA!=null&&sAA.length>0)
743 {if(sAA.indexOf('url:')>=0)
744 {return sAA.substring(4)}
745 if(sAA.indexOf('xmlrpc:')>=0)
746 {return sAA.substring(7)}}}
747 cAutocomplete.prototype.setListURL=function(sURL)
748 {this.sListURL=sURL;}
749 cAutocomplete.prototype.onXmlHttpLoad=function()
750 {if(this.hXMLHttp.readyState==4)
751 {var hError=this.hXMLHttp.parseError
752 if(hError&&hError.errorCode!=0)
753 {alert(hError.reason)}
754 else
755 {this.afterRemoteLoad()}}}
756 cAutocomplete.prototype.onXMLRPCHttpLoad=function()
757 {if(this.hXMLHttp.readyState==4)
758 {var hError=this.hXMLHttp.parseError
759 if(hError&&hError.errorCode!=0)
760 {alert(hError.reason)}
761 else
762 {this.afterRemoteLoadXMLRPC()}}}
763 cAutocomplete.prototype.loadXMLRPCListArray=function()
764 {var sURL=this.sListURL
765 var xmlrpc_url=data_path+'/RPC2.php'
766 var aMethodArgs=sURL.split(' ')
767 var sMethodName=aMethodArgs[0]
768 var sStartWith=this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint)
769 sStartWith=sStartWith.replace(/^\s/,'')
770 sStartWith=sStartWith.replace(/\s$/,'')
771 if(sMethodName.indexOf('?')>0)
772 {sMethodName=sMethodName.replace('/^.+\?/','')
773 sURL=sURL.replace('/\?.+$/','')}
774 else
775 {sURL=xmlrpc_url}
776 if(sMethodName.length<1)
777 {var hInput=document.getElementById(this.sInputId)
778 hInput.value=this.sActiveValue
779 return}
780 var sRequest='<?xml version=\'1.0\' encoding="utf-8" ?>\n'
781 sRequest+='<methodCall><methodName>'+sMethodName+'</methodName>\n'
782 if(aMethodArgs.length<=1)
783 {sRequest+='<params/>\n'}
784 else
785 {sRequest+='<params>\n'
786 for(var nI=1;nI<aMethodArgs.length;nI++)
787 {var sArg=aMethodArgs[nI];if(sArg.indexOf('[S]')>=0)
788 {sArg=sArg.replace('[S]',sStartWith)}
789 sRequest+='<param><value><string>'
790 sRequest+=sArg
791 sRequest+='</string></value></param>\n'}
792 sRequest+='</params>\n'}
793 sRequest+='</methodCall>'
794 if(this.bDebug){this.debug('url: "'+sURL+'" sRequest: "'+sRequest.substring(20)+'"')}
795 this.hXMLHttp.open('POST',sURL,true)
796 var hAC=this
797 this.hXMLHttp.onreadystatechange=function(){hAC.onXMLRPCHttpLoad()}
798 this.hXMLHttp.send(sRequest)}
799 cAutocomplete.prototype.loadListArray=function()
800 {var sURL=this.sListURL
801 var sStartWith=this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint)
802 sStartWith=sStartWith.replace(/^\s/,'')
803 sStartWith=sStartWith.replace(/\s$/,'')
804 if(sURL.indexOf('[S]')>=0)
805 {sURL=sURL.replace('[S]',sStartWith)}
806 else
807 {sURL+=this.sActiveValue}
808 this.hXMLHttp.open('GET',sURL,true)
809 var hAC=this
810 this.hXMLHttp.onreadystatechange=function(){hAC.onXmlHttpLoad()}
811 this.hXMLHttp.send(null)}
812 cAutocomplete.prototype.afterRemoteLoad=function()
813 {var hInput=document.getElementById(this.sInputId)
814 var hArr=new Array()
815 var hTmpArray=this.hXMLHttp.responseText.split('|')
816 var aValueArr
817 for(hKey in hTmpArray)
818 {aValueArr=hTmpArray[hKey].split(cAutocomplete.CS_ARRAY_SEPARATOR)
819 if(aValueArr.length==1)
820 {hArr[hKey]=hTmpArray[hKey]}
821 else
822 {hArr[aValueArr[0]]=hTmpArray[hKey].substr(hTmpArray[hKey].indexOf(cAutocomplete.CS_ARRAY_SEPARATOR)+1)}}
823 hInput.className=''
824 hInput.readonly=false
825 hInput.value=this.sActiveValue
826 this.setListArray(hArr)}
827 cAutocomplete.prototype.afterRemoteLoadXMLRPC=function()
828 {var hInput=document.getElementById(this.sInputId)
829 var hArr=new Array()
830 sResult=this.hXMLHttp.responseText
831 if(this.bDebug){this.debug("response: "+sResult.substring(70,190))}
832 sResult.replace('\n','');sResult.replace('\r','');var hKey=0
833 var i=sResult.indexOf('<string>')
834 while(i>=0){var j
835 sResult=sResult.substring(i+8)
836 j=sResult.indexOf('</string>')
837 hArr[hKey]=sResult.substring(0,j)
838 hKey+=1
839 sResult=sResult.substring(j+9)
840 i=sResult.indexOf('<string>')}
841 hInput.className=''
842 hInput.readonly=false
843 hInput.value=this.sActiveValue
844 this.setListArray(hArr)}
845 cAutocomplete.prototype.prepareList=function(bFullList)
846 {var hInput=document.getElementById(this.sInputId)
847 this.sActiveValue=hInput.value
848 var sST=this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint)
849 var sLST=this.getStringForAutocompletion(this.sLastActiveValue,this.nInsertPoint)
850 if(sLST!=sST||bFullList||!this.bListDisplayed||this.bMatchSubstring)
851 {if(this.bRemoteList)
852 {hInput.className='search'
853 this.bXMLRPC?this.loadXMLRPCListArray():this.loadListArray()
854 return}
855 this.updateAndShowList(bFullList)}}
856 cAutocomplete.prototype.updateAndShowList=function(bFullList)
857 {var hContainer=document.getElementById(this.sListId)
858 var hList=hContainer.getElementsByTagName('UL')[0]
859 var hInput=document.getElementById(this.sInputId)
860 if(this.bListUpdated)
861 {this.createList()}
862 var sST=this.bMatchSubstring?this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint):this.sActiveValue
863 var sLST=this.bMatchSubstring?this.getStringForAutocompletion(this.sLastActiveValue,this.nInsertPoint):this.sLastActiveValue
864 if(sST==sLST)
865 {if(!this.bMatchSubstring)
866 {bFullList=true}}
867 this.filterOptions(bFullList)
868 if(this.nItemsDisplayed==0)
869 {if(this.bForceCorrect)
870 {var aPos=this.getInsertPos(this.sActiveValue,this.nInsertPoint,'')
871 cAutocomplete.markInputRange(hInput,this.nLastMatchLength,aPos[0])}}
872 this.sLastActiveValue=this.sActiveValue
873 if(this.nItemsDisplayed>0)
874 {if(!bFullList||this.bMatchSubstring)
875 {this.deselectOption()}
876 if(this.bAutoComplete&&this.nItemsDisplayed==1)
877 {var sStartWith=this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint)
878 var sItemText=hList.getElementsByTagName('LI')[this.nFirstDisplayed].getElementsByTagName('A')[0].realText
879 if(sStartWith.toLowerCase()==sItemText.toLowerCase())
880 {this.selectOption(hList.getElementsByTagName('LI')[this.nFirstDisplayed].getElementsByTagName('A')[0])
881 this.hideOptions()
882 return}}
883 if(this.bAutoComplete&&!bFullList)
884 {this.selectOption(hList.getElementsByTagName('LI')[this.nFirstDisplayed].getElementsByTagName('A')[0])}
885 this.showList()}
886 else
887 {this.clearList()}}
888 cAutocomplete.prototype.showList=function()
889 {if(cAutocomplete.hListDisplayed)
890 {cAutocomplete.hListDisplayed.clearList()}
891 var hInput=document.getElementById(this.sInputId)
892 var nTop=cDomObject.getOffsetParam(hInput,'offsetTop')
893 var nLeft=cDomObject.getOffsetParam(hInput,'offsetLeft')
894 var hContainer=document.getElementById(this.sListId)
895 var hList=hContainer.getElementsByTagName('UL')[0]
896 if(this.bHasButton)
897 {hContainer.style.width=document.getElementById(this.sInputId).parentNode.offsetWidth}
898 else
899 {hContainer.style.width=document.getElementById(this.sInputId).offsetWidth}
900 var nNumLines=(this.nItemsDisplayed<cAutocomplete.CN_NUMBER_OF_LINES)?this.nItemsDisplayed:cAutocomplete.CN_NUMBER_OF_LINES;hList.style.height=nNumLines*cAutocomplete.CN_LINE_HEIGHT+cAutocomplete.CN_HEIGHT_FIX+'px'
901 hContainer.style.top=nTop+hInput.offsetHeight+cAutocomplete.CN_OFFSET_TOP+'px'
902 hContainer.style.left=nLeft+cAutocomplete.CN_OFFSET_LEFT+'px'
903 hContainer.style.display='none'
904 hContainer.style.visibility='visible'
905 hContainer.style.display='block'
906 cAutocomplete.hListDisplayed=this
907 this.bListDisplayed=true}
908 cAutocomplete.prototype.binarySearch=function(sFilter)
909 {var nLow=0
910 var nHigh=this.aSearchData.length-1
911 var nMid
912 var nTry,nLastTry
913 var sData
914 var nLen=sFilter.length
915 var lastTry
916 while(nLow<=nHigh)
917 {nMid=(nLow+nHigh)/2
918 nTry=(nMid<1)?0:parseInt(nMid)
919 sData=this.aSearchData[nTry].substr(0,nLen)
920 if(sData<sFilter)
921 {nLow=nTry+1
922 continue}
923 if(sData>sFilter)
924 {nHigh=nTry-1
925 continue}
926 if(sData==sFilter)
927 {nHigh=nTry-1
928 nLastTry=nTry
929 continue}
930 return nTry}
931 if(typeof(nLastTry)!="undefined")
932 {return nLastTry}
933 else
934 {return null}}
935 cAutocomplete.prototype.getStringForAutocompletion=function(sString,nPos)
936 {if(sString==null||sString.length==0)
937 {return''}
938 if(this.bMatchSubstring)
939 {var nStartPos=sString.lastIndexOf(cAutocomplete.CS_SEPARATOR,nPos-1)
940 nStartPos=nStartPos<0?0:nStartPos
941 var nEndPos=sString.indexOf(cAutocomplete.CS_SEPARATOR,nPos)
942 nEndPos=nEndPos<0?sString.length:nEndPos
943 var sStr=sString.substr(nStartPos,nEndPos-nStartPos)
944 sStr=sStr.replace(/^(\,?)(\s*)(\S*)(\s*)(\,?)$/g,'$3')
945 return sStr}
946 else
947 {return sString}}
948 cAutocomplete.prototype.insertString=function(sString,nPos,sInsert)
949 {if(this.bMatchSubstring)
950 {var nStartPos=sString.lastIndexOf(cAutocomplete.CS_SEPARATOR,nPos-1)
951 nStartPos=nStartPos<0?0:nStartPos
952 var nEndPos=sString.indexOf(cAutocomplete.CS_SEPARATOR,nPos)
953 nEndPos=nEndPos<0?sString.length:nEndPos
954 var sStr=sString.substr(nStartPos,nEndPos-nStartPos)
955 sStr=sStr.replace(/^(\,?)(\s*)(\S?[\S\s]*\S?)(\s*)(\,?)$/g,'$1$2'+sInsert+'$4$5')
956 sStr=sString.substr(0,nStartPos)+sStr+sString.substr(nEndPos)
957 return sStr}
958 else
959 {return sInsert}}
960 cAutocomplete.prototype.getInsertPos=function(sString,nPos,sInsert)
961 {nPos=nPos==null?0:nPos
962 var nStartPos=sString.lastIndexOf(cAutocomplete.CS_SEPARATOR,nPos-1)
963 nStartPos=nStartPos<0?0:nStartPos
964 var nEndPos=sString.indexOf(cAutocomplete.CS_SEPARATOR,nPos)
965 nEndPos=nEndPos<0?sString.length:nEndPos
966 var sStr=sString.substr(nStartPos,nEndPos-nStartPos)
967 sStr=sStr.replace(/^(\,?)(\s*)(\S?[\S\s]*\S?)(\s*)(\,?)$/g,'$1$2'+sInsert)
968 return[nPos,nStartPos+sStr.length]}
969 cAutocomplete.prototype.filterOptions=function(bShowAll)
970 {if(this.hActiveSelection&&!bShowAll)
971 {this.hActiveSelection.className=''}
972 if(typeof bShowAll=='undefined')
973 {bShowAll=false}
974 var hInput=document.getElementById(this.sInputId)
975 var sStartWith=this.getStringForAutocompletion(this.sActiveValue,this.nInsertPoint)
976 if(bShowAll)
977 {sStartWith=''}
978 var hContainer=document.getElementById(this.sListId)
979 var hList=hContainer.getElementsByTagName('UL')[0]
980 var nItemsLength=hList.childNodes.length
981 var hLinkItem=null
982 var nCount=0
983 var hParent=hList.parentNode
984 var hList=hList.parentNode.removeChild(hList)
985 var hTItems=hList.childNodes
986 this.nItemsDisplayed=0
987 if(sStartWith.length==0)
988 {for(var nI=0;nI<nItemsLength;nI++)
989 {if(this.formatOptions)
990 {hTItems[nI].childNodes[0].innerHTML=this.formatOptions(hTItems[nI].childNodes[0].realText,nI)}
991 hTItems[nI].style.display='block'}
992 nCount=nItemsLength
993 if(nItemsLength>0)
994 {this.nFirstDisplayed=0
995 this.nLastDisplayed=nItemsLength-1}
996 else
997 {this.nFirstDisplayed=this.nLastDisplayed=-1}
998 var aPos=this.getInsertPos(this.sActiveValue,this.nInsertPoint,sStartWith)
999 this.nLastMatchLength=aPos[0]}
1000 else
1001 {this.nFirstDisplayed=this.nLastDisplayed=-1
1002 sStartWith=sStartWith.toLowerCase()
1003 var bEnd=false
1004 if(this.bSorted&&this.bMatchBegin)
1005 {var nStartAt=this.binarySearch(sStartWith)
1006 for(var nI=0;nI<nItemsLength;nI++)
1007 {hTItems[nI].style.display='none'
1008 if(nI>=nStartAt&&!bEnd)
1009 {if(!bEnd&&this.aSearchData[nI].indexOf(sStartWith)!=0)
1010 {bEnd=true
1011 continue}
1012 if(this.formatOptions)
1013 {hTItems[nI].childNodes[0].innerHTML=this.formatOptions(hTItems[nI].childNodes[0].realText,nI)}
1014 hTItems[nI].style.display='block'
1015 nCount++
1016 if(this.nFirstDisplayed<0)
1017 {this.nFirstDisplayed=nI}
1018 this.nLastDisplayed=nI}}}
1019 else
1020 {for(var nI=0;nI<nItemsLength;nI++)
1021 {hTItems[nI].style.display='none'
1022 if((this.bMatchBegin&&this.aSearchData[nI].indexOf(sStartWith)==0)||(!this.bMatchBegin&&this.aSearchData[nI].indexOf(sStartWith)>=0))
1023 {if(this.formatOptions)
1024 {hTItems[nI].childNodes[0].innerHTML=this.formatOptions(hTItems[nI].childNodes[0].realText,nI)}
1025 hTItems[nI].style.display='block'
1026 nCount++
1027 if(this.nFirstDisplayed<0)
1028 {this.nFirstDisplayed=nI}
1029 this.nLastDisplayed=nI}}}
1030 if(nCount>0)
1031 {var aPos=this.getInsertPos(this.sActiveValue,this.nInsertPoint,sStartWith)
1032 this.nLastMatchLength=aPos[0]}}
1033 hParent.appendChild(hList)
1034 this.nItemsDisplayed=nCount}
1035 cAutocomplete.prototype.hideOptions=function()
1036 {var hContainer=document.getElementById(this.sListId)
1037 hContainer.style.visibility='hidden'
1038 hContainer.style.display='none'
1039 this.hListDisplayed=null}
1040 cAutocomplete.prototype.markAutocompletedValue=function()
1041 {var hInput=document.getElementById(this.sInputId)
1042 var sValue=this.hActiveSelection.realText
1043 if(this.bMatchSubstring)
1044 {var aPos=this.getInsertPos(this.sLastActiveValue,this.nInsertPoint,sValue)
1045 var nStartPos=aPos[0]
1046 var nEndPos=aPos[1]}
1047 else
1048 {var nStartPos=this.nInsertPoint
1049 var nEndPos=sValue.length}
1050 this.nStartAC=nStartPos
1051 this.nEndAC=nEndPos
1052 if(this.hMarkRangeTimeout!=null)
1053 {clearTimeout(this.hMarkRangeTimeout)}
1054 this.hMarkRangeTimeout=setTimeout(function(){cAutocomplete.markInputRange2(hInput.id)},cAutocomplete.CN_MARK_TIMEOUT)}
1055 cAutocomplete.prototype.selectOptionByIndex=function(nOptionIndex)
1056 {if(this.bListUpdated)
1057 {this.createList()}
1058 var hContainer=document.getElementById(this.sListId)
1059 var hList=hContainer.getElementsByTagName('UL')[0]
1060 var nItemsLength=hList.childNodes.length
1061 if(nOptionIndex>=0&&nOptionIndex<nItemsLength)
1062 {this.selectOption(hList.childNodes[nOptionIndex].getElementsByTagName('A')[0])}}
1063 cAutocomplete.prototype.selectOptionByValue=function(sValue)
1064 {if(this.bListUpdated)
1065 {this.createList()}
1066 sValue=sValue.toLowerCase()
1067 var hContainer=document.getElementById(this.sListId)
1068 var hList=hContainer.getElementsByTagName('UL')[0]
1069 var nItemsLength=hList.childNodes.length
1070 var nSelectedIndex=-1
1071 for(var nI=0;nI<nItemsLength;nI++)
1072 {if(this.aSearchData[nI].indexOf(sValue)==0)
1073 {nSelectedIndex=nI}}
1074 if(nSelectedIndex>=0)
1075 {this.selectOption(hList.childNodes[nSelectedIndex].getElementsByTagName('A')[0])}}
1076 cAutocomplete.prototype.selectOption=function(hNewOption)
1077 {if(this.hActiveSelection)
1078 {if(this.hActiveSelection==hNewOption)
1079 {return}
1080 else
1081 {this.hActiveSelection.className=''}}
1082 this.hActiveSelection=hNewOption
1083 var hInput=document.getElementById(this.sInputId)
1084 if(this.hActiveSelection!=null)
1085 {if(this.sHiddenInputId!=null)
1086 {if(this.bMatchSubstring)
1087 {document.getElementById(this.sHiddenInputId).value=this.hActiveSelection.getAttribute('itemvalue')}
1088 else
1089 {document.getElementById(this.sHiddenInputId).value=this.hActiveSelection.getAttribute('itemvalue')}}
1090 this.hActiveSelection.className='selected'
1091 if(this.bAutoComplete)
1092 {hInput.value=this.insertString(this.sLastActiveValue,this.nInsertPoint,this.hActiveSelection.realText)
1093 this.bAutocompleted=true
1094 this.markAutocompletedValue()}
1095 else
1096 {var aPos=this.getInsertPos(this.sLastActiveValue,this.nInsertPoint,this.hActiveSelection.realText)
1097 hInput.value=this.insertString(this.sActiveValue,this.nInsertPoint,this.hActiveSelection.realText)
1098 cAutocomplete.setInputCaretPosition(hInput,aPos[1])}
1099 this.sActiveValue=hInput.value
1100 if(this.onSelect)
1101 {this.onSelect()}}
1102 else
1103 {hInput.value=this.sActiveValue
1104 cAutocomplete.setInputCaretPosition(hInput,this.nInsertPoint)}}
1105 cAutocomplete.prototype.deselectOption=function()
1106 {if(this.hActiveSelection!=null)
1107 {this.hActiveSelection.className=''
1108 this.hActiveSelection=null}}
1109 cAutocomplete.prototype.clearList=function()
1110 {this.hideOptions()
1111 this.bListDisplayed=false}
1112 cAutocomplete.prototype.getPrevDisplayedItem=function(hItem)
1113 {if(hItem==null)
1114 {var hContainer=document.getElementById(this.sListId)
1115 hItem=hContainer.getElementsByTagName('UL')[0].childNodes.item(hContainer.getElementsByTagName('UL')[0].childNodes.length-1)}
1116 else
1117 {hItem=getPrevNodeSibling(hItem.parentNode)}
1118 while(hItem!=null)
1119 {if(hItem.style.display=='block')
1120 {return hItem}
1121 hItem=hItem.previousSibling}
1122 return null}
1123 cAutocomplete.prototype.getNextDisplayedItem=function(hItem)
1124 {if(hItem==null)
1125 {var hContainer=document.getElementById(this.sListId)
1126 hItem=hContainer.getElementsByTagName('UL')[0].childNodes.item(0)}
1127 else
1128 {hItem=getNextNodeSibling(hItem.parentNode)}
1129 while(hItem!=null)
1130 {if(hItem.style.display=='block')
1131 {return hItem}
1132 hItem=hItem.nextSibling}
1133 return null}
1134 cAutocomplete.prototype.debug=function(s)
1135 {if(this.bDebug){var hInput=document.getElementById(this.sInputId)
1136 var hContainer=document.createElement('DIV')
1137 hContainer.className='debug'
1138 hContainer.innerHTML=s
1139 hInput.form.appendChild(hContainer)}}
1140 cAutocomplete.onInputKeyDown=function(hEvent)
1141 {if(hEvent==null)
1142 {hEvent=window.event}
1143 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1144 var hAC=hElement.hAutocomplete
1145 var hContainer=document.getElementById(hAC.sListId)
1146 var hInput=document.getElementById(hAC.sInputId)
1147 var hList=hContainer.getElementsByTagName('UL')[0]
1148 var hEl=getParentByTagName(hElement,'A')
1149 if(hContainer!=null&&hAC.bListDisplayed)
1150 {var hLI=null
1151 var hLINext=null
1152 if((hEvent.keyCode==13)||(hEvent.keyCode==27))
1153 {var bItemSelected=hEvent.keyCode==13?true:false
1154 hAC.clearList()
1155 if(hAC.bDebug){hAC.debug("key "+hEvent.keyCode+" new active selection")}}
1156 if(hEvent.keyCode==38)
1157 {if(hAC.bDebug){hAC.debug("key "+hEvent.keyCode+" up")}
1158 hLINext=hAC.getPrevDisplayedItem(hAC.hActiveSelection)
1159 if(hLINext!=null)
1160 {hAC.selectOption(hLINext.childNodes.item(0))
1161 if(hAC.nItemsDisplayed>cAutocomplete.CN_NUMBER_OF_LINES)
1162 {if(hList.scrollTop<5&&hLINext.offsetTop>hList.offsetHeight)
1163 {hList.scrollTop=hList.scrollHeight-hList.offsetHeight}
1164 if(hLINext.offsetTop-hList.scrollTop<0)
1165 {hList.scrollTop-=hLINext.offsetHeight}}}
1166 else
1167 {hAC.selectOption(null)}}
1168 else if(hEvent.keyCode==40)
1169 {if(hAC.bDebug){hAC.debug("key "+hEvent.keyCode+" down")}
1170 hLINext=hAC.getNextDisplayedItem(hAC.hActiveSelection)
1171 if(hLINext!=null)
1172 {hAC.selectOption(hLINext.childNodes.item(0))
1173 if(hAC.nItemsDisplayed>cAutocomplete.CN_NUMBER_OF_LINES)
1174 {if(hList.scrollTop>0&&hList.scrollTop>hLINext.offsetTop)
1175 {hList.scrollTop=0}
1176 if(Math.abs(hLINext.offsetTop-hList.scrollTop-hList.offsetHeight)<5)
1177 {hList.scrollTop+=hLINext.offsetHeight}}}
1178 else
1179 {hAC.selectOption(null)}}}
1180 if(hInput.form)
1181 {hInput.form.bLocked=true
1182 if(hAC.bDebug){hAC.debug("onInputKeyDown form blocked")}}
1183 if(hEvent.keyCode==13||hEvent.keyCode==27||hEvent.keyCode==38||hEvent.keyCode==40)
1184 {if(hEvent.preventDefault)
1185 {hEvent.preventDefault()}else{if(hAC.bDebug){hAC.debug("no preventDefault return false")}}
1186 hEvent.cancelBubble=true
1187 hEvent.returnValue=false
1188 return false}}
1189 cAutocomplete.onInputKeyPress=function(hEvent)
1190 {if(hEvent.keyCode==13||hEvent.keyCode==38||hEvent.keyCode==40)
1191 {if(hEvent.preventDefault)
1192 {hEvent.preventDefault()}
1193 hEvent.cancelBubble=true
1194 hEvent.returnValue=false
1195 return false}}
1196 cAutocomplete.onInputKeyUp=function(hEvent)
1197 {if(hEvent==null)
1198 {hEvent=window.event}
1199 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1200 var hAC=hElement.hAutocomplete
1201 var hInput=document.getElementById(hAC.sInputId)
1202 switch(hEvent.keyCode)
1203 {case 8:if(hAC.bAutoComplete&&hAC.bAutocompleted)
1204 {hAC.bAutocompleted=false
1205 return false}
1206 break
1207 case 38:case 40:if(hAC.bListDisplayed)
1208 {if(hEvent.preventDefault)
1209 {hEvent.preventDefault()}
1210 hEvent.cancelBubble=true
1211 hEvent.returnValue=false
1212 return false}
1213 break
1214 case 32:case 46:case 35:case 36:break;default:if(hEvent.keyCode<48)
1215 {if(hEvent.preventDefault)
1216 {hEvent.preventDefault()}
1217 if(hAC.bDebug){hAC.debug("keyUp: hEvent.returnValue = false")}
1218 hEvent.cancelBubble=true
1219 hEvent.returnValue=false
1220 return false}
1221 break}
1222 if(hAC.hMarkRangeTimeout!=null)
1223 {clearTimeout(hAC.hMarkRangeTimeout)}
1224 if(hAC.hShowTimeout)
1225 {clearTimeout(hAC.hShowTimeout)
1226 hAC.hShowTimeout=null}
1227 var nTimeout=hAC.bRemoteList?cAutocomplete.CN_REMOTE_SHOW_TIMEOUT:cAutocomplete.CN_SHOW_TIMEOUT
1228 hAC.hShowTimeout=setTimeout(function(){hAC.prepareList()},nTimeout)
1229 if(hAC.bDebug){hAC.debug("setTimeout "+nTimeout)}}
1230 cAutocomplete.onInputBlur=function(hEvent)
1231 {if(hEvent==null)
1232 {hEvent=window.event}
1233 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1234 if(hElement.form)
1235 {hElement.form.bLocked=false}
1236 var hAC=hElement.hAutocomplete
1237 if(!hAC.hClearTimeout)
1238 {hAC.hClearTimeout=setTimeout(function(){hAC.clearList()},cAutocomplete.CN_CLEAR_TIMEOUT)}}
1239 cAutocomplete.onInputFocus=function(hEvent)
1240 {if(hEvent==null)
1241 {hEvent=window.event}
1242 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1243 var hAC=hElement.hAutocomplete
1244 if(hAC.hClearTimeout)
1245 {clearTimeout(hAC.hClearTimeout)
1246 hAC.hClearTimeout=null}}
1247 cAutocomplete.saveCaretPosition=function(hEvent)
1248 {if(hEvent==null)
1249 {hEvent=window.event}
1250 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1251 var hAC=hElement.hAutocomplete
1252 var hInput=document.getElementById(hAC.sInputId)
1253 if(hEvent.keyCode!=38&&hEvent.keyCode!=40)
1254 {hAC.nInsertPoint=cAutocomplete.getInputCaretPosition(hInput)}}
1255 cAutocomplete.getInputCaretPosition=function(hInput)
1256 {if(typeof hInput.selectionStart!='undefined')
1257 {if(hInput.selectionStart==hInput.selectionEnd)
1258 {return hInput.selectionStart}
1259 else
1260 {return hInput.selectionStart}}
1261 else if(hInput.createTextRange)
1262 {var hSelRange=document.selection.createRange()
1263 if(hInput.tagName.toLowerCase()=='textarea')
1264 {var hSelBefore=hSelRange.duplicate()
1265 var hSelAfter=hSelRange.duplicate()
1266 hSelRange.moveToElementText(hInput)
1267 hSelBefore.setEndPoint('StartToStart',hSelRange)
1268 return hSelBefore.text.length}
1269 else
1270 {hSelRange.moveStart('character',-1*hInput.value.length)
1271 var nLen=hSelRange.text.length
1272 return nLen}}
1273 return null}
1274 cAutocomplete.setInputCaretPosition=function(hInput,nPosition)
1275 {if(hInput.setSelectionRange)
1276 {hInput.setSelectionRange(nPosition,nPosition)}
1277 else if(hInput.createTextRange)
1278 {var hRange=hInput.createTextRange()
1279 hRange.moveStart('character',nPosition)
1280 hRange.moveEnd('character',nPosition)
1281 hRange.collapse(true)
1282 hRange.select()}}
1283 cAutocomplete.markInputRange=function(hInput,nStartPos,nEndPos)
1284 {if(hInput.setSelectionRange)
1285 {hInput.focus()
1286 hInput.setSelectionRange(nStartPos,nEndPos)}
1287 else if(hInput.createTextRange)
1288 {var hRange=hInput.createTextRange()
1289 hRange.collapse(true)
1290 hRange.moveStart('character',nStartPos)
1291 hRange.moveEnd('character',nEndPos-nStartPos)
1292 hRange.select()}}
1293 cAutocomplete.markInputRange2=function(sInputId)
1294 {var hInput=document.getElementById(sInputId)
1295 var nStartPos=hInput.hAutocomplete.nStartAC
1296 var nEndPos=hInput.hAutocomplete.nEndAC
1297 cAutocomplete.markInputRange(hInput,nStartPos,nEndPos)}
1298 cAutocomplete.onListBlur=function(hEvent)
1299 {if(hEvent==null)
1300 {hEvent=window.event}
1301 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1302 hElement=getParentByProperty(hElement,'className','autocomplete_holder')
1303 var hAC=hElement.hAutocomplete
1304 if(!hAC.hClearTimeout)
1305 {hAC.hClearTimeout=setTimeout(function(){hAC.clearList()},cAutocomplete.CN_CLEAR_TIMEOUT)}}
1306 cAutocomplete.onListFocus=function(hEvent)
1307 {if(hEvent==null)
1308 {hEvent=window.event}
1309 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1310 hElement=getParentByProperty(hElement,'className','autocomplete_holder')
1311 var hAC=hElement.hAutocomplete
1312 if(hAC.hClearTimeout)
1313 {clearTimeout(hAC.hClearTimeout)
1314 hAC.hClearTimeout=null}}
1315 cAutocomplete.onItemClick=function(hEvent)
1316 {if(hEvent==null)
1317 {hEvent=window.event}
1318 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1319 var hContainer=getParentByProperty(hElement,'className','autocomplete_holder')
1320 var hEl=getParentByTagName(hElement,'A')
1321 if(hContainer!=null)
1322 {var hAC=hContainer.hAutocomplete
1323 hAC.selectOption(hEl)
1324 document.getElementById(hAC.sInputId).focus()
1325 hAC.clearList()}
1326 if(hEvent.preventDefault)
1327 {hEvent.preventDefault()}
1328 hEvent.cancelBubble=true
1329 hEvent.returnValue=false
1330 return false}
1331 cAutocomplete.onButtonClick=function(hEvent)
1332 {if(hEvent==null)
1333 {hEvent=window.event}
1334 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1335 var hAC=hElement.hAutocomplete
1336 var hInput=document.getElementById(hAC.sInputId)
1337 if(hInput.disabled)
1338 {return}
1339 if(hAC.bDebug){hAC.debug("onButtonClick")}
1340 hAC.prepareList(true)
1341 var hInput=document.getElementById(hAC.sInputId)
1342 hInput.focus()}
1343 cAutocomplete.onFormSubmit=function(hEvent)
1344 {if(hEvent==null)
1345 {hEvent=window.event}
1346 var hElement=(hEvent.srcElement)?hEvent.srcElement:hEvent.originalTarget
1347 if(hElement.bLocked)
1348 {var hAC=hElement.hAutocomplete
1349 if(hAC.bDebug){hAC.debug("onSubmit: hElement.bLocked")}
1350 hElement.bLocked=false
1351 hEvent.returnValue=false
1352 if(hEvent.preventDefault)
1353 {hEvent.preventDefault()}
1354 return false}}