// JavaScript Document
// This section creates and maintains the Ajax connection to the server

var xmlhttp // Used to create instance of XMLHttpRequest object

//This fuction is called each time a key is pressed in the form field
//txt1 in the clienthint.html page.
function showAnnouncements(){
	
	xmlhttp=GetXmlHttpObject();	//Call the function that creates the instance of XMLHttpRequest object and call it xmlhttp
	
	if (xmlhttp==null){
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	
	var url="/getAnnouncements.asp";	//The URL of the application on the server to be called
	url=url+"?sid="+Math.random();	//Creating a random number parameter prevents the browser from caching the request
	xmlhttp.onreadystatechange=stateChanged;	//stateChanged() is the function that will be called when the request state changes
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

//This function is called each time the server changes the request state. When the state
//changes to 4 (complete) the text returned will be inserted into the innerHTML of the
//"txtHint" span tag. The response from the server app is stored in the responseText
//property if the xmlhttp object.
function stateChanged(){
	if (xmlhttp.readyState==4){
		document.getElementById("announcements").innerHTML=xmlhttp.responseText;
	}
}

//This function creates the XMLHttpRequest object
function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}

	if (window.ActiveXObject){
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;	//User's browser does not support XMLHttpRequest, so return null
}

setTimeout( 'showAnnouncements()', 1000 ); // Call the showAnnouncements function 1 second after the page loads.

//End of Ajax section