var req=null;
var CurrentDIV;
var CurrentFrame;
var sSearch='';
var ResponseText='';

//Set up to use javascript to call pages for data lookup
function Initialize()
{
       try
       {
              req = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch(e)
       {
              try
              {
                     req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch(oc)
              {
                     req = null;
              }
       } 
       if( !req && typeof XMLHttpRequest != "undefined" )
       {
              req = new XMLHttpRequest();
              
       }
       return false;       
   
}
//sends the query to desired page, and returns to div autocomplete
//based on what the user typed
//key paramater has what the user typed.
//div paramater states, which div to stick the data back to.
function SendUpdateQuery(Mode,url,cacheprotect)
{
   Initialize(); 

   var url= url + "&Mode=" + Mode;

   if( req != null)
   {
          req.onreadystatechange = ProcessUpdate;
          req.open("GET", url, false);
          req.send(null);
          //req=null;
   }
}

//checks is status was good when calling url for data lookup

function ProcessUpdate()
{
  if (req.readyState == 4)
   {
          // only if "OK"
          if (req.status == 200)
          {
             ResponseText=req.responseText;
          }
          delete req['onreadystatechange'];
          if (getBrowserName()=='msie')
            {
		        CollectGarbage();
		    }
          
   }
}
function SendQuery(MyDiv, MyFrame, Mode, url,async,cacheprotect)
{

   // key = Search criteria
   // myDiv = div on the page to display results in
   // MyFrame = div on the page to display myDiv in
   // mode = Report search, Condition Search, etc
   // url = url of the page which returns results
       CurrentDIV = MyDiv;
       CurrentFrame = MyFrame;
       Initialize(); 

       var url= url + "&Mode=" + Mode + "&MyDiv=" + MyDiv + "&MyFrame=" + MyFrame; 

       if( req != null)
       {
              req.onreadystatechange = Process;
              req.open("GET", url, async);
              req.send(null);
              if (async==false && getBrowserName()!='msie')
              {
				document.getElementById(CurrentDIV).innerHTML=req.responseText;
			  }
              //req=null;
       }
       
}
//checks is status was good when calling url for data lookup

function Process()
{
       if (req.readyState == 4)
       {
              // only if "OK"
              if (req.status == 200)
              {
               document.getElementById(CurrentDIV).innerHTML=req.responseText;
              }
              delete req['onreadystatechange'];
              if (getBrowserName()=='msie')
                {
			        CollectGarbage();
			    }
              
       }
}
