//holds an instance of XMLHTTPRequest
var xmlHttp = createXmlHttpRequestObject();


	
	
//creates ab XMLHTTPREQUEST instance
function createXmlHttpRequestObject()
{
	//will store the reference to the XMLHttpRequest object
	var xmlHttp;
	//this should work for all browsers except IE6 and older
	try
	{
		//try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		//assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		//try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				//try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e) {}
		}
	}
	//return the created object or display an error message
	if (!xmlHttp)
		alert("Error with your Internet Explorer browser (creating the XMLHttpRequest object). To access the SIMoN Bibliogrpahy please switch to a different browser.");
	else
		return xmlHttp;
}




//called to read a file from the server
function process()
{
     
	//only continue if xmlHttp is not void
	if (xmlHttp)
	{
		//try to connect to the server
		try
		{
			
			// get vars from the input form
			var name = document.getElementById('name').value;
			var email = document.getElementById('email').value;
			var interest = document.getElementById('interest').value;
			var overall = document.getElementById('overall').value;
			var content = document.getElementById('content').value;
			var navigation = document.getElementById('navigation').value;
			var comment = document.getElementById('comment').value;
			
			//assemble the query string to pass to biblio_action.php
			var queryString = "?name=" + name + "&email=" + email + "&interest=" + interest + "&overall=" + overall + "&content=" + content + "&navigation=" + navigation + "&comment=" + comment;
			//initiate server
			xmlHttp.open("GET", "comment_action.php" + queryString, true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
	        
		}
		//display the error in case of failure
		catch(e)
		{
			alert("Cannot connect to server:\n" + e.toString());
		}
	}
}



//function that handles the HTTP response
function handleRequestStateChange()
{
	// display the status of the request
	if (xmlHttp.readyState == 4)
	{
		//continue only if HTTP status is "OK"
		if (xmlHttp.status == 200)
		{
			try
			{
				//read the message from the server
				handleServerResponse();
			}
			catch(e)
			{
				//display error message
				alert("Error reading the response: " + e.toString());
			}
		}
		else
		{
			//display status messgae
			alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}


//function to handle server response
function handleServerResponse()
{
    
	//get the DIV from the results page
	var resultsDisplay = document.getElementById('myDivElement');
	resultsDisplay.innerHTML = xmlHttp.responseText;
	
}

	
	
	
	
	
	
	