//###########################################################
//2009-02-18. Use Ajax to get a string and insert into maintainer.
//###########################################################
function set_ajax_content(url, ajax_src, ajax_tgt, evkey) { //init
  var ajaxsrc = $(ajax_src);
  if (ajaxsrc == null) return;
  new AjaxUpdate2(ajaxsrc, {url:url, ajax_tgt:ajax_tgt, evkey:evkey});
}
function AjaxUpdate2(elementName, options) {
  this.element = $(elementName);
  if (!this.element) throw new Error(elementName + ' not found');
  this.element.AjaxUpdate = this;
  this.options = options || {};
  this.url = this.options.url || "";
  this.ajax_tgt = this.options.ajax_tgt || "";
  this.evkey = this.options.evkey || "blur";
  Event.observe(this.element, this.evkey, this.doKeyup2.bind(this));
}
AjaxUpdate2.prototype.doKeyup2 = function() {
  var callDoajax = this.doajax2;
  setTimeout(callDoajax.bind(this), 100); 
}
AjaxUpdate2.prototype.doajax2 = function() {   
  var val = $F(this.element);
  if (typeof resetForAjax == 'function') {
     resetForAjax();	//a custom function to reset fields values if needed
  }
  if ( val =="") { 
     $(this.ajax_tgt).update();
     return;
  }
  var url = setFormValues(this.url);  //Insert form values into url
  //Send Ajax request 
  new Ajax.Request(url,{method:'get', onSuccess:displayData3.bind(this), onFailure: displayErr1.bind(this) } );
} 
function setFormValues(url) { //Insert form values into url
  var url0 = url.split("form."); //url=I0010s?F1=form1.MNTF1&F2=form.MNTF2&ABC=V
  if (!url0) return url;
  if (url0.length == 1) return url;
  
  for (var i = 1; i<url0.length; i++) {
    var pos = url0[i].indexOf("&");
	var fldname = url0[i];
    if (pos > 0) {
	   fldname = url0[i].substring(0, pos);
	}
    var val = "";
    if ($(fldname))      val = $F(fldname);
	var val1 = encodeURIComponent(val);
	var rep = "form." + fldname;
	url = url.replace(rep, val1);
  }
  return url;
}
function ajax_content(element, url, on_complete) {//use ajax result of url to update element
   var url0 = setFormValues(url);
   new Ajax.Updater(element, url0, {method: "GET", 
     onComplete: function( ) {
	   //execute the passed in function if any
       if (on_complete && typeof on_complete == 'function') {
	      on_complete();  	  
	   }   
     }
   });   
}
function displayData3 (r) {  //display Ajax result  
   fld = $(this.ajax_tgt);
   if (fld) Element.update(fld, r.responseText); 
   if (typeof afterAjax == 'function') {
      afterAjax(r.responseText); //a custom function for post ajax process
   }
}
//###########################################################
// Version:  2008-05-10, mrc ltd., Lombard, IL, USA  
// Use AJAX to query Retrieval and update maintainer fields.
//###########################################################
function setAjaxSource(url, evkey) { //init
  var ajaxsrc = $('ajax_src');
  if (ajaxsrc == null) return;
  new AjaxUpdate(ajaxsrc, {url:url, evkey:evkey});
}
 
function AjaxUpdate(elementName, options) {
  this.element = $(elementName);
  if (!this.element) throw new Error(elementName + ' not found');
  this.element.AjaxUpdate = this;
  this.options = options || {};
  this.url = this.options.url || "";
  this.evkey = this.options.evkey || "blur";
  Event.observe(this.element, this.evkey, this.doKeyup.bind(this));
}
AjaxUpdate.prototype.doKeyup = function() {
  var callDoajax = this.doajax;
  setTimeout(callDoajax.bind(this), 100); 
}
AjaxUpdate.prototype.doajax = function() {   
  var val = $F(this.element);
  if (  val =="") {
  	for (var i=1; i<20; i++) {
      var id = 'ajax_upd' + i;
      var fld = $(id);
      if (fld == null) continue;
      fld.value=""; 	
    }
  	return;
  }
  var tagtype = this.url + val;
  new Ajax.Request(tagtype,{ method: 'get',onSuccess:displayData1.bind(this), 
            onFailure: displayErr1.bind(this) } );
} 
function displayData1 (r) {  
  eval( r.responseText);
  for (var i=1; i<data_array.length; i++) {
    var id = 'ajax_upd' + i;
    var fld = $(id);
    if (fld) fld.value=data_array[i]; 	
    //alert(fld + ",  " + fld.value);
    id = 'ajax_dsp' + i;
    fld = $(id);
    if (fld) Element.update(fld, data_array[i]); 	
  }
  afterAjax(r.responseText);
}
function displayErr1(r) {  
  Element.update(this.ajaxboxid, 'Ajax link failed: '+ r.statusText);  
}
//###########################################################
// Use Ajax to do 1 setp update from Retieval 
//###########################################################
add_record = function(element,ev) {
  stopEvent(ev);
  doajax(element.href);
  var id = element.id;
  if (!id) {
  	return;
  }
  if (id.startsWith("add_hide") ) {
    Element.hide(element);
    if (id.length > 8) {
    	var seq = id.substring(8);
    	//alert(seq);
    	var showId = "add_show" + seq;
    	var showEl = $(showId);
    	if (showEl) {
    	  Element.show($(showId)); 
    	}
    }
  }  
  if (id.startsWith("add_show") ) {
    Element.hide(element);
    if (id.length > 8) {
    	var seq = id.substring(8);
    	var showId = "add_hide" +  seq;
    	var showEl = $(showId);
    	if (showEl) {
    	  Element.show($(showId)); 
    	}
    }
  }  
}
doajax = function(url) {   
  new Ajax.Request(url,{ method: 'get',onSuccess:displayData2, onFailure: displayErr2 } );
} 
function displayData2 (r) {  
	afterAjax();
}
function displayErr2(r) {  
  alert('Ajax link failed: '+ r.statusText);  
}
//###########################################################
// Version:  2007-11-30, mrc ltd., Lombard, IL, USA  
//###########################################################
var AJAX_HOVER_DELAY=150;
function ajaxlink(element,ev) {//mouseover handler
  url=element.href;
  boxw = element.getAttribute('width');
  boxh = element.getAttribute('height');
  new ALinkObj(element, {boxw:boxw,boxh:boxh,url:url,cursorY:ev.clientY});  
}
stopEvent = function(ev) {
  if(window.event){
    ev.returnValue = false;
    ev.cancelBubble = true;
  }else{
    ev.preventDefault();
    ev.stopPropagation();
  }
}
function ALinkObj(elementName, options) {
  this.element = $(elementName);
  if (!this.element) throw new Error(elementName + ' not found');
  this.element.alinkobj = this;
  this.options = options || {};
  this.boxw = this.options.boxw || 300;  
  this.boxh = this.options.boxh || 200;  
  this.url = this.options.url || "";
  this.cursorY = this.options.cursorY || 0;
  this.inAjaxBox = "n"; 
  this.onmouseover();
  Event.observe(this.element, "mouseout", this.hidebox.bind(this));
}
ALinkObj.prototype.onmouseover = function() {
  this.cursorIn = 'y';
  this.ajaxboxid = getAjaxBox();
  this.element.style.cursor = "pointer"; 
  var callDoajax = this.doajax;
  setTimeout(callDoajax.bind(this), AJAX_HOVER_DELAY); 
}
ALinkObj.prototype.doajax = function() {   
  if (this.ajaxBoxSattus == "on") {return;}   
  if (this.cursorIn == 'n') return;   
  var tagtype = this.url;
  new Ajax.Request(tagtype,{ method: 'get',
      onSuccess:displayData.bind(this), 
      onFailure: displayErr.bind(this) } );
} 
function displayData (r) {  
  if (this.cursorIn == 'n') return;
  //Element.setStyle(this.ajaxboxid, {width:this.boxw, height:this.boxh});
  var innerDiv = '<div class="ajaxboxinner">' + r.responseText + "</div>";
  Element.update(this.ajaxboxid, innerDiv);
  this.setAjaxbox();
  this.ajaxBoxSattus = "on"; 
  
  
}
function displayErr(r) {  
  Element.update(this.ajaxboxid, 'Ajax link failed: '+ r.statusText);  
}

ALinkObj.prototype.hidebox = function() { //context is <a> tag  
  this.cursorIn = 'n';
  var func = this.hidebox2;
  setTimeout(func.bind(this), AJAX_HOVER_DELAY);
  Event.observe(this.ajaxboxid, "mouseover", this.ajaxboxIn.bind(this));
  Event.observe(this.ajaxboxid, "mouseout", this.ajaxboxOut.bind(this));
}
ALinkObj.prototype.hidebox2 = function() { 
  if (this.inAjaxBox == "n" && this.ajaxBoxSattus == "on") { 
    Element.hide(this.ajaxboxid);
    //Element.setStyle(this.element,  {color:this.color0});  
    document.body.removeChild(this.ajaxboxid);  
    this.ajaxBoxSattus = "off"; 
  }  
}
ALinkObj.prototype.ajaxboxIn = function(evt) {  
  this.inAjaxBox = "y"; 
}
ALinkObj.prototype.ajaxboxOut = function(evt) { 
  var eX = Event.pointerX(evt);
  var eY = Event.pointerY(evt);
  var offsetxy = 3;
  var isIn = Position.within($(this.ajaxboxid),eX + offsetxy ,eY + offsetxy);
  var isIn2 = Position.within($(this.ajaxboxid),eX - offsetxy ,eY - offsetxy);
  if (isIn && isIn2) { return; }
  Element.hide(this.ajaxboxid);
  //Element.setStyle(this.element,  {color:this.color0});
  this.ajaxBoxSattus = "off";
  this.inAjaxBox = "n";    
}
ALinkObj.prototype.setAjaxbox = function() { //context is this obj
   var offsetx = 12; var offsety = 3;
   var linkElement = this.element;
   var ajaxbox = $(this.ajaxboxid);

   document.body.appendChild(ajaxbox);  
   Element.show(ajaxbox);  
   if (this.boxh == 0) {
      this.boxh = Element.getHeight(ajaxbox) ;
   }  
   Element.setStyle(this.ajaxboxid, {width:this.boxw, height:this.boxh} );
   
   var linkpos = Position.cumulativeOffset(linkElement); 
   var tagx = linkpos[0];
   var tagy  = linkpos[1]; 
   var tagdim = Element.getDimensions(this.element);  
   var jaxdim = Element.getDimensions(ajaxbox);
   ajaxbox.style.position = 'absolute';
   var bodyh = document.body.clientHeight;
   var bodyw = document.body.clientWidth;
   var winsize = windowSize();
   var winh = winsize.h;   
   var winw = winsize.w;  
   var left = tagx + tagdim.width + offsetx;
   var top  = tagy +  offsety;    
   if (this.cursorY > winh/2 ) {
      top  = tagy + tagdim.height - this.boxh; 
   }
   if (tagx > bodyw/2) {
     left  = tagx - this.boxw - offsetx; 
     var browserName=navigator.appName; 
     if (browserName!="Microsoft Internet Explorer") {left =left-20;}
   }
   var allowh = bodyh - top -30 ;
   //if (this.boxh  >= allowh) {top = top - (this.boxh - allowh);}
   if (top < 0) {top = 0;}
   
   ajaxbox.style.left = left;
   ajaxbox.style.top = top;
   //document.body.appendChild(ajaxbox);  
   //Element.show(ajaxbox);
   this.color0 =  Element.getStyle(linkElement, 'color');
   //Element.setStyle(linkElement, {color:'blue'});
}
function setSmartlinkAjax() {
  var atagls =  document.getElementsByTagName('span');   
  var atags = $A(atagls);  
  for (i = 0; i < atags.length ; i++) {
    var alnkid = atags[i].id;
    if (alnkid.indexOf('ajaxlnk') >= 0)  {
       //new ALinkObj(alnkid);
       Element.addClassName(alnkid, 'ajaxlink');
    }
  }
}
function getAjaxBox() {
  var elemSpan = document.createElement("div");
  //elemSpan.id = "ajaxbox";
  elemSpan.className = "ajaxboxclass"; 
  return elemSpan;
}
function windowSize() {
  var winWidth = 0, winHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winWidth = document.documentElement.clientWidth;
    winHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winWidth = document.body.clientWidth;
    winHeight = document.body.clientHeight;
  }
  var winsize = {"w":winWidth, "h":winHeight};
  return winsize;
}
function addLoadListener(func) {
 if ( typeof window.addEventListener != 'undefined' ) {
  window.addEventListener('load', func, false);
 } else if ( typeof window.document.addEventListener != 'undefined' ) {
  window.document.addEventListener('load', func, false);
 }  else if ( typeof window.attachEvent != 'undefined' ) {
  window.attachEvent('onload', func);
 }  else {
  if ( typeof window.onload != 'function' ) {
   window.onload = func;
  } else {
   var oldFunction = window.onload;
   window.onload = function() { oldFunction(); func(); }
  }
 }
}
//#########################################################
var timedelay=50; //ms
var mrcobj=new Object();
mrcobj.Loader=function(url,onload,onerror,method,params,contentType){
  this.req=null;
  mrcobj.currentLoader=this;
  this.onload=onload;
  this.onerror=(onerror) ? onerror : this.defaultError;
  this.loaddoc(url,method,params,contentType);
}
mrcobj.Loader.prototype.loaddoc=function(url,method,params,contentType){
  if (!method){
    method="GET";
  }
  if (!contentType && method=="POST"){
    contentType='application/x-www-form-urlencoded';
  }
  if (window.XMLHttpRequest){
    this.req=new XMLHttpRequest();
  } else if (window.ActiveXObject){
    this.req=new ActiveXObject("Microsoft.XMLHTTP");
    //document.getElementById("mmsg").innerHTML="window.ActiveXObject ="+this.req;
  }

  if (this.req){
  
    try{
      var loader=this;
      this.req.onreadystatechange=function(){
        mrcobj.Loader.onReadyState.call(loader);
      } 
      this.req.open(method,url,true);

      if (contentType){
        this.req.setRequestHeader('Content-Type', contentType);
      }
      this.req.send(params);
    }catch (err){
      this.onerror.call(this);
    }
  }
}
//####################################
mrcobj.Loader.onReadyState=function(){ 
  var req=this.req;
  var ready=req.readyState;
 
  try{ 
  var httpStatus=req.status;
  //document.getElementById("mmsg").innerHTML=" ready=" + ready + ", status=" + httpStatus;
  if (ready==4){
    if (httpStatus==200 || httpStatus==0){
      this.onload.call(this);
    }else{
      //this.onerror.call(this);
    }
  }
  }
  catch(e){}
}
//####################################
mrcobj.Loader.prototype.defaultError=function(){
  alert("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
}
//#############################################################
// used in maintainer. version 2: pass in source fields IDs (names).
function  set_ajax_suggest(server_app, ret_fld, mnt_fld, functions) {
  setJaxbox();
  setJaxboxsMNT(server_app, ret_fld, mnt_fld, functions);
}
//#############################################################
function  setJaxboxsMNT(server_app, ret_fld, mnt_fld, functions) {
  var msg="No matches";// message for no matching record
  var formObj = $(mnt_fld);
  //alert( functions + functions.click);
  if (formObj) {
      if (functions) {
        formObj.functions = functions;
	  }
      formObj.obj = SetProperties(formObj,"k",server_app,true,true,true,true,msg,false, 10000);
	  formObj.ret_fld = ret_fld;  	 	  
	  Event.observe($$('body')[0], "keyup", HideTheBox2.bindAsEventListener(this) );
	  Event.observe($$('body')[0], "click", HideTheBox3.bindAsEventListener(this) );
  }
}      
//####################################
function  setJaxbox() {
    var elemSpan = document.createElement("span");
    elemSpan.id = "jaxbox";
    elemSpan.className = "jaxboxclass"; 
    document.body.appendChild(elemSpan);
}
//####################################
function SetProperties(xElem,xHidden,xserverCode,
        xignoreCase,xmatchAnywhere,xmatchTextBoxWidth,
        xshowNoMatchMessage,xnoMatchingDataMessage,xuseTimeout, xtheVisibleTime){
          var props={
            elem: xElem,
            hidden: xHidden,
            serverCode: xserverCode,
            regExFlags: ( (xignoreCase) ? "i" : "" ),//case
            regExAny: ( (xmatchAnywhere) ? "" : "^" ),
            matchAnywhere: xmatchAnywhere,
            matchTextBoxWidth: xmatchTextBoxWidth,
            theVisibleTime: xtheVisibleTime,
            showNoMatchMessage: xshowNoMatchMessage,
            noMatchingDataMessage: xnoMatchingDataMessage,
            useTimeout: xuseTimeout
          };
          AddHandler(xElem);
          return props;
}
 //####################################      
function AddHandler(objText){
     objText.onkeyup = GiveOptions;
    // objText.onblur = function(){
          //alert("this.obj.useTimeout=" + this.obj.useTimeout + "  );
          //if(this.obj.useTimeout)StartTimeout();
          //setTimeout("HideTheBox()",10);
		// HideTheBox2();
    // }         
}
 
var arrOptions = new Array();
var strLastValue = "";
var bMadeRequest;
var theTextBox;
var objLastActive;
var currentValueSelected = -1;
var bNoResults = false;
var isTiming = false;
//####################################
function GiveOptions(e){      
        var intKey = -1;
        if(window.event){
          intKey = event.keyCode;
          theTextBox = event.srcElement;
        } else {
          intKey = e.which;
          theTextBox = e.target;
        }			
        if(theTextBox.obj.useTimeout){
          //if(isTiming)EraseTimeout();
          //StartTimeout();
        }
        if(theTextBox.value.length == 0  ){
          arrOptions = new Array();
          HideTheBox();
          strLastValue = "";
          return false;
        }
        if(objLastActive == theTextBox){
          if(intKey == 13){
            GrabHighlighted();
            theTextBox.blur();
            //document.forms[0].submit();
            return false;
          }   else if(intKey == 38){
            MoveHighlight(-1);
            GrabHighlighted2()
            return false;
          }   else if(intKey == 40){
            MoveHighlight(1);
            GrabHighlighted2()
            return false;
          }  else {
           // var charCode = (e.charCode)?e.charCode : ((e.which) ? e.which : e.keyCode);
		    if (intKey == 9) { //tab
              hideTheBox(); 
              return false
			}
            if (intKey == 32) {
              //alert("space!"); 
              return false
			}
          }
        }
        if(objLastActive != theTextBox  ||
            theTextBox.value.indexOf(strLastValue) != 0 ||
              ( (arrOptions.length==0 || arrOptions.length==15 ) && !bNoResults) ||
                 (theTextBox.value.length > strLastValue.length)) {
             objLastActive = theTextBox;
             bMadeRequest = true;
             callajax0(theTextBox.value);
           // document.getElementById("mmsg").innerHTML="get data....theTextBox.value="+theTextBox.value;
        }  else if(!bMadeRequest){
          BuildList(theTextBox.value);
          //document.getElementById("mmsg").innerHTML="not get data................";
        }
        strLastValue = theTextBox.value;
}
//####################################
function callajax0(xStrText){
   var today=new Date();  
   var t0=today.getTime(); tt0=t0;
   setTimeout('callajax1('+t0+')', timedelay);
   //alert("op");
}
var tt0=0;
//####################################
function callajax1(stamp){
  if(stamp == tt0) {
    var params = setParms1(theTextBox);
    var loader1 = new mrcobj.Loader(theTextBox.obj.serverCode, BuildChoices,null,"POST",params);
  }
}
//####################################
function setParms1(jbox) {
  var parms="AJAX=Y&AJAXFIELD=" + jbox.ret_fld;
  parms += "&" + jbox.ret_fld + "=" + escape(jbox.value); 
 // alert("parms=" + parms );
  return parms;
}
//####################################00000000000000000
function BuildChoices(){
   if (theTextBox.value.length == 0) return;
   var jaxfield=theTextBox.name;
   var jaxvalue=theTextBox.value;
   var errcode=0;
   //alert(theTextBox.value+'=='+jaxvalue);
   var strText = this.req.responseText;
   if (strText.length==0) return;
   eval(strText);
   if (errcode==1) return;
   var boxvalue=theTextBox.value;
   try{
      if(fieldtype==0){
         boxvalue=boxvalue.replace(/,/gi,'');
         strLastValue=strLastValue.replace(/,/gi,'');
      }
   }catch(e){}
   //if (theTextBox.name != jaxfield || boxvalue != jaxvalue) return; //bj
   BuildList(strLastValue);
   bMadeRequest = false;
}
//####################################
function BuildList(theText){
        SetElementPosition(theTextBox);
        var theMatches = MakeMatches(theText);
        theMatches = theMatches.join().replace(/\,/gi,"");
        if(theMatches.length > 0){
          document.getElementById("jaxbox").innerHTML = theMatches;
          document.getElementById("OptionsList_0").className="highEl";
          currentValueSelected = 0;
          bNoResults = false;
	
		  if (!theTextBox.functions) return;
	      if (!theTextBox.functions.build) return;
	      if (typeof theTextBox.functions.build == 'function') {
	        theTextBox.functions.build();//passed in user defined function
	      }
        } else {
          currentValueSelected = -1;
          bNoResults = true;
          if (theTextBox.obj.showNoMatchMessage) {
            document.getElementById("jaxbox").innerHTML = "<span class='noMatchData'>" +
              theTextBox.obj.noMatchingDataMessage +"</span>";
          } else {
		     HideTheBox();
		  }
        }
}
//####################################
function SetElementPosition(theTextBoxInt){
        var selectedPosX = 0;
        var selectedPosY = 0;
        var theElement = theTextBoxInt;
        if (!theElement) return;
        var theElemHeight = theElement.offsetHeight;
        var theElemWidth = theElement.offsetWidth;
        while(theElement != null){
          selectedPosX += theElement.offsetLeft;
          selectedPosY += theElement.offsetTop;
          theElement = theElement.offsetParent;
        }
        xPosElement = document.getElementById("jaxbox");
        xPosElement.style.left = selectedPosX;
        if(theTextBoxInt.obj.matchTextBoxWidth)
          xPosElement.style.width = theElemWidth+20;
        xPosElement.style.top = selectedPosY + theElemHeight
        xPosElement.style.display = "block";
        if(theTextBoxInt.obj.useTimeout){
          xPosElement.onmouseout = StartTimeout;
          xPosElement.onmouseover = EraseTimeout;
        }
        else{
          xPosElement.onmouseout = null;
          xPosElement.onmouseover = null;
        }
}
//####################################
var countForId = 0;
function MakeMatches(xCompareStr){ 
      	xCompareStr = xCompareStr.replace("$", "\\$");
      	countForId = 0;
        var matchArray = new Array();
        var regExp = new RegExp(theTextBox.obj.regExAny + xCompareStr,theTextBox.obj.regExFlags);
        for(i=0;i<arrOptions.length;i++){
          var theMatch = arrOptions[i].match(regExp);
          //var theMatch = arrOptions[i][0].match(regExp);
          if(theMatch){
            matchArray[matchArray.length]= CreateUnderline(arrOptions[i], xCompareStr,i);
          }
        }
        return matchArray;
}
//####################################
var hiStart = "<span class='spanMatchText'>";
var hiEnd = "</span>";
var selStart = "<span style='width:100%;display:block;' class='normalEl' onmouseover='SetHighColor(this)'";
var selEnd ="</span>";
	  
function CreateUnderline(xStr,xTextMatch,xVal){
  selMid = "onclick='SetText(" + xVal + ")'" + "id='OptionsList_" + countForId + "' theArrayNumber='"+ xVal +"'>";
  var regExp = new RegExp(theTextBox.obj.regExAny + xTextMatch,theTextBox.obj.regExFlags);
  var aStart = xStr.search(regExp);
  var matchedText = xStr.substring(aStart, aStart + xTextMatch.length);
  countForId++;
  return selStart + selMid + xStr.replace(regExp,hiStart + matchedText + hiEnd) + selEnd;
}
//####################################
function MoveHighlight(xDir){
    if(currentValueSelected >= 0){
        newValue = parseInt(currentValueSelected) + parseInt(xDir);
        if(newValue > -1 && newValue < countForId){
            currentValueSelected = newValue;
            SetHighColor (null);
        }
    }
}
//####################################
function SetHighColor(theTextBox){
    if(theTextBox){
        currentValueSelected = theTextBox.id.slice(theTextBox.id.indexOf("_")+1,
        theTextBox.id.length);
    }
    for(i = 0; i < countForId; i++){
        document.getElementById('OptionsList_' + i).className ='normalEl';
    }
    document.getElementById('OptionsList_' + currentValueSelected).className = 'highEl';
}
//####################################
function SetText(xVal){
    theTextBox.value = arrOptions[xVal]; //set text value
    document.getElementById("jaxbox").style.display = "none";
    currentValueSelected = -1; //remove the selected index
    var search = document.forms[0].btn_search;
    if (search) {
        document.forms[0].btn_search.focus();
	}
	if (typeof suggest_click == 'function') {
	   suggest_click();//user defined function
	}
	if (!theTextBox.functions) return;
	if (!theTextBox.functions.click) return;
	if (typeof theTextBox.functions.click == 'function') {
	   theTextBox.functions.click();//passed in user defined function
	}
	// alert(theTextBox.value + theTextBox.functions);
}
//####################################
function GrabHighlighted(){
   if(currentValueSelected >= 0){
     xVal = document.getElementById("OptionsList_" + currentValueSelected).getAttribute("theArrayNumber");
     SetText(xVal);
     HideTheBox();
   }
}
//####################################
function GrabHighlighted2(){
   if(currentValueSelected >= 0){
     xVal = document.getElementById("OptionsList_" + currentValueSelected).getAttribute("theArrayNumber");
     theTextBox.value = arrOptions[xVal]; //set text value
	 if (typeof suggest_select == 'function') {
	    suggest_select(); //execute user defined function
	 }
	 if (!theTextBox.functions) return;
	 if (!theTextBox.functions.select) return;
	 if (typeof theTextBox.functions.select == 'function') {
	   theTextBox.functions.select();//passed in user defined function
	 }
     //SetText(xVal);
     //HideTheBox();
   }
}
//####################################
function HideTheBox(){
    document.getElementById("jaxbox").style.display = "none";
    currentValueSelected = -1;
    EraseTimeout();
}
//####################################
// On blur due to TAB key, hide box
function HideTheBox2(evt){
    var intKey = -1;
    if(window.event){
	  intKey = event.keyCode; 
	} else {
	  intKey = evt.which; 
	}
	//alert(intKey + "-----" + evt.keyCode); 
	if(intKey == 9){ HideTheBox(); } //tab key
}
//####################################
// On  click on page, hide box
function HideTheBox3(evt){
     //alert( "-----" + evt.keyCode);     
	 HideTheBox(); 
}
//####################################
function EraseTimeout(){
    clearTimeout(isTiming);
    isTiming = false;
}
//####################################
function StartTimeout(){
    // alert("theTextBox.obj.theVisibleTime=" );
    //isTiming = setTimeout("HideTheBox()",theTextBox.obj.theVisibleTime);
}
