﻿var req;
var curDiv;
var bi;

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, setDiv, url, bii)
{
       if ( key == null || key.length == 0 )
       {
            document.getElementById(setDiv).innerHTML = "";
       		if (document.layers) document.layers[setDiv].display = "none";
       		else document.getElementById(setDiv).style.display="none";
              return;
       }
       curDiv = setDiv;
       bi = bii;
       Initialize(); 
       var url= url + "&q=" + key + "&setDiv=" + setDiv; 
       if( req != null)
       {
              req.onreadystatechange = Process;
              req.open("GET", url, true);
              req.send(null);
       }
}
 
function Process()
{
       if (req.readyState == 4)
       {

              if (req.status == 200)
              {
                     if(req.responseText=="")
       			        if (document.layers) document.layers[curDiv].display = "none";
       			        else document.getElementById(curDiv).style.display="none";
                     else
                     {     	
                     if(bi=="block")
       				    {			    
       				        if (document.layers) document.layers[curDiv].display="block";
       				        else document.getElementById(curDiv).style.display="block";
                            document.getElementById(curDiv).innerHTML =req.responseText;
                        }
                     if(bi=="inline")
       				    {			    
       				        if (document.layers) document.layers[curDiv].display="inline";
       				        else document.getElementById(curDiv).style.display="inline";
                            document.getElementById(curDiv).innerHTML =req.responseText;
                        }
                     }
              }
              else
              {
                     document.getElementById(curDiv).innerHTML=
                           "FAIL - "+req.statusText;
              }
       }
}
 

function SetTextbox( TextboxID, data, setDiv )
{
    document.getElementById(TextboxID).value = data;
    if ( setDiv.length > 0 )
    {
       	if (document.layers) document.layers[setDiv].display = "none";
       	else document.getElementById(setDiv).style.display="none";
    }
}

function toggleDiv( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function toggleInlineDiv( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'inline':'none';
  vis.display = (vis.display==''||vis.display=='inline')?'none':'inline';
}
