﻿
/*
    ===================================================================================
    
    This script and function are for the communication towards the server using AJAX.

    ===================================================================================
*/


/*
    Creates an object which will communicate with the web-server.
*/
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
			xmlhttp = false;
			}
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		xmlhttp.overrideMimeType("text/xml"); 
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}


/*
    Makes the request to the server.
*/
function DoRequest(url, queryString)
{
    var http = getHTTPObject();
	
	http.open("POST", url, true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) 
		{
			if (http.status == 200)
			{
				var htmlDoc = http.responseText;
				
				stopSearchProgress();

				document.getElementById('ResultPanel').innerHTML = htmlDoc;
				
				document.getElementById('WaitPanel').style.display = "none";
				document.getElementById('ResultPanel').style.display = "block";
			}
			else
			{
				document.getElementById('WaitPanel').style.display = "none";
				document.getElementById('ErrorPanel').style.display = "block";
			}    
		}
	}
	
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send(queryString);

}
