var __currentObj =null; var __objects =new Array(); var _isReqPending =false;      function BS_AJAXUserSearch(root,inputId,actionParam,matchText,waitImg,multiple,quotesAllowed,separator) {this.lastKeyword ='';this.root =root; this.inputId = inputId; this.resultId ='ajax_umatches_result';this.waitId ='ajax_umatches_wait';this.actionParam =actionParam; this.matchText =matchText; this.waitImg =waitImg; 	if(typeof multiple =="undefined")multiple =true; this.multiple =multiple; 	if(typeof quotesAllowed =="undefined")quotesAllowed =false; this.quotesAllowed =quotesAllowed; 	if(typeof separator =="undefined")separator =' ';this.separator =separator; this.foundUser =new Array(); __objects[this.inputId] =this; this.displayWaitCursor =displayWaitCursor; this.findMatchingUser =findMatchingUser; this.displayFoundUser =displayFoundUser;   var inputField =FWS_getElement(this.inputId); var linputId =this.inputId; FWS_addEvent(inputField,'focus',function() {	if(Browser.isIE) this.id =linputId; __currentObj =__objects[this.id]; });FWS_addEvent(inputField,'blur',function() {__currentObj =null; });FWS_addEvent(inputField,'keyup',function() {	if(Browser.isIE) this.id =linputId; __objects[this.id].findMatchingUser(); });}function findMatchingUser() {  	if(_isReqPending) return; var field =document.getElementById(this.inputId); 	if(field.value =='')return; var start =0;	if(this.multiple) {	if(this.quotesAllowed &&field.value.substr_count('"') %2==1)start =field.value.lastIndexOf('"'); else start =field.value.lastIndexOf(this.separator); 	if(start <0)start =0;else start++; }var keyword =field.value.substring(start); keyword =keyword.trim();   	if(keyword ==this.lastKeyword) return; this.lastKeyword =keyword; var tempref =this; var url =this.root +"index.php?"+this.actionParam +"=ajax_get_user&kw=";url +=encodeURIComponent(keyword); myAjax.setEventHandler('onstart',function() {tempref.displayWaitCursor(); _isReqPending =true; });myAjax.setEventHandler('onfinish',function() {FWS_hideElement(tempref.waitId); _isReqPending =false; });myAjax.sendGetRequest(url,function(text) {tempref.displayFoundUser(text); });}function displayWaitCursor() {	if(!FWS_getElement(this.waitId)) {var inputField =FWS_getElement(this.inputId); var div =document.createElement('div'); div.id =this.waitId; div.style.width ='16px';div.style.height ='16px';div.style.padding ='4px';div.style.backgroundColor ='#fff';div.style.border ='1px dotted #999';div.style.position ='absolute';div.style.display ='none';div.innerHTML ='<img src="'+this.root +this.waitImg +'" alt="Wait" />';	inputField.parentNode.appendChild(div); }FWS_displayElement(this.waitId,this.inputId,'tl',5); }function displayFoundUser(text) {	if(!FWS_getElement(this.resultId)) {var inputField =FWS_getElement(this.inputId); var div =document.createElement('div'); div.id =this.resultId; div.onmouseover =div.focus; div.onmouseout =div.blur; div.style.padding ='4px';div.style.whiteSpace ='nowrap';div.style.backgroundColor ='#fff';div.style.border ='1px dotted #999';div.style.position ='absolute';div.style.zIndex =5;div.style.display ='none';	inputField.parentNode.appendChild(div); }var resultField =document.getElementById(this.resultId); this.foundUser =new Array(); var result =text; var resParts =result.split(','); var resStr ='';for(var i =0;i <resParts.length;i++) {	if(resParts[i] =='...')resStr +=resParts[i]; else { this.foundUser[i] =resParts[i]; resStr +='<a href="javascript:addUserToField(\'' + this.inputId;
			resStr += '\',\'' + this.resultId + '\','+this.multiple +',\'' + this.separator;
			resStr += '\','+this.quotesAllowed +',\'' + resParts[i] + '\');">';resStr +=resParts[i] +'</a>';}	if(i <resParts.length -1)resStr +=', ';}	if(resParts.length ==0)resStr ='&nbsp;-&nbsp;';resStr +='<img src="'+this.root +'images/delete.gif" alt=""';resStr +=' style="padding-left: 5px;" onmouseover="this.style.cursor = \'pointer\';"'; resStr +=' onmouseout="this.style.cursor = \'default\';" onclick="hideResults(\'';
	resStr += this.resultId + '\');" />';resultField.innerHTML =this.matchText +': '+resStr; FWS_displayElement(this.resultId,this.inputId,'tlr',5); FWS_getElement(this.inputId).focus(); }    function addUserToField(inputId,resultId,multiple,separator,quotesAllowed,username) {	if(!username) return; var field =document.getElementById(inputId); var usedAlt =false; var start =0;	if(multiple) {var start =field.value.lastIndexOf(separator); var altStart =-1;	if(quotesAllowed) {altStart =field.value.lastIndexOf('"') +1;	if(altStart >start) usedAlt =true; }start =Math.max(altStart,start); 	if(start <0)start =0;}field.value =field.value.substring(0,start); 	if(start >0&&!usedAlt &&multiple) field.value +=separator; field.value +=username; document.getElementById(resultId).style.display ='none';} function hideResults(resultId) {FWS_hideElement(resultId); FWS_hideElement('wait_symbol'); }function keyUp(pEvent) { if(!pEvent) pEvent =window.event; var key =-1; if(pEvent.which) key =pEvent.which; else if(pEvent.keyCode) key =pEvent.keyCode;    if(__currentObj !=null) {	if(key ==32&&pEvent.ctrlKey) {addUserToField(__currentObj.inputId,__currentObj.resultId, __currentObj.multiple,__currentObj.separator, __currentObj.quotesAllowed,__currentObj.foundUser[0]); }else if(key ==27)hideResults(__currentObj.resultId); }}document.onkeyup =keyUp; 
