﻿
var req;
var CurrentDIV;

//Set up to use javascript to call pages
//You do not need to change anything here
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, MyDiv, url)
{
	if ( key == null || key.length == 0 || key == -1 )
	{
		document.getElementById(MyDiv).innerHTML = "";
		HideDiv(MyDiv);
		return;
	}
	CurrentDIV = MyDiv;
	Initialize(); 
	var url= url + "?NewsID=" +  key;

	if( req != null)
	{
		req.onreadystatechange = Process;
		req.open("GET", url, false);
		req.send(null);
	}
}

//checks is status was good
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
		{
			document.getElementById(CurrentDIV).innerHTML=
				"There was a problem retrieving image:<br>"+req.statusText;
		}
	}
}

function ShowDiv(divid)
{
	if (document.layers) document.layers[divid].display="block";
	else
	{
	    document.getElementById(divid).style.display="block";
	}
}

function HideDiv(divid)

{	if (document.layers) document.layers[divid].display="block";
	else document.getElementById(divid).style.display="none";
}

function SetTextbox( TextboxID, data, MyDiv )
{
    document.getElementById(TextboxID).value = data;
    if ( MyDiv.length > 0 )
    {
        HideDiv( MyDiv );
    }
}

