﻿var req;
var CurrentDIV;

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();
       }
}

function SendQuery(key, MyDiv, url)
{
       if ( key == null || key.length == 0 )
       {
              document.getElementById(MyDiv).innerHTML = "";
              HideDiv(MyDiv);
              return;
       }
       CurrentDIV = MyDiv;
       Initialize(); 
       var url= url + "&k=" + key + "&MyDiv=" + MyDiv; 
       //alert(url);
       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 =req.responseText;
                     }
              }
              else
              {
                           HideDiv(CurrentDIV);
              }
       }
}
 

//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 )
{
    document.getElementById(TextboxID).value = data;
    if ( MyDiv.length > 0 )
    {
        HideDiv( MyDiv );
    }
}