﻿//
//
//
var req;
var CurrentDIV;
var txtbox;
    var TAB = 9;
	var ESC = 27;
	var KEYUP = 38;
	var KEYDN = 40;
	var ENTER = 13;
//Set up to use javascript to call pages for data lookup
//YOU DO NOT NEED TO CHANGE ANYTHING BELOW
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();
       }
} 
//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 SendQuery(key, e, MyDiv, Tb, url)
{


       if ( key == null || key.length <2 )
       {
              document.getElementById(MyDiv).innerHTML = "";
              HideDiv(MyDiv);
              return;
       }
       CurrentDIV = MyDiv;
       txtbox = Tb;
       Initialize(); 
       var url= url + "&k=" + key + "&MyDiv=" + MyDiv; 
       //var unicode=e.keyCode? e.keyCode : e.charCode;
       
       //KeyCheck(unicode)
       //alert(unicode);
       if( req != null)
       {
              req.onreadystatechange = Process;
              req.open("GET", url, true);
              req.send(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)
              {
                     if(req.responseText=="")
                           HideDiv(CurrentDIV);
                     else
                     {
                           //alert(req.responseText);
                           ShowDiv(CurrentDIV);
                           document.getElementById(CurrentDIV).innerHTML ="<ul>"+ req.responseText +"</ul>";
                     }
              }
              else
              {
              
              ShowDiv(CurrentDIV);
                     document.getElementById(CurrentDIV).innerHTML=
                           "There was a problem retrieving data:<br>"+req.statusText;
              }
       }
       
}
//Show Div Section in html
function ShowDiv(divid)
{
       if (document.layers)document.layers[divid].display="block";
       else document.getElementById(divid).style.display="block";
}
//Hide Div Section in html
function HideDiv(divid)
{
       if (document.layers)
       {
        document.layers[divid].display = "none";
        }
       else 
       {
       document.getElementById(divid).style.display="none";
       }
}
//Load selected value into textbox, and hide div
function SetTextbox( TextboxID, data, MyDiv )
{
    window.location="searchResults.aspx?searchTxt=" + data;
    //document.getElementById(TextboxID).value = data;
    document.getElementById(TextboxID).focus();
    if ( MyDiv.length > 0 )
    {
        HideDiv( MyDiv );
    }
}

function abc(title)
{
    alert(title);  
}
