// © 2007 Vetup copyright all right reserved
function vt(a,b,c,d,e,f,g,h){z=g;s=a;t=b;y=["/sch","?hl=", "","&l=fr",(d?"&ds="+d:"")].join("");c(s,"submit",M);t.setAttribute("autocomplete","off");b(t,"br",N);y.setAttribute("style","padding:0;margin:0;border-collapse:collapse;font-family:Verdana;font-size:10px;");a(y,"pre",N);z=["pre","", "","&l=1",(e?"&ds="+c:"")].join("");}; vtp.vetupSearch = function(){ this.requestSizeMin = 2; this.inputText = ''; this.inputTextId = ''; this.introInputValue = ''; this.instanceName = ''; this.resultContenerName = ''; this.requesterUri = '/ext/vetupSearch/vetupSearchAsker.php'; this.sites = ''; this.limitStart = ''; this.onSearch = ''; this.isReconstrucing = false; this.create = function (inputId, resultContenerName, vetupSearchLaunchButtonId){ this.inputTextId = inputId; this.resultContenerName = resultContenerName; this.inputText = document.getElementById(inputId); this.instanceName = vtp.vetupSearch.makeInstanceName(inputId); eval(this.instanceName+' = this;'); var onclick = 'vtp.vetupSearch.doSearch(\''+this.instanceName+'\');'; if(vetupSearchLaunchButtonId){ var element = document.getElementById(vetupSearchLaunchButtonId); var where = element.parentNode; var html = element.outerHTML; if(element.onclick){ onclick += element.onclick.toString().replace(/^.*?{/, '').replace(/}$/, '').replace(/\n/g, ' ').replace(/["]/g, "'"); html = html.replace(/onclick=(["']).*?\1/i, ''); };html = html.replace(/\/*\s*>$/g, ' onclick="'+onclick+';return false;">'); where.insertAdjacentHTML('beforeEnd', html); element.style.display = 'none'; }else{ var where = this.inputText.parentNode; var html = '\ <table>\ <tr>\ <td>'+this.inputText.outerHTML+'</td>\ <td>\ <input type="submit" value="Rechercher" onclick="'+onclick+'">\ </td>\ </tr>\ </table>'; this.inputText.removeNode(true); where.insertAdjacentHTML('afterBegin', html); this.inputText = document.getElementById(inputId); };if(!this.inputText.value && this.introInputValue) this.inputText.value = this.introInputValue; this.inputText.onfocus = this.removeIntroValue; this.inputText.onkeyup = this.inputTextKeyUpped; vtp.event.attach('load', this.manageHistory); };this.manageHistory = function(evt){ var request = location.href.capture(/\#request:.+/); if(request){ request = vtp.uri.decode(request); var instanceName = request.capture(/instanceName=(\w+)/); var instance = vtp.vetupSearch.getInstance(null, instanceName); instance.isReconstrucing = true; instance.inputText.value = request.capture(/q=sites:.*? (.+)/); instance.sites = request.capture(/sites:(.*?) /); vtp.vetupSearch.doSearch(instanceName, request.capture(/limitStart=(\d+)/)); } };this.removeIntroValue = function(evt){ var instance = vtp.vetupSearch.getInstance(this); if(this.value == instance.introInputValue){ this.value = ''; } };this.updateInputText = function(inputText, value){ inputText.value = value; this.inputTextOld = value; };this.inputTextCheck = function (){ var value = this.inputText.value; if(this.inputText.value == this.introInputValue){ alert('Veuillez saisir votre recherche.'); return; };if(value.length >= this.requestSizeMin){ if(value || this.limitStart){ this.selectedDbId = ''; this.inputTextOld = value; if(this.onSearch){ if(!this.onSearch()) return; };this.showResults(value); } }else{ if(value.length && value != this.inputTextOld) alert('Votre recherche doit comporter au moins '+this.requestSizeMin+' lettres.'); this.inputTextOld = value; return; } };this.showResults = function(value){ var resultContener = document.getElementById(this.resultContenerName); if(this.sites) value = 'sites:'+this.sites+' '+value; var request = 'isVetupSearch=1&instanceName='+this.instanceName+'&limitStart='+this.limitStart+'&q='+value; document.location = '#request:'+request; var html = vtp.ajaxGet(this.requesterUri, 'POST', request, true); resultContener.innerHTML = html; this.isReconstrucing = false; };this.inputTextKeyUpped = function(evt){ var curkey = vtp.event.getKeyCode(evt); if(curkey != 13) return; vtp.vetupSearch.doSearch(vtp.vetupSearch.makeInstanceName(this.id)); } }; vtp.vetupSearch.doSearch = function(instanceName, limitStart){ var instance = vtp.vetupSearch.getInstance(null, instanceName); if(!limitStart) limitStart = ''; instance.limitStart = limitStart; instance.inputTextCheck(); }; vtp.vetupSearch.makeInstanceName = function(inputId){ return 'inst_'+inputId; }; vtp.vetupSearch.getInstance = function(htmlEntity, instanceName){ if(!instanceName) instanceName = 'inst_'+htmlEntity.id; var vetupSearch = null; eval('vetupSearch = '+instanceName); vetupSearch.instanceName = instanceName; return vetupSearch; };
