function getXMLHTTPRequest() 
{
	var xmlhttp;

	try
	{
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XMLHttpVersion = new Array("Msxml2.XMLHTTP.8.0", 
									   "Msxml2.XMLHTTP.7.0", 
									   "Msxml2.XMLHTTP.6.0", 
									   "Msxml2.XMLHTTP.5.0", 
									   "Msxml2.XMLHTTP.4.0", 
									   "Msxml2.XMLHTTP.3.0", 
									   "Msxml2.XMLHTTP", 
									   "Microsoft.XMLHTTP");
		for (var i = 0; i < XMLHttpVersion.length && !xmlhttp; i++)
		{
			try 
			{
				xmlhttp = new ActiveXObject(XMLHttpVersion[i]);
			}
			catch (e1) { }
		}
	} 
	
	if (!xmlhttp) xmlhttp = null;
	return xmlhttp;
}

var http = getXMLHTTPRequest();

function TestJournal(arg) 
{
	if ((http != null) && ((http.readyState == 4) || (http.readyState == 0)))
	{
		try
		{
			http.open('GET', 'ajax.php?act=testjournal&id='+arg, true);
			http.send(null);
		}
		catch(e) {}
	}
}

function TestFeedBook(arg) 
{
	if ((http != null) && ((http.readyState == 4) || (http.readyState == 0)))
	{
		try
		{
			http.open('GET', 'ajax.php?act=testfeedbook&id='+arg, true);
			http.send(null);
		}
		catch(e) {}
	}
}

function TestBook(arg) 
{
	if ((http != null) && ((http.readyState == 4) || (http.readyState == 0)))
	{
		try
		{
			http.open('GET', 'ajax.php?act=testbook&id='+arg, true);
			http.send(null);
		}
		catch(e) {}
	}
}

function GetBooksAutor(autor, subtema)
{
	if ((http != null) && ((http.readyState == 4) || (http.readyState == 0)))
	{
		try
		{
			var div = document.getElementById('autor' + autor);
			if (div != null)
			{
				if (div.style.display != '')
				{
					http.open('GET', 'ajax.php?act=GetBooksAutor&autor='+autor+'&subtema='+subtema, true);
					http.onreadystatechange = handleResponse;
					http.send(null);
					div.style.display = '';
				}
				else
				{
					div.style.display = 'none';
				}
			}
		}
		catch(e) {}
	}
}

function GetBookInfo(book)
{
	if ((http != null) && ((http.readyState == 4) || (http.readyState == 0)))
	{
		try
		{
			var div = document.getElementById('book' + book);
			if (div != null)
			{
				if (div.style.display != '')
				{
					http.open('GET', 'ajax.php?act=GetBookInfo&book='+book, true);
					http.onreadystatechange = handleResponse;
					http.send(null);
					div.style.display = '';
				}
				else
				{
					div.style.display = 'none';
				}
			}
		}
		catch(e) {}
	}
}

function handleResponse() 
{
	if ((http.readyState == 4) && (http.status == 200))
	{
		try
		{
			var response = http.responseText;
			var pos = response.indexOf("\n");
			var act = response.substr(0, pos);
			if (act == 'GetBooksAutor')
			{
				response = response.substr(pos+1);
				pos = response.indexOf("\n");
				autor = response.substr(0, pos);
				response = response.substr(pos+1);
				var div = document.getElementById('autor' + autor);
				if (div != null) div.innerHTML = response;
			}
			if (act == 'GetBookInfo')
			{
				response = response.substr(pos+1);
				pos = response.indexOf("\n");
				book = response.substr(0, pos);
				response = response.substr(pos+1);
				var div = document.getElementById('book' + book);
				if (div != null) div.innerHTML = response;
			}
		}
		catch(e) {}
	}
}

